Forráskód Böngészése

消耗预警修改

yumeng 2 éve
szülő
commit
6248e324ed

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

@@ -27,4 +27,8 @@ public interface MailLogMapper extends BaseMapper<MailLog> {
     String getUserNameByUserId(@Param("userId") String transferor);
 
     JSONObject getWeChatByMail(@Param("mail") String mail);
+
+    List<JSONObject> selectWeiXinIdListByAccountId(@Param("accountId") Long accountId);
+
+    List<JSONObject> selectBytaDanceWeiXinIdListByAccountId(@Param("accountId") Long accountId);
 }

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

@@ -61,5 +61,43 @@ group by t1.user_id
         WHERE
             wexin_email = #{mail}
     </select>
+    <select id="selectWeiXinIdListByAccountId" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Long">
+        select wexin_id, corp_id
+        from ctop_corp_wexin_user
+        where user_id = (select ctop_user_allocation.user_id from ctop_user_allocation where account_id =  #{accountId} limit 1)
+        union all
+        select wexin_id, corp_id
+        from ctop_corp_wexin_user
+        where user_id = (select leader_id
+                 from sys_user
+                 where id = (SELECT ctop_user_allocation.user_id
+                                  FROM ctop_user_allocation
+                                  WHERE account_id = #{accountId}
+                                  LIMIT 1))
+        union all
+        select wexin_id, corp_id
+        from ctop_corp_wexin_user
+        where user_id = 'f6a6843879c949618e4a859140c8a127'
+    </select>
+    <select id="selectBytaDanceWeiXinIdListByAccountId" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Long">
+        select wexin_id, corp_id
+        from ctop_corp_wexin_user
+        where user_id = (select ctop_user_allocation.user_id
+                 from ctop_user_allocation
+                 where account_id = #{accountId} limit 1)
+                 union all
+                 select wexin_id, corp_id
+                 from ctop_corp_wexin_user
+                 where user_id = (select leader_id
+                                  from sys_user
+                                  where id = (SELECT ctop_user_allocation.user_id
+                                              FROM ctop_user_allocation
+                                              WHERE account_id = #{accountId}
+                                              LIMIT 1))
+                 union all
+                 select wexin_id, corp_id
+                 from ctop_corp_wexin_user
+                 where user_id = '461857c245f54ba5813bcb5900a23092'
+    </select>
 
 </mapper>

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

@@ -73,7 +73,7 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
                         BigDecimal subtract = nowCost.subtract(lastHourCost);
                         BigDecimal divide = nowCost.divide(lastHourCost, 2, RoundingMode.HALF_UP);
                         if (subtract.compareTo(warningAmount) > -1 && divide.compareTo(warningProportion) > -1) {
-                            sendMessage(accountId, userAllocation.getAuthName(), maxHour, nowCost, userAllocation.getProjectId(), project.getProjectName());
+                            sendMessage(accountId, userAllocation.getAuthName(), maxHour, nowCost, userAllocation.getProjectId(), project.getProjectName(), userAllocation.getUserName());
                         }
                     }
                 }
@@ -84,7 +84,7 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
                     BigDecimal subtract = nowCost.subtract(yesterdayHourCost);
                     BigDecimal divide = nowCost.divide(yesterdayHourCost, 2, RoundingMode.HALF_UP);
                     if (subtract.compareTo(warningAmount) > -1 && divide.compareTo(warningProportion) > -1) {
-                        sendYesterdayMessage(accountId, userAllocation.getAuthName(), maxHour, nowCost, userAllocation.getProjectId(), project.getProjectName());
+                        sendYesterdayMessage(accountId, userAllocation.getAuthName(), maxHour, nowCost, userAllocation.getProjectId(), project.getProjectName(), userAllocation.getUserName());
                     }
                 }
             }
@@ -95,35 +95,31 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
     }
 
 
-
-
-
-
-    private void sendYesterdayMessage(Long accountId, String authName, Integer maxHour, BigDecimal nowCost, Long projectId, String projectName) {
+    private void sendYesterdayMessage(Long accountId, String authName, Integer maxHour, BigDecimal nowCost, Long projectId, String projectName, String userName) {
         StringBuilder text = new StringBuilder();
         text.append("较昨日同时段消耗预警").append("<br/>")
                 .append("您的项目:" + projectName + "下的,").append("<br/>")
                 .append("账号:").append(accountId + ",").append("授权名称为:" + authName).append("<br/>")
+                .append("账户所属人:" + userName).append("<br/>")
                 .append("相较于昨日 " + maxHour + "时").append("<br/>")
                 .append("出现消耗暴涨,").append("消耗金额为:" + nowCost).append("<br/>")
                 .append("请您及时查看!");
-            List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
-            corpWexinUtils.sendMessage(wexinIds, text.toString());
-
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdListByAccountId(accountId);
+        corpWexinUtils.sendMessage(wexinIds, text.toString());
     }
 
 
-    private void sendMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId, String projectName) {
+    private void sendMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId, String projectName, String userName) {
         StringBuilder text = new StringBuilder();
         text.append("较上时段消耗预警").append("<br/>")
                 .append("您的项目:" + projectName + " 下的").append("<br/>")
                 .append("账号:").append(accountId + ",").append("授权名称为:" + authName).append("<br/>")
+                .append("账户所属人:" + userName).append("<br/>")
                 .append(hour + " 时").append("相较于 " + (hour - 1) + " 时").append("<br/>")
                 .append("出现消耗暴涨,").append("消耗金额为:" + amount).append("<br/>")
                 .append("请您及时查看!");
-        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdListByAccountId(accountId);
         corpWexinUtils.sendMessage(wexinIds, text.toString());
-
     }
 
 

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

