From 4d6cf92e30c2c7f81f8cc31dfb7559a745782ec1 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期一, 23 六月 2025 13:24:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

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

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignEquipmentFileStreamServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignEquipmentFileStreamServiceImpl.java
new file mode 100644
index 0000000..68972da
--- /dev/null
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dncFlow/service/impl/AssignEquipmentFileStreamServiceImpl.java
@@ -0,0 +1,316 @@
+package org.jeecg.modules.dncFlow.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+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.modules.dnc.constant.DncPassLogPassType;
+import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum;
+import org.jeecg.modules.dnc.dto.TransferPackage;
+import org.jeecg.modules.dnc.entity.*;
+import org.jeecg.modules.dnc.exception.ExceptionCast;
+import org.jeecg.modules.dnc.response.ActivitiCode;
+import org.jeecg.modules.dnc.response.CommonCode;
+import org.jeecg.modules.dnc.response.DocumentCode;
+import org.jeecg.modules.dnc.response.UcenterCode;
+import org.jeecg.modules.dnc.service.*;
+import org.jeecg.modules.dnc.service.impl.FileFerryService;
+import org.jeecg.modules.dnc.utils.ValidateUtil;
+import org.jeecg.modules.dnc.utils.date.DateUtil;
+import org.jeecg.modules.dnc.utils.file.FileUtilS;
+import org.jeecg.modules.dncFlow.constant.GuideCardBatchEnum;
+import org.jeecg.modules.dncFlow.entity.AssignEquipmentFileStream;
+import org.jeecg.modules.dncFlow.entity.DispatchFile;
+import org.jeecg.modules.dncFlow.mapper.AssignEquipmentFileStreamMapper;
+import org.jeecg.modules.dncFlow.service.IAssignEquipmentFileStreamService;
+import org.jeecg.modules.dncFlow.vo.AssignEquipmentFileStreamVo;
+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.mdc.entity.MdcEquipment;
+import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.system.service.IMdcProductionService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.transaction.NoTransactionException;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.util.*;
+
+/**
+ * @Description: DNC-璁惧缁撴瀯鏍戞寚娲句骇鍝佺粨鏋勬爲
+ * @Author: jeecg-boot
+ * @Date:   2025-06-17
+ * @Version: V1.0
+ */
+@Service("IAssignEquipmentFileStreamService")
+public class AssignEquipmentFileStreamServiceImpl extends ServiceImpl<AssignEquipmentFileStreamMapper, AssignEquipmentFileStream> implements IAssignEquipmentFileStreamService , FlowCallBackServiceI {
+
+    @Autowired
+    private IDocInfoService docInfoService;
+    @Autowired
+    private IDocFileService docFileService;
+    @Autowired
+    private IMdcEquipmentService mdcEquipmentService;
+    @Autowired
+    private IGuideCardBatchService iGuideCardBatchService;
+    @Resource
+    private FlowCommonService flowCommonService;
+    @Resource
+    private IFlowDefinitionService flowDefinitionService;
+    @Autowired
+    private IFlowTaskService flowTaskService;
+    @Autowired
+    private TaskService taskService;
+    @Autowired
+    private IFlowMyBusinessService flowMyBusinessService;
+    @Autowired
+    private IDocRelativeService docRelativeService;
+    @Autowired
+    private IDeviceTypeService deviceTypeService;
+    @Autowired
+    private PermissionService permissionService;
+    /**
+     * 娴佺▼鍚姩,淇濆瓨瀵瑰簲鐨勬暟鎹�
+     * @param assignEquipmentFileStream
+     * @return
+     */
+    @Override
+    public Result<?> saveAssignEquipmentFileStream(AssignEquipmentFileStream assignEquipmentFileStream){
+        //鍙傛暟鏍¢獙
+        checkParam(assignEquipmentFileStream);
+        //鑾峰彇璁惧
+        MdcEquipment equipment = mdcEquipmentService.getById(assignEquipmentFileStream.getEquipmentId());
+        if(equipment==null){
+            return Result.error("鏈彂鐜拌璁惧");
+        }
+        //鑾峰彇璁惧鏂囨。淇℃伅
+        DocInfo docInfo =docInfoService.getById(assignEquipmentFileStream.getEquipmentDocId());
+        if(docInfo==null){
+            return Result.error("鏈彂鐜拌璁惧瀵瑰簲鏂囨。");
+        }
+        //鑾峰彇璁惧鏂囦欢淇℃伅
+        DocFile docFile =docFileService.getById(assignEquipmentFileStream.getEquipmentFileId());
+        if(docFile==null){
+            return Result.error("鏈彂鐜拌璁惧瀵瑰簲鏂囦欢");
+        }
+        //鑾峰彇浜у搧鏂囨。淇℃伅
+        DocRelative docRelative=docRelativeService.getById(assignEquipmentFileStream.getDocId());
+        //鑾峰彇瀵瑰簲璁惧绫�
+        DeviceType deviceType = deviceTypeService.getById(docRelative.getAttributionId());
+        if(deviceType!=null){
+            assignEquipmentFileStream.setDeviceTypeId(deviceType.getId());
+            assignEquipmentFileStream.setAttributionId(deviceType.getAttributionId());
+            assignEquipmentFileStream.setAttributionType(deviceType.getAttributionType().toString());
+            PermissionStreamNew permissionStreamNew=permissionService.getPermissionStreams(assignEquipmentFileStream);
+            if(permissionStreamNew==null){
+                return Result.error("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔�");
+            }
+        }
+        DocInfo productDocInfo =docInfoService.getById(docRelative.getDocId());
+        if(productDocInfo==null){
+            return Result.error("鏈彂鐜拌浜у搧缁撴瀯鏍戝搴旀枃妗�");
+        }
+        //鑾峰彇浜у搧鏂囨。淇℃伅瀵瑰簲鏈�鏂扮▼搴忓姞宸ョ‘璁よ〃
+        List<GuideCardBatch> batches = iGuideCardBatchService.list(
+                new QueryWrapper<GuideCardBatch>()
+                        .eq("doc_id", productDocInfo.getDocId())
+                        .eq("flow_status", GuideCardBatchEnum.COMPLETE.getCode())
+                        .orderByDesc("SUBSTRING(serial_number, LEN(serial_number)-3, 4)"));
+        if(CollectionUtils.isEmpty(batches)){
+            return Result.error("璇ユ枃妗e搴旂殑绋嬪簭鍔犲伐纭琛ㄥ鎵规湭閫氳繃锛屼笉鑳借繘琛屽崌鐗�");
+        }
+        this.save(assignEquipmentFileStream);
+        System.out.println("璁惧缁撴瀯鏍戞寚娲句骇鍝佺粨鏋勬爲锛�" + assignEquipmentFileStream.getId());
+        flowCommonService.initActBusiness("璁惧缁撴瀯鏍戞寚娲句骇鍝佺粨鏋勬爲:"+docInfo.getDocName()+"->"+productDocInfo.getDocName(),
+                assignEquipmentFileStream.getId(), "IAssignEquipmentFileStreamService", "nc_assign_equipment_file_stream", null);
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("dataId", assignEquipmentFileStream.getId());
+        variables.put("organization", assignEquipmentFileStream.getApplyReason());
+        variables.put("comment", assignEquipmentFileStream.getApplyReason());
+        variables.put("proofreading",true);
+        Result result= flowDefinitionService.startProcessInstanceByKey("nc_assign_equipment_file_stream", variables);
+        if (!result.isSuccess()) {
+            super.removeById(assignEquipmentFileStream.getId());
+        }
+        return result;
+    }
+
+    /**
+     * 娴佺▼鑺傜偣瀹℃牳
+     * @param assignEquipmentFileStreamVo
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public Result<?> auditAssignEquipmentFileStream(AssignEquipmentFileStreamVo assignEquipmentFileStreamVo){
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        try {
+            // 鍙傛暟鏍¢獙
+            if (!ValidateUtil.validateString(assignEquipmentFileStreamVo.getTaskId()) || !ValidateUtil.validateString(assignEquipmentFileStreamVo.getDataId())) {
+                return Result.error(CommonCode.INVALID_PARAM.toString());
+            }
+            String userId = user.getId();
+            assignEquipmentFileStreamVo.setAssignee(user.getUsername());
+            if (!ValidateUtil.validateString(userId)) {
+                return Result.error(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST.toString());
+            }
+
+            // 鏁版嵁鏌ヨ
+            AssignEquipmentFileStream assignEquipmentFileStream = this.getById(assignEquipmentFileStreamVo.getDataId());
+            if (assignEquipmentFileStream == null) {
+                return Result.error(CommonCode.INVALID_PARAM.toString());
+            }
+            //鑾峰彇璁惧
+            MdcEquipment equipment = mdcEquipmentService.getById(assignEquipmentFileStream.getEquipmentId());
+            if(equipment==null){
+                return Result.error("鏈彂鐜拌璁惧");
+            }
+            //鑾峰彇璁惧鏂囨。淇℃伅
+            DocInfo docInfo =docInfoService.getById(assignEquipmentFileStream.getEquipmentDocId());
+            if(docInfo==null){
+                return Result.error("鏈彂鐜拌璁惧瀵瑰簲鏂囨。");
+            }
+            //鑾峰彇璁惧鏂囦欢淇℃伅
+            DocFile docFile =docFileService.getById(assignEquipmentFileStream.getEquipmentFileId());
+            if(docFile==null){
+                return Result.error("鏈彂鐜拌璁惧瀵瑰簲鏂囦欢");
+            }
+            //鑾峰彇浜у搧鏂囨。淇℃伅
+            DocRelative docRelative=docRelativeService.getById(assignEquipmentFileStream.getDocId());
+            DocInfo productDocInfo =docInfoService.getById(docRelative.getDocId());
+            if(productDocInfo==null){
+                return Result.error("鏈彂鐜拌浜у搧缁撴瀯鏍戝搴旀枃妗�");
+            }
+            //鑾峰彇璁惧
+            MdcEquipment mdcEquipment =mdcEquipmentService.getById(assignEquipmentFileStream.getEquipmentId());
+            if (mdcEquipment==null){
+                return Result.error("鏈彂鐜拌璁惧");
+            }
+            // 2. 鏌ヨ娴佺▼涓氬姟璁板綍锛堝鐞嗙┖缁撴灉锛�
+            List<FlowMyBusiness> businessList = flowMyBusinessService.list(
+                    new QueryWrapper<FlowMyBusiness>()
+                            .eq("process_instance_id", assignEquipmentFileStreamVo.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", assignEquipmentFileStream.getId());
+            values.put("assignee", userId);
+            values.put("comment", assignEquipmentFileStreamVo.getComment());
+            values.put("organization", assignEquipmentFileStreamVo.getComment());
+            assignEquipmentFileStreamVo.setValues(values);
+            // 瀹屾垚娴佺▼浠诲姟
+            Result result = flowTaskService.complete(assignEquipmentFileStreamVo);
+            if (result.isSuccess()) {
+                this.updateById(assignEquipmentFileStream);
+                if (assignEquipmentFileStreamVo.getAuditType().equals("1")) {
+                    //1.浜у搧缁撴瀯鏍憂c鏂囦欢杩涜鍗囩増
+                    DocFile productDocFile = new DocFile();
+                    productDocFile.setDocId(productDocInfo.getDocId());
+                    productDocFile.setFileName(docFile.getFileName());
+                    productDocFile.setFileEncodeName(docFile.getFileEncodeName());
+                    productDocFile.setFilePath(docFile.getFilePath());
+                    productDocFile.setFileSize(docFile.getFileSize());
+                    productDocFile.setFileSuffix(docFile.getFileSuffix());
+                    docFileService.addDocFile(productDocFile);
+                    productDocInfo.setPublishVersion(productDocFile.getDocVersion());
+                    productDocInfo.setPublishFileId(productDocFile.getFileId());
+                    docInfoService.updateById(productDocInfo);
+                }
+            } else {
+                return result;
+            }
+            return Result.OK("鎿嶄綔鎴愬姛");
+        }  catch (Exception e) {
+            try {
+                TransactionStatus transactionStatus = TransactionAspectSupport.currentTransactionStatus();
+                if (!transactionStatus.isCompleted()) {
+                    transactionStatus.setRollbackOnly();
+                }
+            } catch (NoTransactionException ex) {
+                // 蹇界暐鏃犱簨鍔$殑寮傚父
+            }
+            log.error("瀹℃牳澶辫触", e);
+            return Result.error("鎿嶄綔澶辫触锛�" + e.getMessage());
+        }
+    }
+
+
+    //浼犲弬楠岃瘉
+    public boolean checkParam(AssignEquipmentFileStream assignEquipmentFileStream) {
+        if (assignEquipmentFileStream == null) {
+            ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        }
+        if (!ValidateUtil.validateString(assignEquipmentFileStream.getEquipmentId()) || !ValidateUtil.validateString(assignEquipmentFileStream.getDocId())
+                || !ValidateUtil.validateString(assignEquipmentFileStream.getEquipmentFileId()) || !ValidateUtil.validateString(assignEquipmentFileStream.getEquipmentDocId())) {
+            ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        }
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String userId = user.getId();
+        if (!ValidateUtil.validateString(userId)) {
+            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
+        }
+        return true;
+    }
+
+    @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