Browse Source

加速探索功能提交

zhaoxian 3 years ago
parent
commit
c0ee1e4821

+ 3 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/app/mapper/KuaishouAccountBalanceBudgetMapper.java

@@ -3,6 +3,7 @@ package cn.com.ctop.kuaishou.modules.app.mapper;
 
 import cn.com.ctop.kuaishou.modules.app.entity.KuaishouAccountBalanceBudget;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 快手-账余额、预算
@@ -16,4 +17,6 @@ public interface KuaishouAccountBalanceBudgetMapper extends BaseMapper<KuaishouA
     void replace(KuaishouAccountBalanceBudget budget);
 
     void updateAllIsInvalidState();
+
+    KuaishouAccountBalanceBudget queryByAccountId(@Param("accountId") Long accountId);
 }

+ 6 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/app/mapper/xml/KuaishouAccountBalanceBudgetMapper.xml

@@ -33,4 +33,10 @@
         where 1 = 1
     </update>
 
+    <select id="queryByAccountId" resultType="cn.com.ctop.kuaishou.modules.app.entity.KuaishouAccountBalanceBudget">
+        SELECT *
+        FROM ctop_kuaishou_account_balance_budget
+        WHERE account_id = #{accountId}
+    </select>
+
 </mapper>

+ 72 - 43
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouReportDailyExploreController.java

@@ -1,41 +1,45 @@
 package cn.com.ctop.kuaishou.modules.report.controller;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyExploreService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+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.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
-
-import java.util.Date;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import lombok.extern.slf4j.Slf4j;
-
 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.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.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+
+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;
 
 /**
  * 广告组加速探索报表
@@ -47,33 +51,58 @@ import io.swagger.annotations.ApiOperation;
 @Slf4j
 @Api(tags = "广告组加速探索报表")
 @RestController
-@RequestMapping("/kuaishouReportDailyExplore")
+@RequestMapping("/explore")
 public class KuaishouReportDailyExploreController {
     @Autowired
     private IKuaishouReportDailyExploreService kuaishouReportDailyExploreService;
 
     /**
-     * 分页列表查询
-     *
-     * @param kuaishouReportDailyExplore
-     * @param pageNo
-     * @param pageSize
-     * @param req
-     * @return
+     * 查询当日广告组数据
      */
