From b9e2c1619cf61bcd5f24b858fff738244d20566e Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期二, 05 九月 2023 17:04:29 +0800
Subject: [PATCH] 过程检验修改9-5

---
 inspect-server/src/main/java/com/yuanchu/mom/service/impl/FinishedInspectServiceImpl.java |  322 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 301 insertions(+), 21 deletions(-)

diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/FinishedInspectServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/FinishedInspectServiceImpl.java
index 6dca1e1..b7466c0 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/FinishedInspectServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/FinishedInspectServiceImpl.java
@@ -1,26 +1,31 @@
 package com.yuanchu.mom.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 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.yuanchu.mom.mapper.InspectUnacceptedMapper;
-import com.yuanchu.mom.pojo.FinishedInspect;
-import com.yuanchu.mom.mapper.FinishedInspectMapper;
-import com.yuanchu.mom.pojo.InspectUnaccepted;
-import com.yuanchu.mom.service.FinishedInspectService;
+import com.yuanchu.mom.mapper.*;
+import com.yuanchu.mom.pojo.*;
+import com.yuanchu.mom.pojo.vo.FinishedInspectVo1;
+import com.yuanchu.mom.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.yuanchu.mom.service.InspectionItemService;
-import com.yuanchu.mom.service.ProductService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
- *  鏈嶅姟瀹炵幇绫�
+ * 鏈嶅姟瀹炵幇绫�
  * </p>
  *
  * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃
@@ -32,43 +37,186 @@
     @Resource
     private FinishedInspectMapper finishedInspectMapper;
 
+    @Resource
+    MaterialMapper materialMapper;
+
+    @Resource
+    StandardService standardService;
+
+    @Resource
+    SpecificationsService specificationsService;
+
+    @Resource
+    InspectionItemService inspectionItemService;
+
     @Autowired
     private ProductService productService;
 
-    @Autowired
-    private InspectionItemService inspectionItemService;
+    @Resource
+    UserMapper userMapper;
 
     @Resource
     InspectUnacceptedMapper inspectUnacceptedMapper;
