From 97bb7a8832281eafe0ef947ea095258d355e52f5 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 30 十二月 2024 15:57:51 +0800
Subject: [PATCH] 无源器件的数采+电路模版查询

---
 inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java |  363 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 246 insertions(+), 117 deletions(-)

diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
index c857e20..de97e6d 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
@@ -1,13 +1,12 @@
 package com.yuanchu.mom.service.impl;
 
+import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.ExcelWriter;
 import com.alibaba.excel.write.metadata.WriteSheet;
 import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -20,22 +19,27 @@
 import com.yuanchu.mom.exception.ErrorException;
 import com.yuanchu.mom.mapper.*;
 import com.yuanchu.mom.pojo.*;
+import com.yuanchu.mom.service.InformationNotificationService;
 import com.yuanchu.mom.service.InsOrderService;
-import com.yuanchu.mom.service.InsProductService;
 import com.yuanchu.mom.utils.GiveCode;
 import com.yuanchu.mom.utils.QYWXApi;
 import com.yuanchu.mom.utils.QueryWrappers;
 import com.yuanchu.mom.vo.SampleDefectsFatherVo;
 import lombok.AllArgsConstructor;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 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;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
@@ -48,38 +52,47 @@
  * @createDate 2024-03-12 16:17:55
  */
 @Service
-@AllArgsConstructor
 @Transactional(rollbackFor = Exception.class)
-public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder>
-        implements InsOrderService {
+public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderService {
 
+    @Resource
     private GetLook getLook;
-
+    @Resource
     private RoleMapper roleMapper;
-
+    @Resource
     private InsOrderMapper insOrderMapper;
 
+    @Value("${file.path}")
+    private String imgUrl;
+
+    @Value("${wordUrl}")
+    private String wordUrl;
+    @Resource
+    private InsOrderFileMapper insOrderFileMapper;
+    @Resource
     private InsSampleMapper insSampleMapper;
-    private WarehouseHistoryMapper warehouseHistoryMapper;
-
+    @Resource
+    InsProductResult2Mapper insProductResult2Mapper;
+    @Resource
+    InsProductResultMapper insProductResultMapper;
+    @Resource
     private InsProductMapper insProductMapper;
-    private InsProductService insProductService;
-
+    @Resource
     private InsProductUserMapper insProductUserMapper;
-
+    @Resource
     private GiveCode giveCode;
-
-    private InsSampleUserMapper insSampleUserMapper;
-
-    private InsOrderStateMapper insOrderStateMapper;
-
+    @Resource
     UserMapper userMapper;
-
+    @Resource
+    InformationNotificationService informationNotificationService;
+    @Resource
     PowerMapper powerMapper;
-
+    @Resource
     CustomMapper customMapper;
-
+    @Resource
     QYWXApi qywxApi;
+    @Autowired
+    ProcessOrder1Mapper processOrderMapper;
 
 
     //鑾峰彇妫�楠屼笅鍗曟暟鎹�
@@ -118,37 +131,9 @@
         return map;
     }
 
-    //鍒嗛厤绔欑偣
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int upInsOrder(Integer orderId, Integer sampleId, String appointed, Integer userId, String sonLaboratory) {
-        InsOrder insOrder = new InsOrder();
-        insOrder.setId(orderId);
-        insOrder.setAppointed(LocalDate.parse(appointed));
-        insOrder.setSendTime(LocalDateTime.now());
-        insOrderMapper.updateById(insOrder);
-        //淇敼鎴愬彧缁欏綋鍓嶉�夋嫨鐨勮瘯楠屽涓嬪彂鍗曞瓙
-        InsOrderState insOrderState = new InsOrderState();
-        insOrderState.setInsOrderId(orderId);
-        insOrderState.setLaboratory(sonLaboratory);
-        insOrderState.setInsState(0);
-        insOrderState.setNum(1);//鍒濆鏄涓�娆�
-        insOrderStateMapper.insert(insOrderState);
-        //杩欓噷鏄湪缁欏垎閰嶇殑鎸囧畾鐨勪汉鍜岃瘯楠屽涓嬪彂妫�楠屼汉
-        if (userId != null) {
-            InsSampleUser insSampleUser = new InsSampleUser();
-            insSampleUser.setState(0);
-            insSampleUser.setUserId(userId);
-            insSampleUser.setInsSampleId(orderId);
-            insSampleUser.setSonLaboratory(sonLaboratory);
-            insSampleUserMapper.insert(insSampleUser);
-        }
-        return 1;
-    }
-
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing) {
+    public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing, List<MultipartFile> files) {
         insOrder.setState(0);
         //鍒ゆ柇閫夋嫨鐨勫鎵樺崟浣嶄笌鍒跺崟浜虹殑濮旀墭鍗曚綅鏄惁涓�鑷�
         Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId");
@@ -170,13 +155,8 @@
             insOrder.setCompanyId(one.getId());
             code = one.getCode2();
         }
