syh 5 лет назад
Родитель
Сommit
59bfdd0244
30 измененных файлов с 431 добавлено и 266 удалено
  1. 2 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdvertiserController.java
  2. 2 86
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CorpFeishuUserController.java
  3. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java
  4. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/AccountBidJob.java
  5. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/AccountCpaBidJob.java
  6. 0 14
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/CorpFeishuUserMapper.java
  7. 0 5
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/CorpFeishuUserMapper.xml
  8. 1 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IBidWarningService.java
  9. 0 14
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/ICorpFeishuUserService.java
  10. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/ICpaBidWarningService.java
  11. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/AdvertiserServiceImpl.java
  12. 49 14
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/BidWarningServiceImpl.java
  13. 0 18
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CorpFeishuUserServiceImpl.java
  14. 50 25
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CpaBidWarningServiceImpl.java
  15. 7 9
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CrawlerServiceImpl.java
  16. 0 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CreativeTitleServiceImpl.java
  17. 1 9
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouDefectMaterialServiceImpl.java
  18. 3 8
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouUploadServiceImpl.java
  19. 3 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java
  20. 1 1
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  21. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/CorpFeishuUser.java
  22. 18 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/CorpFeishuUserMapper.java
  23. 14 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CorpFeishuUserMapper.xml
  24. 17 0
      module-common/src/main/java/cn/com/ctop/common/module/service/ICorpFeishuUserService.java
  25. 1 3
      module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java
  26. 45 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/CorpFeishuUserServiceImpl.java
  27. 4 13
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java
  28. 27 7
      module-common/src/main/java/cn/com/feishu/provider/MessageProvider.java
  29. 89 0
      module-common/src/main/java/cn/com/feishu/provider/SendImage.java
  30. 91 24
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ByteDanceHourlyAccountWarningServiceImpl.java

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdvertiserController.java

@@ -385,7 +385,7 @@ public class AdvertiserController {
                 }
             }
         }
-        List<UserAllocation> allocations = userAllocationService.getByProjectId(projectId, systemType);
+        List<UserAllocation> allocations = userAllocationService.getByParams(projectId, systemType,null);
         if (null != allocations && !allocations.isEmpty()) {
             for (UserAllocation allocation : allocations) {
                 SheetInfoVo vo = advertiserService.getXxlStatisticInfo(projectId, systemType, allocation.getAccountId(), allocation.getAuthName());
@@ -420,7 +420,7 @@ public class AdvertiserController {
                 }
             }
         }
-        List<UserAllocation> allocations = userAllocationService.getByProjectId(projectId, systemType);
+        List<UserAllocation> allocations = userAllocationService.getByParams(projectId, systemType,null);
         if (null != allocations && !allocations.isEmpty()) {
             for (UserAllocation allocation : allocations) {
                 SheetInfoVo vo = advertiserService.getXxlStatisticInfo(projectId, systemType, allocation.getAccountId(), allocation.getAuthName());

+ 2 - 86
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CorpFeishuUserController.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.ctop.controller;
 
-import com.alibaba.fastjson.JSON;
+import cn.com.ctop.common.module.entity.CorpFeishuUser;
+import cn.com.ctop.common.module.service.ICorpFeishuUserService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -10,28 +11,11 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.modules.ctop.entity.CorpFeishuUser;
-import org.jeecg.modules.ctop.service.ICorpFeishuUserService;
-import org.jeecgframework.poi.excel.ExcelImportUtil;
-import org.jeecgframework.poi.excel.def.NormalExcelConstants;
-import org.jeecgframework.poi.excel.entity.ExportParams;
-import org.jeecgframework.poi.excel.entity.ImportParams;
-import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
-import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
 
  /**
  * 飞书用户信息
@@ -170,72 +154,4 @@ public class CorpFeishuUserController {
 		}
 		return result;
 	}
-
-  /**
-      * 导出excel
-   *
-   * @param request
-   * @param response
-   */
-  @RequestMapping(value = "/exportXls")
-  public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
-      // Step.1 组装查询条件
-      QueryWrapper<CorpFeishuUser> queryWrapper = null;
-      try {
-          String paramsStr = request.getParameter("paramsStr");
-          if (oConvertUtils.isNotEmpty(paramsStr)) {
-              String deString = URLDecoder.decode(paramsStr, "UTF-8");
-              CorpFeishuUser corpFeishuUser = JSON.parseObject(deString, CorpFeishuUser.class);
-              queryWrapper = QueryGenerator.initQueryWrapper(corpFeishuUser, request.getParameterMap());
-          }
-      } catch (UnsupportedEncodingException e) {
-          e.printStackTrace();
-      }
-
-      //Step.2 AutoPoi 导出Excel
-      ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
-      List<CorpFeishuUser> pageList = corpFeishuUserService.list(queryWrapper);
-      //导出文件名称
-      mv.addObject(NormalExcelConstants.FILE_NAME, "飞书用户信息列表");
-      mv.addObject(NormalExcelConstants.CLASS, CorpFeishuUser.class);
-      mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("飞书用户信息列表数据", "导出人:Jeecg", "导出信息"));
-      mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
-      return mv;
-  }
-
-  /**
-      * 通过excel导入数据
-   *
-   * @param request
-   * @param response
-   * @return
-   */
-  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
-  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
-      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
-      Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
-      for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
-          MultipartFile file = entity.getValue();
-          ImportParams params = new ImportParams();
-          params.setTitleRows(2);
-          params.setHeadRows(1);
-          params.setNeedSave(true);
-          try {
-              List<CorpFeishuUser> listCorpFeishuUsers = ExcelImportUtil.importExcel(file.getInputStream(), CorpFeishuUser.class, params);
-              corpFeishuUserService.saveBatch(listCorpFeishuUsers);
-              return Result.ok("文件导入成功!数据行数:" + listCorpFeishuUsers.size());
-          } catch (Exception e) {
-              log.error(e.getMessage(),e);
-              return Result.error("文件导入失败:"+e.getMessage());
-          } finally {
-              try {
-                  file.getInputStream().close();
-              } catch (IOException e) {
-                  e.printStackTrace();
-              }
-          }
-      }
-      return Result.ok("文件导入失败!");
-  }
-
 }

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java

