zhaoxian пре 4 година
родитељ
комит
e09cbb9a2d

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

@@ -106,7 +106,10 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         log.info("------start------");
         Long startTime = System.currentTimeMillis();
         //查询账户绑定过的规则模板
-        List<RuleAccountTemplate> ruleAccountTemplates = ruleAccountTemplateMapper.selectByMap(null);
+        Map<String, Object> map = new HashMap<>();
+        //0状态为启动
+        map.put("template_status", 0);
+        List<RuleAccountTemplate> ruleAccountTemplates = ruleAccountTemplateMapper.selectByMap(map);
         if (Check.isNull(ruleAccountTemplates)) {
             log.error("查询账户绑定过的规则模板失败");
             return;

+ 258 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouStrategyController.java

@@ -0,0 +1,258 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouStrategyService;
+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.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+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.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+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 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;
+
+/**
+ * kuaishou.modules.batch-优化评估策略表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-12-10
+ */
+@Slf4j
+@Api(tags = "kuaishou.modules.batch-优化评估策略表")
+@RestController
+@RequestMapping("/kuaishouStrategy")
+public class KuaishouStrategyController {
+    @Autowired
+    private IKuaishouStrategyService kuaishouStrategyService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param kuaishouStrategy
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-分页列表查询")
+    @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-分页列表查询", notes = "kuaishou.modules.batch-优化评估策略表-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<KuaishouStrategy>> queryPageList(KuaishouStrategy kuaishouStrategy,
+                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                         HttpServletRequest req) {
+        Result<IPage<KuaishouStrategy>> result = new Result<>();
+        QueryWrapper<KuaishouStrategy> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouStrategy, req.getParameterMap());
+        Page<KuaishouStrategy> page = new Page<KuaishouStrategy>(pageNo, pageSize);
+        IPage<KuaishouStrategy> pageList = kuaishouStrategyService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param kuaishouStrategy
+     * @return
+     */
+    @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-添加")
+    @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-添加", notes = "kuaishou.modules.batch-优化评估策略表-添加")
+    @PostMapping(value = "/add")
+    public Result<Object> add(@RequestBody KuaishouStrategy kuaishouStrategy) {
+        Result<Object> result = new Result<>();
+        try {
+            if (Check.isNull(kuaishouStrategy.getAccountId())) {
+                return Result.error(-1, "请选择账户");
+            }
+            kuaishouStrategyService.save(kuaishouStrategy);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param kuaishouStrategy
+     * @return
+     */
+    @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-编辑")
+    @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-编辑", notes = "kuaishou.modules.batch-优化评估策略表-编辑")
+    @PostMapping(value = "/edit")
+    public Result<KuaishouStrategy> edit(@RequestBody KuaishouStrategy kuaishouStrategy) {
+        Result<KuaishouStrategy> result = new Result<KuaishouStrategy>();
+        KuaishouStrategy kuaishouStrategyEntity = kuaishouStrategyService.getById(kuaishouStrategy.getId());
+        if (kuaishouStrategyEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = kuaishouStrategyService.updateById(kuaishouStrategy);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-通过id删除")
+    @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-通过id删除", notes = "kuaishou.modules.batch-优化评估策略表-通过id删除")
+    @DeleteMapping(value = "/delete")
+    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
+        try {
+            kuaishouStrategyService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-批量删除")
+    @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-批量删除", notes = "kuaishou.modules.batch-优化评估策略表-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<KuaishouStrategy> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<KuaishouStrategy> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.kuaishouStrategyService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-通过id查询")
+    @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-通过id查询", notes = "kuaishou.modules.batch-优化评估策略表-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<Object> queryById(@RequestParam(name = "id", required = true) String id) {
+        if (Check.isNull(id)) {
+            return Result.error(-1, "请选择查看的策略");
+        }
+        KuaishouStrategy strategy = kuaishouStrategyService.getById(id);
+        if (Check.isNull(strategy)) {
+            return Result.error(-1, "策略不存在");
+        }
+        return Result.ok(strategy);
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<KuaishouStrategy> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                KuaishouStrategy kuaishouStrategy = JSON.parseObject(deString, KuaishouStrategy.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(kuaishouStrategy, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<KuaishouStrategy> pageList = kuaishouStrategyService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "kuaishou.modules.batch-优化评估策略表列表");
+        mv.addObject(NormalExcelConstants.CLASS, KuaishouStrategy.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("kuaishou.modules.batch-优化评估策略表列表数据", "导出人: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<KuaishouStrategy> listKuaishouStrategys = ExcelImportUtil.importExcel(file.getInputStream(), KuaishouStrategy.class, params);
+                kuaishouStrategyService.saveBatch(listKuaishouStrategys);
+                return Result.ok("文件导入成功!数据行数:" + listKuaishouStrategys.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("文件导入失败!");
+    }
+
+}

+ 217 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouStrategy.java

@@ -0,0 +1,217 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+import com.alibaba.fastjson.JSONArray;
+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;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 快手-优化评估策略表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-12-10
+ */
+@Data
+@TableName("ctop_kuaishou_strategy")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_strategy对象", description = "快手-优化评估策略表")
+public class KuaishouStrategy {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.ID_WORKER_STR)
+    @ApiModelProperty(value = "id")
+    private String id;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+    /**
+     * 策略名称
+     */
+    @Excel(name = "策略名称", width = 15)
+    @ApiModelProperty(value = "策略名称")
+    private String strategyName;
+    /**
+     * 策略状态 0 关停,1激活
+     */
+    @Excel(name = "策略状态 0 关停,1激活", width = 15)
+    @ApiModelProperty(value = "策略状态 0 关停,1激活")
+    private String strategyState;
+    /**
+     * 应用场景{1:素材+出价}{2:素材+定向}{3:时间+出价}。。。
+     */
+    @Excel(name = "应用场景{1:素材+出价}{2:素材+定向}{3:时间+出价}。。。", width = 15)
+    @ApiModelProperty(value = "应用场景{1:素材+出价}{2:素材+定向}{3:时间+出价}。。。")
+    private String scenes;
+    /**
+     * 营销目标{1应用安装},{2电商下单},{3推广品牌},{4营销线上},{5应用活跃}
+     */
+    @Excel(name = "营销目标{1应用安装},{2电商下单},{3推广品牌},{4营销线上},{5应用活跃}", width = 15)
+    @ApiModelProperty(value = "营销目标{1应用安装},{2电商下单},{3推广品牌},{4营销线上},{5应用活跃}")
+    private String marketingGoal;
+    /**
+     * 应用id集
+     */
+    @Excel(name = "应用id集", width = 15)
+    @ApiModelProperty(value = "应用id集")
+    private String appIds;
+    /**
+     * 转化目标
+     */
+    @Excel(name = "转化目标", width = 15)
+    @ApiModelProperty(value = "转化目标")
+    private Long convertId;
+    /**
+     * 定向模板id
+     */
+    @Excel(name = "模板id", width = 15)
+    @ApiModelProperty(value = "模板id")
+    private Long templateId;
+    /**
+     * 地域
+     */
+    @Excel(name = "地域", width = 15)
+    @ApiModelProperty(value = "地域")
+    private String region;
+    /**
+     * 年龄段:{0:不限}{18:18-23岁}{24:24-30岁}{31:31-40岁}{41:41-49岁}{50:50岁+
+     */
+    @Excel(name = "年龄段:{0:不限}{18:18-23岁}{24:24-30岁}{31:31-40岁}{41:41-49岁}{50:50岁+", width = 15)
+    @ApiModelProperty(value = "年龄段:{0:不限}{18:18-23岁}{24:24-30岁}{31:31-40岁}{41:41-49岁}{50:50岁+")
+    private String agesRange;
+    /**
+     * 性别 1:女性, 2:男性, 0:不限
+     */
+    @Excel(name = "性别 1:女性, 2:男性, 0:不限", width = 15)
+    @ApiModelProperty(value = "性别 1:女性, 2:男性, 0:不限")
+    private Integer gender;
+    /**
+     * 操作系统 1: Android, 2: iOS, 0:不限
+     */
+    @Excel(name = "操作系统 1: Android, 2: iOS, 0:不限", width = 15)
+    @ApiModelProperty(value = "操作系统 1: Android, 2: iOS, 0:不限")
+    private Integer platformOs;
+    /**
+     * 自定义人群 0不限,1:定向,:2:排除,:3同时定向排除
+     */
+    @Excel(name = "自定义人群 0不限,1:定向,:2:排除,:3同时定向排除", width = 15)
+    @ApiModelProperty(value = "自定义人群 0不限,1:定向,:2:排除,:3同时定向排除")
+    private String customCrowd;
+    /**
+     * 定向人群包
+     */
+    @Excel(name = "定向人群包", width = 15)
+    @ApiModelProperty(value = "定向人群包")
+    private String population;
+    /**
+     * 排除人群包
+     */
+    @Excel(name = "排除人群包", width = 15)
+    @ApiModelProperty(value = "排除人群包")
+    private String excludePopulation;
+    /**
+     * 投放开始时间
+     */
+    @Excel(name = "投放开始时间", width = 15)
+    @ApiModelProperty(value = "投放开始时间")
+    private String beginTime;
+    /**
+     * 投放结束时间
+     */
+    @Excel(name = "投放结束时间", width = 15)
+    @ApiModelProperty(value = "投放结束时间")
+    private String endTime;
+    /**
+     * 投放时段
+     */
+    @Excel(name = "投放时段", width = 15)
+    @ApiModelProperty(value = "投放时段")
+    private Object scheduleTime;
+    /**
+     * 策略预算
+     */
+    @Excel(name = "策略预算", width = 15)
+    @ApiModelProperty(value = "策略预算")
+    private Long budget;
+    /**
+     * 出价类型(优化目标) 2点击数(CPC),10转化数(OCPM)
+     */
+    @Excel(name = "出价类型(优化目标) 2点击数(CPC),10转化数(OCPM)", width = 15)
+    @ApiModelProperty(value = "出价类型(优化目标) 2点击数(CPC),10转化数(OCPM)")
+    private Integer bidType;
+    /**
+     * 封面点击出价
+     */
+    @Excel(name = "封面点击出价", width = 15)
+    @ApiModelProperty(value = "封面点击出价")
+    private Long bid;
+    /**
+     * 转化目标,2:行为数,180:激活数,53:表单数,190: 付费,191:首日ROI 。。。
+     */
+    @Excel(name = "转化目标,2:行为数,180:激活数,53:表单数,190: 付费,191:首日ROI 。。。", width = 15)
+    @ApiModelProperty(value = "转化目标,2:行为数,180:激活数,53:表单数,190: 付费,191:首日ROI 。。。")
+    private Integer ocpxActionType;
+    /**
+     * 转化目标出价
+     */
+    @Excel(name = "转化目标出价", width = 15)
+    @ApiModelProperty(value = "转化目标出价")
+    private Integer cpaBid;
+    /**
+     * 深度转化目标 3: 付费,7: 次日留存,10: 完件, 11: 授信 ,0:无
+     */
+    @Excel(name = "深度转化目标 3: 付费,7: 次日留存,10: 完件, 11: 授信 ,0:无", width = 15)
+    @ApiModelProperty(value = "深度转化目标 3: 付费,7: 次日留存,10: 完件, 11: 授信 ,0:无")
+    private Integer deepConversionType;
+    /**
+     * 深度转化目标出价
+     */
+    @Excel(name = "深度转化目标出价", width = 15)
+    @ApiModelProperty(value = "深度转化目标出价")
+    private Integer deepConversionBid;
+
+    /**
+     * 广告位 1:优选广告位
+     */
+    private JSONArray sceneId;
+    /**
+     * 下载详情页ID,建站id
+     */
+    private Integer siteId;
+    /**
+     * 第三方开始播放监测链接
+     */
+    private String impressionUrl;
+    /**
+     * 第三方有效播放监测链接
+     */
+    private String adPhotoPlayedT3sUrl;
+    /**
+     * 第三方点击按钮监测链接
+     */
+    private String actionbarClickUrl;
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * updateTime
+     */
+    @ApiModelProperty(value = "updateTime")
+    private Date updateTime;
+}

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouStrategyMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.batch.mapper;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * kuaishou.modules.batch-优化评估策略表
+ *
+ * @author: jeecg-boot
+ * @date: 2020-12-10
+ * @cersion: V1.0
+ */
+public interface KuaishouStrategyMapper extends BaseMapper<KuaishouStrategy> {
+
+}

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouStrategyMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouStrategyMapper">
+
+</mapper>

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

@@ -0,0 +1,14 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: kuaishou.modules.batch-优化评估策略表
+ * @Author: jeecg-boot
+ * @Date:   2020-12-10
+ * @Version: V1.0
+ */
+public interface IKuaishouStrategyService extends IService<KuaishouStrategy> {
+
+}

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -1347,7 +1347,7 @@ public class BatchServiceImpl implements IBatchService {
                                 }
 
                                 if ("4".equals(creativeMaterialType)) {
-                                    if (!Check.isNull("shortSlogan")) {
+                                    if (!Check.isNull(shortSlogan)) {
                                         creativeJson.put("short_slogan", shortSlogan);
                                     }
                                 }

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

@@ -0,0 +1,412 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouStrategyMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouStrategyService;
+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.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 快手-优化评估策略表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-12-10
+ */
+@Service
+public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMapper, KuaishouStrategy> implements IKuaishouStrategyService {
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private IKuaiShouImageGetService imageGetService;
+    @Autowired
+    private IKuaiShouMaterialUploadService uploadService;
+
+    /**
+     * @param oauthToken token签名
+     * @param strategy   策略对象
+     * @param groupJson  广告计划
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
+    private void createGroupLevelStrategy(CtopOauthToken oauthToken, KuaishouStrategy strategy, JSONObject groupJson) throws Exception {
+        JSONObject unitJson = new JSONObject();
+        //广告计划ID
+        if (!Check.isNull(groupJson.getString("campaignId"))) {
+            unitJson.put("campaign_id", groupJson.getString("campaignId"));
+        }
+        //广告组名称
+        if (!Check.isNull(groupJson.getString("unitName"))) {
+            unitJson.put("unit_name", groupJson.getString("unitName"));
+        }
+        // 优化目标出价类型
+        if (!Check.isNull(groupJson.getInteger("bidType"))) {
+            unitJson.put("bid_type", groupJson.getInteger("bidType"));
+        }
+        /* 资源位置
+        1:优选广告位
+        3:视频播放页广告-便利贴广告(不支持深度转化目标的优化);
+        5:联盟广告,与其他类型互斥
+        6:上下滑大屏广告;
+        7:信息流广告;
+        3、6、7可多选*/
+        Integer sceneId = groupJson.getJSONArray("sceneId").getInteger(0);
+        if (!Check.isNull(groupJson.getJSONArray("sceneId"))) {
+            unitJson.put("scene_id", groupJson.getJSONArray("sceneId"));
+        }
+        // 资源创作方式  4: 自定义;5:程序化创意  7:程序化创意2.0
+        if (!Check.isNull(groupJson.getInteger("unitType"))) {
+            unitJson.put("unit_type", groupJson.getInteger("unitType"));
+        }
+        // 创意展现方式1 - 轮播 2 - 优选
+        if (!Check.isNull(groupJson.getInteger("showMode"))) {
+            unitJson.put("show_mode", groupJson.getInteger("showMode"));
+        }
+        /**
+         投放方式
+         1 - 加速投放
+         2 - 平滑投放
+         3-优先低成本(投放时间范围只可为全天;预算不可为不限或空)
+         */
+        if (!Check.isNull(groupJson.getInteger("speed"))) {
+            unitJson.put("speed", groupJson.getInteger("speed"));
+        }
+
+        // 封面点击出价
+        if (!Check.isNull(strategy.getBid())) {
+            unitJson.put("bid", strategy.getBid());
+        }
+
+        // 深度转化出价
+        if (!Check.isNull(strategy.getCpaBid())) {
+            unitJson.put("cpa_bid", strategy.getCpaBid());
+        }
+        // 深度转化目标出价
+        if (!Check.isNull(strategy.getDeepConversionBid())) {
+            unitJson.put("deep_conversion_bid", strategy.getDeepConversionBid());
+        }
+        // 深度转化目标
+        if (!Check.isNull(strategy.getDeepConversionType())) {
+            unitJson.put("deep_conversion_type", strategy.getDeepConversionType());
+        }
+        // 优化目标
+        if (!Check.isNull(strategy.getOcpxActionType())) {
+            unitJson.put("ocpx_action_type", strategy.getOcpxActionType());
+        }
+        //投放开始时间
+        if (!Check.isNull(strategy.getBeginTime())) {
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            boolean beginTimeBoolean = DateUtils.compare(strategy.getBeginTime(), nowDate);
+            if (beginTimeBoolean) {
+                unitJson.put("begin_time", nowDate);
+            } else {
+                unitJson.put("begin_time", strategy.getBeginTime());
+            }
+        }
+        // 投放结束时间
+        if (!Check.isNull(strategy.getEndTime())) {
+            unitJson.put("end_time", strategy.getEndTime());
+        }
+        // 投放时间段
+        if (!Check.isNull(strategy.getScheduleTime())) {
+            unitJson.put("schedule_time", strategy.getScheduleTime());
+        }
+        //定向模板id(选)
+        Long templateId = strategy.getTemplateId();
+        if (!Check.isNull(templateId)) {
+            unitJson.put("template_id", templateId);
+        }
+        // 优先从系统应用商店下载 1:优先从系统应用商店下载使用,默认0
+        if (!Check.isNull(groupJson.getInteger("useAppMarket"))) {
+            unitJson.put("use_app_market", groupJson.getInteger("useAppMarket"));
+        }
+         /*应用商店列表
+          华为:huawei,
+          OPPO:oppo
+          VIVO:vivo
+         小米:xiaomi
+         魅族:meizu
+         锤子:smartisan*/
+        if (!Check.isNull(groupJson.getJSONArray("appStore"))) {
+            unitJson.put("app_store", groupJson.getJSONArray("appStore"));
+        }
+        // 转化目标id
+        if (!Check.isNull(groupJson.getInteger("convertId"))) {
+            unitJson.put("convert_id", groupJson.getInteger("convertId"));
+        }
+        // 广告组单日预算 指定0表示预算不限,默认为0;不小于100元,不超过100000000元,仅支持输入数字;
+        if (!Check.isNull(groupJson.getLong("dayBudget"))) {
+            unitJson.put("day_budget", groupJson.getLong("dayBudget"));
+        }
+        // url类型
+        if (!Check.isNull(groupJson.getInteger("urlType"))) {
+            unitJson.put("url_type", groupJson.getInteger("urlType"));
+        }
+        // url类型
+        if (!Check.isNull(groupJson.getString("webUriType"))) {
+            unitJson.put("web_uri_type", groupJson.getString("webUriType"));
+        }
+        // url
+        if (!Check.isNull(groupJson.getString("url"))) {
+            unitJson.put("url", groupJson.getString("url"));
+        }
+        // appId
+        if (!Check.isNull(groupJson.getLong("appId"))) {
+            unitJson.put("app_id", groupJson.getLong("appId"));
+        }
+        // 预约广告 1:IOS预约 缺省为不传或传0
+        if (!Check.isNull(groupJson.getLong("siteType"))) {
+            unitJson.put("site_type", groupJson.getLong("siteType"));
+        }
+        // 游戏礼包码
+        if (!Check.isNull(groupJson.getLong("giftData"))) {
+            unitJson.put("gift_data", groupJson.getLong("giftData"));
+        }
+        // -----------------用户定向-----------
+        JSONObject targetJson = new JSONObject();
+        // 地域
+        if (!Check.isNull(strategy.getRegion())) {
+            targetJson.put("region", strategy.getRegion());
+        }
+        // 自定义年龄段
+        JSONArray ageArr = groupJson.getJSONArray("age");
+        if (!Check.isNull(ageArr)) {
+            JSONObject ageJson = new JSONObject();
+            ageJson.put("min", ageArr.get(0));
+            ageJson.put("max", ageArr.get(1));
+            targetJson.put("age", ageJson);
+        }
+        // 固定年龄段
+        if (!Check.isNull(strategy.getAgesRange())) {
+            targetJson.put("ages_range", strategy.getAgesRange());
+        }
+        // 性别
+        if (!Check.isNull(strategy.getGender())) {
+            targetJson.put("gender", strategy.getGender());
+        }
+        //操作系统
+        if (!Check.isNull(strategy.getPlatformOs())) {
+            targetJson.put("platform_os", strategy.getPlatformOs());
+        }
+        //Android版本
+        if (!Check.isNull(groupJson.getInteger("androidOsv"))) {
+            targetJson.put("android_osv", groupJson.getInteger("androidOsv"));
+        }
+        // iOS版本
+        if (!Check.isNull(groupJson.getInteger("iosOsv"))) {
+            targetJson.put("ios_osv", groupJson.getInteger("iosOsv"));
+        }
+        //网络环境
+        if (!Check.isNull(groupJson.getInteger("network"))) {
+            targetJson.put("network", groupJson.getInteger("network"));
+        }
+        //设备品牌
+        if (!Check.isNull(groupJson.getJSONArray("deviceBrand"))) {
+            targetJson.put("device_brand", groupJson.getJSONArray("deviceBrand"));
+        }
+        //设备价格
+        if (!Check.isNull(groupJson.getJSONArray("devicePrice"))) {
+            targetJson.put("device_price", groupJson.getJSONArray("devicePrice"));
+        }
+
+        if (sceneId != 5) {
+            //过滤已转化人群纬度
+            if (!Check.isNull(groupJson.getInteger("filterConvertedLevel"))) {
+                targetJson.put("filter_converted_level", groupJson.getInteger("filterConvertedLevel"));
+            }
+            //商业兴趣类型
+            if (!Check.isNull(groupJson.getInteger("businessInterestType"))) {
+                targetJson.put("business_interest_type", groupJson.getInteger("businessInterestType"));
+            }
+            // 商业兴趣
+            if (!Check.isNull(groupJson.getJSONArray("businessInterest"))) {
+                targetJson.put("business_interest", groupJson.getJSONArray("businessInterest"));
+            }
+            //网红粉丝
+            if (!Check.isNull(groupJson.getJSONArray("fansStar"))) {
+                targetJson.put("fans_star", groupJson.getJSONArray("fansStar"));
+            }
+            //兴趣视频用户
+            if (!Check.isNull(groupJson.getJSONArray("interestVideo"))) {
+                targetJson.put("interest_video", groupJson.getJSONArray("interestVideo"));
+            }
+            //智能扩量
+            JSONObject intelliExtendJson = new JSONObject();
+            // 开启智能扩量
+            if (!Check.isNull(groupJson.getInteger("isOpen"))) {
+                intelliExtendJson.put("is_open", groupJson.getInteger("isOpen"));
+            }
+            //不可突破年龄
+            if (!Check.isNull(groupJson.getInteger("noAgeBreak"))) {
+                intelliExtendJson.put("no_age_break", groupJson.getInteger("noAgeBreak"));
+            }
+            //不可突破性别
+            if (!Check.isNull(groupJson.getInteger("noGenderBreak"))) {
+                intelliExtendJson.put("no_gender_break", groupJson.getInteger("noGenderBreak"));
+            }
+            // 不可突破地域
+            if (!Check.isNull(groupJson.getInteger("noAreaBreak"))) {
+                intelliExtendJson.put("no_area_break", groupJson.getInteger("noAreaBreak"));
+            }
+            if (!Check.isNull(intelliExtendJson)) {
+                targetJson.put("intelli_extend", intelliExtendJson);
+            }
+        }
+        // APP行为-按分类
+        if (!Check.isNull(groupJson.getJSONArray("appInterest"))) {
+            targetJson.put("app_interest", groupJson.getJSONArray("appInterest"));
+        }
+        // APP行为-按APP名称
+        if (!Check.isNull(groupJson.getJSONArray("appIds"))) {
+            targetJson.put("app_ids", groupJson.getJSONArray("appIds"));
+        }
+        // 人群包定向
+        if (!Check.isNull(strategy.getPopulation())) {
+            targetJson.put("population", strategy.getPopulation());
+        }
+        // 人群包排除
+        if (!Check.isNull(strategy.getExcludePopulation())) {
+            targetJson.put("exclude_population", strategy.getExcludePopulation());
+        }
+
+        if (!Check.isNull(groupJson.getJSONArray("thirdPlatformCode"))) {
+            targetJson.put("third_platform_code", groupJson.getJSONArray("thirdPlatformCode"));
+        }
+        unitJson.put("target", targetJson);
+        Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson, 1);
+    }
+
+    /**
+     * 根据策略创建创意
+     *
+     * @param
+     * @return com.alibaba.fastjson.JSONObject
+     * @throws
+     * @author ZHAOXA
+     */
+    private Map<String, Object> createCreativeLevelStrategy(CtopOauthToken oauthToken, KuaishouStrategy strategy, JSONObject data) {
+        Map<String, Object> resultMap = new HashMap<>();
+        JSONObject creativeJson = new JSONObject();
+        //广告组ID
+        if (!Check.isNull(data.get("unitId"))) {
+            creativeJson.put("unit_id", data.get("unitId"));
+        }
+        //创意名称
+        if (!Check.isNull(data.get("creativeName"))) {
+            creativeJson.put("creative_name", data.get("creativeName"));
+        }
+        //视频ID
+        if (!Check.isNull(data.get("photoId"))) {
+            creativeJson.put("photo_id", data.get("photoId"));
+        }
+        /**
+         * 素材类型
+         * 1:竖版视频
+         * 2:横版视频
+         * 4:便利贴单图图片创意
+         * 5:竖版图片
+         * 6:横版图片
+         */
+        String creativeMaterialType = data.getString("creativeMaterialType");
+        if (!Check.isNull(creativeMaterialType)) {
+            creativeJson.put("creative_material_type", creativeMaterialType);
+        }
+        //行动号召按钮文案
+        if (!Check.isNull(data.getString("actionBarText"))) {
+            creativeJson.put("action_bar_text", data.getString("actionBarText"));
+        }
+        //广告语
+        if (!Check.isNull(data.getString("description"))) {
+            creativeJson.put("description", data.getString("description"));
+        }
+        //便利贴创意短广告语
+        if (!Check.isNull(data.getString("shortSlogan"))) {
+            creativeJson.put("short_slogan", data.getString("shortSlogan"));
+        }
+        //封面广告语标题
+        if (!Check.isNull(data.getString("stickerTitle"))) {
+            creativeJson.put("sticker_title", data.getString("stickerTitle"));
+        }
+        //贴纸样式类型
+        if (!Check.isNull(data.getString("overlayType"))) {
+            creativeJson.put("overlay_type", data.getString("overlayType"));
+        }
+        //广告标签
+        if (!Check.isNull(data.getString("exposeTag"))) {
+            creativeJson.put("expose_tag", data.getString("exposeTag"));
+        }
+        //广告标签2期
+        if (!Check.isNull(data.getJSONArray("newExposeTag"))) {
+            creativeJson.put("new_expose_tag", data.getJSONArray("newExposeTag"));
+        }
+        //安卓下载中间页ID
+        if (!Check.isNull(data.getLong("siteId"))) {
+            creativeJson.put("site_id", data.getLong("siteId"));
+        }
+        String imageToken = null;
+        String signature = data.getString("signature");
+        if (!Check.isNull(signature)) {
+            QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("account_id", oauthToken.getAccountId());
+            queryWrapper.eq("signature", signature);
+            queryWrapper.last("limit 1");
+            KuaiShouImageGet imageGet = imageGetService.getOne(queryWrapper);
+            if (!Check.isNull(imageGet)) {
+                imageToken = imageGet.getImageToken();
+            } else {
+                String url = imageGetService.getUrlByCode(signature);
+                imageToken = uploadService.kuauiShouImageUpload(url, signature, oauthToken.getAccountId(), oauthToken.getAccessToken());
+            }
+            if (Check.isNull(imageToken)) {
+                resultMap.put("success", false);
+                resultMap.put("creativeName", data.get("creativeName"));
+                resultMap.put("message", "获取图片文件失败");
+                return resultMap;
+            }
+        }
+        JSONArray tokenArr = new JSONArray();
+        //封面图片token
+        creativeJson.put("image_token", imageToken);
+        //便利贴单图图片创意token
+        tokenArr.add(imageToken);
+        creativeJson.put("image_tokens", tokenArr);
+        if (!Check.isNull(data.getString("clickTrackUrl"))) {
+            //第三方点击检测链接
+            creativeJson.put("click_track_url", data.getString("clickTrackUrl"));
+            //第三方开始播放监测链接
+            creativeJson.put("impression_url", data.getString("clickTrackUrl"));
+        }
+        //第三方有效播放监测链接
+        if (!Check.isNull(data.getString("adPhotoPlayedT3sUrl"))) {
+            creativeJson.put("ad_photo_played_t3s_url", data.getString("adPhotoPlayedT3sUrl"));
+        }
+        //第三方点击按钮监测链接
+        if (!Check.isNull(data.getString("actionbarClickUrl"))) {
+            creativeJson.put("actionbar_click_url", data.getString("actionbarClickUrl"));
+        }
+        //创意分类
+        if (!Check.isNull(data.getString("creativeCategory"))) {
+            creativeJson.put("creative_category", data.getString("creativeCategory"));
+        }
+        //创意标签
+        if (!Check.isNull(data.getString("creativeTag"))) {
+            creativeJson.put("creative_tag", data.getString("creative_tag"));
+        }
+        return kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), creativeJson, 1);
+    }
+}