1.0.48 合同物料添加标准物料时关联销售物料信息中自动添加

dev
yinq 2 days ago
parent bb41043301
commit 49f376987b

@ -17,9 +17,12 @@ import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.oa.base.domain.vo.BaseRelationMaterialVo;
import org.dromara.oa.erp.domain.ErpContractMaterial; import org.dromara.oa.erp.domain.ErpContractMaterial;
import org.dromara.oa.erp.domain.vo.ErpContractMaterialVo; import org.dromara.oa.erp.domain.vo.ErpContractMaterialVo;
import org.dromara.oa.erp.mapper.ErpContractMaterialMapper; import org.dromara.oa.erp.mapper.ErpContractMaterialMapper;
import org.dromara.oa.base.domain.bo.BaseRelationMaterialBo;
import org.dromara.oa.base.service.IBaseRelationMaterialService;
import org.dromara.workflow.api.RemoteWorkflowService; import org.dromara.workflow.api.RemoteWorkflowService;
import org.dromara.workflow.api.domain.RemoteStartProcess; import org.dromara.workflow.api.domain.RemoteStartProcess;
import org.dromara.workflow.api.event.ProcessEvent; import org.dromara.workflow.api.event.ProcessEvent;
@ -50,6 +53,8 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
private final ErpContractMaterialMapper contractMaterialMapper; private final ErpContractMaterialMapper contractMaterialMapper;
private final IBaseRelationMaterialService baseRelationMaterialService;
@DubboReference(timeout = 30000) @DubboReference(timeout = 30000)
private RemoteWorkflowService remoteWorkflowService; private RemoteWorkflowService remoteWorkflowService;
@ -63,9 +68,9 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
public ErpContractInfoVo queryById(Long contractId) { public ErpContractInfoVo queryById(Long contractId) {
ErpContractInfoVo contractInfoVo = baseMapper.selectVoById(contractId); ErpContractInfoVo contractInfoVo = baseMapper.selectVoById(contractId);
MPJLambdaWrapper<ErpContractMaterial> lqw = JoinWrappers.lambda(ErpContractMaterial.class) MPJLambdaWrapper<ErpContractMaterial> lqw = JoinWrappers.lambda(ErpContractMaterial.class)
.selectAll(ErpContractMaterial.class) .selectAll(ErpContractMaterial.class)
.eq(contractId != null, ErpContractMaterial::getContractId, contractId) .eq(contractId != null, ErpContractMaterial::getContractId, contractId)
.eq("t.del_flag", "0");; .eq("t.del_flag", "0");
List<ErpContractMaterialVo> contractMaterialList = contractMaterialMapper.selectCustomErpContractMaterialVoList(lqw); List<ErpContractMaterialVo> contractMaterialList = contractMaterialMapper.selectCustomErpContractMaterialVoList(lqw);
contractInfoVo.setContractMaterialList(contractMaterialList); contractInfoVo.setContractMaterialList(contractMaterialList);
return contractInfoVo; return contractInfoVo;
@ -100,30 +105,30 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
private MPJLambdaWrapper<ErpContractInfo> buildQueryWrapper(ErpContractInfoBo bo) { private MPJLambdaWrapper<ErpContractInfo> buildQueryWrapper(ErpContractInfoBo bo) {
Map<String, Object> params = bo.getParams(); Map<String, Object> params = bo.getParams();
MPJLambdaWrapper<ErpContractInfo> lqw = JoinWrappers.lambda(ErpContractInfo.class) MPJLambdaWrapper<ErpContractInfo> lqw = JoinWrappers.lambda(ErpContractInfo.class)
.selectAll(ErpContractInfo.class) .selectAll(ErpContractInfo.class)
.eq(StringUtils.isNotBlank(bo.getContractFlag()), ErpContractInfo::getContractFlag, bo.getContractFlag()) .eq(StringUtils.isNotBlank(bo.getContractFlag()), ErpContractInfo::getContractFlag, bo.getContractFlag())
.eq(StringUtils.isNotBlank(bo.getContractCode()), ErpContractInfo::getContractCode, bo.getContractCode()) .eq(StringUtils.isNotBlank(bo.getContractCode()), ErpContractInfo::getContractCode, bo.getContractCode())
.eq(StringUtils.isNotBlank(bo.getCustomerContractCode()), ErpContractInfo::getCustomerContractCode, bo.getCustomerContractCode()) .eq(StringUtils.isNotBlank(bo.getCustomerContractCode()), ErpContractInfo::getCustomerContractCode, bo.getCustomerContractCode())
.like(StringUtils.isNotBlank(bo.getContractName()), ErpContractInfo::getContractName, bo.getContractName()) .like(StringUtils.isNotBlank(bo.getContractName()), ErpContractInfo::getContractName, bo.getContractName())
.eq(StringUtils.isNotBlank(bo.getContractCategory()), ErpContractInfo::getContractCategory, bo.getContractCategory()) .eq(StringUtils.isNotBlank(bo.getContractCategory()), ErpContractInfo::getContractCategory, bo.getContractCategory())
.eq(StringUtils.isNotBlank(bo.getContractType()), ErpContractInfo::getContractType, bo.getContractType()) .eq(StringUtils.isNotBlank(bo.getContractType()), ErpContractInfo::getContractType, bo.getContractType())
.eq(StringUtils.isNotBlank(bo.getBusinessDirection()), ErpContractInfo::getBusinessDirection, bo.getBusinessDirection()) .eq(StringUtils.isNotBlank(bo.getBusinessDirection()), ErpContractInfo::getBusinessDirection, bo.getBusinessDirection())
.eq(bo.getContractDeptId() != null, ErpContractInfo::getContractDeptId, bo.getContractDeptId()) .eq(bo.getContractDeptId() != null, ErpContractInfo::getContractDeptId, bo.getContractDeptId())
.eq(bo.getContractDate() != null, ErpContractInfo::getContractDate, bo.getContractDate()) .eq(bo.getContractDate() != null, ErpContractInfo::getContractDate, bo.getContractDate())
.eq(bo.getTotalPrice() != null, ErpContractInfo::getTotalPrice, bo.getTotalPrice()) .eq(bo.getTotalPrice() != null, ErpContractInfo::getTotalPrice, bo.getTotalPrice())
.eq(StringUtils.isNotBlank(bo.getContractStatus()), ErpContractInfo::getContractStatus, bo.getContractStatus()) .eq(StringUtils.isNotBlank(bo.getContractStatus()), ErpContractInfo::getContractStatus, bo.getContractStatus())
.eq(StringUtils.isNotBlank(bo.getFlowStatus()), ErpContractInfo::getFlowStatus, bo.getFlowStatus()) .eq(StringUtils.isNotBlank(bo.getFlowStatus()), ErpContractInfo::getFlowStatus, bo.getFlowStatus())
.eq(bo.getTemplateId() != null, ErpContractInfo::getTemplateId, bo.getTemplateId()) .eq(bo.getTemplateId() != null, ErpContractInfo::getTemplateId, bo.getTemplateId())
.eq(StringUtils.isNotBlank(bo.getOssId()), ErpContractInfo::getOssId, bo.getOssId()) .eq(StringUtils.isNotBlank(bo.getOssId()), ErpContractInfo::getOssId, bo.getOssId())
.eq(StringUtils.isNotBlank(bo.getPaymentMethod()), ErpContractInfo::getPaymentMethod, bo.getPaymentMethod()) .eq(StringUtils.isNotBlank(bo.getPaymentMethod()), ErpContractInfo::getPaymentMethod, bo.getPaymentMethod())
.eq(bo.getSignatureAppendix() != null, ErpContractInfo::getSignatureAppendix, bo.getSignatureAppendix()) .eq(bo.getSignatureAppendix() != null, ErpContractInfo::getSignatureAppendix, bo.getSignatureAppendix())
.eq(bo.getTaxRate() != null, ErpContractInfo::getTaxRate, bo.getTaxRate()) .eq(bo.getTaxRate() != null, ErpContractInfo::getTaxRate, bo.getTaxRate())
.eq(StringUtils.isNotBlank(bo.getActiveFlag()), ErpContractInfo::getActiveFlag, bo.getActiveFlag()) .eq(StringUtils.isNotBlank(bo.getActiveFlag()), ErpContractInfo::getActiveFlag, bo.getActiveFlag())
.eq(bo.getContractManagerId() != null, ErpContractInfo::getContractManagerId, bo.getContractManagerId()) .eq(bo.getContractManagerId() != null, ErpContractInfo::getContractManagerId, bo.getContractManagerId())
.eq(StringUtils.isNotBlank(bo.getCapitalizedAmount()), ErpContractInfo::getCapitalizedAmount, bo.getCapitalizedAmount()) .eq(StringUtils.isNotBlank(bo.getCapitalizedAmount()), ErpContractInfo::getCapitalizedAmount, bo.getCapitalizedAmount())
.eq(StringUtils.isNotBlank(bo.getContractTemplateFlag()), ErpContractInfo::getContractTemplateFlag, bo.getContractTemplateFlag()) .eq(StringUtils.isNotBlank(bo.getContractTemplateFlag()), ErpContractInfo::getContractTemplateFlag, bo.getContractTemplateFlag())
.eq("t.del_flag", "0") .eq("t.del_flag", "0")
.orderByDesc(ErpContractInfo::getCreateTime); .orderByDesc(ErpContractInfo::getCreateTime);
return lqw; return lqw;
} }
@ -142,8 +147,12 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
if (flag && contractMaterialList != null && !contractMaterialList.isEmpty()) { if (flag && contractMaterialList != null && !contractMaterialList.isEmpty()) {
bo.setContractId(add.getContractId()); bo.setContractId(add.getContractId());
// 获取合同客户ID优先使用甲方如果为空则使用乙方
Long customerId = add.getOneCustomerId();
for (ErpContractMaterial erpContractMaterial : contractMaterialList) { for (ErpContractMaterial erpContractMaterial : contractMaterialList) {
erpContractMaterial.setContractId(add.getContractId()); erpContractMaterial.setContractId(add.getContractId());
// 处理关联物料信息
processRelationMaterial(erpContractMaterial, customerId);
contractMaterialMapper.insert(erpContractMaterial); contractMaterialMapper.insert(erpContractMaterial);
} }
} }
@ -166,22 +175,63 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
lqwRecord.eq(ErpContractMaterial::getContractId, bo.getContractId()); lqwRecord.eq(ErpContractMaterial::getContractId, bo.getContractId());
List<ErpContractMaterial> contractMaterialOldList = contractMaterialMapper.selectList(lqwRecord); List<ErpContractMaterial> contractMaterialOldList = contractMaterialMapper.selectList(lqwRecord);
if (contractMaterialList != null && !contractMaterialList.isEmpty()) { if (contractMaterialList != null && !contractMaterialList.isEmpty()) {
// 获取合同客户ID优先使用甲方如果为空则使用乙方
Long customerId = update.getOneCustomerId();
for (ErpContractMaterial contractMaterial : contractMaterialList) { for (ErpContractMaterial contractMaterial : contractMaterialList) {
// 处理关联物料信息
processRelationMaterial(contractMaterial, customerId);
contractMaterialMapper.insertOrUpdate(contractMaterial); contractMaterialMapper.insertOrUpdate(contractMaterial);
} }
Set<Long> existingContractMaterialIds = contractMaterialList.stream() Set<Long> existingContractMaterialIds = contractMaterialList.stream()
.map(ErpContractMaterial::getContractMaterialId) .map(ErpContractMaterial::getContractMaterialId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
List<ErpContractMaterial> filterContractMaterialIds = contractMaterialOldList.stream() List<ErpContractMaterial> filterContractMaterialIds = contractMaterialOldList.stream()
.filter(material -> !existingContractMaterialIds.contains(material.getContractMaterialId())) .filter(material -> !existingContractMaterialIds.contains(material.getContractMaterialId()))
.toList(); .toList();
for (ErpContractMaterial filterContractMaterialId : filterContractMaterialIds) { for (ErpContractMaterial filterContractMaterialId : filterContractMaterialIds) {
contractMaterialMapper.deleteById(filterContractMaterialId.getContractMaterialId()); contractMaterialMapper.deleteById(filterContractMaterialId.getContractMaterialId());
} }
} else if (contractMaterialList != null && contractMaterialList.isEmpty()) {
for (ErpContractMaterial contractMaterial : contractMaterialOldList) {
contractMaterialMapper.deleteById(contractMaterial.getContractMaterialId());
}
} }
return baseMapper.updateById(update) > 0; return baseMapper.updateById(update) > 0;
} }
/**
*
*
* @param erpContractMaterial
* @param customerId ID
*/
private void processRelationMaterial(ErpContractMaterial erpContractMaterial, Long customerId) {
if (erpContractMaterial.getMaterialId() != null && customerId != null && erpContractMaterial.getMaterialFlag().equals("1")) {
Long relationMaterialId = erpContractMaterial.getRelationMaterialId();
// 如果relationMaterialId为空则查询是否存在关联物料信息
if (relationMaterialId == null) {
BaseRelationMaterialBo queryBo = new BaseRelationMaterialBo();
queryBo.setMaterialId(erpContractMaterial.getMaterialId());
queryBo.setCustomerId(customerId);
queryBo.setSaleMaterialName(erpContractMaterial.getProductName());
List<BaseRelationMaterialVo> existingRelationMaterials = baseRelationMaterialService.queryList(queryBo);
if (existingRelationMaterials == null || existingRelationMaterials.isEmpty()) {
// 不存在则创建关联物料信息
BaseRelationMaterialBo relationMaterialBo = new BaseRelationMaterialBo();
relationMaterialBo.setMaterialId(erpContractMaterial.getMaterialId());
relationMaterialBo.setCustomerId(customerId);
relationMaterialBo.setSaleMaterialName(erpContractMaterial.getProductName());
baseRelationMaterialService.insertByBo(relationMaterialBo);
relationMaterialId = relationMaterialBo.getRelationMaterialId();
} else {
// 如果已存在使用第一个的ID
relationMaterialId = existingRelationMaterials.get(0).getRelationMaterialId();
}
erpContractMaterial.setRelationMaterialId(relationMaterialId);
}
}
}
/** /**
* *
*/ */

Loading…
Cancel
Save