Merge remote-tracking branch 'origin/dev'

This commit is contained in:
2024-08-05 11:26:41 +08:00
10 changed files with 67 additions and 32 deletions

View File

@@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -38,6 +40,7 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CommonController { public class CommonController {
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
private final ValidateCodeUtil validateCodeUtil; private final ValidateCodeUtil validateCodeUtil;
@Autowired @Autowired
@@ -205,7 +208,6 @@ public class CommonController {
redisUtil.getIncrNum(key, "2"); redisUtil.getIncrNum(key, "2");
} }
/** /**
* 订阅消息 * 订阅消息
* @param wxMsgSubDTO * @param wxMsgSubDTO
@@ -213,10 +215,13 @@ public class CommonController {
*/ */
@PostMapping("/subMsg") @PostMapping("/subMsg")
public Result subscribeWxAccount(@RequestBody WxMsgSubDTO wxMsgSubDTO) { public Result subscribeWxAccount(@RequestBody WxMsgSubDTO wxMsgSubDTO) {
log.info("接收到订阅消息接口调用,携带数据: {}", wxMsgSubDTO);
if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) { if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) {
return Result.fail("shopId或openId缺失"); return Result.fail("shopId或openId缺失");
} }
loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId()); String msg = wxMsgSubDTO.getShopId().replace("msg", "");
String[] split = msg.split(",");
loginService.addShopId(wxMsgSubDTO.getOpenId(), split[0], split.length > 1 ? Integer.valueOf(split[1]) : null);
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
} }

View File

@@ -26,8 +26,7 @@ public interface TbShopOpenIdMapper {
int updateByPrimaryKey(TbShopOpenId record); int updateByPrimaryKey(TbShopOpenId record);
@Select("select * from tb_shop_open_id where open_id=#{openId} and shop_id=#{shopId} limit 1") TbShopOpenId countByOpenId(@Param("openId") String openId, @Param("shopId") Integer shopId, @Param("type") Integer type);
TbShopOpenId countByOpenId(@Param("openId") String openId, @Param("shopId") Integer shopId);
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1") @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1")
List<TbShopOpenId> selectByShopId(@Param("shopId") Integer shopId); List<TbShopOpenId> selectByShopId(@Param("shopId") Integer shopId);

View File

@@ -6,4 +6,5 @@ import lombok.Data;
public class WxMsgSubDTO { public class WxMsgSubDTO {
private String shopId; private String shopId;
private String openId; private String openId;
private Integer type;
} }

View File