@@ -362,7 +362,7 @@ public class UserAllocationController {
     public Result<List<UserAllocation>> selectAccountListByProjectId(Long projectId) {
         Result<List<UserAllocation>> result = new Result<>();
         try {
-            List<UserAllocation> userAllocations = userAllocationService.selectAccountListByProjectId(projectId);
+            List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId,null,null);
             result.setSuccess(true);
             result.setResult(userAllocations);
         } catch (Exception e) {

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/AccountBidJob.java

@@ -21,6 +21,6 @@ public class AccountBidJob implements Job {
      */
     @Override
     public void execute(JobExecutionContext jobExecutionContext) {
-        bidWarningService.BidWarning();
+        bidWarningService.bidWarning();
     }
 }

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/AccountCpaBidJob.java

@@ -48,7 +48,7 @@ public class AccountCpaBidJob implements Job {
                         executorService.submit(new Runnable() {
                             @Override
                             public void run() {
-                                cpaBidWarningService.CpaBidWarning(project);
+                                cpaBidWarningService.cpaBidWarning(project);
                             }
 
                         });

+ 0 - 14
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/CorpFeishuUserMapper.java

@@ -1,14 +0,0 @@
-package org.jeecg.modules.ctop.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.jeecg.modules.ctop.entity.CorpFeishuUser;
-
-/**
- * 飞书用户信息
- * @author: jeecg-boot
- * @date:   2020-06-23
- * @cersion: V1.0
- */
-public interface CorpFeishuUserMapper extends BaseMapper<CorpFeishuUser> {
-
-}

+ 0 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/CorpFeishuUserMapper.xml

@@ -1,5 +0,0 @@
-<?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="org.jeecg.modules.ctop.mapper.CorpFeishuUserMapper">
-
-</mapper>

+ 1 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IBidWarningService.java

@@ -1,7 +1,5 @@
 package org.jeecg.modules.ctop.service;
 
 public interface IBidWarningService {
-    void BidWarning();
-
-
+    void bidWarning();
 }

+ 0 - 14
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/ICorpFeishuUserService.java

@@ -1,14 +0,0 @@
-package org.jeecg.modules.ctop.service;
-
-import com.baomidou.mybatisplus.extension.service.IService;
-import org.jeecg.modules.ctop.entity.CorpFeishuUser;
-
-/**
- * 飞书用户信息
- * @author jeecg-boot
- * @date   2020-06-23
- * @version V1.0
- */
-public interface ICorpFeishuUserService extends IService<CorpFeishuUser> {
-
-}

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/ICpaBidWarningService.java

@@ -3,7 +3,7 @@ package org.jeecg.modules.ctop.service;
 import org.jeecg.modules.ctop.entity.Project;
 
 public interface ICpaBidWarningService {
-    void CpaBidWarning(Project project);
+    void cpaBidWarning(Project project);
 
 
 }

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/AdvertiserServiceImpl.java

@@ -114,7 +114,7 @@ public class AdvertiserServiceImpl extends ServiceImpl<AdvertiserMapper, Adverti
 
     private List<YdPlanAggregateEntity> getYdPlanStatisticInfo(Long projectId, String startDate, String endDate) {
         List<YdPlanAggregateEntity> result = new ArrayList<>();
-        List<UserAllocation> allocations = userAllocationService.getByProjectId(projectId, null);
+        List<UserAllocation> allocations = userAllocationService.getByParams(projectId, null,null);
         if (null != allocations && !allocations.isEmpty()) {
             allocations.forEach(allocation -> {
                 List<YdPlanAggregateEntity> plans = statisticWeekInfoByAccount(allocation, startDate, endDate);

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

@@ -3,14 +3,17 @@ package org.jeecg.modules.ctop.service.impl;
 import cn.com.ctop.common.module.entity.MailLog;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.MailLogMapper;
-import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.service.ICorpFeishuUserService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.BigDecimalUtil;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
 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 cn.com.feishu.provider.MessageProvider;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
@@ -35,7 +38,7 @@ public class BidWarningServiceImpl implements IBidWarningService {
     @Autowired
     private ProjectMapper projectMapper;
     @Autowired
-    private UserAllocationMapper userAllocationMapper;
+    private IUserAllocationService userAllocationService;
     @Autowired
     private KuaiShouGroupMapper groupMapper;
     @Autowired
@@ -49,7 +52,7 @@ public class BidWarningServiceImpl implements IBidWarningService {
      */
 
     @Override
-    public void BidWarning() {
+    public void bidWarning() {
         log.info("开始出价预警定时任务");
         long l = System.currentTimeMillis();
         try {
@@ -62,7 +65,7 @@ public class BidWarningServiceImpl implements IBidWarningService {
                     }
                     Long maxBid = project.getMaxBid();
                     Long projectId = project.getId();
-                    List<UserAllocation> userAllocations = getUserAllocationsByProjectId(projectId);
+                    List<UserAllocation> userAllocations = userAllocationService.getByParams(projectId,null,null);
                     if (!Check.isNull(userAllocations)) {
                         for (UserAllocation userAllocation : userAllocations) {
                             if (userAllocation.getAccountStatus() == 1) {
@@ -93,24 +96,59 @@ public class BidWarningServiceImpl implements IBidWarningService {
 
 
     }
+    private void sendFeishumessage(String mediaId, Long accountId, Long projectId, String projectName, String authName, List<String> unitWarning, Long maxBid) throws Exception {
+        String createTime = DateUtils.getNowDate("yyyy-MM-dd");
+        Integer count = mailLogMapper.selectCountByAccountIdAndDate(accountId, createTime, Integer.getInteger(mediaId));
+        StringBuilder text = new StringBuilder();
+        String s = "";
+        for (int i = 0; i < unitWarning.size(); i++) {
+            s += unitWarning.get(i) + "," + "\n\r";
+
+        }
+        text.append("项目出价预警").append("\n\r").append("您的项目:").append(projectName + ",").append("\n\r")
+                .append("授权名称为:" + authName + " 下的,").append("\n\r").append(s)
+                .append("大于项目设置的最高出价:").append(maxBid / 1000).append(" 元! 请您及时调整。");
+        if (count < 3) {
+            List<String> mailList = mailLogMapper.selectMailList(projectId);
+            String subject;
+            if ("1".equals(mediaId)) {
+                subject = "头条-广告计划出价预警";
+
+            } else {
+                subject = "快手-广告组出价预警";
+            }
+            try {
+                SendMailUtil.sendMail(mailList, subject, text.toString());
+                MailLog mailLog = new MailLog();
+                mailLog.setAccountId(accountId);
+                mailLog.setMailType(1);
+                mailLog.setContent(text.toString());
+                mailLog.setSendEmil(JSON.toJSONString(mailList));
+                mailLog.setSubject(subject);
+                mailLogMapper.insert(mailLog);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
 
-    private List<UserAllocation> getUserAllocationsByProjectId(Long projectId) {
-        QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
-        userAllocationQueryWrapper.eq("project_id", projectId);
-        List<UserAllocation> userAllocations = userAllocationMapper.selectList(userAllocationQueryWrapper);
-        return userAllocations;
+        JSONArray openIds = corpFeishuUserService.getOpenIdByParams(projectId);
+        if(null == openIds||openIds.isEmpty()){
+            log.error("该项目下运营飞书账号尚未绑定邮箱=>projectId:{}",projectId);
+            return;
+        }
+        MessageProvider.batchSend(null,openIds,null,text.toString());
     }
 
+    @Autowired
+    private ICorpFeishuUserService corpFeishuUserService;
 
     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);
         StringBuilder text = new StringBuilder();
         String s = "";
         for (int i = 0; i < unitWarning.size(); i++) {
             s += unitWarning.get(i) + "," + "<br/>";
-
         }
         text.append("项目出价预警").append("<br/>").append("您的项目:").append(projectName + ",").append("<br/>")
                 .append("授权名称为:" + authName + " 下的,").append("<br/>").append(s)
@@ -120,7 +158,6 @@ public class BidWarningServiceImpl implements IBidWarningService {
             String subject;
             if ("1".equals(mediaId)) {
                 subject = "头条-广告计划出价预警";
-
             } else {
                 subject = "快手-广告组出价预警";
             }
@@ -141,8 +178,6 @@ public class BidWarningServiceImpl implements IBidWarningService {
 
         List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
         CorpWexinUtils.sendMessage(wexinIds, text.toString());
-
-
     }
 
 

+ 0 - 18
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CorpFeishuUserServiceImpl.java

@@ -1,18 +0,0 @@
-package org.jeecg.modules.ctop.service.impl;
-
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.jeecg.modules.ctop.entity.CorpFeishuUser;
-import org.jeecg.modules.ctop.mapper.CorpFeishuUserMapper;
-import org.jeecg.modules.ctop.service.ICorpFeishuUserService;
-import org.springframework.stereotype.Service;
-
-/**
- * 飞书用户信息
- * @author jeecg-boot
- * @date   2020-06-23
- * @version V1.0
- */
-@Service
-public class CorpFeishuUserServiceImpl extends ServiceImpl<CorpFeishuUserMapper, CorpFeishuUser> implements ICorpFeishuUserService {
-
-}

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

@@ -3,19 +3,20 @@ package org.jeecg.modules.ctop.service.impl;
 import cn.com.ctop.common.module.entity.MailLog;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.MailLogMapper;
-import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.service.ICorpFeishuUserService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.BigDecimalUtil;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
 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 cn.com.feishu.provider.MessageProvider;
 import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.alibaba.fastjson.JSONArray;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.entity.Project;
-import org.jeecg.modules.ctop.mapper.ProjectMapper;
 import org.jeecg.modules.ctop.service.ICpaBidWarningService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -31,31 +32,25 @@ import java.util.List;
 @Slf4j
 @Service
 public class CpaBidWarningServiceImpl implements ICpaBidWarningService {
-
-    @Autowired
-    private ProjectMapper projectMapper;
     @Autowired
-    private UserAllocationMapper userAllocationMapper;
+    private IUserAllocationService userAllocationService;
     @Autowired
     private KuaiShouGroupMapper groupMapper;
     @Autowired
     private MailLogMapper mailLogMapper;
     @Autowired
     private IByteDanceAdvertisePlanService byteDanceAdvertisePlanService;
-
+    @Autowired
+    private ICorpFeishuUserService corpFeishuUserService;
 
     /**
      * 预警
      */
-
     @Override
-    public void CpaBidWarning(Project project) {
+    public void cpaBidWarning(Project project) {
         try {
-
             BigDecimal maxDeepCpaBid = project.getMaxDeepCpaBid();
-
-
-            List<UserAllocation> userAllocations = getUserAllocationsByProjectId(project.getId());
+            List<UserAllocation> userAllocations = userAllocationService.getByParams(project.getId(),null,null);
             if (!Check.isNull(userAllocations)) {
                 for (UserAllocation userAllocation : userAllocations) {
                     if (userAllocation.getAccountStatus() == 1) {
@@ -79,22 +74,54 @@ public class CpaBidWarningServiceImpl implements ICpaBidWarningService {
         } catch (Exception e) {
             e.printStackTrace();
         }
+    }
 
+    private void sendFeishuMessage(String mediaId, Long accountId, Long projectId, String projectName, String authName, List<String> unitWarning, BigDecimal maxCpaBid) throws Exception {
+        BigDecimal maxBid = BigDecimalUtil.divideBigDecimal(maxCpaBid, new BigDecimal(1000));
+        String createTime = DateUtils.getNowDate("yyyy-MM-dd");
+        Integer count = mailLogMapper.selectCountByAccountIdAndDate(accountId, createTime, Integer.getInteger(mediaId));
+        StringBuilder text = new StringBuilder();
+        String s = "";
+        for (int i = 0; i < unitWarning.size(); i++) {
+            s += unitWarning.get(i) + "," + "\n\r";
 
-    }
+        }
+        text.append("项目深度出价预警").append("\n\r").append("您的项目:").append(projectName + ",").append("\n\r")
+                .append("授权名称为:" + authName + " 下的,").append("\n\r").append(s)
+                .append("大于项目设置的最高深度转化出价:").append(maxBid).append(" 元! 请您及时调整。");
+        if (count < 3) {
+            List<String> mailList = mailLogMapper.selectMailList(projectId);
+            String subject;
+            if ("1".equals(mediaId)) {
+                subject = "头条-广告计划深度转化出价预警";
 
-    private List<UserAllocation> getUserAllocationsByProjectId(Long projectId) {
-        QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
-        userAllocationQueryWrapper.eq("project_id", projectId);
-        List<UserAllocation> userAllocations = userAllocationMapper.selectList(userAllocationQueryWrapper);
-        return userAllocations;
-    }
+            } else {
+                subject = "快手-广告组深度转化出价预警";
+            }
 
+            try {
+                SendMailUtil.sendMail(mailList, subject, text.toString());
+                MailLog mailLog = new MailLog();
+                mailLog.setAccountId(accountId);
+                mailLog.setMailType(1);
+                mailLog.setContent(text.toString());
+                mailLog.setSendEmil(JSON.toJSONString(mailList));
+                mailLog.setSubject(subject);
+                mailLogMapper.insert(mailLog);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        JSONArray openIds = corpFeishuUserService.getOpenIdByParams(projectId);
+        if(null == openIds||openIds.isEmpty()){
+            log.error("该项目下运营飞书账号尚未绑定邮箱=>projectId:{}",projectId);
+            return;
+        }
+        MessageProvider.batchSend(null,openIds,null,text.toString());
+    }
 
     private void sendMessage(String mediaId, Long accountId, Long projectId, String projectName, String authName, List<String> unitWarning, BigDecimal maxCpaBid) {
-
         BigDecimal maxBid = BigDecimalUtil.divideBigDecimal(maxCpaBid, new BigDecimal(1000));
-
         String createTime = DateUtils.getNowDate("yyyy-MM-dd");
         Integer count = mailLogMapper.selectCountByAccountIdAndDate(accountId, createTime, 1);
         StringBuilder text = new StringBuilder();
@@ -133,8 +160,6 @@ public class CpaBidWarningServiceImpl implements ICpaBidWarningService {
 
         List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
         CorpWexinUtils.sendMessage(wexinIds, text.toString());
-
-
     }
 
 

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

@@ -19,14 +19,19 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutorService;
 
 @Service
 @Slf4j
 public class CrawlerServiceImpl implements ICrawlerService {
-    static ExecutorService executorService = null;
     @Autowired
     private IBindAccountLoginService bindAccountLoginService;
+    @Autowired
+    private IKuaishouInspiredAdService inspiredAdService;
+    @Autowired
+    private IKuaishouHotPhotoInfoService hotPhotoInfoService;
+    @Autowired
+    private IKuaishouEffectAdInfoService effectAdInfoService;
+
 
     @Override
     public Map<String, Object> loadInspiration() {
@@ -97,13 +102,6 @@ public class CrawlerServiceImpl implements ICrawlerService {
         loadInspiredAdByPage(pageSize, pageNumber + 1);
     }
 
-    @Autowired
-    private IKuaishouInspiredAdService inspiredAdService;
-    @Autowired
-    private IKuaishouHotPhotoInfoService hotPhotoInfoService;
-    @Autowired
-    private IKuaishouEffectAdInfoService effectAdInfoService;
-
     private void loadeffectAdByPage(int pageSize, int pageNum) {
         String url = "https://cc.e.kuaishou.com/rest/creativeCentor/adCase/effectAd/list";
         JSONObject param = new JSONObject();

+ 0 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CreativeTitleServiceImpl.java

@@ -48,7 +48,6 @@ public class CreativeTitleServiceImpl implements ICreativeTitleService {
             if (!Check.isNull(dataJson)) {
                 return dataJson.getJSONArray("titles");
             }
-
         }
         return null;
     }
@@ -73,7 +72,6 @@ public class CreativeTitleServiceImpl implements ICreativeTitleService {
             if (!Check.isNull(dataJson)) {
                 return dataJson.getJSONArray("titles");
             }
-
         }
         return null;
     }

+ 1 - 9
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouDefectMaterialServiceImpl.java

@@ -42,11 +42,9 @@ public class KuaiShouDefectMaterialServiceImpl extends ServiceImpl<KuaiShouDefec
 
     @Override
     public void getDefectVideo(String startDate, String endDate) {
-
         List<JSONObject> list = creativeMapper.selectCodeByDate(startDate, endDate);
         if (!Check.isNull(list)) {
             for (int i = 0; i < list.size(); i++) {
-
                 JSONObject codeJson = list.get(i);
                 // charge signature
                 String signature = codeJson.getString("signature");
@@ -72,19 +70,13 @@ public class KuaiShouDefectMaterialServiceImpl extends ServiceImpl<KuaiShouDefec
                         continue;
                     }
                     defectMaterial.setUrl(videoGet.getUrl());
-                    QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
-                    userAllocationQueryWrapper.eq("account_id", videoGet.getAccountId());
-                    userAllocationQueryWrapper.last("limit 1");
-                    UserAllocation userAllocation = userAllocationService.getOne(userAllocationQueryWrapper);
+                    UserAllocation userAllocation = userAllocationService.getByAccountId(videoGet.getAccountId());
                     if (!Check.isNull(userAllocation)) {
                         defectMaterial.setProjectId(userAllocation.getProjectId());
                     }
                     this.save(defectMaterial);
-
                 }
             }
-
         }
-
     }
 }

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

@@ -5,8 +5,8 @@ import cn.com.ctop.common.module.entity.MaterialInfo;
 import cn.com.ctop.common.module.entity.MaterialParameter;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.enums.MaterialEnum;
-import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
@@ -54,7 +54,7 @@ public class KuaiShouUploadServiceImpl implements IKuaiShouUploadService {
     @Autowired
     private IUserAllocationService allocationService;
     @Autowired
-    private CtopOauthTokenMapper oauthTokenMapper;
+    private ICtopOauthTokenService oauthTokenService;
     @Autowired
     private MaterialParameterMapper parameterMapper;
     @Autowired
@@ -94,12 +94,7 @@ public class KuaiShouUploadServiceImpl implements IKuaiShouUploadService {
             if (!Check.isNull(list)) {
                 for (UserAllocation allocation : list) {
                     Long accountId = allocation.getAccountId();
-                    QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
-                    tokenQueryWrapper.eq("account_id", accountId);
-                    tokenQueryWrapper.eq("media_id", 2);
-                    tokenQueryWrapper.orderByDesc("create_time");
-                    tokenQueryWrapper.last("limit 1");
-                    CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(tokenQueryWrapper);
+                    CtopOauthToken ctopOauthToken = oauthTokenService.getAccessTokenByAccountIdAndMediaId(2,accountId);
                     if (Check.isNull(ctopOauthToken)) {
                         log.error("快手账户信息为空,accountId:{}", accountId);
                         continue;

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

@@ -1,6 +1,8 @@
 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.service.ICorpFeishuUserService;
 import cn.com.ctop.common.module.service.ICtopCorpWexinUserService;
 import cn.com.ctop.common.module.utils.AesEncryptUtil;
 import cn.com.ctop.common.module.utils.EncryptedString;
@@ -33,8 +35,6 @@ import org.jeecg.common.util.DySmsHelper;
 import org.jeecg.common.util.PasswordUtil;
 import org.jeecg.common.util.RedisUtil;
 import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.modules.ctop.entity.CorpFeishuUser;
-import org.jeecg.modules.ctop.service.ICorpFeishuUserService;
 import org.jeecg.modules.shiro.vo.DefContants;
 import org.jeecg.modules.system.entity.SysDepart;
 import org.jeecg.modules.system.entity.SysUser;
@@ -131,7 +131,7 @@ public class LoginController {
             //用户登录信息
             userInfo(sysUser, getResult);
             sysBaseApi.addLog("用户名: " + email + ",登录成功!", CommonConstant.LOG_TYPE_1, null);
-            CorpFeishuUser feishuUser = corpFeishuUserService.getById(sysUser.getId());
+            CorpFeishuUser feishuUser = corpFeishuUserService.getByUserId(sysUser.getId());
             if (feishuUser == null) {
                 feishuUser = new CorpFeishuUser();
                 feishuUser.setOpenId(openId);

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

@@ -49,7 +49,7 @@ public class SampleTest {
 
     @Test
     public void testOceanEngineJob() {
-       List<UserAllocation>tokens = userAllocationService.getByProjectId(107L,null);
+       List<UserAllocation>tokens = userAllocationService.getByParams(107L,null,null);
        Date startDate = DateUtils.getDate();
        tokens.forEach(token -> {
            CtopOauthToken getToken  = oauthTokenService.getTokenByAccountId(token.getAccountId());

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/CorpFeishuUser.java

@@ -1,4 +1,4 @@
-package org.jeecg.modules.ctop.entity;
+package cn.com.ctop.common.module.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;

+ 18 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/CorpFeishuUserMapper.java

@@ -0,0 +1,18 @@
+package cn.com.ctop.common.module.mapper;
+
+import cn.com.ctop.common.module.entity.CorpFeishuUser;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 飞书用户信息
+ * @author: jeecg-boot
+ * @date:   2020-06-23
+ * @cersion: V1.0
+ */
+public interface CorpFeishuUserMapper extends BaseMapper<CorpFeishuUser> {
+
+    List<String> getOpenIdByParams(@Param(value = "projectId") Long projectId);
+}

+ 14 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CorpFeishuUserMapper.xml

@@ -0,0 +1,14 @@
+<?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.CorpFeishuUserMapper">
+
+    <select id="getOpenIdByParams" resultType="java.lang.String">
+        select
+            fuser.open_id
+        from
+            ctop_corp_feishu_user fuser
+        left join ctop_user_allocation allocation on allocation.user_id = fuser.user_id
+        where
+            allocation.project_id = #{projectId}
+    </select>
+</mapper>

+ 17 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/ICorpFeishuUserService.java

@@ -0,0 +1,17 @@
+package cn.com.ctop.common.module.service;
+
+import cn.com.ctop.common.module.entity.CorpFeishuUser;
+import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 飞书用户信息
+ * @author jeecg-boot
+ * @date   2020-06-23
+ * @version V1.0
+ */
+public interface ICorpFeishuUserService extends IService<CorpFeishuUser> {
+    CorpFeishuUser getByUserId(String userId);
+
+    JSONArray getOpenIdByParams(Long projectId);
+}

+ 1 - 3
module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -17,13 +17,11 @@ public interface IUserAllocationService extends IService<UserAllocation> {
 
     UserAllocation getByAccountId(Long accountId);
 
-    List<UserAllocation> getByProjectId(Long projectId, String systemType);
+    List<UserAllocation> getByParams(Long projectId, String systemType,Integer accountStatus);
 
     Map<String, Object> getPangolinAccountListByParams(String userId, JSONObject data);
 
     Map<String, Object> getPangolinProjectListByParams(String userId);
 
-    List<UserAllocation> selectAccountListByProjectId(Long projectId);
-
     List<UserAllocation> getByMediaId(String mediaId);
 }

+ 45 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CorpFeishuUserServiceImpl.java

@@ -0,0 +1,45 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.entity.CorpFeishuUser;
+import cn.com.ctop.common.module.mapper.CorpFeishuUserMapper;
+import cn.com.ctop.common.module.service.ICorpFeishuUserService;
+import com.alibaba.fastjson.JSONArray;
+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.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 飞书用户信息
+ * @author jeecg-boot
+ * @date   2020-06-23
+ * @version V1.0
+ */
+@Service
+public class CorpFeishuUserServiceImpl extends ServiceImpl<CorpFeishuUserMapper, CorpFeishuUser> implements ICorpFeishuUserService {
+
+    @Autowired
+    private CorpFeishuUserMapper corpFeishuUserMapper;
+    @Override
+    public CorpFeishuUser getByUserId(String userId) {
+        QueryWrapper<CorpFeishuUser>queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id",userId);
+        queryWrapper.orderByDesc("id").last("limit 1");
+        return this.getOne(queryWrapper);
+    }
+
+    @Override
+    public JSONArray getOpenIdByParams(Long projectId) {
+        List<String> openIds = corpFeishuUserMapper.getOpenIdByParams(projectId);
+        if(null == openIds&&openIds.isEmpty()){
+            return null;
+        }
+        JSONArray result = new JSONArray();
+        for(int i=0;i<openIds.size();i++){
+            result.add(openIds.get(i));
+        }
+        return result;
+    }
+}

+ 4 - 13
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -9,8 +9,6 @@ import cn.com.ctop.common.module.utils.StatusCode;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.context.annotation.Primary;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
@@ -24,11 +22,7 @@ import java.util.Map;
  * @Version: V1.0
  */
 @Service
-@Primary
 public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper, UserAllocation> implements IUserAllocationService {
-    @Autowired
-    private UserAllocationMapper userAllocationMapper;
-
     @Override
     public UserAllocation getByAccountId(Long accountId) {
         QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
@@ -37,7 +31,7 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     }
 
     @Override
-    public List<UserAllocation> getByProjectId(Long projectId, String systemType) {
+    public List<UserAllocation> getByParams(Long projectId, String systemType,Integer accountStatus) {
         QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
         if (null != projectId && projectId != 0) {
             queryWrapper.eq("project_id", projectId);
@@ -45,6 +39,9 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         if (null != systemType && !"".equals(systemType.trim())) {
             queryWrapper.eq("system_type", systemType);
         }
+        if(null!=accountStatus){
+            queryWrapper.eq("account_status",accountStatus);
+        }
         queryWrapper.orderByDesc("id");
         return this.list(queryWrapper);
     }
@@ -83,12 +80,6 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     }
 
     @Override
-    public List<UserAllocation> selectAccountListByProjectId(Long projectId) {
-        List<UserAllocation> list = userAllocationMapper.selectAccountListByProjectId(projectId);
-        return list;
-    }
-
-    @Override
     public List<UserAllocation> getByMediaId(String mediaId) {
         QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
         if ("".equals(mediaId)) {

+ 27 - 7
module-common/src/main/java/cn/com/feishu/provider/MessageProvider.java

@@ -2,22 +2,42 @@ package cn.com.feishu.provider;
 
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.feishu.constant.FeishuConstant;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 
-import java.util.List;
-
 public class MessageProvider {
-    public JSONObject batchSend(List<String> departmentIds,List<String> openIds,List<String> userIds,String content) throws Exception {
+    public static JSONObject batchSend(JSONArray departmentIds, JSONArray openIds, JSONArray userIds, String content) throws Exception {
         String tenantAccessToken = AuthProvider.getTenantAccessToken();
         JSONObject contentJson = new JSONObject();
         contentJson.put("text",content);
         JSONObject params = new JSONObject();
-        params.put("department_ids",departmentIds);
-        params.put("open_ids",openIds);
-        params.put("user_ids",userIds);
+        if(null!=departmentIds&&!departmentIds.isEmpty()){
+            params.put("department_ids",departmentIds);
+        }
+        if(null!=openIds&&!openIds.isEmpty()){
+            params.put("open_ids",openIds);
+        }
+        if(null!=userIds&&!userIds.isEmpty()){
+            params.put("user_ids",userIds);
+        }
         params.put("msg_type","text");
         params.put("content",contentJson);
-        return HttpUtils.feishuPostRequest("Bearer"+tenantAccessToken, FeishuConstant.FEISHU_API_URL+FeishuConstant.MESSAGE_BATCH_SEND,params);
+        return HttpUtils.feishuPostRequest("Bearer "+tenantAccessToken, FeishuConstant.FEISHU_API_URL+FeishuConstant.MESSAGE_BATCH_SEND,params);
+    }
+
+    public static void main(String[] args) {
+        JSONArray openIds = new JSONArray();
+        openIds.add("ou_e18db8d339cc33fe1446ff7bd774c074");
+        openIds.add("ou_08ec7422306fa2bfd1baae9b2f724cb4");
+        try {
+            StringBuffer text = new StringBuffer();
+            text.append("项目出价预警").append("\n\r").append("您的项目:").append( "测试项目,").append("")
+                    .append("授权名称为:伊对 下的,").append("").append("")
+                    .append("大于项目设置的最高出价:").append(10000 / 1000).append(" 元! 请您及时调整。");
+            batchSend(null,openIds,null,text.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
 

+ 89 - 0
module-common/src/main/java/cn/com/feishu/provider/SendImage.java

@@ -0,0 +1,89 @@
+package cn.com.feishu.provider;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.util.EntityUtils;
+import java.io.File;
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+
+
+public class SendImage {
+    public static CloseableHttpClient getHttpClient() {
+        try {
+            SSLContextBuilder builder = new SSLContextBuilder();
+            builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
+            SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(builder.build(),
+                    NoopHostnameVerifier.INSTANCE);
+            Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
+                    .register("http", new PlainConnectionSocketFactory())
+                    .register("https", sslConnectionSocketFactory)
+                    .build();
+            PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
+            cm.setMaxTotal(100);
+            CloseableHttpClient httpclient = HttpClients.custom()
+                    .setSSLSocketFactory(sslConnectionSocketFactory)
+                    .setDefaultCookieStore(new BasicCookieStore())
+                    .setConnectionManager(cm).build();
+            return httpclient;
+        } catch (KeyManagementException e) {
+            e.printStackTrace();
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        } catch (KeyStoreException e) {
+            e.printStackTrace();
+        }
+        return HttpClients.createDefault();
+    }
+    public static String SendImageByApacheHttpClient(File file,String tenantAccessToken) throws IOException {
+        CloseableHttpClient client = getHttpClient();
+        HttpPost post = new HttpPost("https://open.feishu.cn/open-apis/image/v4/put/");
+        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+        FileBody bin = new FileBody(file);
+        builder.addPart("image", bin);
+        builder.addTextBody("image_type", "message");
+        HttpEntity multiPartEntity = builder.build();
+        post.setEntity(multiPartEntity);
+        post.setHeader("Authorization", "Bearer "+tenantAccessToken);
+        CloseableHttpResponse response = client.execute(post);
+        System.out.println("http response code:" + response.getStatusLine().getStatusCode());
+        for (Header header: response.getAllHeaders()) {
+            System.out.println(header.toString());
+        }
+        HttpEntity resEntity = response.getEntity();
+        if (resEntity == null) {
+            System.out.println("never here?");
+            return "";
+        }
+        System.out.println("Response content length: " + resEntity.getContentLength());
+        return EntityUtils.toString(resEntity);
+    }
+    public static void main(String[] args) throws Exception {
+        File file = new File("D:\\android\\15812888.jpeg");
+        String token = AuthProvider.getTenantAccessToken();
+        String result = SendImageByApacheHttpClient(file,token);
+        System.out.println(result);
+        /**
+         * {"code":0,"msg":"ok","data":{"image_key":"img_f8bb4cdf-fd0b-4c29-98c5-5147efd4b13g"}}
+         */
+    }
+
+}

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

@@ -3,14 +3,18 @@ package cn.com.ctop.toutiao.modules.report.service.impl;
 import cn.com.ctop.common.module.entity.MailLog;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.MailLogMapper;
-import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.service.ICorpFeishuUserService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
 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 cn.com.feishu.provider.MessageProvider;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
@@ -21,13 +25,13 @@ import java.util.List;
 
 @Service
 @Primary
-
+@Slf4j
 public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourlyAccountWarningService {
 
     @Autowired
     private BytedanceAdvertiserHourlyReportMapper bytedanceAdvertiserHourlyReportMapper;
     @Autowired
-    private UserAllocationMapper userAllocationMapper;
+    private IUserAllocationService userAllocationService;
     @Autowired
     private MailLogMapper mailLogMapper;
     /**
@@ -38,17 +42,11 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
     @Override
     public void byteDanceAccountWarning(Long accountId, String statDate, String anotherDay) {
         try {
-
             Integer maxHour = bytedanceAdvertiserHourlyReportMapper.selectMaxHour(accountId, statDate);
             if (Check.isNull(maxHour)) {
                 return;
             }
-            QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
-            userAllocationQueryWrapper.eq("account_id", accountId);
-            userAllocationQueryWrapper.eq("media_id", 1);
-            userAllocationQueryWrapper.orderByDesc("create_time");
-            userAllocationQueryWrapper.last("limit 1");
-            UserAllocation userAllocation = userAllocationMapper.selectOne(userAllocationQueryWrapper);
+            UserAllocation userAllocation = userAllocationService.getByAccountId(accountId);
             if (Check.isNull(userAllocation)) {
                 return;
             }
@@ -58,20 +56,15 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
             BigDecimal warningAmount = userAllocation.getWarningAmount();
             BigDecimal warningProportion = userAllocation.getWarningProportion();
             BigDecimal nowCost = bytedanceAdvertiserHourlyReportMapper.getCost(accountId, maxHour, statDate);
-
             BigDecimal cost = nowCost.setScale(2, RoundingMode.HALF_UP);
-
-
             if (maxHour != 0) {
                 if (!Check.isNull(nowCost) && nowCost.compareTo(new BigDecimal(0)) != 0) {
                     BigDecimal lastHourCost = bytedanceAdvertiserHourlyReportMapper.getCost(accountId, maxHour - 1, statDate);
                     if (!Check.isNull(lastHourCost) && lastHourCost.compareTo(new BigDecimal(0)) != 0) {
-                        if (!Check.isNull(userAllocation)) {
-                            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(), userAllocation.getProjectName());
-                            }
+                        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(), userAllocation.getProjectName());
                         }
                     }
                 }
@@ -87,11 +80,9 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
                     }
                 }
             }
-
         } catch (Exception e) {
             e.printStackTrace();
         }
-
     }
 
 
@@ -103,8 +94,6 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
                 .append("相较于昨日 " + maxHour + "时").append("<br/>")
                 .append("出现消耗暴涨,").append("消耗金额为:" + nowCost).append("<br/>")
                 .append("请您及时查看!");
-
-
         QueryWrapper<MailLog> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("account_id", accountId);
         queryWrapper.eq("hour", maxHour);
@@ -131,11 +120,90 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
             List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
             CorpWexinUtils.sendMessage(wexinIds, text.toString());
         }
+    }
 
+    private void sendYesterdayFeishuMessage(Long accountId, String authName, Integer maxHour, BigDecimal nowCost, Long projectId, String projectName) throws Exception {
+        StringBuilder text = new StringBuilder();
+        text.append("较昨日同时段消耗预警").append("\n\r")
+                .append("您的项目:" + projectName + "下的,").append("\n\r")
+                .append("账号:").append(accountId + ",").append("授权名称为:" + authName).append("\n\r")
+                .append("相较于昨日 " + maxHour + "时").append("\n\r")
+                .append("出现消耗暴涨,").append("消耗金额为:" + nowCost).append("\n\r")
+                .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();
+            }
+            JSONArray openIds = feishuUserService.getOpenIdByParams(projectId);
+            MessageProvider.batchSend(null,openIds,null,text.toString());
+        }
     }
 
 
 
+    private void sendFeishuMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId, String projectName) throws Exception {
+        StringBuilder text = new StringBuilder();
+        text.append("较上时段消耗预警").append("\n\r")
+                .append("您的项目:" + projectName + " 下的").append("\n\r")
+                .append("账号:").append(accountId + ",").append("授权名称为:" + authName).append("\n\r")
+                .append(hour + " 时").append("相较于 " + (hour - 1) + " 时").append("\n\r")
+                .append("出现消耗暴涨,").append("消耗金额为:" + amount).append("\n\r")
+                .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();
+            }
+        }
+        JSONArray openIds = feishuUserService.getOpenIdByParams(projectId);
+        if(null == openIds&&openIds.isEmpty()){
+            log.error("该项目下运营飞书账号尚未绑定邮箱=>projectId:{}",projectId);
+            return;
+        }
+        MessageProvider.batchSend(null,openIds,null, text.toString());
+    }
+
+    @Autowired
+    private ICorpFeishuUserService feishuUserService;
+
     private void sendMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId, String projectName) {
 
         StringBuilder text = new StringBuilder();
@@ -172,7 +240,6 @@ public class ByteDanceHourlyAccountWarningServiceImpl implements IByteDanceHourl
         }
         List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
         CorpWexinUtils.sendMessage(wexinIds, text.toString());
-
     }