+
+    @Resource
+    RepertoryMapper repertoryMapper;
+
+    @Resource
+    ImportRepertoryMapper importRepertoryMapper;
+
+    @Resource
+    TechnologyMapper technologyMapper;
+
+    @Resource
+    TechniqueMapper techniqueMapper;
 
     @Override
     public Integer addProcessInspectionSheet(FinishedInspect finishedInspect) {
         finishedInspect.setType(0);
         int insert = finishedInspectMapper.insert(finishedInspect);
-        if (insert == 1){
-            List<Map<String, Object>> maps = productService.selectProductList(finishedInspect.getSpecificationsId());
-            inspectionItemService.insertList(finishedInspect.getId(), maps);
+        if (insert == 1) {
+            /*List<Map<String, Object>> maps = productService.selectProductList(finishedInspect.getSpecificationsId());
+            inspectionItemService.insertList(finishedInspect.getId(), maps);*/
             return insert;
         }
         return 0;
     }
 
+
     @Override
-    public Integer inspectionConclusion(Integer finishedInspectId, Integer result) {
+    @Transactional(rollbackFor = Exception.class)
+    public Integer inspectionConclusion(String username, Integer finishedInspectId, Integer result) {
         //鏇存柊妫�楠屽崟閲岄潰鐨勬楠岀粨璁�
         LambdaUpdateWrapper<FinishedInspect> updateWrapper = new LambdaUpdateWrapper<>();
         updateWrapper.eq(FinishedInspect::getId, finishedInspectId);
         updateWrapper.set(FinishedInspect::getResult, result);
         finishedInspectMapper.update(new FinishedInspect(), updateWrapper);
-        //濡傛灉妫�楠岀粨璁轰负涓嶅悎鏍�,鍒欓渶瑕佹柊澧炰笉鍚堟牸妫�楠屽崟
         FinishedInspect finishedInspect = finishedInspectMapper.selectById(finishedInspectId);
+        /*妫�楠岀粨璁轰负涓嶅悎鏍�*/
         if (result == 0) {
-            InspectUnaccepted inspectUnaccepted = InspectUnaccepted.builder()
-                    .reason(finishedInspect.getProjectName() + "涓嶅悎鏍�")  //鏆備笖瀹氫箟涓哄伐绋嬪悕绉颁笉鍚堟牸
-                    .rawInspectId(finishedInspectId)
-                    .type(finishedInspect.getType())
-                    .build();
-            inspectUnacceptedMapper.insert(inspectUnaccepted);
+            //濡傛灉鏄垚鍝佺殑缁撹涓轰笉鍚堟牸,闇�瑕佹柊澧炴垚鍝佷笉鍚堟牸妫�楠屽崟
+            if (finishedInspect.getType() == 0) {
+                /*鏂板鎴愬搧涓嶅悎鏍兼楠屽崟*/
+                InspectUnaccepted inspectUnaccepted = InspectUnaccepted.builder()
+                        .reason(finishedInspect.getProjectName() + "涓嶅悎鏍�")  //鏆備笖瀹氫箟涓哄伐绋嬪悕绉颁笉鍚堟牸
+                        .rawInspectId(finishedInspectId)
+                        .build();
+                inspectUnacceptedMapper.insert(inspectUnaccepted);
+            }
+            //濡傛灉鏄繃绋嬫楠岀殑缁撹涓轰笉鍚堟牸,闇�瑕佹柊澧炲崐鎴愬搧搴撳瓨涓旀楠岀粨鏋滀负涓嶅悎鏍�
+            if (finishedInspect.getType() == 1) {
+                /*鏂板鍗婃垚鍝�(1)搴撳瓨*/
+                //濡傛灉鍏ュ簱鐨勪俊鎭竴鏍峰彧鏈夊簱瀛樹笉涓�鏍�,鍒欏湪鍘熸潵鐨勫簱瀛樻暟閲忎笂鍔犱笂鐩稿簲鐨勬暟閲�
+                LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber())
+                        .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability())
+                        .eq(Repertory::getName, finishedInspect.getMaterial())
+                        .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel())
+                        .eq(Repertory::getUnit, finishedInspect.getUnit())
+                        .eq(Repertory::getType, 1)
+                        .eq(Repertory::getCheckResult, 0);
+                Repertory rep = repertoryMapper.selectOne(queryWrapper);
+                if (rep != null) {
+                    rep.setNumber(rep.getNumber() + finishedInspect.getQuantity());
+                    rep.setUserName(username);
+                    repertoryMapper.updateById(rep);
+                } else {
+                    //濡傛灉闄や簡搴撳瓨鍒殑淇℃伅鏈変换浣曚竴涓笉涓�鏍�,鍒欐柊澧炰竴鏉″崐鎴愬搧搴撳瓨
+                    Repertory repertory = Repertory.builder()
+                            .orderCode(finishedInspect.getOrderNumber())
+                            .qualityTraceability(finishedInspect.getQualityTraceability())
+                            .name(finishedInspect.getMaterial())
+                            .specifications(finishedInspect.getSpecificationsModel())
+                            .unit(finishedInspect.getUnit())
+                            .number(finishedInspect.getQuantity())
+                            .userName(username)
+                            .type(1)
+                            .checkResult(0)//妫�楠岀粨鏋滀负涓嶅悎鏍�
+                            .build();
+                    repertoryMapper.insert(repertory);
+                }
+            }
+        }
+        /*妫�楠岀粨璁轰负鍚堟牸*/
+        if (result == 1) {
+            //濡傛灉鏄垚鍝佹楠屽悎鏍�,,闇�瑕佹柊澧炴垚鍝�(0)搴撳瓨鍜屽叆搴撹褰�
+            if (finishedInspect.getType() == 0) {
+                /*鏂板鎴愬搧鍏ュ簱璁板綍*/
+                ImportRepertory importRepertory = ImportRepertory.builder()
+                        .orderCode(finishedInspect.getOrderNumber())
+                        .qualityTraceability(finishedInspect.getQualityTraceability())
+                        .name(finishedInspect.getMaterial())
+                        .specifications(finishedInspect.getSpecificationsModel())
+                        .unit(finishedInspect.getUnit())
+                        .number(finishedInspect.getQuantity())
+                        .userName(username)
+                        .build();
+                importRepertoryMapper.insert(importRepertory);
+                /*鏂板鎴愬搧(0)搴撳瓨*/
+                //濡傛灉鍏ュ簱鐨勪俊鎭竴鏍峰彧鏈夊簱瀛樹笉涓�鏍�,鍒欏湪鍘熸潵鐨勫簱瀛樻暟閲忎笂鍔犱笂鐩稿簲鐨勬暟閲�
+                LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber())
+                        .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability())
+                        .eq(Repertory::getName, finishedInspect.getMaterial())
+                        .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel())
+                        .eq(Repertory::getUnit, finishedInspect.getUnit())
+                        .eq(Repertory::getType, 0)
+                        .eq(Repertory::getCheckResult, 1);
+                Repertory rep = repertoryMapper.selectOne(queryWrapper);
+                if (rep != null) {
+                    rep.setNumber(rep.getNumber() + finishedInspect.getQuantity());
+                    rep.setUserName(username);
+                    repertoryMapper.updateById(rep);
+                } else {
+                    //濡傛灉闄や簡搴撳瓨鍒殑淇℃伅鏈変换浣曚竴涓笉涓�鏍�,鍒欐柊澧炰竴鏉℃垚鍝佸簱瀛�
+                    Repertory repertory = Repertory.builder()
+                            .orderCode(finishedInspect.getOrderNumber())
+                            .qualityTraceability(finishedInspect.getQualityTraceability())
+                            .name(finishedInspect.getMaterial())
+                            .specifications(finishedInspect.getSpecificationsModel())
+                            .unit(finishedInspect.getUnit())
+                            .number(finishedInspect.getQuantity())
+                            .userName(username)
+                            .type(0)
+                            .checkResult(1)   //搴撳瓨妫�楠岀粨鏋滀负鍚堟牸
+                            .build();
+                    repertoryMapper.insert(repertory);
+                }
+            }
+            //濡傛灉鏄繃绋嬫楠屽悎鏍�,闇�瑕佹柊澧炲崐鎴愬搧(1)搴撳瓨,妫�楠岀粨鏋滀负鍚堟牸1
+            if (finishedInspect.getType() == 1) {
+                /*鏂板鍗婃垚鍝�(1)搴撳瓨*/
+                //濡傛灉鍏ュ簱鐨勪俊鎭竴鏍峰彧鏈夊簱瀛樹笉涓�鏍�,鍒欏湪鍘熸潵鐨勫簱瀛樻暟閲忎笂鍔犱笂鐩稿簲鐨勬暟閲�
+                LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber())
+                        .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability())
+                        .eq(Repertory::getName, finishedInspect.getMaterial())
+                        .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel())
+                        .eq(Repertory::getUnit, finishedInspect.getUnit())
+                        .eq(Repertory::getType, 1)
+                        .eq(Repertory::getCheckResult, 1);
+                Repertory rep = repertoryMapper.selectOne(queryWrapper);
+                if (rep != null) {
+                    rep.setNumber(rep.getNumber() + finishedInspect.getQuantity());
+                    rep.setUserName(username);
+                    repertoryMapper.updateById(rep);
+                } else {
+                    //濡傛灉闄や簡搴撳瓨鍒殑淇℃伅鏈変换浣曚竴涓笉涓�鏍�,鍒欐柊澧炰竴鏉″崐鎴愬搧搴撳瓨
+                    Repertory repertory = Repertory.builder()
+                            .orderCode(finishedInspect.getOrderNumber())
+                            .qualityTraceability(finishedInspect.getQualityTraceability())
+                            .name(finishedInspect.getMaterial())
+                            .specifications(finishedInspect.getSpecificationsModel())
+                            .unit(finishedInspect.getUnit())
+                            .number(finishedInspect.getQuantity())
+                            .userName(username)
+                            .type(1)
+                            .checkResult(1)//妫�楠岀粨鏋滀负鍚堟牸
+                            .build();
+                    repertoryMapper.insert(repertory);
+                }
+            }
+
         }
         return 1;
     }
