|
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
@@ -13,9 +12,7 @@ import com.google.common.collect.Maps;
|
|
|
import com.sckw.contract.dao.KwcContractLogisticsMapper;
|
|
import com.sckw.contract.dao.KwcContractLogisticsMapper;
|
|
|
import com.sckw.contract.model.dto.req.QueryListReqDto;
|
|
import com.sckw.contract.model.dto.req.QueryListReqDto;
|
|
|
import com.sckw.contract.model.dto.res.QueryListResDto;
|
|
import com.sckw.contract.model.dto.res.QueryListResDto;
|
|
|
-import com.sckw.contract.model.entity.KwcContractLogistics;
|
|
|
|
|
-import com.sckw.contract.model.entity.KwcContractLogisticsGoods;
|
|
|
|
|
-import com.sckw.contract.model.entity.KwcContractLogisticsUnit;
|
|
|
|
|
|
|
+import com.sckw.contract.model.entity.*;
|
|
|
import com.sckw.contract.model.report.LogisticsListExport;
|
|
import com.sckw.contract.model.report.LogisticsListExport;
|
|
|
import com.sckw.contract.model.vo.req.*;
|
|
import com.sckw.contract.model.vo.req.*;
|
|
|
import com.sckw.contract.model.vo.res.*;
|
|
import com.sckw.contract.model.vo.res.*;
|
|
@@ -55,6 +52,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -1132,11 +1130,18 @@ public class KwcContractLogisticsService {
|
|
|
? r.getPerformedAmount().toPlainString() : null);
|
|
? r.getPerformedAmount().toPlainString() : null);
|
|
|
List<KwcContractLogisticsGoods> goods = finalContractIdAndGoodsMap.get(r.getId());
|
|
List<KwcContractLogisticsGoods> goods = finalContractIdAndGoodsMap.get(r.getId());
|
|
|
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(goods)){
|
|
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(goods)){
|
|
|
- double totalTransportAmount = goods.stream()
|
|
|
|
|
- .filter(g -> Objects.nonNull(g.getAmount()))
|
|
|
|
|
- .mapToDouble(x -> Double.valueOf(String.valueOf(x.getAmount())))
|
|
|
|
|
- .sum();
|
|
|
|
|
- queryLogisticListResp.setTotalTransportAmount(String.valueOf( totalTransportAmount));
|
|
|
|
|
|
|
+ boolean b = goods.stream().anyMatch(g -> Objects.isNull(g.getAmount()));
|
|
|
|
|
+ if (b){
|
|
|
|
|
+ queryLogisticListResp.setContractTransportAmount(null);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ double totalTransportAmount = goods.stream()
|
|
|
|
|
+ .filter(g -> Objects.nonNull(g.getAmount()))
|
|
|
|
|
+ .mapToDouble(x -> Double.parseDouble(String.valueOf(x.getAmount())))
|
|
|
|
|
+ .sum();
|
|
|
|
|
+ queryLogisticListResp.setTotalTransportAmount(String.valueOf( totalTransportAmount));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1158,4 +1163,128 @@ public class KwcContractLogisticsService {
|
|
|
|
|
|
|
|
return PageDataResult.of(page, resp);
|
|
return PageDataResult.of(page, resp);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Boolean addOrUpdateLogisticsContract(LogisticListReq req) {
|
|
|
|
|
+ log.info("新增物流合同,请求参数 :{}", JSON.toJSONString(req));
|
|
|
|
|
+ //查询物流合同
|
|
|
|
|
+ KwcContractLogistics kwcContractLogistics =
|
|
|
|
|
+ kwcContractLogisticsRepository.queryById(req.getId());
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.equals(kwcContractLogistics.getContractNo(),
|
|
|
|
|
+ req.getBaseInfo().getContractCode())){
|
|
|
|
|
+ throw new BusinessException("合同已存在,合同编号:{}", req.getBaseInfo().getContractCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ long contactId = new IdWorker(1L).nextId();
|
|
|
|
|
+
|
|
|
|
|
+ KwcContractLogistics saveContractLogistics = new KwcContractLogistics();
|
|
|
|
|
+ Date date = new Date();
|
|
|
|
|
+ LogisticListReq.TradeBaseInfo baseInfo = req.getBaseInfo();
|
|
|
|
|
+ if (Objects.nonNull(req.getId())){
|
|
|
|
|
+ saveContractLogistics.setId(contactId);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ saveContractLogistics.setId(contactId);
|
|
|
|
|
+ }
|
|
|
|
|
+ saveContractLogistics.setEntId(LoginUserHolder.getEntId());
|
|
|
|
|
+ saveContractLogistics.setContractNo(baseInfo.getContractCode());
|
|
|
|
|
+ saveContractLogistics.setName(baseInfo.getContractName());
|
|
|
|
|
+ saveContractLogistics.setSigningWay(baseInfo.getSigningWay());
|
|
|
|
|
+ saveContractLogistics.setStartTime(baseInfo.getStartTime());
|
|
|
|
|
+ saveContractLogistics.setEndTime(baseInfo.getEndTime());
|
|
|
|
|
+ saveContractLogistics.setStatus(ContractStatusEnum.WAIT_APPROVE.getCode());
|
|
|
|
|
+ saveContractLogistics.setCreateBy(LoginUserHolder.getUserId());
|
|
|
|
|
+ saveContractLogistics.setCreateTime(date);
|
|
|
|
|
+ saveContractLogistics.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
|
|
+ saveContractLogistics.setUpdateTime(date);
|
|
|
|
|
+ kwcContractLogisticsRepository.saveOrUpdateLogistics(saveContractLogistics);
|
|
|
|
|
+
|
|
|
|
|
+ //保存交易商品信息
|
|
|
|
|
+ saveLogisticsGoods(req, contactId);
|
|
|
|
|
+ //保存物流企业信息
|
|
|
|
|
+ List<Long> entIdList = new ArrayList<>();
|
|
|
|
|
+ if (Objects.nonNull(baseInfo.getProvideEntId())) {
|
|
|
|
|
+ entIdList.add(baseInfo.getProvideEntId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (Objects.nonNull(baseInfo.getPurchaseEntId())) {
|
|
|
|
|
+ entIdList.add(baseInfo.getPurchaseEntId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollectionUtils.isEmpty(entIdList)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ saveLogisticListUnit(entIdList, baseInfo, contactId, date);
|
|
|
|
|
+
|
|
|
|
|
+ return Boolean.TRUE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void saveLogisticsGoods(LogisticListReq req, long contactId) {
|
|
|
|
|
+ //删除商品
|
|
|
|
|
+ kwcContractLogisticsGoodsRepository.deleteByContractId(contactId);
|
|
|
|
|
+ List<LogisticListReq.TradeGoodsInfo> goodsInfos = req.getGoodsInfo();
|
|
|
|
|
+ List<KwcContractLogisticsGoods> goods = goodsInfos.stream()
|
|
|
|
|
+ .map(x -> getKwcContractLogisticsGoods(x, contactId))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ kwcContractLogisticsGoodsRepository.saveLogisticsGoods(goods);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @NotNull
|
|
|
|
|
+ private static KwcContractLogisticsGoods getKwcContractLogisticsGoods(LogisticListReq.TradeGoodsInfo x, long contactId) {
|
|
|
|
|
+ KwcContractLogisticsGoods logisticsGoods = new KwcContractLogisticsGoods();
|
|
|
|
|
+ Date date1 = new Date();
|
|
|
|
|
+ logisticsGoods.setId(x.getGoodsId());
|
|
|
|
|
+ logisticsGoods.setContractId(contactId);
|
|
|
|
|
+ logisticsGoods.setGoodsId(x.getGoodsId());
|
|
|
|
|
+ logisticsGoods.setGoodsName(x.getGoodsName());
|
|
|
|
|
+ logisticsGoods.setSkuId(0L);
|
|
|
|
|
+ logisticsGoods.setAmount(x.getAmount());
|
|
|
|
|
+ logisticsGoods.setUnit(x.getUnit());
|
|
|
|
|
+ logisticsGoods.setPrice(x.getPrice());
|
|
|
|
|
+ logisticsGoods.setPriceUnit(x.getAmountUnit());
|
|
|
|
|
+ logisticsGoods.setCreateBy(LoginUserHolder.getUserId());
|
|
|
|
|
+ logisticsGoods.setCreateTime(date1);
|
|
|
|
|
+ logisticsGoods.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
|
|
+ logisticsGoods.setUpdateTime(date1);
|
|
|
|
|
+ return logisticsGoods;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void saveLogisticListUnit(List<Long> entIdList, LogisticListReq.TradeBaseInfo baseInfo, long contactId, Date date) {
|
|
|
|
|
+ Map<Long, EntCacheResDto> entCacheResDtoMap = commonBusinessService.queryEntCacheMapByIds(entIdList);
|
|
|
|
|
+ List<KwcContractLogisticsUnit> units = Lists.newArrayList();
|
|
|
|
|
+ //存供应商
|
|
|
|
|
+ if(Objects.nonNull(baseInfo.getProvideEntId())) {
|
|
|
|
|
+ buildLogisticsUnit(contactId, baseInfo.getProvideEntId(), baseInfo.getProvidePhone(), entCacheResDtoMap, date, units);
|
|
|
|
|
+ }
|
|
|
|
|
+ //存采购商
|
|
|
|
|
+ if (Objects.nonNull(baseInfo.getPurchaseEntId())) {
|
|
|
|
|
+ buildLogisticsUnit(contactId, baseInfo.getPurchaseEntId(), baseInfo.getPurchasePhone(), entCacheResDtoMap, date, units);
|
|
|
|
|
+ }
|
|
|
|
|
+ //删除企业
|
|
|
|
|
+ kwcContractLogisticsUnitRepository.removeByContractId(contactId);
|
|
|
|
|
+ kwcContractLogisticsUnitRepository.saveUnits(units);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private static void buildLogisticsUnit(long contactId, Long entId, String phone ,
|
|
|
|
|
+ Map<Long
|
|
|
|
|
+ , EntCacheResDto> entCacheResDtoMap, Date date, List<KwcContractLogisticsUnit> units) {
|
|
|
|
|
+ KwcContractLogisticsUnit kwcContractTradeUnit = new KwcContractLogisticsUnit();
|
|
|
|
|
+ kwcContractTradeUnit.setId(new IdWorker(1L).nextId());
|
|
|
|
|
+ kwcContractTradeUnit.setContractId(contactId);
|
|
|
|
|
+ kwcContractTradeUnit.setUnitType(CooperateTypeEnum.SUPPLIER.getCode());
|
|
|
|
|
+ kwcContractTradeUnit.setEntId(entId);
|
|
|
|
|
+ EntCacheResDto entCacheResDto = entCacheResDtoMap.get(kwcContractTradeUnit.getEntId());
|
|
|
|
|
+ if (Objects.nonNull(entCacheResDto)) {
|
|
|
|
|
+ kwcContractTradeUnit.setFirmName(entCacheResDto.getFirmName());
|
|
|
|
|
+ }
|
|
|
|
|
+ kwcContractTradeUnit.setContacts(entCacheResDto.getContacts());
|
|
|
|
|
+ kwcContractTradeUnit.setPhone(entCacheResDto.getPhone());
|
|
|
|
|
+ kwcContractTradeUnit.setSignPhone(phone);
|
|
|
|
|
+ kwcContractTradeUnit.setStatus(Global.NO);
|
|
|
|
|
+ kwcContractTradeUnit.setCreateBy(LoginUserHolder.getUserId());
|
|
|
|
|
+ kwcContractTradeUnit.setCreateTime(date);
|
|
|
|
|
+ kwcContractTradeUnit.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
|
|
+ kwcContractTradeUnit.setUpdateTime(date);
|
|
|
|
|
+ kwcContractTradeUnit.setDelFlag(Global.NO);
|
|
|
|
|
+ units.add(kwcContractTradeUnit);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|