|
|
@@ -122,40 +122,56 @@ 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;
|
|
|
|
|
|
- /**销售合同*/
|
|
|
+ /**
|
|
|
+ * 销售合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.saleSendContract}")
|
|
|
private String saleSendContract;
|
|
|
|
|
|
- /**采购合同*/
|
|
|
+ /**
|
|
|
+ * 采购合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.purchaseSendContract}")
|
|
|
private String purchaseSendContract;
|
|
|
|
|
|
- /**托运合同*/
|
|
|
+ /**
|
|
|
+ * 托运合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.consignmentSendContract}")
|
|
|
private String consignmentSendContract;
|
|
|
|
|
|
- /**承运合同*/
|
|
|
+ /**
|
|
|
+ * 承运合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.acceptanceSendContract}")
|
|
|
private String acceptanceSendContract;
|
|
|
|
|
|
- /**app销售合同*/
|
|
|
+ /**
|
|
|
+ * app销售合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.appSaleSendContract}")
|
|
|
private String appSaleSendContract;
|
|
|
|
|
|
- /**app采购合同*/
|
|
|
+ /**
|
|
|
+ * app采购合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.appPurchaseSendContract}")
|
|
|
private String appPurchaseSendContract;
|
|
|
|
|
|
- /**app托运合同*/
|
|
|
+ /**
|
|
|
+ * app托运合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.appConsignmentSendContract}")
|
|
|
private String appConsignmentSendContract;
|
|
|
|
|
|
- /**app承运合同*/
|
|
|
+ /**
|
|
|
+ * app承运合同
|
|
|
+ */
|
|
|
@Value(value = "${jumpUrl.appAcceptanceSendContract}")
|
|
|
private String appAcceptanceSendContract;
|
|
|
|
|
|
@@ -181,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);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -192,8 +213,8 @@ public class KwcContractTradeService {
|
|
|
* @author: czh
|
|
|
* @date: 2023/7/18
|
|
|
*/
|
|
|
- private List<QueryListResVo> getQueryListResVos(List<QueryListResDto> queryListResDtos,Map<Long,
|
|
|
- List<KwcContractTradeGoods>> contractIdGoodsIdKeyAndGoodsMap,Map<String, KwcContractTradeUnit> contractUnitTypeKeyAndUnitMap ) {
|
|
|
+ private List<QueryListResVo> getQueryListResVos(List<QueryListResDto> queryListResDtos, Map<Long,
|
|
|
+ List<KwcContractTradeGoods>> contractIdGoodsIdKeyAndGoodsMap, Map<String, KwcContractTradeUnit> contractUnitTypeKeyAndUnitMap) {
|
|
|
Map<Long, UserCacheResDto> longUserCacheResDtoMap = new HashMap<>(8);
|
|
|
List<Long> initiateByList = queryListResDtos.stream().map(QueryListResDto::getInitiateBy).toList();
|
|
|
if (CollectionUtils.isNotEmpty(initiateByList)) {
|
|
|
@@ -210,9 +231,9 @@ public class KwcContractTradeService {
|
|
|
queryListResVo.setProvideEntName(queryListResDto.getUnitType().compareTo(EntTypeEnum.SUPPLIER.getCode()) == 0 ? queryListResDto.getEntName() : queryListResDto.getTargetEntName());
|
|
|
queryListResVo.setPurchaseEntName(queryListResDto.getUnitType().compareTo(EntTypeEnum.SUPPLIER.getCode()) == 0 ? queryListResDto.getTargetEntName() : queryListResDto.getEntName());
|
|
|
}
|
|
|
- if(Objects.equals(queryListResDto.getUnitType(),EntTypeEnum.SUPPLIER.getCode())){
|
|
|
+ if (Objects.equals(queryListResDto.getUnitType(), EntTypeEnum.SUPPLIER.getCode())) {
|
|
|
queryListResVo.setProvideEntId(String.valueOf(queryListResDto.getProvideEntId()));
|
|
|
- }else if(Objects.equals(queryListResDto.getUnitType(),EntTypeEnum.PURCHASER.getCode())){
|
|
|
+ } else if (Objects.equals(queryListResDto.getUnitType(), EntTypeEnum.PURCHASER.getCode())) {
|
|
|
queryListResVo.setPurchaseEntId(String.valueOf(queryListResDto.getPurchaseEntId()));
|
|
|
}
|
|
|
|
|
|
@@ -221,7 +242,7 @@ public class KwcContractTradeService {
|
|
|
queryListResVo.setInitiateName(userCacheResDto.getName());
|
|
|
queryListResVo.setInitiateEntName(Objects.isNull(userCacheResDto.getEntInfo()) ? "" : userCacheResDto.getEntInfo().getFirmName());
|
|
|
}
|
|
|
- if (MapUtils.isNotEmpty(contractUnitTypeKeyAndUnitMap)){
|
|
|
+ if (MapUtils.isNotEmpty(contractUnitTypeKeyAndUnitMap)) {
|
|
|
KwcContractTradeUnit kwcContractTradeUnit =
|
|
|
contractUnitTypeKeyAndUnitMap.getOrDefault(queryListResDto.getId() + "-" + EntTypeEnum.SUPPLIER.getCode()
|
|
|
, new KwcContractTradeUnit());
|
|
|
@@ -244,9 +265,9 @@ public class KwcContractTradeService {
|
|
|
queryListResVo.setAmount(queryListResDto.getAmount());
|
|
|
queryListResVo.setPerformedAmount(queryListResDto.getPerformedAmount());
|
|
|
BigDecimal performedAmountMoney = BigDecimal.ZERO;
|
|
|
- if(MapUtils.isNotEmpty(contractIdGoodsIdKeyAndGoodsMap)) {
|
|
|
+ if (MapUtils.isNotEmpty(contractIdGoodsIdKeyAndGoodsMap)) {
|
|
|
List<KwcContractTradeGoods> contractTradeGoods = contractIdGoodsIdKeyAndGoodsMap.get(queryListResDto.getId());
|
|
|
- if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(contractTradeGoods)){
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(contractTradeGoods)) {
|
|
|
for (KwcContractTradeGoods goods : contractTradeGoods) {
|
|
|
BigDecimal performedAmount = goods.getPerformedAmount() != null ? goods.getPerformedAmount() : BigDecimal.ZERO;
|
|
|
BigDecimal price = goods.getPrice() != null ? goods.getPrice() : BigDecimal.ZERO;
|
|
|
@@ -254,11 +275,11 @@ public class KwcContractTradeService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- queryListResVo.setPerformedAmountMoney( performedAmountMoney);
|
|
|
- if(Objects.nonNull(queryListResVo.getEndTime())) {
|
|
|
+ queryListResVo.setPerformedAmountMoney(performedAmountMoney);
|
|
|
+ if (Objects.nonNull(queryListResVo.getEndTime())) {
|
|
|
queryListResVo.setEndTime(DateUtils.getStartOfDay(queryListResVo.getEndTime()));
|
|
|
String endDate = DateUtils.format(queryListResVo.getEndTime(), DateUtils.DATE_PATTERN);
|
|
|
- if (org.apache.commons.lang3.StringUtils.equals(endDate,"9999-12-30")){
|
|
|
+ if (org.apache.commons.lang3.StringUtils.equals(endDate, "9999-12-30")) {
|
|
|
queryListResVo.setEndTime(null);
|
|
|
}
|
|
|
}
|
|
|
@@ -287,9 +308,9 @@ public class KwcContractTradeService {
|
|
|
kwcContractTrade.setId(contactId);
|
|
|
EntCacheResDto entCacheResDto = remoteSystemService.queryEntTreeById(LoginUserHolder.getEntId());
|
|
|
if (Objects.nonNull(entCacheResDto) && StringUtils.isNotBlank(entCacheResDto.getEntTypes())) {
|
|
|
- if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.SUPPLIER.getCode()))){
|
|
|
+ if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.SUPPLIER.getCode()))) {
|
|
|
kwcContractTrade.setStatus(ContractStatusEnum.WAIT_APPROVE.getCode());
|
|
|
- }else if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.PURCHASER.getCode()))){
|
|
|
+ } else if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.PURCHASER.getCode()))) {
|
|
|
kwcContractTrade.setStatus(ContractStatusEnum.SUBMIT.getCode());
|
|
|
}
|
|
|
}
|
|
|
@@ -300,7 +321,7 @@ public class KwcContractTradeService {
|
|
|
}
|
|
|
|
|
|
//保存交易合同商品信息
|
|
|
- kwcContractTradeGoodsService.saveContractTradeGoods(contactId, goodsInfoList,baseInfo.getStartTime(),baseInfo.getEndTime());
|
|
|
+ kwcContractTradeGoodsService.saveContractTradeGoods(contactId, goodsInfoList, baseInfo.getStartTime(), baseInfo.getEndTime());
|
|
|
|
|
|
//存单位信息
|
|
|
kwcContractTradeUnitService.saveContractTradeUnit(contactId, baseInfo);
|
|
|
@@ -330,6 +351,10 @@ public class KwcContractTradeService {
|
|
|
if (StringUtils.isNotBlank(baseInfo.getContractName()) && baseInfo.getContractName().length() > 20) {
|
|
|
throw new SystemException("合同名称超长!");
|
|
|
}
|
|
|
+ //按卸货筽量时必选计量方式
|
|
|
+ if (Objects.equals(baseInfo.getUnloadWay(), Integer.parseInt(DictEnum.LOAD_UNLOAD_WAY_2.getValue())) && Objects.isNull(baseInfo.getMeasurementWay())) {
|
|
|
+ throw new SystemException("卸货方式为按卸货筽量时,计量方式不能为空!");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(goodsInfo)) {
|
|
|
@@ -363,31 +388,21 @@ public class KwcContractTradeService {
|
|
|
|
|
|
/**
|
|
|
* 校验供应单位必须在贸易合同生效期内,且有包含该商品的自动派车的物流合同
|
|
|
+ *
|
|
|
* @param baseInfo
|
|
|
* @param goodsInfo
|
|
|
*/
|
|
|
private void checkLogContractTime(TradeBaseInfoReqVo baseInfo, List<TradeGoodsInfoReqVo> goodsInfo) {
|
|
|
- if (true) {
|
|
|
- return;
|
|
|
- }
|
|
|
if (Objects.equals(DispatchWayEnums.AUTO_DISPATCH.getCode(), baseInfo.getDispatchWay())) {
|
|
|
//商品ids
|
|
|
List<Long> goodsIdList = goodsInfo.stream().map(TradeGoodsInfoReqVo::getGoodsId).collect(Collectors.toList());
|
|
|
- //查询满足条件的物理合同
|
|
|
+ //查询满足条件的物流合同
|
|
|
List<LogisticsEntDtoVO> logisticsList = queryAutoContractLogOrder(baseInfo.getProvideEntId(), goodsIdList);
|
|
|
- List<LogisticsEntDtoVO> filteredLogistics = logisticsList.stream()
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .filter(log -> log.getStartTime() != null && log.getEndTime() != null)
|
|
|
- .filter(log -> {
|
|
|
- boolean startTimeOk = log.getStartTime().after(baseInfo.getStartTime());
|
|
|
- boolean endTimeOk = baseInfo.getEndTime() == null || log.getEndTime().before(baseInfo.getEndTime());
|
|
|
- return startTimeOk && endTimeOk;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isEmpty(filteredLogistics)) {
|
|
|
+ if (CollectionUtils.isEmpty(logisticsList)) {
|
|
|
throw new SystemException("请供应商先签订包含贸易商品的自动派车物流合同。");
|
|
|
}
|
|
|
//结束时间最早的
|
|
|
- LogisticsEntDtoVO logEndTimeMin = filteredLogistics.stream()
|
|
|
+ LogisticsEntDtoVO logEndTimeMin = logisticsList.stream()
|
|
|
.filter(log -> log.getEndTime() != null)
|
|
|
.min(Comparator.comparing(LogisticsEntDtoVO::getEndTime))
|
|
|
.orElse(new LogisticsEntDtoVO());
|
|
|
@@ -429,7 +444,7 @@ public class KwcContractTradeService {
|
|
|
kwcContractTrade.setStartTime(baseInfo.getStartTime());
|
|
|
if (Objects.nonNull(baseInfo.getEndTime())) {
|
|
|
kwcContractTrade.setEndTime(DateUtils.getEndOfDay(baseInfo.getEndTime()));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
LocalDate localDate = LocalDate.of(9999, 12, 30);
|
|
|
Date date1 = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
kwcContractTrade.setEndTime(DateUtils.getEndOfDay(date1));
|
|
|
@@ -460,6 +475,7 @@ public class KwcContractTradeService {
|
|
|
}
|
|
|
}
|
|
|
kwcContractTrade.setAmount(amountTotal);
|
|
|
+ kwcContractTrade.setMeasurementWay(baseInfo.getMeasurementWay());
|
|
|
return kwcContractTrade;
|
|
|
}
|
|
|
|
|
|
@@ -724,12 +740,11 @@ public class KwcContractTradeService {
|
|
|
purchaseSendContract,
|
|
|
appPurchaseSendContract);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("合同签约流程已发起消息出错:", e);
|
|
|
+ log.error("合同签约流程已发起消息出错:", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* @param id 合同id
|
|
|
* @desc: 更新合同为发起
|
|
|
@@ -764,6 +779,9 @@ public class KwcContractTradeService {
|
|
|
EntTypeResDto entTypeResDto = remoteSystemService.queryEntTypeById(LoginUserHolder.getEntId());
|
|
|
|
|
|
TradeBaseInfoReqVo baseInfo = reqVo.getBaseInfo();
|
|
|
+ if (Objects.equals(baseInfo.getUnloadWay(), Integer.parseInt(DictEnum.LOAD_UNLOAD_WAY_2.getValue())) && Objects.isNull(baseInfo.getMeasurementWay())) {
|
|
|
+ throw new BusinessException("卸货方式为按卸货筽量时,计量方式不能为空!");
|
|
|
+ }
|
|
|
kwcContractTrade.setEntId(LoginUserHolder.getEntId());
|
|
|
kwcContractTrade.setContractNo(baseInfo.getContractCode());
|
|
|
kwcContractTrade.setName(baseInfo.getContractName());
|
|
|
@@ -793,15 +811,16 @@ public class KwcContractTradeService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (Objects.nonNull(entTypeResDto) && Objects.equals(entTypeResDto.getType(), EntTypeEnum.SUPPLIER.getCode())){
|
|
|
+ if (Objects.nonNull(entTypeResDto) && Objects.equals(entTypeResDto.getType(), EntTypeEnum.SUPPLIER.getCode())) {
|
|
|
kwcContractTrade.setStatus(ContractStatusEnum.WAIT_APPROVE.getCode());
|
|
|
- }else if (Objects.nonNull(entTypeResDto) && Objects.equals(entTypeResDto.getType(), EntTypeEnum.PURCHASER.getCode())){
|
|
|
+ } else if (Objects.nonNull(entTypeResDto) && Objects.equals(entTypeResDto.getType(), EntTypeEnum.PURCHASER.getCode())) {
|
|
|
kwcContractTrade.setStatus(ContractStatusEnum.SUBMIT.getCode());
|
|
|
}
|
|
|
kwcContractTrade.setAmount(amountTotal);
|
|
|
kwcContractTrade.setSigningUrl(reqVo.getContractFile());
|
|
|
kwcContractTrade.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
kwcContractTrade.setUpdateTime(date);
|
|
|
+ kwcContractTrade.setMeasurementWay(baseInfo.getMeasurementWay());
|
|
|
if (kwcContractTradeMapper.updateById(kwcContractTrade) <= 0) {
|
|
|
throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
}
|
|
|
@@ -979,7 +998,7 @@ public class KwcContractTradeService {
|
|
|
if (CollectionUtils.isEmpty(queryListResDtos)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- return getQueryListResVos(queryListResDtos,null,null);
|
|
|
+ return getQueryListResVos(queryListResDtos, null, null);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1075,7 +1094,7 @@ public class KwcContractTradeService {
|
|
|
authEntIdList.addAll(ids);
|
|
|
}
|
|
|
|
|
|
- List<QueryListResDto> queryListResDtos = kwcContractTradeMapper.queryTradeList(reqVo,authEntIdList);
|
|
|
+ List<QueryListResDto> queryListResDtos = kwcContractTradeMapper.queryTradeList(reqVo, authEntIdList);
|
|
|
if (CollectionUtils.isEmpty(queryListResDtos)) {
|
|
|
return PageHelperUtil.getPageResult(new PageInfo<>());
|
|
|
}
|
|
|
@@ -1339,9 +1358,9 @@ public class KwcContractTradeService {
|
|
|
|
|
|
EntCacheResDto entCacheResDto = remoteSystemService.queryEntTreeById(LoginUserHolder.getEntId());
|
|
|
if (Objects.nonNull(entCacheResDto) && StringUtils.isNotBlank(entCacheResDto.getEntTypes())) {
|
|
|
- if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.SUPPLIER.getCode()))){
|
|
|
+ if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.SUPPLIER.getCode()))) {
|
|
|
kwcContractTrade.setStatus(ContractStatusEnum.WAIT_APPROVE.getCode());
|
|
|
- }else if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.PURCHASER.getCode()))){
|
|
|
+ } else if (org.apache.commons.lang3.StringUtils.equals(entCacheResDto.getEntTypes(), String.valueOf(EntTypeEnum.PURCHASER.getCode()))) {
|
|
|
kwcContractTrade.setStatus(ContractStatusEnum.SUBMIT.getCode());
|
|
|
}
|
|
|
}
|
|
|
@@ -1573,6 +1592,8 @@ public class KwcContractTradeService {
|
|
|
String.valueOf(kwcContractTrade.getUnloadWay())));
|
|
|
tradeBaseInfo.setSalesmanId(kwcContractTrade.getSalesmanId());
|
|
|
tradeBaseInfo.setSalesmanPhone(kwcContractTrade.getSalesmanPhone());
|
|
|
+ tradeBaseInfo.setMeasurementWay(Objects.equals(kwcContractTrade.getMeasurementWay(), -1) ? null : kwcContractTrade.getMeasurementWay());
|
|
|
+ tradeBaseInfo.setMeasurementWayDesc(Objects.equals(kwcContractTrade.getMeasurementWay(), -1) ? "" : DictEnum.getLabel(String.valueOf(kwcContractTrade.getMeasurementWay())));
|
|
|
tradeBaseInfo.setDispatchWay(kwcContractTrade.getDispatchWay());
|
|
|
tradeBaseInfo.setDispatchWayDesc(Optional.ofNullable(kwcContractTrade.getDispatchWay()).map(DispatchWayEnums::getDesc).orElse(""));
|
|
|
return tradeBaseInfo;
|
|
|
@@ -1586,7 +1607,7 @@ public class KwcContractTradeService {
|
|
|
} else {
|
|
|
entId = LoginUserHolder.getEntId();
|
|
|
}
|
|
|
- // Integer type = null;
|
|
|
+ // Integer type = null;
|
|
|
Set<Long> entIds = Sets.newHashSet();
|
|
|
entIds.add(entId);
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getPurchaseEntId())) {
|
|
|
@@ -1740,7 +1761,122 @@ public class KwcContractTradeService {
|
|
|
.filter(x -> org.apache.commons.lang3.StringUtils.equals(x.getProvideEntId(), req.getSupplyEntId()))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
- return queryListResVos;
|
|
|
+ return queryListResVos.stream()
|
|
|
+ .sorted(Comparator.comparing(QueryListResVo::getUpdateTime).reversed()
|
|
|
+ .thenComparing(Comparator.comparing(QueryListResVo::getId).reversed()))
|
|
|
+ .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
|
|
|
@@ -1820,7 +1956,8 @@ public class KwcContractTradeService {
|
|
|
}
|
|
|
queryListResVo.setCreateTime(t.getCreateTime());
|
|
|
queryListResVo.setStartTime(t.getStartTime());
|
|
|
- if (Objects.nonNull(t.getStartTime())) {
|
|
|
+ queryListResVo.setUpdateTime(t.getUpdateTime());
|
|
|
+ if (Objects.nonNull(t.getEndTime())) {
|
|
|
queryListResVo.setEndTime(t.getEndTime());
|
|
|
String endDate = DateUtils.format(t.getEndTime(), DateUtils.DATE_PATTERN);
|
|
|
if (org.apache.commons.lang3.StringUtils.equals(endDate, "9999-12-30")) {
|
|
|
@@ -1875,7 +2012,7 @@ public class KwcContractTradeService {
|
|
|
Date date = new Date();
|
|
|
logistics = logistics.stream()
|
|
|
.peek(log -> {
|
|
|
- if (Objects.isNull(log.getEndTime())){
|
|
|
+ if (Objects.isNull(log.getEndTime())) {
|
|
|
LocalDate localDate = LocalDate.of(9999, 12, 30);
|
|
|
Date date1 = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
log.setEndTime(date1);
|
|
|
@@ -1940,21 +2077,21 @@ public class KwcContractTradeService {
|
|
|
//查询贸易合同企业信息
|
|
|
List<KwcContractTradeUnit> tradeUnits = kwcContractTradeUnitRepository.queryByEntIdAndUnitType(contractTradeOrderDto.getEntId(),
|
|
|
contractTradeOrderDto.getEntType());
|
|
|
- if (org.apache.commons.collections4.CollectionUtils.isEmpty(tradeUnits)){
|
|
|
- return List.of();
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(tradeUnits)) {
|
|
|
+ return List.of();
|
|
|
}
|
|
|
Set<Long> contractIds =
|
|
|
tradeUnits.stream().map(KwcContractTradeUnit::getContractId).collect(Collectors.toSet());
|
|
|
|
|
|
List<KwcContractTradeUnit> tradeUnits1 = kwcContractTradeUnitRepository.queryByContractIds(contractIds);
|
|
|
- if (org.apache.commons.collections4.CollectionUtils.isEmpty(tradeUnits1)){
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(tradeUnits1)) {
|
|
|
return List.of();
|
|
|
}
|
|
|
Map<String, KwcContractTradeUnit> conTractTradeUnitMap =
|
|
|
tradeUnits1.stream().collect(Collectors.toMap(x -> x.getContractId() +
|
|
|
"_" + x.getUnitType(), Function.identity(),
|
|
|
(x, y) -> x));
|
|
|
- contractIds= tradeUnits1.stream()
|
|
|
+ contractIds = tradeUnits1.stream()
|
|
|
.filter(x -> Objects.equals(x.getEntId(), LoginUserHolder.getEntId()) && Objects.equals(x.getUnitType(),
|
|
|
2))
|
|
|
.map(KwcContractTradeUnit::getContractId)
|
|
|
@@ -1966,7 +2103,7 @@ public class KwcContractTradeService {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
Map<Long, KwcContractTradeGoods> contractGoodsMap = kwcContractGoods.stream()
|
|
|
- .collect(Collectors.toMap(KwcContractTradeGoods::getContractId,Function.identity(),(x,y)->x));
|
|
|
+ .collect(Collectors.toMap(KwcContractTradeGoods::getContractId, Function.identity(), (x, y) -> x));
|
|
|
//只查询已签约的
|
|
|
Set<Long> contractIdList = kwcContractGoods.stream()
|
|
|
.filter(x -> Objects.equals(x.getStatus(), ContractStatusEnum.SIGNED.getCode()))
|
|
|
@@ -1978,15 +2115,15 @@ public class KwcContractTradeService {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
kwcContractTrades = kwcContractTrades.stream()
|
|
|
- .filter(x-> Objects.equals(x.getStatus(), ContractStatusEnum.SIGNED.getCode()))
|
|
|
+ .filter(x -> Objects.equals(x.getStatus(), ContractStatusEnum.SIGNED.getCode()))
|
|
|
.collect(Collectors.toList());
|
|
|
return kwcContractTrades.stream()
|
|
|
- .map(x-> getContractTradeOrderInfo(x, conTractTradeUnitMap,contractTradeOrderDto.getEntType(),contractGoodsMap))
|
|
|
+ .map(x -> getContractTradeOrderInfo(x, conTractTradeUnitMap, contractTradeOrderDto.getEntType(), contractGoodsMap))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
private static void checkParam(Long contractTradeOrderDto, Long contractTradeOrderDto1, Integer contractTradeOrderDto2) {
|
|
|
- if (Objects.isNull(contractTradeOrderDto) && Objects.equals(contractTradeOrderDto2,1)) {
|
|
|
+ if (Objects.isNull(contractTradeOrderDto) && Objects.equals(contractTradeOrderDto2, 1)) {
|
|
|
throw new BusinessException("商品id不能为空!");
|
|
|
}
|
|
|
if (Objects.isNull(contractTradeOrderDto1)) {
|
|
|
@@ -1999,7 +2136,7 @@ public class KwcContractTradeService {
|
|
|
|
|
|
@NotNull
|
|
|
private static ContractTradeOrderInfo getContractTradeOrderInfo(KwcContractTrade c, Map<String,
|
|
|
- KwcContractTradeUnit> conTractTradeUnitMap,Integer entType, Map<Long, KwcContractTradeGoods> contractGoodsMap) {
|
|
|
+ KwcContractTradeUnit> conTractTradeUnitMap, Integer entType, Map<Long, KwcContractTradeGoods> contractGoodsMap) {
|
|
|
ContractTradeOrderInfo contractTradeOrderInfo = new ContractTradeOrderInfo();
|
|
|
contractTradeOrderInfo.setId(c.getId());
|
|
|
KwcContractTradeUnit unit = conTractTradeUnitMap.getOrDefault(c.getId() + "_" + entType,
|
|
|
@@ -2031,7 +2168,7 @@ public class KwcContractTradeService {
|
|
|
contractTradeOrderInfo.setSalesmanId(c.getSalesmanId());
|
|
|
contractTradeOrderInfo.setSalesmanPhone(c.getSalesmanPhone());
|
|
|
KwcContractTradeGoods kwcContractTradeGoods = contractGoodsMap.getOrDefault(c.getId(), new KwcContractTradeGoods());
|
|
|
- contractTradeOrderInfo.setSignPrice(Objects.nonNull(kwcContractTradeGoods.getPrice())?kwcContractTradeGoods.getPrice():new BigDecimal("-1"));
|
|
|
+ contractTradeOrderInfo.setSignPrice(Objects.nonNull(kwcContractTradeGoods.getPrice()) ? kwcContractTradeGoods.getPrice() : new BigDecimal("-1"));
|
|
|
contractTradeOrderInfo.setAmount(Objects.isNull(kwcContractTradeGoods.getAmount()) ? new BigDecimal("-1") : kwcContractTradeGoods.getAmount());
|
|
|
return contractTradeOrderInfo;
|
|
|
}
|
|
|
@@ -2050,17 +2187,17 @@ public class KwcContractTradeService {
|
|
|
} else {
|
|
|
entId = LoginUserHolder.getEntId();
|
|
|
}
|
|
|
- // Integer type =null;
|
|
|
+ // Integer type =null;
|
|
|
Set<Long> entIds = Sets.newHashSet();
|
|
|
entIds.add(entId);
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getPurchaseEntId())) {
|
|
|
//查询企业 信息
|
|
|
entIds.add(Long.valueOf(req.getPurchaseEntId()));
|
|
|
- // type=CooperateTypeEnum.PURCHASER.getCode();
|
|
|
+ // type=CooperateTypeEnum.PURCHASER.getCode();
|
|
|
}
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getSupplyEntId())) {
|
|
|
entIds.add(Long.valueOf(req.getSupplyEntId()));
|
|
|
- // type=CooperateTypeEnum.SUPPLIER.getCode();
|
|
|
+ // type=CooperateTypeEnum.SUPPLIER.getCode();
|
|
|
}
|
|
|
Set<Long> contractIds = null;
|
|
|
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(entIds)) {
|
|
|
@@ -2178,12 +2315,13 @@ public class KwcContractTradeService {
|
|
|
|
|
|
/**
|
|
|
* 查询同产品和同托运企业是否存在自动派车合同
|
|
|
- * @param entId 托运企业
|
|
|
+ *
|
|
|
+ * @param entId 托运企业
|
|
|
* @param goodsIds 商品id集合
|
|
|
* @return
|
|
|
*/
|
|
|
public List<LogisticsEntDtoVO> queryAutoContractLogOrder(Long entId, List<Long> goodsIds) {
|
|
|
- log.info("查询满足贸易合合同供应企业和商品的自动派车的物流合同,企业id:{}, 商品id:{}",entId, JSON.toJSONString(goodsIds));
|
|
|
+ log.info("查询满足贸易合合同供应企业和商品的自动派车的物流合同,企业id:{}, 商品id:{}", entId, JSON.toJSONString(goodsIds));
|
|
|
if (Objects.isNull(entId)) {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "供应商企业id不能为空!");
|
|
|
}
|
|
|
@@ -2191,44 +2329,73 @@ public class KwcContractTradeService {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "商品id不能为空!");
|
|
|
}
|
|
|
|
|
|
- //查询供应商企业物流合同信息
|
|
|
+ //1. 查询供应商企业物流合同关联的unit信息
|
|
|
List<KwcContractLogisticsUnit> contractLogisticsUnits = kwcContractLogisticsUnitRepository.queryByEntIdAndType(entId);
|
|
|
if (CollectionUtils.isEmpty(contractLogisticsUnits)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
Set<Long> unitContractIds = contractLogisticsUnits.stream().map(KwcContractLogisticsUnit::getContractId).collect(Collectors.toSet());
|
|
|
|
|
|
- //查询物流商品合同信息
|
|
|
- List<KwcContractLogisticsGoods> contractLogisticsGoods = kwcContractLogisticsGoodsRepository.queryByContractIds(unitContractIds);
|
|
|
- if (CollectionUtils.isEmpty(contractLogisticsGoods)) {
|
|
|
+ //2. 查询自动派车物流合同主信息
|
|
|
+ List<KwcContractLogistics> contractLogisticsList = contractLogisticsRepository.queryByIdsAndDispatch(unitContractIds);
|
|
|
+ if (CollectionUtils.isEmpty(contractLogisticsList)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- Map<Long, List<KwcContractLogisticsGoods>> logisticsGoodsMap = contractLogisticsGoods.stream().collect(Collectors.groupingBy(KwcContractLogisticsGoods::getContractId));
|
|
|
- List<Long> contractIdList = new ArrayList<>();
|
|
|
- //校验合同里是否都包含贸易合同里的商品
|
|
|
- for (Map.Entry<Long, List<KwcContractLogisticsGoods>> entry : logisticsGoodsMap.entrySet()) {
|
|
|
- Long contractId = entry.getKey();
|
|
|
- List<KwcContractLogisticsGoods> logisticsGoodList = entry.getValue();
|
|
|
- if (CollectionUtils.isEmpty(logisticsGoodList)) {
|
|
|
- continue;
|
|
|
+
|
|
|
+ // 3. 拆分合同:通用价格>0的直接保留,通用价格=0的需要校验商品id
|
|
|
+ List<Long> validContractIds = new ArrayList<>();
|
|
|
+ List<Long> needCheckGoodsContractIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (KwcContractLogistics contractLogistics : contractLogisticsList) {
|
|
|
+ if (contractLogistics.getCommonPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //通用价格大于0,无需校验goodsIds
|
|
|
+ validContractIds.add(contractLogistics.getId());
|
|
|
+ } else {
|
|
|
+ // 通用价格=0,需要校验商品
|
|
|
+ needCheckGoodsContractIds.add(contractLogistics.getId());
|
|
|
}
|
|
|
- //提取当前合同下的所有商品ID
|
|
|
- Set<Long> currentGoodsIds = logisticsGoodList.stream().map(KwcContractLogisticsGoods::getGoodsId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
- boolean isContains = goodsIds.stream().allMatch(currentGoodsIds::contains);
|
|
|
- if (isContains) {
|
|
|
- contractIdList.add(contractId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 处理需要校验商品的合同ID
|
|
|
+ if (CollectionUtils.isNotEmpty(needCheckGoodsContractIds)) {
|
|
|
+ //查询物流商品合同信息
|
|
|
+ List<KwcContractLogisticsGoods> contractLogisticsGoods = kwcContractLogisticsGoodsRepository.queryByContractIds(unitContractIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(contractLogisticsGoods)) {
|
|
|
+ // 按合同ID分组商品信息
|
|
|
+ Map<Long, List<KwcContractLogisticsGoods>> logisticsGoodsMap = contractLogisticsGoods.stream().collect(Collectors.groupingBy(KwcContractLogisticsGoods::getContractId));
|
|
|
+ for (Long contractId : needCheckGoodsContractIds) {
|
|
|
+ List<KwcContractLogisticsGoods> logisticsGoodList = logisticsGoodsMap.get(contractId);
|
|
|
+ // 提取当前合同下的所有商品ID
|
|
|
+ Set<Long> currentGoodsIds = logisticsGoodList.stream().map(KwcContractLogisticsGoods::getGoodsId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ // 校验目标商品ID是否全部包含
|
|
|
+ boolean isContains = goodsIds.stream().allMatch(currentGoodsIds::contains);
|
|
|
+ if (isContains) {
|
|
|
+ validContractIds.add(contractId);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if (CollectionUtils.isEmpty(contractIdList)) {
|
|
|
+ if (CollectionUtils.isEmpty(validContractIds)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- //查询自动派车物流合同
|
|
|
- List<KwcContractLogistics> contractLogisticsList = contractLogisticsRepository.queryByIdsAndDispatch(contractIdList);
|
|
|
- return toLogisticsEntDtoVO(entId, contractLogisticsList);
|
|
|
+ //过滤满足商品数据
|
|
|
+ List<KwcContractLogistics> finalContractList = contractLogisticsList.stream()
|
|
|
+ .filter(contract -> validContractIds.contains(contract.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //过滤有效期合同
|
|
|
+ List<KwcContractLogistics> filteredLogistics = finalContractList.stream().filter(Objects::nonNull)
|
|
|
+ .filter(con -> con.getStartTime() != null)
|
|
|
+ .filter(con -> {
|
|
|
+ return !con.getStartTime().after(new Date());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return toLogisticsEntDtoVO(entId, filteredLogistics);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 参数转换
|
|
|
+ *
|
|
|
* @param contractLogisticsList
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -2237,6 +2404,9 @@ public class KwcContractTradeService {
|
|
|
LogisticsEntDtoVO vo = new LogisticsEntDtoVO();
|
|
|
vo.setContractId(log.getId());
|
|
|
vo.setContractNo(log.getContractNo());
|
|
|
+ vo.setContractName(log.getName());
|
|
|
+ vo.setContractSigningWay(String.valueOf(log.getSigningWay()));
|
|
|
+ vo.setContractStatus(String.valueOf(log.getStatus()));
|
|
|
vo.setStartTime(log.getStartTime());
|
|
|
vo.setEndTime(log.getEndTime());
|
|
|
vo.setCommonPrice(log.getCommonPrice());
|
|
|
@@ -2259,12 +2429,13 @@ public class KwcContractTradeService {
|
|
|
|
|
|
/**
|
|
|
* 查询同产品和同托运企业是否存在手动派车合同
|
|
|
- * @param entId 托运企业
|
|
|
+ *
|
|
|
+ * @param entId 托运企业
|
|
|
* @param goodsId 商品id集合
|
|
|
* @return
|
|
|
*/
|
|
|
public List<LogisticsEntDtoVO> queryContractLogOrder(Long entId, Long goodsId) {
|
|
|
- log.info("查询满足贸易合合同供应企业和商品的手动派车的物流合同,企业id:{}, 商品id:{}",entId, goodsId);
|
|
|
+ log.info("查询满足贸易合合同供应企业和商品的手动派车的物流合同,企业id:{}, 商品id:{}", entId, goodsId);
|
|
|
if (Objects.isNull(entId)) {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "供应商企业id不能为空!");
|
|
|
}
|
|
|
@@ -2272,30 +2443,76 @@ public class KwcContractTradeService {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "商品id不能为空!");
|
|
|
}
|
|
|
|
|
|
- //查询供应商企业物流合同信息
|
|
|
+ //1. 查询供应商企业物流合同信息
|
|
|
List<KwcContractLogisticsUnit> contractLogisticsUnits = kwcContractLogisticsUnitRepository.queryByEntIdAndType(entId);
|
|
|
if (CollectionUtils.isEmpty(contractLogisticsUnits)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
Set<Long> unitContractIds = contractLogisticsUnits.stream().map(KwcContractLogisticsUnit::getContractId).collect(Collectors.toSet());
|
|
|
|
|
|
- //查询物流商品合同信息
|
|
|
- List<KwcContractLogisticsGoods> contractLogisticsGoods = kwcContractLogisticsGoodsRepository.queryByLogIdsAndGoodsId(unitContractIds, goodsId);
|
|
|
- if (CollectionUtils.isEmpty(contractLogisticsGoods)) {
|
|
|
+ //2. 查询手动派车物流合同主信息
|
|
|
+ List<KwcContractLogistics> contractLogisticsList = contractLogisticsRepository.queryBycontractIdList(unitContractIds);
|
|
|
+ if (CollectionUtils.isEmpty(contractLogisticsList)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- List<Long> goodContractIds = contractLogisticsGoods.stream().map(KwcContractLogisticsGoods::getContractId).distinct().collect(Collectors.toList());
|
|
|
|
|
|
- //查询自动派车物流合同
|
|
|
- List<KwcContractLogistics> contractLogisticsList = contractLogisticsRepository.queryBycontractIdList(goodContractIds);
|
|
|
- return toLogisticsEntDtoVO(entId, contractLogisticsList);
|
|
|
+ // 3. 拆分合同:通用价格>0的直接保留,通用价格=0的需要校验商品id
|
|
|
+ List<Long> validContractIds = new ArrayList<>();
|
|
|
+ List<Long> needCheckGoodsContractIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (KwcContractLogistics contractLogistics : contractLogisticsList) {
|
|
|
+ if (contractLogistics.getCommonPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //通用价格大于0,无需校验goodsIds
|
|
|
+ validContractIds.add(contractLogistics.getId());
|
|
|
+ } else {
|
|
|
+ // 通用价格=0,需要校验商品
|
|
|
+ needCheckGoodsContractIds.add(contractLogistics.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 处理需要校验商品的合同ID
|
|
|
+ if (CollectionUtils.isNotEmpty(needCheckGoodsContractIds)) {
|
|
|
+ //查询物流商品合同信息
|
|
|
+ List<KwcContractLogisticsGoods> contractLogisticsGoods = kwcContractLogisticsGoodsRepository.queryByContractIds(unitContractIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(contractLogisticsGoods)) {
|
|
|
+ // 按合同ID分组商品信息
|
|
|
+ Map<Long, List<KwcContractLogisticsGoods>> logisticsGoodsMap = contractLogisticsGoods.stream().collect(Collectors.groupingBy(KwcContractLogisticsGoods::getContractId));
|
|
|
+ for (Long contractId : needCheckGoodsContractIds) {
|
|
|
+ List<KwcContractLogisticsGoods> logisticsGoodList = logisticsGoodsMap.get(contractId);
|
|
|
+ // 提取当前合同下的所有商品ID
|
|
|
+ Set<Long> currentGoodsIds = logisticsGoodList.stream().map(KwcContractLogisticsGoods::getGoodsId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
+ // 校验目标商品ID是否包含
|
|
|
+ boolean isContains = currentGoodsIds.contains(goodsId);
|
|
|
+ if (isContains) {
|
|
|
+ validContractIds.add(contractId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(validContractIds)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ //过滤满足商品数据
|
|
|
+ List<KwcContractLogistics> finalContractList = contractLogisticsList.stream()
|
|
|
+ .filter(contract -> validContractIds.contains(contract.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //过滤有效期合同
|
|
|
+ List<KwcContractLogistics> filteredLogistics = finalContractList.stream().filter(Objects::nonNull)
|
|
|
+ .filter(con -> con.getStartTime() != null)
|
|
|
+ .filter(con -> {
|
|
|
+ return !con.getStartTime().after(new Date());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return toLogisticsEntDtoVO(entId, filteredLogistics);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据合同id和商品id查询物流合同商品信息
|
|
|
+ *
|
|
|
* @param contractId 物流合同
|
|
|
- * @param goodsId 商品id
|
|
|
+ * @param goodsId 商品id
|
|
|
* @return
|
|
|
*/
|
|
|
public LogisticsGoodsDto queryLogGoodsByContractId(Long contractId, Long goodsId) {
|
|
|
@@ -2308,7 +2525,7 @@ public class KwcContractTradeService {
|
|
|
//查询物流商品合同信息
|
|
|
KwcContractLogisticsGoods goods = kwcContractLogisticsGoodsRepository.queryByContractIdAndGoodId(contractId, goodsId);
|
|
|
if (goods == null) {
|
|
|
- throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "当前物流合同商品信息不存在!");
|
|
|
+ return new LogisticsGoodsDto();
|
|
|
}
|
|
|
LogisticsGoodsDto dto = new LogisticsGoodsDto();
|
|
|
dto.setGoodsId(goods.getGoodsId());
|
|
|
@@ -2318,7 +2535,6 @@ public class KwcContractTradeService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
//查询物流合同物流企业信息
|
|
|
public TradeContractUnitDto queryEntByContractId(Long contractId) {
|
|
|
KwcContractLogisticsUnit unit = kwcContractLogisticsUnitRepository.queryByLogContractIdUnit(contractId);
|
|
|
@@ -2345,5 +2561,8 @@ public class KwcContractTradeService {
|
|
|
return logisticsScore;
|
|
|
}
|
|
|
|
|
|
+ public Long querySign(Long entId, Integer type) {
|
|
|
+ return kwcContractTradeMapper.selectSignCount(entId, type);
|
|
|
+ }
|
|
|
}
|
|
|
|