|
|
|
|
@ -20,8 +20,11 @@ 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.ErpContractPaymentMethod;
|
|
|
|
|
import org.dromara.oa.erp.domain.vo.ErpContractMaterialVo;
|
|
|
|
|
import org.dromara.oa.erp.domain.vo.ErpContractPaymentMethodVo;
|
|
|
|
|
import org.dromara.oa.erp.mapper.ErpContractMaterialMapper;
|
|
|
|
|
import org.dromara.oa.erp.mapper.ErpContractPaymentMethodMapper;
|
|
|
|
|
import org.dromara.oa.base.domain.bo.BaseRelationMaterialBo;
|
|
|
|
|
import org.dromara.oa.base.service.IBaseRelationMaterialService;
|
|
|
|
|
import org.dromara.workflow.api.RemoteWorkflowService;
|
|
|
|
|
@ -54,6 +57,8 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
|
|
|
|
|
private final ErpContractMaterialMapper contractMaterialMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpContractPaymentMethodMapper contractPaymentMethodMapper;
|
|
|
|
|
|
|
|
|
|
private final IBaseRelationMaterialService baseRelationMaterialService;
|
|
|
|
|
|
|
|
|
|
@DubboReference(timeout = 30000)
|
|
|
|
|
@ -75,6 +80,13 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
List<ErpContractMaterialVo> contractMaterialList = contractMaterialMapper
|
|
|
|
|
.selectCustomErpContractMaterialVoList(lqw);
|
|
|
|
|
contractInfoVo.setContractMaterialList(contractMaterialList);
|
|
|
|
|
// 查询合同付款方式列表
|
|
|
|
|
MPJLambdaWrapper<ErpContractPaymentMethod> paymentLqw = JoinWrappers.lambda(ErpContractPaymentMethod.class)
|
|
|
|
|
.selectAll(ErpContractPaymentMethod.class)
|
|
|
|
|
.eq(contractId != null, ErpContractPaymentMethod::getContractId, contractId)
|
|
|
|
|
.eq(ErpContractPaymentMethod::getDelFlag, "0");
|
|
|
|
|
List<ErpContractPaymentMethodVo> contractPaymentMethodList = contractPaymentMethodMapper.selectCustomErpContractPaymentMethodVoList(paymentLqw);
|
|
|
|
|
contractInfoVo.setContractPaymentMethodList(contractPaymentMethodList);
|
|
|
|
|
return contractInfoVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -169,6 +181,14 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
contractMaterialMapper.insert(erpContractMaterial);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 保存合同付款方式
|
|
|
|
|
List<ErpContractPaymentMethod> contractPaymentMethodList = bo.getContractPaymentMethodList();
|
|
|
|
|
if (flag && contractPaymentMethodList != null && !contractPaymentMethodList.isEmpty()) {
|
|
|
|
|
for (ErpContractPaymentMethod pm : contractPaymentMethodList) {
|
|
|
|
|
pm.setContractId(add.getContractId());
|
|
|
|
|
contractPaymentMethodMapper.insert(pm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MapstructUtils.convert(add, ErpContractInfoVo.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -183,15 +203,24 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
public Boolean updateByBo(ErpContractInfoBo bo) {
|
|
|
|
|
ErpContractInfo update = MapstructUtils.convert(bo, ErpContractInfo.class);
|
|
|
|
|
validEntityBeforeSave(update);
|
|
|
|
|
updateContractMaterialList(bo);
|
|
|
|
|
updateContractPaymentMethodList(bo);
|
|
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新合同物料列表
|
|
|
|
|
*
|
|
|
|
|
* @param bo 合同信息
|
|
|
|
|
*/
|
|
|
|
|
private void updateContractMaterialList(ErpContractInfoBo bo) {
|
|
|
|
|
List<ErpContractMaterial> contractMaterialList = bo.getContractMaterialList();
|
|
|
|
|
MPJLambdaWrapper<ErpContractMaterial> lqwRecord = JoinWrappers.lambda(ErpContractMaterial.class);
|
|
|
|
|
lqwRecord.eq(ErpContractMaterial::getContractId, bo.getContractId());
|
|
|
|
|
List<ErpContractMaterial> contractMaterialOldList = contractMaterialMapper.selectList(lqwRecord);
|
|
|
|
|
if (contractMaterialList != null && !contractMaterialList.isEmpty()) {
|
|
|
|
|
// 获取合同客户ID(优先使用甲方,如果为空则使用乙方)
|
|
|
|
|
Long customerId = update.getOneCustomerId();
|
|
|
|
|
Long customerId = bo.getOneCustomerId();
|
|
|
|
|
for (ErpContractMaterial contractMaterial : contractMaterialList) {
|
|
|
|
|
// 处理关联物料信息
|
|
|
|
|
processRelationMaterial(contractMaterial, customerId);
|
|
|
|
|
contractMaterialMapper.insertOrUpdate(contractMaterial);
|
|
|
|
|
}
|
|
|
|
|
@ -204,12 +233,49 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
|
|
|
|
|
for (ErpContractMaterial filterContractMaterialId : filterContractMaterialIds) {
|
|
|
|
|
contractMaterialMapper.deleteById(filterContractMaterialId.getContractMaterialId());
|
|
|
|
|
}
|
|
|
|
|
} else if (contractMaterialList != null && contractMaterialList.isEmpty()) {
|
|
|
|
|
} else if (contractMaterialList != null && !contractMaterialOldList.isEmpty()) {
|
|
|
|
|
for (ErpContractMaterial contractMaterial : contractMaterialOldList) {
|
|
|
|
|
contractMaterialMapper.deleteById(contractMaterial.getContractMaterialId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新合同付款方式列表(增量:有则插入/更新,无则删除)
|
|
|
|
|
*
|
|
|
|
|
* @param bo 合同信息
|
|
|
|
|
*/
|
|
|
|
|
private void updateContractPaymentMethodList(ErpContractInfoBo bo) {
|
|
|
|
|
List<ErpContractPaymentMethod> contractPaymentMethodList = bo.getContractPaymentMethodList();
|
|
|
|
|
MPJLambdaWrapper<ErpContractPaymentMethod> paymentLqw = JoinWrappers.lambda(ErpContractPaymentMethod.class)
|
|
|
|
|
.selectAll(ErpContractPaymentMethod.class)
|
|
|
|
|
.eq(bo.getContractId() != null, ErpContractPaymentMethod::getContractId, bo.getContractId())
|
|
|
|
|
.eq(ErpContractPaymentMethod::getDelFlag, "0");
|
|
|
|
|
List<ErpContractPaymentMethodVo> oldPaymentList = contractPaymentMethodMapper.selectCustomErpContractPaymentMethodVoList(paymentLqw);
|
|
|
|
|
if (contractPaymentMethodList != null && !contractPaymentMethodList.isEmpty()) {
|
|
|
|
|
Set<Long> newPaymentMethodIds = new HashSet<>();
|
|
|
|
|
for (ErpContractPaymentMethod pm : contractPaymentMethodList) {
|
|
|
|
|
pm.setContractId(bo.getContractId());
|
|
|
|
|
if (pm.getPaymentMethodId() == null) {
|
|
|
|
|
contractPaymentMethodMapper.insert(pm);
|
|
|
|
|
} else {
|
|
|
|
|
contractPaymentMethodMapper.updateById(pm);
|
|
|
|
|
newPaymentMethodIds.add(pm.getPaymentMethodId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<Long> toDelete = oldPaymentList.stream()
|
|
|
|
|
.map(ErpContractPaymentMethodVo::getPaymentMethodId)
|
|
|
|
|
.filter(id -> !newPaymentMethodIds.contains(id))
|
|
|
|
|
.toList();
|
|
|
|
|
if (!toDelete.isEmpty()) {
|
|
|
|
|
contractPaymentMethodMapper.deleteByIds(toDelete);
|
|
|
|
|
}
|
|
|
|
|
} else if (contractPaymentMethodList != null && !oldPaymentList.isEmpty()) {
|
|
|
|
|
List<Long> toDelete = oldPaymentList.stream()
|
|
|
|
|
.map(ErpContractPaymentMethodVo::getPaymentMethodId)
|
|
|
|
|
.toList();
|
|
|
|
|
contractPaymentMethodMapper.deleteByIds(toDelete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|