Ver código fonte

Merge branch 'test' into test_v2

# Conflicts:
#	jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
yumeng 5 anos atrás
pai
commit
fc15324d42
17 arquivos alterados com 329 adições e 299 exclusões
  1. 10 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java
  2. 0 248
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MailLogController.java
  3. 59 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouHourlyAccountWarningLoadJob.java
  4. 5 5
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/BidWarningServiceImpl.java
  5. 7 26
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  6. 6 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/MailLog.java
  7. 13 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java
  8. 4 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/MailLogMapper.java
  9. 3 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/MailLogMapper.xml
  10. 2 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IMailLogService.java
  11. 4 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/MailLogServiceImpl.java
  12. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IAccountWarningService.java
  13. 174 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/AccountWarningServiceImpl.java
  14. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  15. 6 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouReportHourlyAccountMapper.java
  16. 20 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportHourlyAccountMapper.xml
  17. 9 9
      module-toutiao/src/main/java/cn/com/ctop/toutiao/service/impl/ByteDanceAdvertiserDataServiceImpl.java

+ 10 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -152,6 +153,8 @@ public class CallbackController {
                     //创建人
                     String userId = json.getString("userId");
                     Long projectId = json.getLong("projectId");
+                    BigDecimal WarningProportion = json.getBigDecimal("WarningProportion");
+                    BigDecimal WarningAmount = json.getBigDecimal("WarningAmount");
 
                     CtopOauthToken topOauthToken = new CtopOauthToken();
                     topOauthToken.setId(String.valueOf(accountId));
@@ -195,6 +198,9 @@ public class CallbackController {
                     userAllocation.setAccountId(accountId);
                     userAllocation.setProjectId(projectId);
                     userAllocation.setProjectName(projectName);
+                    userAllocation.setWarningProportion(WarningProportion);
+                    userAllocation.setWarningAmount(WarningAmount);
+
                     userAllocation.setCreateTime(new Date());
                     userAllocation.setUpdateTime(new Date());
                     allocationMapper.deleteById(userAllocation.getId());
@@ -281,6 +287,8 @@ public class CallbackController {
             String userName = json.getString("userName");
             Long projectId = json.getLong("projectId");
             String projectName = json.getString("projectName");
+            BigDecimal WarningProportion = json.getBigDecimal("WarningProportion");
+            BigDecimal WarningAmount = json.getBigDecimal("WarningAmount");
 
             JSONObject data = resultObject.getJSONObject("data");
             CtopOauthToken token = new CtopOauthToken(advertiserId, data);
@@ -315,6 +323,8 @@ public class CallbackController {
             userAllocation.setProjectName(projectName);
             userAllocation.setAuthName((String) advertiserDataMap.get("name"));
             userAllocation.setAdvertiserId(advertiserId);
+            userAllocation.setWarningProportion(WarningProportion);
+            userAllocation.setWarningAmount(WarningAmount);
             userAllocation.setCreateTime(new Date());
             userAllocation.setUpdateTime(new Date());
             allocationMapper.deleteById(userAllocation.getId());

+ 0 - 248
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MailLogController.java

@@ -1,248 +0,0 @@
-package org.jeecg.modules.ctop.controller;
-
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-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.MailLog;
-import org.jeecg.modules.ctop.service.IMailLogService;
-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;
-
-/**
- * 邮箱记录表
- *
- * @author jeecg-boot
- * @version V1.0
- * @date 2019-12-08
- */
-@Slf4j
-@Api(tags = "邮箱记录表")
-@RestController
-@RequestMapping("/top/mailLog")
-public class MailLogController {
-    @Autowired
-    private IMailLogService mailLogService;
-
-    /**
-     * 分页列表查询
-     *
-     * @param mailLog
-     * @param pageNo
-     * @param pageSize
-     * @param req
-     * @return
-     */
-    @AutoLog(value = "邮箱记录表-分页列表查询")
-    @ApiOperation(value = "邮箱记录表-分页列表查询", notes = "邮箱记录表-分页列表查询")
-    @GetMapping(value = "/list")
-    public Result<IPage<MailLog>> queryPageList(MailLog mailLog,
-                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
-                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
-                                                HttpServletRequest req) {
-        Result<IPage<MailLog>> result = new Result<IPage<MailLog>>();
-        QueryWrapper<MailLog> queryWrapper = QueryGenerator.initQueryWrapper(mailLog, req.getParameterMap());
-        Page<MailLog> page = new Page<MailLog>(pageNo, pageSize);
-        IPage<MailLog> pageList = mailLogService.page(page, queryWrapper);
-        result.setSuccess(true);
-        result.setResult(pageList);
-        return result;
-    }
-
-    /**
-     * 添加
-     *
-     * @param mailLog
-     * @return
-     */
-    @AutoLog(value = "邮箱记录表-添加")
-    @ApiOperation(value = "邮箱记录表-添加", notes = "邮箱记录表-添加")
-    @PostMapping(value = "/add")
-    public Result<MailLog> add(@RequestBody MailLog mailLog) {
-        Result<MailLog> result = new Result<MailLog>();
-        try {
-            mailLogService.save(mailLog);
-            result.success("添加成功!");
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
-            result.error500("操作失败");
-        }
-        return result;
-    }
-
-    /**
-     * 编辑
-     *
-     * @param mailLog
-     * @return
-     */
-    @AutoLog(value = "邮箱记录表-编辑")
-    @ApiOperation(value = "邮箱记录表-编辑", notes = "邮箱记录表-编辑")
-    @PutMapping(value = "/edit")
-    public Result<MailLog> edit(@RequestBody MailLog mailLog) {
-        Result<MailLog> result = new Result<MailLog>();
-        MailLog mailLogEntity = mailLogService.getById(mailLog.getId());
-        if (mailLogEntity == null) {
-            result.error500("未找到对应实体");
-        } else {
-            boolean ok = mailLogService.updateById(mailLog);
-            if (ok) {
-                result.success("修改成功!");
-            }
-        }
-
-        return result;
-    }
-
-    /**
-     * 通过id删除
-     *
-     * @param id
-     * @return
-     */
-    @AutoLog(value = "邮箱记录表-通过id删除")
-    @ApiOperation(value = "邮箱记录表-通过id删除", notes = "邮箱记录表-通过id删除")
-    @DeleteMapping(value = "/delete")
-    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
-        try {
-            mailLogService.removeById(id);
-        } catch (Exception e) {
-            log.error("删除失败", e.getMessage());
-            return Result.error("删除失败!");
-        }
-        return Result.ok("删除成功!");
-    }
-
-    /**
-     * 批量删除
-     *
-     * @param ids
-     * @return
-     */
-    @AutoLog(value = "邮箱记录表-批量删除")
-    @ApiOperation(value = "邮箱记录表-批量删除", notes = "邮箱记录表-批量删除")
-    @DeleteMapping(value = "/deleteBatch")
-    public Result<MailLog> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
-        Result<MailLog> result = new Result<MailLog>();
-        if (ids == null || "".equals(ids.trim())) {
-            result.error500("参数不识别!");
-        } else {
-            this.mailLogService.removeByIds(Arrays.asList(ids.split(",")));
-            result.success("删除成功!");
-        }
-        return result;
-    }
-
-    /**
-     * 通过id查询
-     *
-     * @param id
-     * @return
-     */
-    @AutoLog(value = "邮箱记录表-通过id查询")
-    @ApiOperation(value = "邮箱记录表-通过id查询", notes = "邮箱记录表-通过id查询")
-    @GetMapping(value = "/queryById")
-    public Result<MailLog> queryById(@RequestParam(name = "id", required = true) String id) {
-        Result<MailLog> result = new Result<MailLog>();
-        MailLog mailLog = mailLogService.getById(id);
-        if (mailLog == null) {
-            result.error500("未找到对应实体");
-        } else {
-            result.setResult(mailLog);
-            result.setSuccess(true);
-        }
-        return result;
-    }
-
-    /**
-     * 导出excel
-     *
-     * @param request
-     * @param response
-     */
-    @RequestMapping(value = "/exportXls")
-    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
-        // Step.1 组装查询条件
-        QueryWrapper<MailLog> queryWrapper = null;
-        try {
-            String paramsStr = request.getParameter("paramsStr");
-            if (oConvertUtils.isNotEmpty(paramsStr)) {
-                String deString = URLDecoder.decode(paramsStr, "UTF-8");
-                MailLog mailLog = JSON.parseObject(deString, MailLog.class);
-                queryWrapper = QueryGenerator.initQueryWrapper(mailLog, request.getParameterMap());
-            }
-        } catch (UnsupportedEncodingException e) {
-            e.printStackTrace();
-        }
-
-        //Step.2 AutoPoi 导出Excel
-        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
-        List<MailLog> pageList = mailLogService.list(queryWrapper);
-        //导出文件名称
-        mv.addObject(NormalExcelConstants.FILE_NAME, "邮箱记录表列表");
-        mv.addObject(NormalExcelConstants.CLASS, MailLog.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<MailLog> listMailLogs = ExcelImportUtil.importExcel(file.getInputStream(), MailLog.class, params);
-                mailLogService.saveBatch(listMailLogs);
-                return Result.ok("文件导入成功!数据行数:" + listMailLogs.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("文件导入失败!");
-    }
-
-}

+ 59 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouHourlyAccountWarningLoadJob.java

@@ -0,0 +1,59 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.CtopAdConstant;
+import cn.com.ctop.kuaishou.modules.batch.service.IAccountWarningService;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+import static org.jeecg.common.util.DateUtils.getAnotherDay;
+
+/**
+ * 获取广告主分时报表
+ *
+ * @author syh
+ */
+@Slf4j
+public class KuaishouHourlyAccountWarningLoadJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IAccountWarningService accountWarningService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                log.info("开始时段消耗预警定时任务");
+                long l = System.currentTimeMillis();
+                try {
+                    List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                    if (null == tokens || tokens.size() <= 0) {
+                        log.info("定时获取头条数据异常:未获取到可用的token");
+                        return;
+                    }
+                    String statDate = DateUtils.getDate("yyyy-MM-dd");
+                    String anotherDay = getAnotherDay("yyyy-MM-dd", statDate, -1);
+
+                    for (CtopOauthToken token : tokens) {
+                        accountWarningService.accountWarning(token.getAccountId(), statDate, anotherDay);
+                    }
+                    log.info("开始时段消耗预警定时任务执行完毕,耗时:{} ms", System.currentTimeMillis() - l);
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+
+                }
+            }
+        };
+        thread.start();
+    }
+}

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

