From bb79df40aa4c1c80f294f2d1965304a3215744cb Mon Sep 17 00:00:00 2001
From: Fixiaobai <fixiaobai@163.com>
Date: 星期四, 31 八月 2023 17:24:50 +0800
Subject: [PATCH] 修改委托信息

---
 inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java |  227 +++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 172 insertions(+), 55 deletions(-)

diff --git a/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java b/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java
index c285546..37cfb30 100644
--- a/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java
+++ b/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java
@@ -1,9 +1,11 @@
 package com.yuanchu.limslaboratory.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.lang.Snowflake;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -13,9 +15,9 @@
 import com.yuanchu.limslaboratory.pojo.vo.InspectDetailVo;
 import com.yuanchu.limslaboratory.pojo.vo.InspectionVo;
 import com.yuanchu.limslaboratory.service.*;
-import com.yuanchu.limslaboratory.utils.MyUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.*;
@@ -61,7 +63,11 @@
     UserMapper userMapper;
 
     @Resource
-    ReportMapper reportMapper;
+    RawMaterialMapper rawMaterialMapper;
+
+    @Resource
+    LinkDetectionMapper linkDetectionMapper;
+
 
     /**
      * 鏌ヨ妫�楠岀敵璇峰崟鍒楄〃
@@ -74,14 +80,45 @@
         return inspectionMapper.selectInspectsList(page, message);
     }
 
+    //鏂板妫�楠屽崟-->閫夋嫨妫�楠岄」鐩増鏈�
+    @Override
+    public List<Integer> chooseVer(String name, String mcode, String specifications) {
+        Integer specificationId = getSpecificationId(name, mcode, specifications);
+        return productMapper.chooseVersion(specificationId);
+    }
+
+    //鏂板妫�楠屽崟-->閫夋嫨妫�楠岄」鐩増鏈�-->鏌ョ湅璇ョ増鏈笅鎴戜滑瑕佸仛鐨勯」鐩姹�
+    @Override
+    public List<Map<String, Object>> lookProByVer(String name, String mcode, String specifications, Integer version, String experiment) {
+        Integer specificationId = getSpecificationId(name, mcode, specifications);
+        /*濡傛灉璇曢獙椤圭洰涓虹┖鍒欐槸鎴愬搧妫�楠屾垨鑰呭師鏉愭枡妫�楠屽垯鏄睍绀鸿鐗堟湰鐨勬墍鏈夐」鐩楠岃姹傚弬鏁�*/
+        if (ObjectUtils.isEmpty(experiment)) {
+            return productMapper.pageProductInformation(specificationId, version);
+        }
+        /*濡傛灉涓嶄负绌哄垯鏄鎵樻楠�,鍙睍绀烘垜浠妫�楠岀殑椤圭洰瑕佹眰鍙傛暟*/
+        //鑾峰彇璇曢獙椤圭洰淇℃伅(缁撴瀯,瀵肩嚎澶栧緞)
+        List<String> experiments = Arrays.stream(experiment.split(",")).collect(Collectors.toList());
+        //鏍规嵁鍨嬪彿id鍜岄」鐩俊鎭煡璇㈤」鐩俊鎭�
+        List<Map<String, Object>> products = new ArrayList<>();
+        for (String exper : experiments) {
+            List<Map<String, Object>> list = productMapper.selFath(specificationId, exper, version);
+            if (ObjectUtils.isEmpty(list)) {
+                Map<String, Object> project = productMapper.selNam(specificationId, exper, version);
+                products.add(project);
+            }
+            products.addAll(list);
+        }
+        return products;
+    }
+
     /**
      * 鏂板妫�楠岀敵璇疯〃
-     *
-     * @param id
+     * @param id 鐢ㄦ埛id
      * @param
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Integer addInspect(Integer id, InspectionVo inspectionVo) {
         /*鏂板妫�楠岀敵璇疯〃*/
         Inspection inspection = Inspection.builder()
@@ -92,6 +129,22 @@
                 .userId(id)
                 .build();
         inspectionMapper.insert(inspection);
