Quellcode durchsuchen

骄阳系统合并

yumeng vor 4 Jahren
Ursprung
Commit
e6bcf50fa8
21 geänderte Dateien mit 345 neuen und 120 gelöschten Zeilen
  1. 22 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java
  2. 7 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/BidWarningServiceImpl.java
  3. 6 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CpaBidWarningServiceImpl.java
  4. 19 17
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/orderplatform/util/ApprovalNodeNoticeHandler.java
  5. 17 11
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java
  6. 27 23
      module-check/src/main/java/cn/com/ctop/notice/handler/SendWeChatHandle.java
  7. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/CtopCorpWexinUser.java
  8. 86 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/WexinConfig.java
  9. 4 3
      module-common/src/main/java/cn/com/ctop/common/module/mapper/MailLogMapper.java
  10. 15 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/WexinConfigMapper.java
  11. 6 6
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MailLogMapper.xml
  12. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/WexinConfigMapper.xml
  13. 16 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IWexinConfigService.java
  14. 7 4
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MailLogServiceImpl.java
  15. 6 2
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/SendMessageServiceImpl.java
  16. 29 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/WexinConfigServiceImpl.java
  17. 45 31
      module-common/src/main/java/cn/com/ctop/common/module/utils/CorpWexinUtils.java
  18. 7 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/AccountWarningServiceImpl.java
  19. 6 3
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/material/service/impl/KuaishouBidWarningServiceImpl.java
  20. 6 3
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/BytedanceBidWarningServiceImpl.java
  21. 7 4
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ByteDanceHourlyAccountWarningServiceImpl.java

