Procházet zdrojové kódy

加速探索初版

zhaoxian před 3 roky
rodič
revize
7e94cae48c

+ 1 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -212,6 +212,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/dimension/kuaiShouDimensionAccount/*", "anon");
         filterChainDefinitionMap.put("/ai/projectCreate/*", "anon");
         filterChainDefinitionMap.put("/cwjsPolicyInfo/**", "anon");
+        filterChainDefinitionMap.put("/explores/**", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 36 - 23
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouGroupExploreController.java

@@ -1,3 +1,4 @@
+
 package cn.com.ctop.kuaishou.modules.report.controller;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouGroupExplore;
@@ -11,11 +12,19 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+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.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Arrays;
 
+
 /**
  * 广告组的加速探索报表
  *
@@ -23,14 +32,16 @@ import java.util.Arrays;
  * @version V1.0
  * @date 2021-02-02
  */
+
 @Slf4j
 @Api(tags = "广告组的加速探索报表")
 @RestController
-@RequestMapping("/explore")
+@RequestMapping("/explores")
 public class KuaishouGroupExploreController {
     @Autowired
     private IKuaishouGroupExploreService kuaishouGroupExploreService;
 
+
     /**
      * 分页列表查询
      *
@@ -40,6 +51,7 @@ public class KuaishouGroupExploreController {
      * @param req
      * @return
      */
+
     @GetMapping(value = "/list")
     public Result<IPage<KuaishouGroupExplore>> queryPageList(KuaishouGroupExplore kuaishouGroupExplore,
                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@@ -54,76 +66,71 @@ public class KuaishouGroupExploreController {
         return result;
     }
 
+
     /**
      * 查询加速探索信息接口
      *
      * @param data
      * @return
      */
+
     @PostMapping(value = "/unitExploreInfoGet")
     public Result<Object> unitExploreInfoGet(@RequestBody JSONObject data) {
         try {
-            return kuaishouGroupExploreService.unitExploreInfoGet(data);
+            return kuaishouGroupExploreService.unitExploreInfoGet(data.getLong("accountId"), data.getLong("unitId"));
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             return Result.error("操作失败");
         }
     }
 
-    /**
-     * 广告组的加速探索预算设置接口
-     *
-     * @param data
-     * @return
-     */
+
     @PostMapping(value = "/unitExploreBudgetUpdate")
     public Result<Object> unitExploreBudgetUpdate(@RequestBody JSONObject data) {
         try {
-            return kuaishouGroupExploreService.unitExploreBudgetUpdate(data);
+            return kuaishouGroupExploreService.unitExploreBudgetUpdate(data.getLong("accountId"), data.getLong("unitId"), data.getLong("exploreBudget"));
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             return Result.error("操作失败");
         }
     }
 
-    /**
-     * 暂停广告组的加速探索预算接口
-     *
-     * @param data
-     * @return
-     */
-    @PostMapping(value = "/unitExploreStatusPause")
-    public Result<Object> unitExploreStatusPause(@RequestBody JSONObject data) {
+    @PostMapping(value = "/querySpeedExploreReport")
+    public Result<Object> querySpeedExploreReport(@RequestBody JSONObject data) {
         try {
-            return kuaishouGroupExploreService.unitExploreStatusPause(data);
+            return kuaishouGroupExploreService.querySpeedExploreReport(data.getLong("accountId"), data.getLong("unitId"), data.getInteger("exploreBudget"), data.getLong("max_explore_budget"));
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             return Result.error("操作失败");
         }
     }
 
+
     /**
-     * 查询广告组的加速探索报表接口
+     * 暂停广告组的加速探索预算接口
      *
      * @param data
      * @return
      */
-    @PostMapping(value = "/querySpeedExploreReport")
-    public Result<Object> querySpeedExploreReport(@RequestBody JSONObject data) {
+
+    @PostMapping(value = "/unitExploreStatusPause")
+    public Result<Object> unitExploreStatusPause(@RequestBody JSONObject data) {
         try {
-            return kuaishouGroupExploreService.querySpeedExploreReport(data);
+            return kuaishouGroupExploreService.unitExploreStatusPause(data);
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             return Result.error("操作失败");
         }
     }
 
+
     /**
      * 辅助探索
      *
      * @param data
      * @return
      */
+
     @PostMapping(value = "/adUnitExploreSupport")
     public Result<Object> adUnitExploreSupport(@RequestBody JSONObject data) {
         try {
@@ -141,6 +148,7 @@ public class KuaishouGroupExploreController {
      * @param kuaishouGroupExplore
      * @return
      */
+
     @PostMapping(value = "/add")
     public Result<KuaishouGroupExplore> add(@RequestBody KuaishouGroupExplore kuaishouGroupExplore) {
         Result<KuaishouGroupExplore> result = new Result<>();
@@ -160,6 +168,7 @@ public class KuaishouGroupExploreController {
      * @param kuaishouGroupExplore
      * @return
      */
+
     @PutMapping(value = "/edit")
     public Result<KuaishouGroupExplore> edit(@RequestBody KuaishouGroupExplore kuaishouGroupExplore) {
         Result<KuaishouGroupExplore> result = new Result<KuaishouGroupExplore>();
@@ -176,12 +185,14 @@ public class KuaishouGroupExploreController {
         return result;
     }
 
+
     /**
      * 通过id删除
      *
      * @param id
      * @return
      */
+
     @DeleteMapping(value = "/delete")
     public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
         try {
@@ -199,6 +210,7 @@ public class KuaishouGroupExploreController {
      * @param ids
      * @return
      */
+
     @DeleteMapping(value = "/deleteBatch")
     public Result<KuaishouGroupExplore> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
         Result<KuaishouGroupExplore> result = new Result<>();
@@ -217,6 +229,7 @@ public class KuaishouGroupExploreController {
      * @param id
      * @return
      */
+
     @GetMapping(value = "/queryById")
     public Result<KuaishouGroupExplore> queryById(@RequestParam(name = "id", required = true) String id) {
         Result<KuaishouGroupExplore> result = new Result<>();

+ 5 - 5
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouGroupExploreService.java

@@ -11,20 +11,20 @@ import java.math.BigDecimal;
 /**
  * @Description: 广告组的加速探索报表
  * @Author: jeecg-boot
- * @Date:   2021-02-02
+ * @Date: 2021-02-02
  * @Version: V1.0
  */
 public interface IKuaishouGroupExploreService extends IService<KuaishouGroupExplore> {
 
-    Result<Object> unitExploreInfoGet(JSONObject data);
+    Result<Object> unitExploreInfoGet(Long accountId, Long unitId);
 
-    Result<Object> unitExploreBudgetUpdate(JSONObject data);
+    Result<Object> unitExploreBudgetUpdate(Long accountId, Long unitId, Long exploreBudget);
 
     Result<Object> unitExploreStatusPause(JSONObject data);
 
-    Result<Object> querySpeedExploreReport(JSONObject data);
+    Result<Object> querySpeedExploreReport(Long accountId, Long unitId, Integer exploreStatus, Long maxExploreBudget);
 
-    void unitOpenSpeedExplore(Long accountId, Long unitId, BigDecimal groupAccount,Long accountExploreId);
+    void unitOpenSpeedExplore(Long accountId, Long unitId, BigDecimal groupAccount, Long accountExploreId);
 
     void getReportByAccount(CtopOauthToken token);
 

+ 50 - 41
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouGroupExploreServiceImpl.java

@@ -2,12 +2,20 @@ package cn.com.ctop.kuaishou.modules.report.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
-import cn.com.ctop.common.module.utils.*;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.common.module.utils.StatusCode;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouGroupSpeedExploreLog;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouGroupSpeedExploreLogService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouGroupExplore;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouGroupExploreMapper;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouGroupExploreService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyExploreService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -18,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -35,25 +44,23 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
     private ICtopOauthTokenService tokenService;
     @Autowired
     private IKuaishouGroupSpeedExploreLogService groupSpeedExploreLogService;
+    @Autowired
+    private IKuaishouReportDailyExploreService dailyExploreService;
+
+    @Autowired
+    private IKuaiShouGroupService kuaiShouGroupService;
 
     /**
-     * 查询加速探索信息
+     * 查询加速探索状态、预算
      *
      * @param
+     * @return
      * @throws
      * @author ZHAOXA
      */
     @Override
-    public Result<Object> unitExploreInfoGet(JSONObject data) {
+    public Result<Object> unitExploreInfoGet(Long accountId, Long unitId) {
         try {
-            Long accountId = data.getLong("accountId");
-            if (Check.isNull(accountId)) {
-                return Result.error("请选择广告主");
-            }
-            Long unitId = data.getLong("unitId");
-            if (Check.isNull(unitId)) {
-                return Result.error("请选择广告组");
-            }
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.UNIT_EXPLORE_INFO_GET;
             Map<String, String> header = new HashMap<>();
@@ -80,27 +87,16 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
     }
 
     /**
-     * 广告组加速探索预算设置
+     * 开启广告组加速探索
      *
      * @param
      * @throws
      * @author ZHAOXA
      */
     @Override
-    public Result<Object> unitExploreBudgetUpdate(JSONObject data) {
+    public Result<Object> unitExploreBudgetUpdate(Long accountId, Long unitId, Long exploreBudget) {
+        String msg = null;
         try {
-            Long accountId = data.getLong("accountId");
-            if (Check.isNull(accountId)) {
-                return Result.error("请选择广告主");
-            }
-            Long unitId = data.getLong("unitId");
-            if (Check.isNull(unitId)) {
-                return Result.error("请选择广告组");
-            }
-            Long exploreBudget = data.getLong("exploreBudget");
-            if (Check.isNull(exploreBudget)) {
-                return Result.error("请填写加速探索预算");
-            }
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.UNIT_EXPLORE_BUDGET_UPDATE;
             Map<String, String> header = new HashMap<>();
@@ -115,6 +111,21 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
+                    Result<Object> result1 = this.unitExploreInfoGet(accountId, unitId);
+                    if (result1.getCode() == 200) {
+                        JSONObject resultData = (JSONObject) result1.getResult();
+                        Integer exploreStatus = resultData.getInteger("explore_status");
+                        Long maxExploreBudget = resultData.getLong("max_explore_budget");
+                        KuaiShouGroup kuaiShouGroup = new KuaiShouGroup();
+
+                        KuaishouReportDailyExplore kuaishouGroupExplore = new KuaishouReportDailyExplore();
+                        kuaishouGroupExplore.setAccountId(accountId);
+                        kuaishouGroupExplore.setUnitId(unitId);
+                        kuaishouGroupExplore.setStatDate(new Date());
+                        kuaishouGroupExplore.setMaxExploreBudget(maxExploreBudget);
+                        kuaishouGroupExplore.setExploreStatus(exploreStatus);
+                        dailyExploreService.save(kuaishouGroupExplore);
+                    }
                     return Result.ok(resultJson.getJSONObject("data"));
                 } else {
                     log.info("广告组的加速探索预算设置失败,accountId:{},返回信息:{}", accountId, resultJson);
@@ -122,7 +133,7 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
                 }
             }
         } catch (Exception e) {
-            log.error("广告组的加速探索预算设置失败", e);
+            log.error("广告组({})启动加速探索失败", unitId, e);
         }
         return Result.error("广告组的加速探索预算设置失败");
     }
@@ -178,16 +189,8 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
      * @author ZHAOXA
      */
     @Override
-    public Result<Object> querySpeedExploreReport(JSONObject data) {
+    public Result<Object> querySpeedExploreReport(Long accountId, Long unitId, Integer exploreStatus, Long maxExploreBudget) {
         try {
-            Long accountId = data.getLong("accountId");
-            if (Check.isNull(accountId)) {
-                return Result.error("请选择广告主");
-            }
-            Long unitId = data.getLong("unitId");
-            if (Check.isNull(unitId)) {
-                return Result.error("请选择广告组");
-            }
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.QUERY_SPEED_EXPLORE_REPORT;
             Map<String, String> header = new HashMap<>();
@@ -202,19 +205,25 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
                     JSONObject exploreJson = resultJson.getJSONObject("data");
-                    KuaishouGroupExplore kuaishouGroupExplore = JSONObject.toJavaObject(exploreJson, KuaishouGroupExplore.class);
+                    KuaishouReportDailyExplore kuaishouGroupExplore = JSONObject.toJavaObject(exploreJson, KuaishouReportDailyExplore.class);
                     if (Check.isNull(kuaishouGroupExplore)) {
                         return Result.error("查询失败,结果为空");
                     }
-                    QueryWrapper<KuaishouGroupExplore> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("unit_id", kuaishouGroupExplore.getUnitId());
-                    KuaishouGroupExplore one = this.getOne(queryWrapper);
+                    QueryWrapper<KuaishouReportDailyExplore> queryWrapper = new QueryWrapper<>();
+                    queryWrapper.eq("unit_id", unitId);
+                    queryWrapper.eq("account_id", accountId);
+                    KuaishouReportDailyExplore one = dailyExploreService.getOne(queryWrapper);
                     if (!Check.isNull(one)) {
                         kuaishouGroupExplore.setId(one.getId());
                     }
                     kuaishouGroupExplore.setAccountId(accountId);
-                    this.saveOrUpdate(kuaishouGroupExplore);
-                    return Result.ok("添加成功");
+                    kuaishouGroupExplore.setExploreStatus(exploreStatus);
+                    kuaishouGroupExplore.setMaxExploreBudget(maxExploreBudget);
+                    kuaishouGroupExplore.setStatDate(new Date());
+                    boolean b = dailyExploreService.saveOrUpdate(kuaishouGroupExplore);
+                    if (b) {
+                        return Result.ok("添加成功");
+                    }
                 } else {
                     log.info("查询广告组的加速探索报表失败,accountId:{},返回信息:{}", accountId, resultJson);
                     return Result.error("查询广告组的加速探索报表失败," + resultJson.getString("message"));