Browse Source

定时提醒发送时报信息

yumeng 4 years ago
parent
commit
ef06477b85

+ 4 - 0
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -11,6 +11,7 @@ import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaishouAccountMaterialRepo
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyImageService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyImageService;
 import cn.com.ctop.oa.modules.service.IAppchatCreateService;
 import cn.com.ctop.oa.modules.service.IAppchatCreateService;
 import cn.com.ctop.oa.modules.service.IWechatNoListService;
 import cn.com.ctop.oa.modules.service.IWechatNoListService;
+import cn.com.ctop.oa.modules.service.IWechatUserListService;
 import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
 import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceCampaignService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceCampaignService;
@@ -51,10 +52,13 @@ public class SampleTest {
     private RedisUtil redisUtil;
     private RedisUtil redisUtil;
     @Autowired
     @Autowired
     private IAppchatCreateService appchatCreateService;
     private IAppchatCreateService appchatCreateService;
+    @Autowired
+    private IWechatUserListService wechatUserInfoService;
 
 
 
 
     @Test
     @Test
     public void loadKuaishouCookie() throws ParseException {
     public void loadKuaishouCookie() throws ParseException {
+        wechatUserInfoService.getUserList();
 
 
         // appchatCreateService.createAppChat(null, null, null);
         // appchatCreateService.createAppChat(null, null, null);
         appchatCreateService.getChatInfo(null);
         appchatCreateService.getChatInfo(null);

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/ICtopCorpWexinUserService.java

@@ -13,4 +13,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface ICtopCorpWexinUserService extends IService<CtopCorpWexinUser> {
 public interface ICtopCorpWexinUserService extends IService<CtopCorpWexinUser> {
 
 
     String getEmailByUserId(String userId);
     String getEmailByUserId(String userId);
+
+    CtopCorpWexinUser getInfoByUserId(String userId);
 }
 }

+ 11 - 2
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopCorpWexinUserServiceImpl.java

@@ -3,12 +3,12 @@ package cn.com.ctop.common.module.service.impl;
 import cn.com.ctop.common.module.entity.CtopCorpWexinUser;
 import cn.com.ctop.common.module.entity.CtopCorpWexinUser;
 import cn.com.ctop.common.module.mapper.CtopCorpWexinUserMapper;
 import cn.com.ctop.common.module.mapper.CtopCorpWexinUserMapper;
 import cn.com.ctop.common.module.service.ICtopCorpWexinUserService;
 import cn.com.ctop.common.module.service.ICtopCorpWexinUserService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Primary;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
 /**
 /**
  * 企业微信用户表
  * 企业微信用户表
  *
  *
@@ -27,4 +27,13 @@ public class CtopCorpWexinUserServiceImpl extends ServiceImpl<CtopCorpWexinUserM
     public String getEmailByUserId(String userId) {
     public String getEmailByUserId(String userId) {
         return ctopCorpWexinUserMapper.queryEmailByUserId(userId);
         return ctopCorpWexinUserMapper.queryEmailByUserId(userId);
     }
     }
+
+    @Override
+    public CtopCorpWexinUser getInfoByUserId(String userId) {
+        QueryWrapper<CtopCorpWexinUser> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("wexin_id", userId);
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        return this.getOne(queryWrapper);
+    }
 }
 }

+ 20 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/SendHourlyMessageJob.java

@@ -0,0 +1,20 @@
+package cn.com.ctop.job.bytedance.handler;
+
+import cn.com.ctop.oa.modules.service.IAppchatCreateService;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SendHourlyMessageJob {
+    @Autowired
+    private IAppchatCreateService appchatCreateService;
+
+    /**
+     * 出价预警
+     **/
+    @XxlJob("sendHourlyMessageJob")
+    public void execute() {
+        appchatCreateService.getChatInfo("wrSHhWEAAAhWApP92IL0nAuA9pQZ1W7w");
+    }
+}

+ 1 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/constant/QYWxConstant.java

@@ -21,6 +21,7 @@ public class QYWxConstant {
     public static final String APP_ROVAL_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovaldetail";  //获取审批申请详情
     public static final String APP_ROVAL_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovaldetail";  //获取审批申请详情
     public static final String APPCHAT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/create";  //创建群聊
     public static final String APPCHAT_CREATE = "https://qyapi.weixin.qq.com/cgi-bin/appchat/create";  //创建群聊
     public static final String APPCHAT_GET = "https://qyapi.weixin.qq.com/cgi-bin/appchat/get";  //创建群聊
     public static final String APPCHAT_GET = "https://qyapi.weixin.qq.com/cgi-bin/appchat/get";  //创建群聊
+    public static final String APPCHAT_SEND = "https://qyapi.weixin.qq.com/cgi-bin/appchat/send"; // 发送消息
 
 
     /**
     /**
      * 天津优容智汇 企业微信信息
      * 天津优容智汇 企业微信信息

+ 2 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/IWechatUserListService.java

@@ -17,5 +17,7 @@ public interface IWechatUserListService extends IService<WechatUserList> {
     void getYRUserList();
     void getYRUserList();
 
 
     List<WechatUserList> queryList(int dataType);
     List<WechatUserList> queryList(int dataType);
+
+    WechatUserList getInfoByUserId(String userId);
 }
 }
 
 

+ 50 - 9
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/AppchatCreateServiceImpl.java

@@ -1,5 +1,8 @@
 package cn.com.ctop.oa.modules.service.impl;
 package cn.com.ctop.oa.modules.service.impl;
 
 
+import cn.com.ctop.common.module.entity.CtopCorpWexinUser;
+import cn.com.ctop.common.module.service.ICtopCorpWexinUserService;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.oa.modules.constant.QYWxConstant;
 import cn.com.ctop.oa.modules.constant.QYWxConstant;
 import cn.com.ctop.oa.modules.service.IAppchatCreateService;
 import cn.com.ctop.oa.modules.service.IAppchatCreateService;
@@ -24,7 +27,8 @@ public class AppchatCreateServiceImpl implements IAppchatCreateService {
     private IWechatTokenService tokenService;
     private IWechatTokenService tokenService;
     @Autowired
     @Autowired
     private IWechatUserListService userListService;
     private IWechatUserListService userListService;
-
+    @Autowired
+    private ICtopCorpWexinUserService ctopCorpWexinUserService;
 
 
     @Override
     @Override
     public void createAppChat(String name, String owner, JSONArray userlist) {
     public void createAppChat(String name, String owner, JSONArray userlist) {
@@ -34,8 +38,6 @@ public class AppchatCreateServiceImpl implements IAppchatCreateService {
                 throw new Exception("获取token失败");
                 throw new Exception("获取token失败");
             }
             }
             System.err.println(qywxAccessToken);
             System.err.println(qywxAccessToken);
-
-
             JSONObject params = new JSONObject();
             JSONObject params = new JSONObject();
             params.put("name", "易车时报发送");
             params.put("name", "易车时报发送");
             params.put("owner", "qy01338f036d3ce902287758b529");
             params.put("owner", "qy01338f036d3ce902287758b529");
@@ -53,15 +55,54 @@ public class AppchatCreateServiceImpl implements IAppchatCreateService {
 
 
     @Override
     @Override
     public void getChatInfo(String chatid) {
     public void getChatInfo(String chatid) {
-
         Map<String, Object> qywxAccessToken = tokenService.getQYWXAccessToken();
         Map<String, Object> qywxAccessToken = tokenService.getQYWXAccessToken();
-        System.err.println(qywxAccessToken);
-
         TreeMap params = new TreeMap();
         TreeMap params = new TreeMap();
-
-        params.put("chatid", "wrSHhWEAAAhWApP92IL0nAuA9pQZ1W7w");
+        params.put("chatid", chatid);
         params.put("access_token", qywxAccessToken.get(ACCESS_TOKEN));
         params.put("access_token", qywxAccessToken.get(ACCESS_TOKEN));
         String resultStr = HttpUtils.httpGetRequest(QYWxConstant.APPCHAT_GET, null, params);
         String resultStr = HttpUtils.httpGetRequest(QYWxConstant.APPCHAT_GET, null, params);
-        System.err.println(resultStr);
+        JSONObject jsonObject = JSONObject.parseObject(resultStr);
+        if (Check.isNull(jsonObject)) {
+            return;
+        }
+        Integer errcode = jsonObject.getInteger("errcode");
+        if (errcode != 0) {
+            log.error("获取群聊信息返回code失败");
+            return;
+        }
+        JSONObject chat_info = jsonObject.getJSONObject("chat_info");
+        if (Check.isNull(chat_info)) {
+            return;
+        }
+        JSONArray userlist = chat_info.getJSONArray("userlist");
+        if (Check.isNull(userlist)) {
+            return;
+        }
+        StringBuilder text = new StringBuilder();
+        for (int i = 0; i < userlist.size(); i++) {
+            String userId = userlist.getString(i);
+            CtopCorpWexinUser userInfo = ctopCorpWexinUserService.getInfoByUserId(userId);
+            if (Check.isNull(userInfo)) {
+                continue;
+            }
+            if (userInfo.getWexinName().equals("于蒙蒙") || userInfo.getWexinName().equals("吴永前")) {
+                continue;
+            }
+            text.append("@" + userInfo.getWexinName());
+        }
+        text.append("\n");
+        text.append("\n");
+        text.append("请及时发送该时段易车时报!");
+        text.append("\n");
+        text.append("17点和22点必须提前10分钟准时发出!");
+        JSONObject postJson = new JSONObject();
+        postJson.put("chatid", chatid);
+        postJson.put("msgtype", "text");
+        JSONObject content = new JSONObject();
+        content.put("content", text);
+        postJson.put("text", content);
+        postJson.put("safe", 0);
+        String postStr = HttpUtils.httpPostRequestTest(QYWxConstant.APPCHAT_SEND + "?access_token=" + qywxAccessToken.get(ACCESS_TOKEN), postJson.toJSONString(), null);
+        log.info("定时发送消息返回结果:{}", postStr);
+
     }
     }
 }
 }

+ 10 - 0
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatUserListServiceImpl.java

@@ -11,6 +11,7 @@ import cn.com.ctop.oa.modules.service.IWechatTokenService;
 import cn.com.ctop.oa.modules.service.IWechatUserListService;
 import cn.com.ctop.oa.modules.service.IWechatUserListService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xxl.job.core.enums.NoEn;
 import com.xxl.job.core.enums.NoEn;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
@@ -138,4 +139,13 @@ public class WechatUserListServiceImpl extends ServiceImpl<WechatUserListMapper,
     public List<WechatUserList> queryList(int dataType) {
     public List<WechatUserList> queryList(int dataType) {
         return wechatUserListMapper.queryList(dataType);
         return wechatUserListMapper.queryList(dataType);
     }
     }
+
+    @Override
+    public WechatUserList getInfoByUserId(String userId) {
+        QueryWrapper<WechatUserList> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id", userId);
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        return this.getOne(queryWrapper);
+    }
 }
 }