|
|
@@ -2,8 +2,9 @@ package com.sckw.transport.service;
|
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.sckw.core.common.enums.NumberConstant;
|
|
|
-import com.sckw.core.common.enums.StringConstant;
|
|
|
import com.sckw.core.common.enums.enums.DictTypeEnum;
|
|
|
import com.sckw.core.model.enums.LogisticsOrderEnum;
|
|
|
import com.sckw.core.model.page.PageResult;
|
|
|
@@ -20,6 +21,7 @@ import com.sckw.mongo.model.SckwLogisticsOrder;
|
|
|
import com.sckw.order.api.dubbo.TradeOrderInfoService;
|
|
|
import com.sckw.order.api.model.AddressInfoDetail;
|
|
|
import com.sckw.order.api.model.OrderDetailRes;
|
|
|
+import com.sckw.order.api.model.UpdateOrderAmountParam;
|
|
|
import com.sckw.product.api.dubbo.GoodsInfoService;
|
|
|
import com.sckw.product.api.model.KwpGoods;
|
|
|
import com.sckw.stream.model.SckwBusSum;
|
|
|
@@ -39,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -356,7 +359,8 @@ public class LogisticsConsignmentService {
|
|
|
order.setTOrderNo(bo.getTOrderNo());
|
|
|
order.setLOrderNo(lOrderNo);
|
|
|
order.setPid(null);
|
|
|
- order.setPids(orderId + StringConstant.SEMICOLON);
|
|
|
+// order.setPids(orderId + StringConstant.COMMA);
|
|
|
+ order.setPids(orderId.toString());
|
|
|
order.setSettlementCycle(bo.getSettlementCycle());
|
|
|
order.setPrice(new BigDecimal(bo.getPrice()));
|
|
|
order.setPriceType(remoteSystemService.queryDictByTypeAndValue(DictTypeEnum.PRICE_TYPE.getType(), bo.getPriceType()) == null ?
|
|
|
@@ -471,8 +475,6 @@ public class LogisticsConsignmentService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 采购订单-获取托运订单数据
|
|
|
- *
|
|
|
* @param id
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
@@ -491,19 +493,33 @@ public class LogisticsConsignmentService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 销售订单-获取托运订单数据
|
|
|
+ * 销售订单-采购订单-获取托运订单数据
|
|
|
*
|
|
|
* @param id
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
- public HttpResult sellLogisticsOrder(String id, Integer page, Integer pageSize) {
|
|
|
- Long count = getLogisticsOrderCount(id);
|
|
|
- Integer newPage = page - 1;
|
|
|
- List<LogisticsOrderDTO> list = getLogisticsOrderData(id, newPage, pageSize);
|
|
|
- PageResult build = PageResult.build(page, pageSize, count, list);
|
|
|
- return HttpResult.ok(build);
|
|
|
+ public HttpResult logisticsOrder(String id, Integer page, Integer pageSize) {
|
|
|
+ HttpResult httpResult = new HttpResult();
|
|
|
+ OrderDetailRes orderDetailRes = tradeOrderInfoService.getOrderDetailById(Long.parseLong(id));
|
|
|
+ /**根据下单方式决定托运数据是否展示*/
|
|
|
+ boolean flag = false;
|
|
|
+ if (String.valueOf(NumberConstant.ONE).equals(orderDetailRes.getSource())) {
|
|
|
+ flag = true;
|
|
|
+ } else if (String.valueOf(NumberConstant.TWO).equals(orderDetailRes.getSource())) {
|
|
|
+ flag = true;
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("获取贸易订单下单方式异常!");
|
|
|
+ }
|
|
|
+ if (flag) {
|
|
|
+ Long count = getLogisticsOrderCount(id);
|
|
|
+ Integer newPage = page - 1;
|
|
|
+ List<LogisticsOrderDTO> list = getLogisticsOrderData(id, newPage, pageSize);
|
|
|
+ PageResult build = PageResult.build(page, pageSize, count, list);
|
|
|
+ httpResult.setData(build);
|
|
|
+ }
|
|
|
+ return httpResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -557,4 +573,109 @@ public class LogisticsConsignmentService {
|
|
|
List<OrderCarDTO> list = waybillOrderMapper.selectWaybillOrderCarList(id, page, pageSize);
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 采购订单/销售订单-托运订单列表-撤销托运
|
|
|
+ *
|
|
|
+ * @param ids 物流订单id
|
|
|
+ * @param type 单据操作类型
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public HttpResult cancelConsign(List<String> ids, String type) {
|
|
|
+ if (CollectionUtils.isEmpty(ids) || ids.size() < NumberConstant.ONE) {
|
|
|
+ throw new RuntimeException("单据id不能为空");
|
|
|
+ }
|
|
|
+ List<JSONObject> list = new ArrayList<>();
|
|
|
+ //1采购 2销售
|
|
|
+ if (String.valueOf(NumberConstant.ONE).equals(type)) {
|
|
|
+ cancelConsignByOrder(ids, list);
|
|
|
+ } else if (String.valueOf(NumberConstant.TWO).equals(type)) {
|
|
|
+ cancelConsignBySellOrder(ids, list);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("类型错误!");
|
|
|
+ }
|
|
|
+ return HttpResult.ok(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 销售订单撤销托运
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ private void cancelConsignBySellOrder(List<String> ids, List<JSONObject> list) {
|
|
|
+ ids.forEach(s -> {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("id", s);
|
|
|
+ /**当前单据作废
|
|
|
+ * 托运数量回归溯
|
|
|
+ */
|
|
|
+ KwtLogisticsOrder kwtLogisticsOrder = kwtLogisticsOrderMapper.selectOne(new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, s));
|
|
|
+ if (kwtLogisticsOrder == null || (!String.valueOf(LogisticsOrderEnum.PENDING_ORDER.getCode()).equals(kwtLogisticsOrder.getStatus()))) {
|
|
|
+ log.info("物流订单单据id:{}", s);
|
|
|
+ jsonObject.put("message", "单据状态异常或单据不存在");
|
|
|
+ jsonObject.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
+ }else {
|
|
|
+ OrderDetailRes orderDetailRes = tradeOrderInfoService.getOrderDetailById(Long.parseLong(s));
|
|
|
+ UpdateOrderAmountParam param = new UpdateOrderAmountParam();
|
|
|
+ param.setTOrderId(Long.parseLong(s));
|
|
|
+ param.setActualAmount(orderDetailRes.getActualAmount().add(kwtLogisticsOrder.getLoadAmount()));
|
|
|
+ param.setEntrustAmount(orderDetailRes.getEntrustAmount().add(kwtLogisticsOrder.getEntrustAmount().subtract(kwtLogisticsOrder.getLoadAmount())));
|
|
|
+ tradeOrderInfoService.updateOrderAmount(param);
|
|
|
+ kwtLogisticsOrder.setDelFlag(1);
|
|
|
+ kwtLogisticsOrder.setUpdateTime(new Date());
|
|
|
+ kwtLogisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getId())
|
|
|
+ .set(KwtLogisticsOrder::getDelFlag, NumberConstant.ONE)
|
|
|
+ .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtLogisticsOrder::getUpdateTime, new Date()));
|
|
|
+ jsonObject.put("status", HttpStatus.SUCCESS_CODE);
|
|
|
+ }
|
|
|
+ list.add(jsonObject);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 采购订单撤销托运
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ private void cancelConsignByOrder(List<String> ids, List<JSONObject> list) {
|
|
|
+ ids.forEach(s -> {
|
|
|
+ /**当前单据作废
|
|
|
+ * 托运数量回归溯源
|
|
|
+ */
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("id", s);
|
|
|
+ /**当前单据作废
|
|
|
+ * 托运数量回归溯
|
|
|
+ */
|
|
|
+ KwtLogisticsOrder kwtLogisticsOrder = kwtLogisticsOrderMapper.selectOne(new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, s));
|
|
|
+ if (kwtLogisticsOrder == null || (!String.valueOf(LogisticsOrderEnum.PENDING_ORDER.getCode()).equals(kwtLogisticsOrder.getStatus()))) {
|
|
|
+ log.info("物流订单单据id:{}", s);
|
|
|
+ jsonObject.put("message", "单据状态异常或单据不存在");
|
|
|
+ jsonObject.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
+ }else {
|
|
|
+ OrderDetailRes orderDetailRes = tradeOrderInfoService.getOrderDetailById(Long.parseLong(s));
|
|
|
+ UpdateOrderAmountParam param = new UpdateOrderAmountParam();
|
|
|
+ param.setTOrderId(Long.parseLong(s));
|
|
|
+ param.setActualAmount(orderDetailRes.getActualAmount().add(kwtLogisticsOrder.getLoadAmount()));
|
|
|
+ param.setEntrustAmount(orderDetailRes.getEntrustAmount().add(kwtLogisticsOrder.getEntrustAmount().subtract(kwtLogisticsOrder.getLoadAmount())));
|
|
|
+ tradeOrderInfoService.updateOrderAmount(param);
|
|
|
+ kwtLogisticsOrder.setDelFlag(1);
|
|
|
+ kwtLogisticsOrder.setUpdateTime(new Date());
|
|
|
+ kwtLogisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getId())
|
|
|
+ .set(KwtLogisticsOrder::getDelFlag, NumberConstant.ONE)
|
|
|
+ .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtLogisticsOrder::getUpdateTime, new Date()));
|
|
|
+ jsonObject.put("status", HttpStatus.SUCCESS_CODE);
|
|
|
+ }
|
|
|
+ list.add(jsonObject);
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|