From 0cb87e5f72febf26b3a17b4eb61e8d1b8c079279 Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期一, 26 五月 2025 10:03:44 +0800 Subject: [PATCH] 刀具刃磨-刃磨刀具选择列表接口/ 工具报损-审批、提交 工具盘点-审批 ,提交 --- lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/ToolsStocktakingBoundServiceImpl.java | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 99 insertions(+), 1 deletions(-) diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/ToolsStocktakingBoundServiceImpl.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/ToolsStocktakingBoundServiceImpl.java index 1548e1d..d263f68 100644 --- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/ToolsStocktakingBoundServiceImpl.java +++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/ToolsStocktakingBoundServiceImpl.java @@ -2,13 +2,18 @@ import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 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.exception.JeecgBootException; import org.jeecg.common.system.vo.LoginUser; 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; @@ -16,9 +21,13 @@ import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.service.ISysUserService; import org.jeecg.modules.tms.entity.BaseTools; +import org.jeecg.modules.tms.entity.ToolsLossBound; import org.jeecg.modules.tms.entity.ToolsStocktakingBound; import org.jeecg.modules.tms.entity.ToolsStocktakingBoundDetail; +import org.jeecg.modules.tms.entity.dto.LossBoundFlowDto; +import org.jeecg.modules.tms.entity.dto.StocktakingBoundFlowDto; import org.jeecg.modules.tms.enums.OutBillStatus; +import org.jeecg.modules.tms.enums.OutBoundStatusEnum; import org.jeecg.modules.tms.mapper.ToolsStocktakingBoundDetailMapper; import org.jeecg.modules.tms.mapper.ToolsStocktakingBoundMapper; import org.jeecg.modules.tms.service.IToolsStocktakingBoundService; @@ -53,6 +62,11 @@ private IFlowDefinitionService flowDefinitionService; @Autowired private IFlowTaskService flowTaskService; + @Autowired + private IFlowMyBusinessService flowMyBusinessService; + @Autowired + private TaskService taskService; + @Override @Transactional(rollbackFor = Exception.class) public void saveMain(ToolsStocktakingBound toolsStocktakingBound, List<ToolsStocktakingBoundDetail> toolsStocktakingBoundDetailList) { @@ -99,6 +113,7 @@ toolsStocktakingBoundMapper.deleteById(id); } } + @Override @Transactional(rollbackFor = Exception.class) public boolean submintOrder(String id) { @@ -140,13 +155,96 @@ } + @Override + public void approvalProcess(StocktakingBoundFlowDto stocktakingBoundFlowDto) { + if (StrUtil.isBlank(stocktakingBoundFlowDto.getTaskId()) || StrUtil.isBlank(stocktakingBoundFlowDto.getDataId())) { + throw new JeecgBootException("闈炴硶鍙傛暟锛�"); + } + // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛 + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if (user == null || StrUtil.isBlank(user.getId())) { + throw new JeecgBootException("璐﹀彿涓嶅瓨鍦�"); + } + //鑾峰彇鎶ユ崯鍗曚俊鎭� + ToolsStocktakingBound toolsStocktakingBound = getById(stocktakingBoundFlowDto.getDataId()); + if (toolsStocktakingBound == null) { + throw new JeecgBootException("鏈壘鍒板搴旂殑鍑哄簱鐢宠鍗曪紒"); + } + //鑾峰彇娴佺▼涓氬姟璁板綍 + FlowMyBusiness flowMyBusiness = getFlowMyBusiness(stocktakingBoundFlowDto.getInstanceId()); + if (flowMyBusiness == null) { + throw new JeecgBootException("娴佺▼璁板綍涓嶅瓨鍦�"); + } + + // 妫�鏌ョ敤鎴锋槸鍚︽湁鏉冮檺鎿嶄綔浠诲姟 + if (!isUserAuthorized(flowMyBusiness, user)) { + throw new JeecgBootException("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔�"); + } + + // 璁ら浠诲姟 + if (!claimTask(flowMyBusiness.getTaskId(), user)) { + throw new JeecgBootException("浠诲姟涓嶅瓨鍦ㄣ�佸凡瀹屾垚鎴栧凡琚粬浜鸿棰�"); + } + + //璁剧疆娴佺▼鍙橀噺 + setupProcessVariables(stocktakingBoundFlowDto, toolsStocktakingBound, user); + + //瀹屾垚娴佺▼浠诲姟 + Result result = flowTaskService.complete(stocktakingBoundFlowDto); + + //鏍规嵁浠诲姟瀹屾垚缁撴灉鏇存柊鐢宠鍗曠姸鎬� + if (result.isSuccess()) { + toolsStocktakingBound.setApprovalStatus(stocktakingBoundFlowDto.getStatus()); + if (OutBillStatus.APPROVED.getValue().equals(stocktakingBoundFlowDto.getStatus())) { + toolsStocktakingBound.setApprovalStatus(OutBoundStatusEnum.NOT_OUTBOUND.getValue()); + } + toolsStocktakingBound.setApprovalDate(new Date()); + toolsStocktakingBound.setApprovalOpinion(stocktakingBoundFlowDto.getApprovalOpinion()); + updateById(toolsStocktakingBound); + } + } + + private void setupProcessVariables(StocktakingBoundFlowDto stocktakingBoundFlowDto, ToolsStocktakingBound toolsStocktakingBound, LoginUser user) { + if (OutBillStatus.SUBMITTED.getValue().equals(toolsStocktakingBound.getApprovalStatus()) && user.getUsername().equals(toolsStocktakingBound.getReviewer())) { + Map<String, Object> values = new HashMap<>(); + values.put("dataId", toolsStocktakingBound.getId()); + values.put("organization", stocktakingBoundFlowDto.getApprovalOpinion()); + values.put("comment", stocktakingBoundFlowDto.getApprovalOpinion()); + values.put("status", stocktakingBoundFlowDto.getStatus()); + values.put("NextAssignee", Collections.singletonList(toolsStocktakingBound.getReviewer())); + stocktakingBoundFlowDto.setValues(values); + } + } + + private FlowMyBusiness getFlowMyBusiness(String instanceId) { + List<FlowMyBusiness> businessList = flowMyBusinessService.list( + new LambdaQueryWrapper<FlowMyBusiness>().eq(FlowMyBusiness::getProcessInstanceId, instanceId)); + return businessList.isEmpty() ? null : businessList.get(0); + } + + private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) { + List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); + return todoUsers != null && todoUsers.contains(user.getUsername()); + } + + private boolean claimTask(String taskId, LoginUser user) { + Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); + if (task == null) { + return false; + } + if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { + return false; + } + taskService.claim(taskId, user.getUsername()); + return true; + } @Override public void afterFlowHandle(FlowMyBusiness business) { business.getTaskNameId();//鎺ヤ笅鏉ュ鎵圭殑鑺傜偣 - business.getValues();//鍓嶇浼犺繘鏉ョ殑鍙傛暟 + business.getValues(); business.getActStatus(); } -- Gitblit v1.9.3