From e756af0f5bfd1addbd5d5c145441fb34aad91a28 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期三, 25 六月 2025 13:55:58 +0800
Subject: [PATCH] 同步工控网

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/GuideCardBatchServiceImpl.java |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 288 insertions(+), 12 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
index e108ded..f61a051 100644
--- 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
@@ -1,19 +1,39 @@
 package org.jeecg.modules.dnc.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.shiro.SecurityUtils;
+import org.flowable.engine.TaskService;
+import org.flowable.task.api.Task;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
-import org.jeecg.modules.dnc.entity.GuideCardBatch;
+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.IGuideCardBatchService;
+import org.jeecg.modules.dnc.response.ActivitiCode;
+import org.jeecg.modules.dnc.response.CommonCode;
+import org.jeecg.modules.dnc.response.UcenterCode;
+import org.jeecg.modules.dnc.service.*;
+import org.jeecg.modules.dnc.utils.ValidateUtil;
+import org.jeecg.modules.dncFlow.constant.GuideCardBatchEnum;
+import org.jeecg.modules.dncFlow.entity.DispatchFile;
+import org.jeecg.modules.dncFlow.vo.GuideCardBatchFlowTaskVo;
+import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
+import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
+import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
+import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
+import org.jeecg.modules.flowable.service.IFlowDefinitionService;
+import org.jeecg.modules.flowable.service.IFlowTaskService;
 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 org.springframework.transaction.interceptor.TransactionAspectSupport;
 
-import java.util.Date;
-import java.util.List;
+import javax.annotation.Resource;
+import java.util.*;
 
 /**
  * @Description: nc鏂囦欢瀵瑰簲鏁版帶绋嬪簭鍔犲伐纭琛�
@@ -21,11 +41,37 @@
  * @Date:   2025-05-27
  * @Version: V1.0
  */