-        //瀹為獙瀹ょ紪鍙�
-        String code2 = baseMapper.selLaboratoryCode(insOrder.getLaboratory());
-        if (StringUtils.isEmpty(code2)) {
-            code2 = "";
-        }
         //澶栭儴濮旀墭缂栧彿
-        insOrder.setOutEntrustCode(giveCode.giveCode3("ZT/" + code2 + "-" + code + "-", insOrder.getCompanyId(), insOrder.getLaboratory(), "ins_order", "", "yyMM"));
+        insOrder.setOutEntrustCode(giveCode.giveCode("WT-", "ins_order", "-", "yyMMdd"));
         String giveCode = this.giveCode.giveCode("JCZX-" + code + "-", "ins_sample", "", "yyMMdd");
         insOrderMapper.insert(insOrder);
         AtomicInteger count = new AtomicInteger();
@@ -186,7 +166,7 @@
             a.setInsOrderId(insOrder.getId());
             //鏍峰搧缂栧彿
             if (StrUtil.isEmpty(a.getSampleCode())) {
-                a.setSampleCode("TX(WYQJ)-" + giveCode.split("-")[2] + "-" + count.get());
+                a.setSampleCode("YP-" + a.getModel() + "-" + giveCode.split("-")[2] + "-" + count.get());
             }
             insSampleMapper.insert(a);
             //鏍峰搧鐨勬楠岄」鐩�
@@ -230,10 +210,145 @@
             }
 
         });
