forked from angelo/java-retail-app
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
4a890936db
|
@ -1,11 +1,15 @@
|
||||||
package com.hzs.retail.sale.controller.service.impl;
|
package com.hzs.retail.sale.controller.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64Encoder;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.hzs.activity.pick.service.IAcPickMemberLogService;
|
import com.hzs.activity.pick.service.IAcPickMemberLogService;
|
||||||
import com.hzs.activity.pick.service.IAcPickService;
|
import com.hzs.activity.pick.service.IAcPickService;
|
||||||
|
import com.hzs.common.core.config.BdConfig;
|
||||||
import com.hzs.common.core.constant.*;
|
import com.hzs.common.core.constant.*;
|
||||||
import com.hzs.common.core.domain.R;
|
import com.hzs.common.core.domain.R;
|
||||||
import com.hzs.common.core.enums.*;
|
import com.hzs.common.core.enums.*;
|
||||||
|
@ -13,6 +17,7 @@ import com.hzs.common.core.enums.retail.ERetailWaresPrice;
|
||||||
import com.hzs.common.core.exception.ServiceException;
|
import com.hzs.common.core.exception.ServiceException;
|
||||||
import com.hzs.common.core.service.RedisService;
|
import com.hzs.common.core.service.RedisService;
|
||||||
import com.hzs.common.core.utils.*;
|
import com.hzs.common.core.utils.*;
|
||||||
|
import com.hzs.common.core.web.domain.AjaxResult;
|
||||||
import com.hzs.common.domain.activity.pick.AcPick;
|
import com.hzs.common.domain.activity.pick.AcPick;
|
||||||
import com.hzs.common.domain.activity.pick.AcPickMemberLog;
|
import com.hzs.common.domain.activity.pick.AcPickMemberLog;
|
||||||
import com.hzs.common.domain.member.account.CuMemberAccount;
|
import com.hzs.common.domain.member.account.CuMemberAccount;
|
||||||
|
@ -22,6 +27,7 @@ import com.hzs.common.domain.sale.ext.BdWaresDetailExt;
|
||||||
import com.hzs.common.domain.sale.ext.SaOrderExt;
|
import com.hzs.common.domain.sale.ext.SaOrderExt;
|
||||||
import com.hzs.common.domain.sale.ext.SaOrderWaresLimitExt;
|
import com.hzs.common.domain.sale.ext.SaOrderWaresLimitExt;
|
||||||
import com.hzs.common.domain.sale.order.*;
|
import com.hzs.common.domain.sale.order.*;
|
||||||
|
import com.hzs.common.domain.sale.product.BdProduct;
|
||||||
import com.hzs.common.domain.sale.wares.BdWaresRange;
|
import com.hzs.common.domain.sale.wares.BdWaresRange;
|
||||||
import com.hzs.common.domain.system.base.BdStorehouse;
|
import com.hzs.common.domain.system.base.BdStorehouse;
|
||||||
import com.hzs.common.domain.system.config.BdGrade;
|
import com.hzs.common.domain.system.config.BdGrade;
|
||||||
|
@ -37,6 +43,7 @@ import com.hzs.retail.sale.param.RetailOrderUpgradeParam;
|
||||||
import com.hzs.sale.order.param.OrderItemsParam;
|
import com.hzs.sale.order.param.OrderItemsParam;
|
||||||
import com.hzs.sale.order.service.*;
|
import com.hzs.sale.order.service.*;
|
||||||
import com.hzs.sale.order.service.impl.SaOrderHandle;
|
import com.hzs.sale.order.service.impl.SaOrderHandle;
|
||||||
|
import com.hzs.sale.product.service.IBdProductService;
|
||||||
import com.hzs.sale.wares.service.IBdWaresDetailService;
|
import com.hzs.sale.wares.service.IBdWaresDetailService;
|
||||||
import com.hzs.sale.wares.service.IBdWaresExtendService;
|
import com.hzs.sale.wares.service.IBdWaresExtendService;
|
||||||
import com.hzs.sale.wares.service.IBdWaresRangeService;
|
import com.hzs.sale.wares.service.IBdWaresRangeService;
|
||||||
|
@ -71,6 +78,8 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISaOrderWaresService iSaOrderWaresService;
|
private ISaOrderWaresService iSaOrderWaresService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private IBdProductService iBdProductService;
|
||||||
|
@Autowired
|
||||||
private IBdWaresExtendService iBdWaresExtendService;
|
private IBdWaresExtendService iBdWaresExtendService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IBdWaresDetailService iBdWaresDetailService;
|
private IBdWaresDetailService iBdWaresDetailService;
|
||||||
|
@ -86,6 +95,8 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
||||||
private IAcPickService iAcPickService;
|
private IAcPickService iAcPickService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAcPickMemberLogService iAcPickMemberLogService;
|
private IAcPickMemberLogService iAcPickMemberLogService;
|
||||||
|
@Autowired
|
||||||
|
private ISaOrderSyncService iSaOrderSyncService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
@ -537,6 +548,8 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
||||||
log.error("新零售 payRegSaOrder 会员注册失败,{}", saveResult.getMsg());
|
log.error("新零售 payRegSaOrder 会员注册失败,{}", saveResult.getMsg());
|
||||||
throw new RuntimeException("会员注册失败");
|
throw new RuntimeException("会员注册失败");
|
||||||
}
|
}
|
||||||
|
// 同步全网产品库存
|
||||||
|
this.allProductSync(saOrderExt);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -559,6 +572,8 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
||||||
log.error("新零售 payUpgOrder 会员升级失败,{}", saveResult.getMsg());
|
log.error("新零售 payUpgOrder 会员升级失败,{}", saveResult.getMsg());
|
||||||
throw new RuntimeException("会员升级失败");
|
throw new RuntimeException("会员升级失败");
|
||||||
}
|
}
|
||||||
|
// 同步全网产品库存
|
||||||
|
this.allProductSync(saOrderExt);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -578,6 +593,8 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
||||||
log.error("新零售 payOtherOrder 会员其它订单失败,{}", saveResult.getMsg());
|
log.error("新零售 payOtherOrder 会员其它订单失败,{}", saveResult.getMsg());
|
||||||
throw new RuntimeException("下单支付失败");
|
throw new RuntimeException("下单支付失败");
|
||||||
}
|
}
|
||||||
|
// 同步全网产品库存
|
||||||
|
this.allProductSync(saOrderExt);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -929,4 +946,58 @@ public class RetailOrderServiceImpl implements IRetailOrderService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步全网产品库存
|
||||||
|
*
|
||||||
|
* @param saOrderExt
|
||||||
|
*/
|
||||||
|
private void allProductSync(SaOrderExt saOrderExt) {
|
||||||
|
if (EYesNo.NO.getIntValue() == BdConfig.getProductSync()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<Integer, BdProduct> productMap = iBdProductService.queryProductMap(saOrderExt.getOrderItemsList().stream().map(SaOrderItems::getPkProduct).collect(Collectors.toSet()), null);
|
||||||
|
// 开启线程调用全网产品库存
|
||||||
|
// 请求参数
|
||||||
|
Map<String, Object> bodyMap = new HashMap<>();
|
||||||
|
bodyMap.put("source", BdConfig.getSysName());
|
||||||
|
bodyMap.put("orderCode", saOrderExt.getOrderCode());
|
||||||
|
List<Map<String, Object>> bodyDetailList = new ArrayList<>();
|
||||||
|
for (SaOrderItems saOrderItems : saOrderExt.getOrderItemsList()) {
|
||||||
|
Map<String, Object> detailMap = new HashMap<>();
|
||||||
|
detailMap.put("wmsCode", productMap.get(saOrderItems.getPkProduct()).getWmsCode());
|
||||||
|
detailMap.put("changeNum", saOrderItems.getQuantity());
|
||||||
|
bodyDetailList.add(detailMap);
|
||||||
|
}
|
||||||
|
bodyMap.put("detailList", bodyDetailList);
|
||||||
|
// 请求头
|
||||||
|
String header = Base64Encoder.encode(BdConfig.getSysName() + "!" + saOrderExt.getOrderCode());
|
||||||
|
ThreadUtils.threadPoolExecutor.submit(() -> {
|
||||||
|
log.info("同步产品,header: {}", header);
|
||||||
|
log.info("同步产品,bodyMap: {}", bodyMap);
|
||||||
|
HttpRequest httpRequest = HttpUtil.createPost(BdConfig.getProductSyncUrl());
|
||||||
|
httpRequest.header("authorization", header);
|
||||||
|
httpRequest.body(JSONUtil.toJsonStr(bodyMap));
|
||||||
|
httpRequest.setReadTimeout(5000);
|
||||||
|
try {
|
||||||
|
// 同步产品接口返回
|
||||||
|
String resultStr = httpRequest.execute().body();
|
||||||
|
AjaxResult ajaxResult = JSONUtil.toBean(resultStr, AjaxResult.class);
|
||||||
|
log.info("同步产品,resultStr: {}", resultStr);
|
||||||
|
if (!ajaxResult.isSuccess()) {
|
||||||
|
// 同步产品失败,250毫秒后重试
|
||||||
|
Thread.sleep(250);
|
||||||
|
resultStr = httpRequest.execute().body();
|
||||||
|
log.info("同步产品失败重试,resultStr: {}", resultStr);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("同步产品库存异常", e);
|
||||||
|
// 保存订单产品同步记录
|
||||||
|
iSaOrderSyncService.save(SaOrderSync.builder()
|
||||||
|
.orderCode(saOrderExt.getOrderCode())
|
||||||
|
.bodyDetail(JSONUtil.toJsonStr(bodyDetailList))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.hzs.sale.order.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.hzs.common.domain.sale.order.SaOrderSync;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单产品同步记录 Mapper 接口
|
||||||
|
*/
|
||||||
|
public interface SaOrderSyncMapper extends BaseMapper<SaOrderSync> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.hzs.sale.order.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.hzs.common.domain.sale.order.SaOrderSync;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单产品同步记录 服务类
|
||||||
|
*/
|
||||||
|
public interface ISaOrderSyncService extends IService<SaOrderSync> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.hzs.sale.order.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.hzs.common.domain.sale.order.SaOrderSync;
|
||||||
|
import com.hzs.sale.order.mapper.SaOrderSyncMapper;
|
||||||
|
import com.hzs.sale.order.service.ISaOrderSyncService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单产品同步记录 服务实现类
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SaOrderSyncServiceImpl extends ServiceImpl<SaOrderSyncMapper, SaOrderSync> implements ISaOrderSyncService {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.hzs.sale.order.mapper.SaOrderSyncMapper">
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -10,6 +10,11 @@ import org.springframework.stereotype.Component;
|
||||||
@ConfigurationProperties(prefix = "bd")
|
@ConfigurationProperties(prefix = "bd")
|
||||||
public class BdConfig {
|
public class BdConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统名称(ESysName)
|
||||||
|
*/
|
||||||
|
private static String sysName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前环境
|
* 当前环境
|
||||||
*/
|
*/
|
||||||
|
@ -32,14 +37,21 @@ public class BdConfig {
|
||||||
// */
|
// */
|
||||||
// private static String android;
|
// private static String android;
|
||||||
|
|
||||||
private static Integer enable;
|
/**
|
||||||
|
* 商品同步是否开启(0=开启,1=不开启)
|
||||||
|
*/
|
||||||
|
private static Integer productSync;
|
||||||
|
/**
|
||||||
|
* 商品同步地址
|
||||||
|
*/
|
||||||
|
private static String productSyncUrl;
|
||||||
|
|
||||||
public static String getEnv() {
|
public static String getSysName() {
|
||||||
return env;
|
return sysName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnv(String env) {
|
public void setSysName(String sysName) {
|
||||||
BdConfig.env = env;
|
BdConfig.sysName = sysName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPc() {
|
public static String getPc() {
|
||||||
|
@ -74,11 +86,20 @@ public class BdConfig {
|
||||||
// HzsConfig.android = android;
|
// HzsConfig.android = android;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static Integer getEnable() {
|
public static Integer getProductSync() {
|
||||||
return enable;
|
return productSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnable(Integer enable) {
|
public void setProductSync(Integer productSync) {
|
||||||
BdConfig.enable = enable;
|
BdConfig.productSync = productSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getProductSyncUrl() {
|
||||||
|
return productSyncUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductSyncUrl(String productSyncUrl) {
|
||||||
|
BdConfig.productSyncUrl = productSyncUrl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,8 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 是否默认
|
* 是否默认
|
||||||
* @Author: ljc
|
|
||||||
* @Time: 2022/9/27 10:31
|
|
||||||
* @Classname: EDefault
|
|
||||||
* @Package_name: com.hzs.common.core.enums
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
public enum EDefault {
|
public enum EDefault {
|
||||||
|
@ -36,5 +31,4 @@ public enum EDefault {
|
||||||
*/
|
*/
|
||||||
private final String label;
|
private final String label;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.hzs.common.core.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统名称
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum ESysName {
|
||||||
|
|
||||||
|
MANAGE("manage", "后台管理"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新零售
|
||||||
|
*/
|
||||||
|
BF("bf", "新零售BF"),
|
||||||
|
/**
|
||||||
|
* 新零售店铺
|
||||||
|
*/
|
||||||
|
BL("bl", "新零售店铺BL"),
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际值
|
||||||
|
*/
|
||||||
|
private final String value;
|
||||||
|
/**
|
||||||
|
* 显示标签
|
||||||
|
*/
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
public static ESysName getEnumByValue(String value) {
|
||||||
|
for (ESysName enums : ESysName.values()) {
|
||||||
|
if (enums.getValue().equals(value)) {
|
||||||
|
return enums;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLabelByValue(String value) {
|
||||||
|
for (ESysName enums : ESysName.values()) {
|
||||||
|
if (enums.getValue().equals(value)) {
|
||||||
|
return enums.getLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.hzs.common.domain.sale.order;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.*;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单产品同步记录
|
||||||
|
*/
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("SA_ORDER_SYNC")
|
||||||
|
public class SaOrderSync implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@TableId("PK_ID")
|
||||||
|
private Long pkId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单编号
|
||||||
|
*/
|
||||||
|
@TableField("ORDER_CODE")
|
||||||
|
private String orderCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品明细列表
|
||||||
|
*/
|
||||||
|
@TableField("BODY_DETAIL")
|
||||||
|
private String bodyDetail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField("CREATION_TIME")
|
||||||
|
private Date creationTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步状态(1=失败)
|
||||||
|
*/
|
||||||
|
@TableField("STATUS")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue