|
|
@@ -10,14 +10,13 @@ import com.github.pagehelper.PageInfo;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Sets;
|
|
|
-import com.sckw.contract.api.model.dto.req.TradeEntListQueryFeignDto;
|
|
|
-import com.sckw.contract.api.model.dto.res.TradeEntInfoResVo;
|
|
|
-import com.sckw.contract.api.model.dto.req.TradeEntListQueryFeignDto;
|
|
|
import com.sckw.contract.dao.KwcContractLogisticsMapper;
|
|
|
import com.sckw.contract.model.dto.req.QueryListReqDto;
|
|
|
+import com.sckw.contract.model.dto.req.TradeEntListQueryFeignDto;
|
|
|
import com.sckw.contract.model.dto.res.QueryListResDto;
|
|
|
-import com.sckw.contract.api.model.dto.res.TradeEntInfoResVo;
|
|
|
+import com.sckw.contract.model.dto.res.TradeEntInfoResVo;
|
|
|
import com.sckw.contract.model.entity.*;
|
|
|
+import com.sckw.contract.model.enums.LogisticsTransportBizTypeEnum;
|
|
|
import com.sckw.contract.model.report.LogisticsListExport;
|
|
|
import com.sckw.contract.model.vo.req.*;
|
|
|
import com.sckw.contract.model.vo.res.*;
|
|
|
@@ -1114,6 +1113,10 @@ public class KwcContractLogisticsService {
|
|
|
if (CollectionUtils.isEmpty(contractIdList) && CollectionUtils.isNotEmpty(entIdList)){
|
|
|
return PageDataResult.empty(req.getPageNum(),req.getPageSize());
|
|
|
}
|
|
|
+ applyContractTypeFilterToIds(req, entId, contractIdList);
|
|
|
+ if (CollectionUtils.isEmpty(contractIdList)) {
|
|
|
+ return PageDataResult.empty(req.getPageNum(), req.getPageSize());
|
|
|
+ }
|
|
|
DataPermissionDTO perm = fetchDataPermissionForCurrentUser();
|
|
|
contractIdList = applyDataPermissionToLogisticsContractIds(contractIdList, perm);
|
|
|
if (CollectionUtils.isEmpty(contractIdList)) {
|
|
|
@@ -1181,19 +1184,39 @@ public class KwcContractLogisticsService {
|
|
|
List<QueryLogisticListResp> resp = records.stream()
|
|
|
.map(r -> getQueryLogisticListResp(r, finalContractUniTypeAndUnitMap,
|
|
|
finalContractIdAndGoodsMap, finalLongUserCacheResDtoMap, finalLogTradeOrderIdAndWaybillMap,
|
|
|
- contractIdAndLogisticsOrderMap))
|
|
|
+ contractIdAndLogisticsOrderMap, entId))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
return PageDataResult.of(page, resp);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 合同类型筛选:1 托运合同 2 承运合同(相对当前查看企业 entId 在合同中的角色)
|
|
|
+ */
|
|
|
+ private void applyContractTypeFilterToIds(QueryLogisticListReq req, Long entId, Set<Long> contractIdList) {
|
|
|
+ if (req == null || entId == null || CollectionUtils.isEmpty(contractIdList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer ct = req.getContractType();
|
|
|
+ if (ct == null || (ct != 1 && ct != 2)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int unitType = ct == 1 ? CooperateTypeEnum.CONSIGN.getCode() : CooperateTypeEnum.CARRIAGE.getCode();
|
|
|
+ List<KwcContractLogisticsUnit> typeUnits = kwcContractLogisticsUnitRepository.queryByEntIdAndEntType(entId, unitType);
|
|
|
+ Set<Long> allowed = typeUnits.stream()
|
|
|
+ .map(KwcContractLogisticsUnit::getContractId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ contractIdList.retainAll(allowed);
|
|
|
+ }
|
|
|
+
|
|
|
@NotNull
|
|
|
private static QueryLogisticListResp getQueryLogisticListResp(KwcContractLogistics r,
|
|
|
Map<String, KwcContractLogisticsUnit> finalContractUniTypeAndUnitMap,
|
|
|
Map<Long, List<KwcContractLogisticsGoods>> finalContractIdAndGoodsMap,
|
|
|
Map<Long, UserCacheResDto> finalLongUserCacheResDtoMap,
|
|
|
Map<Long, RWaybillSubOrderVo> logTradeOrderIdAndWaybillMap,
|
|
|
- Map<Long, WayContaractbillOrderVo> contractIdAndLogisticsOrderMap) {
|
|
|
+ Map<Long, WayContaractbillOrderVo> contractIdAndLogisticsOrderMap,
|
|
|
+ Long viewerEntId) {
|
|
|
QueryLogisticListResp queryLogisticListResp = new QueryLogisticListResp();
|
|
|
queryLogisticListResp.setId(r.getId());
|
|
|
queryLogisticListResp.setContractStatus(r.getStatus());
|
|
|
@@ -1209,7 +1232,15 @@ public class KwcContractLogisticsService {
|
|
|
queryLogisticListResp.setCarriageUnit(String.valueOf(carriageUnit.getEntId()));
|
|
|
queryLogisticListResp.setCarriageUnitName(carriageUnit.getFirmName());
|
|
|
}
|
|
|
-
|
|
|
+ if (Objects.nonNull(viewerEntId)) {
|
|
|
+ if (Objects.nonNull(logisticsUnit) && Objects.equals(viewerEntId, logisticsUnit.getEntId())) {
|
|
|
+ queryLogisticListResp.setContractType(1);
|
|
|
+ queryLogisticListResp.setContractTypeDesc("托运合同");
|
|
|
+ } else if (Objects.nonNull(carriageUnit) && Objects.equals(viewerEntId, carriageUnit.getEntId())) {
|
|
|
+ queryLogisticListResp.setContractType(2);
|
|
|
+ queryLogisticListResp.setContractTypeDesc("承运合同");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
queryLogisticListResp.setContractCode(r.getContractNo());
|
|
|
queryLogisticListResp.setContractName(r.getName());
|
|
|
@@ -1323,6 +1354,9 @@ public class KwcContractLogisticsService {
|
|
|
if(Objects.equals(baseInfo.getSettlement(),1)){
|
|
|
throw new BusinessException("暂不支持普通结算模式");
|
|
|
}
|
|
|
+ int transportBizType = resolveTransportBizType(baseInfo);
|
|
|
+ baseInfo.setTransportBizType(transportBizType);
|
|
|
+ validateLogisticsContractBiz(req, transportBizType);
|
|
|
if (Objects.nonNull(req.getId())){
|
|
|
saveContractLogistics.setId(req.getId());
|
|
|
}else {
|
|
|
@@ -1370,7 +1404,14 @@ public class KwcContractLogisticsService {
|
|
|
|
|
|
saveContractLogistics.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
saveContractLogistics.setUpdateTime(date);
|
|
|
- saveContractLogistics.setCommonPrice(baseInfo.getCommonPrice());
|
|
|
+ saveContractLogistics.setTransportBizType(transportBizType);
|
|
|
+ if (LogisticsTransportBizTypeEnum.isRawOreTransfer(transportBizType)) {
|
|
|
+ saveContractLogistics.setCommonPrice(null);
|
|
|
+ saveContractLogistics.setAllowedError(baseInfo.getAllowedError().setScale(4, RoundingMode.HALF_UP));
|
|
|
+ } else {
|
|
|
+ saveContractLogistics.setCommonPrice(baseInfo.getCommonPrice());
|
|
|
+ saveContractLogistics.setAllowedError(null);
|
|
|
+ }
|
|
|
saveContractLogistics.setSigningUrl(req.getContractFile());
|
|
|
kwcContractLogisticsRepository.saveOrUpdateLogistics(saveContractLogistics);
|
|
|
|
|
|
@@ -1389,6 +1430,44 @@ public class KwcContractLogisticsService {
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
+ private static int resolveTransportBizType(LogisticListReq.TradeBaseInfo baseInfo) {
|
|
|
+ Integer t = baseInfo.getTransportBizType();
|
|
|
+ if (t == null) {
|
|
|
+ return LogisticsTransportBizTypeEnum.TRADE_TRANSPORT.getCode();
|
|
|
+ }
|
|
|
+ if (!Objects.equals(t, LogisticsTransportBizTypeEnum.TRADE_TRANSPORT.getCode())
|
|
|
+ && !Objects.equals(t, LogisticsTransportBizTypeEnum.RAW_ORE_TRANSFER.getCode())) {
|
|
|
+ throw new BusinessException("合同类型无效,请选择贸易运输或原矿转运");
|
|
|
+ }
|
|
|
+ return t;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateLogisticsContractBiz(LogisticListReq req, int transportBizType) {
|
|
|
+ LogisticListReq.TradeBaseInfo baseInfo = req.getBaseInfo();
|
|
|
+ if (LogisticsTransportBizTypeEnum.isRawOreTransfer(transportBizType)) {
|
|
|
+ if (baseInfo.getAllowedError() == null) {
|
|
|
+ throw new BusinessException("原矿转运合同须填写允许误差");
|
|
|
+ }
|
|
|
+ if (baseInfo.getAllowedError().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new BusinessException("允许误差须大于0");
|
|
|
+ }
|
|
|
+ if (baseInfo.getAllowedError().compareTo(new BigDecimal("1000")) > 0) {
|
|
|
+ throw new BusinessException("允许误差不能超过1000‰");
|
|
|
+ }
|
|
|
+ if (baseInfo.getCommonPrice() != null && baseInfo.getCommonPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ throw new BusinessException("原矿转运合同不可录入通用运价");
|
|
|
+ }
|
|
|
+ List<LogisticListReq.TradeGoodsInfo> goodsInfos = req.getGoodsInfo();
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(goodsInfos)) {
|
|
|
+ for (LogisticListReq.TradeGoodsInfo g : goodsInfos) {
|
|
|
+ if (g.getPrice() != null && g.getPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ throw new BusinessException("原矿转运合同不可录入运输单价");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void checkAutoDispatchingContractEntType(LogisticListReq.TradeBaseInfo baseInfo,Map<Long, EntCacheResDto> entCacheResDtoMap) {
|
|
|
if(DispatchingTypeEnum.AUTO.getValue().equals(baseInfo.getDispatchWay())){
|
|
|
EntCacheResDto entCacheResDto = entCacheResDtoMap.get(baseInfo.getProvideEntId());
|
|
|
@@ -1456,10 +1535,12 @@ public class KwcContractLogisticsService {
|
|
|
logisticsGoods.setSkuId(0L);
|
|
|
logisticsGoods.setAmount(x.getAmount());
|
|
|
logisticsGoods.setUnit(x.getUnit());
|
|
|
- if (Objects.isNull(x.getPrice())) {
|
|
|
+ if (LogisticsTransportBizTypeEnum.isRawOreTransfer(baseInfo.getTransportBizType())) {
|
|
|
+ logisticsGoods.setPrice(null);
|
|
|
+ } else if (Objects.isNull(x.getPrice())) {
|
|
|
logisticsGoods.setPrice(Objects.nonNull(baseInfo.getCommonPrice())? baseInfo.getCommonPrice().setScale(2,
|
|
|
RoundingMode.HALF_UP) : null);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
logisticsGoods.setPrice(x.getPrice());
|
|
|
}
|
|
|
logisticsGoods.setPriceUnit(x.getAmountUnit());
|
|
|
@@ -1599,7 +1680,16 @@ public class KwcContractLogisticsService {
|
|
|
|
|
|
tradeBaseInfo.setStartTime(logistics.getStartTime());
|
|
|
|
|
|
- tradeBaseInfo.setCommonPrice(logistics.getCommonPrice().compareTo(new BigDecimal("0.00"))==0 ? null: logistics.getCommonPrice());
|
|
|
+ Integer transportBizType = logistics.getTransportBizType();
|
|
|
+ if (transportBizType == null) {
|
|
|
+ transportBizType = LogisticsTransportBizTypeEnum.TRADE_TRANSPORT.getCode();
|
|
|
+ }
|
|
|
+ tradeBaseInfo.setTransportBizType(transportBizType);
|
|
|
+ tradeBaseInfo.setTransportBizTypeDesc(LogisticsTransportBizTypeEnum.getLabelByCode(transportBizType));
|
|
|
+ tradeBaseInfo.setAllowedError(logistics.getAllowedError());
|
|
|
+
|
|
|
+ BigDecimal commonPrice = logistics.getCommonPrice();
|
|
|
+ tradeBaseInfo.setCommonPrice(commonPrice != null && commonPrice.compareTo(BigDecimal.ZERO) == 0 ? null : commonPrice);
|
|
|
tradeBaseInfo.setContractStatus(String.valueOf(logistics.getStatus()));
|
|
|
tradeBaseInfo.setContractStatusDesc(ContractStatusEnum.getNameByCode(logistics.getStatus()));
|
|
|
|
|
|
@@ -1667,7 +1757,6 @@ public class KwcContractLogisticsService {
|
|
|
payableAddDto.setCarriageEntId(collect.get(CooperateTypeEnum.CARRIAGE.getCode()).getEntId());
|
|
|
payableAddDto.setTradeAmount(BigDecimal.ZERO);
|
|
|
payableAddDto.setRemark("运费清单初始化");
|
|
|
- log.info("托运放:{}与承运方:{}签订物流合同,运费清单初始化",payableAddDto.getConsignEntId(),payableAddDto.getCarriageEntId());
|
|
|
BaseResult<Object> payable = paymentFeignService.initPayable(payableAddDto);
|
|
|
if (payable.getCode() == HttpStatus.SUCCESS_CODE){
|
|
|
log.info("创建运费清单成功");
|
|
|
@@ -1718,6 +1807,7 @@ public class KwcContractLogisticsService {
|
|
|
.filter(contractId ->contractIds.contains(contractId)).collect(Collectors.toSet());
|
|
|
}
|
|
|
}
|
|
|
+ applyContractTypeFilterToIds(req, entId, contractIdList);
|
|
|
if (org.apache.commons.collections4.CollectionUtils.isEmpty(contractIdList) && org.apache.commons.collections4.CollectionUtils.isNotEmpty(entIdList)){
|
|
|
Map<Integer, List<KwcContractLogistics>> statusAndLogOrdersMap = new HashMap<>();
|
|
|
List<ContractStatusCountResp.ContractStatusCount> statusCounts = statusEnums.stream()
|