+        List<User> users1 = userMapper.getUserByRole("妫�娴嬩腑蹇冧富浠�");
+        List<User> users2 = userMapper.getUserByRole("鐮斿彂閮ㄧ粡鐞�");
+        List<User> users3 = userMapper.getUserByRole("鎶�鏈礋璐d汉");
         //閫氫俊:濡傛灉鏄疌绫昏鍗曟棤闇�瀹℃牳鐩存帴閫氳繃
         if (insOrder.getOrderType().equals("C")) {
             insOrder.setState(1);
             upInsOrderOfState(insOrder);
+        } else if (insOrder.getOrderType().equals("A")) {
+            //甯歌澶栭儴鍗曢渶娑堟伅鎻愰啋妫�楠屼腑蹇冧富浠诲拰鐮斿彂閮ㄧ粡鐞�
+            //todo 涓嬪崟瀹℃牳浼佷笟寰俊鎺ㄩ��
+            users1.addAll(users2);
+            String account = users1.stream().map(User::getAccount).collect(Collectors.joining("|"));
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("touser", account);//鎺ユ敹娑堟伅鎴愬憳鐨勮处鍙�'ZT-031292'杩欑绫诲瀷(濡傛灉鏈夊涓敤'|'鍒嗛殧)
+            map.put("msgtype", "text");//娑堟伅绫诲瀷 text:鏂囨湰
+            map.put("agentid", 1000517);//搴旂敤id
+            HashMap<String, Object> hashMap = new HashMap<>();
+            hashMap.put("content", "鎮ㄦ湁涓�鏉℃楠岃鍗曢渶瑕佸鏍�,璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傚閮ㄨ鍗曞彿鏄細" + insOrder.getOutEntrustCode() +
+                    ",鏍峰搧鍚嶇О鏄細"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(","))+
+                    ",璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傝鐐瑰嚮<a href=\"https://ztwxlims.ztt.cn:7443/enter\">涓ぉ閫氫俊LIMS绯荤粺 </a>");
+            map.put("text", hashMap);//娑堟伅鍐呭
+            map.put("safe", 0);//鏄惁淇濆瘑娑堟伅.0鍚�
+            map.put("enable_id_trans", 0);//鏄惁寮�鍚痠d杞瘧.0鍚�
+            map.put("enable_duplicate_check", 0);//鏄惁寮�鍚噸澶嶆秷鎭鏌�.0鍚�
+            qywxApi.send(map);
+            //lims娑堟伅鎻愰啋
+            ArrayList<InformationNotification> notificationArrayList = new ArrayList<>();
+            for (User user : users1) {
+                InformationNotification info = new InformationNotification();
+                info.setCreateUser(userMapper.selectById(userId).getName());
+                info.setMessageType("2");
+                info.setTheme("瀹℃牳閫氱煡");
+                info.setContent("鎮ㄦ湁涓�鏉℃楠岃鍗曞緟瀹℃牳娑堟伅,璁㈠崟鐨勫閮ㄧ紪鍙锋槸:" + insOrder.getOutEntrustCode()+",鏍峰搧鍚嶇О鏄細"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(",")));
+                info.setSenderId(userId);
+                info.setViewStatus(false);
+                info.setJumpPath("b1-inspection-order");
+                info.setConsigneeId(user.getId());
+                notificationArrayList.add(info);
+            }
+            informationNotificationService.saveBatch(notificationArrayList);
+        } else if (insOrder.getOrderType().equals("B")) {
+            //闈炲父瑙勫閮ㄥ崟闇�娑堟伅鎻愰啋妫�楠屼腑蹇冧富浠�,鐮斿彂閮ㄧ粡鐞嗗拰鎶�鏈礋璐d汉
+            //todo  涓嬪崟瀹℃牳浼佷笟寰俊鎺ㄩ��
+            users1.addAll(users2);
+            users1.addAll(users3);
+            String account = users1.stream().map(User::getAccount).collect(Collectors.joining("|"));
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("touser", account);//鎺ユ敹娑堟伅鎴愬憳鐨勮处鍙�'ZT-031292'杩欑绫诲瀷(濡傛灉鏈夊涓敤'|'鍒嗛殧)
+            map.put("msgtype", "text");//娑堟伅绫诲瀷 text:鏂囨湰
+            map.put("agentid", 1000517);//搴旂敤id
+            HashMap<String, Object> hashMap = new HashMap<>();
+            hashMap.put("content", "鎮ㄦ湁涓�鏉℃楠岃鍗曢渶瑕佸鏍�,璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傚閮ㄨ鍗曞彿鏄細" + insOrder.getOutEntrustCode() +
+                    ",鏍峰搧鍚嶇О鏄細"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(",")) +
+                    ",璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傝鐐瑰嚮<a href=\"https://ztwxlims.ztt.cn:7443/enter\">涓ぉ閫氫俊LIMS绯荤粺 </a>");
+            map.put("text", hashMap);//娑堟伅鍐呭
+            map.put("safe", 0);//鏄惁淇濆瘑娑堟伅.0鍚�
+            map.put("enable_id_trans", 0);//鏄惁寮�鍚痠d杞瘧.0鍚�
+            map.put("enable_duplicate_check", 0);//鏄惁寮�鍚噸澶嶆秷鎭鏌�.0鍚�
+            qywxApi.send(map);
+            //lims娑堟伅鎻愰啋
+            ArrayList<InformationNotification> notificationArrayList = new ArrayList<>();
+            for (User user : users1) {
+                InformationNotification info = new InformationNotification();
+                info.setCreateUser(userMapper.selectById(userId).getName());
+                info.setMessageType("2");
+                info.setTheme("瀹℃牳閫氱煡");
+                info.setContent("鎮ㄦ湁涓�鏉℃楠岃鍗曞緟瀹℃牳娑堟伅,璁㈠崟鐨勫閮ㄧ紪鍙锋槸:" + insOrder.getOutEntrustCode()+",鏍峰搧鍚嶇О鏄細"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(",")));
+                info.setSenderId(userId);
+                info.setViewStatus(false);
+                info.setJumpPath("b1-inspection-order");
+                info.setConsigneeId(user.getId());
+                notificationArrayList.add(info);
+            }
+            informationNotificationService.saveBatch(notificationArrayList);
+        }
+        //濡傛灉鏈変笂浼犵殑闄勪欢
+        if (CollectionUtils.isNotEmpty(files)) {
+            for (MultipartFile file : files) {
+                String urlString;
+                String pathName;
+                String path;
+                String filename = file.getOriginalFilename();
+                String contentType = file.getContentType();
+                InsOrderFile insOrderFile = new InsOrderFile();
+                insOrderFile.setInsOrderId(insOrder.getId());
+                insOrderFile.setFileName(filename);
+                if (contentType != null && contentType.startsWith("image/")) {
+                    // 鏄浘鐗�
+                    path = imgUrl;
+                    insOrderFile.setType(1);
+                } else {
+                    // 鏄枃浠�
+                    path = wordUrl;
+                    insOrderFile.setType(2);
+                }
+                try {
+                    File realpath = new File(path);
+                    if (!realpath.exists()) {
+                        realpath.mkdirs();
+                    }
+                    pathName = UUID.randomUUID() + "_" + file.getOriginalFilename().replace("#", "&");
+                    urlString = realpath + "/" + pathName;
+                    file.transferTo(new File(urlString));
+                    insOrderFile.setFileUrl(pathName);
+                    insOrderFileMapper.insert(insOrderFile);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    System.err.println("闄勪欢涓婁紶閿欒");
+                }
+            }
+        }
+        //todo 鏍锋満鍛樻帹閫佷紒涓氬井淇� @zss
+        if (!insOrder.getFormType().equals("鍏朵粬鎴愬搧")) {
+            String account = userMapper.selectById(insOrder.getIssueUser()).getAccount();
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("touser", account);//鎺ユ敹娑堟伅鎴愬憳鐨勮处鍙�'ZT-031292'杩欑绫诲瀷(濡傛灉鏈夊涓敤'|'鍒嗛殧)
+            map.put("msgtype", "text");//娑堟伅绫诲瀷 text:鏂囨湰
+            map.put("agentid", 1000517);//搴旂敤id
+            HashMap<String, Object> hashMap = new HashMap<>();
+            hashMap.put("content", "鎮ㄦ湁涓�鏉¤鍗曢渶瑕佸畬鎴�,璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傚閮ㄨ鍗曞彿鏄細" + insOrder.getOutEntrustCode() +
+                    ",鏍峰搧鍚嶇О鏄細"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(","))+
+                    ",璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傝鐐瑰嚮<a href=\"https://ztwxlims.ztt.cn:7443/enter\">涓ぉ閫氫俊LIMS绯荤粺 </a>");
+            map.put("text", hashMap);//娑堟伅鍐呭
+            map.put("safe", 0);//鏄惁淇濆瘑娑堟伅.0鍚�
+            map.put("enable_id_trans", 0);//鏄惁寮�鍚痠d杞瘧.0鍚�
+            map.put("enable_duplicate_check", 0);//鏄惁寮�鍚噸澶嶆秷鎭鏌�.0鍚�
+            qywxApi.send(map);
+
+            //LIMS绯荤粺娑堟伅鎺ㄩ��
+            InformationNotification info = new InformationNotification();
+            info.setCreateUser(insProductMapper.selectUserById(userId).get("name"));
+            info.setMessageType("1");
+            info.setTheme("鏍锋満鍛橀�氱煡");
+            info.setContent("鎮ㄦ湁涓�鏉℃楠岃鍗曠殑鏍锋満寰呭畬鎴愭秷鎭�,澶栭儴璁㈠崟鍙锋槸锛�" + insOrder.getOutEntrustCode() + ",鏍峰搧鍚嶇О鏄細"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(",")));
+            info.setSenderId(userId);
+            info.setConsigneeId(insOrder.getIssueUser());
+            info.setViewStatus(false);
+            info.setJumpPath("b1-inspection-order");
+            informationNotificationService.addInformationNotification(info);
         }
         return insOrder.getId();
     }
