|
|
@@ -122,7 +122,7 @@ public class KwcContractTradeService {
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private GoodsInfoService goodsInfoService;
|
|
|
|
|
|
- @DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
+ @DubboReference(version = "1.0.0", group = "design", check = false,timeout = 8000)
|
|
|
private TradeOrderInfoService tradeOrderInfoService;
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 8000)
|
|
|
private TransportRemoteService transportRemoteService;
|
|
|
@@ -197,7 +197,12 @@ public class KwcContractTradeService {
|
|
|
|
|
|
List<QueryListResVo> queryListResVoPageDataResult = queryTradeListByPage(queryTradeReq);
|
|
|
|
|
|
- return PageHelperUtil.getPageResult(new PageInfo<>(queryListResVoPageDataResult), queryListResVoPageDataResult, reqVo.getPageSize());
|
|
|
+ long total = countQueryTradeListByPage(queryTradeReq);
|
|
|
+ PageInfo<QueryListResVo> pageInfo = new PageInfo<>(queryListResVoPageDataResult);
|
|
|
+ pageInfo.setTotal(total);
|
|
|
+ pageInfo.setPageNum(reqVo.getPageNum());
|
|
|
+ pageInfo.setPageSize(reqVo.getPageSize());
|
|
|
+ return PageHelperUtil.getPageResult(pageInfo);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1762,6 +1767,118 @@ public class KwcContractTradeService {
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ private long countQueryTradeListByPage(QueryTradeReq req) {
|
|
|
+ Long entId;
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getEntId())) {
|
|
|
+ entId = Long.valueOf(req.getEntId());
|
|
|
+ } else {
|
|
|
+ entId = LoginUserHolder.getEntId();
|
|
|
+ }
|
|
|
+ Set<Long> entIds = Sets.newHashSet();
|
|
|
+ entIds.add(entId);
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getPurchaseEntId())) {
|
|
|
+ entIds.add(Long.valueOf(req.getPurchaseEntId()));
|
|
|
+ }
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getSupplyEntId())) {
|
|
|
+ entIds.add(Long.valueOf(req.getSupplyEntId()));
|
|
|
+ }
|
|
|
+ Set<Long> contractIds = null;
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(entIds)) {
|
|
|
+ List<KwcContractTradeUnit> units = kwcContractTradeUnitRepository.queryByEntIds(entIds);
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(units)) {
|
|
|
+ Set<Long> contractIdList = units.stream().filter(x -> Objects.equals(x.getEntId(), entId))
|
|
|
+ .map(KwcContractTradeUnit::getContractId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ contractIds = units.stream()
|
|
|
+ .map(KwcContractTradeUnit::getContractId)
|
|
|
+ .filter(contractIdList::contains)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(contractIds)) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ // 不分页,获取完整数据用于计算总数
|
|
|
+ List<KwcContractTrade> records = kwcContractTradeRepository.queryTradeListByPageList(
|
|
|
+ req.getContractCode(),
|
|
|
+ req.getContractName(),
|
|
|
+ req.getSupplementCode(),
|
|
|
+ contractIds, req.getStatus(), req.getDispatchWay(), 0, 0);
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(records)) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ entIds.addAll(records.stream().map(KwcContractTrade::getEntId).collect(Collectors.toSet()));
|
|
|
+ List<EntTypeResDto> ents = remoteSystemService.queryEntTypeByIds(entIds);
|
|
|
+ Map<Long, EntTypeResDto> entIdAndEntMap = Maps.newHashMap();
|
|
|
+ if (CollectionUtils.isNotEmpty(ents)) {
|
|
|
+ entIdAndEntMap =
|
|
|
+ ents.stream().collect(Collectors.toMap(EntTypeResDto::getEntId, Function.identity(), (v1, v2) -> v1));
|
|
|
+ }
|
|
|
+ EntTypeResDto entTypeResDto = entIdAndEntMap.getOrDefault(entId, new EntTypeResDto());
|
|
|
+ List<KwcContractTrade> contractTrades = Lists.newArrayList();
|
|
|
+ List<KwcContractTrade> contractTrades1 = Lists.newArrayList();
|
|
|
+ if (entTypeResDto.getType().equals(EntTypeEnum.PURCHASER.getCode())) {
|
|
|
+ List<Integer> statusList = Arrays.asList(ContractStatusEnum.SIGNED.getCode(), ContractStatusEnum.COMPLETE.getCode());
|
|
|
+ Map<Long, EntTypeResDto> finalEntIdAndEntMap1 = entIdAndEntMap;
|
|
|
+
|
|
|
+ records.forEach(record -> {
|
|
|
+ EntTypeResDto orDefault = finalEntIdAndEntMap1.getOrDefault(record.getEntId(), new EntTypeResDto());
|
|
|
+ if (Objects.equals(orDefault.getType(), EntTypeEnum.SUPPLIER.getCode()) && statusList.contains(record.getStatus())) {
|
|
|
+ contractTrades.add(record);
|
|
|
+ } else if (Objects.equals(orDefault.getType(), EntTypeEnum.PURCHASER.getCode())) {
|
|
|
+ contractTrades1.add(record);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (entTypeResDto.getType().equals(EntTypeEnum.SUPPLIER.getCode())) {
|
|
|
+ Map<Long, EntTypeResDto> finalEntIdAndEntMap = entIdAndEntMap;
|
|
|
+ records.forEach(record -> {
|
|
|
+ EntTypeResDto orDefault = finalEntIdAndEntMap.getOrDefault(record.getEntId(), new EntTypeResDto());
|
|
|
+ if (Objects.equals(orDefault.getType(), EntTypeEnum.PURCHASER.getCode()) && !Objects.equals(record.getStatus(), ContractStatusEnum.CANNEL.getCode())) {
|
|
|
+ contractTrades.add(record);
|
|
|
+ } else if (Objects.equals(orDefault.getType(), EntTypeEnum.SUPPLIER.getCode())) {
|
|
|
+ contractTrades1.add(record);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ contractTrades.addAll(contractTrades1);
|
|
|
+ records = contractTrades;
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(records)) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getPurchaseEntId())
|
|
|
+ || org.apache.commons.lang3.StringUtils.isNotBlank(req.getSupplyEntId())) {
|
|
|
+ Set<Long> tradeContractIds = records.stream().map(KwcContractTrade::getId).collect(Collectors.toSet());
|
|
|
+ List<KwcContractTradeUnit> tradeUnits = kwcContractTradeUnitRepository.queryByContractIds(tradeContractIds);
|
|
|
+ Map<String, KwcContractTradeUnit> contractUnitTypeKeyAndUnitMap = Maps.newHashMap();
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(tradeUnits)) {
|
|
|
+ contractUnitTypeKeyAndUnitMap = tradeUnits.stream()
|
|
|
+ .peek(x -> x.setContractIdUniTypeKey(x.getContractId() + "-" + x.getUnitType()))
|
|
|
+ .collect(Collectors.toMap(KwcContractTradeUnit::getContractIdUniTypeKey, Function.identity(), (v1
|
|
|
+ , v2) -> v1));
|
|
|
+ }
|
|
|
+ Map<String, KwcContractTradeUnit> finalContractUnitTypeKeyAndUnitMap = contractUnitTypeKeyAndUnitMap;
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getPurchaseEntId())) {
|
|
|
+ records = records.stream().filter(record -> {
|
|
|
+ KwcContractTradeUnit purchaseEnt =
|
|
|
+ finalContractUnitTypeKeyAndUnitMap.getOrDefault(record.getId() + "-" + CooperateTypeEnum.PURCHASER.getCode(),
|
|
|
+ new KwcContractTradeUnit());
|
|
|
+ return org.apache.commons.lang3.StringUtils.equals(String.valueOf(purchaseEnt.getEntId()), req.getPurchaseEntId());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getSupplyEntId())) {
|
|
|
+ records = records.stream().filter(record -> {
|
|
|
+ KwcContractTradeUnit provideEnt =
|
|
|
+ finalContractUnitTypeKeyAndUnitMap.getOrDefault(record.getId() + "-" + CooperateTypeEnum.SUPPLIER.getCode(),
|
|
|
+ new KwcContractTradeUnit());
|
|
|
+ return org.apache.commons.lang3.StringUtils.equals(String.valueOf(provideEnt.getEntId()), req.getSupplyEntId());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return records.size();
|
|
|
+ }
|
|
|
+
|
|
|
@NotNull
|
|
|
private static QueryListResVo getQueryListResVo(KwcContractTrade t,
|
|
|
Map<String, KwcContractTradeUnit> finalContractUnitTypeKeyAndUnitMap,
|