|
|
@@ -1,21 +1,34 @@
|
|
|
package com.sckw.order.serivce;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.sckw.core.common.enums.enums.DictEnum;
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.model.vo.TableStatisticRes;
|
|
|
import com.sckw.core.utils.BeanUtils;
|
|
|
+import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.OrderGenerateUtils;
|
|
|
+import com.sckw.core.web.context.LoginUserHolder;
|
|
|
+import com.sckw.mongo.model.SckwTradeOrder;
|
|
|
import com.sckw.order.dao.KwoTradeOrderMapper;
|
|
|
-import com.sckw.order.model.KwoTradeOrder;
|
|
|
+import com.sckw.order.model.*;
|
|
|
import com.sckw.order.model.vo.req.*;
|
|
|
import com.sckw.order.model.vo.res.OrderDetailRes;
|
|
|
import com.sckw.order.model.vo.res.OrderListRes;
|
|
|
+import com.sckw.product.api.dubbo.GoodsInfoService;
|
|
|
+import com.sckw.product.api.model.KwpGoods;
|
|
|
import com.sckw.stream.model.SckwBusSum;
|
|
|
+import com.sckw.system.api.RemoteSystemService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.cloud.stream.function.StreamBridge;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @desc: 交易订单(采购订单/销售订单)service
|
|
|
@@ -27,11 +40,18 @@ import java.util.List;
|
|
|
@RequiredArgsConstructor
|
|
|
public class KwoTradeOrderService {
|
|
|
|
|
|
+ @DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
+ private RemoteSystemService remoteSystemService;
|
|
|
+
|
|
|
+ @DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
+ private GoodsInfoService goodsInfoService;
|
|
|
+
|
|
|
private final KwoTradeOrderMapper kwoTradeOrderMapper;
|
|
|
private final StreamBridge streamBridge;
|
|
|
private final KwoTradeOrderAddressService kwoTradeOrderAddressService;
|
|
|
private final KwoTradeOrderUnitService kwoTradeOrderUnitService;
|
|
|
private final KwoTradeOrderGoodsService kwoTradeOrderGoodsService;
|
|
|
+ private final KwoTradeOrderContractService kwoTradeOrderContractService;
|
|
|
private final KwoTradeOrderTrackService kwoTradeOrderTrackService;
|
|
|
|
|
|
private static final String ORDER_NO_PREFIX = "CD";
|
|
|
@@ -43,47 +63,187 @@ public class KwoTradeOrderService {
|
|
|
* @Param param:
|
|
|
* @return: void
|
|
|
*/
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void addPurchaseOrderDraft(PurchaseOrderParam param) {
|
|
|
KwoTradeOrder order = BeanUtils.copyProperties(param, KwoTradeOrder.class);
|
|
|
- order.setTOrderNo(OrderGenerateUtils.generateOrderNo("CD")).setSource(DictEnum.TORDER_SOURCE_0.getValue())
|
|
|
- .setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_0.getValue()));
|
|
|
+ order.setEntId(LoginUserHolder.getEntId()).setTOrderNo(OrderGenerateUtils.generateOrderNo(ORDER_NO_PREFIX))
|
|
|
+ .setUnit(Objects.nonNull(param.getGoodsInfo()) ? param.getGoodsInfo().getUnit() : null)
|
|
|
+ .setSource(DictEnum.TORDER_SOURCE_0.getValue()).setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_0.getValue()));
|
|
|
kwoTradeOrderMapper.insert(order);
|
|
|
- //存MongoD
|
|
|
- SckwBusSum sckwBusSum = new SckwBusSum();
|
|
|
- streamBridge.send("sckw-busSum", sckwBusSum);
|
|
|
+ addOtherOrderInfo(order, BeanUtils.copyProperties(param, ValetOrderParam.class));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc: 添加其他订单信息
|
|
|
+ * @author: yzc
|
|
|
+ * @date: 2023-07-13 8:53
|
|
|
+ * @Param id:
|
|
|
+ * @Param tOrderNo:
|
|
|
+ * @Param status:
|
|
|
+ * @Param param:
|
|
|
+ * @return: void
|
|
|
+ */
|
|
|
+ private void addOtherOrderInfo(KwoTradeOrder tradeOrder, ValetOrderParam param) {
|
|
|
+ Long id = tradeOrder.getId();
|
|
|
+ String tOrderNo = tradeOrder.getTOrderNo();
|
|
|
+ SckwTradeOrder order = BeanUtils.copyProperties(tradeOrder, SckwTradeOrder.class);
|
|
|
+ //todo: 当前线程获取企业名称
|
|
|
+ order.setFirmName(String.valueOf(LoginUserHolder.get().getEntId())).setTOrderId(id);
|
|
|
+ //添加商品信息
|
|
|
+ GoodsInfo goodsInfo = param.getGoodsInfo();
|
|
|
+ KwoTradeOrderGoods goods = BeanUtils.copyProperties(goodsInfo, KwoTradeOrderGoods.class);
|
|
|
+ if (Objects.nonNull(goods)) {
|
|
|
+ goods.setTOrderId(id).setTOrderNo(tOrderNo);
|
|
|
+ kwoTradeOrderGoodsService.insert(goods);
|
|
|
+ BeanUtils.copyProperties(goodsInfo, order);
|
|
|
+ }
|
|
|
+ //添加单位信息
|
|
|
+ List<UnitInfo> unitInfos = param.getUnitInfo();
|
|
|
+ if (CollectionUtils.isNotEmpty(unitInfos)) {
|
|
|
+ List<KwoTradeOrderUnit> list = new ArrayList<>(unitInfos.size());
|
|
|
+ List<Long> entIds = unitInfos.stream().map(UnitInfo::getEntId).distinct().toList();
|
|
|
+ //todo: 获取一级企业信息
|
|
|
+ unitInfos.forEach(e -> {
|
|
|
+ KwoTradeOrderUnit unit = BeanUtils.copyProperties(e, KwoTradeOrderUnit.class);
|
|
|
+ unit.setTOrderId(id).setTOrderNo(tOrderNo)
|
|
|
+ .setTopEntId(e.getEntId());
|
|
|
+ list.add(unit);
|
|
|
+ if (Objects.equals(e.getUnitType(), DictEnum.TORDER_UNIT_TYPE_1.getValue())) {
|
|
|
+ order.setSupplyEntId(e.getEntId()).setSupplyTopEntId(e.getEntId()).setSupplyFirmName(e.getFirmName())
|
|
|
+ .setSupplyContacts(e.getContacts()).setSupplyPhone(e.getPhone());
|
|
|
+ } else {
|
|
|
+ order.setProcureEntId(e.getEntId()).setProcureTopEntId(e.getEntId()).setProcureFirmName(e.getFirmName())
|
|
|
+ .setProcureContacts(e.getContacts()).setProcurePhone(e.getPhone());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ kwoTradeOrderUnitService.insertBatch(list);
|
|
|
+ }
|
|
|
+ //添加地址信息
|
|
|
+ List<AddressInfo> addressInfos = param.getAddressInfo();
|
|
|
+ if (CollectionUtils.isNotEmpty(addressInfos)) {
|
|
|
+ List<KwoTradeOrderAddress> list = new ArrayList<>(addressInfos.size());
|
|
|
+ addressInfos.forEach(e -> {
|
|
|
+ KwoTradeOrderAddress address = BeanUtils.copyProperties(e, KwoTradeOrderAddress.class);
|
|
|
+ address.setTOrderId(id).setTOrderNo(tOrderNo);
|
|
|
+ list.add(address);
|
|
|
+ if (Objects.equals(e.getAddressType(), DictEnum.TORDER_ADDRESS_TYPE_1.getValue())) {
|
|
|
+ order.setLoadName(e.getName()).setLoadType(e.getType()).setLoadContacts(e.getContacts())
|
|
|
+ .setLoadPhone(e.getPhone()).setLoadCityCode(e.getCityCode()).setLoadCityName(e.getCityName())
|
|
|
+ .setLoadDetailAddress(e.getDetailAddress()).setLoadLat(e.getLat()).setLoadLng(e.getLng());
|
|
|
+ } else {
|
|
|
+ order.setUnloadName(e.getName()).setUnloadType(e.getType()).setUnloadContacts(e.getContacts())
|
|
|
+ .setUnloadPhone(e.getPhone()).setUnloadCityCode(e.getCityCode()).setUnloadCityName(e.getCityName())
|
|
|
+ .setUnloadDetailAddress(e.getDetailAddress()).setUnloadLat(e.getLat()).setUnloadLng(e.getLng());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ kwoTradeOrderAddressService.insertBatch(list);
|
|
|
+ }
|
|
|
+ //添加合同信息
|
|
|
+ ContractInfo contractInfo = param.getContractInfo();
|
|
|
+ KwoTradeOrderContract contract = BeanUtils.copyProperties(contractInfo, KwoTradeOrderContract.class);
|
|
|
+ if (Objects.nonNull(contract)) {
|
|
|
+ contract.setTOrderId(id).setTOrderNo(tOrderNo);
|
|
|
+ kwoTradeOrderContractService.insert(contract);
|
|
|
+ BeanUtils.copyProperties(contractInfo, order);
|
|
|
+ }
|
|
|
+ //添加状态信息
|
|
|
+ KwoTradeOrderTrack track = new KwoTradeOrderTrack();
|
|
|
+ track.setTOrderId(id).setTOrderNo(tOrderNo).setStatus(tradeOrder.getStatus()).setRemark(tradeOrder.getRemark());
|
|
|
+ kwoTradeOrderTrackService.insert(track);
|
|
|
+ order.setDeliveryType("").setProjectName("").setEntrustAmount(BigDecimal.ZERO).setActualAmount(BigDecimal.ZERO)
|
|
|
+ .setContractId(0L).setContractNo("").setContractName("").setContractSigningWay("")
|
|
|
+ .setCreateByName(LoginUserHolder.getUserName()).setUpdateByName(LoginUserHolder.getUserName());
|
|
|
+ //存MongoDb
|
|
|
+ saveMongoDb(1, order);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveMongoDb(Integer method, Object order) {
|
|
|
+ SckwBusSum busSum = new SckwBusSum();
|
|
|
+ busSum.setBusSumType("tradeOrder");
|
|
|
+ busSum.setMethod(method);
|
|
|
+ busSum.setObject(order);
|
|
|
+ streamBridge.send("sckw-busSum", JSON.toJSONString(busSum));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @desc: 代客下单草稿
|
|
|
* @author: yzc
|
|
|
* @date: 2023-07-07 15:31
|
|
|
- * @Param valetOrderParam:
|
|
|
+ * @Param param:
|
|
|
* @return: void
|
|
|
*/
|
|
|
- public void addValetOrderDraft(ValetOrderParam valetOrderParam) {
|
|
|
-
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addValetOrderDraft(ValetOrderParam param) {
|
|
|
+ KwoTradeOrder order = BeanUtils.copyProperties(param, KwoTradeOrder.class);
|
|
|
+ order.setEntId(LoginUserHolder.getEntId()).setTOrderNo(OrderGenerateUtils.generateOrderNo(ORDER_NO_PREFIX))
|
|
|
+ .setUnit(Objects.nonNull(param.getGoodsInfo()) ? param.getGoodsInfo().getUnit() : null)
|
|
|
+ .setSource(DictEnum.TORDER_SOURCE_1.getValue()).setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_0.getValue()));
|
|
|
+ kwoTradeOrderMapper.insert(order);
|
|
|
+ addOtherOrderInfo(order, BeanUtils.copyProperties(param, ValetOrderParam.class));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @desc: 采购下单提交
|
|
|
* @author: yzc
|
|
|
* @date: 2023-07-07 15:31
|
|
|
- * @Param purchaseOrderParam:
|
|
|
+ * @Param param:
|
|
|
* @return: void
|
|
|
*/
|
|
|
- public void addPurchaseOrderSubmit(PurchaseOrderParam purchaseOrderParam) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addPurchaseOrderSubmit(PurchaseOrderParam param) {
|
|
|
+ orderCheck(param);
|
|
|
+ KwoTradeOrder order = BeanUtils.copyProperties(param, KwoTradeOrder.class);
|
|
|
+ order.setEntId(LoginUserHolder.getEntId()).setTOrderNo(OrderGenerateUtils.generateOrderNo(ORDER_NO_PREFIX))
|
|
|
+ .setUnit(param.getGoodsInfo().getUnit()).setSource(DictEnum.TORDER_SOURCE_0.getValue())
|
|
|
+ .setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_1.getValue()));
|
|
|
+ kwoTradeOrderMapper.insert(order);
|
|
|
+ goodsInfoService.updateGoodsAmount(param.getGoodsInfo().getGoodsId(),param.getAmount());
|
|
|
+ addOtherOrderInfo(order, BeanUtils.copyProperties(param, ValetOrderParam.class));
|
|
|
+ }
|
|
|
|
|
|
+ private void orderCheck(PurchaseOrderParam param) {
|
|
|
+ //todo: 则先校验是否存在对供应企业的预付钱包 ;【预计采购金额】是否大于预付清单的【可用预付】金额
|
|
|
+ KwpGoods goods = goodsInfoService.getGoodsById(param.getGoodsInfo().getGoodsId());
|
|
|
+ if (Objects.isNull(goods) || !Objects.equals(goods.getStatus(), 1)) {
|
|
|
+ throw new BusinessException("商品不存在或已下架!");
|
|
|
+ }
|
|
|
+ if (Objects.equals(param.getTrading(), DictEnum.TRADE_TYPE_0.getValue())) {
|
|
|
+ if (param.getPrice().compareTo(goods.getAdvancePrice()) < 0){
|
|
|
+ throw new BusinessException("采购订单金额不能小于商品最低预付款限额!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal goodsAmount = goods.getAmount();
|
|
|
+ if (goods.getAmount().compareTo(param.getAmount()) < 0) {
|
|
|
+ throw new BusinessException("商品库存量小于采购数量!");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @desc: 代客下单提交
|
|
|
* @author: yzc
|
|
|
* @date: 2023-07-07 15:32
|
|
|
- * @Param valetOrderParam:
|
|
|
+ * @Param param:
|
|
|
* @return: void
|
|
|
*/
|
|
|
- public void addValetOrderSubmit(ValetOrderParam valetOrderParam) {
|
|
|
-
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addValetOrderSubmit(ValetOrderParam param) {
|
|
|
+ orderCheck(param);
|
|
|
+ KwoTradeOrder order = BeanUtils.copyProperties(param, KwoTradeOrder.class);
|
|
|
+ order.setEntId(LoginUserHolder.getEntId()).setTOrderNo(OrderGenerateUtils.generateOrderNo(ORDER_NO_PREFIX))
|
|
|
+ .setUnit(param.getGoodsInfo().getUnit()).setSource(DictEnum.TORDER_SOURCE_1.getValue());
|
|
|
+ String contractStatus = param.getContractInfo().getContractStatus();
|
|
|
+ if (Objects.equals(contractStatus, DictEnum.CONTRACT_STATUS_0.getValue())) {
|
|
|
+ order.setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_3.getValue()));
|
|
|
+ } else if (Objects.equals(contractStatus, DictEnum.CONTRACT_STATUS_1.getValue())) {
|
|
|
+ order.setStatus(Integer.valueOf(DictEnum.TORDER_STATUS_4.getValue()));
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("Invalid contract status");
|
|
|
+ }
|
|
|
+ kwoTradeOrderMapper.insert(order);
|
|
|
+ goodsInfoService.updateGoodsAmount(param.getGoodsInfo().getGoodsId(),param.getAmount());
|
|
|
+ addOtherOrderInfo(order, BeanUtils.copyProperties(param, ValetOrderParam.class));
|
|
|
}
|
|
|
|
|
|
/**
|