From d0e1a3fb24d0ee76aa4ef1b0e042392b4d3ac794 Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期四, 07 十一月 2024 16:38:26 +0800
Subject: [PATCH] 预计参数多层次分级,新增型号增加namePath

---
 modules/mainPart/src/main/java/com/zt/life/modules/mainPart/basicInfo/service/XhProductModelService.java |   95 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 69 insertions(+), 26 deletions(-)

diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/basicInfo/service/XhProductModelService.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/basicInfo/service/XhProductModelService.java
index f9a0192..946c469 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/basicInfo/service/XhProductModelService.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/basicInfo/service/XhProductModelService.java
@@ -70,7 +70,7 @@
     }
 
     public List<XhProductModel> getAllTree(Boolean showXdy, Integer ztShow, Long productId) {
-        List<XhProductModel> productList = null;
+        List<XhProductModel> productList = new ArrayList<>();
         if (showXdy) {
             if (productId != null) {
                 productList = baseDao.selectList(new QueryWrapper<XhProductModel>().eq(Constant.TableColumn.IS_DELETE,
@@ -102,8 +102,28 @@
                     productList = baseDao.selectList(new QueryWrapper<XhProductModel>().eq(Constant.TableColumn.IS_DELETE,
                             Constant.Bool.NO).lt("product_type", 5).ne("product_type", 1).and(wrapper -> wrapper.eq("ship_id", productId).or().eq("id", productId)).orderByAsc(Constant.TableColumn.SORT));
                 } else if (ztShow == 5) {
-                    productList = baseDao.selectList(new QueryWrapper<XhProductModel>().eq(Constant.TableColumn.IS_DELETE,
-                            Constant.Bool.NO).gt("product_type", 1).and(wrapper -> wrapper.eq("ship_id", productId).or().eq("id", productId)).orderByAsc(Constant.TableColumn.SORT));
+                    List<XhProductModel> dbList = baseDao.getProductListByShip(productId,2,5);
+                    for (XhProductModel row : dbList) {
+                        if (row.getSameSbNum()!=null && row.getSameSbNum() > 1) {
+                            for (int i = 1; i <= row.getSameSbNum(); i++) {
+                                try {
+                                    XhProductModel newRow = row.clone();
+                                    newRow.setDeviceNo(i);
+                                    newRow.setName(row.getName() + "-" + i);
+                                    newRow.setDataId(row.getId().toString() + "-" + i);
+                                    productList.add(newRow);
+                                } catch (CloneNotSupportedException e) {
+                                    e.printStackTrace();
+                                }
+                            }
+                        } else {
+                            row.setDeviceNo(0);
+                            row.setDataId(row.getId().toString());
+                            productList.add(row);
+                        }
+                    }
+                    productList.sort(Comparator.comparing(XhProductModel::getSort, Comparator.naturalOrder())
+                            .thenComparing(XhProductModel::getDeviceNo, Comparator.naturalOrder()));
                 }
             }
         }
@@ -117,8 +137,8 @@
         return baseDao.getNo(pid, productType);
     }
 
-    public List<XhProductModel> getProductList() {
-        List<XhProductModel> ProductList = baseDao.getProductList();
+    public List<XhProductModel> getProductList(Long shipId, Integer type) {
+        List<XhProductModel> ProductList = baseDao.getProductList(shipId,type);
         return TreeUtils.build(ProductList);
     }
 
@@ -304,6 +324,7 @@
                         ParamData itemEntity = new ParamData();
                         itemEntity.setShipId(shipId);
                         itemEntity.setProductId(curXtId);
+                        itemEntity.setBasicUnitNum(1);
                         paramDataService.insert(itemEntity);
                     }
 
@@ -323,13 +344,14 @@
                         ParamData itemEntity = new ParamData();
                         itemEntity.setShipId(shipId);
                         itemEntity.setProductId(curFxtId);
+                        itemEntity.setBasicUnitNum(1);
                         paramDataService.insert(itemEntity);
                     }
 
                     xhProductModel.setPid(curFxtId == null ? curXtId : curFxtId);
                     xhProductModel.setId(curSbId);
                     xhProductModel.setName(sb);
-                    //xhProductModel.setSameSbName(sameSbName);
+                    xhProductModel.setSameSbNum(sameSbNum);
                     xhProductModel.setEquipType(equipType);
                     xhProductModel.setProductType("5");
                     xhProductModel.setSort(Integer.valueOf(sort));
@@ -347,9 +369,9 @@
                     //缁戝畾璁惧ID
                     itemEntity.setShipId(shipId);
                     itemEntity.setProductId(curSbId);
+                    itemEntity.setBasicUnitNum(sameSbNum);
                     itemEntity.setReliabDistribType(reliabType.get(reliabDistribType));
                     itemEntity.setBasicJoinCompute(isOrNot.get(basicJoinCompute));
-                    itemEntity.setBasicUnitNum(sameSbNum);
                     itemEntity.setBasicMtbfRegulate(basicMtbfRegulate);
                     itemEntity.setBasicMtbfRegulSuccRate(basicMtbfRegulSuccRate);
                     itemEntity.setBasicMtbfOperatingRatio(basicMtbfOperatingRatio);
