合同流程 更新接口API

master
Harry Yang 2022-12-30 18:06:39 +08:00
parent 9093fab194
commit 6cf9459452
6 changed files with 104 additions and 27 deletions

View File

@ -147,6 +147,7 @@ public class ApplicationExceptionHandler {
@ExceptionHandler(NullPointerException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Json nullPointer(NullPointerException exception) {
log.error("An Exception occurred", exception);
final StackTraceElement[] stackTrace = exception.getStackTrace();
if (ObjectUtils.isEmpty(stackTrace)) {
return Json.failed("空指针", "暂无堆栈信息");

View File

@ -477,43 +477,101 @@ public class ProcessController {
@Transactional(rollbackFor = Exception.class)
public void update(@RequestBody @Valid ProcessUpdateForm form) throws Exception {
ProjectProcess entity = processService.getById(form.getId());
Integer processId = entity.getId();
ProcessType processType = entity.getProcessType();
entity.setTaxRate(form.getTaxRate());
entity.setContractNo(form.getContractNo());
entity.setContractName(form.getContractName());
entity.setApplyDept(form.getApplyDept());
entity.setSealTypes(SealTypeArray.of(form.getSealTypes()));
entity.setApplyDept(String.join(",", form.getApplyDept()));
entity.setAttachmentUri(JSON.toJSONString(form.getAttachments()));
entityManager.merge(entity);
switch (entity.getProcessType()) {
case sale_contract: {
SaleContract contract = processService.findSaleContract(form.getId());
contract.setClientName(form.getClientName());
contract.setPaymentTerms(form.getPaymentTerms());
contract.setApplyPersonPhone(form.getApplyPersonPhone());
entityManager.merge(contract);
break;
}
case procurement_contract: {
ProcurementContract contract = processService.findProcurementContract(form.getId());
contract.setProcurementMode(form.getProcurementMode());
contract.setPaymentTerms(form.getPaymentTerms());
contract.setSupplierName(form.getSupplierName());
entityManager.merge(contract);
if (processType == ProcessType.sale_contract) {
SaleContract contract = processService.findSaleContract(form.getId());
contract.setClientName(form.getClientName());
contract.setPaymentTerms(form.getPaymentTerms());
contract.setApplyPersonPhone(form.getApplyPersonPhone());
entityManager.merge(contract);
// 保存BudgetPurchaseAmount的时候要检测 budgetCostId 该条记录不能重复
// BudgetPurchaseAmount purchaseAmount = processService.getPurchaseAmount(amountForm.budgetCostId, processId);
break;
}
default:
throw new UnsupportedOperationException("还不支持");
processService.updateIncomeDetails(form.getIncomeDetails());
}
else if (processType == ProcessType.procurement_contract) {
ProcurementContract contract = processService.findProcurementContract(form.getId());
contract.setProcurementMode(form.getProcurementMode());
contract.setPaymentTerms(form.getPaymentTerms());
contract.setSupplierName(form.getSupplierName());
entityManager.merge(contract);
processService.updateIncomeDetails(form.getIncomeDetails());
Integer contractId = contract.getId();
if (!CollectionUtils.isEmpty(form.supplierMaterials)) {
for (SupplierMaterial material : form.supplierMaterials) {
material.setProcessId(processId);
material.setContractId(contractId);
entityManager.merge(material);
}
}
if (!CollectionUtils.isEmpty(form.purchaseAmount)) {
for (BudgetPurchaseAmountModel amountForm : form.purchaseAmount) {
// 草稿模式也不允许为空 (基础数据)
Assert.notNull(amountForm.amount, "合同明细填写不完整");
Assert.notNull(amountForm.budgetCostId, "合同明细填写不完整");
// 已经采购的数量 要么是数据库存在的值要么是0 ,数据库获取已经采购数目
BigDecimal amountAlready = processService.getAmountAlready(amountForm.budgetCostId);
// 新建
BudgetPurchaseAmount purchaseAmount = new BudgetPurchaseAmount();
purchaseAmount.setId(amountForm.id);
purchaseAmount.setProcessId(processId);
purchaseAmount.setContractId(contractId);
purchaseAmount.setAmount(amountForm.amount);
purchaseAmount.setBudgetCostId(amountForm.budgetCostId);
purchaseAmount.setAmountCurrent(amountForm.amountCurrent);
// 更新到数据库
purchaseAmount.setAmountAlready(amountAlready);
// TODO 提交模式才计算 剩余
if (form.getStatus() == ProcessStatus.to_be_audit) {
// 当前的必须填写
Assert.notNull(amountForm.amountCurrent, "合同明细填写不完整");
// 提交的时候 更新(计算)已经采购的数量 = 已经采购的数量 + 本次采购数量
amountAlready = amountAlready.add(amountForm.amountCurrent);
purchaseAmount.setAmountAlready(amountAlready); // 更新数据库
// amountForm.amount 和数据库的一致 剩余的未采购数量 = 总数 - 已经采购数量
BigDecimal amountLeft = amountForm.amount.subtract(amountAlready);
purchaseAmount.setAmountLeft(amountLeft);
}
entityManager.merge(purchaseAmount);
Integer amountId = purchaseAmount.getId(); // ID 自动生成或者使用之前已经有的
// 保存成本对应的 明细
if (!CollectionUtils.isEmpty(amountForm.details)) {
for (BudgetPurchaseDetailModel detail : amountForm.details) {
BudgetPurchaseDetail purchaseDetail = new BudgetPurchaseDetail();
// 关联主键
purchaseDetail.setId(detail.id);
purchaseDetail.setAmountId(amountId);
purchaseDetail.setProcessId(processId);
purchaseDetail.setContractId(contractId);
purchaseDetail.setBudgetCostId(amountForm.budgetCostId);
BeanUtils.copyProperties(detail, purchaseDetail, "details");
entityManager.merge(purchaseDetail);
}
}
}
}
}
if (form.getStatus() == ProcessStatus.to_be_audit) {
processService.startAuditProgress(entity);

View File

@ -18,6 +18,8 @@ import lombok.ToString;
@EqualsAndHashCode
public class BudgetPurchaseAmountModel {
public Integer id;
// 所有的
public BigDecimal amount;

View File

@ -13,6 +13,8 @@ import lombok.Data;
@Data
public class BudgetPurchaseDetailModel {
public Integer id;
// 供应商名称
private String supplierName;

View File

@ -123,6 +123,7 @@ public class ProjectProcess implements Serializable {
@PrePersist
void prePersist() {
this.createAt = LocalDateTime.now();
this.lastUpdateAt = this.createAt;
}
static class SealTypeArraySerializer extends JsonSerializer<SealTypeArray> {

View File

@ -8,6 +8,7 @@ import cn.palmte.work.model.enums.ProcessStatus;
import cn.palmte.work.model.enums.ProcurementMode;
import cn.palmte.work.model.process.BudgetPurchaseAmountModel;
import cn.palmte.work.model.process.ProcessAttachment;
import cn.palmte.work.model.process.SupplierMaterial;
import lombok.Data;
/**
@ -22,7 +23,17 @@ public class ProcessUpdateForm {
@NotNull
private Integer id;
private String[] applyDept;
// 申请部门 部门1,部门2,部门3 (逗号分割)
private String applyDept;
// 申请部门ID(逗号分割)
private String applyDeptId;
// 申请部门领导ID
private Integer applyDeptLeaderId;
// 申请部门领导
private String applyDeptLeaderName;
// 合同编号
private String contractNo;
@ -55,8 +66,10 @@ public class ProcessUpdateForm {
private List<ProcessAttachment> attachments;
private List<SaleContractDetailForm> incomeDetails;
public List<SaleContractDetailForm> incomeDetails;
public List<SupplierMaterial> supplierMaterials;
// 采购详情
private List<BudgetPurchaseAmountModel> purchaseAmount;
public List<BudgetPurchaseAmountModel> purchaseAmount;
}