|
@@ -0,0 +1,472 @@
|
|
|
|
|
+package com.fs.his.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.fs.company.domain.Company;
|
|
|
|
|
+import com.fs.company.domain.CompanyDept;
|
|
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
|
|
+import com.fs.company.service.ICompanyDeptService;
|
|
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
|
|
+import com.fs.company.service.ICompanyUserService;
|
|
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
|
|
+import com.fs.core.utils.OrderCodeUtils;
|
|
|
|
|
+import com.fs.erp.domain.ErpOrder;
|
|
|
|
|
+import com.fs.erp.domain.ErpOrderItem;
|
|
|
|
|
+import com.fs.erp.domain.ErpOrderPayment;
|
|
|
|
|
+import com.fs.erp.dto.ErpOrderResponseDTO;
|
|
|
|
|
+import com.fs.erp.dto.OrderItemDTO;
|
|
|
|
|
+import com.fs.erp.dto.PaymentDTO;
|
|
|
|
|
+import com.fs.erp.dto.ShopOrderDTO;
|
|
|
|
|
+import com.fs.erp.http.JstErpHttpService;
|
|
|
|
|
+import com.fs.erp.service.IErpOrderService;
|
|
|
|
|
+import com.fs.his.config.FsSysConfig;
|
|
|
|
|
+import com.fs.his.domain.FsExpress;
|
|
|
|
|
+import com.fs.his.domain.FsExternalOrder;
|
|
|
|
|
+import com.fs.his.domain.FsExternalOrderItem;
|
|
|
|
|
+import com.fs.his.domain.FsStore;
|
|
|
|
|
+import com.fs.his.domain.FsStoreProduct;
|
|
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
|
|
+import com.fs.his.domain.FsUserAddress;
|
|
|
|
|
+import com.fs.his.domain.vo.FsExternalOrderListVO;
|
|
|
|
|
+import com.fs.his.mapper.FsExternalOrderMapper;
|
|
|
|
|
+import com.fs.his.mapper.FsExternalOrderItemMapper;
|
|
|
|
|
+import com.fs.his.mapper.FsStoreMapper;
|
|
|
|
|
+import com.fs.his.mapper.FsStoreProductMapper;
|
|
|
|
|
+import com.fs.his.param.FsExternalOrderAddParam;
|
|
|
|
|
+import com.fs.his.service.IFsExternalOrderService;
|
|
|
|
|
+import com.fs.his.service.IFsExpressService;
|
|
|
|
|
+import com.fs.his.service.IFsUserAddressService;
|
|
|
|
|
+import com.fs.his.service.IFsUserService;
|
|
|
|
|
+import com.fs.his.utils.ConfigUtil;
|
|
|
|
|
+import com.fs.his.vo.FsExternalOrderDetailVO;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class FsExternalOrderServiceImpl implements IFsExternalOrderService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsExternalOrderMapper fsExternalOrderMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsExternalOrderItemMapper fsExternalOrderItemMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsUserAddressService userAddressService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStoreProductMapper fsStoreProductMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsUserService fsUserService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ConfigUtil configUtil;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStoreMapper fsStoreMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ICompanyService companyService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ICompanyUserService companyUserService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ICompanyDeptService companyDeptService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsExpressService expressService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsUserAddressService fsUserAddressService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ @Qualifier("JSTErpOrderServiceImpl")
|
|
|
|
|
+ private IErpOrderService jstOrderService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private JstErpHttpService jstErpHttpService;
|
|
|
|
|
+
|
|
|
|
|
+ private Map<Integer, IErpOrderService> erpServiceMap;
|
|
|
|
|
+
|
|
|
|
|
+ @PostConstruct
|
|
|
|
|
+ public void initErpServiceMap() {
|
|
|
|
|
+ erpServiceMap = new HashMap<>();
|
|
|
|
|
+ erpServiceMap.put(5, jstOrderService);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public FsExternalOrder selectFsExternalOrderByOrderId(Long orderId) {
|
|
|
|
|
+ return fsExternalOrderMapper.selectFsExternalOrderByOrderId(orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public FsExternalOrder selectFsExternalOrderByOrderCode(String orderCode) {
|
|
|
|
|
+ return fsExternalOrderMapper.selectFsExternalOrderByOrderCode(orderCode);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+
|
|
|
|
|
+ public List<FsExternalOrder> selectFsExternalOrderList(FsExternalOrder fsExternalOrder) {
|
|
|
|
|
+ return fsExternalOrderMapper.selectFsExternalOrderList(fsExternalOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<FsExternalOrderListVO> selectExternalOrderListVO(FsExternalOrder fsExternalOrder) {
|
|
|
|
|
+ return fsExternalOrderMapper.selectExternalOrderListVO(fsExternalOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public FsExternalOrderDetailVO selectExternalOrderDetailVO(Long orderId) {
|
|
|
|
|
+ FsExternalOrderDetailVO detailVO = fsExternalOrderMapper.selectExternalOrderDetailVO(orderId);
|
|
|
|
|
+ if (detailVO != null) {
|
|
|
|
|
+ List<FsExternalOrderDetailVO.ProductItemVO> productList = fsExternalOrderItemMapper.selectProductItemVOByOrderId(orderId);
|
|
|
|
|
+ detailVO.setProductList(productList);
|
|
|
|
|
+ }
|
|
|
|
|
+ return detailVO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int insertFsExternalOrder(FsExternalOrder fsExternalOrder) {
|
|
|
|
|
+ return fsExternalOrderMapper.insertFsExternalOrder(fsExternalOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateFsExternalOrder(FsExternalOrder fsExternalOrder) {
|
|
|
|
|
+ return fsExternalOrderMapper.updateFsExternalOrder(fsExternalOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int deleteFsExternalOrderByOrderId(Long orderId) {
|
|
|
|
|
+ return fsExternalOrderMapper.deleteFsExternalOrderByOrderId(orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int deleteFsExternalOrderByOrderIds(Long[] orderIds) {
|
|
|
|
|
+ return fsExternalOrderMapper.deleteFsExternalOrderByOrderIds(orderIds);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public R createExternalOrder(FsExternalOrderAddParam param) {
|
|
|
|
|
+ if (StringUtils.isBlank(param.getOrderCode())) {
|
|
|
|
|
+ String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
|
|
+ if (StringUtils.isEmpty(orderSn)) {
|
|
|
|
|
+ return R.error("订单号生成失败,请重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ param.setOrderCode(orderSn);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsExternalOrder existOrder = fsExternalOrderMapper.selectFsExternalOrderByOrderCode(param.getOrderCode());
|
|
|
|
|
+ if (existOrder != null) {
|
|
|
|
|
+ return R.error("订单号已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(param.getProductIds())) {
|
|
|
|
|
+ return R.error("商品列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<FsStoreProduct> storeProductList = fsStoreProductMapper.getStoreProductInProductIds(param.getProductIds());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(storeProductList)) {
|
|
|
|
|
+ return R.error("商品不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsExternalOrder order = new FsExternalOrder();
|
|
|
|
|
+ order.setOrderCode(param.getOrderCode());
|
|
|
|
|
+ order.setSource(param.getSource());
|
|
|
|
|
+ order.setUserId(param.getUserId());
|
|
|
|
|
+ FsUserAddress address = userAddressService.selectFsUserAddressByAddressId(param.getAddressId());
|
|
|
|
|
+ if (address != null) {
|
|
|
|
|
+ order.setUserName(address.getRealName());
|
|
|
|
|
+ order.setUserPhone(address.getPhone());
|
|
|
|
|
+ order.setUserAddress(address.getProvince() + address.getCity() + address.getDistrict() + address.getDetail());
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setFreightPrice(param.getFreightPrice());
|
|
|
|
|
+ order.setPayType(param.getPayType());
|
|
|
|
|
+ order.setCompanyId(param.getCompanyId());
|
|
|
|
|
+ order.setCompanyUserId(param.getCompanyUserId());
|
|
|
|
|
+ order.setRemark(param.getRemark());
|
|
|
|
|
+ order.setStatus(2);
|
|
|
|
|
+ order.setIsPay(1);
|
|
|
|
|
+ order.setIsSync(0);
|
|
|
|
|
+ order.setShippingType(1);
|
|
|
|
|
+ order.setExternalCreateTime(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ Long totalNum = 0L;
|
|
|
|
|
+ BigDecimal totalPrice = BigDecimal.ZERO;
|
|
|
|
|
+ List<FsExternalOrderItem> items = new ArrayList<>();
|
|
|
|
|
+ Long storeId = 0L;
|
|
|
|
|
+ for (FsStoreProduct product : storeProductList) {
|
|
|
|
|
+ Long num = 1L;
|
|
|
|
|
+ BigDecimal price = product.getPrice() != null ? product.getPrice() : BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal itemTotalPrice = price.multiply(BigDecimal.valueOf(num));
|
|
|
|
|
+
|
|
|
|
|
+ totalNum += num;
|
|
|
|
|
+ totalPrice = totalPrice.add(itemTotalPrice);
|
|
|
|
|
+
|
|
|
|
|
+ FsExternalOrderItem item = new FsExternalOrderItem();
|
|
|
|
|
+ item.setProductId(product.getProductId());
|
|
|
|
|
+ item.setProductName(product.getProductName());
|
|
|
|
|
+ item.setProductCode(product.getBarCode());
|
|
|
|
|
+ item.setProductImage(product.getImgUrl());
|
|
|
|
|
+ item.setProductSpec(product.getPrescribeSpec());
|
|
|
|
|
+ item.setNum(num);
|
|
|
|
|
+ item.setPrice(price);
|
|
|
|
|
+ item.setTotalPrice(itemTotalPrice);
|
|
|
|
|
+ item.setCostPrice(product.getCostPrice());
|
|
|
|
|
+ item.setDeliveryStatus(0);
|
|
|
|
|
+ items.add(item);
|
|
|
|
|
+ storeId = product.getStoreId();
|
|
|
|
|
+ }
|
|
|
|
|
+ if(storeId !=null){
|
|
|
|
|
+ order.setStoreId(storeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ order.setTotalNum(totalNum);
|
|
|
|
|
+ order.setTotalPrice(totalPrice);
|
|
|
|
|
+ order.setPayPrice(param.getPayMoney() != null ? param.getPayMoney() : totalPrice);
|
|
|
|
|
+
|
|
|
|
|
+ if (fsExternalOrderMapper.insertFsExternalOrder(order) > 0) {
|
|
|
|
|
+ for (FsExternalOrderItem item : items) {
|
|
|
|
|
+ item.setOrderId(order.getOrderId());
|
|
|
|
|
+ fsExternalOrderItemMapper.insertFsExternalOrderItem(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ FsUser fsUser = fsUserService.selectFsUserByUserId(order.getUserId());
|
|
|
|
|
+ if (fsUser != null && (fsUser.getIsBuy() == null || fsUser.getIsBuy() == 0)) {
|
|
|
|
|
+ FsUser u = new FsUser();
|
|
|
|
|
+ u.setUserId(order.getUserId());
|
|
|
|
|
+ u.setIsBuy(1);
|
|
|
|
|
+ fsUserService.updateFsUser(u);
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok().put("orderId", order.getOrderId()).put("orderCode", order.getOrderCode());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.error("订单创建失败,请重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Long> selectUnsyncedOrderIds() {
|
|
|
|
|
+ return fsExternalOrderMapper.selectUnsyncedOrderIds();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void pushToJstBatch(List<Long> orderIds) throws Exception {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(orderIds)) {
|
|
|
|
|
+ log.info("没有需要推送的外部订单");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsSysConfig sysConfig = configUtil.getSysConfig();
|
|
|
|
|
+ Integer erpOpen = sysConfig.getErpOpen();
|
|
|
|
|
+ if (erpOpen == null || erpOpen == 0) {
|
|
|
|
|
+ log.warn("ERP未开启,跳过外部订单同步");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer erpType = sysConfig.getErpType();
|
|
|
|
|
+ if (erpType == null || erpType != 5) {
|
|
|
|
|
+ log.warn("ERP类型不是聚水潭,跳过同步: {}", erpType);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<ShopOrderDTO> shopOrderList = new ArrayList<>();
|
|
|
|
|
+ Map<String, Long> orderCodeToIdMap = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (Long orderId : orderIds) {
|
|
|
|
|
+ FsExternalOrder order = fsExternalOrderMapper.selectFsExternalOrderByOrderId(orderId);
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ log.warn("外部订单不存在: {}", orderId);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ShopOrderDTO shopOrderDTO = buildShopOrderDTO(order);
|
|
|
|
|
+ if (shopOrderDTO != null) {
|
|
|
|
|
+ shopOrderList.add(shopOrderDTO);
|
|
|
|
|
+ orderCodeToIdMap.put(order.getOrderCode(), orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (shopOrderList.isEmpty()) {
|
|
|
|
|
+ log.info("没有有效的订单需要推送");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int batchSize = 50;
|
|
|
|
|
+ for (int i = 0; i < shopOrderList.size(); i += batchSize) {
|
|
|
|
|
+ int endIndex = Math.min(i + batchSize, shopOrderList.size());
|
|
|
|
|
+ List<ShopOrderDTO> batch = new ArrayList<>(shopOrderList.subList(i, endIndex));
|
|
|
|
|
+
|
|
|
|
|
+ ErpOrderResponseDTO response = jstErpHttpService.batchUpload(batch);
|
|
|
|
|
+ log.info("外部订单推送聚水潭,批次: {}-{}, 结果: {}", i, endIndex, response);
|
|
|
|
|
+
|
|
|
|
|
+ if (response != null && !CollectionUtils.isEmpty(response.getDatas())) {
|
|
|
|
|
+ for (ErpOrderResponseDTO.OrderData data : response.getDatas()) {
|
|
|
|
|
+ if (data != null && data.getIssuccess()) {
|
|
|
|
|
+ String orderCode = data.getSoId();
|
|
|
|
|
+ Long orderId = orderCodeToIdMap.get(orderCode);
|
|
|
|
|
+ if (orderId != null) {
|
|
|
|
|
+ FsExternalOrder updateOrder = new FsExternalOrder();
|
|
|
|
|
+ updateOrder.setOrderId(orderId);
|
|
|
|
|
+ updateOrder.setIsSync(1);
|
|
|
|
|
+ updateOrder.setExtendOrderId(data.getOId().toString());
|
|
|
|
|
+ updateOrder.setSyncMsg("推送成功");
|
|
|
|
|
+ fsExternalOrderMapper.updateFsExternalOrder(updateOrder);
|
|
|
|
|
+ log.info("外部订单推送成功,订单号: {}, 外部单号: {}", orderCode, data.getOId());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (data != null) {
|
|
|
|
|
+ String orderCode = data.getSoId();
|
|
|
|
|
+ Long orderId = orderCodeToIdMap.get(orderCode);
|
|
|
|
|
+ if (orderId != null) {
|
|
|
|
|
+ FsExternalOrder updateOrder = new FsExternalOrder();
|
|
|
|
|
+ updateOrder.setOrderId(orderId);
|
|
|
|
|
+ updateOrder.setIsSync(2);
|
|
|
|
|
+ updateOrder.setSyncMsg(data.getMsg());
|
|
|
|
|
+ fsExternalOrderMapper.updateFsExternalOrder(updateOrder);
|
|
|
|
|
+ log.error("外部订单推送失败,订单号: {}, 原因: {}", orderCode, data.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Thread.sleep(600);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ShopOrderDTO buildShopOrderDTO(FsExternalOrder order) {
|
|
|
|
|
+ if (order.getStoreId() == null) {
|
|
|
|
|
+ log.warn("外部订单店铺ID为空: {}", order.getOrderId());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsStore fsStore = fsStoreMapper.selectFsStoreByStoreId(order.getStoreId());
|
|
|
|
|
+ if (fsStore == null) {
|
|
|
|
|
+ log.warn("外部订单店铺不存在: {}", order.getStoreId());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ShopOrderDTO shopOrderDTO = new ShopOrderDTO();
|
|
|
|
|
+ shopOrderDTO.setShopId(Long.valueOf(fsStore.getShopCode()));
|
|
|
|
|
+ shopOrderDTO.setSoId(order.getOrderCode());
|
|
|
|
|
+
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ shopOrderDTO.setOrderDate(sdf.format(new Date()));
|
|
|
|
|
+ shopOrderDTO.setShopStatus("WAIT_SELLER_SEND_GOODS");
|
|
|
|
|
+ shopOrderDTO.setShopBuyerId(order.getUserName());
|
|
|
|
|
+ shopOrderDTO.setPayAmount(order.getPayPrice().doubleValue());
|
|
|
|
|
+ shopOrderDTO.setFreight(order.getFreightPrice() != null ? order.getFreightPrice().doubleValue() : 0.0);
|
|
|
|
|
+
|
|
|
|
|
+ StringBuilder remarkBuilder = new StringBuilder();
|
|
|
|
|
+ if (order.getCompanyId() != null) {
|
|
|
|
|
+ Company company = companyService.selectCompanyById(order.getCompanyId());
|
|
|
|
|
+ if (company != null) {
|
|
|
|
|
+ remarkBuilder.append(company.getCompanyName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (order.getCompanyUserId() != null) {
|
|
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(order.getCompanyUserId());
|
|
|
|
|
+ if (companyUser != null) {
|
|
|
|
|
+ CompanyDept dept = companyDeptService.selectCompanyDeptById(companyUser.getDeptId());
|
|
|
|
|
+ if (dept != null) {
|
|
|
|
|
+ List<String> names = companyDeptService.selectCompanyDeptNamesByIds(dept.getAncestors());
|
|
|
|
|
+ if (names != null && names.size() > 0) {
|
|
|
|
|
+ remarkBuilder.append("-").append(StringUtils.join(names, ",")).append(",").append(dept.getDeptName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ remarkBuilder.append("-").append(companyUser.getNickName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (order.getRemark() != null) {
|
|
|
|
|
+ remarkBuilder.append(" ").append(order.getRemark());
|
|
|
|
|
+ }
|
|
|
|
|
+ shopOrderDTO.setRemark(remarkBuilder.toString());
|
|
|
|
|
+
|
|
|
|
|
+ String receiverName = order.getUserName();
|
|
|
|
|
+ receiverName = receiverName == null ? "" : receiverName.replaceAll("[^\\u4e00-\\u9fa5a-zA-Z0-9]", "");
|
|
|
|
|
+ if (StringUtils.isBlank(receiverName)) {
|
|
|
|
|
+ receiverName = "收件人";
|
|
|
|
|
+ }
|
|
|
|
|
+ shopOrderDTO.setReceiverName(receiverName.length() > 20 ? receiverName.substring(0, 20) : receiverName);
|
|
|
|
|
+ shopOrderDTO.setReceiverPhone(order.getUserPhone());
|
|
|
|
|
+
|
|
|
|
|
+ String[] address = order.getUserAddress().split(" ");
|
|
|
|
|
+ if (address.length < 3) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String kdnAddress = fsUserAddressService.getKdnAddress(order.getUserAddress());
|
|
|
|
|
+ Map<String, Object> result = JSON.parseObject(kdnAddress);
|
|
|
|
|
+ Map<String, String> addData = (Map<String, String>) ((Map) result.get("Data")).get("result");
|
|
|
|
|
+ if (addData != null) {
|
|
|
|
|
+ shopOrderDTO.setReceiverState((String) addData.get("ProvinceName"));
|
|
|
|
|
+ shopOrderDTO.setReceiverCity((String) addData.get("CityName"));
|
|
|
|
|
+ shopOrderDTO.setReceiverDistrict((String) addData.get("ExpAreaName"));
|
|
|
|
|
+ shopOrderDTO.setReceiverAddress((String) addData.get("StreetName") + addData.get("Address"));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("地址解析失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ shopOrderDTO.setReceiverState(address[0]);
|
|
|
|
|
+ shopOrderDTO.setReceiverCity(address[1]);
|
|
|
|
|
+ shopOrderDTO.setReceiverDistrict(address[2]);
|
|
|
|
|
+ if (address.length > 3) {
|
|
|
|
|
+ StringBuilder addrs = new StringBuilder();
|
|
|
|
|
+ for (int i = 3; i < address.length; i++) {
|
|
|
|
|
+ addrs.append(address[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+ shopOrderDTO.setReceiverAddress(addrs.toString());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ shopOrderDTO.setReceiverAddress(address[2]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (shopOrderDTO.getReceiverAddress() != null) {
|
|
|
|
|
+ shopOrderDTO.setReceiverAddress(shopOrderDTO.getReceiverAddress().replace("+", "加").replace("\n", ""));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<FsExternalOrderItem> orderItems = fsExternalOrderItemMapper.selectFsExternalOrderItemByOrderId(order.getOrderId());
|
|
|
|
|
+ List<OrderItemDTO> itemDTOList = new ArrayList<>();
|
|
|
|
|
+ for (FsExternalOrderItem orderItem : orderItems) {
|
|
|
|
|
+ OrderItemDTO itemDTO = new OrderItemDTO();
|
|
|
|
|
+ itemDTO.setSkuId(orderItem.getProductCode() != null ? orderItem.getProductCode().trim() : "");
|
|
|
|
|
+ itemDTO.setShopSkuId(orderItem.getProductCode() != null ? orderItem.getProductCode().trim() : "");
|
|
|
|
|
+ itemDTO.setName(orderItem.getProductName());
|
|
|
|
|
+ itemDTO.setShopIId(orderItem.getProductCode() != null ? orderItem.getProductCode().trim() : "");
|
|
|
|
|
+ itemDTO.setPropertiesValue(orderItem.getProductSpec());
|
|
|
|
|
+ itemDTO.setAmount(orderItem.getTotalPrice());
|
|
|
|
|
+ itemDTO.setPrice(orderItem.getPrice());
|
|
|
|
|
+ itemDTO.setQty(orderItem.getNum().intValue());
|
|
|
|
|
+ itemDTO.setOuterOiId(String.format("%s%d", order.getOrderCode(), orderItem.getItemId()));
|
|
|
|
|
+ itemDTOList.add(itemDTO);
|
|
|
|
|
+ }
|
|
|
|
|
+ shopOrderDTO.setItems(itemDTOList);
|
|
|
|
|
+
|
|
|
|
|
+ PaymentDTO paymentDTO = new PaymentDTO();
|
|
|
|
|
+ paymentDTO.setAmount(order.getPayPrice().doubleValue());
|
|
|
|
|
+ paymentDTO.setOuterPayId(order.getOrderCode());
|
|
|
|
|
+ paymentDTO.setPayDate(sdf.format(new Date()));
|
|
|
|
|
+ paymentDTO.setPayment("微信支付");
|
|
|
|
|
+ paymentDTO.setBuyerAccount(order.getUserName());
|
|
|
|
|
+ paymentDTO.setSellerAccount("平台销售");
|
|
|
|
|
+ shopOrderDTO.setPay(paymentDTO);
|
|
|
|
|
+
|
|
|
|
|
+ return shopOrderDTO;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|