diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java new file mode 100644 index 0000000..7afb82e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java @@ -0,0 +1,94 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + +/** + * + * @TableName tb_shop_msg_state + */ +@Data +public class TbShopMsgState implements Serializable { + /** + * + */ + private Integer id; + + /** + * + */ + private Integer shopId; + + /** + * + */ + private Integer type; + + /** + * + */ + private Integer state; + + /** + * + */ + private Date createTime; + + /** + * + */ + private Date updateTime; + + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + TbShopMsgState other = (TbShopMsgState) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) + && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) + && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); + result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); + result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", shopId=").append(shopId); + sb.append(", type=").append(type); + sb.append(", state=").append(state); + sb.append(", createTime=").append(createTime); + sb.append(", updateTime=").append(updateTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java new file mode 100644 index 0000000..10f7430 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java @@ -0,0 +1,28 @@ +package com.chaozhanggui.system.cashierservice.mapper; + +import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState; +import org.apache.ibatis.annotations.Select; + +/** +* @author Administrator +* @description 针对表【tb_shop_msg_state】的数据库操作Mapper +* @createDate 2024-08-12 14:38:33 +* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopMsgState +*/ +public interface TbShopMsgStateMapper { + + int deleteByPrimaryKey(Long id); + + int insert(TbShopMsgState record); + + int insertSelective(TbShopMsgState record); + + TbShopMsgState selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(TbShopMsgState record); + + int updateByPrimaryKey(TbShopMsgState record); + + @Select("select * from tb_shop_msg_state where shop_id=#{shopId} and type=#{type};") + TbShopMsgState selectByType(Integer type, Integer shopId); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 81409f7..2bdda19 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -341,9 +341,9 @@ public class CartService { shopOpenIds.forEach(item -> { String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId()); if (message == null) { - WxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), + wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num) - , item.getOpenId()); + , item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId()); redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L); }else { log.info("{}已在30分钟内推送过消息,跳过发送", item.getOpenId()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java index 35e9098..245130e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java @@ -6,7 +6,10 @@ import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum; +import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -27,6 +30,8 @@ public class WxAccountUtil { @Value("${wx.ysk.warnMsgTmpId}") private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0"; + private final TbShopMsgStateMapper shopMsgStateMapper; + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); static { @@ -98,7 +103,13 @@ public class WxAccountUtil { throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); } - public static JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId) { + public JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId, ShopWxMsgTypeEnum typeEnum, Integer shopId) { + TbShopMsgState shopMsgState = shopMsgStateMapper.selectByType(typeEnum.getType(), shopId); + if (shopMsgState == null || shopMsgState.getState().equals(0)) { + log.info("店铺未开启推送:{}", shopMsgState); + return null; + } + stock = stock < 0 ? 0 : stock; Integer finalStock = stock; Map data = new HashMap() {{ diff --git a/src/main/resources/mapper/TbShopMsgStateMapper.xml b/src/main/resources/mapper/TbShopMsgStateMapper.xml new file mode 100644 index 0000000..cd820c5 --- /dev/null +++ b/src/main/resources/mapper/TbShopMsgStateMapper.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + id,shop_id,type, + state,create_time,update_time + + + + + + delete from tb_shop_msg_state + where id = #{id,jdbcType=INTEGER} + + + insert into tb_shop_msg_state + ( id,shop_id,type + ,state,create_time,update_time + ) + values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{type,jdbcType=INTEGER} + ,#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP} + ) + + + insert into tb_shop_msg_state + + id, + shop_id, + type, + state, + create_time, + update_time, + + + #{id,jdbcType=INTEGER}, + #{shopId,jdbcType=INTEGER}, + #{type,jdbcType=INTEGER}, + #{state,jdbcType=INTEGER}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, + + + + update tb_shop_msg_state + + + shop_id = #{shopId,jdbcType=INTEGER}, + + + type = #{type,jdbcType=INTEGER}, + + + state = #{state,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_shop_msg_state + set + shop_id = #{shopId,jdbcType=INTEGER}, + type = #{type,jdbcType=INTEGER}, + state = #{state,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + +