¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.tms.service.impl; |
| | | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | 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.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | 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.service.ISysBusinessCodeRuleService; |
| | | import org.jeecg.modules.tms.entity.ToolLedger; |
| | | import org.jeecg.modules.tms.entity.ToolLedgerDetail; |
| | | import org.jeecg.modules.tms.entity.ToolsLossBound; |
| | | import org.jeecg.modules.tms.entity.ToolsLossBoundDetail; |
| | | import org.jeecg.modules.tms.entity.dto.LossBoundFlowDto; |
| | | import org.jeecg.modules.tms.enums.OutBillStatus; |
| | | import org.jeecg.modules.tms.enums.OutBoundStatusEnum; |
| | | import org.jeecg.modules.tms.mapper.ToolsLossBoundDetailMapper; |
| | | import org.jeecg.modules.tms.mapper.ToolsLossBoundMapper; |
| | | import org.jeecg.modules.tms.service.IToolLedgerDetailService; |
| | | import org.jeecg.modules.tms.service.IToolLedgerService; |
| | | import org.jeecg.modules.tms.service.IToolsLossBoundDetailService; |
| | | import org.jeecg.modules.tms.service.IToolsLossBoundService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @Description: æèå |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-05-21 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service("IToolsLossBoundService") |
| | | public class ToolsLossBoundServiceImpl extends ServiceImpl<ToolsLossBoundMapper, ToolsLossBound> implements IToolsLossBoundService, FlowCallBackServiceI { |
| | | |
| | | @Autowired |
| | | private ToolsLossBoundMapper baseMapper; |
| | | |
| | | @Autowired |
| | | private ToolsLossBoundDetailMapper baseDetailMapper; |
| | | @Autowired |
| | | private IToolsLossBoundDetailService toolsLossBoundDetailService; |
| | | @Resource |
| | | private FlowCommonService flowCommonService; |
| | | @Resource |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | @Autowired |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Autowired |
| | | private IToolLedgerService toolLedgerService; |
| | | |
| | | @Autowired |
| | | private IToolLedgerDetailService toolLedgerDetailService; |
| | | |
| | | @Override |
| | | public void delMain(String id) { |
| | | baseDetailMapper.deleteByMainId(id); |
| | | baseMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void delBatchMain(Collection<? extends Serializable> idList) { |
| | | for (Serializable id : idList) { |
| | | baseDetailMapper.deleteByMainId(id.toString()); |
| | | baseMapper.deleteById(id); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void addTotal(ToolsLossBound toolsLossBound) { |
| | | LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (loginUser != null) { |
| | | toolsLossBound.setHandler(loginUser.getId()); |
| | | } |
| | | toolsLossBound.setOrderCode(businessCodeRuleService.generateBusinessCodeSeq("LossBound")); |
| | | toolsLossBound.setOrderStatus(OutBillStatus.DRAFT.getValue()); |
| | | save(toolsLossBound); |
| | | |
| | | List<ToolsLossBoundDetail> detailList = toolsLossBound.getToolsLossBoundDetailList(); |
| | | List<ToolsLossBoundDetail> newDetailList = new ArrayList<>(); |
| | | |
| | | if (CollectionUtils.isNotEmpty(detailList)) { |
| | | detailList.forEach(item -> { |
| | | item.setLossBoundId(toolsLossBound.getId()); |
| | | newDetailList.add(item); |
| | | }); |
| | | |
| | | toolsLossBoundDetailService.saveBatch(newDetailList); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public IPage<ToolsLossBound> queryPageList(Page<ToolsLossBound> page, Map<String, String[]> parameterMap) { |
| | | QueryWrapper<ToolsLossBound> queryWrapper = Wrappers.query(); |
| | | String[] orderCode = parameterMap.get("orderCode"); |
| | | if (orderCode != null && orderCode.length > 0) { |
| | | queryWrapper.like("t.order_code", orderCode[0]); |
| | | } |
| | | String[] statuses = parameterMap.get("orderStatus"); |
| | | if (statuses != null && statuses.length > 0) { |
| | | queryWrapper.eq("t.order_status", statuses[0]); |
| | | } |
| | | return this.baseMapper.queryPageList(page, queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public void editTotal(ToolsLossBound toolsLossBound) { |
| | | //å 餿ææç» |
| | | toolsLossBoundDetailService.remove(new LambdaQueryWrapper<ToolsLossBoundDetail>().eq(ToolsLossBoundDetail::getLossBoundId, toolsLossBound.getId())); |
| | | ToolsLossBound toolsLossBound1 = BeanUtil.copyProperties(toolsLossBound, ToolsLossBound.class); |
| | | this.baseMapper.updateById(toolsLossBound1); |
| | | List<ToolsLossBoundDetail> detailList = CollectionUtil.newArrayList(); |
| | | toolsLossBound.getToolsLossBoundDetailList().forEach(item -> { |
| | | item.setLossBoundId(toolsLossBound1.getId()); |
| | | detailList.add(item); |
| | | }); |
| | | toolsLossBoundDetailService.saveBatch(detailList); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean submintOrder(String id) { |
| | | |
| | | ToolsLossBound toolsLossBound = this.getById(id); |
| | | if (toolsLossBound == null) { |
| | | return false; |
| | | } else { |
| | | toolsLossBound.setReviewer(toolsLossBound.getReviewer()); |
| | | |
| | | flowCommonService.initActBusiness("æ¥æåå·:" + toolsLossBound.getOrderCode() + ";æ¥æäºº: " + toolsLossBound.getLosser() + ";è¿è¡æ¥æ", toolsLossBound.getId(), "IToolsStocktakingBoundService", "tools_Loss_Approval", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", toolsLossBound.getId()); |
| | | if (StrUtil.isEmpty(toolsLossBound.getReviewer())) { |
| | | variables.put("organization", "æ°å¢å·¥å
·æ¥æåé»è®¤å¯å¨æµç¨"); |
| | | variables.put("comment", "æ°å¢å·¥å
·æ¥æåé»è®¤å¯å¨æµç¨"); |
| | | } else { |
| | | variables.put("organization", toolsLossBound.getLossReason()); |
| | | variables.put("comment", toolsLossBound.getLossReason()); |
| | | } |
| | | variables.put("proofreading", true); |
| | | List<String> usernames = new ArrayList<>(); |
| | | usernames.add(toolsLossBound.getReviewer()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("tools_Loss_Approval", variables); |
| | | if (result != null) { |
| | | toolsLossBound.setLossTime(new Date()); |
| | | toolsLossBound.setOrderStatus(OutBillStatus.SUBMITTED.getValue()); |
| | | //ä¿åå·¥å |
| | | baseMapper.updateById(toolsLossBound); |
| | | return result.isSuccess(); |
| | | } |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void approvalProcess(LossBoundFlowDto lossBoundFlowDto) { |
| | | if (StrUtil.isBlank(lossBoundFlowDto.getTaskId()) || StrUtil.isBlank(lossBoundFlowDto.getDataId())) { |
| | | throw new JeecgBootException("鿳忰ï¼"); |
| | | } |
| | | |
| | | // è·åå½åç»å½ç¨æ· |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null || StrUtil.isBlank(user.getId())) { |
| | | throw new JeecgBootException("è´¦å·ä¸åå¨"); |
| | | } |
| | | |
| | | //è·åæ¥æåä¿¡æ¯ |
| | | ToolsLossBound toolsLossBound = getById(lossBoundFlowDto.getDataId()); |
| | | if (toolsLossBound == null) { |
| | | throw new JeecgBootException("æªæ¾å°å¯¹åºçåºåºç³è¯·åï¼"); |
| | | } |
| | | |
| | | //è·åæµç¨ä¸å¡è®°å½ |
| | | FlowMyBusiness flowMyBusiness = getFlowMyBusiness(lossBoundFlowDto.getInstanceId()); |
| | | if (flowMyBusiness == null) { |
| | | throw new JeecgBootException("æµç¨è®°å½ä¸åå¨"); |
| | | } |
| | | |
| | | // æ£æ¥ç¨æ·æ¯å¦ææéæä½ä»»å¡ |
| | | if (!isUserAuthorized(flowMyBusiness, user)) { |
| | | throw new JeecgBootException("ç¨æ·æ ææä½æ¤ä»»å¡"); |
| | | } |
| | | |
| | | // 认é¢ä»»å¡ |
| | | if (!claimTask(flowMyBusiness.getTaskId(), user)) { |
| | | throw new JeecgBootException("ä»»å¡ä¸åå¨ã已宿æå·²è¢«ä»äººè®¤é¢"); |
| | | } |
| | | |
| | | //设置æµç¨åé |
| | | setupProcessVariables(lossBoundFlowDto, toolsLossBound, user); |
| | | |
| | | //宿æµç¨ä»»å¡ |
| | | Result result = flowTaskService.complete(lossBoundFlowDto); |
| | | |
| | | //æ ¹æ®ä»»å¡å®æç»ææ´æ°ç³è¯·åç¶æ |
| | | if (result.isSuccess()) { |
| | | toolsLossBound.setOrderStatus(lossBoundFlowDto.getStatus()); |
| | | if (OutBillStatus.APPROVED.getValue().equals(lossBoundFlowDto.getStatus())) { |
| | | toolsLossBound.setOrderStatus(OutBoundStatusEnum.NOT_OUTBOUND.getValue()); |
| | | } |
| | | /** |
| | | * æ´æ°å®¡æ¹æ¶é´ãå®¡æ¹æè§ æ´æ°åºåæ£å åºåæ»æ° |
| | | * è·åå·¥å
·æç»å表ï¼éåæ¯ä¸ªå·¥å
·æç»ï¼æ´æ°å¯¹åºçå·¥å
·åºåè®°å½ã |
| | | * å¯¹äºæ¯ä¸ªå·¥å
·ï¼è·å对åºçå·¥å
·åºåè®°å½ï¼ToolLedgerï¼ï¼å¹¶æ´æ°æ»åºåæ°éï¼totalCountï¼åæå¤±æ°éï¼lossCountï¼ã |
| | | * ç¡®ä¿å¨æ´æ°æ»åºåæ°éä¹åï¼æ£æ¥æ»åºåæ°éæ¯å¦å¤§äºæçäºæå¤±æ°éã妿䏿»¡è¶³æ¡ä»¶ï¼æåºå¼å¸¸æè¿è¡å
¶ä»å¤çã |
| | | * æåï¼ä¿åæ´æ°åçå·¥å
·åºåè®°å½ã |
| | | */ |
| | | |
| | | List<ToolsLossBoundDetail> detailList = toolsLossBound.getToolsLossBoundDetailList(); |
| | | |
| | | if (CollectionUtils.isEmpty(detailList)) { |
| | | throw new JeecgBootException("æ¥ææç»ä¸ºç©ºï¼æ æ³è¿è¡åºåæ£å"); |
| | | } |
| | | Map<String, BigDecimal> toolLossMap = new HashMap<>(); |
| | | for (ToolsLossBoundDetail item : detailList) { |
| | | if (item.getToolId() == null || item.getLossNumber() == null) { |
| | | continue; // |
| | | } |
| | | toolLossMap.put(item.getToolId(), toolLossMap.getOrDefault(item.getToolId(), BigDecimal.ZERO).add(item.getLossNumber())); |
| | | } |
| | | /** |
| | | * éåæ¯ä¸ª toolIdï¼æ´æ°å¯¹åºç ToolLedger |
| | | */ |
| | | for (Map.Entry<String, BigDecimal> entry : toolLossMap.entrySet()) { |
| | | String toolId = entry.getKey(); |
| | | BigDecimal totalLossNumber = entry.getValue(); |
| | | |
| | | ToolLedger toolLedger = toolLedgerService.getOne(new QueryWrapper<ToolLedger>().eq("id", toolId)); |
| | | if (toolLedger == null) { |
| | | throw new JeecgBootException("æªæ¾å°å¯¹åºçå·¥å
·åºåè®°å½ï¼toolIdï¼" + toolId); |
| | | } |
| | | |
| | | // æ£åæ»åºå |
| | | if (toolLedger.getTotalCount() != null && toolLedger.getTotalCount().compareTo(totalLossNumber) >= 0) { |
| | | toolLedger.setTotalCount(toolLedger.getTotalCount().subtract(totalLossNumber)); |
| | | toolLedger.setLossCount(toolLedger.getLossCount().add(totalLossNumber)); |
| | | } else { |
| | | throw new JeecgBootException("åºåä¸è¶³ï¼æ æ³å®ææ¥ææä½ï¼toolIdï¼" + toolId); |
| | | } |
| | | |
| | | // æ´æ°æ°æ®åºä¸ç ToolLedger |
| | | toolLedgerService.updateById(toolLedger); |
| | | /** |
| | | * æ°å¢é»è¾ï¼æ´æ°å°è´¦æç»è¡¨ ToolLedgerDetail ä¸çç¶æåæ®µä¸º 6 |
| | | */ |
| | | UpdateWrapper<ToolLedgerDetail> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("tool_id", toolId) |
| | | .set("status", 6); // ç¶æè®¾ç½®ä¸º 6 |
| | | |
| | | toolLedgerDetailService.update(updateWrapper); |
| | | } |
| | | |
| | | toolsLossBound.setApprovalDate(new Date()); |
| | | toolsLossBound.setApprovalOpinion(lossBoundFlowDto.getApprovalOpinion()); |
| | | updateById(toolsLossBound); |
| | | } |
| | | } |
| | | |
| | | private void setupProcessVariables(LossBoundFlowDto lossBoundFlowDto, ToolsLossBound toolsLossBound, LoginUser user) { |
| | | if (OutBillStatus.SUBMITTED.getValue().equals(toolsLossBound.getOrderStatus()) && user.getUsername().equals(toolsLossBound.getReviewer())) { |
| | | Map<String, Object> values = new HashMap<>(); |
| | | values.put("dataId", toolsLossBound.getId()); |
| | | values.put("organization", lossBoundFlowDto.getApprovalOpinion()); |
| | | values.put("comment", lossBoundFlowDto.getApprovalOpinion()); |
| | | values.put("status", lossBoundFlowDto.getStatus()); |
| | | values.put("NextAssignee", Collections.singletonList(toolsLossBound.getReviewer())); |
| | | lossBoundFlowDto.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; |
| | | } |
| | | } |