| | |
| | | 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; |
| | | import com.ruoyi.purchase.mapper.PaymentRegistrationMapper; |
| | | import com.ruoyi.purchase.mapper.ProductRecordMapper; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | | import com.ruoyi.purchase.mapper.TicketRegistrationMapper; |
| | | import com.ruoyi.purchase.pojo.PaymentRegistration; |
| | | import com.ruoyi.purchase.pojo.ProductRecord; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import com.ruoyi.purchase.pojo.TicketRegistration; |
| | | import com.ruoyi.purchase.service.IPurchaseLedgerService; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.mapper.QualityInspectParamMapper; |
| | |
| | | import com.ruoyi.quality.pojo.QualityTestStandard; |
| | | import com.ruoyi.quality.pojo.QualityTestStandardParam; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | | import com.ruoyi.sales.pojo.InvoiceRegistrationProduct; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | |
| | | private final ProductMapper productMapper; |
| | | private final ProductModelMapper productModelMapper; |
| | | private final SysUserMapper sysUserMapper; |
| | | private final TicketRegistrationMapper ticketRegistrationMapper; |
| | | private final ProductRecordMapper productRecordMapper; |
| | | private final PaymentRegistrationMapper paymentRegistrationMapper; |
| | | private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper; |
| | | private final StringRedisTemplate redisTemplate; |
| | | private final QualityInspectMapper qualityInspectMapper; |
| | | private final CommonFileServiceImpl commonFileService; |
| | |
| | | private final QualityInspectParamMapper qualityInspectParamMapper; |
| | | private final ApproveProcessServiceImpl approveProcessService; |
| | | private final ProcurementRecordMapper procurementRecordStorageMapper; |
| | | private final ISysNoticeService sysNoticeService; |
| | | private final FileUtil fileUtil; |
| | | |
| | | @Override |
| | |
| | | } |
| | | purchaseLedgerMapper.updateById(purchaseLedger); |
| | | } |
| | | // 6.采购审核新增;审批管理未配置采购审批人时,审批服务会自动置为审批通过。 |
| | | addApproveByPurchase(loginUser, purchaseLedger); |
| | | |
| | | // 4. 处理子表数据 |
| | | List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData(); |
| | | if (productList != null && !productList.isEmpty()) { |
| | | handleSalesLedgerProducts(purchaseLedger.getId(), productList, purchaseLedgerDto.getType()); |
| | | } |
| | | //新增原材料检验 审批之后才生成检验 |
| | | // if (productList != null) { |
| | | // for (SalesLedgerProduct saleProduct : productList) { |
| | | // //是否推送质检,如果true就添加 |
| | | // if (saleProduct.getIsChecked()) { |
| | | // addQualityInspect(purchaseLedger, saleProduct); |
| | | // } |
| | | // } |
| | | // } |
| | | // 6.采购审核新增;审批管理未配置采购审批人时,审批服务会自动置为审批通过。 |
| | | addApproveByPurchase(loginUser, purchaseLedger); |
| | | // 5. 迁移临时文件到正式目录 |
| | | fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_LEDGER, purchaseLedger.getId(), purchaseLedgerDto.getStorageBlobDTOS()); |
| | | 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); |
| | |
| | | |
| | | LocalDateTime localDateTime = entryDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | salesLedgerProduct.setRegisterDate(localDateTime); |
| | | salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity()); |
| | | salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getTaxInclusiveTotalPrice()); |
| | | salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice()); |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | } |
| | | } |
| | |
| | | queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, ids) |
| | | .eq(SalesLedgerProduct::getType, 2); |
| | | salesLedgerProductMapper.delete(queryWrapper); |
| | | // 批量删除关联的采购台账的来票登记 |
| | | LambdaQueryWrapper<TicketRegistration> ticketRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getPurchaseLedgerId,ids); |
| | | ticketRegistrationMapper.delete(ticketRegistrationLambdaQueryWrapper); |
| | | // 批量删除关联的采购台账的来票登记记录 |
| | | LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | productRecordLambdaQueryWrapper.in(ProductRecord::getPurchaseLedgerId,ids); |
| | | productRecordMapper.delete(productRecordLambdaQueryWrapper); |
| | | // 批量删除付款登记 |
| | | LambdaQueryWrapper<PaymentRegistration> paymentRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | paymentRegistrationLambdaQueryWrapper.in(PaymentRegistration::getPurchaseLedgerId, ids); |
| | | paymentRegistrationMapper.delete(paymentRegistrationLambdaQueryWrapper); |
| | | //批量删除检验标准 |
| | | LambdaQueryWrapper<QualityInspect> materialInspectLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | materialInspectLambdaQueryWrapper.in(QualityInspect::getPurchaseLedgerId, ids); |
| | |
| | | queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) |
| | | .eq(SalesLedgerProduct::getType, 2); |
| | | List<SalesLedgerProduct> productList = salesLedgerProductMapper.selectList(queryWrapper); |
| | | productList.forEach(product -> { |
| | | product.setFutureTickets(product.getFutureTickets() != null ? product.getFutureTickets() : product.getQuantity()); |
| | | product.setFutureTicketsAmount(product.getFutureTicketsAmount() != null ? product.getFutureTicketsAmount() : product.getTaxInclusiveTotalPrice()); |
| | | product.setTicketsNum(null); |
| | | product.setTicketsAmount(null); |
| | | product.setTempFutureTickets(product.getFutureTickets()); |
| | | product.setTempFutureTicketsAmount(product.getFutureTicketsAmount()); |
| | | }); |
| | | resultDto.setProductData(productList); |
| | | return resultDto; |
| | | } |
| | |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(id); |
| | | |
| | | BeanUtils.copyProperties(purchaseLedger, purchaseLedgerDto); |
| | | // TicketRegistration ticketRegistration = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getPurchaseLedgerId, id)); |
| | | // if (ticketRegistration != null) { |
| | | // purchaseLedgerDto.setInvoiceNumber(ticketRegistration.getInvoiceNumber()); |
| | | // purchaseLedgerDto.setInvoiceAmount(ticketRegistration.getInvoiceAmount()); |
| | | // purchaseLedgerDto.setTicketRegistrationId(ticketRegistration.getId()); |
| | | // } |
| | | return purchaseLedgerDto; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<PurchaseLedgerDto> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedgerDto purchaseLedger) { |
| | | IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger); |
| | | purchaseLedgerDtoIPage.getRecords().forEach(purchaseLedgerDto -> { |
| | | List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, purchaseLedgerDto.getId()).eq(CommonFile::getType, FileNameType.PURCHASE.getValue())); |
| | | purchaseLedgerDto.setSalesLedgerFiles(commonFiles); |
| | | }); |
| | | return purchaseLedgerDtoIPage; |
| | | } |
| | | |
| | | @Override |
| | | public List<InvoiceRegistrationProduct> getProductBySalesNo(Long id) { |
| | | List<InvoiceRegistrationProduct> invoiceRegistrationProducts = invoiceRegistrationProductMapper.selectList(new LambdaQueryWrapper<InvoiceRegistrationProduct>() |
| | | .select(InvoiceRegistrationProduct::getId, InvoiceRegistrationProduct::getProductCategory, InvoiceRegistrationProduct::getSpecificationModel, |
| | | InvoiceRegistrationProduct::getUnit, InvoiceRegistrationProduct::getQuantity) |
| | | .eq(InvoiceRegistrationProduct::getSalesLedgerId, id)); |
| | | if (invoiceRegistrationProducts.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return invoiceRegistrationProducts; |
| | | return purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger); |
| | | } |
| | | |
| | | @Override |
| | |
| | | salesLedgerProduct.setType(2); |
| | | // 计算不含税总价 |
| | | salesLedgerProduct.setTaxExclusiveTotalPrice(salesLedgerProduct.getTaxInclusiveTotalPrice().divide(new BigDecimal(1).add(salesLedgerProduct.getTaxRate().divide(new BigDecimal(100))), 2, RoundingMode.HALF_UP)); |
| | | salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity()); |
| | | salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getTaxExclusiveTotalPrice()); |
| | | list.stream() |
| | | .filter(map -> map.get("productName").equals(salesLedgerProduct.getProductCategory()) && map.get("model").equals(salesLedgerProduct.getSpecificationModel())) |
| | | .findFirst() |
| | |
| | | salesLedgerProduct.setRegister(loginUser.getNickName()); |
| | | salesLedgerProduct.setRegisterDate(LocalDateTime.now()); |
| | | salesLedgerProduct.setApproveStatus(0); |
| | | salesLedgerProduct.setPendingTicketsTotal(salesLedgerProductImportDto.getTaxInclusiveTotalPrice()); |
| | | // 是否质检判断 |
| | | salesLedgerProduct.setIsChecked(salesLedgerProductImportDto.getIsChecked() == 1); |
| | | if(salesLedgerProductImportDto.getIsChecked() == 1){ |
| | |
| | | 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; |
| | | } |
| | | /** |
| | | * 下划线命名转驼峰命名 |
| | | */ |