| | |
| | | import com.ruoyi.account.pojo.AccountIncome; |
| | | import com.ruoyi.account.service.AccountExpenseService; |
| | | import com.ruoyi.account.service.AccountIncomeService; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.service.IApproveProcessService; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.mapper.SupplierManageMapper; |
| | |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.other.pojo.TempFile; |
| | | import com.ruoyi.procurementrecord.dto.SimplePP; |
| | | import com.ruoyi.procurementrecord.service.ProcurementPriceManagementService; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerDto; |
| | |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | |
| | | public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService { |
| | | private final AccountExpenseService accountExpenseService; |
| | | private final PurchaseLedgerMapper purchaseLedgerMapper; |
| | | private final IApproveProcessService approveProcessService; |
| | | |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | |
| | | |
| | | private final StringRedisTemplate redisTemplate; |
| | | |
| | | private final ProcurementPriceManagementService procurementPriceManagementService; |
| | | |
| | | @Value("${file.upload-dir}") |
| | | private String uploadDir; |
| | | |
| | |
| | | } |
| | | return purchaseLedgerMapper.selectList(queryWrapper); |
| | | } |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addPurchaseTemplate(PurchaseLedgerDto purchaseLedgerDto) { |
| | | //录入人 |
| | | SysUser sysUser = userMapper.selectUserById(purchaseLedgerDto.getRecorderId()); |
| | | |
| | | SupplierManage supplierManage = supplierManageMapper.selectById(purchaseLedgerDto.getSupplierId()); |
| | | |
| | | PurchaseLedger purchaseLedger = new PurchaseLedger(); |
| | | purchaseLedgerDto.setApprovalStatus(3); |
| | | BeanUtils.copyProperties(purchaseLedgerDto, purchaseLedger); |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | if(ObjectUtils.isNotEmpty(loginUser) && null != loginUser.getTenantId()) { |
| | | purchaseLedger.setTenantId(loginUser.getTenantId()); |
| | | } |
| | | purchaseLedger.setSupplierName(supplierManage.getSupplierName()); |
| | | purchaseLedger.setRecorderName(sysUser.getNickName()); |
| | | purchaseLedger.setPhoneNumber(sysUser.getPhonenumber()); |
| | | purchaseLedger.setPurchaseContractNumber("11111"); |
| | | purchaseLedger.setEntryDate(Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant())); |
| | | purchaseLedgerMapper.insert(purchaseLedger); |
| | | |
| | | // 4. 处理子表数据 |
| | | List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData(); |
| | | if (productList != null && !productList.isEmpty()) { |
| | | productList.forEach(product -> { |
| | | product.setSalesLedgerId(purchaseLedger.getId()); |
| | | product.setType(purchaseLedgerDto.getType()); |
| | | }); |
| | | productList.forEach(salesLedgerProductMapper::insert); |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException { |
| | |
| | | migrateTempFilesToFormal(purchaseLedger.getId(), purchaseLedgerDto.getTempFileIds()); |
| | | } |
| | | |
| | | //6.采购需要审批 |
| | | //新增审批数据 |
| | | ApproveProcessVO approveProcessVO = new ApproveProcessVO(); |
| | | approveProcessVO.setApproveDeptId(purchaseLedger.getTenantId()); |
| | | //审批理由是采购合同号用这个来关联 |
| | | approveProcessVO.setApproveReason(purchaseLedger.getPurchaseContractNumber()); |
| | | DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | approveProcessVO.setApproveTime(LocalDate.now().format(dateFormat)); |
| | | //5是采购申请 |
| | | approveProcessVO.setApproveType(5); |
| | | //录入人=申请人 |
| | | approveProcessVO.setApproveUser(purchaseLedger.getRecorderId()); |
| | | //审批人 |
| | | approveProcessVO.setApproveUserIds(purchaseLedgerDto.getApproveUserIds()); |
| | | try { |
| | | approveProcessService.addApprove(approveProcessVO); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | |
| | | if (products == null || products.isEmpty()) { |
| | | throw new BaseException("产品信息不存在"); |
| | | } |
| | | |
| | | PurchaseLedger ledger = purchaseLedgerMapper.selectById(salesLedgerId); |
| | | // 提前收集所有需要查询的ID |
| | | Set<Long> productIds = products.stream() |
| | | .map(SalesLedgerProduct::getProductId) |
| | |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | } |
| | | } |
| | | |
| | | updateList.addAll(insertList); |
| | | updateList.forEach(it->{ |
| | | SimplePP simplePP = new SimplePP(); |
| | | simplePP.setProductId(it.getProductId()); |
| | | simplePP.setSupplierName(ledger.getSupplierName()); |
| | | simplePP.setSupplierId(ledger.getSupplierId()); |
| | | simplePP.setUnit(it.getUnit()); |
| | | simplePP.setProductName(it.getProductCategory()); |
| | | simplePP.setSpecification(it.getSpecificationModel()); |
| | | simplePP.setFinalPrice(it.getTaxInclusiveUnitPrice().divide( |
| | | BigDecimal.ONE.add(it.getTaxRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP)), |
| | | 2, // 保留4位(可根据业务调整) |
| | | RoundingMode.HALF_UP |
| | | )); |
| | | simplePP.setRemark( |
| | | "系统根据采购提交自动生成。采购合同号为:" + purchaseLedger.getPurchaseContractNumber() + "。" |
| | | ); |
| | | procurementPriceManagementService.autoCreateRecord(simplePP); |
| | | }); |
| | | |
| | | |
| | | |
| | | // 计算总含税金额 |
| | | BigDecimal totalTaxInclusiveAmount = products.stream() |
| | |
| | | LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | productRecordLambdaQueryWrapper.in(ProductRecord::getPurchaseLedgerId,ids); |
| | | productRecordMapper.delete(productRecordLambdaQueryWrapper); |
| | | // 删除关联的审批表 |
| | | List<String> strings = purchaseLedgerMapper.selectBatchIds(Arrays.asList(ids)).stream() |
| | | .map(PurchaseLedger::getPurchaseContractNumber) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | List<ApproveProcess> list = approveProcessService.list(Wrappers.<ApproveProcess>lambdaQuery().eq(ApproveProcess::getApproveType, 5) .in(ApproveProcess::getApproveReason, strings)); |
| | | if (CollectionUtils.isNotEmpty(list)){ |
| | | List<String> approveIds = list.stream() |
| | | .map(ApproveProcess::getApproveId) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | Long[] ides = approveIds.stream() |
| | | .filter(s -> s != null && !s.isEmpty()) |
| | | .map(Long::valueOf) |
| | | .toArray(Long[]::new); |
| | | approveProcessService.delApprove(ides); |
| | | } |
| | | // 批量删除采购台账 |
| | | return purchaseLedgerMapper.deleteBatchIds(Arrays.asList(ids)); |
| | | } |
| | |
| | | |
| | | // 3.查询上传文件 |
| | | LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>(); |
| | | salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId()); |
| | | salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId()) |
| | | .eq(CommonFile::getType,FileNameType.PURCHASE.getValue()); |
| | | List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper); |
| | | |
| | | // 4. 转换 DTO |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PurchaseLedgerDto getPurchaseByCode(PurchaseLedgerDto purchaseLedgerDto) { |
| | | // 1. 查询主表 |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>() .eq(PurchaseLedger::getPurchaseContractNumber, purchaseLedgerDto.getPurchaseContractNumber()) .last("LIMIT 1")); |
| | | if (purchaseLedger == null) { |
| | | throw new BaseException("采购台账不存在"); |
| | | } |
| | | // 2. 查询子表 |
| | | LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>(); |
| | | productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) .eq(SalesLedgerProduct::getType, 2); |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper); |
| | | // 4. 转换 DTO |
| | | PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); BeanUtils.copyProperties(purchaseLedger, resultDto); |
| | | if (!products.isEmpty()) { |
| | | resultDto.setHasChildren(true); |
| | | resultDto.setProductData(products); |
| | | } |
| | | return resultDto; |
| | | } |
| | | |
| | | @Override |
| | | public List getPurchasesNo() { |
| | | LambdaQueryWrapper<PurchaseLedger> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.select(PurchaseLedger::getId, PurchaseLedger::getPurchaseContractNumber, PurchaseLedger::getSupplierId); |