国贸2.0系统合同分页查询:查询逻辑修改

This commit is contained in:
guojunyun
2025-11-03 15:45:23 +08:00
parent 57022e04c0
commit 25053c316e

View File

@@ -44,10 +44,9 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays; import java.util.stream.Collectors;
import java.util.Iterator; import java.util.stream.Stream;
import java.util.List;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.pojo.CommonResult.success; import static com.zt.plat.framework.common.pojo.CommonResult.success;
@@ -393,55 +392,49 @@ public class ContractApiImpl implements ContractApi {
// 合同ID // 合同ID
Long mainDOId = contractMainDO.getId(); Long mainDOId = contractMainDO.getId();
// 合同主信息 // 合同动态条款查询
List<ContractOtherFieldDO> mainFields = contractOtherFieldMapper.selectList( List<ContractOtherFormDO> otherFormDOs = contractOtherFormMapper.selectList(
new LambdaQueryWrapperX<ContractOtherFieldDO>()
.eq(ContractOtherFieldDO::getContractMainId, mainDOId)
.isNull(ContractOtherFieldDO::getRelativityId)
);
JSONObject resultJson = new JSONObject();
mainFields.forEach(field
-> resultJson.putOnce(field.getFieldNumber(), field.getFieldValue()));
// 附件清单列表
List<ContractOtherFormDO> attachForms = contractOtherFormMapper.selectList(
new LambdaQueryWrapperX<ContractOtherFormDO>() new LambdaQueryWrapperX<ContractOtherFormDO>()
.eq(ContractOtherFormDO::getContractMainId, mainDOId) .eq(ContractOtherFormDO::getContractMainId, mainDOId)
.eq(ContractOtherFormDO::getFormNumber, "attachList")
); );
if (attachForms != null && !attachForms.isEmpty()) { // 合同动态条款明细查询
JSONArray jsonArray = new JSONArray(); List<ContractOtherFieldDO> otherFieldDOs = contractOtherFieldMapper.selectList(
attachForms.forEach(form -> {
ContractOtherFieldDO fieldDO = contractOtherFieldMapper.selectOne(
new LambdaQueryWrapperX<ContractOtherFieldDO>() new LambdaQueryWrapperX<ContractOtherFieldDO>()
.eq(ContractOtherFieldDO::getContractMainId, mainDOId) .eq(ContractOtherFieldDO::getContractMainId, mainDOId)
.eq(ContractOtherFieldDO::getRelativityId, form.getId())
); );
if (fieldDO != null) {
jsonArray.add(fieldDO.getFieldValue()); JSONObject resultJson = new JSONObject();
// 设置主信息
otherFieldDOs.stream()
.filter(otherFieldDO -> otherFieldDO.getRelativityId() == null)
.forEach(otherFieldDO
-> resultJson.putOnce(otherFieldDO.getFieldNumber(), otherFieldDO.getFieldValue()));
// 设置明细信息
otherFormDOs.stream()
.collect(Collectors.groupingBy(ContractOtherFormDO::getFormNumber))
.forEach((key, value) -> {
JSONArray detailsJson = new JSONArray();
value.forEach(detail -> {
// 根据条款id筛选条款明细
Stream<ContractOtherFieldDO> stream = otherFieldDOs.stream()
.filter(otherFieldDO
-> Objects.equals(otherFieldDO.getRelativityId(), detail.getId()));
if ("attachList".equals(key)) {
// 基础数据类型
stream.forEach(otherFieldDO
-> detailsJson.add(otherFieldDO.getFieldValue()));
} else {
// 对象数据类型
JSONObject detailJson = new JSONObject();
stream.forEach(otherFieldDO
-> detailJson.putOnce(otherFieldDO.getFieldNumber(), otherFieldDO.getFieldValue()));
detailsJson.add(detailJson);
} }
}); });
if (!jsonArray.isEmpty()) { resultJson.putOnce(key, detailsJson);
resultJson.putOnce("attachList", jsonArray); });
}
}
// 客商信息
resultJson.putOnce("partnerList", getQueryFieldJsonArray(mainDOId, "partnerList"));
// 收发港/站点
resultJson.putOnce("goodsSiteList", getQueryFieldJsonArray(mainDOId, "goodsSiteList"));
// 货物装卸要求
resultJson.putOnce("loadingRequirementsList", getQueryFieldJsonArray(mainDOId, "loadingRequirementsList"));
// 收付款账号
resultJson.putOnce("accountList", getQueryFieldJsonArray(mainDOId, "accountList"));
// 费用明细
resultJson.putOnce("freightList", getQueryFieldJsonArray(mainDOId, "freightList"));
// 服务费用项目
resultJson.putOnce("serviceFeeList", getQueryFieldJsonArray(mainDOId, "serviceFeeList"));
// 仓库明细
resultJson.putOnce("storgeList", getQueryFieldJsonArray(mainDOId, "storgeList"));
// 接货地址
resultJson.putOnce("receivingAddrList", getQueryFieldJsonArray(mainDOId, "receivingAddrList"));
// 添加到结果集 // 添加到结果集
resultList.add(resultJson.toBean(IntContract.class)); resultList.add(resultJson.toBean(IntContract.class));
@@ -451,33 +444,6 @@ public class ContractApiImpl implements ContractApi {
return success(result); return success(result);
} }
private JSONArray getQueryFieldJsonArray(Long mainDOId, String fieldName) {
JSONArray jsonArray = new JSONArray();
List<ContractOtherFormDO> forms = contractOtherFormMapper.selectList(
new LambdaQueryWrapperX<ContractOtherFormDO>()
.eq(ContractOtherFormDO::getContractMainId, mainDOId)
.eq(ContractOtherFormDO::getFormNumber, fieldName)
);
if (forms != null && !forms.isEmpty()) {
forms.forEach(form -> {
List<ContractOtherFieldDO> fieldDOs = contractOtherFieldMapper.selectList(
new LambdaQueryWrapperX<ContractOtherFieldDO>()
.eq(ContractOtherFieldDO::getContractMainId, mainDOId)
.eq(ContractOtherFieldDO::getRelativityId, form.getId())
);
if (fieldDOs != null && !fieldDOs.isEmpty()) {
JSONObject jsonObject = new JSONObject();
fieldDOs.forEach(field
-> jsonObject.putOnce(field.getFieldNumber(), field.getFieldValue()));
jsonArray.add(jsonObject);
}
});
}
return jsonArray.isEmpty() ? null : jsonArray;
}
@Override @Override
public CommonResult<List<PurchaseOrderWithDetailsDTO>> getOrderByOrderIds(List<Long> ids) { public CommonResult<List<PurchaseOrderWithDetailsDTO>> getOrderByOrderIds(List<Long> ids) {
if (ids == null || ids.isEmpty()) { if (ids == null || ids.isEmpty()) {