|
|
|
|
@ -17,9 +17,12 @@ import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
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.vo.ErpContractMaterialVo;
|
|
|
|
|
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.domain.RemoteStartProcess;
|
|
|
|
|
import org.dromara.workflow.api.event.ProcessEvent;
|
|
|
|
|
@ -50,6 +53,8 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
|
|
|
|
|
private final ErpContractMaterialMapper contractMaterialMapper;
|
|
|
|
|
|
|
|
|
|
private final IBaseRelationMaterialService baseRelationMaterialService;
|
|
|
|
|
|
|
|
|
|
@DubboReference(timeout = 30000)
|
|
|
|
|
private RemoteWorkflowService remoteWorkflowService;
|
|
|
|
|
|
|
|
|
|
@ -65,7 +70,7 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
MPJLambdaWrapper<ErpContractMaterial> lqw = JoinWrappers.lambda(ErpContractMaterial.class)
|
|
|
|
|
.selectAll(ErpContractMaterial.class)
|
|
|
|
|
.eq(contractId != null, ErpContractMaterial::getContractId, contractId)
|
|
|
|
|
.eq("t.del_flag", "0");;
|
|
|
|
|
.eq("t.del_flag", "0");
|
|
|
|
|
List<ErpContractMaterialVo> contractMaterialList = contractMaterialMapper.selectCustomErpContractMaterialVoList(lqw);
|
|
|
|
|
contractInfoVo.setContractMaterialList(contractMaterialList);
|
|
|
|
|
return contractInfoVo;
|
|
|
|
|
@ -142,8 +147,12 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
|
|
if (flag && contractMaterialList != null && !contractMaterialList.isEmpty()) {
|
|
|
|
|
bo.setContractId(add.getContractId());
|
|
|
|
|
// 获取合同客户ID(优先使用甲方,如果为空则使用乙方)
|
|
|
|
|
Long customerId = add.getOneCustomerId();
|
|
|
|
|
for (ErpContractMaterial erpContractMaterial : contractMaterialList) {
|
|
|
|
|
erpContractMaterial.setContractId(add.getContractId());
|
|
|
|
|
// 处理关联物料信息
|
|
|
|
|
processRelationMaterial(erpContractMaterial, customerId);
|
|
|
|
|
contractMaterialMapper.insert(erpContractMaterial);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -166,7 +175,11 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
lqwRecord.eq(ErpContractMaterial::getContractId, bo.getContractId());
|
|
|
|
|
List<ErpContractMaterial> contractMaterialOldList = contractMaterialMapper.selectList(lqwRecord);
|
|
|
|
|
if (contractMaterialList != null && !contractMaterialList.isEmpty()) {
|
|
|
|
|
// 获取合同客户ID(优先使用甲方,如果为空则使用乙方)
|
|
|
|
|
Long customerId = update.getOneCustomerId();
|
|
|
|
|
for (ErpContractMaterial contractMaterial : contractMaterialList) {
|
|
|
|
|
// 处理关联物料信息
|
|
|
|
|
processRelationMaterial(contractMaterial, customerId);
|
|
|
|
|
contractMaterialMapper.insertOrUpdate(contractMaterial);
|
|
|
|
|
}
|
|
|
|
|
Set<Long> existingContractMaterialIds = contractMaterialList.stream()
|
|
|
|
|
@ -178,10 +191,47 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
for (ErpContractMaterial filterContractMaterialId : filterContractMaterialIds) {
|
|
|
|
|
contractMaterialMapper.deleteById(filterContractMaterialId.getContractMaterialId());
|
|
|
|
|
}
|
|
|
|
|
} else if (contractMaterialList != null && contractMaterialList.isEmpty()) {
|
|
|
|
|
for (ErpContractMaterial contractMaterial : contractMaterialOldList) {
|
|
|
|
|
contractMaterialMapper.deleteById(contractMaterial.getContractMaterialId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存前的数据校验
|
|
|
|
|
*/
|
|
|
|
|
|