refactor: 优化采购订单相关功能及代码结构

重构采购订单模块,包括以下改进:
1. 移除PurchaseOrderItemVo中冗余字段
2. 在ContractCtx中添加调试日志
3. 修改InventoryTabSkinContracts和PurchaseOrderTabSkinBillVoucher中的equals比较逻辑
4. 调整PurchaseOrderVo的税率字段类型并添加锁定标志
5. 修正FXML文件中的控制器路径
6. 优化InventoryStringConverter的toString方法格式
7. 在PurchaseBillVoucherItemService中添加凭证查询条件
8. 改进ContractRepairTasker的进度更新逻辑
9. 修复AbstContractRepairTasker中的子合同同步问题
10. 优化PurchaseOrderTabSkinItems的表格列显示
11. 添加InventoryCatalogStringConverter及相关缓存支持
12. 完善PurchaseBillVoucherService的查询逻辑
13. 增强ContractService的库存查询功能
14. 改进PurchaseOrderItemService的合同项查询逻辑
15. 为InventoryService添加缓存支持
16. 优化ContractTabSkinPurchaseOrders的员工列显示
17. 改进ContractTabSkinItemsV2的数量显示逻辑
18. 重构PurchaseOrderViewModel的数据绑定逻辑
This commit is contained in:
2025-10-12 00:52:01 +08:00
parent 333feb0d5a
commit ddd9dad945
30 changed files with 316 additions and 90 deletions

View File

@@ -178,6 +178,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
Map<String, Object> data;
try {
data = repository.queryContractDetail(guid);
holder.debug("查询合同详情成功, guid=" + guid);
} catch (Exception e) {
throw new RuntimeException("查询合同详情失败, guid=" + guid, e);
}

View File

@@ -186,6 +186,14 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
return new ArrayList<>(updateMap.keySet());
}
/**
* 同步采购订单条目
*
* @param order
* @param map
* @param holder
* @return
*/
private boolean applyPurchaseOrderDetail(PurchaseOrder order, Map<String, Object> map, MessageHolder holder) {
String code = (String) map.get("cPOID");
@@ -203,6 +211,10 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
modified = true;
}
if (updateNumber(order::getTaxRate, order::setTaxRate, (float) map.get("iTaxRate"), holder, "税率")) {
modified = true;
}
if (updateEmployeeByCode(order::getEmployee, order::setEmployee, (String) map.get("cPersonCode"), holder,
"业务员")) {
modified = true;

View File

@@ -9,7 +9,9 @@ import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.ecep.contract.ds.contract.model.ContractItem;
import com.ecep.contract.vo.ContractCatalogVo;
import jakarta.persistence.criteria.Root;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -122,7 +124,7 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
}
public List<Contract> findAllByCompany(CompanyVo company, ContractPayWay payWay, LocalDate beginDate,
LocalDate endDate) {
LocalDate endDate) {
return contractRepository.findAll((root, query, cb) -> {
Predicate p = cb.and(
cb.equal(root.get("company").get("id"), company.getId()),
@@ -280,6 +282,16 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
// relation
spec = SpecificationUtils.andParam(spec, paramsNode, "group", "kind", "type", "group", "company", "project");
if (paramsNode.has("inventory")) {
// ContractItem
spec = SpecificationUtils.and(spec, (root, query, cb) -> {
Root<ContractItem> itemRoot = query.from(ContractItem.class);
return cb.and(
cb.equal(itemRoot.get("inventory").get("id"), paramsNode.get("inventory").asInt()),
cb.equal(root, itemRoot.get("contract"))
);
});
}
return spec;
}

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
import java.util.List;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ContractVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -63,6 +64,8 @@ public class PurchaseBillVoucherItemService
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
spec = SpecificationUtils.andParam(spec, paramsNode, "voucher");
return findAll(spec, pageable);
}

View File

@@ -2,6 +2,9 @@ package com.ecep.contract.ds.contract.service;
import java.util.List;
import com.ecep.contract.ds.vendor.model.PurchaseBillVoucherItem;
import com.ecep.contract.ds.vendor.model.PurchaseOrderItem;
import jakarta.persistence.criteria.Root;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -130,6 +133,17 @@ public class PurchaseBillVoucherService
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company", "inventory");
if (paramsNode.has("purchaseOrder")) {
spec = SpecificationUtils.and(spec, (root, query, cb) -> {
Root<PurchaseBillVoucherItem> voucherItemRoot = query.from(PurchaseBillVoucherItem.class);
Root<PurchaseOrderItem> orderItemRoot = query.from(PurchaseOrderItem.class);
return cb.and(
cb.equal(voucherItemRoot.get("orderItem"), orderItemRoot),
cb.equal(orderItemRoot.get("order").get("id"), paramsNode.get("purchaseOrder").asInt()),
cb.equal(root, voucherItemRoot.get("voucher"))
);
});
}
return findAll(spec, pageable).map(PurchaseBillVoucher::toVo);
}

View File

@@ -3,6 +3,7 @@ package com.ecep.contract.ds.contract.service;
import java.util.List;
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
import com.ecep.contract.vo.ContractItemVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -90,6 +91,29 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "order", "inventory");
if (paramsNode.has("contractItem")) {
ContractItemService itemService = SpringApp.getBean(ContractItemService.class);
var contractItem = itemService.findById(paramsNode.get("contractItem").asInt());
if (contractItem.getInventoryId() == null) {
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
return builder.and(
builder.equal(root.get("order").get("contract").get("id"), contractItem.getContractId()),
builder.equal(root.get("inventory").get("id"), null)
);
});
} else {
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
return builder.and(
builder.equal(root.get("order").get("contract").get("id"), contractItem.getContractId()),
builder.equal(root.get("inventory").get("id"), contractItem.getInventoryId())
);
});
}
}
return findAll(spec, pageable).map(PurchaseOrderItem::toVo);
}

