修改耗材库存
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
package com.chaozhanggui.system.cashierservice.task;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbConsInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbUserShopMsgMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbConsInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg;
|
||||
import com.chaozhanggui.system.cashierservice.util.HttpClientUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.N;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ConsInfoTask {
|
||||
|
||||
private ScheduledExecutorService executorService=Executors.newScheduledThreadPool(100);
|
||||
|
||||
|
||||
@Value("${wx.appId}")
|
||||
private String appId;
|
||||
|
||||
|
||||
@Value("${wx.secrete}")
|
||||
private String secrete;
|
||||
|
||||
|
||||
@Autowired
|
||||
TbConsInfoMapper tbConsInfoMapper;
|
||||
|
||||
@Autowired
|
||||
TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||
|
||||
|
||||
|
||||
public void init(){
|
||||
executorService.scheduleWithFixedDelay(timerTask(),0,10,TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
|
||||
public TimerTask timerTask () {
|
||||
return new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<TbConsInfo> tbShopInfos= tbConsInfoMapper.selectAllInfo();
|
||||
if(Objects.nonNull(tbShopInfos)&&tbShopInfos.size()>0){
|
||||
tbShopInfos.parallelStream().forEach(it->{
|
||||
|
||||
if(N.gt(it.getConWarning(),it.getStockNumber())){
|
||||
TbUserShopMsg tbUserShopMsg=tbUserShopMsgMapper.selectByPrimaryKey(it.getShopId());
|
||||
if(Objects.nonNull(tbUserShopMsg)&&Objects.nonNull(tbUserShopMsg.getOpenId())){
|
||||
JSONObject object= getAccessToken();
|
||||
String accessToken=object.get("access_token")+"";
|
||||
|
||||
JSONObject object1=new JSONObject();
|
||||
|
||||
object1.put("template_id","BKTcsYHW1xnUaE-CFmF7pOglJH0aLEyW9e4r5nWKUIU");
|
||||
object1.put("touser",tbUserShopMsg.getOpenId());
|
||||
|
||||
|
||||
JSONObject data=new JSONObject();
|
||||
|
||||
JSONObject tabname=new JSONObject();
|
||||
tabname.put("value",it.getConName());
|
||||
|
||||
|
||||
JSONObject thing21=new JSONObject();
|
||||
thing21.put("value",it.getStockNumber().toPlainString());
|
||||
|
||||
JSONObject thing8=new JSONObject();
|
||||
thing8.put("value","耗材库存不足,请及时补充。");
|
||||
|
||||
data.put("thing1.",tabname);
|
||||
data.put("thing2",thing21);
|
||||
data.put("thing3",thing8);
|
||||
|
||||
object1.put("data",data);
|
||||
|
||||
object1.put("miniprogram_state","trial");
|
||||
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();
|
||||
log.info("返回结果:{}",response);
|
||||
JSONObject resObj=JSONObject.parseObject(response);
|
||||
if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
JSONObject getAccessToken(){
|
||||
String requestUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
Map<String, String> requestUrlParam = new HashMap<>();
|
||||
//小程序appId
|
||||
requestUrlParam.put("appid", appId);
|
||||
//小程序secret
|
||||
requestUrlParam.put("secret", secrete);
|
||||
//默认参数
|
||||
requestUrlParam.put("grant_type", "client_credential");
|
||||
JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(requestUrl,requestUrlParam));
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user