From c2ff8c71c67eb76ef23ad21acb53401ea978c282 Mon Sep 17 00:00:00 2001
From: Crunchy <3114200645@qq.com>
Date: 星期二, 23 七月 2024 17:24:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 cnas-server/src/main/java/com/yuanchu/mom/controller/CapacityScopeController.java |  261 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 254 insertions(+), 7 deletions(-)

diff --git a/cnas-server/src/main/java/com/yuanchu/mom/controller/CapacityScopeController.java b/cnas-server/src/main/java/com/yuanchu/mom/controller/CapacityScopeController.java
index 0bcb4ac..1e72fb4 100644
--- a/cnas-server/src/main/java/com/yuanchu/mom/controller/CapacityScopeController.java
+++ b/cnas-server/src/main/java/com/yuanchu/mom/controller/CapacityScopeController.java
@@ -2,12 +2,15 @@
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.poi.excel.ExcelUtil;
+import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.util.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.yuanchu.mom.annotation.ValueAuth;
 import com.yuanchu.mom.annotation.ValueClassify;
 import com.yuanchu.mom.dto.PageTestObjectDto;
+import com.yuanchu.mom.excel.StructureTestObjectData;
+import com.yuanchu.mom.excel.StructureTestObjectListener;
 import com.yuanchu.mom.exception.ErrorException;
 import com.yuanchu.mom.pojo.*;
 import com.yuanchu.mom.service.*;
@@ -22,8 +25,8 @@
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.io.InputStream;
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -172,11 +175,11 @@
         InputStream inputStream = file.getInputStream();
         List<StructureItemParameter> lists = new ArrayList<>();
         AtomicReference<String> sample = new AtomicReference<>();
-        ExcelUtil.readBySax(inputStream, 0, (i, l, list1) -> {
-            if (i == 0 && l == 1) {
+        ExcelUtil.readBySax(inputStream, -1, (i, l, list1) -> {
+            if (l == 1) {
                 sample.set(list1.get(1) + "");
             }
-            if (i == 0 && l >= 1) {
+            if (l >= 1) {
                 StructureItemParameter str = new StructureItemParameter();
                 if (list1.get(1) == null) {
                     str.setSample(null);
@@ -223,6 +226,7 @@
                         db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class)
                                 .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem())
                                 .eq(StructureItemParameter::getSample, str.getSample())
+                                .last("limit 1")
                         );
                     } catch (Exception e) {
                         throw new ErrorException("閲嶅鏌ヨ锛�" + str.getInspectionItem());
@@ -233,6 +237,7 @@
                                 .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem())
                                 .eq(StructureItemParameter::getSample, str.getSample())
                                 .eq(StructureItemParameter::getInspectionItemSubclass, str.getInspectionItemSubclass())
+                                .last("limit 1")
                         );
                     } catch (Exception e) {
                         throw new ErrorException("閲嶅鏌ヨ锛�" + str.getInspectionItem() + " " + str.getInspectionItemSubclass());
@@ -282,7 +287,7 @@
                 if (list1.get(13) == null) {
                     str.setPrice(null);
                 } else {
-                    str.setPrice(BigDecimal.valueOf(Long.parseLong((list1.get(13).toString()))));
+                    str.setPrice(list1.get(13) + "");
                 }
 
                 if (list1.get(14) == null) {
@@ -334,17 +339,259 @@
                 } else {
                     str.setTemplateId(null);
                 }
+                try {
+                    if (list1.get(22) != null && list1.get(22) != "") {
+                        str.setInspectionItemClass(list1.get(22) + "");
+                    } else {
+                        str.setInspectionItemClass(null);
+                    }
+                } catch (Exception e) {
+                }
+                try {
+                    if (list1.get(23) != null && list1.get(23) != "") {
+                        str.setInspectionItemClassEn(list1.get(23) + "");
+                    } else {
+                        str.setInspectionItemClassEn(null);
+                    }
+                } catch (Exception e) {
+                }
+                try {
+                    if (list1.get(24) != null) {
+                        str.setLaboratory(list1.get(24) + "");
+                    }
+                } catch (Exception e) {
+                }
                 lists.add(str);
             }
         });
         structureItemParameterService.removeNoSample(sample.get());
         // 濡傛灉鏁版嵁搴撻噷闈㈢殑鏁版嵁瀛樺湪閭d箞灏辨墽琛屾洿鏂版嫹璐濇搷浣�
         try {
-            structureItemParameterService.saveBatch(lists);
+            structureItemParameterService.saveOrUpdateBatch(lists);
         } catch (Exception e) {
             e.printStackTrace();
             throw new RuntimeException("鏈嶅姟绔姤閿欏暒!!!");
         }
         return Result.success();
     }
