库存预警支持多用户提醒

This commit is contained in:
2024-07-02 15:19:40 +08:00
parent ac3ef8d8d3
commit 57160c66c5
5 changed files with 246 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbShopOpenId;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @author Administrator
* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Mapper
* @createDate 2024-07-02 14:21:02
* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopOpenId
*/
public interface TbShopOpenIdMapper {
int deleteByPrimaryKey(Long id);
int insert(TbShopOpenId record);
int insertSelective(TbShopOpenId record);
TbShopOpenId selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(TbShopOpenId record);
int updateByPrimaryKey(TbShopOpenId record);
@Select("select * from tb_shop_open_id where open_id=#{openId}")
TbShopOpenId countByOpenId(@Param("openId") String openId);
@Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1")
List<TbShopOpenId> selectByShopId(@Param("shopId") Integer shopId);
}

View File

@@ -0,0 +1,94 @@
package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 商家openid信息表
* @TableName tb_shop_open_id
*/
@Data
public class TbShopOpenId implements Serializable {
/**
*
*/
private Integer id;
/**
* 店铺id
*/
private Integer shopId;
/**
* 已经订阅消息的商家微信号
*/
private String openId;
/**
*
*/
private Integer status;
/**
*
*/
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;
}
TbShopOpenId other = (TbShopOpenId) 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.getOpenId() == null ? other.getOpenId() == null : this.getOpenId().equals(other.getOpenId()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (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 + ((getOpenId() == null) ? 0 : getOpenId().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().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(", openId=").append(openId);
sb.append(", status=").append(status);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@@ -60,15 +60,18 @@ public class CartService {
private final TbUserShopMsgMapper tbUserShopMsgMapper;
private final WechatUtil wechatUtil;
private final TbShopOpenIdMapper shopOpenIdMapper;
@Autowired
private RabbitProducer producer;
@Qualifier("tbShopInfoMapper")
@Autowired
private TbShopInfoMapper tbShopInfoMapper;
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil) {
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, TbShopOpenIdMapper shopOpenIdMapper) {
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
this.wechatUtil = wechatUtil;
this.shopOpenIdMapper = shopOpenIdMapper;
}
public void initCart(JSONObject jsonObject) {
@@ -402,7 +405,7 @@ public class CartService {
redisUtil.getIncrNum(key, "2");
}
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product));
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, num));
}
@@ -410,7 +413,7 @@ public class CartService {
* 校验商品库存警戒线并通知商户
* @param productSku sku
*/
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product) {
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer num) {
if (productSku.getWarnLine() == null) {
return;
}
@@ -432,10 +435,12 @@ public class CartService {
(product.getIsDistribute() == 1 && product.getStockNumber() <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() <= productSku.getWarnLine()
) {
TbUserShopMsg tbUserShopMsg = tbUserShopMsgMapper.selectByShopId(productSku.getShopId());
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber().toString() : productSku.getStockNumber().toString(),
"耗材库存不足,请及时补充。", tbUserShopMsg.getOpenId());
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
shopOpenIds.forEach(item -> {
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber()-num) : String.valueOf(productSku.getStockNumber() - num),
"耗材库存不足,请及时补充。", item.getOpenId());
});
}
}

View File

@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
@@ -56,8 +57,11 @@ public class LoginService {
@Autowired
TbUserShopMsgMapper tbUserShopMsgMapper;
private final TbShopOpenIdMapper shopOpenIdMapper;
public LoginService(TbShopOpenIdMapper shopOpenIdMapper) {
this.shopOpenIdMapper = shopOpenIdMapper;
}
public Result wxBusinessLogin(String openId,String shopId){
@@ -69,13 +73,22 @@ public class LoginService {
shopMsg.setOpenId(openId);
shopMsg.setCreateTime(new Date());
shopMsg.setStatus("1");
tbUserShopMsgMapper.insert(shopMsg);
}else {
shopMsg.setOpenId(openId);
shopMsg.setUpdateTime(new Date());
tbUserShopMsgMapper.updateByPrimaryKey(shopMsg);
}
// 为商家绑定openid
if (shopOpenIdMapper.countByOpenId(openId) == null) {
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenIdMapper.insert(shopOpenId);
}
return Result.success(CodeEnum.SUCCESS,shopMsg);
}

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.dao.TbShopOpenIdMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="openId" column="open_id" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="TINYINT"/>
<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,open_id,
status,create_time,update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_shop_open_id
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from tb_shop_open_id
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId" useGeneratedKeys="true">
insert into tb_shop_open_id
( id,shop_id,open_id
,status,create_time,update_time
)
values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{openId,jdbcType=VARCHAR}
,#{status,jdbcType=TINYINT},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopOpenId" useGeneratedKeys="true">
insert into tb_shop_open_id
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="shopId != null">shop_id,</if>
<if test="openId != null">open_id,</if>
<if test="status != null">status,</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="openId != null">#{openId,jdbcType=VARCHAR},</if>
<if test="status != null">#{status,jdbcType=TINYINT},</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.TbShopOpenId">
update tb_shop_open_id
<set>
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER},
</if>
<if test="openId != null">
open_id = #{openId,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
</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.TbShopOpenId">
update tb_shop_open_id
set
shop_id = #{shopId,jdbcType=INTEGER},
open_id = #{openId,jdbcType=VARCHAR},
status = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>