库存预警支持多账号订阅

This commit is contained in:
SongZhang 2024-07-02 16:13:24 +08:00
parent d35a5f2cc0
commit e31f3c831a
4 changed files with 312 additions and 12 deletions

View File

@ -0,0 +1,30 @@
package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbShopOpenId;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @author Administrator
* @description 针对表tb_shop_open_id(商家openid信息表)的数据库操作Mapper
* @createDate 2024-07-02 14:37:08
* @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 shop_id=#{shopId} and status=1")
List<TbShopOpenId> selectByShopId(Integer integer);
}

View File

@ -0,0 +1,176 @@
package com.chaozhanggui.system.cashierservice.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 商家openid信息表
* @TableName tb_shop_open_id
*/
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;
/**
*
*/
public Integer getId() {
return id;
}
/**
*
*/
public void setId(Integer id) {
this.id = id;
}
/**
* 店铺id
*/
public Integer getShopId() {
return shopId;
}
/**
* 店铺id
*/
public void setShopId(Integer shopId) {
this.shopId = shopId;
}
/**
* 已经订阅消息的商家微信号
*/
public String getOpenId() {
return openId;
}
/**
* 已经订阅消息的商家微信号
*/
public void setOpenId(String openId) {
this.openId = openId;
}
/**
*
*/
public Integer getStatus() {
return status;
}
/**
*
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
*
*/
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;
}
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

@ -25,7 +25,6 @@ import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.CARTEXIST;
@ -69,13 +68,16 @@ public class OrderService {
private final TbUserShopMsgMapper tbUserShopMsgMapper;
private final TbShopOpenIdMapper shopOpenIdMapper;
private static ConcurrentHashMap<String, HashSet<Integer>> codeMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, HashSet<String>> userMap = new ConcurrentHashMap<>();
public OrderService(WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper) {
public OrderService(WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper) {
this.wechatUtil = wechatUtil;
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
this.shopOpenIdMapper = shopOpenIdMapper;
}
@Transactional(rollbackFor = Exception.class)
@ -237,21 +239,20 @@ public class OrderService {
jsonObject.put("cartId",cart.getId());
jsonObject.put("type","create");
producer.cons(jsonObject.toString());
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(skuWithBLOBs, product, shopInfo));
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(skuWithBLOBs, product, shopInfo, number));
return Result.success(CodeEnum.SUCCESS, masterId);
}
/**
* 校验商品库存警戒线并通知商户
*
* @param productSku sku
*/
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, TbShopInfo shopInfo) {
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, TbShopInfo shopInfo, Integer num) {
if (productSku.getWarnLine() == null) {
return;
}
if (productSku.getStockNumber() == null) {
productSku.setStockNumber((double) 0);
}
@ -260,13 +261,15 @@ public class OrderService {
product.setStockNumber(0);
}
if (
(product.getIsDistribute() == 1 && productSku.getStockNumber() <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && product.getStockNumber() <= productSku.getWarnLine()
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
) {
TbUserShopMsg tbUserShopMsg = tbUserShopMsgMapper.selectByShopId(productSku.getShopId());
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
product.getIsDistribute() == 1 ? productSku.getStockNumber().toString() : product.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

@ -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>