@@ -1,6 +1,8 @@
 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.utils.Check;
 import cn.com.ctop.common.module.utils.CorpWexinUtils;
@@ -10,9 +12,7 @@ import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
-import org.jeecg.modules.ctop.entity.MailLog;
 import org.jeecg.modules.ctop.entity.Project;
-import org.jeecg.modules.ctop.mapper.MailLogMapper;
 import org.jeecg.modules.ctop.mapper.ProjectMapper;
 import org.jeecg.modules.ctop.service.IBidWarningService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -80,16 +80,15 @@ public class BidWarningServiceImpl implements IBidWarningService {
     private void sendMessage(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);
+        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(projectName + ",").append("<br/>")
+        text.append("项目出价预警").append("<br/>").append("您的项目:").append(projectName + ",").append("<br/>")
                 .append("授权名称为:" + authName + " 下的,").append("<br/>").append(s)
                 .append("大于项目设置的最高出价:").append(maxBid / 1000).append(" 元! 请您及时调整。");
         if (count < 3) {
@@ -99,6 +98,7 @@ public class BidWarningServiceImpl implements IBidWarningService {
                 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);

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

@@ -1,14 +1,10 @@
 package org.jeecg;
 
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
-import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.HttpUtils2;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
+import cn.com.ctop.kuaishou.modules.batch.service.IAccountWarningService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.impl.client.BasicCookieStore;
 import org.jeecg.modules.ctop.service.IBidWarningService;
@@ -27,9 +23,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
@@ -117,9 +111,6 @@ public class SampleTest {
         sender.send();
     }
 
-    @Autowired
-    private CtopOauthTokenMapper oauthTokenMapper;
-
     @Test
     public void loadKuaishouDataSingle() throws Exception {
         String url = "https://a201903112120030590198943.szwego.com/static/index.html#/shop_detail/A201903112120030590198943";
@@ -149,31 +140,21 @@ public class SampleTest {
 
     @Test
     public void testMail() throws Exception {
-        QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("account_id", 35675);
-        CtopOauthToken token = oauthTokenMapper.selectOne(queryWrapper);
-
-        kuaishouInterfaceService.getCreativeList(token, null, null);
-
         // String accessToken, Long advertiserId, Date startDate, Date endDate, Integer page
-        //   kuaishouInterfaceService.getTargetingTags(35675L, "83dbda039c238c3d3484df248866815c");
+        kuaishouInterfaceService.getGroupList("adf659b9b43e8952f9a3f0c5269505ca", 35675L, null, null, 1);
     }
 
 
     @Autowired
     private IBidWarningService bidWarningService;
 
+    @Autowired
+    private IAccountWarningService accountWarningService;
+
     @Test
     public void testMa() throws Exception {
-        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/dmp/population/list";
-        Map<String, String> headers = new HashMap<String, String>();
-        headers.put("Access-Token", "4e0c7411f78d47cce7a77b2d40b283f2");
-        headers.put("Content-Type", " application/json");
-        JSONObject requestJson = new JSONObject();
-        requestJson.put("advertiser_id", 23212L);
-        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
-        JSONObject resultJson = JSONObject.parseObject(result);
-        System.err.println(resultJson);
+       // accountWarningService.accountWarning(23212L);
+
     }
 
 

+ 6 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/MailLog.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;
@@ -56,6 +56,11 @@ public class MailLog {
     @Excel(name = "内容", width = 15)
     @ApiModelProperty(value = "内容")
     private String content;
+
+
+    private Integer mailType;
+    private Integer hour;
+
     /**
      * 创建时间
      */

+ 13 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java

@@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
 import org.jeecgframework.poi.excel.annotation.Excel;
 import org.springframework.format.annotation.DateTimeFormat;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -81,6 +82,18 @@ public class UserAllocation {
     @Excel(name = "输入账号  --登陆", width = 15)
     @ApiModelProperty(value = "输入账号  --登陆")
     private String accountName;
+
+
+    /**
+     * 预警 金额
+     */
+    private BigDecimal warningAmount;
+
+    /**
+     * 预警 比例
+     */
+    private BigDecimal warningProportion;
+
     /**
      * 创建时间
      */

+ 4 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/MailLogMapper.java

@@ -1,8 +1,8 @@
-package org.jeecg.modules.ctop.mapper;
+package cn.com.ctop.common.module.mapper;
 
+import cn.com.ctop.common.module.entity.MailLog;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
-import org.jeecg.modules.ctop.entity.MailLog;
 
 import java.util.List;
 
@@ -15,9 +15,10 @@ import java.util.List;
  */
 public interface MailLogMapper extends BaseMapper<MailLog> {
 
-    Integer selectCountByAccountIdAndDate(@Param("accountId") Long accountId, @Param("createTime") String createTime);
+    Integer selectCountByAccountIdAndDate(@Param("accountId") Long accountId, @Param("createTime") String createTime, @Param("type") Integer type);
 
     List<String> selectMailList(@Param("projectId") Long projectId);
 
     List<String> selectWeiXinIdList(@Param("projectId") Long projectId);
+
 }

+ 3 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/MailLogMapper.xml

@@ -1,6 +1,6 @@
 <?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.MailLogMapper">
+<mapper namespace="cn.com.ctop.common.module.mapper.MailLogMapper">
 
 
     <select id="selectCountByAccountIdAndDate" resultType="java.lang.Integer">
@@ -11,6 +11,7 @@
         ctop_mail_log
         where account_id = #{accountId}
         and DATE_FORMAT(create_time,'%Y-%m-%d') = #{createTime}
+        and mail_type = #{type}
 
 
     </select>
@@ -38,4 +39,5 @@
     </select>
 
 
+
 </mapper>

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

@@ -1,7 +1,7 @@
-package org.jeecg.modules.ctop.service;
+package cn.com.ctop.common.module.service;
 
+import cn.com.ctop.common.module.entity.MailLog;
 import com.baomidou.mybatisplus.extension.service.IService;
-import org.jeecg.modules.ctop.entity.MailLog;
 
 /**
  * 邮箱记录表

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

@@ -1,9 +1,9 @@
-package org.jeecg.modules.ctop.service.impl;
+package cn.com.ctop.common.module.service.impl;
 
+import cn.com.ctop.common.module.entity.MailLog;
+import cn.com.ctop.common.module.mapper.MailLogMapper;
+import cn.com.ctop.common.module.service.IMailLogService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.jeecg.modules.ctop.entity.MailLog;
-import org.jeecg.modules.ctop.mapper.MailLogMapper;
-import org.jeecg.modules.ctop.service.IMailLogService;
 import org.springframework.stereotype.Service;
 
 /**

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IAccountWarningService.java

@@ -0,0 +1,5 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+public interface IAccountWarningService {
+    void accountWarning(Long account, String statDate, String anotherDay);
+}

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

@@ -0,0 +1,174 @@
+package cn.com.ctop.kuaishou.modules.batch.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.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.service.IAccountWarningService;
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportHourlyAccountMapper;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.List;
+
+@Service
+public class AccountWarningServiceImpl implements IAccountWarningService {
+    @Autowired
+    private KuaishouReportHourlyAccountMapper hourlyAccountMapper;
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private MailLogMapper mailLogMapper;
+
+
+    /**
+     * 账户 出价预警
+     *
+     * @param accountId
+     */
+    @Override
+    public void accountWarning(Long accountId, String statDate, String anotherDay) {
+        try {
+
+
+            Integer maxHour = hourlyAccountMapper.selectMaxHour(accountId, statDate);
+            if (Check.isNull(maxHour)) {
+                return;
+            }
+
+            QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
+            userAllocationQueryWrapper.eq("account_id", accountId);
+            userAllocationQueryWrapper.eq("media_id", 2);
+            userAllocationQueryWrapper.orderByDesc("create_time");
+            userAllocationQueryWrapper.last("limit 1");
+            UserAllocation userAllocation = userAllocationMapper.selectOne(userAllocationQueryWrapper);
+            if (Check.isNull(userAllocation)) {
+                return;
+
+            }
+            BigDecimal warningAmount = userAllocation.getWarningAmount();
+            BigDecimal warningProportion = userAllocation.getWarningProportion();
+            BigDecimal nowCost = hourlyAccountMapper.getCost(accountId, maxHour, statDate);
+            if (maxHour != 0) {
+                if (!Check.isNull(nowCost) && nowCost.compareTo(new BigDecimal(0)) != 0) {
+                    BigDecimal lastHourCost = hourlyAccountMapper.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, nowCost, userAllocation.getProjectId());
+                            }
+                        }
+
+                    }
+
+                }
+            }
+
+
+            if (!Check.isNull(nowCost) && nowCost.compareTo(new BigDecimal(0)) != 0) {
+                BigDecimal yesterdayHourCost = hourlyAccountMapper.getCost(accountId, maxHour, anotherDay);
+                if (!Check.isNull(yesterdayHourCost) && yesterdayHourCost.compareTo(new BigDecimal(0)) != 0) {
+                    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());
+                    }
+                }
+
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    private void sendYesterdayMessage(Long accountId, String authName, Integer maxHour, BigDecimal nowCost, Long projectId) {
+
+        StringBuilder text = new StringBuilder();
+        text.append("较昨日同时段消耗预警").append("<br/>").append("您的账号:").append(accountId + ",").append("<br/>")
+                .append("授权名称为:" + authName + "相较于昨日").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<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+            CorpWexinUtils.sendMessage(wexinIds, text.toString());
+        }
+
+
+    }
+
+
+    private void sendMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId) {
+
+        StringBuilder text = new StringBuilder();
+        text.append("较上时段消耗预警").append("<br/>").append("您的账号:").append(accountId + ",").append("<br/>")
+                .append("授权名称为:" + authName + ",").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<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
+        CorpWexinUtils.sendMessage(wexinIds, text.toString());
+
+    }
+
+
+}

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -148,6 +148,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             kuaishouReportHourlyAccount.setUpdateTime(new Date());
             hourlyAccountService.saveOrUpdate(kuaishouReportHourlyAccount);
         }
