| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.approve.mapper.ApproveProcessMapper; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | |
| | | private ApproveProcessServiceImpl approveProcessService; |
| | | @Autowired |
| | | private StockUtils stockUtils; |
| | | @Autowired |
| | | private ISalesLedgerService salesLedgerService; |
| | | |
| | | |
| | | @GetMapping("/listPage") |
| | |
| | | @Log(title = "发货信息管理", businessType = BusinessType.INSERT) |
| | | public AjaxResult add(@RequestBody ShippingInfoDto req) throws Exception { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH","shipping_no"); |
| | | // 发货审批 |
| | | ApproveProcessVO approveProcessVO = new ApproveProcessVO(); |
| | | approveProcessVO.setApproveType(7); |
| | | approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId()); |
| | | // 审批原因格式:发货单号:{发货类型}:{发货车牌号} |
| | | String approveReason = "发货单号:" + sh + "\n" + req.getType(); |
| | | if ("货车".equals(req.getType()) && req.getShippingCarNumber() != null) { |
| | | approveReason += ":" + req.getShippingCarNumber(); |
| | | } else if ("快递".equals(req.getType()) && req.getExpressCompany() != null) { |
| | | approveReason += ":" + req.getExpressCompany(); |
| | | |
| | | // 查询销售单号 |
| | | String salesContractNo = ""; |
| | | if (req.getSalesLedgerId() != null) { |
| | | SalesLedger salesLedger = salesLedgerService.getById(req.getSalesLedgerId()); |
| | | if (salesLedger != null) { |
| | | salesContractNo = salesLedger.getSalesContractNo(); |
| | | } |
| | | } |
| | | approveProcessVO.setApproveReason(approveReason); |
| | | approveProcessVO.setApproveUserIds(req.getApproveUserIds()); |
| | | approveProcessVO.setApproveUser(loginUser.getUserId()); |
| | | approveProcessVO.setApproveTime(LocalDate.now().toString()); |
| | | approveProcessService.addApprove(approveProcessVO); |
| | | // 添加发货消息 |
| | | |
| | | String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH", "shipping_no"); |
| | | |
| | | // 查询该销售合同下是否有"待审核"的发货记录,用于合并审批(需审批人相同) |
| | | boolean shouldMergeApproval = false; |
| | | ApproveProcess existingApprove = null; |
| | | List<ShippingInfo> pendingShippings = shippingInfoMapper.selectList( |
| | | new LambdaQueryWrapper<ShippingInfo>() |
| | | .eq(ShippingInfo::getSalesLedgerId, req.getSalesLedgerId()) |
| | | .eq(ShippingInfo::getStatus, "待审核") |
| | | ); |
| | | if (!CollectionUtils.isEmpty(pendingShippings) && salesContractNo != null && !salesContractNo.isEmpty()) { |
| | | // 找到对应的审批流程(通过销售单号匹配,且审批人相同) |
| | | existingApprove = approveProcessService.getOne( |
| | | new LambdaQueryWrapper<ApproveProcess>() |
| | | .like(ApproveProcess::getApproveReason, "销售单号:" + salesContractNo) |
| | | .eq(ApproveProcess::getApproveType, 7) // 发货审批类型 |
| | | .eq(ApproveProcess::getApproveStatus, 0) // 待审核状态 |
| | | .eq(ApproveProcess::getApproveUser, loginUser.getUserId()) // 审批人相同 |
| | | .orderByDesc(ApproveProcess::getCreateTime) |
| | | .last("limit 1") |
| | | ); |
| | | if (existingApprove != null) { |
| | | shouldMergeApproval = true; |
| | | } |
| | | } |
| | | |
| | | // 生成当前发货信息的描述 |
| | | StringBuilder currentShippingDesc = new StringBuilder(); |
| | | currentShippingDesc.append("发货单号:").append(sh); |
| | | if (salesContractNo != null && !salesContractNo.isEmpty()) { |
| | | currentShippingDesc.append("\n销售单号:").append(salesContractNo); |
| | | } |
| | | currentShippingDesc.append("\n").append(req.getType()); |
| | | if ("货车".equals(req.getType()) && req.getShippingCarNumber() != null && !req.getShippingCarNumber().isEmpty()) { |
| | | currentShippingDesc.append(":").append(req.getShippingCarNumber()); |
| | | } else if ("快递".equals(req.getType()) && req.getExpressCompany() != null && !req.getExpressCompany().isEmpty()) { |
| | | currentShippingDesc.append(":").append(req.getExpressCompany()); |
| | | } |
| | | |
| | | if (shouldMergeApproval && existingApprove != null) { |
| | | // 合并审批:将被合并的发货单号添加到审批原因中 |
| | | String updatedReason = existingApprove.getApproveReason() + "\n\n" + currentShippingDesc.toString(); |
| | | existingApprove.setApproveReason(updatedReason); |
| | | approveProcessService.updateById(existingApprove); |
| | | } else { |
| | | // 创建新的审批流程 |
| | | ApproveProcessVO approveProcessVO = new ApproveProcessVO(); |
| | | approveProcessVO.setApproveType(7); |
| | | approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId()); |
| | | approveProcessVO.setApproveReason(currentShippingDesc.toString()); |
| | | approveProcessVO.setApproveUserIds(req.getApproveUserIds()); |
| | | approveProcessVO.setApproveUser(loginUser.getUserId()); |
| | | approveProcessVO.setApproveTime(LocalDate.now().toString()); |
| | | approveProcessService.addApprove(approveProcessVO); |
| | | } |
| | | |
| | | // 添加发货记录 |
| | | req.setShippingNo(sh); |
| | | req.setStatus("待审核"); |
| | | boolean save = shippingInfoService.save(req); |