@@ -275,31 +390,13 @@
         insOrder.setExamineTime(LocalDateTime.now());
         if (insOrder.getState() == 1) {
             //瀹℃牳閫氳繃鎵嶄細鐢熸垚濮旀墭缂栧彿
-            Custom custom = customMapper.selectById(order.getCompanyId());
-            System.out.println("=============" + custom.getCompany());
-            System.out.println("-------------" + order.getCompany());
-            insOrder.setEntrustCode(giveCode.giveCode2("TXJC-", insOrder.getCompanyId(), insOrder.getLaboratory(), "ins_order", "", "yyMMdd"));
-            int day = insProductService.selectOrderManDay(insOrder.getId());//棰勮瀹屾垚鏃堕棿
-            //纭畾璁㈠崟鐨勪笅鍙戞椂闂村拰绾﹀畾鏃堕棿
-            insOrder.setAppointed(LocalDate.parse(LocalDateTime.now().plusHours(day).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
+            insOrder.setEntrustCode(giveCode.giveCode2("WT-", "ins_order", "-", "yyMMdd"));
             insOrder.setSendTime(LocalDateTime.now());
-            /*todo 鏍规嵁璁㈠崟绫诲瀷鍒ゆ柇鏄惁闇�瑕佹帹閫佷紒涓氬井淇� @zss*/
-            if (!order.getFormType().equals("鍏朵粬鎴愬搧")) {
-               /* HashMap<String, Object> map = new HashMap<>();
-                String account = userMapper.selectById(order.getIssueUser()).getAccount();
-                map.put("touser", account);//鎺ユ敹娑堟伅鎴愬憳鐨勮处鍙�'ZT-031292'杩欑绫诲瀷(濡傛灉鏈夊涓敤'|'鍒嗛殧)
-                map.put("toparty", "");//鎺ユ敹閮ㄩ棬id
-                map.put("totag", "");//娑堟伅鏍囩id
-                map.put("msgtype", "text");//娑堟伅绫诲瀷 text:鏂囨湰
-                map.put("agentid", 1000513);//搴旂敤id
-                HashMap<String, Object> hashMap = new HashMap<>();
-                hashMap.put("content", "鎮ㄦ湁涓�鏉¤鍗曢渶鐢熸垚妫�楠�,璇峰墠寰�LIMS绯荤粺鏌ョ湅銆�<a href=\"http://10.1.13.77/enter\"> </a>");
-                map.put("text", JSONArray.toJSONString(hashMap));//娑堟伅鍐呭
-                map.put("safe", 0);//鏄惁淇濆瘑娑堟伅.0鍚�
-                map.put("enable_id_trans", 0);//鏄惁寮�鍚痠d杞瘧.0鍚�
-                map.put("enable_duplicate_check", 0);//鏄惁寮�鍚噸澶嶆秷鎭鏌�.0鍚�
-                qywxApi.send(map);*/
-            }
+            /*瀹℃牳閫氳繃杩橀渶瑕佹柊澧炰竴鏉nas瑕佹眰銆佹爣涔﹀拰鍚堝悓璇勫*/
+            ProcessOrder processOrder = new ProcessOrder();
+            processOrder.setInsOrderId(insOrder.getId());
+            processOrder.setRule(insOrder.getRule());
+            processOrderMapper.insert(processOrder);
         }
         return insOrderMapper.updateById(insOrder);
     }
@@ -330,8 +427,8 @@
         }
         insOrderMapper.updateById(order);
         //鏌ヨ璇ヨ鍗曟槸A绫昏繕鏄疊绫�
