feat(采购订单): 添加合同条目关联及税率绑定功能
新增采购订单条目与合同条目的关联字段,实现税率和税率锁定的UI绑定 优化采购订单同步逻辑,支持从U8系统获取更多字段信息 调整界面文本显示,修复部分字段绑定问题
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.ecep.contract.cloud.u8;
|
||||
|
||||
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
@@ -303,6 +304,16 @@ public class YongYouU8Repository {
|
||||
return getJdbcTemplate().queryForList("select * from PO_Podetails where ContractCode=?", code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据采购合同POID,查询合同项
|
||||
*
|
||||
* @param order 采购合同
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> findAllPurchaseOrderItemByOrder(PurchaseOrder order) {
|
||||
return getJdbcTemplate().queryForList("select * from PO_Podetails where POID=?", order.getRefId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询存货档案数据
|
||||
*
|
||||
@@ -374,5 +385,4 @@ public class YongYouU8Repository {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -848,17 +848,22 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
holder.error("条目没有合同");
|
||||
return false;
|
||||
}
|
||||
String rowGUID = (String) map.get("RowGUID");
|
||||
|
||||
// 条目货物的code
|
||||
String code = (String) map.get("strCode");
|
||||
// 条目货物规格
|
||||
String spec = (String) map.get("cInvStd");
|
||||
// 条目货物名称
|
||||
String title = (String) map.get("strName");
|
||||
double amount = (double) map.get("dblQuantity");
|
||||
// 条目货物单位
|
||||
String unit = (String) map.get("strMeasureUnit");
|
||||
double amount = (double) map.get("dblQuantity");
|
||||
double taxRate = (double) map.get("dblTaxRatio");
|
||||
double taxPrice = (double) map.get("dblPrice");
|
||||
double exclusiveTaxPrice = (double) map.get("dblUntaxPrice");
|
||||
|
||||
String inventoryCatalogCode = (String) map.get("cInvCCode");
|
||||
String chiefCode = (String) map.get("strChief");
|
||||
String inventoryCode = (String) map.get("strInvoiceID");
|
||||
|
||||
String startDate = (String) map.get("dtStartDate");
|
||||
@@ -873,6 +878,11 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
boolean modified = false;
|
||||
|
||||
holder.debug("条目:" + title + " x " + amount);
|
||||
|
||||
if (updateText(item::getRowId, item::setRowId, rowGUID, holder, "行号")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (taxRate >= TaxRateUtils.TAX_RATE_GENERAL_OLDEST
|
||||
&& TaxRateUtils.isAfterTaxRateChangeTo13(contract.getSetupDate())) {
|
||||
holder.debug("税率 " + taxRate + "% 调整为 13%");
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.ds.contract.service.ContractItemService;
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -30,6 +31,7 @@ import com.ecep.contract.ds.vendor.model.PurchaseOrderItem;
|
||||
import com.ecep.contract.util.NumberUtils;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
@@ -96,10 +98,12 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
);
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllPurchaseOrderItemByContractCode(contract.getCode());
|
||||
holder.debug("查找到 " + ds.size() + " 条采购订单条目记录在 " + CloudServiceConstant.U8_NAME);
|
||||
|
||||
// U8 中 PO_Podetails 表中有与合同相关的字段,而PO_Pomain表中没有, 所以需要先查询 PO_Podetails, 再根据 POID 查询 PO_Pomain,补全采购订单
|
||||
holder.debug("在 " + CloudServiceConstant.U8_NAME + " 中检索采购订单条目记录...");
|
||||
Map<PurchaseOrder, List<PurchaseOrderItem>> updateMap = new HashMap<>();
|
||||
List<Map<String, Object>> ds = repository.findAllPurchaseOrderItemByContractCode(contract.getCode());
|
||||
holder.info("根据合同号#" + contract.getCode() + ", 查找到 " + ds.size() + " 条采购订单条目");
|
||||
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer poId = (Integer) map.get("POID");
|
||||
if (poId == 0) {
|
||||
@@ -109,8 +113,9 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
PurchaseOrder order = ordersMap.get(poId);
|
||||
if (order == null) {
|
||||
order = new PurchaseOrder();
|
||||
order.setContract(getCachedBean(ContractService.class).getById(contract.getId()));
|
||||
order.setRefId(poId);
|
||||
Contract v0 = getCachedBean(ContractService.class).getById(contract.getId());
|
||||
order.setContract(v0);
|
||||
order.setRefId((Integer) map.get("ID"));
|
||||
|
||||
order = ordersService.save(order);
|
||||
ordersMap.put(poId, order);
|
||||
@@ -200,6 +205,8 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
String venBank = (String) map.get("cVenBank");
|
||||
String venBankAccount = (String) map.get("cVenAccount");
|
||||
|
||||
Double taxRate = (Double) map.get("iTaxRate");
|
||||
|
||||
String venCode = (String) map.get("cVenCode");
|
||||
String memo = (String) map.get("cMemo");
|
||||
|
||||
@@ -211,7 +218,7 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateNumber(order::getTaxRate, order::setTaxRate, (float) map.get("iTaxRate"), holder, "税率")) {
|
||||
if (updateNumber(order::getTaxRate, order::setTaxRate, taxRate.floatValue(), holder, "税率")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
@@ -251,12 +258,13 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(order.getDescription(), memo)) {
|
||||
order.setDescription(memo);
|
||||
holder.info("描述修改为: " + memo);
|
||||
modified = true;
|
||||
if (StringUtils.hasText(memo)) {
|
||||
if (!Objects.equals(order.getDescription(), memo)) {
|
||||
order.setDescription(memo);
|
||||
holder.info("描述修改为: " + memo);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
updateCompanyBankAccount(order.getContract(), venBank, venBankAccount, holder);
|
||||
|
||||
return modified;
|
||||
@@ -277,6 +285,8 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
Integer refId = (Integer) map.get("ID");
|
||||
String inventoryCode = (String) map.get("cInvCode");
|
||||
String contractCode = (String) map.get("ContractCode");
|
||||
String contractItemRowId = (String) map.get("ContractRowGUID");
|
||||
String memo = (String) map.get("cbMemo");
|
||||
|
||||
String title = (String) map.get("cInvCode");
|
||||
double quantity = (double) map.get("iQuantity");
|
||||
@@ -326,9 +336,16 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(item.getDescription(), contractCode)) {
|
||||
item.setDescription(contractCode);
|
||||
holder.info("描述修改为: " + contractCode);
|
||||
var contractItem = getCachedBean(ContractItemService.class).findByRowId(contractItemRowId);
|
||||
if (!Objects.equals(item.getContractItem(), contractItem)) {
|
||||
item.setContractItem(contractItem);
|
||||
holder.info("合同条目修改为: #" + contractItem.getId());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(item.getDescription(), memo)) {
|
||||
item.setDescription(memo);
|
||||
holder.info("描述修改为: " + memo);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,13 +41,19 @@ public class ContractItem
|
||||
@ToString.Exclude
|
||||
private Contract contract;
|
||||
|
||||
/**
|
||||
* RowId,GUID
|
||||
*/
|
||||
@Column(name = "ROW_ID")
|
||||
private String rowId;
|
||||
|
||||
/**
|
||||
* 相关数据Id
|
||||
*/
|
||||
@Column(name = "REF_ID")
|
||||
private Integer refId;
|
||||
/**
|
||||
* 项目编号
|
||||
* 条目编号
|
||||
*/
|
||||
@Column(name = "ITEM_CODE")
|
||||
private String itemCode;
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
package com.ecep.contract.ds.contract.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.ds.contract.model.ContractItem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.contract.model.ContractItem;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ContractItemRepository extends JpaRepository<ContractItem, Integer>, JpaSpecificationExecutor<ContractItem> {
|
||||
|
||||
Optional<ContractItem> findByRowId(String rowId);
|
||||
|
||||
List<ContractItem> findAllByItemCode(String itemCode);
|
||||
|
||||
List<ContractItem> findByContractId(int contractId);
|
||||
|
||||
List<ContractItem> findByInventoryId(int inventoryId);
|
||||
|
||||
|
||||
}
|
||||
@@ -57,6 +57,15 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
|
||||
return itemRepository.findById(id).map(ContractItem::toVo).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public List<ContractItem> findAllByItemCode(String itemCode) {
|
||||
return itemRepository.findAllByItemCode(itemCode);
|
||||
}
|
||||
|
||||
public ContractItem findByRowId(String rowId) {
|
||||
return itemRepository.findByRowId(rowId).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<ContractItem> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
@@ -99,7 +108,7 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
|
||||
return itemRepository.findByContractId(contract.getId());
|
||||
}
|
||||
|
||||
public List<ContractItem> findAllByContract(ContractVo contract) {
|
||||
public List<ContractItem> findAllByContract(ContractVo contract) {
|
||||
return itemRepository.findByContractId(contract.getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
||||
import com.ecep.contract.vo.ContractItemVo;
|
||||
@@ -90,29 +91,28 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "order", "inventory");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "order", "inventory", "contractItem");
|
||||
|
||||
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())
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
@@ -158,13 +158,25 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
|
||||
if (vo.getOrder() == null) {
|
||||
model.setOrder(null);
|
||||
} else {
|
||||
model.setOrder(SpringApp.getBean(PurchaseOrdersService.class).getById(vo.getOrder()));
|
||||
if (!Objects.equals(model.getOrder().getId(), vo.getOrder())) {
|
||||
model.setOrder(SpringApp.getBean(PurchaseOrdersService.class).getById(vo.getOrder()));
|
||||
}
|
||||
}
|
||||
|
||||
if (vo.getInventoryId() == null) {
|
||||
model.setInventory(null);
|
||||
} else {
|
||||
model.setInventory(SpringApp.getBean(InventoryService.class).getById(vo.getInventoryId()));
|
||||
if (!Objects.equals(model.getInventory().getId(), vo.getInventoryId())) {
|
||||
model.setInventory(SpringApp.getBean(InventoryService.class).getById(vo.getInventoryId()));
|
||||
}
|
||||
}
|
||||
|
||||
if (vo.getContractItemId() == null) {
|
||||
model.setContractItem(null);
|
||||
} else {
|
||||
if (!Objects.equals(model.getContractItem().getId(), vo.getContractItemId())) {
|
||||
model.setContractItem(SpringApp.getBean(ContractItemService.class).getById(vo.getContractItemId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,8 @@ public class PurchaseOrder
|
||||
vo.setCode(code);
|
||||
vo.setRefId(refId);
|
||||
vo.setVendorCode(vendorCode);
|
||||
vo.setTaxRate(taxRate);
|
||||
vo.setTaxRateLocked(taxRateLocked);
|
||||
|
||||
vo.setMakerDate(makerDate);
|
||||
vo.setModifyDate(modifyDate);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ecep.contract.ds.vendor.model;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.ecep.contract.ds.contract.model.ContractItem;
|
||||
import com.ecep.contract.model.BasedEntity;
|
||||
import com.ecep.contract.model.IdentityEntity;
|
||||
import com.ecep.contract.model.Inventory;
|
||||
@@ -50,6 +51,11 @@ public class PurchaseOrderItem implements IdentityEntity, BasedEntity, Voable<Pu
|
||||
@JoinColumn(name = "INVENTORY_ID")
|
||||
@ToString.Exclude
|
||||
private Inventory inventory;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "CONTRACT_ITEM_ID")
|
||||
@ToString.Exclude
|
||||
private ContractItem contractItem;
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
@@ -110,6 +116,7 @@ public class PurchaseOrderItem implements IdentityEntity, BasedEntity, Voable<Pu
|
||||
vo.setOrder(order != null ? order.getId() : null);
|
||||
vo.setRefId(refId);
|
||||
vo.setInventoryId(inventory != null ? inventory.getId() : null);
|
||||
vo.setContractItemId(contractItem != null ? contractItem.getId() : null);
|
||||
vo.setQuantity(quantity);
|
||||
vo.setPrice(price);
|
||||
vo.setTaxRate(taxRate);
|
||||
|
||||
Reference in New Issue
Block a user