From 23855599412c4d61b38d78f0f3abd3430a48b5b1 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 25 六月 2025 11:51:38 +0800
Subject: [PATCH] Merge branch 'mdc_hyjs_master'

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/GuideCardBatchServiceImpl.java |  143 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/GuideCardBatchServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/GuideCardBatchServiceImpl.java
new file mode 100644
index 0000000..836f70c
--- /dev/null
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/GuideCardBatchServiceImpl.java
@@ -0,0 +1,143 @@
+package org.jeecg.modules.dnc.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum;
+import org.jeecg.modules.dnc.entity.*;
+import org.jeecg.modules.dnc.mapper.GuideCardBatchMapper;
+import org.jeecg.modules.dnc.service.*;
+import org.jeecg.modules.system.service.ISysDictService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Description: nc鏂囦欢瀵瑰簲鏁版帶绋嬪簭鍔犲伐纭琛�
+ * @Author: jeecg-boot
+ * @Date:   2025-05-27
+ * @Version: V1.0
+ */
+@Service
+public class GuideCardBatchServiceImpl extends ServiceImpl<GuideCardBatchMapper, GuideCardBatch> implements IGuideCardBatchService {
+
+    @Autowired
+    private ISysDictService sysDictService;
+
+    @Autowired
+    private IDocInfoService docInfoService;
+
+    @Autowired
+    private IPartsInfoService partsInfoService;
+
+    @Autowired
+    private IProcessStreamService processStreamService;
+
+    @Autowired
+    private IWorkStepService workStepService;
+
+    @Autowired
+    private IDeviceTypeService deviceTypeService;
+
+    /**
+     * 鐢熸垚娴佹按鍙�
+     * @param code
+     * @return
+     */
+    @Override
+    public String getSerialNumber(String code) {
+        // 浜嬩欢缂栧彿鏍煎紡锛氬勾浠藉悗涓や綅 + 鍗曚綅缂栫爜 + 鎿嶄綔宸ヨ处鍙� + 娴佹按鍙凤紙4浣嶏級
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+
+        // 鑾峰彇褰撳墠骞翠唤鍚庝袱浣�
+        String yearSuffix = DateUtils.formatDate(new Date(), "yy");
+
+        // 鏌ヨ褰撳勾鎵�鏈夎褰�
+        QueryWrapper<GuideCardBatch> wrapper = new QueryWrapper<>();
+        wrapper.apply("YEAR(create_time) = YEAR(GETDATE())");
+        wrapper.isNotNull("serial_number");
+        wrapper.orderByDesc("SUBSTRING(serial_number, LEN(serial_number)-3, 4)");
+
+        List<GuideCardBatch> list = this.list(wrapper);
+
+        // 鐢熸垚娴佹按鍙烽�昏緫
+        String serialSuffix;
+        if (!list.isEmpty()) {
+            // 鎻愬彇鏈�鏂版祦姘村彿鐨勫悗鍥涗綅
+            String lastSerial = list.get(0).getSerialNumber();
+            String lastSuffix = lastSerial.substring(lastSerial.length() - 4);
+
+            // 娴佹按鍙疯嚜澧烇紙澶勭悊9999婧㈠嚭锛�
+            int nextNum = Integer.parseInt(lastSuffix) + 1;
+            serialSuffix = String.format("%04d", nextNum > 9999 ? 1 : nextNum); // 瓒呰繃9999鍒欓噸缃负0001
+        } else {
+            serialSuffix = "0001"; // 褰撳勾鏃犺褰曞垯鍒濆鍖�
+        }
+
+        // 鎷兼帴瀹屾暣缂栧彿
+        return yearSuffix+"-"+ code+"-"+ user.getUsername()+"-"+ serialSuffix;
+    }
+
+    /**
+     * 瀵煎叆NC鏂囦欢榛樿浜х敓nc鏂囦欢瀵瑰簲鏁版帶绋嬪簭鍔犲伐纭琛�
+     * @param docId
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean importGuideCardBatch(String docId,String attributionId,Integer attributionType){
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        DocInfo docInfo=docInfoService.getById(docId);
+        if (docInfo==null){
+            return false;
+        }
+        PartsInfo partsInfo=new PartsInfo();
+        ProcessStream processStream;
+        WorkStep workStep;
+        DeviceType deviceType;
+        GuideCardBatch guideCardBatch=new GuideCardBatch();
+        if (DocAttributionTypeEnum.PROCESS.getCode().equals(attributionType)){
+            //宸ュ簭璁惧绫�
+            deviceType=deviceTypeService.getById(attributionId);
+            if (deviceType==null){
+                return false;
+            }
+            processStream=processStreamService.getById(deviceType.getAttributionId());
+            if (processStream==null){
+                return false;
+            }
+            guideCardBatch.setProcessWorkCode(processStream.getProcessCode());
+            partsInfo=partsInfoService.getById(processStream.getPartsId());
+        }else if (DocAttributionTypeEnum.WORKSITE.getCode().equals(attributionType)){
+            //宸ユ璁惧绫�
+            deviceType=deviceTypeService.getById(attributionId);
+            if (deviceType==null){
+                return false;
+            }
+            workStep=workStepService.getById(deviceType.getAttributionId());
+            if (workStep==null){
+                return false;
+            }
+            guideCardBatch.setProcessWorkCode(workStep.getStepCode());
+            partsInfo=partsInfoService.getById(workStep.getPartsId());
+        }
+        guideCardBatch.setDocId(docId);
+        guideCardBatch.setSerialNumber(getSerialNumber("C140"));
+        guideCardBatch.setUnit(sysDictService.queryDictTextByKey("unit_code", "C140"));
+        guideCardBatch.setDocName(docInfo.getDocName());
+        if (partsInfo!=null){
+            guideCardBatch.setPartsCode(partsInfo.getPartsCode());
+            guideCardBatch.setPartsName(partsInfo.getPartsName());
+            guideCardBatch.setMaterielDesp(partsInfo.getMaterielDesp());
+        }
+        guideCardBatch.setFlowStatus("0");
+        guideCardBatch.setCompiler(user.getUsername());
+        guideCardBatch.setCreateTime(new Date());
+        return this.save(guideCardBatch);
+    }
+}

--
Gitblit v1.9.3