-        if (order.getOrderType().equals("A")) {
-            //濡傛灉鏄疉绫�,1鍜�2鍜�3閮藉鏍搁�氳繃杩欎釜鍗曞瓙灏卞鏍搁�氳繃
+        if (order.getOrderType().equals("B")) {
+            //濡傛灉鏄疊绫�,1鍜�2鍜�3閮藉鏍搁�氳繃杩欎釜鍗曞瓙灏卞鏍搁�氳繃
             if (order.getCheckState1() == 1 && order.getCheckState2() == 1 && order.getCheckState3() == 1) {
                 order.setState(1);
                 upInsOrderOfState(order);
@@ -339,8 +436,8 @@
                 order.setState(2);
                 upInsOrderOfState(order);
             }
-        } else if (order.getOrderType().equals("B")) {
-            //濡傛灉鏄疊绫�,1鍜�2瀹℃牳閫氳繃鍚庤繖涓崟瀛愬氨瀹℃牳閫氳繃
+        } else if (order.getOrderType().equals("A")) {
+            //濡傛灉鏄疉绫�,1鍜�2瀹℃牳閫氳繃鍚庤繖涓崟瀛愬氨瀹℃牳閫氳繃
             if (order.getCheckState1() == 1 && order.getCheckState2() == 1) {
                 order.setState(1);
                 upInsOrderOfState(order);
@@ -353,27 +450,42 @@
     }
 
     @Override
-    public Map<String, Object> getInsOrderAndSample(Integer id, String laboratory) {
+    public Map<String, Object> getInsOrderAndSample(Integer sampleId, String laboratory) {
+        InsSample insSample = insSampleMapper.selectById(sampleId);
         Map<String, Object> map = new HashMap<>();
-        InsOrder insOrder = insOrderMapper.selectById2(id);
-        List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory);
-        if (list.size() == 0) {
-            list = insSampleMapper.getInsOrderAndSample2(id, laboratory);
-        }
-        for (SampleProductDto sampleProductDto : list) {
-            List<Integer> ids = sampleProductDto.getInsProduct().stream().map(InsProduct::getId).collect(Collectors.toList());
-            List<InsProductUser> insProductUsers = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery()
-                    .in(InsProductUser::getInsProductId, ids));
-            if (CollectionUtils.isNotEmpty(insProductUsers)) {
-                List<Integer> userIds = insProductUsers.stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList());
-                String collect = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(","));
-                sampleProductDto.setCheckName(collect);
+        InsOrder insOrder = insOrderMapper.selectById2(insSample.getInsOrderId());
+        SampleProductDto sampleProductDto = insSampleMapper.getInsOrderAndSample(sampleId, laboratory);
+        //鍐嶆璇曢獙浼氬嚭鐜颁负绌虹殑鎯呭喌
+        if (ObjectUtils.isEmpty(sampleProductDto)) {
+            List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
+                    .eq(InsProduct::getInsSampleId, insSample.getId())
+                    .eq(InsProduct::getState, 1)
+                    .eq(InsProduct::getSonLaboratory, laboratory));
+            for (InsProduct insProduct : insProducts) {
+                List<InsProductResult2> insProductResult2List = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery()
+                        .eq(InsProductResult2::getInsProductId, insProduct.getId()).isNull(InsProductResult2::getNum));
+                insProduct.setInsProductResult2(insProductResult2List);
+                InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery()
+                        .eq(InsProductResult::getInsProductId, insProduct.getId()).isNull(InsProductResult::getNum));
+                insProduct.setInsProductResult(insProductResult);
             }
