| | |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ruoyi.approve.bean.dto.ApprovalInstanceDto; |
| | | import com.ruoyi.approve.mapper.ApprovalTemplateMapper; |
| | | import com.ruoyi.approve.pojo.ApprovalInstance; |
| | |
| | | .last("limit 1") |
| | | ); |
| | | if(Objects.isNull(oldApprovalInstance)){ |
| | | addApproveByPurchase(loginUser, purchaseLedger); |
| | | addApproveByPurchase(loginUser, purchaseLedger, productList); |
| | | } |
| | | // 5. 迁移临时文件到正式目录 |
| | | fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_LEDGER, purchaseLedger.getId(), purchaseLedgerDto.getStorageBlobDTOS()); |
| | |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | } |
| | | // 采购审核 |
| | | addApproveByPurchase(loginUser,salesLedger); |
| | | List<SalesLedgerProduct> snapshotProducts = salesLedgerProductMapper.selectList( |
| | | new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId()) |
| | | .eq(SalesLedgerProduct::getType, 2) |
| | | ); |
| | | addApproveByPurchase(loginUser, salesLedger, snapshotProducts); |
| | | } |
| | | |
| | | return AjaxResult.success("导入成功"); |
| | |
| | | |
| | | @Override |
| | | public PurchaseLedgerDto getPurchaseByCode(PurchaseLedgerDto purchaseLedgerDto) { |
| | | // 1. 查询主表 |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>() |
| | | PurchaseLedger purchaseLedger = null; |
| | | ApprovalInstance approvalSnapshotInstance = null; |
| | | |
| | | // 1. 优先按当前审批实例查询快照 |
| | | if (purchaseLedgerDto.getApprovalInstanceId() != null) { |
| | | approvalSnapshotInstance = approvalInstanceService.getById(purchaseLedgerDto.getApprovalInstanceId()); |
| | | if (approvalSnapshotInstance != null && approvalSnapshotInstance.getBusinessId() != null) { |
| | | purchaseLedger = purchaseLedgerMapper.selectById(approvalSnapshotInstance.getBusinessId()); |
| | | } |
| | | } |
| | | |
| | | // 2. 没传审批实例ID时,退回到按采购合同号查询 |
| | | if (purchaseLedger == null) { |
| | | purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>() |
| | | .eq(PurchaseLedger::getPurchaseContractNumber, purchaseLedgerDto.getPurchaseContractNumber()) |
| | | .last("LIMIT 1")); |
| | | if (purchaseLedger == null) { |
| | | throw new BaseException("采购台账不存在"); |
| | | } |
| | | } |
| | | |
| | | // 2. 查询子表 |
| | | // 3. 查询当前采购单对应的审批快照 |
| | | if (approvalSnapshotInstance == null) { |
| | | approvalSnapshotInstance = approvalInstanceService.getOne(new LambdaQueryWrapper<ApprovalInstance>() |
| | | .eq(ApprovalInstance::getBusinessId, purchaseLedger.getId()) |
| | | .eq(ApprovalInstance::getBusinessType, 5L) |
| | | .eq(ApprovalInstance::getDeleted, 0) |
| | | .orderByDesc(ApprovalInstance::getId) |
| | | .last("LIMIT 1")); |
| | | } |
| | | |
| | | if (approvalSnapshotInstance != null && StringUtils.hasText(approvalSnapshotInstance.getFormConfig())) { |
| | | try { |
| | | PurchaseLedgerDto snapshot = JSON.parseObject(approvalSnapshotInstance.getFormConfig(), PurchaseLedgerDto.class); |
| | | if (snapshot != null) { |
| | | snapshot.setId(purchaseLedger.getId()); |
| | | if (snapshot.getPurchaseContractNumber() == null) { |
| | | snapshot.setPurchaseContractNumber(purchaseLedger.getPurchaseContractNumber()); |
| | | } |
| | | if (snapshot.getSupplierId() == null) { |
| | | snapshot.setSupplierId(purchaseLedger.getSupplierId()); |
| | | } |
| | | if (snapshot.getSupplierName() == null) { |
| | | snapshot.setSupplierName(purchaseLedger.getSupplierName()); |
| | | } |
| | | if (snapshot.getSalesContractNo() == null) { |
| | | snapshot.setSalesContractNo(purchaseLedger.getSalesContractNo()); |
| | | } |
| | | if (snapshot.getSalesContractNoId() == null) { |
| | | snapshot.setSalesContractNoId(purchaseLedger.getSalesLedgerId()); |
| | | } |
| | | if (snapshot.getProjectName() == null) { |
| | | snapshot.setProjectName(purchaseLedger.getProjectName()); |
| | | } |
| | | if (snapshot.getEntryDate() == null) { |
| | | snapshot.setEntryDate(purchaseLedger.getEntryDate()); |
| | | } |
| | | if (snapshot.getExecutionDate() == null) { |
| | | snapshot.setExecutionDate(purchaseLedger.getExecutionDate()); |
| | | } |
| | | if (snapshot.getRemarks() == null) { |
| | | snapshot.setRemarks(purchaseLedger.getRemarks()); |
| | | } |
| | | if (snapshot.getRecorderId() == null) { |
| | | snapshot.setRecorderId(purchaseLedger.getRecorderId()); |
| | | } |
| | | if (snapshot.getRecorderName() == null) { |
| | | snapshot.setRecorderName(purchaseLedger.getRecorderName()); |
| | | } |
| | | snapshot.setProductData(snapshot.getProductData() == null ? Collections.emptyList() : snapshot.getProductData()); |
| | | snapshot.setHasChildren(CollectionUtils.isNotEmpty(snapshot.getProductData())); |
| | | return snapshot; |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("解析采购审批快照失败: {}", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // 4. 查询子表 |
| | | LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>(); |
| | | productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) |
| | | .eq(SalesLedgerProduct::getType, 2); |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper); |
| | | |
| | | // 4. 转换 DTO |
| | | // 5. 转换 DTO |
| | | PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); |
| | | BeanUtils.copyProperties(purchaseLedger, resultDto); |
| | | if (!products.isEmpty()) { |
| | |
| | | return resultDto; |
| | | } |
| | | |
| | | public void addApproveByPurchase(LoginUser loginUser,PurchaseLedger purchaseLedger) { |
| | | public void addApproveByPurchase(LoginUser loginUser, PurchaseLedger purchaseLedger, List<SalesLedgerProduct> productList) { |
| | | if (loginUser == null) { |
| | | return; |
| | | } |
| | |
| | | approvalInstance.setTitle(purchaseLedger.getPurchaseContractNumber()+"审批"); |
| | | approvalInstance.setApplicantName(loginUser.getNickName()); |
| | | approvalInstance.setApplyTime(LocalDateTime.now()); |
| | | PurchaseLedgerDto snapshot = new PurchaseLedgerDto(); |
| | | BeanUtils.copyProperties(purchaseLedger, snapshot); |
| | | snapshot.setProductData(productList == null ? Collections.emptyList() : new ArrayList<>(productList)); |
| | | approvalInstance.setFormConfig(JSON.toJSONString(snapshot)); |
| | | approvalInstanceService.add(approvalInstance); |
| | | |
| | | } |