Merge remote-tracking branch 'origin/dev' into hph
This commit is contained in:
@@ -53,4 +53,7 @@ public interface TbProductSkuMapper {
|
|||||||
|
|
||||||
@Select("select * from tb_product_sku where is_grounding=1 and product_id=#{id}")
|
@Select("select * from tb_product_sku where is_grounding=1 and product_id=#{id}")
|
||||||
List<TbProductSku> selectByProductCheckGrounding(@Param("id") Integer id);
|
List<TbProductSku> selectByProductCheckGrounding(@Param("id") Integer id);
|
||||||
|
|
||||||
|
@Select("select * from tb_product_sku where is_grounding=1 and is_del=0 and product_id=#{id}")
|
||||||
|
List<TbProductSku> selectGroundingByProId(Integer id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ public class TbProductSku implements Serializable {
|
|||||||
|
|
||||||
private Integer isPauseSale = 0;
|
private Integer isPauseSale = 0;
|
||||||
private Integer isDel;
|
private Integer isDel;
|
||||||
|
private String specSnap;
|
||||||
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ public class OrderService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
RedisUtil redisUtil;
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
|
private final WxAccountUtil wxAccountUtil;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RabbitProducer producer;
|
RabbitProducer producer;
|
||||||
|
|
||||||
@@ -79,7 +81,8 @@ public class OrderService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ProductService productService;
|
private ProductService productService;
|
||||||
|
|
||||||
public OrderService(WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper) {
|
public OrderService(WxAccountUtil wxAccountUtil, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper) {
|
||||||
|
this.wxAccountUtil = wxAccountUtil;
|
||||||
this.wechatUtil = wechatUtil;
|
this.wechatUtil = wechatUtil;
|
||||||
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
||||||
this.shopOpenIdMapper = shopOpenIdMapper;
|
this.shopOpenIdMapper = shopOpenIdMapper;
|
||||||
@@ -277,9 +280,8 @@ public class OrderService {
|
|||||||
) {
|
) {
|
||||||
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
|
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
|
||||||
shopOpenIds.forEach(item -> {
|
shopOpenIds.forEach(item -> {
|
||||||
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
|
wxAccountUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
|
||||||
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber()-num) : String.valueOf(productSku.getStockNumber() - num),
|
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber()-num) : String.valueOf(productSku.getStockNumber() - num), item.getOpenId());
|
||||||
"商品库存不足,请及时补充。", item.getOpenId());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.chaozhanggui.system.cashierservice.dao.*;
|
|||||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
|
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
|
||||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
|
import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||||
@@ -18,8 +19,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -41,9 +41,11 @@ public class ProductService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TbProductSkuResultMapper tbProductSkuResultMapper;
|
TbProductSkuResultMapper tbProductSkuResultMapper;
|
||||||
|
@Autowired
|
||||||
|
private LimitSubmitAspect limitSubmitAspect;
|
||||||
|
|
||||||
|
|
||||||
public Result queryCategory(String shopId,Integer page,Integer pageSize){
|
public Result queryCategory(String shopId,Integer page,Integer pageSize){
|
||||||
PageHelperUtil.startPage(page, pageSize);
|
PageHelperUtil.startPage(page, pageSize);
|
||||||
List<TbShopCategory> list=tbShopCategoryMapper.selectByAll(shopId);
|
List<TbShopCategory> list=tbShopCategoryMapper.selectByAll(shopId);
|
||||||
PageInfo pageInfo=new PageInfo(list);
|
PageInfo pageInfo=new PageInfo(list);
|
||||||
@@ -119,12 +121,66 @@ public class ProductService {
|
|||||||
it.setTbProductSpec(tbProductSpec);
|
it.setTbProductSpec(tbProductSpec);
|
||||||
|
|
||||||
TbProductSkuResult skuResult=tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
TbProductSkuResult skuResult=tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||||
if(ObjectUtil.isEmpty(skuResult)){
|
|
||||||
skuResult=new TbProductSkuResult();
|
|
||||||
|
// 上下架对应的sku
|
||||||
|
String selectSpec = it.getSelectSpec();
|
||||||
|
|
||||||
|
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||||
|
HashSet<String> specSet = new HashSet<>();
|
||||||
|
tbProductSkus.forEach(item -> {
|
||||||
|
String specSnap = item.getSpecSnap();
|
||||||
|
if (specSnap != null) {
|
||||||
|
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||||
|
if (tagSnap != null) {
|
||||||
|
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||||
|
JSONObject snapJSON;
|
||||||
|
|
||||||
|
JSONArray finalSnap = new JSONArray();
|
||||||
|
String finalValues = "";
|
||||||
|
|
||||||
|
HashMap<String, String> snapMap = new HashMap<>();
|
||||||
|
for (Object snap : tagSnaps) {
|
||||||
|
snapJSON = (JSONObject) snap;
|
||||||
|
String values = snapJSON.getString("value");
|
||||||
|
if (StrUtil.isNotBlank(values)) {
|
||||||
|
String[] valueList = values.split(",");
|
||||||
|
for (String value : valueList) {
|
||||||
|
if (specSet.contains(value)) {
|
||||||
|
finalValues = finalValues + (value) + ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StrUtil.isNotBlank(finalValues)) {
|
||||||
|
finalValues = StrUtil.removeSuffix(finalValues, ",");
|
||||||
|
snapJSON.put("value", finalValues);
|
||||||
|
finalSnap.add(snapJSON);
|
||||||
|
snapMap.put(snapJSON.getString("name"), snapJSON.getString("value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectSpec != null) {
|
||||||
|
JSONArray selectSpecJSON = JSONObject.parseArray(selectSpec);
|
||||||
|
for (Object selectSpecInfo : selectSpecJSON) {
|
||||||
|
JSONObject specInfo = (JSONObject) selectSpecInfo;
|
||||||
|
specInfo.put("value", snapMap.get(specInfo.getString("name")).split(","));
|
||||||
|
specInfo.put("selectSpecResult", snapMap.get(specInfo.getString("name")).split(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
it.setSelectSpec(selectSpecJSON.toJSONString());
|
||||||
|
}
|
||||||
|
|
||||||
|
skuResult.setTagSnap(finalSnap.toJSONString());
|
||||||
}
|
}
|
||||||
it.setProductSkuResult(skuResult);
|
it.setProductSkuResult(skuResult);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 查询sku信息
|
// 查询sku信息
|
||||||
List<TbProductSku> skuWithBLOBs = tbProductSkuMapper.selectByProductCheckGrounding(it.getId());
|
List<TbProductSku> skuWithBLOBs = tbProductSkuMapper.selectByProductCheckGrounding(it.getId());
|
||||||
it.setSkuList(skuWithBLOBs);
|
it.setSkuList(skuWithBLOBs);
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
package com.chaozhanggui.system.cashierservice.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class WxAccountUtil {
|
||||||
|
@Value("${wx.ysk.appId}")
|
||||||
|
private static String appId = "wx212769170d2c6b2a";
|
||||||
|
@Value("${wx.ysk.secrete}")
|
||||||
|
private static String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0";
|
||||||
|
@Value("${wx.ysk.warnMsgTmpId}")
|
||||||
|
private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0";
|
||||||
|
|
||||||
|
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
|
||||||
|
linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口");
|
||||||
|
linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID");
|
||||||
|
linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口");
|
||||||
|
linkedHashMap.put("40037","不合法的 template_id");
|
||||||
|
linkedHashMap.put("43101","用户未订阅消息");
|
||||||
|
linkedHashMap.put("43107","订阅消息能力封禁");
|
||||||
|
linkedHashMap.put("43108","并发下发消息给同一个粉丝");
|
||||||
|
linkedHashMap.put("45168","命中敏感词");
|
||||||
|
linkedHashMap.put("47003","参数错误");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRadarQrCode(Integer shopId) {
|
||||||
|
HashMap<String, Object> req = new HashMap<>();
|
||||||
|
req.put("expire_seconds", 300);
|
||||||
|
req.put("action_name", "QR_STR_SCENE");
|
||||||
|
HashMap<Object, Object> actionInfo = new HashMap<>();
|
||||||
|
HashMap<String, Object> scene = new HashMap<>();
|
||||||
|
scene.put("scene_str", "msg" + shopId);
|
||||||
|
actionInfo.put("scene", scene);
|
||||||
|
req.put("action_info", actionInfo);
|
||||||
|
log.info("开始获取公众号二维码, 请求数据: {}", req);
|
||||||
|
String resp = HttpUtil.post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getAccessToken(), JSONObject.toJSONString(req));
|
||||||
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
|
log.warn("获取微信公众号二维码结束,响应: {}", resp);
|
||||||
|
if (!respInfo.containsKey("url")) {
|
||||||
|
log.warn("获取微信公众号二维码失败,响应: {}", resp);
|
||||||
|
throw new MsgException(resp);
|
||||||
|
}
|
||||||
|
return respInfo.getString("url");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getAccessToken() {
|
||||||
|
String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete));
|
||||||
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
|
if (!respInfo.containsKey("access_token")) {
|
||||||
|
log.warn("公众号获取token失败, 响应内容: {}", resp);
|
||||||
|
throw new MsgException(resp);
|
||||||
|
}
|
||||||
|
return respInfo.getString("access_token");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONObject sendTemplateMsg(String templateId, String toUserOpenId, Map<String, Object> data) {
|
||||||
|
log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||||
|
String accessToken = getAccessToken();
|
||||||
|
|
||||||
|
JSONObject object1=new JSONObject();
|
||||||
|
|
||||||
|
object1.put("template_id", templateId);
|
||||||
|
object1.put("touser", toUserOpenId);
|
||||||
|
object1.put("data",data);
|
||||||
|
|
||||||
|
String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
|
||||||
|
log.info("微信模板消息发送成功,响应内容:{}",response);
|
||||||
|
JSONObject resObj=JSONObject.parseObject(response);
|
||||||
|
if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){
|
||||||
|
return resObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONObject sendStockWarnMsg(String shopName, String productName, String stock, String toUserOpenId) {
|
||||||
|
Map<String, Object> data = new HashMap<String, Object>() {{
|
||||||
|
put("thing22", new HashMap<String, Object>(){{
|
||||||
|
put("value", shopName);
|
||||||
|
}});
|
||||||
|
put("thing4", new HashMap<String, Object>(){{
|
||||||
|
put("value", productName);
|
||||||
|
}});
|
||||||
|
put("number5", new HashMap<String, Object>(){{
|
||||||
|
put("value", stock);
|
||||||
|
}});
|
||||||
|
}};
|
||||||
|
log.info("开始发送库存预警消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||||
|
return sendTemplateMsg(msgTmpId, toUserOpenId, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,6 +51,11 @@ wx:
|
|||||||
secrete: c33e06467c6879a62af633d50ed6b720
|
secrete: c33e06467c6879a62af633d50ed6b720
|
||||||
warnMsgTmpId: IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY
|
warnMsgTmpId: IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY
|
||||||
|
|
||||||
|
ysk:
|
||||||
|
appId: wx212769170d2c6b2a
|
||||||
|
secrete: 8492a7e8d55bbb1b57f5c8276ea1add0
|
||||||
|
warnMsgTmpId: C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user