From 295bf6f10ad0b668d2dbaa4525a15d6d52807ef1 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 20 八月 2025 14:24:42 +0800
Subject: [PATCH] 导入工控网,附件改名

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/excution/StartDispatcher.java |  185 ++++++++++++++++++++++++++++++----------------
 1 files changed, 120 insertions(+), 65 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/excution/StartDispatcher.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/excution/StartDispatcher.java
index bc6ce9d..4aa863c 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/excution/StartDispatcher.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/excution/StartDispatcher.java
@@ -1,88 +1,143 @@
 package org.springblade.mdm.flow.excution;
 
 import io.swagger.v3.oas.annotations.media.Schema;
-import org.flowable.common.engine.impl.identity.Authentication;
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 import org.flowable.engine.IdentityService;
 import org.flowable.engine.runtime.ProcessInstance;
 import org.springblade.core.secure.utils.AuthUtil;
-import org.springblade.core.tool.api.R;
-import org.springblade.flow.core.feign.IFlowClient;
-import org.springblade.flow.core.pojo.entity.BladeFlow;
-import org.springblade.flow.core.utils.TaskUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.mdm.basesetting.producedivision.entity.ProduceDivision;
+import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService;
+import org.springblade.mdm.flow.constants.FlowContants;
+import org.springblade.mdm.flow.entity.FlowProgramFile;
+import org.springblade.mdm.flow.service.FlowCommonService;
+import org.springblade.mdm.flow.service.FlowProgramFileService;
 import org.springblade.mdm.flow.vo.TaskAssignVO;