@@ -423,29 +445,43 @@
         List<ProductDto> data = baseDao.getProductByShip(shipId);
         data = TreeUtils.build(data);
         List<ProductDto> List = new ArrayList<>();
-        this.writeExcel(data, List);
+        this.writeList(data, List);
         // 璇诲彇妯℃澘鏂囦欢
         try (InputStream inputStream = getClass().getResourceAsStream("/浜у搧缁撴瀯鏍戝鍑烘ā鏉�.xlsx")) {
             Workbook workbook = new XSSFWorkbook(inputStream);
             // 鑾峰彇绗竴涓伐浣滆〃
             Sheet sheet = workbook.getSheetAt(0);
+            List.sort((o1, o2) -> {
+                String[] parentList1 = o1.getNamePath().split(",");
+                String[] parentList2 = o2.getNamePath().split(",");
+                String xt1 = parentList1.length > 0 ? parentList1[0] : "";
+                String xt2 = parentList2.length > 0 ? parentList2[0] : "";
+
+                // 棣栧厛姣旇緝xt鍊�
+                int xtCompare = xt1.compareTo(xt2);
+                if (xtCompare != 0) {
+                    return xtCompare;
+                }
+
+                // 濡傛灉xt鐩稿悓锛屾瘮杈僷arentList鐨勯暱搴︼紝纭繚parentList.length = 2鐨勬暟鎹帓鍦ㄥ墠闈�
+                return Integer.compare(parentList1.length, parentList2.length);
+            });
             int num = 0;
             String xt = "";
             String fxt = "";
             String sb = "";
             for (int i = 0; i < List.size(); i++) {
-                if (List.get(i).getProductType() == 5) {
                     num = num + 1;
                     String[] parentList = List.get(i).getNamePath().split(",");
                     Row row = sheet.createRow(sheet.getLastRowNum() + 1); // 鍒涘缓鏂拌
                     Cell cell = row.createCell(0);
                     cell.setCellValue(num);
+                if (!xt.equals(parentList[0])) {
+                    xt = parentList[0];
+                    cell = row.createCell(1);
+                    cell.setCellValue(xt);
+                }
                     if (parentList.length > 2) {
-                        if (!xt.equals(parentList[0])) {
-                            xt = parentList[0];
-                            cell = row.createCell(1);
-                            cell.setCellValue(xt);
-                        }
                         if (!fxt.equals(parentList[1])) {
                             fxt = parentList[1];
                             cell = row.createCell(2);
@@ -457,12 +493,6 @@
                             cell.setCellValue(sb);
                         }
                     } else {
-                        if (!xt.equals(parentList[0])) {
-                            xt = parentList[0];
-                            cell = row.createCell(1);
-                            cell.setCellValue(xt);
-                        }
-
                         if (!sb.equals(parentList[1])) {
                             sb = parentList[1];
                             cell = row.createCell(3);
@@ -470,9 +500,8 @@
                         }
                     }
                     cell = row.createCell(4);
-                    if (StringUtils.isNotBlank(List.get(i).getSameSbName())) {
-                        cell.setCellValue(List.get(i).getSameSbName());
-                    }
+                    cell.setCellValue(List.get(i).getSameSbNum());
+
                     cell = row.createCell(5);
                     if (StringUtils.isNotBlank(List.get(i).getEquipType())) {
                         cell.setCellValue(List.get(i).getEquipType());
@@ -542,7 +571,6 @@
                         cell.setCellValue(List.get(i).getRepairMttcrOtherParams3());
                     }
                 }
-            }
             response.setContentType("application/octet-stream;charset=UTF-8");
             String encodedFilename = DownloadService.getNameEncoder(request, name + "_浜у搧缁撴瀯鏍�.xlsx");
             response.addHeader("Content-Disposition", "attachment;filename=" + encodedFilename);
@@ -555,10 +583,25 @@
 
     }
 
-    private void writeExcel(List<ProductDto> data, List<ProductDto> List) {
+    private void writeList(List<ProductDto> data, List<ProductDto> List) {
         for (ProductDto dto : data) {
             List.add(dto);
-            writeExcel(dto.getChildren(), List);
+            writeList(dto.getChildren(), List);
         }
     }
+    public void refreshCache() {
+        List<XhProductModel> productList = baseDao.getProductListAll();
+        Map<Long, XhProductModel> imgMap = new HashMap<>();
+        for (XhProductModel product : productList) {
+            imgMap.put(product.getId(), product);
+        }
+        CacheUtils.put("sysImgCache", "sysImgCache", imgMap);
+    }
+
+    public void getImg(HttpServletResponse response, Long id) {
+        Map<Long, XhProductModel> imgMap = new HashMap<>();
+        imgMap = (Map<Long, XhProductModel>) CacheUtils.get("sysImgCache","sysImgCache");
+        XhProductModel product = imgMap.get(id);
+        sysPictureBaseService.getSvgImage(response,product.getOperatImg());
+    }
 }

--
Gitblit v1.9.1