فهرست منبع

预警规则匹配逻辑——添加可复制规则功能

zhaoxian 4 سال پیش
والد
کامیت
3ee8eb0290
26فایلهای تغییر یافته به همراه648 افزوده شده و 81 حذف شده
  1. 1 33
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  2. 3 3
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleAccountTemplateController.java
  3. 23 9
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleAccountThresholdController.java
  4. 79 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleSwitchController.java
  5. 5 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleTemplateController.java
  6. 7 7
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleAccountThreshold.java
  7. 5 4
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/RuleAccountTemplateMapper.xml
  8. 9 1
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IRuleAccountThresholdService.java
  9. 3 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleAccountTemplateServiceImpl.java
  10. 122 2
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleAccountThresholdServiceImpl.java
  11. 1 1
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleGroupServiceImpl.java
  12. 16 2
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleTemplateServiceImpl.java
  13. 13 4
      module-common/src/main/java/cn/com/ctop/common/module/entity/RuleDataAccount.java
  14. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/RuleDataPlan.java
  15. 14 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java
  16. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java
  17. 10 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java
  18. 6 0
      module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDanceCheckAccountLandingPageJob.java
  19. 120 0
      module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDanceCheckAccountMonitoringLinkJob.java
  20. 49 0
      module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/RuleDataAccountCleanJob.java
  21. 7 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IRuleByteDanceAccountService.java
  22. 17 15
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ReportServiceImpl.java
  23. 45 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/RuleByteDanceAccountServiceImpl.java
  24. 6 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/tool/constants/QueryToolUrlConstant.java
  25. 23 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/tool/service/IByteDanceGetAccountFundService.java
  26. 60 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/tool/service/impl/ByteDanceGetAccountFundServiceImpl.java

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

@@ -6,11 +6,9 @@ import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
 import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
-import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouAgentAccountMapper;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
@@ -37,8 +35,6 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-import static org.jeecg.common.util.DateUtils.getAnotherDay;
-
 @RunWith(SpringRunner.class)
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("wps")
@@ -201,22 +197,6 @@ public class SampleTest {
         }
     }
 
-    @Autowired
-    private IKuaiShouDailyReportTaskService dailyReportTaskService;
-    /**
-     * 测试获取快手图片消耗数据入库
-     */
-    @Test
-    public void loadKuaishouImageTaskFile(){
-        String nowDate = DateUtils.getDate("yyyy-MM-dd");
-        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
-        for(int i=1;i<15;i++){
-            String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
-            tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
-        }
-        //  查询快手token
-    }
-
     @Test
     public void testLoadBytedanceImageData(){
         List<CtopOauthToken>tokens = tokenService.selectToutiaoToken();
@@ -238,8 +218,7 @@ public class SampleTest {
         System.out.println("素材数据获取完成");
 
     }
-    @Autowired
-    private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
+
     @Autowired
     private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
     @Test
@@ -279,17 +258,6 @@ public class SampleTest {
     @Autowired
     IUReportService uReportService;
 
-    @Test
-    public void loadBytedanceData(){
-        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
-        for (int i=0;i<tokens.size();i++) {
-            for(int j=0;j<4;j++){
-                String getDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -j));
-                bytedanceReportService.bytedanceVideoMaterialReport(tokens.get(i), getDate, getDate);
-            }
-        }
-    }
-
     @Autowired
     private IBytedanceReportService bytedanceReportService;
     @Test

+ 3 - 3
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleAccountTemplateController.java