-import org.springblade.mdm.program.entity.NcProgram;
-import org.springblade.mdm.program.service.NcProgramService;
+import org.springblade.mdm.program.entity.NcNode;
+import org.springblade.mdm.program.service.NcNodeService;
+import org.springblade.mdm.program.service.NodeDeptQueryService;
+import org.springblade.mdm.utils.EntityUtil;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.flowable.engine.RuntimeService;
+import org.springframework.transaction.annotation.Transactional;
+
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+@AllArgsConstructor
 @Service("startDispatcher")
 public class StartDispatcher  {
 
-	@Autowired
-	private RuntimeService runtimeService;
-	@Autowired
-	private AutoAssignUsersService autoAssignUsersService;
-	@Autowired
-	private IdentityService identityService;
+	private final RuntimeService runtimeService;
+	private final AutoAssignUsersService autoAssignUsersService;
 
-	@Autowired
-	private NcProgramService ncProgramService;
-	private static final String PROCESS_KEY = "dispatch";
+	private final IdentityService identityService;
+	private final NcNodeService ncNodeService;
 
-	public void start(TaskAssignVO startVO){
-
-		Map<String,Object> preAssignee = autoAssignUsersService.autoAssignUsers(startVO.getProducePlanId());
-		Map<String, Object> vars = new HashMap<>(preAssignee);
-
-		vars.put("machineCode",startVO.getMachineCode());
-		vars.put("machineMode",startVO.getMachineMode());
-
-		vars.put("processNo",startVO.getProcessNo());
-		vars.put("processName",startVO.getProcessName());
-		vars.put("processEdition",startVO.getProcessEdition());
-
-		vars.put("craftEdition",startVO.getCraftEdition());
-		vars.put("planStartTime",startVO.getPlanStartTime());
-		vars.put("drawingNo",startVO.getDrawingNo());
-		vars.put("drawingNoEdition",startVO.getDrawingNoEdition());
-		vars.put("planLockDays",startVO.getPlanLockDays());
-
-		//闆剁粍浠朵唬鐮�
-		String partNo = generatePartNo(startVO);
-		vars.put("partNo",partNo);
-
-		NcProgram curedNcProgram = ncProgramService.getCuredNcProgram(partNo,startVO.getMachineCode());
-		vars.put("curedNcProgram",curedNcProgram);
-
-		//璁剧疆鏄惁鏈夊浐鍖栫▼搴忔爣璁�
-		vars.put("hasCuredProgram",curedNcProgram != null ? "Y":"N");
-
-		String businessKey = "0";//涓氬姟琛╧ey
-
-		identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//璁剧疆娴佺▼鍙戣捣浜�
-		ProcessInstance pinst = runtimeService.startProcessInstanceByKey(PROCESS_KEY,businessKey,vars);
-
-		int a=1;
-		//log.info()
-	}
+	private final FlowProgramFileService flowProgramFileService;
+	private final NodeDeptQueryService nodeDeptQueryService;
+	private final ProduceDivisionService produceDivisionService;
+	private final FlowCommonService flowCommonService;
 
 	/**
-	 * 鐢熸垚闆剁粍浠剁紪鍙�
-	 * 鍥惧彿銆佸浘鍙风増娆°�佸伐搴忓彿銆佸伐搴忓悕绉般�佸伐鑹虹増娆°�佸伐搴忕増娆� 缁勫悎璧锋潵鑾峰緱闆剁粍浠跺彿
-	 * @param startVO
-	 * @return
+	 * 鍚姩娲惧伐娴佺▼
+	 * @param startVO 琛ㄥ崟鏁版嵁
+	 * @return 娴佺▼瀹炰緥id
 	 */
-	String generatePartNo(TaskAssignVO startVO){
-		//TODO 杩欎釜鏍煎紡鏈‘瀹氾紝闇�瑕佺‘璁�
-		return String.format("%s-%s-%s-%s-%s-%s",
-			startVO.getDrawingNo(),
-			startVO.getDrawingNoEdition(),
-			startVO.getProcessNo(),
-			startVO.getProcessName(),
-			startVO.getCraftEdition(),
-			startVO.getProcessEdition());
+	@Transactional
+	public String start(TaskAssignVO startVO){
+		Map<String, Object> vars = new HashMap<>();
+
+		ProduceDivision div = flowCommonService.putDefaultAssignees(vars,startVO.getDrawingNo(),null);
+		vars.put(FlowContants.ASSIGNEE,div.getTeamLeaderId());//绗竴涓敤鎴风粍闀�
+		vars.put(FlowContants.TITLE,startVO.getTitle());
+
+		//涓存椂娴佺▼鏍囧織锛屾槑纭寚瀹歒锛屽睘浜庝复鏃舵祦绋�
+		vars.put(FlowContants.IS_TEMP_FLOW,FlowContants.Y.equals(startVO.getIsTempFlow())?FlowContants.Y:FlowContants.N);
+		//鏈哄簥缂栧彿
+		vars.put(FlowContants.MACHINE_CODE,startVO.getMachineCode());
+		String workshop = nodeDeptQueryService.getWorkshopNameByMachineCode(startVO.getMachineCode());
+		vars.put(FlowContants.WORKSHOP,workshop);
+		//鏈哄簥鍨嬪彿
+		vars.put(FlowContants.MACHINE_MODE,startVO.getMachineMode());
+
+		vars.put(FlowContants.PROCESS_NO,startVO.getProcessNo());
+		vars.put(FlowContants.PROCESS_NAME,startVO.getProcessName());
+		vars.put(FlowContants.PROCESS_EDITION,startVO.getProcessEdition());
+		vars.put(FlowContants.CRAFT_EDITION,startVO.getCraftEdition());
+		vars.put("planStartTime",startVO.getPlanStartTime());
+		vars.put(FlowContants.DRAWING_NO,startVO.getDrawingNo());
+		vars.put(FlowContants.DRAWING_NO_EDITION,startVO.getDrawingNoEdition());
+		vars.put("planLockDays",startVO.getPlanLockDays());
+		vars.put(FlowContants.PRODUCT_MODEL,startVO.getProductModel());
+
+		if(StringUtils.isNotBlank(startVO.getDeviation())) {
+			vars.put(FlowContants.DEVIATION, startVO.getDeviation());//鍋忕鍗�
+		}
+		String programPkgName = NcNodeService.genProgramName(startVO.getDrawingNo(),startVO.getProcessNo());
+		vars.put(FlowContants.PROGRAM_PACKAGE_NAME,programPkgName);
+
+		NcNode curedProgramPackage = ncNodeService.getCuredProgramPackage(programPkgName,startVO.getMachineCode());
+		//璁剧疆鏄惁鏈夊浐鍖栫▼搴忔爣璁�
+		vars.put(FlowContants.HAS_CURED_PROGRAM,curedProgramPackage != null ? FlowContants.Y:FlowContants.N);
+		//宸ュ簭鐗堟鏄惁涓�鑷达紝鏄惁鍦ㄦ湁鏁堟湡鍐�
+		if(curedProgramPackage != null && Func.isBlank(startVO.getDeviation())){//鍋忕鍗曚紭鍏堬紝濡傛灉鏈夊亸绂诲崟锛岄偅涔堟壘鍒板浐鍖栫▼搴忕殑涔熶笉绠楀浐鍖栦簡
+			vars.put(FlowContants.CURED_NODE_ID,curedProgramPackage.getId());
+			vars.put(FlowContants.IS_PROCESS_EDITION_SAME, StringUtils.equals(curedProgramPackage.getProcessEdition(),startVO.getProcessEdition()) ? "Y":"N");
+			vars.put(FlowContants.VALIDITY_PERIOD, curedProgramPackage.withinValidityPeriod() ? FlowContants.Y:FlowContants.N);
+		}else{
+			vars.put(FlowContants.IS_PROCESS_EDITION_SAME, FlowContants.Y);
+			vars.put(FlowContants.VALIDITY_PERIOD, FlowContants.Y);
+		}
+		String myProcessName = "璇曞垏涓嬪彂娴佺▼";
+		if(vars.getOrDefault(FlowContants.HAS_CURED_PROGRAM,FlowContants.N).equals(FlowContants.Y)){
+			myProcessName = "鍥哄寲涓嬪彂娴佺▼";
+		}
+		if(StringUtils.isNotBlank(startVO.getDeviation()) ){
+			myProcessName = "鍋忕鍗�";
+		}
+		vars.put(FlowContants.MY_PROCESS_NAME, myProcessName);
+
+		String businessKey = "0";//涓氬姟琛╧ey
+		identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//璁剧疆娴佺▼鍙戣捣浜�
+		ProcessInstance inst = runtimeService.startProcessInstanceByKey(FlowContants.TRY_PROCESS_KEY,businessKey,vars);
+
+		if(curedProgramPackage != null) {//瀛樺湪宸插浐鍖栫▼搴忥紝澶嶅埗鍘熸潵鐨勭▼搴忔枃浠躲��
+			copyFlowProgramFiles(curedProgramPackage.getId(),inst.getProcessInstanceId());
+
+			curedProgramPackage.setProcessInstanceId(inst.getProcessInstanceId());
+			ncNodeService.updateById(curedProgramPackage);
+		}
+
+
+		return inst.getProcessInstanceId();
 	}
+
+
+	/**
+	 * 澶嶅埗娴佺▼绋嬪簭鏂囦欢
+	 * @param processInstanceId 鏂板惎鍔ㄧ殑娴佺▼id
+	 */
+	private void copyFlowProgramFiles(long packageNameNodeId,String processInstanceId) {
+		List<Long> fileIds = ncNodeService.getProgramFilesByPackageId(packageNameNodeId).stream().map(NcNode::getFlowProgramFileId).toList();
+		if(!fileIds.isEmpty()) {
+			List<FlowProgramFile> fileList = flowProgramFileService.lambdaQuery().in(FlowProgramFile::getId, fileIds).list();
+
+			for (FlowProgramFile file : fileList) {
+				FlowProgramFile newFile = new FlowProgramFile();
+				BeanUtils.copyProperties(file, newFile);
+				EntityUtil.clearBaseProperties(newFile);
+
+				newFile.setProcessInstanceId(processInstanceId);
+
+				this.flowProgramFileService.save(newFile);
+			}
+		}
+	}
+
+
 }

--
Gitblit v1.9.3