inspect-server/src/main/java/com/yuanchu/mom/controller/InsOrderPlanController.java
@@ -165,15 +165,15 @@ @ValueClassify("æ£éªä»»å¡") @ApiOperation(value = "ä¸ä¼ éä»¶") @PostMapping("/uploadFile") public Result<?> uploadFile(Integer orderId, MultipartFile file) { return Result.success(insOrderPlanService.uploadFile(orderId, file)); public Result<?> uploadFile(Integer orderId, MultipartFile file, String sonLaboratory) { return Result.success(insOrderPlanService.uploadFile(orderId, file, sonLaboratory)); } @ValueClassify("æ£éªä»»å¡") @ApiOperation(value = "å é¤éä»¶") @PostMapping("/delfile") public Result<?> delfile(Integer id) { return Result.success(insOrderFileService.removeById(id)); return Result.success(insOrderFileService.delfile(id)); } @ValueAuth inspect-server/src/main/java/com/yuanchu/mom/controller/WarehouseController.java
@@ -27,7 +27,7 @@ return Result.success(warehouseService.addWarehouse(name)); } @ValueAuth @ValueClassify("æ ·å管ç") @GetMapping("/selectWarehouse") @ApiOperation("æ¥è¯¢ä»åº") public Result selectWarehouse() { @@ -85,8 +85,8 @@ @ValueClassify("æ ·å管ç") @PostMapping("/outWarehouse") @ApiOperation("æ ·ååºåº") public Result outWarehouse(String sampleCode) { return Result.success(warehouseService.outWarehouse(sampleCode)); public Result outWarehouse(String sampleCode, boolean a) { return Result.success(warehouseService.outWarehouse(sampleCode,a)); } @ValueAuth inspect-server/src/main/java/com/yuanchu/mom/dto/Exceldata.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,14 @@ package com.yuanchu.mom.dto; import lombok.Data; import java.util.Map; @Data public class Exceldata { private Map<Integer, Object> project ; private Map<String,Object> dataRow; } inspect-server/src/main/java/com/yuanchu/mom/mapper/InsOrderFileMapper.java
@@ -17,5 +17,5 @@ */ public interface InsOrderFileMapper extends BaseMapper<InsOrderFile> { IPage<InsOrderFile> getFileList(@Param("page") Page page, @Param("ew") QueryWrapper<InsOrderFile> ew , @Param("insOrderId") Integer insOrderId); IPage<InsOrderFile> getFileList(@Param("page") Page page, @Param("ew") QueryWrapper<InsOrderFile> ew , @Param("insOrderId") Integer insOrderId, @Param("sonLaboratory") String sonLaboratory); } inspect-server/src/main/java/com/yuanchu/mom/pojo/InsOrderFile.java
@@ -65,4 +65,8 @@ @TableField(fill = FieldFill.INSERT_UPDATE) private LocalDateTime updateTime; @ApiModelProperty("æå±ç«ç¹") @ValueTableShow(6) private String sonLaboratory; } inspect-server/src/main/java/com/yuanchu/mom/service/InsOrderFileService.java
@@ -12,4 +12,5 @@ * @since 2024-06-06 10:08:21 */ public interface InsOrderFileService extends IService<InsOrderFile> { int delfile(Integer id); } inspect-server/src/main/java/com/yuanchu/mom/service/InsOrderPlanService.java
@@ -47,7 +47,7 @@ Map<String,Object> getFileList(Page page, InsOrderFile insOrderFile); int uploadFile(Integer orderId, MultipartFile file); int uploadFile(Integer orderId, MultipartFile file,String sonLaboratory); List<String> upPlanUser2(Integer orderId); inspect-server/src/main/java/com/yuanchu/mom/service/WarehouseService.java
@@ -34,7 +34,7 @@ int inWarehouse(String trees, String sampleCode); int outWarehouse(String sampleCode); int outWarehouse(String sampleCode, boolean a); Map<String, Object> getSampleRecord(Integer id); inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderFileServiceImpl.java
@@ -20,4 +20,20 @@ */ @Service public class InsOrderFileServiceImpl extends ServiceImpl<InsOrderFileMapper, InsOrderFile> implements InsOrderFileService { @Resource private InsOrderFileMapper insOrderFileMapper; @Value("${wordUrl}") private String wordUrl; //å é¤éä»¶ @Override public int delfile(Integer id) { InsOrderFile insOrderFile = insOrderFileMapper.selectById(id); File file = new File(wordUrl + "/" + insOrderFile.getFileUrl()); file.delete(); insOrderFileMapper.deleteById(id); return 0; } } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -129,6 +129,9 @@ @Resource private InsOrderFileMapper insOrderFileMapper; @Resource FuSheUtils fuSheUtils; @Override public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) { Map<String, Object> map = new HashMap<>(); @@ -290,13 +293,18 @@ map.put("head", PrintChina.printChina(InsOrderFile.class)); Integer insOrderId = insOrderFile.getInsOrderId(); insOrderFile.setInsOrderId(null); IPage<InsOrderFile> insOrderFileIPage = insOrderFileMapper.getFileList(page, QueryWrappers.queryWrappers(insOrderFile), insOrderId); String sonLaboratory = null; if (ObjectUtils.isNotEmpty(insOrderFile.getSonLaboratory())) { sonLaboratory = insOrderFile.getSonLaboratory(); insOrderFile.setSonLaboratory(null); } IPage<InsOrderFile> insOrderFileIPage = insOrderFileMapper.getFileList(page, QueryWrappers.queryWrappers(insOrderFile), insOrderId, sonLaboratory); map.put("body", insOrderFileIPage); return map; } @Override public int uploadFile(Integer orderId, MultipartFile file) { public int uploadFile(Integer orderId, MultipartFile file, String sonLaboratory) { String urlString; String pathName; String path; @@ -319,16 +327,39 @@ if (!realpath.exists()) { realpath.mkdirs(); } pathName = UUID.randomUUID() + "_" + file.getOriginalFilename(); pathName = file.getOriginalFilename(); urlString = realpath + "/" + pathName; file.transferTo(new File(urlString)); insOrderFile.setFileUrl(pathName); return insOrderFileMapper.insert(insOrderFile); } catch (Exception e) { e.printStackTrace(); System.err.println("éä»¶ä¸ä¼ é误"); return 0; if (ObjectUtils.isNotEmpty(sonLaboratory)) { insOrderFile.setSonLaboratory(sonLaboratory); //å é¤éå¤çæ°æ® insOrderFileMapper.delete(Wrappers.<InsOrderFile>lambdaQuery() .eq(InsOrderFile::getInsOrderId, orderId) .eq(InsOrderFile::getType, insOrderFile.getType()) .eq(InsOrderFile::getFileName, insOrderFile.getFileName()) .eq(InsOrderFile::getSonLaboratory, insOrderFile.getSonLaboratory()) .eq(InsOrderFile::getFileUrl, insOrderFile.getFileUrl())); } else { //å é¤éå¤çæ°æ® insOrderFileMapper.delete(Wrappers.<InsOrderFile>lambdaQuery() .eq(InsOrderFile::getInsOrderId, orderId) .eq(InsOrderFile::getType, insOrderFile.getType()) .eq(InsOrderFile::getFileName, insOrderFile.getFileName()) .isNull(InsOrderFile::getSonLaboratory) .eq(InsOrderFile::getFileUrl, insOrderFile.getFileUrl())); } insOrderFileMapper.insert(insOrderFile); //妿æ¯è¾å°è¯éª(è¿åº/è¿ç¨ä¸ä¼ çcsvæä»¶) String[] split = filename.split("\\."); if (ObjectUtils.isNotEmpty(sonLaboratory) && (sonLaboratory.equals("è¿åº") || sonLaboratory.equals("è¿åº")) && split[split.length - 1].equals("csv")) { fuSheUtils.getFuSheWord(sonLaboratory, insOrderFile); } } catch (Exception e) { System.err.println("éä»¶ä¸ä¼ é误"); } return 0; } @Override @@ -419,7 +450,8 @@ throw new ErrorException("è¯¥æ ·åçæ£éªä»»å¡è¿æ²¡æç»æè¯éªæç»§ç»è¯éª,ææ¶æ æ³åºåº!"); } } warehouseService.outWarehouse(sampleCode); boolean a = true; warehouseService.outWarehouse(sampleCode, a); return 0; } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
@@ -40,6 +40,8 @@ import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.net.URLEncoder; import java.time.LocalDate; import java.time.LocalDateTime; @@ -500,7 +502,9 @@ .filter(dto -> dto.getPrice() != null) // è¿æ»¤æä»·æ ¼ä¸º null ç对象 .mapToDouble(value -> value.getPrice().doubleValue() * value.getNum()) .sum(); map.put("total", totalPrice); BigDecimal bd = new BigDecimal(totalPrice).setScale(2, RoundingMode.HALF_UP); double roundedTotalPrice = bd.doubleValue(); map.put("total", roundedTotalPrice); return map; } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
@@ -251,15 +251,6 @@ } catch (Exception e) { throw new ErrorException("æ¾ä¸å°æ¹å人çç¾å"); } //è·ååºæçæ¥åä¸ç¨ç« /* String sealUrl; try { String laboratory = insOrderMapper.selectById(insReport.getInsOrderId()).getLaboratory(); sealUrl = insReportMapper.getLaboratoryByName(laboratory); } catch (Exception e) { throw new ErrorException("æ¾ä¸å°æ¥åä¸ç¨ç« "); } if (sealUrl == null) throw new ErrorException("æ¾ä¸å°æ¥åä¸ç¨ç« ");*/ //ç³»ç»çææ¥åå°å String url = insReport.getUrl(); //æå¨ä¸ä¼ æ¥åå°å @@ -488,20 +479,6 @@ public String wordToPdf(String wordPath, String pdfPath, String sealUrl) { FileOutputStream os = null; try { //åè¯ ä¸ç¶åæ¢åææ°´å° // InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml"); /*String url; try { InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml"); File file = File.createTempFile("temp", ".tmp"); OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); url = file.getAbsolutePath(); } catch (FileNotFoundException e) { throw new ErrorException("æ¾ä¸å°æ¨¡æ¿æä»¶"); } catch (IOException e) { throw new RuntimeException(e); }*/ InputStream is = new ClassPathResource("/lib/license.xml").getInputStream(); License license = new License(); license.setLicense(is); @@ -527,6 +504,7 @@ } } } doc.updateFields(); doc.save(os, SaveFormat.PDF); //æ·»å éªç¼ç« inspect-server/src/main/java/com/yuanchu/mom/service/impl/WarehouseServiceImpl.java
@@ -1,5 +1,7 @@ package com.yuanchu.mom.service.impl; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.yuanchu.mom.dto.HistoryDto; @@ -20,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author Administrator @@ -42,6 +45,8 @@ private WarehouseCellService warehouseCellService; private InsSampleMapper insSampleMapper; private InsOrderStateMapper insOrderStateMapper; private InsProductMapper insProductMapper; @@ -98,11 +103,37 @@ @Override @Transactional(rollbackFor = Exception.class) public int upShelf(WarehouseShelf warehouseShelf) { WarehouseShelf shelf = warehouseShelfMapper.selectById(warehouseShelf.getId()); if (shelf.getCol()>=warehouseShelf.getCol() && shelf.getRow() >= warehouseShelf.getRow()) { //å¦æç»´æ¤çæ°æ®å°äºåæçè¡åæ°å¯ä»¥è¿è¡ä¿®æ¹ warehouseCellMapper.update(null, Wrappers.<WarehouseCell>lambdaUpdate() .eq(WarehouseCell::getShelfId, warehouseShelf.getWarehouseId()) .gt(WarehouseCell::getRow, warehouseShelf.getRow()) .gt(WarehouseCell::getCol, warehouseShelf.getCol()) .eq(WarehouseCell::getShelfId, warehouseShelf.getId()) .and(true, wrapper -> wrapper.gt(WarehouseCell::getRow, warehouseShelf.getRow()) .or() .gt(WarehouseCell::getCol, warehouseShelf.getCol())) .set(WarehouseCell::getState, 0)); }else { //å¦æç»´æ¤çæ°æ®å¤§äºåæçè¡åæ°éè¦è¿è¡é¢å¤æ·»å List<WarehouseCell> cells = new ArrayList<>(); for (int i = 1; i < warehouseShelf.getRow() + 1; i++) { for (int a = 1; a < warehouseShelf.getCol() + 1; a++) { WarehouseCell cell = new WarehouseCell(); cell.setRow(i); cell.setCol(a); cell.setState(1); cell.setShelfId(warehouseShelf.getId()); WarehouseCell warehouseCell = warehouseCellMapper.selectOne(Wrappers.<WarehouseCell>lambdaQuery() .eq(WarehouseCell::getShelfId, warehouseShelf.getId()) .eq(WarehouseCell::getRow, i) .eq(WarehouseCell::getCol, a)); if (ObjectUtils.isNotEmpty(warehouseCell)){ cell.setId(warehouseCell.getId()); } cells.add(cell); } } warehouseCellService.saveOrUpdateBatch(cells); } warehouseShelfMapper.updateById(warehouseShelf); return 0; } @@ -139,7 +170,7 @@ } @Override public int outWarehouse(String sampleCode) { public int outWarehouse(String sampleCode, boolean a) { List<InsSample> samples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getSampleCode, sampleCode).select(InsSample::getId,InsSample::getCellId)); if(samples.size()!=1){ throw new ErrorException("æ ·åç¼å·è¾å ¥æè¯¯"); @@ -147,6 +178,21 @@ if(samples.get(0).getCellId()==null){ throw new ErrorException("æ ·å " + sampleCode + " æªå ¥åº"); } if (!a) { //å¤æè¯¥è®¢åæ¯å¦ç«ç¹ä»»å¡æ(ç»§ç»è¯éªæè æ¯ç»æè¯éª) List<InsOrderState> orderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery() .eq(InsOrderState::getInsOrderId, samples.get(0).getInsOrderId()) .eq(InsOrderState::getInsState, 5)); List<Integer> orderIds = new ArrayList<Integer>(); orderIds.add(6); if (CollectionUtils.isEmpty(orderStates)) { List<Integer> collect = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery() .eq(InsOrderState::getInsOrderId, samples.get(0).getInsOrderId())).stream().map(InsOrderState::getInsState).distinct().collect(Collectors.toList()); if (collect.size()!=0 && !collect.containsAll(orderIds)) { throw new ErrorException("è¯¥æ ·åçæ£éªä»»å¡è¿æ²¡æç»æè¯éªæç»§ç»è¯éª,ææ¶æ æ³åºåº!"); } } } WarehouseHistory history = new WarehouseHistory(); history.setState(2); history.setInsSampleId(samples.get(0).getId()); inspect-server/src/main/java/com/yuanchu/mom/utils/FuSheUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,443 @@ package com.yuanchu.mom.utils; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.config.Configure; import com.deepoove.poi.config.ConfigureBuilder; import com.deepoove.poi.data.*; import com.deepoove.poi.data.style.*; import com.deepoove.poi.util.TableTools; import com.yuanchu.mom.dto.Exceldata; import com.yuanchu.mom.exception.ErrorException; import com.yuanchu.mom.mapper.InsOrderFileMapper; import com.yuanchu.mom.mapper.InsOrderMapper; import com.yuanchu.mom.pojo.InsOrder; import com.yuanchu.mom.pojo.InsOrderFile; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.openxml4j.util.ZipSecureFile; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xwpf.usermodel.*; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @Component public class FuSheUtils { @Value("${wordUrl}") private String wordUrl; @Resource InsOrderFileMapper insOrderFileMapper; @Resource InsOrderMapper insOrderMapper; public void getFuSheWord(String sonLaboratory, InsOrderFile insOrderFile) { //读åexcelæä»¶å 容 String excelFilePath = wordUrl + "/" + insOrderFile.getFileUrl(); // æ´æ°ä¸ºä½ çæä»¶è·¯å¾ FileInputStream fileInputStream = null; Workbook workbook = null; try { fileInputStream = new FileInputStream(new File(excelFilePath)); workbook = new XSSFWorkbook(fileInputStream); // å¯¹äº .xlsx æä»¶ XWPFDocument document = new XWPFDocument(); Exceldata exceldata = new Exceldata(); Map<Integer, Object> project = new HashMap<>(); HashMap<String, Object> datas1 = new HashMap<>(); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { String s = ""; Sheet sheet = workbook.getSheetAt(i); String sheetName = sheet.getSheetName(); Map<String, Object> map1 = new HashMap<>(); Map<String, Object> datas = new HashMap<>(); List<Map<String, Object>> list = new ArrayList<>(); for (Row row : sheet) { if (row.getRowNum() != 1) { HashMap<String, Object> map = new HashMap<>(); for (Cell cell : row) { if (row.getRowNum() == 0) { switch (cell.getCellType()) { case STRING: project.put(cell.getColumnIndex(), cell.getStringCellValue()); System.out.print(cell.getStringCellValue() + "\t"); break; case NUMERIC: System.out.print(cell.getNumericCellValue() + "\t"); break; case BOOLEAN: System.out.print(cell.getBooleanCellValue() + "\t"); break; case FORMULA: System.out.print(cell.getCellFormula() + "\t"); break; default: System.out.print("NULL\t"); } } else { switch (cell.getCellType()) { case STRING: if (StringUtils.isNotEmpty(s)) { datas.put(s, list); } list = new ArrayList<>(); s = cell.getStringCellValue(); datas.put(s, cell.getStringCellValue()); System.out.print(cell.getStringCellValue() + "\t"); break; case NUMERIC: int columnIndex = cell.getColumnIndex(); Object o = project.get(columnIndex); map.put(o.toString(), cell.getNumericCellValue()); System.out.print(cell.getNumericCellValue() + "\t"); break; case BOOLEAN: System.out.print(cell.getBooleanCellValue() + "\t"); break; case FORMULA: System.out.print(cell.getCellFormula() + "\t"); break; default: System.out.print("NULL\t"); } } if (map.isEmpty()) { list.add(map); } } } } datas.put(s, list); map1.put(sheetName, datas); datas1.putAll(map1); } exceldata.setProject(project); exceldata.setDataRow(datas1); System.out.println(exceldata); HashMap<String, Object> map = new HashMap<>(); for (String s : datas1.keySet()) { Map<String, List<HashMap<String, Object>>> numbers = (Map<String, List<HashMap<String, Object>>>) datas1.get(s); for (String s1 : numbers.keySet()) { List<HashMap<String, Object>> hashMaps = numbers.get(s1); List<Double> floatList = new ArrayList<>(); for (Map<String, Object> number : hashMaps) { number.put("端å£", s1); Double o = (Double) number.get("é¢ç"); floatList.add(o); } Double maxValue = Collections.max(floatList); Double minValue = Collections.min(floatList); if (map.get(minValue + "-" + maxValue + "-" + s) == null) { map.put(minValue + "-" + maxValue + "-" + s, s1); } else { Object o = map.get(minValue + "-" + maxValue + "-" + s); map.put(minValue + "-" + maxValue + "-" + s, s1 + "," + o); } } } System.out.println(map); int size = map.size(); for (String s1 : map.keySet()) { String o = map.get(s1).toString(); List<String> collect = Arrays.stream(o.split(",")).collect(Collectors.toList()); int size1 = -1; for (String s : datas1.keySet()) { Map<String, List<HashMap<String, Object>>> o1 = (Map<String, List<HashMap<String, Object>>>) datas1.get(s); for (String s3 : o1.keySet()) { List<HashMap<String, Object>> numbers = o1.get(s3); for (String s2 : collect) { if (s3.equals(s2)) { if (numbers.size() > size1) { size1 = numbers.size(); } } } map.put(s1, o + "," + size1); } } } System.out.println(map); createWord(sonLaboratory, document, exceldata, map, insOrderFile); } catch (IOException e) { e.printStackTrace(); } finally { // å ³éèµæº try { if (workbook != null) { workbook.close(); } if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } } public void createWord(String sonLaboratory, XWPFDocument document, Exceldata exceldata, HashMap<String, Object> map, InsOrderFile insOrderFile) throws IOException { int size = 1; XWPFParagraph paragraphs = document.createParagraph(); XWPFRun runs = paragraphs.createRun(); runs.setBold(true); // è®¾ç½®ææ¬å ç² runs.setText("è¾å°æ¹åå¾åæ°"); for (String s : map.keySet()) { Map<String, Object> dataRow = exceldata.getDataRow(); String result = s.substring(s.lastIndexOf("-") + 1); String result1 = s.substring(0, s.lastIndexOf("-")); String o = map.get(s).toString(); String[] split = o.split(","); Integer s1 = Integer.parseInt(split[split.length - 1]); Integer i1 = split.length - 1; int row = 3 + s1; int cell = 6 + i1; XWPFTable table1 = document.createTable(2, cell); mergeCellsHorizontally(table1, 1, 0, cell - 1); mergeCellsHorizontally(table1, 0, 4, cell - 2); table1.setInsideHBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å 鍿°´å¹³è¾¹æ¡ table1.setInsideVBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å é¨åç´è¾¹æ¡ table1.setBottomBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // ä¸è¾¹æ¡ table1.setTopBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // ä¸è¾¹æ¡ table1.setLeftBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å·¦è¾¹æ¡ table1.setRightBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å³è¾¹æ¡ XWPFParagraph paragraph12 = table1.getRow(0).getCell(0).getParagraphArray(0); paragraph12.setAlignment(ParagraphAlignment.CENTER); XWPFRun run12 = paragraph12.createRun(); run12.setText("åºå·"); XWPFParagraph paragraph13 = table1.getRow(0).getCell(1).getParagraphArray(0); paragraph13.setAlignment(ParagraphAlignment.CENTER); XWPFRun run13 = paragraph13.createRun(); run13.setText("æ£éªé¡¹ç®"); XWPFParagraph paragraph14 = table1.getRow(0).getCell(2).getParagraphArray(0); paragraph14.setAlignment(ParagraphAlignment.CENTER); XWPFRun run14 = paragraph14.createRun(); run14.setText("åä½"); XWPFParagraph paragraph15 = table1.getRow(0).getCell(3).getParagraphArray(0); paragraph15.setAlignment(ParagraphAlignment.CENTER); XWPFRun run15 = paragraph15.createRun(); run15.setText("æ åè¦æ±"); XWPFParagraph paragraph16 = table1.getRow(0).getCell(cell - 1).getParagraphArray(0); paragraph16.setAlignment(ParagraphAlignment.CENTER); XWPFRun run16 = paragraph16.createRun(); run16.setText("æ£éªç»è®º"); XWPFParagraph paragraph17 = table1.getRow(0).getCell(4).getParagraphArray(0); paragraph17.setAlignment(ParagraphAlignment.CENTER); XWPFRun run17 = paragraph17.createRun(); run17.setText("æ£éªç»æ"); XWPFParagraph paragraph18 = table1.getRow(1).getCell(0).getParagraphArray(0); paragraph18.setAlignment(ParagraphAlignment.CENTER); XWPFRun run18 = paragraph18.createRun(); run18.setText("颿®µï¼ " + result1 + "MHz " + "ä¸å¾è§" + result); List<String> collect = Arrays.stream(split).collect(Collectors.toList()); List<Map<String, Object>> list = new ArrayList<>(); // 对ææçé®èå Map<String, List<Map<String, Object>>> aggregatedMap = new HashMap<>(); Map<String, List<Map<String, Object>>> o1 = (Map<String, List<Map<String, Object>>>) dataRow.get(result); for (String s2 : collect) { if (s2.contains("端å£")) { List<Map<String, Object>> mapList = o1.get(s2); list.addAll(mapList); } } // é忝ä¸ä¸ªé¡¹ç® for (Map<String, Object> item : list) { for (String key : item.keySet()) { // å¦æè¯¥é®å¨ aggregatedMap ä¸ä¸åå¨ï¼åå建ä¸ä¸ªæ°ç List aggregatedMap.putIfAbsent(key, new ArrayList<>()); // å°å½åé¡¹ç®æ·»å å°å¯¹åºé®ç List ä¸ aggregatedMap.get(key).add(item); } } for (String s2 : aggregatedMap.keySet()) { if (s2.equals("端å£") || s2.equals("é¢ç")) { continue; } List<Map<String, Object>> mapList = aggregatedMap.get(s2); // å建ä¸ä¸ªè¡¨æ ¼ XWPFTable table = document.createTable(row, cell); table.setWidth("100%"); //åç´ mergeCellsVertically(table, 0, 0, row - 1); mergeCellsVertically(table, 1, 0, row - 1); mergeCellsVertically(table, 2, 0, row - 1); mergeCellsVertically(table, 3, 0, row - 1); mergeCellsVertically(table, 4, 0, 1); mergeCellsVertically(table, cell - 1, 0, 1); mergeCellsVertically(table, cell - 1, 2, row - 2); //æ°´å¹³ mergeCellsHorizontally(table, 0, 5, cell - 2); mergeCellsHorizontally(table, row - 1, 5, cell - 2); table.setInsideHBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å 鍿°´å¹³è¾¹æ¡ table.setInsideVBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å é¨åç´è¾¹æ¡ table.setBottomBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // ä¸è¾¹æ¡ table.setTopBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // ä¸è¾¹æ¡ table.setLeftBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å·¦è¾¹æ¡ table.setRightBorder(XWPFTable.XWPFBorderType.SINGLE, 2, 0, "000000"); // å³è¾¹æ¡ // 设置åå æ ¼ææ¬å¹¶å± ä¸ XWPFParagraph paragraph = table.getRow(0).getCell(0).getParagraphArray(0); paragraph.setAlignment(ParagraphAlignment.CENTER); XWPFRun run = paragraph.createRun(); run.setText(String.valueOf(size)); XWPFParagraph paragraph1 = table.getRow(0).getCell(1).getParagraphArray(0); paragraph1.setAlignment(ParagraphAlignment.CENTER); XWPFRun run1 = paragraph1.createRun(); run1.setText(s2); // è°ç¨æ¹æ³æå第ä¸ä¸ªæ¬å·å çå 容 String firstContent = extractFirstContentFromBrackets(s2); if (firstContent != null) { XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); paragraph2.setAlignment(ParagraphAlignment.CENTER); XWPFRun run2 = paragraph2.createRun(); run2.setText(firstContent); } else { System.out.println("æ²¡ææ¾å°æ¬å·å çå 容ã"); } XWPFParagraph paragraph3 = table.getRow(0).getCell(3).getParagraphArray(0); paragraph3.setAlignment(ParagraphAlignment.CENTER); XWPFRun run3 = paragraph3.createRun(); run3.setText("/"); XWPFParagraph paragraph4 = table.getRow(0).getCell(4).getParagraphArray(0); paragraph4.setAlignment(ParagraphAlignment.CENTER); XWPFRun run4 = paragraph4.createRun(); run4.setText("é¢çï¼MHzï¼"); XWPFParagraph paragraph5 = table.getRow(0).getCell(5).getParagraphArray(0); paragraph5.setAlignment(ParagraphAlignment.CENTER); XWPFRun run5 = paragraph5.createRun(); run5.setText("端å£"); XWPFParagraph paragraph6 = table.getRow(0).getCell(cell - 1).getParagraphArray(0); paragraph6.setAlignment(ParagraphAlignment.CENTER); XWPFRun run6 = paragraph6.createRun(); run6.setText("/"); XWPFParagraph paragraph7 = table.getRow(1).getCell(cell - 1).getParagraphArray(0); paragraph7.setAlignment(ParagraphAlignment.CENTER); XWPFRun run7 = paragraph7.createRun(); run7.setText("åæ ¼"); XWPFParagraph paragraph8 = table.getRow(row - 1).getCell(4).getParagraphArray(0); paragraph8.setAlignment(ParagraphAlignment.CENTER); XWPFRun run8 = paragraph8.createRun(); run8.setText("å¹³åå¼"); XWPFParagraph paragraph9 = table.getRow(row - 1).getCell(cell - 1).getParagraphArray(0); paragraph9.setAlignment(ParagraphAlignment.CENTER); XWPFRun run9 = paragraph9.createRun(); run9.setText("/"); for (int i = 0; i < collect.size(); i++) { String s3 = collect.get(i); if (s3.contains("端å£")) { XWPFParagraph paragraph10 = table.getRow(1).getCell(5 + i).getParagraphArray(0); paragraph10.setAlignment(ParagraphAlignment.CENTER); XWPFRun run10 = paragraph10.createRun(); run10.setText(s3); } } Map<Double, List<Map<String, Object>>> group = mapList.stream() .collect(Collectors.groupingBy(item -> (Double) item.get("é¢ç"))); group = new TreeMap<>(group); int hang = 2; Double count = 0.0; for (Double aDouble : group.keySet()) { List<Map<String, Object>> mapList1 = group.get(aDouble); for (Map<String, Object> stringObjectMap : mapList1) { String port = stringObjectMap.get("端å£").toString(); for (int i = 5; i < cell - 1; i++) { String text = table.getRow(1).getCell(i).getText(); if (text.equals(port)) { XWPFParagraph paragraph10 = table.getRow(hang).getCell(i).getParagraphArray(0); paragraph10.setAlignment(ParagraphAlignment.CENTER); XWPFRun run10 = paragraph10.createRun(); count = (Double) stringObjectMap.get(s2) + count; String project = stringObjectMap.get(s2).toString(); run10.setText(project); } } } XWPFParagraph paragraph10 = table.getRow(hang).getCell(4).getParagraphArray(0); paragraph10.setAlignment(ParagraphAlignment.CENTER); XWPFRun run10 = paragraph10.createRun(); run10.setText(String.valueOf(aDouble)); hang++; } XWPFParagraph paragraph11 = table.getRow(row - 1).getCell(5).getParagraphArray(0); paragraph11.setAlignment(ParagraphAlignment.CENTER); XWPFRun run11 = paragraph11.createRun(); double v = count / (Double.parseDouble(s1.toString()) * Double.parseDouble(i1.toString())); run11.setText(String.format("%.2f",v)); size++; } } // è¾åºå°æä»¶ try { InsOrder insOrder = insOrderMapper.selectById(insOrderFile.getInsOrderId()); String[] split = insOrderFile.getFileName().split("\\."); String name = insOrderFile.getFileName().substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length())); FileOutputStream out = new FileOutputStream(wordUrl + "/" + insOrder.getEntrustCode() + "&" + sonLaboratory + name + "è§£æçè¾å°ç«ç¹æ¥å.docx"); document.write(out); out.close(); document.close(); InsOrderFile orderFile = new InsOrderFile(); orderFile.setInsOrderId(insOrderFile.getInsOrderId()); orderFile.setFileUrl(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "è§£æçè¾å°ç«ç¹æ¥å.docx"); orderFile.setType(2); orderFile.setFileName(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "è§£æçè¾å°ç«ç¹æ¥å.docx"); orderFile.setSonLaboratory(sonLaboratory); insOrderFileMapper.insert(orderFile); } catch (IOException e) { e.printStackTrace(); } } // æ°´å¹³åå¹¶åå æ ¼ private static void mergeCellsHorizontally(XWPFTable table, int row, int fromCol, int toCol) { for (int i = fromCol; i <= toCol; i++) { if (i == fromCol) { table.getRow(row).getCell(i).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); } else { table.getRow(row).getCell(i).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); } } } // åç´åå¹¶åå æ ¼ private static void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) { for (int i = fromRow; i <= toRow; i++) { if (i == fromRow) { table.getRow(i).getCell(col).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); } else { table.getRow(i).getCell(col).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); } } } // æå第ä¸ä¸ªæ¬å·å çå 容 public static String extractFirstContentFromBrackets(String str) { // å®ä¹æ£å表达å¼ï¼å¹é æ¬å·å çå 容ï¼åæ¶æ¯æä¸æåè±ææ¬å· Pattern pattern = Pattern.compile("\\ï¼(.*?)\\ï¼|\\((.*?)\\)"); Matcher matcher = pattern.matcher(str); // æ¥æ¾ç¬¬ä¸ä¸ªå¹é çå 容 if (matcher.find()) { // è·åæ¬å·å çå 容ï¼å¤ææ¯ä¸ææ¬å·è¿æ¯è±ææ¬å· return matcher.group(1) != null ? matcher.group(1) : matcher.group(2); } return null; // å¦ææ²¡ææ¾å°å¹é 项ï¼åè¿ånull } } inspect-server/src/main/java/com/yuanchu/mom/utils/WordUtils.java
@@ -144,7 +144,8 @@ if (inspectionItemSubclass.contains("äºè°")) { aa += (angles + 1) * portRow * often; } } else { } else { if (inspectionItemSubclass.contains("çµå驻波æ¯")) { aa += (angles + 1) * portRow; } @@ -232,7 +233,8 @@ paragraphRenderDataList.add(paragraphRenderData); cellRenderData.setParagraphs(paragraphRenderDataList); cells.add(cellRenderData); } else { } else { if (insOrderState.getVersion() == 1) { //éçµè°çæ¬(ç®åç) if (inspectionItemSubclass.contains("çµå驻波æ¯") && i <= 2 * portRow) { @@ -1597,6 +1599,7 @@ insOrderFile.setFileName(name); insOrderFile.setType(2); insOrderFile.setFileUrl(name); insOrderFile.setSonLaboratory("çµè·¯è¯éª"); insOrderFileMapper.insert(insOrderFile); } @@ -1648,7 +1651,7 @@ .eq(InsProduct::getInsResult, 1)); productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + "")); //å°é¡¹ç®æç §ç«ç¹è¿è¡åç±» Map<String, List<InsProduct>> listMap = s.getInsProduct().stream().collect(Collectors.groupingBy(InsProduct::getLaboratory)); Map<String, List<InsProduct>> listMap = s.getInsProduct().stream().collect(Collectors.groupingBy(InsProduct::getSonLaboratory)); // å建ä¸ä¸ª Map å°ç«ç¹å项ç®IDçæ å°å ³ç³» Map<String, Set<Integer>> labToDeviceMap = new HashMap<>(); // è·åææç«ç¹ç项ç®ID å表 @@ -1874,6 +1877,121 @@ } } } else { //å¦æåªæç¯å¢è¯éªæ²¡æçµè·¯è¯éª strings.remove("è¿åº"); strings.remove("è¿åº"); if (strings.size() > 0) { Map<String, String> table2 = new HashMap<>(); table2.put("indexs", "ç¯å¢è¯éª:" + String.join("ã", strings) + "â1"); table2.put("term", "ç¯å¢è¯éª:" + String.join("ã", strings) + "â1"); table2.put("result", "ç¯å¢è¯éª:" + String.join("ã", strings) + "â1"); tables.add(table2); /*å建ç¯å¢è¯éªæ¡ä»¶è¡¨2*(é¡¹ç®æ°+1)*/ List<InsProduct> products = samples.stream().flatMap(sampleProductDto -> sampleProductDto.getInsProduct().stream() .filter(insProduct -> !insProduct.getInspectionItem().equals("çµè·¯è¯éª")) .filter(insProduct -> !insProduct.getInspectionItem().equals("è¾å°è¯éª"))) .map(insProduct -> { InsProduct product = new InsProduct(); product.setInspectionItemSubclass(insProduct.getInspectionItemSubclass()); product.setTell(insProduct.getTell()); return product; }).distinct().collect(Collectors.toList()); List<RowRenderData> rows = new ArrayList<>(); //è¡æ° for (int i = 0; i < products.size() + 1; i++) { RowRenderData rowRenderData = new RowRenderData(); RowStyle rowStyle = new RowStyle(); rowStyle.setHeight(40); rowRenderData.setRowStyle(rowStyle); List<CellRenderData> cells = new ArrayList<>(); //åæ° for (int j = 0; j < 2; j++) { CellRenderData cellRenderData = new CellRenderData(); CellStyle cellStyle = new CellStyle(); cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER); cellRenderData.setCellStyle(cellStyle); List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); ParagraphStyle paragraphStyle = new ParagraphStyle(); paragraphStyle.setAlign(ParagraphAlignment.CENTER); paragraphRenderData.setParagraphStyle(paragraphStyle); List<RenderData> renderData = new ArrayList<>(); TextRenderData textRenderData = new TextRenderData(); Style style = new Style(); style.setFontFamily("å®ä½"); style.setColor("000000"); textRenderData.setStyle(style); if (i == 0) { //第ä¸è¡ if (j == 0) { //第ä¸å textRenderData.setText("项ç®"); renderData.add(textRenderData); paragraphRenderData.setContents(renderData); paragraphRenderDataList.add(paragraphRenderData); cellRenderData.setParagraphs(paragraphRenderDataList); cells.add(cellRenderData); } else { //第äºå textRenderData.setText("è¯éªè¦æ±"); renderData.add(textRenderData); paragraphRenderData.setContents(renderData); paragraphRenderDataList.add(paragraphRenderData); cellRenderData.setParagraphs(paragraphRenderDataList); cells.add(cellRenderData); } } else { //å ¶ä½è¡ if (j == 0) { //第ä¸å textRenderData.setText(products.get(i - 1).getInspectionItemSubclass()); renderData.add(textRenderData); paragraphRenderData.setContents(renderData); paragraphRenderDataList.add(paragraphRenderData); cellRenderData.setParagraphs(paragraphRenderDataList); cells.add(cellRenderData); } else { textRenderData.setText(products.get(i - 1).getTell()); renderData.add(textRenderData); paragraphRenderData.setContents(renderData); paragraphRenderDataList.add(paragraphRenderData); cellRenderData.setParagraphs(paragraphRenderDataList); cells.add(cellRenderData); } } } rowRenderData.setCells(cells); if (rowRenderData.getCells().size() != 0) { rows.add(rowRenderData); } } TableRenderData tableRenderData = new TableRenderData(); tableRenderData.setRows(rows); int countSize = tableRenderData.getRows().get(0).getCells().size(); for (RowRenderData row : tableRenderData.getRows()) { if (row.getCells().size() != countSize) { throw new ErrorException("æ¯è¡åå æ ¼ä¸ç¸ç"); } } TableStyle tableStyle = new TableStyle(); tableStyle.setWidth(XWPFTable.DEFAULT_PERCENTAGE_WIDTH); tableStyle.setAlign(TableRowAlign.CENTER); BorderStyle borderStyle = new BorderStyle(); borderStyle.setColor("000000"); borderStyle.setType(XWPFTable.XWPFBorderType.THICK); borderStyle.setSize(4); tableStyle.setLeftBorder(borderStyle); tableStyle.setTopBorder(borderStyle); tableStyle.setRightBorder(borderStyle); tableStyle.setBottomBorder(borderStyle); tableRenderData.setTableStyle(tableStyle); Map<String, Object> table4 = new HashMap<>(); table4.put("table4", tableRenderData); tables4.add(table4); } } String url; try { inspect-server/src/main/resources/mapper/InsOrderFileMapper.xml
@@ -12,13 +12,19 @@ <result column="create_time" property="createTime"/> <result column="update_user" property="updateUser"/> <result column="update_time" property="updateTime"/> <result column="son_laboratory" property="sonLaboratory"/> </resultMap> <select id="getFileList" resultType="com.yuanchu.mom.pojo.InsOrderFile"> select A.* from (select iof.*, name from ins_order_file iof left join user u on iof.create_user = u.id where ins_order_id=#{insOrderId}) A where ins_order_id=#{insOrderId} <if test="sonLaboratory!=null and sonLaboratory!=''"> and son_laboratory=#{sonLaboratory} or son_laboratory is null </if> ) A <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''"> ${ew.customSqlSegment} </if> inspect-server/src/main/resources/mapper/InsOrderMapper.xml
@@ -158,7 +158,7 @@ A.company, A.`name`, COUNT(1) num, SUM(A.price) price ROUND(SUM(A.price),2) price FROM (SELECT i.id, i.entrust_code, i.create_time, @@ -349,63 +349,56 @@ A.inspection_item, A.company, A.`name`, production, engineering, COUNT(1) num, SUM(A.price) price, SUM(A.cost) cost FROM (SELECT i.id, ROUND(SUM(A.price),2) price FROM (SELECT i.id, i.entrust_code, i.create_time, isa.sample, isa.sample_code, isa.model, c.price, c.cost, c.inspection_item, ins_sample_id, sum(c.price * times) price, GROUP_CONCAT(distinct c.inspection_item SEPARATOR ',') inspection_item, i.company, u.`name`, i.create_user, c.ins_sample_id, production, engineering FROM ins_order i u.`name` FROM ins_order i LEFT JOIN ins_sample isa ON isa.ins_order_id = i.id LEFT JOIN `user` u ON u.id = i.user_id left join custom cus on cus.id = u.company LEFT JOIN (select SUM(b.price) price, sum(b.man_hour) cost,b.ins_sample_id, GROUP_CONCAT(b.inspection_item2 SEPARATOR ',') inspection_item from (select * , GROUP_CONCAT(CONCAT(inspection_item,'@',inspection_item_subclass) SEPARATOR ',')inspection_item2 from ins_product where state = 1 and ins_result is not null and ins_result!=2 and template_id IS NOT NULL GROUP BY ins_sample_id,man_hour_group) b GROUP BY b.ins_sample_id) c ON c.ins_sample_id = isa.id where (<!--i.state = 1 or i.state = 3 or -->i.state = 4) and c.ins_sample_id IS not NULL)A GROUP BY A.id, LEFT JOIN (select ip.ins_sample_id, ip.inspection_item, ip.inspection_item_subclass, ip.price, sum(aowh.output_work_time) times from ins_product ip left join auxiliary_output_working_hours aowh on ip.id = aowh.ins_product_id where state = 1 and ins_result is not null and ins_result != 2 and template_id IS NOT NULL group by ip.ins_sample_id, ip.inspection_item, ip.inspection_item_subclass, ip.price) c ON c.ins_sample_id = isa.id where (i.state = 4) and c.ins_sample_id IS not NULL group by i.id, i.entrust_code, i.create_time, isa.sample, isa.model, i.company, ins_sample_id, u.`name`) A GROUP BY A.id, A.entrust_code, A.create_time, A.sample, A.model, A.inspection_item, A.company, A.`name`, production, engineering ORDER BY A.id, A.entrust_code, A.create_time, A.sample, A.model, A.inspection_item, A.company, A.`name`, production, engineering) B A.`name` ) B <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''"> ${ew.customSqlSegment} </if> inspect-server/src/main/resources/mapper/WarehouseCellMapper.xml
@@ -17,11 +17,12 @@ </resultMap> <select id="getWarehouse" resultMap="WarehouseCellAndHistoryDto"> select wc.id, wc.row, wc.col, i.id sampleId, i.sample, i.model, i.sample_code from warehouse_cell wc select wc.id, wc.row, wc.col, i.id sampleId, i.sample, i.model, i.sample_code from warehouse_cell wc left join ins_sample i on i.cell_id = wc.id where wc.state = 1 and wc.shelf_id = #{shelfId} order by wc.id order by wc.row ,wc.col, wc.id </select> <resultMap id="WarehouseCellAndHistoryDto" type="com.yuanchu.mom.dto.WarehouseCellAndSampleDto">