| | |
| | | import com.ruoyi.approve.mapper.ApprovalTemplateMapper; |
| | | import com.ruoyi.approve.pojo.ApprovalTemplate; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.pojo.ApprovalInstance; |
| | | import com.ruoyi.approve.service.ApprovalInstanceService; |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | import com.ruoyi.basic.enums.ApplicationTypeEnum; |
| | |
| | | import com.ruoyi.sales.dto.ShippingApproveDto; |
| | | import com.ruoyi.sales.dto.ShippingInfoDto; |
| | | import com.ruoyi.sales.dto.ShippingProductDetailDto; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.mapper.ShippingInfoMapper; |
| | | import com.ruoyi.sales.mapper.ShippingProductDetailMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.sales.pojo.ShippingProductDetail; |
| | | import com.ruoyi.sales.service.ShippingInfoService; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.stream.Collectors; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | |
| | | private final StockUtils stockUtils; |
| | | |
| | |
| | | IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req); |
| | | listPage.getRecords().forEach(item -> { |
| | | item.setStorageBlobVOs(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, item.getId())); |
| | | if (item.getReturnNos() != null && !item.getReturnNos().isEmpty()) { |
| | | item.setReturnNoList(java.util.Arrays.asList(item.getReturnNos().split(","))); |
| | | } else { |
| | | item.setReturnNoList(new java.util.ArrayList<>()); |
| | | } |
| | | }); |
| | | return listPage; |
| | | } |
| | |
| | | stockUtils.deleteStockOutRecord(shippingInfo.getId(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | } |
| | | } |
| | | |
| | | // 删除工作流实例 |
| | | List<ApprovalInstance> approvalInstances = approvalInstanceService.list(new LambdaQueryWrapper<ApprovalInstance>() |
| | | .in(ApprovalInstance::getBusinessId, ids) |
| | | .eq(ApprovalInstance::getBusinessType, 7L) |
| | | ); |
| | | if(!approvalInstances.isEmpty()){ |
| | | approvalInstanceService.delete( |
| | | approvalInstances.stream() |
| | | .map(ApprovalInstance::getId) |
| | | .collect(Collectors.toList()) |
| | | ); |
| | | } |
| | | |
| | | //删除发货明细 |
| | | shippingProductDetailMapper.delete(new LambdaQueryWrapper<ShippingProductDetail>().in(ShippingProductDetail::getShippingInfoId, ids)); |
| | | |
| | |
| | | @Override |
| | | public boolean addReq(ShippingInfoDto req) { |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | // 校验该产品是否已有待审核/审核中的发货记录,防止重复提交 |
| | | Long salesLedgerProductId = req.getSalesLedgerProductId(); |
| | | if (salesLedgerProductId != null) { |
| | | long pendingCount = this.count(new LambdaQueryWrapper<ShippingInfo>() |
| | | .eq(ShippingInfo::getSalesLedgerProductId, salesLedgerProductId) |
| | | .in(ShippingInfo::getStatus, "待审核", "审核中")); |
| | | if (pendingCount > 0) { |
| | | throw new RuntimeException("该产品已有待审核的发货记录,请勿重复提交"); |
| | | } |
| | | } |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH","shipping_no",req.getCreateTime()); |
| | | // 先保存发货单,再发起审批;无审核人自动通过时需要按发货编号回写发货状态。 |
| | | req.setShippingNo(sh); |
| | | req.setStatus("待审核"); |
| | | // Fetch projectId from SalesLedger |
| | | if (req.getSalesLedgerId() != null) { |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(req.getSalesLedgerId()); |
| | | if (salesLedger != null && salesLedger.getProjectId() != null) { |
| | | req.setProjectId(salesLedger.getProjectId()); |
| | | } |
| | | } |
| | | |
| | | boolean save = this.add(req); |
| | | // 发货审批 |
| | | ApprovalTemplate approvalTemplate = approvalTemplateMapper.selectOne( |
| | | new LambdaQueryWrapper<ApprovalTemplate>() |
| | | .eq(ApprovalTemplate::getBusinessType, 7L) |
| | | .eq(ApprovalTemplate::getDeleted, 0) |
| | | .orderByDesc(ApprovalTemplate::getId) |
| | | .last("LIMIT 1") |
| | | ); |
| | | if (approvalTemplate == null) { |
| | | throw new RuntimeException("请先配置发货审批模板"); |
| | | } |
| | | ApprovalInstanceDto approvalInstance = new ApprovalInstanceDto(); |
| | | approvalInstance.setTemplateId(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getId()); |
| | | approvalInstance.setTemplateName(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getTemplateName()); |
| | | approvalInstance.setTemplateId(approvalTemplate.getId()); |
| | | approvalInstance.setTemplateName(approvalTemplate.getTemplateName()); |
| | | approvalInstance.setBusinessId(req.getId()); |
| | | approvalInstance.setBusinessType(7L); |
| | | approvalInstance.setCurrentLevel(1); |
| | | approvalInstance.setTitle(sh+"审批"); |
| | | approvalInstance.setTitle(sh); |
| | | approvalInstance.setApplicantId(loginUser.getUserId()); |
| | | approvalInstance.setApplicantName(loginUser.getNickName()); |
| | | approvalInstance.setApplyTime(LocalDateTime.now()); |
| | | approvalInstanceService.add(approvalInstance); |
| | | // 创建审批实例后,更新发货状态为"审核中",使前端正确显示审批状态 |
| | | req.setStatus("审核中"); |
| | | this.updateById(req); |
| | | return true; |
| | | } |
| | | } |