-@Service
-public class GuideCardBatchServiceImpl extends ServiceImpl<GuideCardBatchMapper, GuideCardBatch> implements IGuideCardBatchService {
+@Service("IGuideCardBatchService")
+public class GuideCardBatchServiceImpl extends ServiceImpl<GuideCardBatchMapper, GuideCardBatch> implements IGuideCardBatchService , FlowCallBackServiceI {
 
     @Autowired
     private ISysDictService sysDictService;
+
+    @Autowired
+    private IDocInfoService docInfoService;
+
+    @Autowired
+    private IPartsInfoService partsInfoService;
+
+    @Autowired
+    private IProcessStreamService processStreamService;
+
+    @Autowired
+    private IWorkStepService workStepService;
+
+    @Autowired
+    private IDeviceTypeService deviceTypeService;
+
+    @Resource
+    private FlowCommonService flowCommonService;
+    @Resource
+    private IFlowDefinitionService flowDefinitionService;
+    @Autowired
+    private IFlowTaskService flowTaskService;
+    @Autowired
+    private TaskService taskService;
+    @Autowired
+    private IFlowMyBusinessService flowMyBusinessService;
 
     /**
      * 鐢熸垚娴佹按鍙�
@@ -42,9 +88,9 @@
 
         // 鏌ヨ褰撳勾鎵�鏈夎褰�
         QueryWrapper<GuideCardBatch> wrapper = new QueryWrapper<>();
-        wrapper.likeRight("create_time", DateUtils.formatDate(new Date(), "yyyy"));
+        wrapper.apply("YEAR(create_time) = YEAR(GETDATE())");
         wrapper.isNotNull("serial_number");
-        wrapper.orderByDesc("SUBSTR(serial_number, -4)");
+        wrapper.orderByDesc("SUBSTRING(serial_number, LEN(serial_number)-3, 4)");
 
         List<GuideCardBatch> list = this.list(wrapper);
 
@@ -62,10 +108,240 @@
             serialSuffix = "0001"; // 褰撳勾鏃犺褰曞垯鍒濆鍖�
         }
 
-        // 鑾峰彇鍗曚綅缂栫爜
-        String unitCode = sysDictService.queryDictTextByKey("unit_code", code);
-
         // 鎷兼帴瀹屾暣缂栧彿
-        return yearSuffix + unitCode + user.getUsername() + serialSuffix;
+        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());
+        }
+        if (partsInfo==null){
+            return false;
+        }
+        guideCardBatch.setDocId(docId);
+        guideCardBatch.setSerialNumber(getSerialNumber("C140"));
+        guideCardBatch.setUnit(sysDictService.queryDictTextByKey("unit_code", "C140"));
+        guideCardBatch.setDocName(docInfo.getDocName());
+        guideCardBatch.setPartsCode(partsInfo.getPartsCode());
+        guideCardBatch.setPartsName(partsInfo.getPartsName());
+        guideCardBatch.setMaterielDesp(partsInfo.getMaterielDesp());
+        guideCardBatch.setCompiler(user.getUsername());
+        guideCardBatch.setCreateTime(new Date());
+        return this.save(guideCardBatch);
+    }
+
+    /**
+     * 鍙戣捣纭娴佺▼
+     * @param id
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> startGuideCardBatch(String id){
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        //鑾峰彇绋嬪簭鍔犲伐纭琛�
+        GuideCardBatch guideCardBatch=this.getById(id);
+        if (guideCardBatch==null) {
+            return Result.ok("鏈壘鍒板搴旂殑绋嬪簭鍔犲伐纭琛�");
+        }
+        //濉厖鏁版嵁
+        guideCardBatch.setCompiler(user.getUsername());
+        guideCardBatch.setCompilerTime(new Date());
+        guideCardBatch.setFlowStatus(GuideCardBatchEnum.VERIFY.getCode());
+        this.updateById(guideCardBatch);
+        System.out.println("绋嬪簭鍔犲伐纭琛� 纭娴佺▼锛�" + guideCardBatch.getId());
+        flowCommonService.initActBusiness("娴佹按鍙凤細"+guideCardBatch.getSerialNumber()+" 绋嬪簭鍔犲伐纭琛ㄨ繘琛岀‘璁ゆ祦绋�",
+                guideCardBatch.getId(), "IGuideCardBatchService", "nc_guide_card_batch", null);
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("dataId", guideCardBatch.getId());
+        variables.put("organization", "鐢ㄦ埛"+user.getRealname()+"鍙戣捣娴佺▼");
+        variables.put("comment",  "鐢ㄦ埛"+user.getRealname()+"鍙戣捣娴佺▼");
+        variables.put("proofreading",true);
+        Result result= flowDefinitionService.startProcessInstanceByKey("nc_guide_card_batch", variables);
+        if (!result.isSuccess()) {
+            guideCardBatch.setCompiler(null);
+            guideCardBatch.setCompilerTime(null);
+            this.updateById(guideCardBatch);
+        }
+        return result;
+    }
+
+    /**
+     * 娴佺▼鑺傜偣瀹℃牳
+     * @param guideCardBatchFlowTaskVo
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> auditGuideCardBatch(GuideCardBatchFlowTaskVo guideCardBatchFlowTaskVo){
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        try {
+            // 鍙傛暟鏍¢獙
+            if (!ValidateUtil.validateString(guideCardBatchFlowTaskVo.getTaskId()) || !ValidateUtil.validateString(guideCardBatchFlowTaskVo.getDataId())) {
+                return Result.error(CommonCode.INVALID_PARAM.toString());
+            }
+            String userId = user.getId();
+            guideCardBatchFlowTaskVo.setAssignee(user.getUsername());
+            if (!ValidateUtil.validateString(userId)) {
+                return Result.error(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST.toString());
+            }
+
+            // 鏁版嵁鏌ヨ
+            GuideCardBatch guideCardBatch = this.getById(guideCardBatchFlowTaskVo.getDataId());
+            if (guideCardBatch == null) {
+                return Result.error(CommonCode.INVALID_PARAM.toString());
+            }
+            DocInfo docInfo = docInfoService.getById(guideCardBatch.getDocId());
+            if (docInfo == null) {
+                return Result.error(ActivitiCode.ACT_DOC_ERROR.toString());
+            }
+
+            // 2. 鏌ヨ娴佺▼涓氬姟璁板綍锛堝鐞嗙┖缁撴灉锛�
+            List<FlowMyBusiness> businessList = flowMyBusinessService.list(
+                    new QueryWrapper<FlowMyBusiness>()
+                            .eq("process_instance_id", guideCardBatchFlowTaskVo.getInstanceId())
+            );
+            if (businessList.isEmpty()) {
+                return Result.error("娴佺▼璁板綍涓嶅瓨鍦�");
+            }
+            FlowMyBusiness flowMyBusiness = businessList.get(0);
+
+            // 3. 鏍¢獙鐢ㄦ埛鏄惁涓哄�欓�夊鐞嗕汉
+            List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class);
+            if (todoUsers == null || !todoUsers.contains(user.getUsername())) {
+                return Result.error("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔�");
+            }
+
+            // 4. 璁ら浠诲姟锛堝鐞嗗凡琚棰嗙殑鎯呭喌锛�
+            String taskId = flowMyBusiness.getTaskId();
+            Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+            if (task == null) {
+                return Result.error("浠诲姟涓嶅瓨鍦ㄦ垨宸插畬鎴�");
+            }
+            if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) {
+                return Result.error("浠诲姟宸茶浠栦汉璁ら");
+            }
+            taskService.claim(taskId, user.getUsername());
+
+            // 璁剧疆娴佺▼鍙橀噺
+            Map<String, Object> values = new HashMap<>();
+            values.put("dataId", guideCardBatch.getId());
+            values.put("assignee", userId);
+            values.put("comment", guideCardBatchFlowTaskVo.getComment());
+            values.put("organization", guideCardBatchFlowTaskVo.getComment());
+            if (guideCardBatchFlowTaskVo.getCheckType() != null) {
+                values.put("checkType", guideCardBatchFlowTaskVo.getCheckType());
+            }
+            if (guideCardBatchFlowTaskVo.getConfirmType() != null) {
+                values.put("confirmType", guideCardBatchFlowTaskVo.getConfirmType());
+            }
+            if (guideCardBatchFlowTaskVo.getApproveType() != null) {
+                values.put("approveType", guideCardBatchFlowTaskVo.getApproveType());
+            }
+            guideCardBatchFlowTaskVo.setValues(values);
+            // 瀹屾垚娴佺▼浠诲姟
+            Result result = flowTaskService.complete(guideCardBatchFlowTaskVo);
+            if (result.isSuccess()) {
+                if (guideCardBatchFlowTaskVo.getCheckType() != null) {
+                    if (guideCardBatchFlowTaskVo.getCheckType()){
+                        guideCardBatch.setFlowStatus(GuideCardBatchEnum.CONFIRM.getCode());
+                        guideCardBatch.setProofreader(user.getUsername());
+                        guideCardBatch.setProofreaderTime(new Date());
+                    }else {
+                        guideCardBatch.setFlowStatus(GuideCardBatchEnum.PREPARE.getCode());
+                    }
+                }
+                if (guideCardBatchFlowTaskVo.getConfirmType() != null) {
+                    if (guideCardBatchFlowTaskVo.getConfirmType()){
+                        guideCardBatch.setFlowStatus(GuideCardBatchEnum.APPROVE.getCode());
+                        guideCardBatch.setOperator(user.getUsername());
+                        guideCardBatch.setInspectionTime(new Date());
+                        guideCardBatch.setInspectionOpinion(guideCardBatchFlowTaskVo.getInspectionOpinion());
+                    }else {
+                        guideCardBatch.setFlowStatus(GuideCardBatchEnum.PREPARE.getCode());
+                    }
+                }
+                if (guideCardBatchFlowTaskVo.getApproveType() != null) {
+                    if (guideCardBatchFlowTaskVo.getApproveType()){
+                        guideCardBatch.setFlowStatus(GuideCardBatchEnum.COMPLETE.getCode());
+                        guideCardBatch.setApprover(user.getUsername());
+                        guideCardBatch.setApproverTime(new Date());
+                    }else {
+                        guideCardBatch.setFlowStatus(GuideCardBatchEnum.PREPARE.getCode());
+                        }
+                }
+                this.updateById(guideCardBatch);
+            } else {
+                return result;
+            }
+            return Result.OK("鎿嶄綔鎴愬姛");
+        } catch (Exception e) {
+            // 璁剧疆浜嬪姟鍥炴粴
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return Result.error("鎿嶄綔澶辫触锛�" + e.getMessage());
+        }
+    }
+
+    @Override
+    public void afterFlowHandle(FlowMyBusiness business) {
+        business.getTaskNameId();//鎺ヤ笅鏉ュ鎵圭殑鑺傜偣
+        business.getValues();//鍓嶇浼犺繘鏉ョ殑鍙傛暟
+        business.getActStatus();
+    }
+
+    @Override
+    public Object getBusinessDataById(String dataId) {
+        return this.getById(dataId);
+    }
+
+    @Override
+    public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) {
+        return null;
+    }
+
+    @Override
+    public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
+        //涓氬姟鏄惁骞查娴佺▼锛屼笟鍔″共棰勶紝娴佺▼骞查锛屾寚瀹氫汉鍛樿繘琛屽鐞�
+        return null;
     }
 }

--
Gitblit v1.9.3