| | |
| | | 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 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.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 javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Autowired |
| | | private IToolLedgerService toolLedgerService; |
| | | |
| | | @Autowired |
| | | private IToolLedgerDetailService toolLedgerDetailService; |
| | | |
| | | @Override |
| | | public void delMain(String id) { |
| | |
| | | @Override |
| | | public void editTotal(ToolsLossBound toolsLossBound) { |
| | | //删除所有明细 |
| | | toolsLossBoundDetailService.remove(new LambdaQueryWrapper<ToolsLossBoundDetail>() |
| | | .eq(ToolsLossBoundDetail::getLossBoundId, toolsLossBound.getId())); |
| | | 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(); |
| | |
| | | } else { |
| | | toolsLossBound.setReviewer(toolsLossBound.getReviewer()); |
| | | |
| | | flowCommonService.initActBusiness("报损单号:" + toolsLossBound.getOrderCode() + ";报损人: " + toolsLossBound.getLosser() + ";进行报损", |
| | | toolsLossBound.getId(), "IToolsStocktakingBoundService", "tools_Loss_Approval", null); |
| | | 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())) { |
| | |
| | | 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 FlowMyBusiness getFlowMyBusiness(String instanceId) { |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new LambdaQueryWrapper<FlowMyBusiness>().eq(FlowMyBusiness::getProcessInstanceId, instanceId)); |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list(new LambdaQueryWrapper<FlowMyBusiness>().eq(FlowMyBusiness::getProcessInstanceId, instanceId)); |
| | | return businessList.isEmpty() ? null : businessList.get(0); |
| | | } |
| | | |