-    @ApiOperation(value = "广告组加速探索报表-分页列表查询", notes = "广告组加速探索报表-分页列表查询")
-    @GetMapping(value = "/list")
-    public Result<IPage<KuaishouReportDailyExplore>> queryPageList(KuaishouReportDailyExplore kuaishouReportDailyExplore,
-                                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
-                                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
-                                                                   HttpServletRequest req) {
-        Result<IPage<KuaishouReportDailyExplore>> result = new Result<>();
-        QueryWrapper<KuaishouReportDailyExplore> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouReportDailyExplore, req.getParameterMap());
-        Page<KuaishouReportDailyExplore> page = new Page<KuaishouReportDailyExplore>(pageNo, pageSize);
-        IPage<KuaishouReportDailyExplore> pageList = kuaishouReportDailyExploreService.page(page, queryWrapper);
-        result.setSuccess(true);
-        result.setResult(pageList);
-        return result;
+    @PostMapping(value = "/todaylist")
+    public Result<Object> todaylist(@RequestBody JSONObject request) {
+        try {
+            return kuaishouReportDailyExploreService.todaylist(request);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+    /**
+     * 查询加上探索历史
+     */
+    @PostMapping(value = "/historyList")
+    public Result<Object> historyList(@RequestBody JSONObject request) {
+        try {
+            return kuaishouReportDailyExploreService.historyList(request);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+
+    /**
+     * 批量开启
+     */
+    @PostMapping(value = "/openBudgets")
+    public Result<Object> openBudgets(@RequestBody JSONObject request) {
+        try {
+            JSONArray unitIds = request.getJSONArray("unitIds");
+            Long accountId = request.getLong("accountId");
+            Long exploreBudget = request.getLong("exploreBudget");
+            if (Check.isNull(accountId) || Check.isNull(exploreBudget)) {
+                return Result.error("缺少参数");
+            }
+            return kuaishouReportDailyExploreService.openBudgets(accountId, unitIds, exploreBudget);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
     }
 
     /**

+ 15 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouReportDailyExploreMapper.java

@@ -1,7 +1,11 @@
 package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 广告组加速探索报表
@@ -12,4 +16,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaishouReportDailyExploreMapper extends BaseMapper<KuaishouReportDailyExplore> {
 
+    List<KuaishouReportDailyExplore> getUnitListByStudyStatus();
+
+    List<JSONObject> getTodaylist(@Param("accountId") Long accountId, @Param("sortCode") String sortCode, @Param("sortType") String sortType);
+
+    Long getTodaylistTotal(@Param("accountId") Long accountId);
+
+    List<JSONObject> getHistoryList(@Param("request") JSONObject request, @Param("sortCode") String sortCode, @Param("sortType") String sortType);
+
+    Long getHistoryListTotal(@Param("request") JSONObject request);
+
+    List<Long> getUnitIds(@Param("accountId") Long accountId);
 }

+ 98 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportDailyExploreMapper.xml

@@ -2,4 +2,102 @@
 <!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.KuaishouReportDailyExploreMapper">
 
+    <select id="getUnitListByStudyStatus"
+            resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore">
+        SELECT account_id, unit_id
+        FROM ctop_kuaishou_report_daily_explore
+        WHERE explore_status IN (0, 1)
+    </select>
+
+    <select id="getTodaylistTotal" resultType="java.lang.Long">
+        SELECT count(1)
+        FROM ctop_kuaishou_group
+        WHERE account_id = #{accountId}
+          AND put_status = 1
+          AND study_status = 1
+          AND unit_id NOT IN (
+            SELECT unit_id FROM ctop_kuaishou_report_daily_explore WHERE account_id = #{accountId}
+        )
+
+    </select>
+
+    <select id="getTodaylist" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t2.unit_id,
+        t2.unit_name,
+        IFNULL(charge,'-') as 'charge',
+        IFNULL(activation,'-') as 'activation',
+        IFNULL(ROUND(charge/activation,2),'-') as 'activationCost',
+        IFNULL(event_pay,'-') as 'eventPay',
+        IFNULL(ROUND(charge/event_pay,2),'-') as 'eventPayCost',
+        IFNULL(event_register,'-') as 'eventRegister',
+        IFNULL(ROUND(charge/event_register,2),'-') as 'eventRegisterCost',
+        IFNULL(aclick,'-') as 'aclick'
+        FROM ctop_etl_kuaishou_group_daily_report t1
+        Right JOIN (
+        SELECT unit_id,unit_name FROM ctop_kuaishou_group WHERE account_id = #{accountId} AND unit_id NOT IN (
+        SELECT unit_id FROM ctop_kuaishou_report_daily_explore WHERE account_id = #{accountId}
+        )
+        AND put_status = 1
+        AND study_status = 1
+        ) t2 ON t1.unit_id = t2.unit_id
+        AND stat_date = DATE_FORMAT(now(),'%Y-%m-%d')
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode} ${sortType}
+        </if>
+    </select>
+
+    <select id="getHistoryListTotal" resultType="java.lang.Long">
+        SELECT count(1)
+        FROM ctop_kuaishou_report_daily_explore
+        WHERE account_id = #{request.accountId}
+          AND stat_date &gt;= CONCAT(#{request.startTime}, ' 00:00:01')
+          AND stat_date &lt;= CONCAT(#{request.endTime}, ' 23:59:59')
+    </select>
+
+    <select id="getHistoryList" resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore">
+        SELECT
+        id,
+        account_id,
+        unit_id,
+        unit_name,
+        explore_budget,
+        ocpx_action_type,
+        total_charge,
+        impression,
+        photo_click,
+        click,
+        unified_conversion,
+        unitfied_conversion_cost,
+        stat_date,
+        explore_status
+        FROM ctop_kuaishou_report_daily_explore
+        WHERE account_id = #{request.accountId}
+        AND stat_date &gt;= CONCAT(#{request.startTime},' 00:00:01')
+        AND stat_date &lt;= CONCAT(#{request.endTime},' 23:59:59')
+        <if test="request.unitId != null">
+            AND unit_id = #{request.unitId}
+        </if>
+        <if test="request.unitName != null">
+            AND LOCATE(#{request.unitName},unit_name)
+        </if>
+        <if test="request.exploreStatus != null ">
+            AND explore_status = #{request.exploreStatus}
+        </if>
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode} ${sortType}
+        </if>
+    </select>
+
+    <select id="getUnitIds" resultType="java.lang.Long">
+        SELECT unit_id
+        FROM ctop_kuaishou_group
+        WHERE account_id = #{accountId}
+          AND put_status = 1
+          AND study_status = 1
+          AND unit_id NOT IN (
+            SELECT unit_id FROM ctop_kuaishou_report_daily_explore WHERE account_id = #{accountId}
+        )
+    </select>
+
 </mapper>

+ 14 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouReportDailyExploreService.java

@@ -1,7 +1,12 @@
 package cn.com.ctop.kuaishou.modules.report.service;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+
+import java.util.List;
 
 /**
  * 广告组加速探索报表
@@ -11,4 +16,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaishouReportDailyExploreService extends IService<KuaishouReportDailyExplore> {
 
+    void getExploreUnitReports(Long accountId, Long unitId);
+
+    List<KuaishouReportDailyExplore> getUnitListByStudyStatus();
+
+    Result<Object> todaylist(JSONObject request);
+
+    Result<Object> historyList(JSONObject request);
+
+    Result<Object> openBudgets(Long accountId, JSONArray unitIds,Long exploreBudget);
 }

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

@@ -218,7 +218,7 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
                         kuaishouGroupExplore.setId(one.getId());
                     }
                     KuaiShouGroup kuaiShouGroup = kuaiShouGroupService.selectGroupByUnitId(accountId, unitId);
-                    if(!Check.isNull(kuaiShouGroup)){
+                    if (!Check.isNull(kuaiShouGroup)) {
                         kuaishouGroupExplore.setUnitName(kuaiShouGroup.getUnitName());
                         kuaishouGroupExplore.setCampaignId(kuaiShouGroup.getCampaignId());
                     }
@@ -322,6 +322,4 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
         }
         return Result.error("辅助探索失败");
     }
-
-
 }

+ 152 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportDailyExploreServiceImpl.java

@@ -1,11 +1,25 @@
 package cn.com.ctop.kuaishou.modules.report.service.impl;
 
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.app.entity.KuaishouAccountBalanceBudget;
+import cn.com.ctop.kuaishou.modules.app.mapper.KuaishouAccountBalanceBudgetMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyExploreMapper;
+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.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 广告组加速探索报表
  *
@@ -16,4 +30,142 @@ import org.springframework.stereotype.Service;
 @Service
 public class KuaishouReportDailyExploreServiceImpl extends ServiceImpl<KuaishouReportDailyExploreMapper, KuaishouReportDailyExplore> implements IKuaishouReportDailyExploreService {
 
+    @Autowired
+    private KuaishouReportDailyExploreMapper reportDailyExploreMapper;
+
+    @Autowired
+    private KuaishouAccountBalanceBudgetMapper kuaishouAccountBalanceBudgetMapper;
+
+    @Autowired
+    private IKuaishouGroupExploreService kuaishouGroupExploreService;
+
+    @Autowired
+    private IKuaiShouGroupService kuaiShouGroupService;
+
+    @Override
+    public void getExploreUnitReports(Long accountId, Long unitId) {
+        Result<Object> result = kuaishouGroupExploreService.unitExploreInfoGet(accountId, unitId);
+        if (result.getCode() == 200) {
+            JSONObject resultResult = (JSONObject) result.getResult();
+            if (!Check.isNull(resultResult)) {
+                kuaishouGroupExploreService.querySpeedExploreReport(accountId, unitId, resultResult.getInteger("explore_status"), resultResult.getLong("max_explore_budget"));
+            }
+        }
+    }
+
+    @Override
+    public List<KuaishouReportDailyExplore> getUnitListByStudyStatus() {
+        return reportDailyExploreMapper.getUnitListByStudyStatus();
+    }
+
+    @Override
+    public Result<Object> todaylist(JSONObject request) {
+        Integer pageNo = request.getInteger("pageNo");
+        Integer pageSize = request.getInteger("pageSize");
+        if (Check.isNull(pageNo)) {
+            pageNo = 1;
+        }
+        if (Check.isNull(pageSize)) {
+            pageSize = 10;
+        }
+        Long accountId = request.getLong("accountId");
+        if (Check.isNull(accountId)) {
+            return Result.error("未选择账户");
+        }
+        String sortCode = request.getString("sortCode");
+        String sortType = request.getString("sortType");
+        if (Check.isNull(sortCode)) {
+            sortCode = "charge";
+        }
+        if (Check.isNull(sortType)) {
+            sortType = "DESC";
+        }
+        Long total = reportDailyExploreMapper.getTodaylistTotal(accountId);
+        PageHelper.startPage(pageNo, pageSize, false);
+        PageInfo pageInfo = new PageInfo(reportDailyExploreMapper.getTodaylist(accountId, sortCode, sortType));
+        pageInfo.setTotal(total);
+        JSONObject result = new JSONObject();
+        result.put("pageInfo", pageInfo);
+        KuaishouAccountBalanceBudget balanceBudget = kuaishouAccountBalanceBudgetMapper.queryByAccountId(accountId);
+        if (!Check.isNull(balanceBudget)) {
+            result.put("dayBudget", balanceBudget.getDayBudget());
+        }
+        return Result.ok(result);
+    }
+
+    @Override
+    public Result<Object> historyList(JSONObject request) {
+        Integer pageNo = request.getInteger("pageNo");
+        Integer pageSize = request.getInteger("pageSize");
+        if (Check.isNull(pageNo)) {
+            pageNo = 1;
+        }
+        if (Check.isNull(pageSize)) {
+            pageSize = 10;
+        }
+        Long accountId = request.getLong("accountId");
+        if (Check.isNull(accountId)) {
+            return Result.error("未选择账户");
+        }
+        String sortCode = request.getString("sortCode");
+        String sortType = request.getString("sortType");
+        if (Check.isNull(sortCode)) {
+            sortCode = "total_charge";
+        }
+        if (Check.isNull(sortType)) {
+            sortType = "DESC";
+        }
+        if (Check.isNull(request.getString("startTime"))) {
+            request.put("startTime", DateUtils.getNowDate("yyyy-MM-dd"));
+            request.put("endTime", DateUtils.getNowDate("yyyy-MM-dd"));
+        }
+        Long total = reportDailyExploreMapper.getHistoryListTotal(request);
+        PageHelper.startPage(pageNo, pageSize, false);
+        PageInfo pageInfo = new PageInfo(reportDailyExploreMapper.getHistoryList(request, sortCode, sortType));
+        pageInfo.setTotal(total);
+        JSONObject result = new JSONObject();
+        result.put("pageInfo", pageInfo);
+        KuaishouAccountBalanceBudget balanceBudget = kuaishouAccountBalanceBudgetMapper.queryByAccountId(accountId);
+        if (!Check.isNull(balanceBudget)) {
+            result.put("dayBudget", balanceBudget.getDayBudget());
+        }
+        return Result.ok(result);
+    }
+
+    @Override
+    public Result<Object> openBudgets(Long accountId, JSONArray unitIds, Long exploreBudget) {
+        try {
+            StringBuilder errUnitIds = new StringBuilder();
+            if (Check.isNull(unitIds) || unitIds.isEmpty()) {
+                List<Long> unitids = reportDailyExploreMapper.getUnitIds(accountId);
+                for (Long unitid : unitids) {
+                    Result<Object> result = kuaishouGroupExploreService.unitExploreBudgetUpdate(accountId, unitid, exploreBudget);
+                    if (result.getCode() != 200) {
+                        if (errUnitIds.length() > 0) {
+                            errUnitIds.append(",");
+                        }
+                        errUnitIds.append(unitid);
+                    }
+                }
+            } else {
+                for (int i = 0; i < unitIds.size(); i++) {
+                    Long unitId = unitIds.getLong(i);
+                    Result<Object> result = kuaishouGroupExploreService.unitExploreBudgetUpdate(accountId, unitId, exploreBudget);
+                    if (result.getCode() != 200) {
+                        if (errUnitIds.length() > 0) {
+                            errUnitIds.append(",");
+                        }
+                        errUnitIds.append(unitId);
+                    }
+                }
+            }
+            if (errUnitIds.length() > 0) {
+                return Result.ok(errUnitIds.insert(0, "启动完成,其中广告组:").append("启动失败"));
+            }
+            return Result.ok("全部启动完成");
+        } catch (Exception e) {
+            log.error("启动加速探索异常", e);
+            return Result.error("启动加速探索失败");
+        }
+    }
 }