+        /*濡傛灉鏄師鏉愭枡妫�楠�,鏂板涔嬪悗瑕佹洿鏀瑰師鏉愭枡鎶ユ鐨勭姸鎬佸拰妫�楠屼汉,妫�楠屾棩鏈�*/
+        if (inspectionVo.getType()==0) {
+            RawMaterial rawMaterial = new RawMaterial();
+            rawMaterial.setId(inspectionVo.getId());
+            rawMaterial.setType(1);
+            rawMaterial.setInspectionDate(DateUtil.date());
+            rawMaterial.setSurveyor(userMapper.selectById(id).getName());
+            rawMaterialMapper.updateById(rawMaterial);
+        }
+        /*濡傛灉鏄鎵樻楠�,鏂板涔嬪悗瑕佹洿鏀瑰鎵樻姤妫�鐨勭姸鎬�*/
+        else if (inspectionVo.getType()==2){
+            LinkDetection linkDetection = new LinkDetection();
+            linkDetection.setId(inspectionVo.getId());
+            linkDetection.setInspectionStatus(2);
+            linkDetectionMapper.updateById(linkDetection);
+        }
         /*鏂板妫�楠屾牱鍝佽〃*/
         InspectionMaterial inspectionMaterial = InspectionMaterial.builder()
                 .code(inspectionVo.getMcode())
@@ -105,25 +158,55 @@
                 .build();
         inspectionMaterialMapper.insert(inspectionMaterial);
         /*鏂板妫�楠岄」鐩〃*/
-        //鑾峰彇鐗╂枡id
-        Material material = materialMapper.selectOne(Wrappers.<Material>query()
-                .eq("name", inspectionVo.getName())
-                .eq("code", inspectionVo.getMcode()));
-        //鑾峰彇瑙勬牸鍚嶇О鍜屽瀷鍙峰悕绉�
-        String specification = inspectionVo.getSpecifications();
-        String[] split = specification.split("-");
-        String stName = split[0];
-        String spName = split[1];
-        //鑾峰彇瑙勬牸id
-        Standard standard = standardService.getOne(Wrappers.<Standard>query()
-                .eq("name", stName)
-                .eq("material_id", material.getId()));
-        //鑾峰彇鍨嬪彿id
-        Specifications specifications = specificationsService.getOne(Wrappers.<Specifications>query()
-                .eq("name", spName)
-                .eq("standard_id", standard.getId()));
-        //鏍规嵁鍨嬪彿id鏌ヨ椤圭洰淇℃伅
-        List<Product> productList = productMapper.selectList(Wrappers.<Product>query().eq("specifications_id", specifications.getId()));
+        //鏍规嵁鏍峰搧鍚嶇О缂栧彿浠ュ強鍨嬪彿瑙勬牸鑾峰彇鍨嬪彿id
+        Integer specificationId = null;
+        if(ObjectUtils.isNotEmpty(inspectionVo.getSpecificationId())){
+            specificationId =Integer.parseInt(inspectionVo.getSpecificationId());
+        }else{
+            specificationId=getSpecificationId(inspectionVo.getName(), inspectionVo.getMcode(), inspectionVo.getSpecifications());
+        }
+        //濡傛灉璇曢獙椤圭洰瀛楁涓嶄负绌哄垯鎸夎瀛楁鐨勯」鐩繘琛屽尮閰�
+        if (ObjectUtils.isNotEmpty(inspectionVo.getExperiment())) {
+            //鑾峰彇璇曢獙椤圭洰淇℃伅(缁撴瀯,瀵肩嚎澶栧緞)
+            List<String> experiments = Arrays.stream(inspectionVo.getExperiment().split(",")).collect(Collectors.toList());
+            //鏍规嵁鍨嬪彿id鍜岄」鐩俊鎭煡璇㈤」鐩俊鎭�
+            List<Product> products = new ArrayList<>();
+            for (String experiment : experiments) {
+                List<Product> productList1 = productMapper.selectList(Wrappers.<Product>query()
+                        .eq("specifications_id", specificationId)
+                        .eq("father", experiment)
+                        .eq("version", inspectionVo.getVersion()));
+                if (ObjectUtils.isEmpty(productList1)) {
+                    Product product = productMapper.selectOne(Wrappers.<Product>query()
+                            .eq("specifications_id", specificationId)
+                            .isNull("father")
+                            .eq("name", experiment)
+                            .eq("version", inspectionVo.getVersion()));
+                    products.add(product);
+                } else products.addAll(productList1);
+            }
+            //灏嗘煡璇㈢殑椤圭洰淇℃伅鏋勫缓鎴愭楠岄」鐩�
+            ArrayList<InspectionProduct> list = new ArrayList<>();
+            for (Product product : products) {
+                InspectionProduct rawInsProduct = InspectionProduct.builder()
+                        .name(product.getName())
+                        .unit(product.getUnit())
+                        .required(product.getRequired())
+                        .internal(product.getInternal())
+                        .inspectionMaterialId(inspectionMaterial.getId())
+                        .build();
+                list.add(rawInsProduct);
+            }
+            //妫�楠岄」鐩壒閲忔坊鍔�
+            inspectionProductService.saveBatch(list);
+            return inspection.getId();
+        }
+        //濡傛灉璇曢獙椤圭洰涓虹┖鍒欐寜鐓у瀷鍙穒d鍦ㄦ爣鍑嗗簱閲岄潰鍏ㄩ儴鍖归厤
+        List<Product> productList =
+                productMapper.selectList(Wrappers.<Product>query()
+                        .eq("specifications_id", specificationId)
+                .eq("version",inspectionVo.getVersion()));
+        //灏嗘煡璇㈢殑椤圭洰淇℃伅鏋勫缓鎴愭楠岄」鐩�
         ArrayList<InspectionProduct> list = new ArrayList<>();
         for (Product product : productList) {
             InspectionProduct rawInsProduct = InspectionProduct.builder()
@@ -131,7 +214,7 @@
                     .unit(product.getUnit())
                     .required(product.getRequired())
                     .internal(product.getInternal())
-                    .inspectionMaterialId(material.getId())
+                    .inspectionMaterialId(inspectionMaterial.getId())
                     .build();
             list.add(rawInsProduct);
         }
