1.推送增加店铺开关校验

This commit is contained in:
SongZhang 2024-08-12 14:35:27 +08:00
parent 86df7addd6
commit 22eadf7193
6 changed files with 308 additions and 4 deletions

View File

@ -0,0 +1,176 @@
package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName tb_shop_msg_state
*/
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;
/**
*
*/
public Integer getId() {
return id;
}
/**
*
*/
public void setId(Integer id) {
this.id = id;
}
/**
*
*/
public Integer getShopId() {
return shopId;
}
/**
*
*/
public void setShopId(Integer shopId) {
this.shopId = shopId;
}
/**
*
*/
public Integer getType() {
return type;
}
/**
*
*/
public void setType(Integer type) {
this.type = type;
}
/**
*
*/
public Integer getState() {
return state;
}
/**
*
*/
public void setState(Integer state) {
this.state = state;
}
/**
*
*/
public Date getCreateTime() {
return createTime;
}
/**
*
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
*
*/
public Date getUpdateTime() {
return updateTime;
}
/**
*
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
@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();
}
}

View File

@ -0,0 +1,29 @@
package com.chaozhanggui.system.cashierservice.mapper;
import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* @author Administrator
* @description 针对表tb_shop_msg_state的数据库操作Mapper
* @createDate 2024-08-12 14:27:26
* @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(@Param("type") Integer type, @Param("shopId") Integer shopId);
}

View File

@ -133,7 +133,7 @@ public class ConsMsgConsumer {
log.info("开始推送耗材模板消息rediskey{}", value);
if (Objects.isNull(value)) {
JSONObject jsonObject = wxAccountUtil.sendStockWarnMsg("耗材库存不足", tbConsInfo.getConName(),
tbConsInfo.getStockNumber().subtract(tbConsInfo.getStockConsume()).toBigInteger().intValue(), tbUserShopMsg.getOpenId());
tbConsInfo.getStockNumber().subtract(tbConsInfo.getStockConsume()).toBigInteger().intValue(), tbUserShopMsg.getOpenId(), ShopWxMsgTypeEnum.CONSUMABLES_MSG, shopId);
if (jsonObject != null) {
log.info("写入redis:{}",key);
redisUtil.saveMessage(key, "1", 30 * 60);

View File

@ -298,7 +298,7 @@ public class OrderService {
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
shopOpenIds.forEach(item -> {
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber()-num : (int) (productSku.getStockNumber() - num), item.getOpenId());
product.getIsDistribute() == 1 ? product.getStockNumber()-num : (int) (productSku.getStockNumber() - num), item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopId);
});
}
}

View File

@ -5,7 +5,10 @@ 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.bean.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;
@ -25,7 +28,7 @@ public class WxAccountUtil {
private static String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0";
@Value("${wx.ysk.warnMsgTmpId}")
private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0";
private final TbShopMsgStateMapper shopMsgStateMapper;
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
static {
@ -97,7 +100,12 @@ public class WxAccountUtil {
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
}
public 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<String, Object> data = new HashMap<String, Object>() {{

View File

@ -0,0 +1,91 @@
<?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.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="type" column="type" jdbcType="INTEGER"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,shop_id,type,
state,create_time,update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_shop_msg_state
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from tb_shop_msg_state
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState" useGeneratedKeys="true">
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>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState" useGeneratedKeys="true">
insert into tb_shop_msg_state
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="shopId != null">shop_id,</if>
<if test="type != null">type,</if>
<if test="state != null">state,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id,jdbcType=INTEGER},</if>
<if test="shopId != null">#{shopId,jdbcType=INTEGER},</if>
<if test="type != null">#{type,jdbcType=INTEGER},</if>
<if test="state != null">#{state,jdbcType=INTEGER},</if>
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
<if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
update tb_shop_msg_state
<set>
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=INTEGER},
</if>
<if test="state != null">
state = #{state,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopMsgState">
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}
</update>
</mapper>