@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.service; package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.thread.ThreadUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@@ -30,6 +31,7 @@ import java.math.BigDecimal;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
/** /**
* @author lyf * @author lyf
@@ -461,6 +463,10 @@ public class CartService {
return; return;
} }
if (product.getIsStock() == null || product.getIsStock() != 1) {
return;
}
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(product.getShopId())); TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(product.getShopId()));
if (shopInfo == null) { if (shopInfo == null) {
log.info("商品库存预警发送失败店铺不存在店铺id{}", product.getShopId()); log.info("商品库存预警发送失败店铺不存在店铺id{}", product.getShopId());
@@ -844,17 +850,6 @@ public class CartService {
log.info("开始发送mq消息消耗耗材消息内容{}", jsonObject2); log.info("开始发送mq消息消耗耗材消息内容{}", jsonObject2);
producer.cons(jsonObject2.toString()); producer.cons(jsonObject2.toString());
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
// 发送判断耗材是否耗尽消息
JSONObject objectMsg = new JSONObject();
objectMsg.put("skuId", Integer.valueOf(cashierCart.getSkuId()));
objectMsg.put("shopId", Integer.valueOf(cashierCart.getShopId()));
producer.con_msg(objectMsg.toString());
}
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
orderInfo.setDetailList(orderDetails); orderInfo.setDetailList(orderDetails);
JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject1 = new JSONObject();
@@ -874,6 +869,18 @@ public class CartService {
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); // PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), jsonObject.getString("userId")); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), jsonObject.getString("userId"));
redisUtil.saveMessage(RedisCst.ORDER_EXPIRED.concat(orderId.toString()), orderId.toString(), 60 * 16L); redisUtil.saveMessage(RedisCst.ORDER_EXPIRED.concat(orderId.toString()), orderId.toString(), 60 * 16L);
ThreadUtil.execAsync(() -> {
ThreadUtil.sleep(5, TimeUnit.SECONDS);
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
// 发送判断耗材是否耗尽消息
JSONObject objectMsg = new JSONObject();
objectMsg.put("skuId", Integer.valueOf(cashierCart.getSkuId()));
objectMsg.put("shopId", Integer.valueOf(cashierCart.getShopId()));
producer.con_msg(objectMsg.toString());
}
});
} catch (Exception e) { } catch (Exception e) {

View File

@@ -4,7 +4,6 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisCst;
@@ -20,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
@@ -64,7 +62,7 @@ public class LoginService {
this.shopOpenIdMapper = shopOpenIdMapper; this.shopOpenIdMapper = shopOpenIdMapper;
} }
public void addShopId(String openId,String shopId) { public void addShopId(String openId, String shopId, Integer type) {
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId); TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
if(Objects.isNull(shopMsg)){ if(Objects.isNull(shopMsg)){
shopMsg=new TbUserShopMsg(); shopMsg=new TbUserShopMsg();
@@ -76,13 +74,17 @@ public class LoginService {
} }
// 为商家绑定openid // 为商家绑定openid
if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId)) == null) { TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), type);
if ( tbShopOpenId == null) {
TbShopOpenId shopOpenId = new TbShopOpenId(); TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId); shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date()); shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId)); shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(1); shopOpenId.setStatus(1);
shopOpenIdMapper.insert(shopOpenId); shopOpenIdMapper.insert(shopOpenId);
}else {
tbShopOpenId.setUpdateTime(DateUtil.date());
shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId);
} }
} }
@@ -95,17 +97,17 @@ public class LoginService {
shopMsg.setOpenId(openId); shopMsg.setOpenId(openId);
shopMsg.setCreateTime(new Date()); shopMsg.setCreateTime(new Date());
shopMsg.setStatus("1"); shopMsg.setStatus("1");
tbUserShopMsgMapper.insert(shopMsg); // tbUserShopMsgMapper.insert(shopMsg);
} }
// 为商家绑定openid // 为商家绑定openid
if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId)) == null) { if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), null) == null) {
TbShopOpenId shopOpenId = new TbShopOpenId(); TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId); shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date()); shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId)); shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(1); shopOpenId.setStatus(1);
shopOpenIdMapper.insert(shopOpenId); // shopOpenIdMapper.insert(shopOpenId);
} }
return Result.success(CodeEnum.SUCCESS,shopMsg); return Result.success(CodeEnum.SUCCESS,shopMsg);

View File

@@ -20,15 +20,20 @@ import com.chaozhanggui.system.cashierservice.util.*;
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil; import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -56,9 +61,12 @@ public class UserService {
private final WxAccountUtil wxAccountUtil; private final WxAccountUtil wxAccountUtil;
public UserService(FileService fileService, WxAccountUtil wxAccountUtil) { private final ResourceLoader resourceLoader;
public UserService(FileService fileService, WxAccountUtil wxAccountUtil, ResourceLoader resourceLoader) {
this.fileService = fileService; this.fileService = fileService;
this.wxAccountUtil = wxAccountUtil; this.wxAccountUtil = wxAccountUtil;
this.resourceLoader = resourceLoader;
} }
public JSONObject modityIntegral(IntegralVo integralVo, String userSign) { public JSONObject modityIntegral(IntegralVo integralVo, String userSign) {
@@ -254,8 +262,12 @@ public class UserService {
throw new MsgException("店铺不存在"); throw new MsgException("店铺不存在");
} }
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId)), new QrConfig(100, 100), "png", outputStream); Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg");
InputStream inputStream = resource.getInputStream();
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1), new QrConfig(500, 500).
setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream);
return fileService.uploadFileByInputStream(".png", new ByteArrayInputStream(outputStream.toByteArray()));
return fileService.uploadFileByInputStream("png", new ByteArrayInputStream(outputStream.toByteArray()));
} }
} }

View File

@@ -47,13 +47,13 @@ public class WxAccountUtil {
// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI"); // sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
} }
public static String getRadarQrCode(Integer shopId) { public static String getRadarQrCode(Integer shopId, Integer type) {
HashMap<String, Object> req = new HashMap<>(); HashMap<String, Object> req = new HashMap<>();
req.put("expire_seconds", 300); req.put("expire_seconds", 300);
req.put("action_name", "QR_STR_SCENE"); req.put("action_name", "QR_STR_SCENE");
HashMap<Object, Object> actionInfo = new HashMap<>(); HashMap<Object, Object> actionInfo = new HashMap<>();
HashMap<String, Object> scene = new HashMap<>(); HashMap<String, Object> scene = new HashMap<>();
scene.put("scene_str", "msg" + shopId); scene.put("scene_str", "msg" + shopId + "," + type);
actionInfo.put("scene", scene); actionInfo.put("scene", scene);
req.put("action_info", actionInfo); req.put("action_info", actionInfo);
log.info("开始获取公众号二维码, 请求数据: {}", req); log.info("开始获取公众号二维码, 请求数据: {}", req);

View File

@@ -24,6 +24,15 @@
from tb_shop_open_id from tb_shop_open_id
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<select id="countByOpenId" resultType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId">
select * from tb_shop_open_id
where open_id=#{openId}
and shop_id=#{shopId}
<if test="type != null">and type=#{type}</if>
limit 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from tb_shop_open_id delete from tb_shop_open_id

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB