¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.tms.service.impl; |
| | | |
| | | |
| | | 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; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | 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; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @Description: çç¹å表 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-05-16 |
| | | * @Version: V1.0 |
| | | */ |
| | | |
| | | @Service("IToolsStocktakingBoundService") |
| | | public class ToolsStocktakingBoundServiceImpl extends ServiceImpl<ToolsStocktakingBoundMapper, ToolsStocktakingBound> implements IToolsStocktakingBoundService, FlowCallBackServiceI { |
| | | |
| | | |
| | | @Autowired |
| | | private ISysUserService systemUserService; |
| | | @Autowired |
| | | private ToolsStocktakingBoundMapper toolsStocktakingBoundMapper; |
| | | @Autowired |
| | | private ToolsStocktakingBoundDetailMapper toolsStocktakingBoundDetailMapper; |
| | | @Resource |
| | | private FlowCommonService flowCommonService; |
| | | @Resource |
| | | 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) { |
| | | toolsStocktakingBoundMapper.insert(toolsStocktakingBound); |
| | | if (toolsStocktakingBoundDetailList != null && toolsStocktakingBoundDetailList.size() > 0) { |
| | | for (ToolsStocktakingBoundDetail entity : toolsStocktakingBoundDetailList) { |
| | | //å¤é®è®¾ç½® |
| | | entity.setGoodsShelvesId(toolsStocktakingBound.getId()); |
| | | toolsStocktakingBoundDetailMapper.insert(entity); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateMain(ToolsStocktakingBound toolsStocktakingBound, List<ToolsStocktakingBoundDetail> toolsStocktakingBoundDetailList) { |
| | | toolsStocktakingBoundMapper.updateById(toolsStocktakingBound); |
| | | |
| | | //1.å
å é¤åè¡¨æ°æ® |
| | | toolsStocktakingBoundDetailMapper.deleteByMainId(toolsStocktakingBound.getId()); |
| | | |
| | | //2.åè¡¨æ°æ®éæ°æå
¥ |
| | | if (toolsStocktakingBoundDetailList != null && toolsStocktakingBoundDetailList.size() > 0) { |
| | | for (ToolsStocktakingBoundDetail entity : toolsStocktakingBoundDetailList) { |
| | | //å¤é®è®¾ç½® |
| | | entity.setGoodsShelvesId(toolsStocktakingBound.getId()); |
| | | toolsStocktakingBoundDetailMapper.insert(entity); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delMain(String id) { |
| | | toolsStocktakingBoundDetailMapper.deleteByMainId(id); |
| | | toolsStocktakingBoundMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delBatchMain(Collection<? extends Serializable> idList) { |
| | | for (Serializable id : idList) { |
| | | toolsStocktakingBoundDetailMapper.deleteByMainId(id.toString()); |
| | | toolsStocktakingBoundMapper.deleteById(id); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean submintOrder(String id) { |
| | | |
| | | ToolsStocktakingBound toolsStocktakingBound = this.getById(id); |
| | | if (toolsStocktakingBound == null) { |
| | | return false; |
| | | } else { |
| | | toolsStocktakingBound.setReviewer(toolsStocktakingBound.getReviewer()); |
| | | //ä¿®æ¹ç¶æ |
| | | // toolsStocktakingBound.setApprovalStatus(OutBillStatus.SUBMITTED.getValue()); |
| | | flowCommonService.initActBusiness("çç¹åå·:" + toolsStocktakingBound.getOrderCode() + ";çç¹åç§°: " + toolsStocktakingBound.getStocktakingName() + ";è¿è¡çç¹", |
| | | toolsStocktakingBound.getId(), "IToolsStocktakingBoundService", "tools_stocktaking_bound", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", toolsStocktakingBound.getId()); |
| | | if (StrUtil.isEmpty(toolsStocktakingBound.getReviewer())) { |
| | | variables.put("organization", "æ°å¢å·¥å
·çç¹åé»è®¤å¯å¨æµç¨"); |
| | | variables.put("comment", "æ°å¢å·¥å
·çç¹åé»è®¤å¯å¨æµç¨"); |
| | | } else { |
| | | variables.put("organization", toolsStocktakingBound.getRemark()); |
| | | variables.put("comment", toolsStocktakingBound.getRemark()); |
| | | } |
| | | variables.put("proofreading", true); |
| | | List<String> usernames = new ArrayList<>(); |
| | | usernames.add(toolsStocktakingBound.getReviewer()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("tools_stocktaking_bound", variables); |
| | | if (result != null) { |
| | | toolsStocktakingBound.setInventoryTime(new Date()); |
| | | toolsStocktakingBound.setApprovalStatus(OutBillStatus.SUBMITTED.getValue()); |
| | | //ä¿åå·¥å |
| | | toolsStocktakingBoundMapper.updateById(toolsStocktakingBound); |
| | | return result.isSuccess(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @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.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) { |
| | | Object object = values.get("NextAssignee"); |
| | | return (List<String>) object; |
| | | } |
| | | } |