@@ -142,6 +225,7 @@
 
     //鏍规嵁妫�楠屽崟id鏌ヨ鍘熸潗鏂欐楠屽崟璇︽儏
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public InspectDetailVo selectInspectsListById(Integer id) {
         /*灏嗘楠屽崟鍩烘湰淇℃伅鏌ヨ鍑烘潵骞跺皝瑁呭埌RawInspectVo瀵硅薄涓�*/
         Inspection inspection = inspectionMapper.selectById(id);
@@ -160,8 +244,10 @@
         BeanUtils.copyProperties(inspectionMaterial, inspectDetailVo);
         /*鏌ヨ妫�楠屽崟閲岄潰鐨勬楠岄」鐩�,骞跺皝瑁呭埌RawInspectVo瀵硅薄涓�*/
         LambdaQueryWrapper<InspectionProduct> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(InspectionProduct::getInspectionMaterialId, inspectionMaterial.getId());
+        queryWrapper
+                .eq(InspectionProduct::getInspectionMaterialId, inspectionMaterial.getId());
         List<InspectionProduct> inspectionProducts = inspectionProductMapper.selectList(queryWrapper);
+        System.out.println(inspectionProducts);
         //杩欓噷鏌ュ埌鐨勮澶噄d鍜屾楠屽憳id瑕佹煡璇㈠悕绉�
         List<InsProductVo> insProductVos = inspectionProducts.stream().map(insProduct -> {
             //灏嗕竴涓璞$殑鍊艰祴鍊肩粰鍙︿竴涓璞�
@@ -173,47 +259,78 @@
                 insProductVo.setInstrumentName(equipmentName);
             }
             //鑾峰彇鐢ㄦ埛鍚�(鍓嶆彁鏄鏋滃瓨鍦�)
-            if (insProduct.getUserId() != null) {
-                String userName = userMapper.selectById(insProduct.getUserId()).getName();
+            if (insProduct.getUserProId() != null) {
+                String userName = userMapper.selectById(insProduct.getUserProId()).getName();
                 insProductVo.setUserName(userName);
             }
             //椤圭洰鍏宠仈鐗╂枡id
             insProductVo.setInspectionMaterialId(inspectionMaterial.getId());
+            insProductVo.setId(insProduct.getId());
             return insProductVo;
         }).collect(Collectors.toList());
         inspectDetailVo.setInsProducts(insProductVos);
         return inspectDetailVo;
     }
 
-    //鏇存柊妫�楠屽崟妫�楠岀粨鏋�
+    //浣滃簾妫�楠屽崟
     @Override
-    public boolean updateInspectsById(Integer id) {
-        //鏇存柊妫�楠屽崟閲岄潰鐨勬楠岀姸鎬佸拰妫�楠岀粨璁�
-        InspectDetailVo inspectDetailVo = selectInspectsListById(id);
-        Inspection inspection = Inspection.builder()
-                .id(id)
-                .inspectionStatus(inspectDetailVo.getInspectionStatus())
-                .build();
+    @Transactional(rollbackFor = Exception.class)
+    public String delInspect(Integer id) {
+        /*浣滃簾妫�楠屽崟*/
+        Inspection inspection = new Inspection();
+        inspection.setId(id);
+        inspection.setState(0);
         inspectionMapper.updateById(inspection);
-        //鐢熸垚鎶ュ憡鍗�
-        Report report = new Report();
-        //鐢熸垚鎶ュ憡鍗曞彿
-        String code = MyUtil.getTimeSixNumberCode("BG","BG");
-        //鑾峰彇妫�楠岀粨璁�
-        String conclusion = "";
-        Inspection inspection1 = inspectionMapper.selectById(id);
-        if (inspection1.getInspectionStatus().equals(1)) {
-            conclusion = "鍚堟牸";
-        }else {
-            conclusion = "涓嶅悎鏍�";
-        }
-        report.setCode(code);
-        report.setStatus(0);
-        report.setConclusion(conclusion);
-        report.setInspectionId(id);
-        reportMapper.insert(report);
-
-        return true;
+        /*浣滃簾妫�楠屾牱鍝�*/
+        InspectionMaterial inspectionMaterial = inspectionMaterialMapper.selectOne(Wrappers.<InspectionMaterial>query().eq("inspection_id", id));
+        inspectionMaterial.setState(0);
+        inspectionMaterialMapper.updateById(inspectionMaterial);
+        /*浣滃簾妫�楠岄」鐩�*/
+        inspectionProductMapper.updat(inspectionMaterial.getId());
+        return "浣滃簾鎴愬姛!";
     }
+
+    //淇濆瓨妫�楠岄」鐩矗浠讳汉
+    @Override
+    public String chooseUseProId(Integer id, Integer userProId) {
+        InspectionProduct inspectionProduct = new InspectionProduct();
+        inspectionProduct.setId(id);
+        inspectionProduct.setUserProId(userProId);
+        inspectionProductMapper.updateById(inspectionProduct);
+        return "淇濆瓨鎴愬姛!";
+    }
+
+    @Override
+    public boolean chooseEquipment(Integer id, Integer equipmentId) {
+        UpdateWrapper<InspectionProduct>inspectionProductUpdateWrapper=new UpdateWrapper<>();
+        inspectionProductUpdateWrapper.lambda().set(InspectionProduct::getInstrumentId,equipmentId)
+                .eq(InspectionProduct::getId,id);
+        return inspectionProductMapper.update(null,inspectionProductUpdateWrapper)>0;
+    }
+
+    /*鏍规嵁鏍峰搧鍚嶇О,鏍峰搧缂栧彿,鍨嬪彿瑙勬牸鑾峰彇鍨嬪彿id*/
+    private Integer getSpecificationId(String name, String mcode, String specification) {
+        //鑾峰彇鐗╂枡id
+        Material material = materialMapper.selectOne(Wrappers.<Material>query()
+                .eq("name", name)
+                .eq("code", mcode));
+        if (Objects.isNull(material)){
+            return null;
+        }
+        //鑾峰彇瑙勬牸鍚嶇О鍜屽瀷鍙峰悕绉�
+        String[] split = specification.split("-");
+        String stName = split[0];
+        String spName = split[1];
+        //鑾峰彇瑙勬牸id
+        Standard standard = standardService.getOne(Wrappers.<Standard>query()
+                .eq("name", stName)
+                .eq("material_id", material.getId()));
+        //鑾峰彇鍨嬪彿id
+        Specifications specifications = specificationsService.getOne(Wrappers.<Specifications>query()
+                .eq("name", spName)
+                .eq("standard_id", standard.getId()));
+        return specifications.getId();
+    }
+
 }
 

--
Gitblit v1.9.3