From 1214b18558c19b09c02161b1dbbef342ad2c1e8f Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期六, 12 十月 2024 17:14:46 +0800
Subject: [PATCH] 试验前后样品检查+开始结束时间

---
 inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java |  133 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 100 insertions(+), 33 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..e1d1bc2 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,5 +1,6 @@
 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;
@@ -20,6 +21,7 @@
 import com.yuanchu.mom.exception.ErrorException;
 import com.yuanchu.mom.mapper.*;
 import com.yuanchu.mom.pojo.*;
+import com.yuanchu.mom.service.InsOrderPlanService;
 import com.yuanchu.mom.service.InsOrderService;
 import com.yuanchu.mom.service.InsProductService;
 import com.yuanchu.mom.utils.GiveCode;
@@ -29,10 +31,14 @@
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
+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.net.URLEncoder;
 import java.time.LocalDate;
@@ -48,37 +54,46 @@
  * @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;
+    @Resource
     private WarehouseHistoryMapper warehouseHistoryMapper;
-
+    @Resource
     private InsProductMapper insProductMapper;
+    @Resource
     private InsProductService insProductService;
-
+    @Resource
     private InsProductUserMapper insProductUserMapper;
-
+    @Resource
     private GiveCode giveCode;
-
+    @Resource
     private InsSampleUserMapper insSampleUserMapper;
-
+    @Resource
     private InsOrderStateMapper insOrderStateMapper;
-
+    @Resource
     UserMapper userMapper;
-
+    @Resource
     PowerMapper powerMapper;
-
+    @Resource
     CustomMapper customMapper;
-
+    @Resource
     QYWXApi qywxApi;
 
 
@@ -124,7 +139,7 @@
     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.setAppointed(LocalDate.parse(appointed));
         insOrder.setSendTime(LocalDateTime.now());
         insOrderMapper.updateById(insOrder);
         //淇敼鎴愬彧缁欏綋鍓嶉�夋嫨鐨勮瘯楠屽涓嬪彂鍗曞瓙
@@ -148,7 +163,7 @@
 
     @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 +185,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 +196,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);
             //鏍峰搧鐨勬楠岄」鐩�
@@ -235,6 +245,42 @@
             insOrder.setState(1);
             upInsOrderOfState(insOrder);
         }
+        //濡傛灉鏈変笂浼犵殑闄勪欢
+        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();
+                    urlString = realpath + "/" + pathName;
+                    file.transferTo(new File(urlString));
+                    insOrderFile.setFileUrl(pathName);
+                    insOrderFileMapper.insert(insOrderFile);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    System.err.println("闄勪欢涓婁紶閿欒");
+                }
+            }
+        }
         return insOrder.getId();
     }
 
@@ -275,13 +321,10 @@
         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.setEntrustCode(giveCode.giveCode2("WT-", "ins_order", "-", "yyMMdd"));
             //纭畾璁㈠崟鐨勪笅鍙戞椂闂村拰绾﹀畾鏃堕棿
-            insOrder.setAppointed(LocalDate.parse(LocalDateTime.now().plusHours(day).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
+            //int day = insProductService.selectOrderManDay(insOrder.getId());//棰勮瀹屾垚鏃堕棿
+            //insOrder.setAppointed(LocalDate.parse(LocalDateTime.now().plusHours(day).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
             insOrder.setSendTime(LocalDateTime.now());
             /*todo 鏍规嵁璁㈠崟绫诲瀷鍒ゆ柇鏄惁闇�瑕佹帹閫佷紒涓氬井淇� @zss*/
             if (!order.getFormType().equals("鍏朵粬鎴愬搧")) {
@@ -461,11 +504,7 @@
         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;
-            }
             if (processedCodes.contains(sampleProductDto3.getCode())) {
                 return false;
             } else {
@@ -474,6 +513,26 @@
             }
         }).collect(Collectors.toList());
         return sampleProductDto3s;
+    }
+
+    //鏍¢獙鐢垫満缂栧彿
+    @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 (CollectionUtils.isNotEmpty(samples)) {
+            Map<String, List<InsSample>> collect = samples.stream().collect(Collectors.groupingBy(InsSample::getEntrustCode));
+            return collect;
+        } else return null;
     }
 
     @Override
@@ -526,6 +585,14 @@
             throw new RuntimeException("瀵煎嚭澶辫触");
         }
     }
+
+    @Override
+    public int addNumber(List<InsSample> insSamples) {
+        for (InsSample insSample : insSamples) {
+            insSampleMapper.updateById(insSample);
+        }
+        return 0;
+    }
 }
 
 

--
Gitblit v1.9.3