+
+
     }
 
     /**

+ 6 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouReportHourlyAccountMapper.java

@@ -2,6 +2,12 @@ package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyAccount;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
 
 public interface KuaishouReportHourlyAccountMapper extends BaseMapper<KuaishouReportHourlyAccount> {
+    Integer selectMaxHour(@Param("accountId") Long accountId, @Param("statDate") String statDate);
+
+    BigDecimal getCost(@Param("accountId") Long accountId, @Param("statHour") Integer statHour, @Param("statDate") String statDate);
 }

+ 20 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportHourlyAccountMapper.xml

@@ -2,4 +2,24 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportHourlyAccountMapper">
 
+    <select id="selectMaxHour" resultType="java.lang.Integer">
+        select max(stat_hour)
+        from
+        ctop_kuaishou_report_hourly_account
+        where account_id = #{accountId}
+        and stat_date = #{statDate}
+
+    </select>
+
+    <select id="getCost" resultType="java.math.BigDecimal">
+        select charge
+        from
+        ctop_kuaishou_report_hourly_account
+        where
+        account_id = #{accountId}
+        and stat_date = #{statDate}
+        and stat_hour = #{statHour}
+
+    </select>
+
 </mapper>

+ 9 - 9
module-toutiao/src/main/java/cn/com/ctop/toutiao/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -81,17 +81,19 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
 
     public void getAd(String accountId, int pageNum, String ids, String date) {
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId);
-        String[] idString = ids.split(StringUtils.COMMA);
-        JSONArray getIds = new JSONArray();
-        if (null != idString && idString.length > 0) {
-            for (int i = 0; i < idString.length; i++) {
-                Long getId = Long.parseLong(idString[i]);
-                getIds.add(getId);
+        JSONArray getIds = null;
+        if (null != ids && !ids.equals("")) {
+            String[] idString = ids.split(StringUtils.COMMA);
+            if (null != idString && idString.length > 0) {
+                for (int i = 0; i < idString.length; i++) {
+                    Long getId = Long.parseLong(idString[i]);
+                    getIds.add(getId);
+                }
             }
         }
 
         // 请求地址
-        String url = "https://ad.toutiao.com/open_api/2/ad/get/";
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
         // 请求参数
         Map<String, Object> filtering = new HashMap<>();
         if (null != getIds && getIds.size() > 0) {
@@ -106,9 +108,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         param.put("page", pageNum);
         param.put("page_size", 100);
         param.put("filtering", filtering);
-        log.info("查询广告计划信息参数:{}", param.toJSONString());
         JSONObject resultObject = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, param);
-        log.info("获取公告计划信息返回数据:{}", resultObject.toJSONString());
         Integer code = resultObject.getInteger("code");
         if (null == code || !code.equals(0)) {
             log.error("获取广告计划信息接口异常==》accountId:{},message:{}", accountId, resultObject.getString("message"));