@@ -70,12 +70,12 @@ public class RuleAccountTemplateController {
     /**
      * 查询账户下关联的模板
      *
-     * @param page
+     * @param pageNo
      * @param pageSize
      * @return
      */
     @GetMapping(value = "/getTemplateApplied")
-    public Result<PageInfo<TemplateAppliedVo>> getTemplateApplied(int page, int pageSize, Long accountId, String projectName, String userName) {
+    public Result<PageInfo<TemplateAppliedVo>> getTemplateApplied(int pageNo, int pageSize, Long accountId, String projectName, String userName) {
         Result<PageInfo<TemplateAppliedVo>> result = new Result<>();
         try {
             LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
@@ -94,7 +94,7 @@ public class RuleAccountTemplateController {
             if (!Check.isNull(userName)) {
                 requestMap.put("userName", userName);
             }
-            PageHelper.startPage(page, pageSize);
+            PageHelper.startPage(pageNo, pageSize);
             List<TemplateAppliedVo> list = ruleAccountTemplateService.getTemplateApplied(requestMap);
 
             PageInfo<TemplateAppliedVo> pageInfo = new PageInfo<>(list);

+ 23 - 9
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleAccountThresholdController.java

@@ -3,7 +3,9 @@ package cn.com.ctop.alarm.modules.controller;
 import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
 import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
 import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.utils.Check;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -19,15 +21,7 @@ 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.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
@@ -56,6 +50,26 @@ public class RuleAccountThresholdController {
     @Autowired
     private IRuleAccountThresholdService ruleAccountThresholdService;
 
+
+    @PostMapping(value = "/fillThreshold")
+    public Result<JSONObject> fillThreshold(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参为空");
+            }
+            JSONObject returnJson = ruleAccountThresholdService.fillThreshold(requestJson);
+            result.setSuccess(true);
+            result.setResult(returnJson);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
     /**
      * 分页列表查询
      *

+ 79 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleSwitchController.java

@@ -0,0 +1,79 @@
+package cn.com.ctop.alarm.modules.controller;
+
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/rule/switch/")
+public class RuleSwitchController {
+
+    @Autowired
+    IUserAllocationService userAllocationService;
+
+    /**
+     *  账户添加内广监测链接预警
+     */
+    @PostMapping(value = "/onOrOffMonitoringLink")
+    public Result<Object> onOrOffMonitoringLink(@RequestParam Long accountId, @RequestParam String switchType){
+        Result<Object> result=new Result<>();
+        UserAllocation userAllocation=new UserAllocation();
+        userAllocation.setAccountId(accountId);
+        UpdateWrapper<UserAllocation> wrapper=new UpdateWrapper<>();
+        //开启预警
+        if(switchType.equals("on")){
+            wrapper.set("landing_page",0);
+            wrapper.setEntity(userAllocation);
+            boolean update = userAllocationService.update(wrapper);
+            if(update){
+                result.success("监测链接预警开启成功");
+            }
+        }else if(switchType.equals("off")){
+            wrapper.set("landing_page",1);
+            wrapper.setEntity(userAllocation);
+            boolean update = userAllocationService.update(wrapper);
+            if(update){
+                result.success("监测链接预警关闭成功");
+            }
+        }else {
+            result.error500("未知操作");
+        }
+        return result;
+    }
+
+    /**
+     *  账户添加落地页链接预警
+     */
+    @PostMapping(value = "/onOrOffLandingPage")
+    public Result<Object> onOrOffLandingPage(@RequestParam Long accountId, @RequestParam String switchType){
+        Result<Object> result=new Result<>();
+        UserAllocation userAllocation=new UserAllocation();
+        userAllocation.setAccountId(accountId);
+        UpdateWrapper<UserAllocation> wrapper=new UpdateWrapper<>();
+        //开启预警
+        if(switchType.equals("on")){
+            wrapper.set("landing_page",0);
+            wrapper.setEntity(userAllocation);
+            boolean update = userAllocationService.update(wrapper);
+            if(update){
+                result.success("落地页链接预警开启成功");
+            }
+        }else if(switchType.equals("off")){
+            wrapper.set("landing_page",1);
+            wrapper.setEntity(userAllocation);
+            boolean update = userAllocationService.update(wrapper);
+            if(update){
+                result.success("落地页链接预警关闭成功");
+            }
+        }else {
+            result.error500("未知操作");
+        }
+        return result;
+    }
+}

+ 5 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleTemplateController.java

@@ -128,7 +128,12 @@ public class RuleTemplateController {
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      HttpServletRequest req) {
         Result<IPage<RuleTemplate>> result = new Result<>();
+        String templateName = ruleTemplate.getTemplateName();
+        ruleTemplate.setTemplateName(null);
         QueryWrapper<RuleTemplate> queryWrapper = QueryGenerator.initQueryWrapper(ruleTemplate, req.getParameterMap());
+        if (!Check.isNull(templateName)) {
+            queryWrapper.like("template_name", templateName);
+        }
         Page<RuleTemplate> page = new Page<RuleTemplate>(pageNo, pageSize);
         IPage<RuleTemplate> pageList = ruleTemplateService.page(page, queryWrapper);
         result.setSuccess(true);

+ 7 - 7
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleAccountThreshold.java

@@ -1,21 +1,17 @@
 package cn.com.ctop.alarm.modules.entity;
 
-import java.io.Serializable;
-import java.util.Date;
-
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableField;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
-import com.fasterxml.jackson.annotation.JsonFormat;
-import org.springframework.format.annotation.DateTimeFormat;
 import org.jeecgframework.poi.excel.annotation.Excel;
 
+import java.util.Date;
+
 /**
  * 规则关联账户 阈值
  *
@@ -42,6 +38,10 @@ public class RuleAccountThreshold {
     @Excel(name = "账户id", width = 15)
     @ApiModelProperty(value = "账户id")
     private Long accountId;
+
+    private Long groupId; // 组id
+    private String batchNo; // 批次号
+
     /**
      * 规则id
      */
@@ -53,7 +53,7 @@ public class RuleAccountThreshold {
      */
     @Excel(name = "阈值", width = 15)
     @ApiModelProperty(value = "阈值")
-    private String threshoId;
+    private String threshold;
     /**
      * createTime
      */

+ 5 - 4
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/RuleAccountTemplateMapper.xml

@@ -4,8 +4,9 @@
 
     <select id="getTemplateApplied" parameterType="Map"
             resultType="cn.com.ctop.alarm.modules.entity.vo.TemplateAppliedVo">
-        t1.account_id accountId,SELECT
-        t2.auth_name autnName,
+        select
+        t1.account_id accountId,
+        t2.auth_name authName,
         t1.template_id templateId,
         (
         SELECT
@@ -14,7 +15,7 @@
         ctop_rule_template
         WHERE
         id = t1.template_id
-        ) templateName,
+        ) as templateName,
         t3.id projectId,
         t3.project_name projectName,
         t2.user_id userId,
@@ -23,7 +24,7 @@
         ctop_rule_account_template t1
         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
-        left sys_user t4 on t2.user_id = t4.id
+        left join sys_user t4 on t2.user_id = t4.id
         where 1 = 1
         <if test="params.userId !=null and params.userId !='' ">
             and t2.user_id = #{params.userId}

+ 9 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IRuleAccountThresholdService.java

@@ -1,14 +1,22 @@
 package cn.com.ctop.alarm.modules.service;
 
 import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
  * @Description: 规则关联账户 阈值
  * @Author: jeecg-boot
- * @Date:   2020-11-15
+ * @Date: 2020-11-15
  * @Version: V1.0
  */
 public interface IRuleAccountThresholdService extends IService<RuleAccountThreshold> {
 
+    /**
+     * 阈值填充
+     *
+     * @param requestJson
+     * @return
+     */
+    JSONObject fillThreshold(JSONObject requestJson) throws Exception;
 }

+ 3 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleAccountTemplateServiceImpl.java

@@ -87,6 +87,9 @@ public class RuleAccountTemplateServiceImpl extends ServiceImpl<RuleAccountTempl
                 RuleAccountThreshold threshold = new RuleAccountThreshold();
                 threshold.setAccountId(accountId);
                 threshold.setRuleId(ruleBase.getId());
+                if (ruleBase.getVariableType() == 0) {
+                    threshold.setThreshold(ruleBase.getThreshold());
+                }
                 ruleAccountThresholdService.save(threshold);
             }
 

+ 122 - 2
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleAccountThresholdServiceImpl.java

@@ -3,17 +3,137 @@ package cn.com.ctop.alarm.modules.service.impl;
 import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
 import cn.com.ctop.alarm.modules.mapper.RuleAccountThresholdMapper;
 import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
+import cn.com.ctop.common.module.utils.Check;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
 
 /**
  * 规则关联账户 阈值
+ *
  * @author jeecg-boot
- * @date   2020-11-15
  * @version V1.0
+ * @date 2020-11-15
  */
 @Service
 public class RuleAccountThresholdServiceImpl extends ServiceImpl<RuleAccountThresholdMapper, RuleAccountThreshold> implements IRuleAccountThresholdService {
+    @Autowired
+    private RuleAccountThresholdMapper ruleAccountThresholdMapper;
+
+    /**
+     * 填充阈值
+     *
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public JSONObject fillThreshold(JSONObject requestJson) throws Exception {
+        Long accountId = requestJson.getLong("accountId");
+        if (Check.isNull(accountId)) {
+            throw new Exception("请传入账户id");
+        }
+        JSONArray ruleList = requestJson.getJSONArray("ruleList");
+        if (Check.isNull(ruleList)) {
+            throw new Exception("请输入具体的规则字段");
+        }
+        Integer updateCount = 0;
+        for (int i = 0; i < ruleList.size(); i++) {
+            JSONObject groupJson = ruleList.getJSONObject(i);
+            if (Check.isNull(groupJson)) {
+                continue;
+            }
+            JSONArray ruleDetail = groupJson.getJSONArray("ruleDetail");
+            if (Check.isNull(ruleDetail)) {
+                continue;
+            }
+
+            Long groupId = groupJson.getLong("groupId");
+            Integer isCopy = groupJson.getInteger("isCopy");
+
+            String batchNo = UUID.randomUUID().toString().replace(" ", "");
+
+            for (int j = 0; j < ruleDetail.size(); j++) {
+                if (isCopy == 1) { // 规则组可复制
+                    JSONArray ruleDetailArr = ruleDetail.getJSONArray(i);
+                    if (Check.isNull(ruleDetailArr)) {
+                        continue;
+                    }
+                    Map<String, Object> deleteMap = new HashMap<>();
+                    deleteMap.put("account_id", accountId);
+                    deleteMap.put("group_id", groupId);
+                    ruleAccountThresholdMapper.deleteByMap(deleteMap);
+                    for (int k = 0; k < ruleDetailArr.size(); k++) {
+                        JSONObject ruleJson = ruleDetailArr.getJSONObject(k);
+                        if (Check.isNull(ruleJson)) {
+                            continue;
+                        }
+                        Long ruleId = ruleJson.getLong("ruleId");
+                        if (Check.isNull(ruleId)) {
+                            continue;
+                        }
+                        String threshold = ruleJson.getString("threshold");
+                        if (Check.isNull(threshold)) {
+                            continue;
+                        }
+                        RuleAccountThreshold addRuleAccountThreshold = new RuleAccountThreshold();
+                        addRuleAccountThreshold.setAccountId(accountId);
+                        addRuleAccountThreshold.setGroupId(groupId);
+                        addRuleAccountThreshold.setThreshold(threshold);
+                        addRuleAccountThreshold.setRuleId(ruleId);
+                        addRuleAccountThreshold.setBatchNo(batchNo);
+                        int insert = ruleAccountThresholdMapper.insert(addRuleAccountThreshold);
+                        if (insert > 0) {
+                            updateCount += 1;
+                        }
+                    }
+                } else if (isCopy == 0) {
+
+
+                    JSONObject ruleJson = ruleDetail.getJSONObject(j);
+                    Long ruleId = ruleJson.getLong("ruleId");
+                    if (Check.isNull(ruleId)) {
+                        continue;
+                    }
+                    String threshold = ruleJson.getString("threshold");
+                    if (Check.isNull(threshold)) {
+                        continue;
+                    }
+                    RuleAccountThreshold updateThreshold = new RuleAccountThreshold();
+                    /*if (threshold.contains("[") && threshold.contains("]")) {
+                     *//*  String replace = threshold.replace("[", "").replace("]", "");
+                    List<String> strings = Arrays.asList(replace.split(","));
+                    JSONArray array = new JSONArray();
+                    for (int k = 0; k < strings.size(); k++) {
+                        array.add(strings.get(i))
+                         JSONArray.parseArray(strings);
+                    }*//*
+
+                    updateThreshold.setThreshoId(JSONArray.parseArray(threshold).toJSONString());
+                } else {
+
+                }*/
+                    updateThreshold.setThreshold(threshold);
+                    QueryWrapper<RuleAccountThreshold> updateQueryWrapper = new QueryWrapper();
+                    updateQueryWrapper.eq("account_id", accountId);
+                    updateQueryWrapper.eq("rule_id", ruleId);
+                    int update = ruleAccountThresholdMapper.update(updateThreshold, updateQueryWrapper);
+                    if (update > 0) {
+                        updateCount += 1;
+                    }
+                }
+            }
+        }
 
+        JSONObject returnJson = new JSONObject();
+        returnJson.put("code", 0);
+        returnJson.put("updateCount", updateCount);
+        return returnJson;
+    }
 }

+ 1 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleGroupServiceImpl.java

@@ -344,7 +344,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     return null;
                 }
                 for (RuleAccountThreshold threshold : thresholdList) {
-                    obj.put(String.valueOf(threshold.getRuleId()), threshold.getThreshoId());
+                    obj.put(String.valueOf(threshold.getRuleId()), threshold.getThreshold());
                 }
             }
         } catch (Exception e) {

+ 16 - 2
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleTemplateServiceImpl.java

@@ -255,7 +255,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
     public JSONObject queryDetailByAccountIdAndTemplateId(Long accountId, Long templateId) throws Exception {
         JSONObject returnJson = new JSONObject();
         RuleTemplate template = ruleTemplateMapper.selectById(templateId);
-        if (Check.isNull(ruleTemplateMapper)) {
+        if (Check.isNull(template)) {
             throw new Exception("获取模板基本信息为空");
         }
 
@@ -307,8 +307,21 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                 accountThresholdQueryWrapper.eq("rule_id", ruleId);
                 RuleAccountThreshold threshold = accountThresholdService.getOne(accountThresholdQueryWrapper);
                 if (!Check.isNull(threshold)) {
-                    ruleJson.put("threshold", threshold.getThreshoId());
+                    String value = threshold.getThreshold();
+                    if (!Check.isNull(value)) {
+                        if (value.contains("[") && value.contains("]")) {
+                            ruleJson.put("threshold", JSONArray.parseArray(value));
+                        } else {
+                            ruleJson.put("threshold", value);
+                        }
+                    } else {
+                        ruleJson.put("threshold", null);
+                    }
+                    // ruleJson.put("threshold", threshold.getThreshoId());
+                } else {
+                    ruleJson.put("threshold", null);
                 }
+
                 ruleJson.put("ruleDimension", ruleBase.getRuleDimension());
                 ruleJson.put("variableType", ruleBase.getVariableType());
                 ruleJson.put("isUnlimited", ruleBase.getIsUnlimited());
@@ -337,4 +350,5 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
         returnJson.put("ruleList", ruleList);
         return returnJson;
     }
+
 }

+ 13 - 4
module-common/src/main/java/cn/com/ctop/common/module/entity/RuleDataAccount.java

@@ -3,6 +3,7 @@ package cn.com.ctop.common.module.entity;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -22,11 +23,19 @@ import java.util.Date;
 @TableName("ctop_rule_data_account")
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
+@ApiModel(value="ctop_rule_data_account对象", description="规则账户清洗数据")
 public class RuleDataAccount {
 
-	@TableId(type = IdType.AUTO)
+	/**id*/
+    @ApiModelProperty(value = "id")
 	private Long id;
+	/**账户id*/
+	@Excel(name = "账户id", width = 15)
+    @ApiModelProperty(value = "账户id")
 	private Long accountId;
+	/**账户name*/
+	@Excel(name = "账户id", width = 15)
+	@ApiModelProperty(value = "账户id")
 	private String accountName;
 	/**消耗*/
 	@Excel(name = "消耗", width = 15)
@@ -52,6 +61,9 @@ public class RuleDataAccount {
 	@Excel(name = "nextDayOpenCost", width = 15)
     @ApiModelProperty(value = "nextDayOpenCost")
 	private BigDecimal nextDayOpenCost;
+
+	private BigDecimal nextDayOpenRate;
+
 	/**status*/
 	@Excel(name = "status", width = 15)
     @ApiModelProperty(value = "status")
@@ -62,7 +74,4 @@ public class RuleDataAccount {
 	/**updateTime*/
     @ApiModelProperty(value = "updateTime")
 	private Date updateTime;
-
-	public RuleDataAccount() {
-	}
 }

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

@@ -41,6 +41,8 @@ public class RuleDataPlan {
 	private String pricing;
 	private BigDecimal budget;
 	private Integer status;
+	private BigDecimal cpaBid;
+	private BigDecimal deepCpabid;
 	private Date createTime;
 	private Date updateTime;
 

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

@@ -112,6 +112,20 @@ public class UserAllocation implements Serializable {
     private Integer accountStatus;
 
     /**
+     * 检测链接预警
+     * 0 启动
+     * 1 禁用
+     */
+    private Integer monitoringLink;
+
+    /**
+     * 检测链接预警
+     * 0 启动
+     * 1 禁用
+     */
+    private Integer landingPage;
+
+    /**
      * 修改时间
      */
     @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")

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

@@ -32,4 +32,6 @@ public interface IUserAllocationService extends IService<UserAllocation> {
     List<JSONObject> getUserIdListByProjectId(Long projectId);
 
     List<JSONObject> getAccountIdListByUserId(Long userId);
+
+    List<UserAllocation> getUserAllocations(String mediaId ,int switchType);
 }

+ 10 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -119,4 +119,14 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     public List<JSONObject> getAccountIdListByUserId(Long userId) {
         return userAllocationMapper.getAccountIdListByUserId(userId);
     }
+
+    @Override
+    public List<UserAllocation> getUserAllocations(String mediaId, int switchType) {
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("media_id", mediaId);
+        queryWrapper.eq("account_status", 0);
+        queryWrapper.eq("monitoring_link", 0);
+        queryWrapper.orderByDesc("create_time");
+        return this.list(queryWrapper);
+    }
 }

+ 6 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDanceCheckAccountLandingPageJob.java

@@ -0,0 +1,6 @@
+package cn.com.ctop.job.bytedance.handler;
+
+public class ByteDanceCheckAccountLandingPageJob {
+
+
+}

+ 120 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDanceCheckAccountMonitoringLinkJob.java

@@ -0,0 +1,120 @@
+package cn.com.ctop.job.bytedance.handler;
+
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.toutiao.modules.material.entity.ByteDanceAdvertisePlan;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeService;
+import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xxl.job.core.log.XxlJobLogger;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+public class ByteDanceCheckAccountMonitoringLinkJob {
+
+    @Autowired
+    private IUserAllocationService allocationService;
+    @Autowired
+    private IByteDanceAdvertisePlanService advertisePlanService;
+    @Autowired
+    private IByteDanceCreativeService creativeService;
+    @Autowired
+    private ISendMessageService sendMessageService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
+    @XxlJob("byteDanceCheckAccountMonitoringLinkJob")
+    public ReturnT<String> execute(String param) throws Exception{
+
+        //查询开启监测链接预警的账户
+        //Todo 暂时单线程
+        List<UserAllocation> userAllocations=allocationService.getUserAllocations("1",0);
+        userAllocations.forEach(userAllocation->{
+            List<ByteDanceAdvertisePlan> plans = advertisePlanService.getAllPlans(userAllocation.getAccountId(), DateUtils.formatDate(new Date()));
+            if(null!=plans&&!plans.isEmpty()){
+                for (ByteDanceAdvertisePlan plan:plans) {
+                    Map<String, Object> creativeDetail = creativeService.getCreativeDetail(oauthTokenService.getTokenByAccountId(userAllocation.getAccountId()), plan.getId());
+                    if(null!=creativeDetail.get("data")){
+                        JSONObject data = (JSONObject) creativeDetail.get("data");
+                        checkMonitorLink(data,plan,userAllocation);
+                    }
+                }
+            }
+        });
+        XxlJobLogger.log("监测链接检查完成");
+        return ReturnT.SUCCESS;
+    }
+
+    private void checkMonitorLink(JSONObject data, ByteDanceAdvertisePlan plan, UserAllocation allocation) {
+        String downloadUrl = plan.getDownloadUrl();
+        boolean errorflag = false;
+        String errorMsg = "";
+        String token = plan.getName().split("-")[0];
+        if(null!=token&& "衍生计划".equals(token)){
+            token = plan.getName().split("-")[1];
+        }
+        String tokenInfo = "surl_token="+token;
+        String appType = plan.getAppType();
+
+        if(null!=downloadUrl){
+            if("APP_IOS".equals(appType)){
+                if(!downloadUrl.contains("https://apps.apple.com/cn/app")){
+                    errorMsg+= "应用下载链接填写异常;";
+                    errorflag = true;
+                }
+            }
+            if("APP_ANDROID".equals(appType)){
+                if(!downloadUrl.contains(token)){
+                    errorMsg+= "应用下载链接填写异常;";
+                    errorflag = true;
+                }
+            }
+        }
+        //展示监测链接
+        String trackUrl = data.getString("trackUrl");
+        if(null!=trackUrl&&!"".equals(trackUrl.trim())){
+            if(!trackUrl.contains(tokenInfo)){
+                errorMsg+= "展示监测链接填写异常;";
+                errorflag = true;
+            }
+        }
+        //点击监测链接
+        String actionTrackUrl = data.getString("actionTrackUrl");
+        if(null!=actionTrackUrl&&!"".equals(actionTrackUrl.trim())){
+            if("APP_IOS".equals(appType)){
+                if(!actionTrackUrl.contains(tokenInfo)||!actionTrackUrl.contains("app_platform=ios")){
+                    errorMsg+= "点击监测链接填写异常;";
+                    errorflag = true;
+                }
+            }
+            if("APP_ANDROID".equals(appType)){
+                if(!actionTrackUrl.contains(tokenInfo)||!actionTrackUrl.contains("tt/")){
+                    errorMsg+= "点击监测链接填写异常;";
+                    errorflag = true;
+                }
+            }
+        }
+        //视频有效播放监测链接
+        String videoPlayEffectiveTrackUrl = data.getString("videoPlayEffectiveTrackUrl");
+        if(null!=videoPlayEffectiveTrackUrl&&!"".equals(videoPlayEffectiveTrackUrl.trim())){
+            if(!videoPlayEffectiveTrackUrl.contains(tokenInfo)){
+                errorMsg+= "视频有效播放监测链接填写异常;";
+                errorflag = true;
+            }
+        }
+        if(errorflag){
+            sendMessage(allocation,"警告:账户:"+allocation.getAuthName()+"(id:"+allocation.getAccountId()+")下的广告计划:"+plan.getName()+"(id:"+plan.getId()+")"+"监测链接异常>>"+errorMsg);
+        }
+    }
+    private void sendMessage(UserAllocation allocation, String errorMsg) {
+        sendMessageService.sendMessage(allocation.getUserId(),errorMsg);
+    }
+}

+ 49 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/RuleDataAccountCleanJob.java

@@ -0,0 +1,49 @@
+package cn.com.ctop.job.bytedance.handler;
+
+/**
+ *  Created by JQ.bi on 2020.11.16
+ */
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.toutiao.modules.report.service.IRuleByteDanceAccountService;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xxl.job.core.log.XxlJobLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class RuleDataAccountCleanJob {
+
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
+    @Autowired
+    private IRuleByteDanceAccountService ruleByteDanceAccountService;
+
+    private ExecutorService executorPool = Executors.newFixedThreadPool(6);
+
+    @XxlJob("ruleDataAccountCleanJob")
+    public ReturnT<String> execute(String param) throws Exception {
+        XxlJobLogger.log("规则预警账户维度数据开始清洗");
+        //查询所有头条账户
+        List<CtopOauthToken> tokens = oauthTokenService.selectToutiaoToken();
+        if (null == tokens || tokens.isEmpty()) {
+            XxlJobLogger.log("未获取到可用的token");
+            return ReturnT.FAIL;
+        }
+        tokens.forEach(token->executorPool.submit(() -> {
+            ruleByteDanceAccountService.cleanRuleDataAccount(token.getAccountId());
+        }));
+        if(!executorPool.isShutdown()){
+            executorPool.shutdown();
+        }
+        XxlJobLogger.log("规则预警账户维度数据清洗结束");
+        return ReturnT.SUCCESS;
+    }
+}

+ 7 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IRuleByteDanceAccountService.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.toutiao.modules.report.service;
+
+public interface IRuleByteDanceAccountService {
+
+    void cleanRuleDataAccount(Long accountId);
+
+}

+ 17 - 15
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ReportServiceImpl.java

@@ -99,13 +99,13 @@ public class ReportServiceImpl implements IReportService {
             return;
         }
 
-        for (var i = 0; i < dataArray.size(); i++) {
-            var data = dataArray.getJSONObject(i);
+        for (int i = 0; i < dataArray.size(); i++) {
+            JSONObject data = dataArray.getJSONObject(i);
             if (null != conditions.getTimeGranularity() && conditions.getTimeGranularity().equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
-                var hourlyReport = new BytedanceAdvertiserHourlyReport(data);
+                BytedanceAdvertiserHourlyReport hourlyReport = new BytedanceAdvertiserHourlyReport(data);
                 advertiserHourlyReportService.saveOrUpdate(hourlyReport);
             } else {
-                var dailyReport = new BytedanceAdvertiserDailyReport(data);
+                BytedanceAdvertiserDailyReport dailyReport = new BytedanceAdvertiserDailyReport(data);
                 advertiserDailyReportService.saveOrUpdate(dailyReport);
             }
         }
@@ -185,20 +185,22 @@ public class ReportServiceImpl implements IReportService {
         UserAllocation allocation = userAllocationService.getByAccountId(token.getAccountId());
         for (var i = 0; i < dataArray.size(); i++) {
             var data = dataArray.getJSONObject(i);
-            var dailyReport = new RuleDataPlan(data, token.getAccountId());
-            dailyReport.setAccountName(allocation.getAuthName());
-            ByteDanceAdvertisePlan plan = advertiserDataService.getSinglePlanById(token,dailyReport.getId()+"");
+            var ruleDataPlan = new RuleDataPlan(data, token.getAccountId());
+            ruleDataPlan.setAccountName(allocation.getAuthName());
+            ByteDanceAdvertisePlan plan = advertiserDataService.getSinglePlanById(token,ruleDataPlan.getId()+"");
             if(null!=plan){
-                dailyReport.setBudget(plan.getBudget());
-                dailyReport.setDownloadUrl(plan.getDownloadUrl());
-                dailyReport.setExternalUrl(plan.getExternalUrl());
-                dailyReport.setPricing(plan.getPricing());
+                ruleDataPlan.setBudget(plan.getBudget());
+                ruleDataPlan.setDownloadUrl(plan.getDownloadUrl());
+                ruleDataPlan.setExternalUrl(plan.getExternalUrl());
+                ruleDataPlan.setPricing(plan.getPricing());
+                ruleDataPlan.setCpaBid(plan.getCpaBid());
+                ruleDataPlan.setDeepCpabid(plan.getDeepCpaBid());
                 RuleDataTarget target = new RuleDataTarget();
                 JSONObject audienceObject = JSONObject.parseObject(plan.getAudience());
                 target.setAccountId(token.getAccountId());
                 target.setAccountName(allocation.getAuthName());
-                target.setPlanId(dailyReport.getPlanId());
-                target.setId(dailyReport.getPlanId());
+                target.setPlanId(ruleDataPlan.getPlanId());
+                target.setId(ruleDataPlan.getPlanId());
                 target.setCreateTime(new Date());
                 target.setUpdateTime(new Date());
                 if(null!=audienceObject.getString("retargeting_tags_exclude")){
@@ -231,10 +233,10 @@ public class ReportServiceImpl implements IReportService {
                 Map<String, Object> creativeDetail = creativeService.getCreativeDetail(token, plan.getId());
                 if(null!=creativeDetail.get("data")){
                     JSONObject detail = (JSONObject) creativeDetail.get("data");
-                    formatCreativeData(detail,allocation,dailyReport);
+                    formatCreativeData(detail,allocation,ruleDataPlan);
                 }
             }
-            ruleDataPlanService.saveOrUpdate(dailyReport);
+            ruleDataPlanService.saveOrUpdate(ruleDataPlan);
         }
         getPlanRuleDataByPage(token, conditions, page + 1);
     }

+ 45 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/RuleByteDanceAccountServiceImpl.java

@@ -0,0 +1,45 @@
+package cn.com.ctop.toutiao.modules.report.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.RuleDataAccount;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IRuleDataAccountService;
+import cn.com.ctop.toutiao.modules.report.service.IRuleByteDanceAccountService;
+import cn.com.ctop.toutiao.modules.tool.service.IByteDanceGetAccountFundService;
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class RuleByteDanceAccountServiceImpl implements IRuleByteDanceAccountService {
+
+    @Autowired
+    IByteDanceGetAccountFundService byteDanceGetAccountFundService;
+    @Autowired
+    ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    IRuleDataAccountService ruleDataAccountService;
+
+    @Override
+    public void cleanRuleDataAccount(Long accountId) {
+        CtopOauthToken oauthToken=oauthTokenService.getTokenByAccountId(accountId);
+        //查询账户实时数据
+        JSONObject dataAccount=byteDanceGetAccountFundService.getAccountReportBy(oauthToken,accountId);
+        if(!dataAccount.isEmpty()){
+            JSONObject fundData=byteDanceGetAccountFundService.getAccountFundBy(oauthToken,accountId);
+            RuleDataAccount ruleDataAccount=new RuleDataAccount();
+            ruleDataAccount.setId(accountId);
+            ruleDataAccount.setAccountId(accountId);
+            ruleDataAccount.setAccountName(fundData.getString("name"));
+            ruleDataAccount.setCost(dataAccount.getBigDecimal("cost"));
+            ruleDataAccount.setValidBalance(fundData.getBigDecimal("valid_balance"));
+            ruleDataAccount.setConvertNum(dataAccount.getLong("convert"));
+            ruleDataAccount.setConvertCost(dataAccount.getBigDecimal("convert_cost"));
+            ruleDataAccount.setNextDayOpenNum(dataAccount.getLong("next_day_open"));
+            ruleDataAccount.setNextDayOpenCost(dataAccount.getBigDecimal("next_day_open_cost"));
+            ruleDataAccount.setNextDayOpenCost(dataAccount.getBigDecimal("next_day_open_rate"));
+
+            ruleDataAccountService.saveOrUpdate(ruleDataAccount);
+        }
+    }
+}

+ 6 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/tool/constants/QueryToolUrlConstant.java

@@ -44,4 +44,10 @@ public class QueryToolUrlConstant {
     //获取图片素材
     public static final String FILE_IMAGE_GET="https://ad.oceanengine.com/open_api/2/file/image/get/";
 
+    //查询账户余额
+    public static final String GET_ADVERTISER_FUND="https://ad.oceanengine.com/open_api/2/advertiser/fund/get/";
+
+    //查询账户当日实时数据
+    public static final String GET_ADVERTISER_REPORT="https://ad.oceanengine.com/open_api/2/report/advertiser/get/";
+
 }

+ 23 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/tool/service/IByteDanceGetAccountFundService.java

@@ -0,0 +1,23 @@
+package cn.com.ctop.toutiao.modules.tool.service;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ *  Created by JQ.bi on 2020.11.15
+ *
+ *  拉取账户余额
+ */
+public interface IByteDanceGetAccountFundService {
+
+    /**
+     * 获取账号余额信息
+     */
+    JSONObject getAccountFundBy(CtopOauthToken token, Long advertiserId);
+
+    /**
+     * 获取账号余额信息
+     */
+    JSONObject getAccountReportBy(CtopOauthToken token, Long advertiserId);
+
+}

+ 60 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/tool/service/impl/ByteDanceGetAccountFundServiceImpl.java

@@ -0,0 +1,60 @@
+package cn.com.ctop.toutiao.modules.tool.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.toutiao.modules.tool.constants.QueryToolUrlConstant;
+import cn.com.ctop.toutiao.modules.tool.service.IByteDanceGetAccountFundService;
+import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.log.XxlJobLogger;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.constant.SystemDateConstant;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class ByteDanceGetAccountFundServiceImpl implements IByteDanceGetAccountFundService {
+
+    @Override
+    public JSONObject getAccountFundBy(CtopOauthToken token, Long advertiserId) {
+
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        JSONObject params=new JSONObject();
+        params.put("advertiser_id",advertiserId);
+
+        JSONObject jsonObject = JSONObject.parseObject(HttpUtils.httpGetRequest(QueryToolUrlConstant.GET_ADVERTISER_FUND, headers,params));
+        if(jsonObject.getInteger("code")!=0){
+            XxlJobLogger.log("查询账户余额失败==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            return null;
+        }
+        return jsonObject.getJSONObject("data");
+    }
+
+    @Override
+    public JSONObject getAccountReportBy(CtopOauthToken token, Long advertiserId) {
+
+        JSONObject result= new JSONObject();
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        String now = DateUtils.getNowDate(SystemDateConstant.yyyy_MM_dd);
+        JSONObject params=new JSONObject();
+        params.put("advertiser_id",advertiserId);
+        params.put("start_date",now);
+        params.put("end_date",now);
+        JSONObject jsonObject = JSONObject.parseObject(HttpUtils.httpGetRequest(QueryToolUrlConstant.GET_ADVERTISER_REPORT, headers,params));
+        if(jsonObject.getInteger("code")!=0){
+            XxlJobLogger.log("账户{}获取实时数据失败---{}",advertiserId,jsonObject.getString("message"));
+        }else {
+            result= (JSONObject) jsonObject.getJSONObject("data").getJSONArray("list").get(0);
+        }
+        return result;
+    }
+}