+            SampleProductDto dto = new SampleProductDto();
+            dto.setInsProduct(insProducts);
+            BeanUtils.copyProperties(insSample,dto);
+            sampleProductDto=dto;
+        }
+        List<Integer> ids = sampleProductDto.getInsProduct().stream().map(InsProduct::getId).collect(Collectors.toList());
+        List<InsProductUser> insProductUsers = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery()
+                .in(InsProductUser::getInsProductId, ids));
+        if (CollectionUtils.isNotEmpty(insProductUsers)) {
+            List<Integer> userIds = insProductUsers.stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList());
+            String collect = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(","));
+            sampleProductDto.setCheckName(collect);
         }
         map.put("insOrder", insOrder);
-        map.put("sampleProduct", list);
+        map.put("sampleProduct", sampleProductDto);
         //鏌ヨ鎵�鏈夎褰曟ā鐗堝幓閲�
-        List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory);
+        List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(insSample.getInsOrderId(), laboratory);
         map.put("reportModel", list2);
         return map;
     }
@@ -436,7 +548,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;
     }
 
@@ -460,20 +574,27 @@
     public List<SampleProductDto3> labelPrinting(String ids) {
         List<Integer> list = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList());
         List<SampleProductDto3> sampleProductDtos = insSampleMapper.selectSampleProductListByOrderId3(list);
