| | |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | import com.ruoyi.basic.enums.ApplicationTypeEnum; |
| | | import com.ruoyi.common.enums.ApprovalStatusEnum; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.project.system.service.ISysNoticeService; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerDto; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerImportDto; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerProductImportDto; |
| | |
| | | private final QualityInspectParamMapper qualityInspectParamMapper; |
| | | private final ApproveProcessServiceImpl approveProcessService; |
| | | private final ProcurementRecordMapper procurementRecordStorageMapper; |
| | | private final ISysNoticeService sysNoticeService; |
| | | private final FileUtil fileUtil; |
| | | |
| | | @Override |
| | |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long saveShortagePurchaseDraft(PurchaseLedgerDto purchaseLedgerDto) throws Exception { |
| | | if (purchaseLedgerDto == null) { |
| | | throw new BaseException("采购台账数据不能为空"); |
| | | } |
| | | if (StringUtils.isBlank(purchaseLedgerDto.getSalesContractNo())) { |
| | | throw new BaseException("销售订单号不能为空"); |
| | | } |
| | | if (CollectionUtils.isEmpty(purchaseLedgerDto.getProductData())) { |
| | | throw new BaseException("采购产品信息不能为空"); |
| | | } |
| | | |
| | | SalesLedger salesLedger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>() |
| | | .eq(SalesLedger::getSalesContractNo, purchaseLedgerDto.getSalesContractNo()) |
| | | .last("limit 1")); |
| | | if (salesLedger == null) { |
| | | throw new BaseException("销售订单不存在"); |
| | | } |
| | | |
| | | PurchaseLedger purchaseLedger = new PurchaseLedger(); |
| | | BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger); |
| | | purchaseLedger.setSalesLedgerId(salesLedger.getId()); |
| | | purchaseLedger.setSalesContractNo(salesLedger.getSalesContractNo()); |
| | | purchaseLedger.setProjectName(salesLedger.getProjectName()); |
| | | if (purchaseLedger.getEntryDate() == null) { |
| | | purchaseLedger.setEntryDate(salesLedger.getEntryDate() != null ? salesLedger.getEntryDate() : new Date()); |
| | | } |
| | | if (!StringUtils.hasText(purchaseLedger.getPurchaseContractNumber())) { |
| | | purchaseLedger.setPurchaseContractNumber(getPurchaseNo()); |
| | | } |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | Long currentUserId = loginUser != null && loginUser.getUserId() != null ? loginUser.getUserId() : null; |
| | | if (loginUser != null && loginUser.getTenantId() != null) { |
| | | purchaseLedger.setTenantId(loginUser.getTenantId()); |
| | | } |
| | | |
| | | SysUser recorderUser = resolveShortagePurchaseRecorderUser(purchaseLedgerDto, currentUserId); |
| | | if (ObjectUtils.isNotEmpty(recorderUser)) { |
| | | purchaseLedger.setRecorderId(recorderUser.getUserId()); |
| | | purchaseLedger.setRecorderName(recorderUser.getNickName()); |
| | | purchaseLedger.setPhoneNumber(recorderUser.getPhonenumber()); |
| | | } |
| | | |
| | | // String originalApplicantName = resolveOriginalApplicantName(salesLedger); // 溯源销售申请人 |
| | | String originalApplicantName = SecurityUtils.getLoginUser().getNickName(); // 当前登录用户 |
| | | purchaseLedger.setRemarks(mergeShortagePurchaseRemark( |
| | | purchaseLedger.getRemarks(), |
| | | originalApplicantName, |
| | | ObjectUtils.isNotEmpty(recorderUser) ? recorderUser.getNickName() : null |
| | | )); |
| | | |
| | | purchaseLedger.setApprovalStatus(ApprovalStatusEnum.DRAFT.getCode()); |
| | | |
| | | boolean isNewDraft = purchaseLedger.getId() == null; |
| | | if (isNewDraft) { |
| | | purchaseLedgerMapper.insert(purchaseLedger); |
| | | } else { |
| | | PurchaseLedger dbPurchaseLedger = purchaseLedgerMapper.selectById(purchaseLedger.getId()); |
| | | if (dbPurchaseLedger == null) { |
| | | throw new BaseException("采购台账不存在"); |
| | | } |
| | | if (!ApprovalStatusEnum.DRAFT.getCode().equals(dbPurchaseLedger.getApprovalStatus())) { |
| | | throw new BaseException("非草稿状态的采购台账不允许通过简易新增修改"); |
| | | } |
| | | purchaseLedgerMapper.updateById(purchaseLedger); |
| | | } |
| | | |
| | | handleSalesLedgerProducts(purchaseLedger.getId(), purchaseLedgerDto.getProductData(), purchaseLedgerDto.getType()); |
| | | fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_LEDGER, purchaseLedger.getId(), purchaseLedgerDto.getStorageBlobDTOS()); |
| | | |
| | | if (isNewDraft) { |
| | | Long noticeUserId = resolveShortagePurchaseCopyUserId(purchaseLedgerDto, currentUserId); |
| | | if (noticeUserId != null && noticeUserId > 0) { |
| | | sysNoticeService.simpleNoticeByUser( |
| | | "采购申请提醒", |
| | | "销售订单号 " + salesLedger.getSalesContractNo() + " 的采购申请已创建,请补全采购订单信息后提交审核。", |
| | | Collections.singletonList(noticeUserId), |
| | | "/procurementManagement/procurementLedger?purchaseContractNumber=" + purchaseLedger.getPurchaseContractNumber() |
| | | ); |
| | | } |
| | | } |
| | | return purchaseLedger.getId(); |
| | | } |
| | | public void addQualityInspect(PurchaseLedger purchaseLedger, SalesLedgerProduct saleProduct) { |
| | | QualityInspect qualityInspect = new QualityInspect(); |
| | | qualityInspect.setInspectType(0); |
| | |
| | | approveProcessService.addApprove(approveProcessVO); |
| | | } |
| | | |
| | | private Long resolveShortagePurchaseCopyUserId(PurchaseLedgerDto purchaseLedgerDto, Long currentUserId) { |
| | | if (purchaseLedgerDto != null && purchaseLedgerDto.getCcUserId() != null) { |
| | | return purchaseLedgerDto.getCcUserId(); |
| | | } |
| | | return currentUserId; |
| | | } |
| | | |
| | | private SysUser resolveShortagePurchaseRecorderUser(PurchaseLedgerDto purchaseLedgerDto, Long currentUserId) { |
| | | if (purchaseLedgerDto != null && purchaseLedgerDto.getCcUserId() != null) { |
| | | SysUser ccUser = sysUserMapper.selectUserById(purchaseLedgerDto.getCcUserId()); |
| | | if (ccUser != null) { |
| | | return ccUser; |
| | | } |
| | | } |
| | | if (purchaseLedgerDto != null && StringUtils.isNotBlank(purchaseLedgerDto.getCcUserName())) { |
| | | SysUser ccUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>() |
| | | .eq(SysUser::getNickName, purchaseLedgerDto.getCcUserName()) |
| | | .last("limit 1")); |
| | | if (ccUser != null) { |
| | | return ccUser; |
| | | } |
| | | } |
| | | return currentUserId == null ? null : sysUserMapper.selectUserById(currentUserId); |
| | | } |
| | | |
| | | private String resolveOriginalApplicantName(SalesLedger salesLedger) { |
| | | if (salesLedger == null) { |
| | | return null; |
| | | } |
| | | if (salesLedger.getCreateUser() != null) { |
| | | SysUser applicant = sysUserMapper.selectUserById(salesLedger.getCreateUser().longValue()); |
| | | if (applicant != null && StringUtils.hasText(applicant.getNickName())) { |
| | | return applicant.getNickName(); |
| | | } |
| | | } |
| | | if (StringUtils.hasText(salesLedger.getEntryPerson())) { |
| | | return salesLedger.getEntryPerson(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String mergeShortagePurchaseRemark(String originalRemark, String applicantName, String recorderName) { |
| | | String sentence = "原申请人:" + (StringUtils.hasText(applicantName) ? applicantName : "未识别") |
| | | + ",由抄送人" + (StringUtils.hasText(recorderName) ? recorderName : "未识别") |
| | | + "补全采购订单信息后提交审核。"; |
| | | if (!StringUtils.hasText(originalRemark)) { |
| | | return sentence; |
| | | } |
| | | if (originalRemark.contains("原申请人:")) { |
| | | return originalRemark; |
| | | } |
| | | return originalRemark + "\\n" + sentence; |
| | | } |
| | | /** |
| | | * 下划线命名转驼峰命名 |
| | | */ |