-}
\ No newline at end of file
+
+    @ValueClassify(value = "鑳藉姏鑼冨洿")
+    @ApiOperation(value = "瑁呭瀵煎叆妫�楠岄」鐩�")
+    @PostMapping("/importEquipData")
+    @Transactional
+    public Result importEquipData(@RequestParam("file") MultipartFile file) throws Exception {
+        InputStream inputStream = file.getInputStream();
+        List<StructureItemParameter> lists = new ArrayList<>();
+        AtomicReference<String> sample = new AtomicReference<>();
+        ExcelUtil.readBySax(inputStream, -1, (i, l, list1) -> {
+            if (l == 1) {
+                sample.set(list1.get(1) + "");
+            }
+            if (l >= 1) {
+                StructureItemParameter str = new StructureItemParameter();
+                if (list1.get(1) == null) {
+                    str.setSample(null);
+                } else {
+                    String brand = (String) list1.get(1);
+                    StringBuilder builder = new StringBuilder();
+                    builder.append("[");
+                    if (ObjectUtil.isNotEmpty(list1.get(2))) {
+                        String production = (String) list1.get(2);
+                        if (!production.contains("锛�")) {
+                            builder.append(String.format("[\"%s\",\"%s\"]", brand, production));
+                        } else {
+                            Arrays.stream(production.split("锛�")).forEach(item -> {
+                                builder.append(String.format("[\"%s\",\"%s\"],", brand, item));
+                            });
+                            builder.deleteCharAt(builder.length() - 1);
+                        }
+                    } else {
+                        builder.append("[");
+                        builder.append(String.format("\"%s\"", brand));
+                        builder.append("]");
+                    }
+                    builder.append("]");
+                    str.setSample(builder.toString());
+                }
+                str.setInspectionItem(list1.get(4).toString());
+                if (list1.get(5) != null) {
+                    str.setInspectionItemEn(list1.get(5).toString());
+                }
+                if (list1.get(6) == null) {
+                    str.setInspectionItemSubclass(null);
+                } else {
+                    str.setInspectionItemSubclass(list1.get(6).toString());
+                }
+                if (list1.get(7) == null) {
+                    str.setInspectionItemSubclassEn(null);
+                } else {
+                    str.setInspectionItemSubclassEn(String.valueOf(list1.get(7).toString()));
+                }
+                StructureItemParameter db_str;
+                if (StringUtils.isEmpty(str.getInspectionItemSubclass())) {
+                    // 姣旇緝涓や釜鏉′欢
+                    try {
+                        db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class)
+                                .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem())
+                                .eq(StructureItemParameter::getSample, str.getSample())
+                                .last("limit 1")
+                        );
+                    } catch (Exception e) {
+                        throw new ErrorException("閲嶅鏌ヨ锛�" + str.getInspectionItem());
+                    }
+                } else {
+                    try {
+                        db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class)
+                                .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem())
+                                .eq(StructureItemParameter::getSample, str.getSample())
+                                .eq(StructureItemParameter::getInspectionItemSubclass, str.getInspectionItemSubclass())
+                                .last("limit 1")
+                        );
+                    } catch (Exception e) {
+                        throw new ErrorException("閲嶅鏌ヨ锛�" + str.getInspectionItem() + " " + str.getInspectionItemSubclass());
+                    }
+                }
+                if (ObjectUtils.isNotEmpty(db_str)) {
+                    str.setId(db_str.getId());
+                }
+                if (list1.get(8) == null) {
+                    str.setMethod(null);
+                } else {
+                    StringBuffer buffer = new StringBuffer();
+                    String input = list1.get(8).toString();
+                    buffer.append("[");
+                    String[] values = input.split("锛�");
+                    for (String value : values) {
+                        buffer.append("\"").append(value.trim()).append("\",");
+                    }
+                    buffer.deleteCharAt(buffer.length() - 1);
+                    buffer.append("]");
+                    str.setMethod(buffer.toString());
+                }
+
+                if (list1.get(9) == null) {
+                    str.setSonLaboratory(null);
+                } else {
+                    str.setSonLaboratory(list1.get(9).toString());
+                }
+                if (list1.get(10) == null) {
+                    str.setUnit(null);
+                } else {
+                    str.setUnit(list1.get(10).toString());
+                }
+
+                if (list1.get(11) == null) {
+                    str.setAskTell(null);
+                } else {
+                    str.setAskTell(list1.get(11).toString());
+                }
+
+                if (list1.get(12) == null) {
+                    str.setAsk(null);
+                } else {
+                    str.setAsk(list1.get(12).toString());
+                }
+
+                if (list1.get(13) == null) {
+                    str.setPrice(null);
+                } else {
+                    str.setPrice(list1.get(13) + "");
+                }
+
+                if (list1.get(14) == null) {
+                    str.setManHour(null);
+                } else {
+                    str.setManHour(Double.valueOf(list1.get(14).toString()));
+                }
+
+                if (list1.get(15) == null) {
+                    str.setManHourGroup(null);
+                } else {
+                    str.setManHourGroup(list1.get(15).toString());
+                }
+
+                if (list1.get(16) == null) {
+                    str.setManDay(null);
+                } else {
+                    str.setManDay(Integer.valueOf(list1.get(16).toString()));
+                }
+                String jy;
+                if (list1.get(17).toString().equals("闈為噰闆嗙被鍨�")) {
+                    jy = "0";
+                } else {
+                    jy = "1";
+                }
+                str.setInspectionItemType(jy);
+                String validateValueType = list1.get(18).toString();
+                if (StringUtils.isNotBlank(validateValueType)) {
+                    Enums enums = enumService.getOne(Wrappers.lambdaQuery(Enums.class)
+                            .eq(Enums::getCategory, "妫�楠屽�肩被鍨�")
+                            .eq(Enums::getLabel, validateValueType));
+                    str.setInspectionValueType(enums.getValue());
+                }
+                int bsm;
+                if (list1.get(19).toString().equals("鍚�")) {
+                    bsm = 0;
+                } else {
+                    bsm = 1;
+                }
+                str.setBsm(bsm + "");
+                if (list1.get(20) != null) {
+                    str.setDic(list1.get(20) + "");
+                } else {
+                    str.setDic(null);
+                }
+                StandardTemplate standTempIdByName = standardTemplateService.getStandTempIdByName(String.valueOf(list1.get(21)));
+                if (standTempIdByName != null) {
+                    str.setTemplateId(standTempIdByName.getId());
+                } else {
+                    str.setTemplateId(null);
+                }
+                try {
+                    if (list1.get(22) != null && list1.get(22) != "") {
+                        str.setInspectionItemClass(list1.get(22) + "");
+                    } else {
+                        str.setInspectionItemClass(null);
+                    }
+                } catch (Exception e) {
+                }
+                try {
+                    if (list1.get(23) != null && list1.get(23) != "") {
+                        str.setInspectionItemClassEn(list1.get(23) + "");
+                    } else {
+                        str.setInspectionItemClassEn(null);
+                    }
+                } catch (Exception e) {
+                }
+                try {
+                    if (list1.get(24) != null) {
+                        str.setLaboratory(list1.get(24) + "");
+                    }
+                } catch (Exception e) {
+                }
+                lists.add(str);
+            }
+        });
+        structureItemParameterService.removeNoSample(sample.get());
+        // 濡傛灉鏁版嵁搴撻噷闈㈢殑鏁版嵁瀛樺湪閭d箞灏辨墽琛屾洿鏂版嫹璐濇搷浣�
+        try {
+            structureItemParameterService.saveOrUpdateBatch(lists);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("鏈嶅姟绔姤閿欏暒!!!");
+        }
+        return Result.success();
+    }
+
+    @ValueClassify(value = "鑳藉姏鑼冨洿")
+    @ApiOperation(value = "瀵煎叆妫�楠屽璞�")
+    @PostMapping("/importExcel")
+    public Result importExcel(@RequestParam("file") MultipartFile file) {
+        try {
+            EasyExcel.read(file.getInputStream(), StructureTestObjectData.class, new StructureTestObjectListener(productService)).sheet().doRead();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return Result.success();
+    }
+}

--
Gitblit v1.9.3