@@ -77,4 +225,136 @@
     public IPage<Map<String, Object>> selectFinishedInspectPage(Page<Object> page, Integer inspectResult, String inspectDate, String inspectUsername) {
         return finishedInspectMapper.selectFinishedInspectPage(page, inspectResult, inspectDate, inspectUsername);
     }
+
+    //鏂板杩囩▼妫�楠屽崟-->鏍规嵁璁㈠崟鍙烽�夋嫨浜у搧淇℃伅
+    @Override
+    public List<Map<String, Object>> chooseMater(String orderNumber) {
+        return finishedInspectMapper.chooseMater(orderNumber);
+    }
+
+    //鏂板杩囩▼妫�楠屽崟
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public String addProcess(String userId, FinishedInspectVo1 finishedInspectVo1) {
+        /*鏂板杩囩▼妫�楠屽崟*/
+        FinishedInspect finishedInspect = new FinishedInspect();
+        finishedInspect.setType(1);
+        finishedInspect.setUserId(Integer.parseInt(userId));
+        BeanUtils.copyProperties(finishedInspectVo1, finishedInspect);
+        finishedInspectMapper.insert(finishedInspect);
+        /*鎵归噺鏂板杩囩▼妫�楠岄」鐩〃*/
+        //鑾峰彇鍨嬪彿id
+        Integer specificationId = getSpecificationId(finishedInspectVo1.getMaterial(), finishedInspectVo1.getMaterialCode(), finishedInspectVo1.getSpecificationsModel());
+        //鏌ヨ鏍囧噯BOM鎶�鏈寚鏍囦腑璇ュ瀷鍙峰伐鑹轰笅鏈�鏂扮増鏈殑妫�楠岄」鐩�
+        Integer ver = productService.selectVerByPro(specificationId).get(0);//璇ュ瀷鍙蜂笅鎶�鏈寚鏍囨渶鏂扮増鏈�
+        List<Product> productList = productService.selProByVerSpe(finishedInspectVo1.getTechnologyId(), ver);
+        List<InspectionItem> inspectionItemList = productList.stream().map(product -> {
+            InspectionItem inspectionItem = new InspectionItem();
+            BeanUtils.copyProperties(product, inspectionItem);
+            inspectionItem.setFinishInspectId(finishedInspect.getId());
+            //濡傛灉鏂板鏃惰繕濉啓浜嗘楠屽�煎垯瑕佽繘琛屽垽鏂楠岀粨鏋�
+            if (ObjectUtils.isNotEmpty(finishedInspectVo1.getInspectionValue())) {
+                inspectionItem.setInspectionValue(finishedInspectVo1.getInspectionValue());
+                //鍒ゆ柇妫�娴嬪�兼槸鍚︽弧瓒虫爣鍑嗗�煎拰鍐呮帶鍊肩殑瑕佹眰,濡傛灉涓嶆弧瓒冲垯妫�楠岀粨璁轰负涓嶅悎鏍�0
+                String required = product.getRequired();//鏍囧噯鍊�
+                String internal = product.getInternal();//鍐呮帶鍊�
+                String testValue = finishedInspectVo1.getInspectionValue();//妫�娴嬪��
+                List<Integer> list = Arrays.stream(testValue.split(",")).map(s -> {
+                    int values = checkValues(required, internal, s);
+                    return values;
+                }).collect(Collectors.toList());
+                if (list.contains(0)) {
+                    //濡傛灉鍏朵腑涓�涓楠屽�间笉鍚堟牸鍒欒椤圭洰妫�楠屼笉鍚堟牸
+                    inspectionItem.setResult(0);
+                } else {
+                    inspectionItem.setResult(1);
+                }
+                inspectionItem.setUsername(userMapper.selectById(userId).getName());
+            }
+            return inspectionItem;
+        }).collect(Collectors.toList());
+        inspectionItemService.saveBatch(inspectionItemList);
+        return "鏂板杩囩▼妫�楠屽崟"+finishedInspect.getId()+"鎴愬姛!";
+    }
+
+    //鏂板杩囩▼妫�楠屽崟-->閫夋嫨璁惧
+    @Override
+    public List<Map<String, Object>> chooseDev(Integer technologyId, String father, String name) {
+        //璇ュ伐鑹篿d涓嬬敓浜у伐鑹烘渶鏂扮増鏈�
+        Integer ver = techniqueMapper.selectVerByTeId(technologyId).get(0);
+        return techniqueMapper.selDevByVerTecIdFaNam(technologyId,father,name,ver);
+    }
+
+
+    /*鏍规嵁鏍峰搧鍚嶇О,鏍峰搧缂栧彿,鍨嬪彿瑙勬牸鑾峰彇鍨嬪彿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();
+    }
+
+    /*鍒ゆ柇妫�娴嬪�兼槸鍚︽弧瓒虫爣鍑嗗�煎拰鍐呮帶鍊肩殑瑕佹眰,濡傛灉涓嶆弧瓒冲垯妫�楠岀粨璁轰负涓嶅悎鏍�*/
+    private int checkValues(String standardValueStr, String controlValueStr, String detectionValueStr) {
+        boolean isStandardValueSatisfied = isValueSatisfied(standardValueStr, detectionValueStr);
+        boolean isControlValueSatisfied = isValueSatisfied(controlValueStr, detectionValueStr);
+
+        if (isStandardValueSatisfied && isControlValueSatisfied) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
+    private boolean isValueSatisfied(String valueStr, String detectionValueStr) {
+        String substring = valueStr.substring(1, 2);
+        if (substring.equals("=")) {
+            String operator = valueStr.substring(0, 2);
+            Double standardValue = Double.parseDouble(valueStr.substring(2));
+            Double detectionValue = Double.parseDouble(detectionValueStr);
+            switch (operator) {
+                case ">=":
+                    return detectionValue >= standardValue;
+                case "<=":
+                    return detectionValue <= standardValue;
+                default:
+                    return false;
+            }
+        } else {
+            String operator = valueStr.substring(0, 1);
+            Double standardValue = Double.parseDouble(valueStr.substring(1));
+            Double detectionValue = Double.parseDouble(detectionValueStr);
+            switch (operator) {
+                case ">":
+                    return detectionValue > standardValue;
+                case "鈮�":
+                    return detectionValue >= standardValue;
+                case "鈮�":
+                    return detectionValue <= standardValue;
+                case "<":
+                    return detectionValue < standardValue;
+                case "=":
+                    return detectionValue.equals(standardValue);
+                default:
+                    return false;
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.3