View File

@@ -77,6 +77,7 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
public PurchaseOrderVo findByRefId(Integer refId) {
return repository.findByRefId(refId).map(PurchaseOrder::toVo).orElse(null);
}
public PurchaseOrder getByRefId(Integer refId) {
return repository.findByRefId(refId).orElse(null);
}
@@ -161,6 +162,8 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
model.setCode(vo.getCode());
model.setRefId(vo.getRefId());
model.setVendorCode(vo.getVendorCode());
model.setTaxRate(vo.getTaxRate());
model.setTaxRateLocked(vo.isTaxRateLocked());
model.setDescription(vo.getDescription());
// 处理关联实体 - 合同

View File

@@ -265,12 +265,12 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
});
v1 = contractProperty.get();
var projectVo = projectService.findById(projectId);
var projectVo = projectId == null ? null : projectService.findById(projectId);
if (contractCtx.updateContractProject(v1, projectVo, subHolder)) {
modified = true;
}
} catch (Exception e) {
throw new RuntimeException("同步子合同失败, 合同b编号:" + v1.getCode(), e);
throw new RuntimeException("同步子合同失败, 合同编号:" + v1.getCode(), e);
}
if (modified) {
try {

View File

@@ -61,6 +61,12 @@ public class PurchaseOrder
@Column(name = "VEN_CODE")
private String vendorCode;
@Column(name = "TAX_RATE")
private float taxRate;
@Column(name = "TAX_RATE_LOCKED")
private boolean taxRateLocked;
/**
* 制单人
*/
@@ -95,6 +101,7 @@ public class PurchaseOrder
@JoinColumn(name = "CLOSER_ID")
@ToString.Exclude
private Employee closer;
@Column(name = "CLOSER_DATE")
private LocalDateTime closerDate;
@@ -134,7 +141,7 @@ public class PurchaseOrder
vo.setCode(code);
vo.setRefId(refId);
vo.setVendorCode(vendorCode);
vo.setDescription(description);
vo.setMakerDate(makerDate);
vo.setModifyDate(modifyDate);
vo.setVerifierDate(verifierDate);
@@ -152,6 +159,8 @@ public class PurchaseOrder
if (closer != null) {
vo.setCloserId(closer.getId());
}
vo.setDescription(description);
return vo;
}
}

View File

@@ -43,6 +43,7 @@ public class ContractRepairTasker extends AbstContractRepairTasker implements We
if (contract.getPayWay() == ContractPayWay.PAY) {
if (StringUtils.hasText(contract.getParentCode())) {
parent = contractCtx.findContractByCode(contract.getParentCode());
holder.info("找到上级合同 " + parent.getCode() + " - " + parent.getName());
}
}
@@ -54,7 +55,7 @@ public class ContractRepairTasker extends AbstContractRepairTasker implements We
setContract(contractProperty.get());
updateProgress(1, 1);
updateProgress(100, 100);
}
public void setContract(ContractVo contract) {