添加耗材警告

This commit is contained in:
韩鹏辉
2024-07-05 10:20:09 +08:00
parent 781a4baa81
commit d772c63ee5
6 changed files with 79 additions and 55 deletions

View File

@@ -1,13 +1,10 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.dao.TbUserShopMsgMapper; import com.chaozhanggui.system.cashierservice.dao.TbUserShopMsgMapper;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
@@ -19,7 +16,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.*; import java.util.*;

View File

@@ -6,16 +6,18 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
@Component @Component
@Mapper @Mapper
public interface TbUserShopMsgMapper { public interface TbUserShopMsgMapper {
int deleteByPrimaryKey(Integer shopId); int deleteByPrimaryKey(Integer id);
int insert(TbUserShopMsg record); int insert(TbUserShopMsg record);
int insertSelective(TbUserShopMsg record); int insertSelective(TbUserShopMsg record);
TbUserShopMsg selectByPrimaryKey(Integer shopId); TbUserShopMsg selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(TbUserShopMsg record); int updateByPrimaryKeySelective(TbUserShopMsg record);
@@ -23,4 +25,7 @@ public interface TbUserShopMsgMapper {
@Select("select * from tb_user_shop_msg where shop_id=#{shopId}") @Select("select * from tb_user_shop_msg where shop_id=#{shopId}")
TbUserShopMsg selectByShopId(@Param("shopId") String shopId); TbUserShopMsg selectByShopId(@Param("shopId") String shopId);
}
List<TbUserShopMsg> selectByShopId(@Param("shopId") Integer shopId);
}

View File

@@ -4,6 +4,8 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
public class TbUserShopMsg implements Serializable { public class TbUserShopMsg implements Serializable {
private Integer id;
private Integer shopId; private Integer shopId;
private String openId; private String openId;
@@ -18,6 +20,14 @@ public class TbUserShopMsg implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getShopId() { public Integer getShopId() {
return shopId; return shopId;
} }

View File

@@ -116,48 +116,52 @@ public class ConsMsgConsumer {
String key = redisUtil.getMessage(RedisCst.ORDER_MESSAGE.concat(tbConsInfo.getShopId().toString()).concat("#").concat(tbConsInfo.getId().toString())); String key = redisUtil.getMessage(RedisCst.ORDER_MESSAGE.concat(tbConsInfo.getShopId().toString()).concat("#").concat(tbConsInfo.getId().toString()));
if (Objects.isNull(key)) { if (Objects.isNull(key)) {
TbUserShopMsg tbUserShopMsg = tbUserShopMsgMapper.selectByPrimaryKey(tbConsInfo.getShopId()); List<TbUserShopMsg> tbUserShopMsgs = tbUserShopMsgMapper.selectByShopId(tbConsInfo.getShopId());
if (Objects.nonNull(tbUserShopMsg) && Objects.nonNull(tbUserShopMsg.getOpenId())) { if (Objects.nonNull(tbUserShopMsgs) && tbUserShopMsgs.size()>0) {
JSONObject access_token = getAccessToken();
String accessToken = String.valueOf(access_token.get("access_token"));
JSONObject object1 = new JSONObject(); for (TbUserShopMsg tbUserShopMsg : tbUserShopMsgs) {
JSONObject access_token = getAccessToken();
String accessToken = String.valueOf(access_token.get("access_token"));
object1.put("template_id", "IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY"); JSONObject object1 = new JSONObject();
object1.put("touser", tbUserShopMsg.getOpenId());
object1.put("template_id", "IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY");
object1.put("touser", tbUserShopMsg.getOpenId());
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
JSONObject thing1 = new JSONObject(); JSONObject thing1 = new JSONObject();
thing1.put("value", shopInfo.getShopName()); thing1.put("value", shopInfo.getShopName());
JSONObject thing5 = new JSONObject(); JSONObject thing5 = new JSONObject();
thing5.put("value", "耗材库存不足,请及时补充。"); thing5.put("value", "耗材库存不足,请及时补充。");
JSONObject thing6 = new JSONObject(); JSONObject thing6 = new JSONObject();
thing6.put("value", product.getName()); thing6.put("value", product.getName());
JSONObject thing7 = new JSONObject(); JSONObject thing7 = new JSONObject();
thing7.put("value", tbConsInfo.getStockNumber().toPlainString()); thing7.put("value", tbConsInfo.getStockNumber().toPlainString());
data.put("thing1", thing1); data.put("thing1", thing1);
data.put("thing6", thing6); data.put("thing6", thing6);
data.put("number7", thing7); data.put("number7", thing7);
data.put("thing5", thing5); data.put("thing5", thing5);
object1.put("data", data); object1.put("data", data);
object1.put("miniprogram_state", miniprogramState); object1.put("miniprogram_state", miniprogramState);
object1.put("lang", "zh_CN"); object1.put("lang", "zh_CN");
String response = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); String response = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
log.info("返回结果:{}", response); log.info("返回结果:{}", response);
JSONObject resObj = JSONObject.parseObject(response); JSONObject resObj = JSONObject.parseObject(response);
if (ObjectUtil.isNotEmpty(resObj) && ObjectUtil.isNotNull(resObj) && "0".equals(String.valueOf(resObj.get("errcode")))) { if (ObjectUtil.isNotEmpty(resObj) && ObjectUtil.isNotNull(resObj) && "0".equals(String.valueOf(resObj.get("errcode")))) {
redisUtil.saveMessage(key, object1.toString(),10*60*1000); redisUtil.saveMessage(key, object1.toString(),10*60*1000);
}
} }
} }
} }

View File

@@ -52,14 +52,8 @@
<!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名--> <!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<!-- <table tableName="%" schema="fycashier" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table>--> <!-- <table tableName="%" schema="fycashier" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table>-->
<table tableName="tb_cons_info" domainObjectName="TbConsInfo"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="tb_user_shop_msg" domainObjectName="TbUserShopMsg"
<table tableName="tb_prosku_con" domainObjectName="TbProskuCon"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" > enableSelectByExample="false" selectByExampleQueryId="false" >
</table> </table>

View File

@@ -2,7 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!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.TbUserShopMsgMapper"> <mapper namespace="com.chaozhanggui.system.cashierservice.dao.TbUserShopMsgMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg"> <resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg">
<id column="shop_id" jdbcType="INTEGER" property="shopId" /> <id column="id" jdbcType="INTEGER" property="id" />
<result column="shop_id" jdbcType="INTEGER" property="shopId" />
<result column="open_id" jdbcType="VARCHAR" property="openId" /> <result column="open_id" jdbcType="VARCHAR" property="openId" />
<result column="remark" jdbcType="VARCHAR" property="remark" /> <result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="status" jdbcType="VARCHAR" property="status" /> <result column="status" jdbcType="VARCHAR" property="status" />
@@ -10,29 +11,32 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
shop_id, open_id, remark, status, create_time, update_time id, shop_id, open_id, remark, status, create_time, update_time
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from tb_user_shop_msg from tb_user_shop_msg
where shop_id = #{shopId,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tb_user_shop_msg delete from tb_user_shop_msg
where shop_id = #{shopId,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg"> <insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg">
insert into tb_user_shop_msg (shop_id, open_id, remark, insert into tb_user_shop_msg (id, shop_id, open_id,
status, create_time, update_time remark, status, create_time,
) update_time)
values (#{shopId,jdbcType=INTEGER}, #{openId,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, values (#{id,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{openId,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP} #{remark,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
) #{updateTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg"> <insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg">
insert into tb_user_shop_msg insert into tb_user_shop_msg
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="shopId != null"> <if test="shopId != null">
shop_id, shop_id,
</if> </if>
@@ -53,6 +57,9 @@
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="shopId != null"> <if test="shopId != null">
#{shopId,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER},
</if> </if>
@@ -76,6 +83,9 @@
<update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg"> <update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg">
update tb_user_shop_msg update tb_user_shop_msg
<set> <set>
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER},
</if>
<if test="openId != null"> <if test="openId != null">
open_id = #{openId,jdbcType=VARCHAR}, open_id = #{openId,jdbcType=VARCHAR},
</if> </if>
@@ -92,15 +102,20 @@
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
</if> </if>
</set> </set>
where shop_id = #{shopId,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg"> <update id="updateByPrimaryKey" parameterType="com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg">
update tb_user_shop_msg update tb_user_shop_msg
set open_id = #{openId,jdbcType=VARCHAR}, set shop_id = #{shopId,jdbcType=INTEGER},
open_id = #{openId,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR}, remark = #{remark,jdbcType=VARCHAR},
status = #{status,jdbcType=VARCHAR}, status = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP} update_time = #{updateTime,jdbcType=TIMESTAMP}
where shop_id = #{shopId,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</update> </update>
<select id="selectByShopId" resultMap="BaseResultMap">
select * from tb_user_shop_msg where shop_id=#{shopId}
</select>
</mapper> </mapper>