-        Set<String> processedCodes = new HashSet<>();
-        //濡傛灉鏄厜绾ゆ垨鑰呮槸鍏夌氦甯﹂粯璁ゅ彧鎵撳嵃绗竴涓�
-        List<SampleProductDto3> sampleProductDto3s = sampleProductDtos.stream().filter(sampleProductDto3 -> {
-            if (!"鍏夌氦".equals(sampleProductDto3.getIoSampleType()) && !"鍏夌氦甯�".equals(sampleProductDto3.getIoSampleType())) {
-                return true;
+        return sampleProductDtos;
+    }
+
+    //鏍¢獙鐢垫満缂栧彿
+    @Override
+    public Map<String, List<InsSample>> checkNumber(String ids) {
+        List<InsSample> samples = new ArrayList<>();
+        List<Integer> list = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList());
+        List<InsSample> sampleDtos = insSampleMapper.selectInsSample(list);
+        //鍒ゆ柇鏍峰搧鍨嬪彿鏄惁鏄疊Z
+        for (InsSample sampleDto : sampleDtos) {
+            if (sampleDto.getModel().contains("BZ")) {
+                if (ObjectUtils.isEmpty(sampleDto.getMotorNumber())) {
+                    samples.add(sampleDto);
+                }
             }
-            if (processedCodes.contains(sampleProductDto3.getCode())) {
-                return false;
-            } else {
-                processedCodes.add(sampleProductDto3.getCode());
-                return true;
-            }
-        }).collect(Collectors.toList());
-        return sampleProductDto3s;
+        }
+        if (CollectionUtils.isNotEmpty(samples)) {
+            Map<String, List<InsSample>> collect = samples.stream().collect(Collectors.groupingBy(InsSample::getEntrustCode));
+            return collect;
+        } else return null;
     }
 
     @Override
@@ -526,6 +647,14 @@
             throw new RuntimeException("瀵煎嚭澶辫触");
         }
     }
+
+    @Override
+    public int addNumber(List<InsSample> insSamples) {
+        for (InsSample insSample : insSamples) {
+            insSampleMapper.updateById(insSample);
+        }
+        return 0;
+    }
 }
 
 

--
Gitblit v1.9.3