@@ -55,10 +55,7 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
             if (Check.isNull(userAllocation)) {
                 return;
             }
-
             Project project = projectService.getById(userAllocation.getProjectId());
-
-
             if (userAllocation.getAccountStatus() == 1) {
                 return;
             }
@@ -73,7 +70,7 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
                         BigDecimal subtract = nowCost.subtract(lastHourCost);
                         BigDecimal divide = nowCost.divide(lastHourCost, 2, RoundingMode.HALF_UP);
                         if (subtract.compareTo(warningAmount) > -1 && divide.compareTo(warningProportion) > -1) {
-                            sendMessage(accountId, userAllocation.getAuthName(), maxHour, cost, userAllocation.getProjectId(), project.getProjectName());
+                            sendMessage(accountId, userAllocation.getAuthName(), maxHour, cost, userAllocation.getProjectId(), project.getProjectName(),userAllocation.getUserName());
                         }
                     }
                 }
@@ -85,7 +82,7 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
                     BigDecimal subtract = nowCost.subtract(yesterdayHourCost);
                     BigDecimal divide = nowCost.divide(yesterdayHourCost, 2, RoundingMode.HALF_UP);
                     if (subtract.compareTo(warningAmount) > -1 && divide.compareTo(warningProportion) > -1) {
-                        sendYesterdayMessage(accountId, userAllocation.getAuthName(), maxHour, cost, userAllocation.getProjectId(), project.getProjectName());
+                        sendYesterdayMessage(accountId, userAllocation.getAuthName(), maxHour, cost, userAllocation.getProjectId(), project.getProjectName(),userAllocation.getUserName());
                     }
                 }
             }
@@ -95,77 +92,31 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
     }
 
 
-    private void sendYesterdayMessage(Long accountId, String authName, Integer maxHour, BigDecimal nowCost, Long projectId, String projectName) {
+    private void sendYesterdayMessage(Long accountId, String authName, Integer maxHour, BigDecimal nowCost, Long projectId, String projectName,String userName) {
         StringBuilder text = new StringBuilder();
         text.append("较昨日同时段消耗预警").append("<br/>")
                 .append("您的项目:" + projectName + "下的,").append("<br/>")
                 .append("账号:").append(accountId + ",").append("授权名称为:" + authName).append("<br/>")
+                .append("账户所属人:" + userName).append("<br/>")
                 .append("相较于昨日 " + maxHour + "时").append("<br/>")
                 .append("出现消耗暴涨,").append("消耗金额为:" + nowCost).append("<br/>")
                 .append("请您及时查看!");
-        QueryWrapper<MailLog> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("account_id", accountId);
-        queryWrapper.eq("hour", maxHour);
-        queryWrapper.eq("mail_type", 3);
-        queryWrapper.orderByDesc("create_time");
-        queryWrapper.last("limit 1");
-        MailLog checkMailLog = mailLogMapper.selectOne(queryWrapper);
-        if (Check.isNull(checkMailLog)) {
-            List<String> mailList = mailLogMapper.selectMailList(projectId);
-            String subject = "头条-较昨日同时段账户消耗预警";
-            try {
-                SendMailUtil.sendMail(mailList, subject, text.toString());
-                MailLog mailLog = new MailLog();
-                mailLog.setAccountId(accountId);
-                mailLog.setMailType(3);
-                mailLog.setHour(maxHour);
-                mailLog.setContent(text.toString());
-                mailLog.setSendEmil(JSON.toJSONString(mailList));
-                mailLog.setSubject(subject);
-                mailLogMapper.insert(mailLog);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+            List<JSONObject> wexinIds = mailLogMapper.selectBytaDanceWeiXinIdListByAccountId(accountId);
             corpWexinUtils.sendMessage(wexinIds, text.toString());
-        }
-    }
 
-    private void sendMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId, String projectName) {
+    }
 
+    private void sendMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId, String projectName,String userName) {
         StringBuilder text = new StringBuilder();
         text.append("较上时段消耗预警").append("<br/>")
                 .append("您的项目:" + projectName + " 下的").append("<br/>")
                 .append("账号:").append(accountId + ",").append("授权名称为:" + authName).append("<br/>")
+                .append("账户所属人:" + userName).append("<br/>")
                 .append(hour + " 时").append("相较于 " + (hour - 1) + " 时").append("<br/>")
                 .append("出现消耗暴涨,").append("消耗金额为:" + amount).append("<br/>")
                 .append("请您及时查看!");
 
-        QueryWrapper<MailLog> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("account_id", accountId);
-        queryWrapper.eq("hour", hour);
-        queryWrapper.eq("mail_type", 2);
-        queryWrapper.orderByDesc("create_time");
-        queryWrapper.last("limit 1");
-        MailLog checkMailLog = mailLogMapper.selectOne(queryWrapper);
-        if (Check.isNull(checkMailLog)) {
-            List<String> mailList = mailLogMapper.selectMailList(projectId);
-            String subject = "头条-账户消耗预警";
-            try {
-                SendMailUtil.sendMail(mailList, subject, text.toString());
-                MailLog mailLog = new MailLog();
-                mailLog.setAccountId(accountId);
-                mailLog.setMailType(2);
-                mailLog.setHour(hour);
-                mailLog.setContent(text.toString());
-                mailLog.setSendEmil(JSON.toJSONString(mailList));
-                mailLog.setSubject(subject);
-                mailLogMapper.insert(mailLog);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-        List<JSONObject> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        List<JSONObject> wexinIds = mailLogMapper.selectBytaDanceWeiXinIdListByAccountId(accountId);
         corpWexinUtils.sendMessage(wexinIds, text.toString());
     }