diff --git a/ruoyi-gateway/src/main/resources/application.yml b/ruoyi-gateway/src/main/resources/application.yml index 98c9dd04..97c7b61d 100644 --- a/ruoyi-gateway/src/main/resources/application.yml +++ b/ruoyi-gateway/src/main/resources/application.yml @@ -1,6 +1,6 @@ # Tomcat server: - port: 8080 + port: 8095 servlet: context-path: / diff --git a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractChangeServiceImpl.java b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractChangeServiceImpl.java index 5706f496..fbfa2c43 100644 --- a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractChangeServiceImpl.java +++ b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractChangeServiceImpl.java @@ -1,6 +1,5 @@ package org.dromara.oa.erp.service.impl; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.dromara.common.core.enums.BusinessStatusEnum; @@ -27,11 +26,9 @@ import org.dromara.oa.erp.mapper.*; import org.dromara.oa.erp.service.IErpContractChangeService; import java.math.BigDecimal; -import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.List; -import java.util.Map; -import java.util.Collection; import java.util.Objects; /** @@ -55,6 +52,15 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { /** 合同变更流程编码(审批通过后回写用) */ public static final String FLOW_CODE_CONTRACT_CHANGE = "HTBG"; + /** 变更类型:1内容变更 2解除合同 */ + private static final String CHANGE_TYPE_CONTENT = "1"; + private static final String CHANGE_TYPE_TERMINATE = "2"; + /** 未回写 */ + private static final String WRITE_BACK_NO = "0"; + /** 已回写/可用 */ + private static final String WRITE_BACK_YES = "1"; + private static final String CHANGE_STATUS_AVAILABLE = "3"; + /** * 查询合同变更 * @@ -93,34 +99,31 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { } private MPJLambdaWrapper buildQueryWrapper(ErpContractChangeBo bo) { - Map params = bo.getParams(); - MPJLambdaWrapper lqw = JoinWrappers.lambda(ErpContractChange.class) - .selectAll(ErpContractChange.class) - .eq(ErpContractChange::getDelFlag, "0") - .eq(bo.getContractId() != null, ErpContractChange::getContractId, bo.getContractId()) - .eq(StringUtils.isNotBlank(bo.getChangeCode()), ErpContractChange::getChangeCode, bo.getChangeCode()) - .eq(StringUtils.isNotBlank(bo.getChangeType()), ErpContractChange::getChangeType, bo.getChangeType()) - .eq(StringUtils.isNotBlank(bo.getChangeContractCode()), ErpContractChange::getChangeContractCode, bo.getChangeContractCode()) - .like(StringUtils.isNotBlank(bo.getChangeContractName()), ErpContractChange::getChangeContractName, bo.getChangeContractName()) - .like(StringUtils.isNotBlank(bo.getCustomerName()), ErpContractChange::getCustomerName, bo.getCustomerName()) - .eq(bo.getChangeContractAmount() != null, ErpContractChange::getChangeContractAmount, bo.getChangeContractAmount()) - .eq(StringUtils.isNotBlank(bo.getContractCode()), ErpContractChange::getContractCode, bo.getContractCode()) - .like(StringUtils.isNotBlank(bo.getContractName()), ErpContractChange::getContractName, bo.getContractName()) - .like(StringUtils.isNotBlank(bo.getOriginalCustomerName()), ErpContractChange::getOriginalCustomerName, bo.getOriginalCustomerName()) - .eq(bo.getOriginalContractAmount() != null, ErpContractChange::getOriginalContractAmount, bo.getOriginalContractAmount()) - .eq(StringUtils.isNotBlank(bo.getChangeReason()), ErpContractChange::getChangeReason, bo.getChangeReason()) - .eq(bo.getApplyTime() != null, ErpContractChange::getApplyTime, bo.getApplyTime()) - .eq(bo.getUndertakeDeptId() != null, ErpContractChange::getUndertakeDeptId, bo.getUndertakeDeptId()) - .eq(bo.getUndertakeBy() != null, ErpContractChange::getUndertakeBy, bo.getUndertakeBy()) - .eq(StringUtils.isNotBlank(bo.getIndustryRegion()), ErpContractChange::getIndustryRegion, bo.getIndustryRegion()) - .eq(StringUtils.isNotBlank(bo.getSealLegalEntity()), ErpContractChange::getSealLegalEntity, bo.getSealLegalEntity()) - .eq(StringUtils.isNotBlank(bo.getChangeStatus()), ErpContractChange::getChangeStatus, bo.getChangeStatus()) - .eq(StringUtils.isNotBlank(bo.getFlowStatus()), ErpContractChange::getFlowStatus, bo.getFlowStatus()) - .eq(StringUtils.isNotBlank(bo.getWriteBackFlag()), ErpContractChange::getWriteBackFlag, bo.getWriteBackFlag()) - .eq(bo.getWriteBackTime() != null, ErpContractChange::getWriteBackTime, bo.getWriteBackTime()) - .eq(StringUtils.isNotBlank(bo.getActiveFlag()), ErpContractChange::getActiveFlag, bo.getActiveFlag()) -; - return lqw; + return JoinWrappers.lambda(ErpContractChange.class) + .selectAll(ErpContractChange.class) + .eq(ErpContractChange::getDelFlag, "0") + .eq(bo.getContractId() != null, ErpContractChange::getContractId, bo.getContractId()) + .eq(StringUtils.isNotBlank(bo.getChangeCode()), ErpContractChange::getChangeCode, bo.getChangeCode()) + .eq(StringUtils.isNotBlank(bo.getChangeType()), ErpContractChange::getChangeType, bo.getChangeType()) + .eq(StringUtils.isNotBlank(bo.getChangeContractCode()), ErpContractChange::getChangeContractCode, bo.getChangeContractCode()) + .like(StringUtils.isNotBlank(bo.getChangeContractName()), ErpContractChange::getChangeContractName, bo.getChangeContractName()) + .like(StringUtils.isNotBlank(bo.getCustomerName()), ErpContractChange::getCustomerName, bo.getCustomerName()) + .eq(bo.getChangeContractAmount() != null, ErpContractChange::getChangeContractAmount, bo.getChangeContractAmount()) + .eq(StringUtils.isNotBlank(bo.getContractCode()), ErpContractChange::getContractCode, bo.getContractCode()) + .like(StringUtils.isNotBlank(bo.getContractName()), ErpContractChange::getContractName, bo.getContractName()) + .like(StringUtils.isNotBlank(bo.getOriginalCustomerName()), ErpContractChange::getOriginalCustomerName, bo.getOriginalCustomerName()) + .eq(bo.getOriginalContractAmount() != null, ErpContractChange::getOriginalContractAmount, bo.getOriginalContractAmount()) + .eq(StringUtils.isNotBlank(bo.getChangeReason()), ErpContractChange::getChangeReason, bo.getChangeReason()) + .eq(bo.getApplyTime() != null, ErpContractChange::getApplyTime, bo.getApplyTime()) + .eq(bo.getUndertakeDeptId() != null, ErpContractChange::getUndertakeDeptId, bo.getUndertakeDeptId()) + .eq(bo.getUndertakeBy() != null, ErpContractChange::getUndertakeBy, bo.getUndertakeBy()) + .eq(StringUtils.isNotBlank(bo.getIndustryRegion()), ErpContractChange::getIndustryRegion, bo.getIndustryRegion()) + .eq(StringUtils.isNotBlank(bo.getSealLegalEntity()), ErpContractChange::getSealLegalEntity, bo.getSealLegalEntity()) + .eq(StringUtils.isNotBlank(bo.getChangeStatus()), ErpContractChange::getChangeStatus, bo.getChangeStatus()) + .eq(StringUtils.isNotBlank(bo.getFlowStatus()), ErpContractChange::getFlowStatus, bo.getFlowStatus()) + .eq(StringUtils.isNotBlank(bo.getWriteBackFlag()), ErpContractChange::getWriteBackFlag, bo.getWriteBackFlag()) + .eq(bo.getWriteBackTime() != null, ErpContractChange::getWriteBackTime, bo.getWriteBackTime()) + .eq(StringUtils.isNotBlank(bo.getActiveFlag()), ErpContractChange::getActiveFlag, bo.getActiveFlag()); } /** @@ -156,8 +159,13 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { /** * 保存前的数据校验 */ - private void validEntityBeforeSave(ErpContractChange entity){ - //TODO 做一些数据校验,如唯一约束 + private void validEntityBeforeSave(ErpContractChange entity) { + if (entity.getContractId() == null) { + throw new IllegalArgumentException("原合同ID不能为空"); + } + if (StringUtils.isBlank(entity.getChangeType())) { + throw new IllegalArgumentException("变更类型不能为空"); + } } /** @@ -183,9 +191,13 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { validEntityBeforeSave(main); if (isUpdate) { + ErpContractChange existing = baseMapper.selectById(main.getContractChangeId()); + if (existing != null && StringUtils.isNotBlank(existing.getWriteBackFlag()) && WRITE_BACK_YES.equals(existing.getWriteBackFlag())) { + main.setWriteBackFlag(existing.getWriteBackFlag()); + main.setWriteBackTime(existing.getWriteBackTime()); + } baseMapper.updateById(main); - // 内容变更时先删子表再插 - if ("1".equals(bo.getChangeType())) { + if (CHANGE_TYPE_CONTENT.equals(bo.getChangeType())) { deleteChangeSubByChangeId(main.getContractChangeId()); } } else { @@ -193,17 +205,18 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { bo.setContractChangeId(main.getContractChangeId()); } - if ("1".equals(bo.getChangeType())) { + if (CHANGE_TYPE_CONTENT.equals(bo.getChangeType())) { + Long changeId = main.getContractChangeId(); if (bo.getChangeInfo() != null) { ErpContractChangeInfo info = MapstructUtils.convert(bo.getChangeInfo(), ErpContractChangeInfo.class); - info.setContractChangeId(main.getContractChangeId()); + info.setContractChangeId(changeId); info.setChangeInfoId(null); changeInfoMapper.insert(info); } if (bo.getChangeMaterialList() != null && !bo.getChangeMaterialList().isEmpty()) { for (ErpContractChangeMaterialBo m : bo.getChangeMaterialList()) { ErpContractChangeMaterial e = MapstructUtils.convert(m, ErpContractChangeMaterial.class); - e.setContractChangeId(main.getContractChangeId()); + e.setContractChangeId(changeId); e.setChangeMaterialId(null); changeMaterialMapper.insert(e); } @@ -211,7 +224,7 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { if (bo.getChangePaymentMethodList() != null && !bo.getChangePaymentMethodList().isEmpty()) { for (ErpContractChangePaymentMethodBo p : bo.getChangePaymentMethodList()) { ErpContractChangePaymentMethod e = MapstructUtils.convert(p, ErpContractChangePaymentMethod.class); - e.setContractChangeId(main.getContractChangeId()); + e.setContractChangeId(changeId); e.setChangePaymentId(null); changePaymentMethodMapper.insert(e); } @@ -244,20 +257,19 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { e.setChangeContractName(bo.getChangeContractName()); e.setCustomerName(bo.getCustomerName()); e.setChangeContractAmount(bo.getChangeContractAmount()); - e.setWriteBackFlag("0"); + if (bo.getContractChangeId() == null) { + e.setWriteBackFlag(WRITE_BACK_NO); + } return e; } private void deleteChangeSubByChangeId(Long contractChangeId) { - LambdaQueryWrapper q1 = new LambdaQueryWrapper<>(); - q1.eq(ErpContractChangeInfo::getContractChangeId, contractChangeId); - changeInfoMapper.delete(q1); - LambdaQueryWrapper q2 = new LambdaQueryWrapper<>(); - q2.eq(ErpContractChangeMaterial::getContractChangeId, contractChangeId); - changeMaterialMapper.delete(q2); - LambdaQueryWrapper q3 = new LambdaQueryWrapper<>(); - q3.eq(ErpContractChangePaymentMethod::getContractChangeId, contractChangeId); - changePaymentMethodMapper.delete(q3); + changeInfoMapper.delete(new LambdaQueryWrapper() + .eq(ErpContractChangeInfo::getContractChangeId, contractChangeId)); + changeMaterialMapper.delete(new LambdaQueryWrapper() + .eq(ErpContractChangeMaterial::getContractChangeId, contractChangeId)); + changePaymentMethodMapper.delete(new LambdaQueryWrapper() + .eq(ErpContractChangePaymentMethod::getContractChangeId, contractChangeId)); } @Override @@ -281,55 +293,56 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { @Transactional(rollbackFor = Exception.class) public void writeBackToContract(Long contractChangeId) { ErpContractChange change = baseMapper.selectById(contractChangeId); - if (change == null || !"0".equals(change.getWriteBackFlag())) { + if (change == null || !WRITE_BACK_NO.equals(change.getWriteBackFlag())) { return; } - change.setChangeStatus("3"); - baseMapper.updateById(change); Long contractId = change.getContractId(); - if ("2".equals(change.getChangeType())) { - ErpContractInfo info = contractInfoMapper.selectById(contractId); - if (info != null) { - info.setActiveFlag("0"); - contractInfoMapper.updateById(info); - } + if (CHANGE_TYPE_TERMINATE.equals(change.getChangeType())) { + doWriteBackTerminate(contractId); } else { - List infoList = changeInfoMapper.selectVoList( - new LambdaQueryWrapper().eq(ErpContractChangeInfo::getContractChangeId, contractChangeId)); - if (!infoList.isEmpty()) { - ErpContractInfo contractInfo = contractInfoMapper.selectById(contractId); - if (contractInfo != null) { - ErpContractChangeInfoVo snap = infoList.get(0); - copyChangeInfoToContract(snap, contractInfo); - contractInfoMapper.updateById(contractInfo); - } - } - contractMaterialMapper.delete(new LambdaQueryWrapper().eq(ErpContractMaterial::getContractId, contractId)); - List materials = changeMaterialMapper.selectList( - new LambdaQueryWrapper().eq(ErpContractChangeMaterial::getContractChangeId, contractChangeId)); - for (ErpContractChangeMaterial m : materials) { - ErpContractMaterial cm = new ErpContractMaterial(); - BeanUtil.copyProperties(m, cm, "contractMaterialId", "contractChangeId", "createTime", "updateTime", "createBy", "updateBy"); - cm.setContractId(contractId); - cm.setContractMaterialId(null); - contractMaterialMapper.insert(cm); - } - contractPaymentMethodMapper.delete(new LambdaQueryWrapper().eq(ErpContractPaymentMethod::getContractId, contractId)); - List payments = changePaymentMethodMapper.selectList( - new LambdaQueryWrapper().eq(ErpContractChangePaymentMethod::getContractChangeId, contractChangeId)); - for (ErpContractChangePaymentMethod p : payments) { - ErpContractPaymentMethod cpm = new ErpContractPaymentMethod(); - BeanUtil.copyProperties(p, cpm, "paymentMethodId", "contractChangeId", "changePaymentId", "createTime", "updateTime", "createBy", "updateBy"); - cpm.setContractId(contractId); - cpm.setPaymentMethodId(null); - contractPaymentMethodMapper.insert(cpm); - } + doWriteBackContent(contractChangeId, contractId); } - change.setWriteBackFlag("1"); + change.setChangeStatus(CHANGE_STATUS_AVAILABLE); + change.setFlowStatus(BusinessStatusEnum.FINISH.getStatus()); + change.setWriteBackFlag(WRITE_BACK_YES); change.setWriteBackTime(new Date()); baseMapper.updateById(change); } + private void doWriteBackTerminate(Long contractId) { + ErpContractInfo info = contractInfoMapper.selectById(contractId); + if (info != null) { + info.setActiveFlag("0"); + contractInfoMapper.updateById(info); + } + } + + private void doWriteBackContent(Long contractChangeId, Long contractId) { + List infoList = changeInfoMapper.selectVoList( + new LambdaQueryWrapper().eq(ErpContractChangeInfo::getContractChangeId, contractChangeId)); + if (!infoList.isEmpty()) { + ErpContractInfo contractInfo = contractInfoMapper.selectById(contractId); + if (contractInfo != null) { + copyChangeInfoToContract(infoList.get(0), contractInfo); + contractInfoMapper.updateById(contractInfo); + } + } + LambdaQueryWrapper materialDel = new LambdaQueryWrapper().eq(ErpContractMaterial::getContractId, contractId); + contractMaterialMapper.delete(materialDel); + List materials = changeMaterialMapper.selectList( + new LambdaQueryWrapper().eq(ErpContractChangeMaterial::getContractChangeId, contractChangeId)); + for (ErpContractChangeMaterial m : materials) { + contractMaterialMapper.insert(copyChangeMaterialToContract(m, contractId)); + } + LambdaQueryWrapper paymentDel = new LambdaQueryWrapper().eq(ErpContractPaymentMethod::getContractId, contractId); + contractPaymentMethodMapper.delete(paymentDel); + List payments = changePaymentMethodMapper.selectList( + new LambdaQueryWrapper().eq(ErpContractChangePaymentMethod::getContractChangeId, contractChangeId)); + for (ErpContractChangePaymentMethod p : payments) { + contractPaymentMethodMapper.insert(copyChangePaymentToContract(p, contractId)); + } + } + /** * 合同变更流程监听:审批通过后回写合同表 */ @@ -353,7 +366,7 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { contract.setBusinessDirection(snap.getBusinessDirection()); contract.setContractDeptId(snap.getContractDeptId()); contract.setContractDate(snap.getContractDate()); - contract.setTotalPrice(snap.getTotalPrice() != null ? BigDecimal.valueOf(snap.getTotalPrice()) : null); + contract.setTotalPrice(toBigDecimal(snap.getTotalPrice())); contract.setOneCustomerId(snap.getOneCustomerId()); contract.setOneRepresent(snap.getOneRepresent()); contract.setOneDate(snap.getOneDate()); @@ -375,11 +388,59 @@ public class ErpContractChangeServiceImpl implements IErpContractChangeService { contract.setWarrantyPeriodDescription(snap.getWarrantyPeriodDescription()); contract.setDeliveryLocation(snap.getDeliveryLocation()); contract.setShipMethod(snap.getShipMethod()); - contract.setTaxRate(snap.getTaxRate() != null ? BigDecimal.valueOf(snap.getTaxRate()) : null); + contract.setTaxRate(toBigDecimal(snap.getTaxRate())); contract.setSigningPlace(snap.getSigningPlace()); contract.setMaterialRemark(snap.getMaterialRemark()); contract.setContractTemplateFlag(snap.getContractTemplateFlag()); contract.setCapitalizedAmount(snap.getCapitalizedAmount()); contract.setRemark(snap.getRemark()); } + + /** 变更物料快照转合同物料(回写)*/ + private ErpContractMaterial copyChangeMaterialToContract(ErpContractChangeMaterial m, Long contractId) { + ErpContractMaterial cm = new ErpContractMaterial(); + cm.setContractId(contractId); + cm.setContractMaterialId(null); + cm.setMaterialFlag(m.getMaterialFlag()); + cm.setProductName(m.getProductName()); + cm.setSpecificationDescription(m.getSpecificationDescription()); + cm.setMaterialId(m.getMaterialId()); + cm.setRelationMaterialId(m.getRelationMaterialId()); + cm.setUnitId(m.getUnitId()); + cm.setRemark(m.getRemark()); + cm.setActiveFlag(StringUtils.isNotBlank(m.getActiveFlag()) ? m.getActiveFlag() : "1"); + cm.setAmount(toBigDecimal(m.getAmount())); + cm.setBeforePrice(toBigDecimal(m.getBeforePrice())); + cm.setTaxRate(toBigDecimal(m.getTaxRate())); + cm.setIncludingPrice(toBigDecimal(m.getIncludingPrice())); + cm.setSubtotal(toBigDecimal(m.getSubtotal())); + return cm; + } + + /** 变更付款方式快照转合同付款方式(回写),兼容 Long/Number 与 BigDecimal */ + private ErpContractPaymentMethod copyChangePaymentToContract(ErpContractChangePaymentMethod p, Long contractId) { + ErpContractPaymentMethod cpm = new ErpContractPaymentMethod(); + cpm.setContractId(contractId); + cpm.setPaymentMethodId(null); + cpm.setSortOrder(p.getSortOrder()); + cpm.setPaymentStageId(p.getPaymentStageId()); + cpm.setPaymentDeadline(toBigDecimal(p.getPaymentDeadline())); + cpm.setPaymentPercentage(toBigDecimal(p.getPaymentPercentage())); + cpm.setInvoicePercentage(toBigDecimal(p.getInvoicePercentage())); + cpm.setPaymentAmount(toBigDecimal(p.getPaymentAmount())); + cpm.setPaymentDescription(p.getPaymentDescription()); + cpm.setRemark(p.getRemark()); + cpm.setActiveFlag(StringUtils.isNotBlank(p.getActiveFlag()) ? p.getActiveFlag() : "1"); + return cpm; + } + + private static BigDecimal toBigDecimal(Number n) { + if (n == null) { + return null; + } + if (n instanceof BigDecimal) { + return (BigDecimal) n; + } + return BigDecimal.valueOf(n.doubleValue()); + } }