+ 22 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.common.module.entity.*;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.common.module.mapper.MailLogMapper;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.*;
@@ -131,6 +132,10 @@ public class TestController {
     private IKuaiShouCreativeService creativeService;
     @Autowired
     private IKuaiShouGroupService groupService;
+    @Autowired
+    private MailLogMapper mailLogMapper;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
     @Autowired
     private IBatchService batchService;
@@ -141,6 +146,18 @@ public class TestController {
     @Value("${xxl-job.requestUrl}")
     private String jobUrl;
 
+    @GetMapping("/testSend")
+    public void testSend(String userId) {
+
+        JSONObject weChatId = mailLogMapper.getWChatIdByUserId(userId);
+        if (weChatId.isEmpty()) {
+            log.error(String.format("User WeChat not found. userId =%s", userId));
+            //TODO 通知管理员添加邮箱
+        } else {
+            corpWexinUtils.sendMessageByWeChatId(weChatId, "hahahahahahah");
+        }
+    }
+
     @GetMapping("/uploadVideo")
     public String uploadVideo(Long projectId) {
 
@@ -1460,6 +1477,7 @@ public class TestController {
     @Autowired
     private IKuaishouStrategyService kuaishouStrategyService;
     static ExecutorService executorServic1e = Executors.newFixedThreadPool(5);
+
     /**
      * 勿动勿删,煜一人群报表数据拉取接口。
      *
@@ -1542,6 +1560,7 @@ public class TestController {
         ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
         return result;
     }
+
     @Autowired
     private IBytedanceCheckReportTaskInfoService checkReportTaskInfoService;
 
@@ -1557,9 +1576,9 @@ public class TestController {
     @GetMapping("testCheckCost")
     public Map<String, Object> testCheckCost(String date) throws ParseException {
         Map<String, Object> result = new HashMap<>();
-        List<BytedanceCheckReportTaskInfo>taskInfos = checkReportTaskInfoService.getListByParams(null,"2021-06-01",0);
-        if(null!=taskInfos&&!taskInfos.isEmpty()){
-            for (BytedanceCheckReportTaskInfo taskInfo:taskInfos) {
+        List<BytedanceCheckReportTaskInfo> taskInfos = checkReportTaskInfoService.getListByParams(null, "2021-06-01", 0);
+        if (null != taskInfos && !taskInfos.isEmpty()) {
+            for (BytedanceCheckReportTaskInfo taskInfo : taskInfos) {
                 checkReportTaskInfoService.checkCost(taskInfo);
             }
         }

+ 7 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/BidWarningServiceImpl.java

@@ -13,6 +13,7 @@ import cn.com.ctop.common.module.utils.SendMailUtil;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
@@ -42,6 +43,8 @@ public class BidWarningServiceImpl implements IBidWarningService {
     private MailLogMapper mailLogMapper;
     @Autowired
     private IByteDanceAdvertisePlanService byteDanceAdvertisePlanService;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
 
     /**
@@ -62,7 +65,7 @@ public class BidWarningServiceImpl implements IBidWarningService {
                     }
                     Long maxBid = project.getMaxBid();
                     Long projectId = project.getId();
-                    List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId,null,null);
+                    List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId, null, null);
                     if (!Check.isNull(userAllocations)) {
                         for (UserAllocation userAllocation : userAllocations) {
                             if (userAllocation.getAccountStatus() == 1) {
@@ -91,6 +94,7 @@ public class BidWarningServiceImpl implements IBidWarningService {
             e.printStackTrace();
         }
     }
+
     private void sendMessage(String mediaId, Long accountId, Long projectId, String projectName, String authName, List<String> unitWarning, Long maxBid) {
         String createTime = DateUtils.getNowDate("yyyy-MM-dd");
         Integer count = mailLogMapper.selectCountByAccountIdAndDate(accountId, createTime, 1);
@@ -125,8 +129,8 @@ public class BidWarningServiceImpl implements IBidWarningService {
             }
         }
 
-        List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-        CorpWexinUtils.sendMessage(wexinIds, text.toString());
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        corpWexinUtils.sendMessage(wexinIds, text.toString());
     }
 
 

+ 6 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CpaBidWarningServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.ctop.common.module.utils.SendMailUtil;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.service.ICpaBidWarningService;
@@ -37,6 +38,8 @@ public class CpaBidWarningServiceImpl implements ICpaBidWarningService {
     private MailLogMapper mailLogMapper;
     @Autowired
     private IByteDanceAdvertisePlanService byteDanceAdvertisePlanService;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
     /**
      * 预警
@@ -45,7 +48,7 @@ public class CpaBidWarningServiceImpl implements ICpaBidWarningService {
     public void cpaBidWarning(Project project) {
         try {
             BigDecimal maxDeepCpaBid = project.getMaxDeepCpaBid();
-            List<UserAllocation> userAllocations = userAllocationService.getByParams(project.getId(),null,null);
+            List<UserAllocation> userAllocations = userAllocationService.getByParams(project.getId(), null, null);
             if (!Check.isNull(userAllocations)) {
                 for (UserAllocation userAllocation : userAllocations) {
                     if (userAllocation.getAccountStatus() == 1) {
@@ -109,8 +112,8 @@ public class CpaBidWarningServiceImpl implements ICpaBidWarningService {
             }
         }
 
-        List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-        CorpWexinUtils.sendMessage(wexinIds, text.toString());
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        corpWexinUtils.sendMessage(wexinIds, text.toString());
     }
 
 

+ 19 - 17
jeecg-boot-module-system/src/main/java/org/jeecg/modules/orderplatform/util/ApprovalNodeNoticeHandler.java

@@ -21,18 +21,20 @@ public class ApprovalNodeNoticeHandler {
 
     @Autowired
     IPlatformMaterialService platformMaterialService;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
     /**
-     *  企业微信通知
+     * 企业微信通知
      */
-    public void NOTICE_WE_CHAT_ORDER(String operate, String orderCode){
-        Map<String, JSONObject> relatePerson=relatePerson(orderCode,null);
-        message(operate,null, relatePerson.get("orderRelatePerson"));
+    public void NOTICE_WE_CHAT_ORDER(String operate, String orderCode) {
+        Map<String, JSONObject> relatePerson = relatePerson(orderCode, null);
+        message(operate, null, relatePerson.get("orderRelatePerson"));
     }
 
-    public void NOTICE_WE_CHAT_MATERIAL(String operate, String materialCode){
-        Map<String, JSONObject> relatePerson=relatePerson(null,materialCode);
-        message(operate,relatePerson.get("materialRelatePerson"),null);
+    public void NOTICE_WE_CHAT_MATERIAL(String operate, String materialCode) {
+        Map<String, JSONObject> relatePerson = relatePerson(null, materialCode);
+        message(operate, relatePerson.get("materialRelatePerson"), null);
     }
 
     /**
@@ -40,7 +42,7 @@ public class ApprovalNodeNoticeHandler {
      */
     private Map<String, JSONObject> relatePerson(String orderCode, String materialCode) {
         Map<String, JSONObject> result = new HashMap<>();
-        if (null==materialCode) {
+        if (null == materialCode) {
             result.put("orderRelatePerson", platformMaterialService.getOrderRelatePersonByMaterialCode(orderCode));
         } else {
             result.put("materialRelatePerson", platformMaterialService.getMaterialRelatePersonByMaterialCode(materialCode));
@@ -166,12 +168,12 @@ public class ApprovalNodeNoticeHandler {
      */
     private void sendWeChat(Set<String> users, String message) {
         users.forEach(userId -> {
-            String weChatId = mailLogMapper.getWChatIdByUserId(userId);
+            JSONObject weChatId = mailLogMapper.getWChatIdByUserId(userId);
             if (weChatId.isEmpty()) {
                 log.error(String.format("User WeChat not found. userId =%s", userId));
                 //TODO 通知管理员添加邮箱
             } else {
-                CorpWexinUtils.sendMessageByWeChatId(weChatId, message);
+                corpWexinUtils.sendMessageByWeChatId(weChatId, message);
             }
         });
     }
@@ -180,12 +182,12 @@ public class ApprovalNodeNoticeHandler {
      * 发送通知消息到多人企业微信
      */
     private void sendWeChat(String userId, String message) {
-            String weChatId = mailLogMapper.getWChatIdByUserId(userId);
-            if (weChatId.isEmpty()) {
-                log.error(String.format("User WeChat not found. userId =%s", userId));
-                //TODO 通知管理员添加邮箱
-            } else {
-                CorpWexinUtils.sendMessageByWeChatId(weChatId, message);
-            }
+        JSONObject weChatId = mailLogMapper.getWChatIdByUserId(userId);
+        if (weChatId.isEmpty()) {
+            log.error(String.format("User WeChat not found. userId =%s", userId));
+            //TODO 通知管理员添加邮箱
+        } else {
+            corpWexinUtils.sendMessageByWeChatId(weChatId, message);
+        }
     }
 }

+ 17 - 11
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java

@@ -1,11 +1,9 @@
 package org.jeecg.modules.system.controller;
 
-import cn.com.ctop.common.module.entity.CorpFeishuUser;
-import cn.com.ctop.common.module.entity.CtopCorpWexinUser;
-import cn.com.ctop.common.module.entity.SysDepart;
-import cn.com.ctop.common.module.entity.SysUser;
+import cn.com.ctop.common.module.entity.*;
 import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.AesEncryptUtil;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.ResultMapUtils;
 import cn.com.ctop.common.module.utils.StatusCode;
 import cn.com.feishu.provider.AuthProvider;
@@ -69,6 +67,8 @@ public class LoginController {
     private ICorpFeishuUserService corpFeishuUserService;
     @Autowired
     private ICtopCorpWexinUserService ctopCorpWexinUserService;
+    @Autowired
+    private IWexinConfigService wexinConfigService;
     private static final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
 
     @GetMapping("feishu/url")
@@ -152,18 +152,23 @@ public class LoginController {
         }
     }
 
+
     @RequestMapping(value = "/wxlogin", method = RequestMethod.POST)
     @ApiOperation("企业微信登录接口")
-    public Result<JSONObject> wxlogin(@RequestParam(name = "code") String code) throws Exception {
+    public Result<JSONObject> wxlogin(@RequestParam(name = "code") String code, @RequestParam(name = "corpId") String corpId) throws Exception {
         Result<JSONObject> result = new Result<>();
+        WexinConfig wexinConfig = wexinConfigService.getInfoByCorpId(corpId);
+        if (Check.isNull(wexinConfig)) {
+            result.error500("未找到用户配置,请联系管理员");
+            return result;
+        }
         val configStorage = new WxCpDefaultConfigImpl();
-        configStorage.setCorpId("ww24b8a47826f5875f");
-        configStorage.setAgentId(1000002);
-        configStorage.setCorpSecret("MJIlySADGPlgvADnkFQPUpfZD4yV-4WN6066OgNnb0s");
-        configStorage.setToken("hcst2019");
-        configStorage.setAesKey("hcst2019");
+        configStorage.setCorpId(wexinConfig.getCorpId());
+        configStorage.setAgentId(wexinConfig.getAgentId());
+        configStorage.setCorpSecret(wexinConfig.getCorpSecret());
+        configStorage.setToken(wexinConfig.getToken());
+        configStorage.setAesKey(wexinConfig.getAesKey());
         val service = new WxCpServiceImpl();
-
         service.setWxCpConfigStorage(configStorage);
         WxCpOAuth2Service wxCpOAuth2Service = service.getOauth2Service();
         try {
@@ -193,6 +198,7 @@ public class LoginController {
                 CtopCorpWexinUser ctopCorpWexinUser = ctopCorpWexinUserService.getById(sysUser.getId());
                 if (ctopCorpWexinUser == null) {
                     ctopCorpWexinUser = new CtopCorpWexinUser();
+                    ctopCorpWexinUser.setCorpId(corpId);
                     ctopCorpWexinUser.setUserId(sysUser.getId());
                     ctopCorpWexinUser.setWexinEmail(user.getEmail());
                     ctopCorpWexinUser.setWexinGender(user.getGender().getGenderName());

+ 27 - 23
module-check/src/main/java/cn/com/ctop/notice/handler/SendWeChatHandle.java

@@ -2,6 +2,7 @@ package cn.com.ctop.notice.handler;
 
 import cn.com.ctop.common.module.mapper.MailLogMapper;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -16,43 +17,46 @@ public class SendWeChatHandle {
 
     @Autowired
     MailLogMapper mailLogMapper;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
-    public void sendWeChatByMail(String mail,String message){
-        String weChatId=mailLogMapper.getWeChatByMail(mail);
-        if(weChatId.isEmpty()){
-        log.error(String.format("mail's WeChat not found. mail =%s", mail));
-        //TODO 通知管理员添加邮箱
-    }else{
-        List<String> messageList= splitMessage(message);
-        messageList.forEach(it->CorpWexinUtils.sendMessageByWeChatId(weChatId,it));
+    public void sendWeChatByMail(String mail, String message) {
+        JSONObject weChatId = mailLogMapper.getWeChatByMail(mail);
+        if (weChatId.isEmpty()) {
+            log.error(String.format("mail's WeChat not found. mail =%s", mail));
+            //TODO 通知管理员添加邮箱
+        } else {
+            List<String> messageList = splitMessage(message);
+            messageList.forEach(it -> corpWexinUtils.sendMessageByWeChatId(weChatId, it));
+        }
     }
-}
 
     /**
      * 发送多人,邮箱逗号隔开
+     *
      * @param mails
      * @param message
      */
-    public void sendWeChatByMails(String mails,String message){
-        List<String> mail= Arrays.asList(mails.split(","));
-        mail.forEach(m-> this.sendWeChatByMail(m,message));
+    public void sendWeChatByMails(String mails, String message) {
+        List<String> mail = Arrays.asList(mails.split(","));
+        mail.forEach(m -> this.sendWeChatByMail(m, message));
     }
 
     /**
-     *  消息切割
+     * 消息切割
      */
-    private List<String> splitMessage(String message){
-        List<String> messageList=new ArrayList<>();
-        if(message.length()>1006){
-            int number=message.length()/1006;
-            for(int i=0;i<number;i++){
-                if(i!=number-1){
-                    messageList.add(message.substring(i*1006,(i+1)*1006-1));
-                }else {
-                    messageList.add(message.substring((i+1)*1006));
+    private List<String> splitMessage(String message) {
+        List<String> messageList = new ArrayList<>();
+        if (message.length() > 1006) {
+            int number = message.length() / 1006;
+            for (int i = 0; i < number; i++) {
+                if (i != number - 1) {
+                    messageList.add(message.substring(i * 1006, (i + 1) * 1006 - 1));
+                } else {
+                    messageList.add(message.substring((i + 1) * 1006));
                 }
             }
-        }else {
+        } else {
             messageList.add(message);
         }
         return messageList;

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/CtopCorpWexinUser.java

@@ -37,6 +37,7 @@ public class CtopCorpWexinUser {
     @Excel(name = "userId", width = 15)
     @ApiModelProperty(value = "userId")
     private String userId;
+
     /**
      * wexinId
      */
@@ -67,6 +68,7 @@ public class CtopCorpWexinUser {
     @Excel(name = "wexinGender", width = 15)
     @ApiModelProperty(value = "wexinGender")
     private String wexinGender;
+    private String corpId;
     /**
      * createTime
      */

+ 86 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/WexinConfig.java

@@ -0,0 +1,86 @@
+package cn.com.ctop.common.module.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import me.chanjar.weixin.cp.api.WxCpService;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-06-17
+ */
+@Data
+@TableName("ctop_wexin_config")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_wexin_config对象", description = "企业微信配置信息")
+public class WexinConfig {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.UUID)
+    @ApiModelProperty(value = "id")
+    private Integer id;
+    /**
+     * corpId
+     */
+    @Excel(name = "corpId", width = 15)
+    @ApiModelProperty(value = "corpId")
+    private String corpId;
+    /**
+     * agentId
+     */
+    @Excel(name = "agentId", width = 15)
+    @ApiModelProperty(value = "agentId")
+    private Integer agentId;
+    /**
+     * corpSecret
+     */
+    @Excel(name = "corpSecret", width = 15)
+    @ApiModelProperty(value = "corpSecret")
+    private String corpSecret;
+    /**
+     * aesKey
+     */
+    @Excel(name = "aesKey", width = 15)
+    @ApiModelProperty(value = "aesKey")
+    private String aesKey;
+    /**
+     * token
+     */
+    @Excel(name = "token", width = 15)
+    @ApiModelProperty(value = "token")
+    private String token;
+    /**
+     * remarks
+     */
+    @Excel(name = "remarks", width = 15)
+    @ApiModelProperty(value = "remarks")
+    private String remarks;
+    /**
+     * createTime
+     */
+    @ApiModelProperty(value = "createTime")
+    private Date createTime;
+    /**
+     * updateTime
+     */
+    @ApiModelProperty(value = "updateTime")
+    private Date updateTime;
+
+    @TableField(exist = false)
+    private WxCpService wxCpService;
+}

+ 4 - 3
module-common/src/main/java/cn/com/ctop/common/module/mapper/MailLogMapper.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.MailLog;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -19,11 +20,11 @@ public interface MailLogMapper extends BaseMapper<MailLog> {
 
     List<String> selectMailList(@Param("projectId") Long projectId);
 
-    List<String> selectWeiXinIdList(@Param("projectId") Long projectId);
+    List<JSONObject> selectWeiXinIdList(@Param("projectId") Long projectId);
 
-    String getWChatIdByUserId(@Param("userId") String responsibleId);
+    JSONObject getWChatIdByUserId(@Param("userId") String responsibleId);
 
     String getUserNameByUserId(@Param("userId") String transferor);
 
-    String getWeChatByMail(@Param("mail") String mail);
+    JSONObject getWeChatByMail(@Param("mail") String mail);
 }

+ 15 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/WexinConfigMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.common.module.mapper;
+
+import cn.com.ctop.common.module.entity.WexinConfig;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * 2021-06-17
+ * @version V1.0
+ */
+public interface WexinConfigMapper extends BaseMapper<WexinConfig> {
+
+}

+ 6 - 6
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MailLogMapper.xml

@@ -27,9 +27,9 @@
     </select>
 
 
-    <select id="selectWeiXinIdList" resultType="java.lang.String">
+    <select id="selectWeiXinIdList" resultType="com.alibaba.fastjson.JSONObject">
      select
-     t2.wexin_id
+     t2.wexin_id,t2.corp_id
      from
      ctop_project_member t1
      left join ctop_corp_wexin_user t2
@@ -41,8 +41,8 @@
      and t2.wexin_id != ''
     </select>
 
-    <select id="getWChatIdByUserId" resultType="java.lang.String">
-    select t1.wexin_id
+    <select id="getWChatIdByUserId" resultType="com.alibaba.fastjson.JSONObject">
+    select t1.wexin_id,corp_id
     from ctop_corp_wexin_user t1
     left join  sys_user t2
     on  t1.user_id = t2.id
@@ -58,9 +58,9 @@
     where id = #{userId}
     </select>
 
-    <select id="getWeChatByMail" resultType="java.lang.String">
+    <select id="getWeChatByMail" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
-            wexin_id
+            wexin_id,corp_id
         FROM
             ctop_corp_wexin_user
         WHERE

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/WexinConfigMapper.xml

@@ -0,0 +1,5 @@
+<?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="cn.com.ctop.common.module.mapper.WexinConfigMapper">
+
+</mapper>

+ 16 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IWexinConfigService.java

@@ -0,0 +1,16 @@
+package cn.com.ctop.common.module.service;
+
+import cn.com.ctop.common.module.entity.WexinConfig;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * 2021-06-17
+ * @version V1.0
+ */
+public interface IWexinConfigService extends IService<WexinConfig> {
+
+    WexinConfig getInfoByCorpId(String corpId);
+}

+ 7 - 4
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MailLogServiceImpl.java

@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
 import cn.com.feishu.provider.MessageProvider;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Primary;
@@ -25,11 +26,13 @@ import org.springframework.stereotype.Service;
 public class MailLogServiceImpl extends ServiceImpl<MailLogMapper, MailLog> implements IMailLogService {
     @Autowired
     private MailLogMapper mailLogMapper;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
 
     @Override
     public void sendWeChat(String responsibleId, Long accountId, String projectName, String transferor, String assignee) {
-        String weChatId = mailLogMapper.getWChatIdByUserId(responsibleId);
+        JSONObject weChatId = mailLogMapper.getWChatIdByUserId(responsibleId);
         if (!Check.isNull(weChatId)) {
             String transferorName = mailLogMapper.getUserNameByUserId(transferor); // 转让人姓名
             String assigneeName = mailLogMapper.getUserNameByUserId(assignee); // 转让人姓名
@@ -39,7 +42,7 @@ public class MailLogServiceImpl extends ServiceImpl<MailLogMapper, MailLog> impl
                     .append("账号:" + accountId).append(",申请由:" + transferorName + "转户于:" + assigneeName).append("<br/>")
                     .append("等待您的审核,请您及时处理!");
 
-            CorpWexinUtils.sendMessageByWeChatId(weChatId, text.toString());
+            corpWexinUtils.sendMessageByWeChatId(weChatId, text.toString());
         }
 
         CorpFeishuUser user = corpFeishuUserService.getByUserId(responsibleId);
@@ -74,7 +77,7 @@ public class MailLogServiceImpl extends ServiceImpl<MailLogMapper, MailLog> impl
     @Override
     public void sendWeChatByStatus(String projectName, Integer status, String userId, Long accountId) {
 
-        String weChatId = mailLogMapper.getWChatIdByUserId(userId);
+        JSONObject weChatId = mailLogMapper.getWChatIdByUserId(userId);
         if (!Check.isNull(weChatId)) {
             String statusName = "";
 
@@ -91,7 +94,7 @@ public class MailLogServiceImpl extends ServiceImpl<MailLogMapper, MailLog> impl
                     .append("申请的转户操作已:" + statusName).append("<br/>")
                     .append("请您前往验证,谢谢!");
 
-            CorpWexinUtils.sendMessageByWeChatId(weChatId, text.toString());
+            corpWexinUtils.sendMessageByWeChatId(weChatId, text.toString());
         }
 
         CorpFeishuUser user = corpFeishuUserService.getByUserId(userId);

+ 6 - 2
module-common/src/main/java/cn/com/ctop/common/module/service/impl/SendMessageServiceImpl.java

@@ -4,6 +4,7 @@ import cn.com.ctop.common.module.mapper.MailLogMapper;
 import cn.com.ctop.common.module.service.ISendMessageService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -13,11 +14,14 @@ import org.springframework.stereotype.Service;
 public class SendMessageServiceImpl implements ISendMessageService {
     @Autowired
     private MailLogMapper mailLogMapper;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
+
     @Override
     public void sendMessage(String userId, String text) {
-        String weChatId = mailLogMapper.getWChatIdByUserId(userId);
+        JSONObject weChatId = mailLogMapper.getWChatIdByUserId(userId);
         if (!Check.isNull(weChatId)) {
-            CorpWexinUtils.sendMessageByWeChatId(weChatId, text);
+            corpWexinUtils.sendMessageByWeChatId(weChatId, text);
             log.info("消息发送成功,userId:{}", userId);
         }
     }

+ 29 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/WexinConfigServiceImpl.java

@@ -0,0 +1,29 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.entity.WexinConfig;
+import cn.com.ctop.common.module.mapper.WexinConfigMapper;
+import cn.com.ctop.common.module.service.IWexinConfigService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 企业微信配置信息
+ *
+ * @author jeecg-boot
+ * 2021-06-17
+ * @version V1.0
+ */
+@Service
+public class WexinConfigServiceImpl extends ServiceImpl<WexinConfigMapper, WexinConfig> implements IWexinConfigService {
+
+    @Override
+    public WexinConfig getInfoByCorpId(String corpId) {
+        QueryWrapper<WexinConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("corp_id", corpId);
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        WexinConfig config = this.getOne(queryWrapper);
+        return config;
+    }
+}

+ 45 - 31
module-common/src/main/java/cn/com/ctop/common/module/utils/CorpWexinUtils.java

@@ -1,5 +1,9 @@
 package cn.com.ctop.common.module.utils;
 
+import cn.com.ctop.common.module.entity.WexinConfig;
+import cn.com.ctop.common.module.service.IWexinConfigService;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import lombok.val;
 import me.chanjar.weixin.common.error.WxErrorException;
@@ -7,69 +11,79 @@ import me.chanjar.weixin.cp.api.WxCpService;
 import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
 import me.chanjar.weixin.cp.bean.WxCpMessage;
 import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+@Service
 @Slf4j
 public class CorpWexinUtils {
-    private static WxCpService wxCpService;
+    @Autowired
+    private IWexinConfigService wexinConfigService;
+    private static Map<String, WexinConfig> configMap = new HashMap<>();
 
-    {
-        initService();
-    }
-
-    public static void initService() {
-        val configStorage = new WxCpDefaultConfigImpl();
-        configStorage.setCorpId("ww24b8a47826f5875f");
-        configStorage.setAgentId(1000002);
-        configStorage.setCorpSecret("MJIlySADGPlgvADnkFQPUpfZD4yV-4WN6066OgNnb0s");
-        configStorage.setToken("hcst2019");
-        configStorage.setAesKey("hcst2019");
-        wxCpService = new WxCpServiceImpl();
-        wxCpService.setWxCpConfigStorage(configStorage);
+    private Map<String, WexinConfig> getConfigMap() {
+        QueryWrapper<WexinConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.orderByDesc("create_time");
+        List<WexinConfig> list = wexinConfigService.list(queryWrapper);
+        for (WexinConfig config : list) {
+            WxCpService wxCpService = new WxCpServiceImpl();
+            val configStorage = new WxCpDefaultConfigImpl();
+            configStorage.setCorpId(config.getCorpId());
+            configStorage.setAgentId(config.getAgentId());
+            configStorage.setCorpSecret(config.getCorpSecret());
+            configStorage.setToken(config.getToken());
+            configStorage.setAesKey(config.getAesKey());
+            wxCpService.setWxCpConfigStorage(configStorage);
+            config.setWxCpService(wxCpService);
+            configMap.put(config.getCorpId(), config);
+        }
+        return configMap;
     }
 
-    public static void sendMessage(List<String> wxUserList, String content) {
-        if (wxCpService == null) {
-            initService();
+    public void sendMessage(List<JSONObject> wxUserList, String content) {
+        if (Check.isNullMap(configMap)) {
+            getConfigMap();
         }
         if (wxUserList != null && wxUserList.size() > 0) {
-            for (String userId : wxUserList) {
+            for (JSONObject userInfo : wxUserList) {
                 WxCpMessage message = new WxCpMessage();
                 message.setMsgType("text");
                 message.setContent(content);
                 message.setAgentId(1000002);
-                message.setToUser(userId);
+                message.setToUser(userInfo.getString("wexin_id"));
                 try {
+                    WexinConfig config = configMap.get(userInfo.getString("corp_id"));
+                    WxCpService wxCpService = config.getWxCpService();
                     wxCpService.messageSend(message);
                 } catch (WxErrorException e) {
-                    log.error("发送信息失败,userId:{}", userId);
+                    log.error("发送信息失败,userId:{}", userInfo.getString("wexin_id"));
                     e.printStackTrace();
                 }
             }
         }
     }
-
-    public synchronized static void sendMessageByWeChatId(String weChatId, String content) {
-        if (wxCpService == null) {
-            initService();
+    public void sendMessageByWeChatId(JSONObject weChatInfo, String content) {
+        if (Check.isNullMap(configMap)) {
+            this.getConfigMap();
         }
-        if (!Check.isNull(weChatId)) {
+        if (!Check.isNull(weChatInfo)) {
             WxCpMessage message = new WxCpMessage();
             message.setMsgType("text");
             message.setContent(content);
             message.setAgentId(1000002);
-            message.setToUser(weChatId);
+            message.setToUser(weChatInfo.getString("wexin_id"));
             try {
+                WexinConfig config = configMap.get(weChatInfo.getString("corp_id"));
+                WxCpService wxCpService = config.getWxCpService();
                 wxCpService.messageSend(message);
             } catch (WxErrorException e) {
-                log.error("发送信息失败,userId:{}", weChatId);
+                log.error("发送信息失败,userId:{}", weChatInfo.getString("wexin_id"));
                 e.printStackTrace();
             }
-
         }
-
-
     }
-
 }

+ 7 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/AccountWarningServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.ctop.common.module.utils.SendMailUtil;
 import cn.com.ctop.kuaishou.modules.batch.service.IAccountWarningService;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportHourlyAccountMapper;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +33,8 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
     private MailLogMapper mailLogMapper;
     @Autowired
     private IProjectService projectService;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
 
     /**
@@ -127,8 +130,8 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
             } catch (Exception e) {
                 e.printStackTrace();
             }
-            List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-            CorpWexinUtils.sendMessage(wexinIds, text.toString());
+            List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+            corpWexinUtils.sendMessage(wexinIds, text.toString());
         }
     }
 
@@ -167,8 +170,8 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
                 e.printStackTrace();
             }
         }
-        List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-        CorpWexinUtils.sendMessage(wexinIds, text.toString());
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        corpWexinUtils.sendMessage(wexinIds, text.toString());
 
     }
 

+ 6 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/material/service/impl/KuaishouBidWarningServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.ctop.common.module.utils.SendMailUtil;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import cn.com.ctop.kuaishou.modules.material.service.IKuaishouBidWarningService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.xxl.job.core.context.XxlJobHelper;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,6 +31,8 @@ public class KuaishouBidWarningServiceImpl implements IKuaishouBidWarningService
     private KuaiShouGroupMapper groupMapper;
     @Autowired
     private MailLogMapper mailLogMapper;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
 
     /**
@@ -51,7 +54,7 @@ public class KuaishouBidWarningServiceImpl implements IKuaishouBidWarningService
                 }
                 Long maxBid = project.getMaxBid();
                 Long projectId = project.getId();
-                List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId,null,null);
+                List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId, null, null);
                 if (!Check.isNull(userAllocations)) {
                     for (UserAllocation userAllocation : userAllocations) {
                         if (userAllocation.getAccountStatus() == 1) {
@@ -108,7 +111,7 @@ public class KuaishouBidWarningServiceImpl implements IKuaishouBidWarningService
             }
         }
 
-        List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-        CorpWexinUtils.sendMessage(wexinIds, text.toString());
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        corpWexinUtils.sendMessage(wexinIds, text.toString());
     }
 }

+ 6 - 3
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/BytedanceBidWarningServiceImpl.java

@@ -13,6 +13,7 @@ import cn.com.ctop.common.module.utils.SendMailUtil;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
 import cn.com.ctop.toutiao.modules.material.service.IBytedanceBidWarningService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.xxl.job.core.context.XxlJobHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
@@ -34,6 +35,8 @@ public class BytedanceBidWarningServiceImpl implements IBytedanceBidWarningServi
     private MailLogMapper mailLogMapper;
     @Autowired
     private IByteDanceAdvertisePlanService byteDanceAdvertisePlanService;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
     @Override
     public void bidWarning() {
@@ -48,7 +51,7 @@ public class BytedanceBidWarningServiceImpl implements IBytedanceBidWarningServi
                     }
                     Long maxBid = project.getMaxBid();
                     Long projectId = project.getId();
-                    List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId,null,null);
+                    List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId, null, null);
                     if (!Check.isNull(userAllocations)) {
                         for (UserAllocation userAllocation : userAllocations) {
                             if (userAllocation.getAccountStatus() == 1) {
@@ -108,7 +111,7 @@ public class BytedanceBidWarningServiceImpl implements IBytedanceBidWarningServi
             }
         }
 
-        List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-        CorpWexinUtils.sendMessage(wexinIds, text.toString());
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        corpWexinUtils.sendMessage(wexinIds, text.toString());
     }
 }

+ 7 - 4
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ByteDanceHourlyAccountWarningServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.ctop.common.module.utils.SendMailUtil;
 import cn.com.ctop.toutiao.modules.report.mapper.BytedanceAdvertiserHourlyReportMapper;
 import cn.com.ctop.toutiao.modules.report.service.IByteDanceHourlyAccountWarningService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +36,8 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
     private MailLogMapper mailLogMapper;
     @Autowired
     private IProjectService projectService;
+    @Autowired
+    private CorpWexinUtils corpWexinUtils;
 
     /**
      * 头条账户 出价预警
@@ -123,8 +126,8 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
             } catch (Exception e) {
                 e.printStackTrace();
             }
-            List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-            CorpWexinUtils.sendMessage(wexinIds, text.toString());
+            List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+            corpWexinUtils.sendMessage(wexinIds, text.toString());
         }
     }
 
@@ -162,8 +165,8 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
                 e.printStackTrace();
             }
         }
-        List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-        CorpWexinUtils.sendMessage(wexinIds, text.toString());
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        corpWexinUtils.sendMessage(wexinIds, text.toString());
     }