Forráskód Böngészése

出价方式预警

yumeng 4 éve
szülő
commit
be6779c3d2
21 módosított fájl, 1452 hozzáadás és 664 törlés
  1. 4 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java
  2. 658 654
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java
  3. 248 0
      module-common/src/main/java/cn/com/ctop/common/module/controller/WarningOperationLogController.java
  4. 2 1
      module-common/src/main/java/cn/com/ctop/common/module/entity/Project.java
  5. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java
  6. 75 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/WarningOperationLog.java
  7. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/ProjectMapper.java
  8. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java
  9. 15 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/WarningOperationLogMapper.java
  10. 11 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/ProjectMapper.xml
  11. 6 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml
  12. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/WarningOperationLogMapper.xml
  13. 23 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java
  14. 14 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IWarningOperationLogService.java
  15. 35 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java
  16. 19 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/WarningOperationLogServiceImpl.java
  17. 3 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouTemplateService.java
  18. 31 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IWarningOperationService.java
  19. 44 7
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  20. 134 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateServiceImpl.java
  21. 117 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/WarningOperationServiceImpl.java

+ 4 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -826,9 +826,11 @@ public class TestController {
         oauthTokenQueryWrapper.last("limit 1");
         CtopOauthToken token = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);
         try {
-            kuaishouInterfaceService.getCampaignList(token, null, null);
+            // kuaishouInterfaceService.getCampaignList(token, null, null);
             //1:获取全量广告组数据
-            kuaishouInterfaceService.getGroupList(token, null, null);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date parse = simpleDateFormat.parse("2020-11-11");
+            kuaishouInterfaceService.getGroupList(token, parse, parse);
         } catch (Exception e) {
             e.printStackTrace();
         }

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 658 - 654
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java


+ 248 - 0
module-common/src/main/java/cn/com/ctop/common/module/controller/WarningOperationLogController.java

@@ -0,0 +1,248 @@
+package cn.com.ctop.common.module.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import cn.com.ctop.common.module.service.IWarningOperationLogService;
+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.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 预警操作记录
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-11
+ */
+@Slf4j
+@Api(tags = "预警操作记录")
+@RestController
+@RequestMapping("/wa/warningOperationLog")
+public class WarningOperationLogController {
+    @Autowired
+    private IWarningOperationLogService warningOperationLogService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param warningOperationLog
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-分页列表查询")
+    @ApiOperation(value = "预警操作记录-分页列表查询", notes = "预警操作记录-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<WarningOperationLog>> queryPageList(WarningOperationLog warningOperationLog,
+                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                            HttpServletRequest req) {
+        Result<IPage<WarningOperationLog>> result = new Result<>();
+        QueryWrapper<WarningOperationLog> queryWrapper = QueryGenerator.initQueryWrapper(warningOperationLog, req.getParameterMap());
+        Page<WarningOperationLog> page = new Page<WarningOperationLog>(pageNo, pageSize);
+        IPage<WarningOperationLog> pageList = warningOperationLogService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param warningOperationLog
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-添加")
+    @ApiOperation(value = "预警操作记录-添加", notes = "预警操作记录-添加")
+    @PostMapping(value = "/add")
+    public Result<WarningOperationLog> add(@RequestBody WarningOperationLog warningOperationLog) {
+        Result<WarningOperationLog> result = new Result<>();
+        try {
+            warningOperationLogService.save(warningOperationLog);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param warningOperationLog
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-编辑")
+    @ApiOperation(value = "预警操作记录-编辑", notes = "预警操作记录-编辑")
+    @PutMapping(value = "/edit")
+    public Result<WarningOperationLog> edit(@RequestBody WarningOperationLog warningOperationLog) {
+        Result<WarningOperationLog> result = new Result<WarningOperationLog>();
+        WarningOperationLog warningOperationLogEntity = warningOperationLogService.getById(warningOperationLog.getId());
+        if (warningOperationLogEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = warningOperationLogService.updateById(warningOperationLog);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-通过id删除")
+    @ApiOperation(value = "预警操作记录-通过id删除", notes = "预警操作记录-通过id删除")
+    @DeleteMapping(value = "/delete")
+    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
+        try {
+            warningOperationLogService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-批量删除")
+    @ApiOperation(value = "预警操作记录-批量删除", notes = "预警操作记录-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<WarningOperationLog> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<WarningOperationLog> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.warningOperationLogService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-通过id查询")
+    @ApiOperation(value = "预警操作记录-通过id查询", notes = "预警操作记录-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<WarningOperationLog> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<WarningOperationLog> result = new Result<>();
+        WarningOperationLog warningOperationLog = warningOperationLogService.getById(id);
+        if (warningOperationLog == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(warningOperationLog);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<WarningOperationLog> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                WarningOperationLog warningOperationLog = JSON.parseObject(deString, WarningOperationLog.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(warningOperationLog, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<WarningOperationLog> pageList = warningOperationLogService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "预警操作记录列表");
+        mv.addObject(NormalExcelConstants.CLASS, WarningOperationLog.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("预警操作记录列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<WarningOperationLog> listWarningOperationLogs = ExcelImportUtil.importExcel(file.getInputStream(), WarningOperationLog.class, params);
+                warningOperationLogService.saveBatch(listWarningOperationLogs);
+                return Result.ok("文件导入成功!数据行数:" + listWarningOperationLogs.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("文件导入失败!");
+    }
+
+}

+ 2 - 1
module-common/src/main/java/cn/com/ctop/common/module/entity/Project.java

@@ -127,7 +127,8 @@ public class Project {
 
     @TableField(exist = false)
     private Integer needExamine;
-
+    private Integer bidType;
+    private Integer ocpxActionType;
 
    /* @TableField(exist = false)
     private String responsibleName; // 运营负责人

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

@@ -126,6 +126,9 @@ public class UserAllocation implements Serializable {
     @ApiModelProperty(value = "平台类型 1 头条 2快手")
     private String mediaId;
 
+
+
+
    /* @TableField(exist = false)
     private String advertiserName;
 

+ 75 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/WarningOperationLog.java

@@ -0,0 +1,75 @@
+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;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 预警操作记录
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-11
+ */
+@Data
+@TableName("ctop_warning_operation_log")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_warning_operation_log对象", description = "预警操作记录")
+public class WarningOperationLog {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long unitId;
+    /**
+     * 发送人
+     */
+    @Excel(name = "发送人", width = 15)
+    @ApiModelProperty(value = "发送人")
+    private String userId;
+    /**
+     * 标题
+     */
+    @Excel(name = "标题", width = 15)
+    @ApiModelProperty(value = "标题")
+    private String subject;
+    /**
+     * 预警类型 1 出价方式  2 出价过高
+     */
+    @Excel(name = "预警类型 1 出价方式  2 出价过高 ", width = 15)
+    @ApiModelProperty(value = "预警类型 1 出价方式  2 出价过高 ")
+    private Integer warningType;
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 3 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/ProjectMapper.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.Project;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -14,4 +15,6 @@ import org.apache.ibatis.annotations.Param;
 public interface ProjectMapper extends BaseMapper<Project> {
 
     String getNameByAccountId(@Param("accountId") Long accountId);
+
+    JSONObject getWarningInfoByProjectId(@Param("projectId") Long projectId);
 }

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -25,4 +25,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<JSONObject> getUserIdListByProjectId(@Param("projectId") Long projectId);
 
     List<JSONObject> getAccountIdListByUserId(@Param("userId") Long userId);
+
+    Long getProjectIdByAccountId(@Param("accountId") Long accountId);
 }

+ 15 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/WarningOperationLogMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.common.module.mapper;
+
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 预警操作记录
+ *
+ * @author: jeecg-boot
+ * @date: 2020-11-11
+ * @cersion: V1.0
+ */
+public interface WarningOperationLogMapper extends BaseMapper<WarningOperationLog> {
+
+}

+ 11 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/ProjectMapper.xml

@@ -10,4 +10,15 @@
      )
     </select>
 
+    <select id="getWarningInfoByProjectId" resultType="com.alibaba.fastjson.JSONObject">
+     select
+     id projectId,
+     project_name projectName,
+     max_bid maxBid,
+     bid_type bidType,
+     ocpx_action_type ocpxActionType
+     from ctop_project
+     where id = #{projectId}
+    </select>
+
 </mapper>

+ 6 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -63,5 +63,11 @@
     AND t1.account_status = 0
     </select>
 
+    <select id="getProjectIdByAccountId" resultType="java.lang.Long">
+    select  project_id  from  ctop_user_allocation
+    where account_id = #{accountId}
+    limit 1
+    </select>
+
 
 </mapper>

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/WarningOperationLogMapper.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.common.module.mapper.WarningOperationLogMapper">
+
+</mapper>

+ 23 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java

@@ -58,4 +58,27 @@ public interface IMessageTemplate {
      */
     String getAlarmCostMessage(JSONObject cost);
 
+    /**
+     * 快手 组出价方式错误消息模板
+     *
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     * @return
+     */
+
+    String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name);
+
+
+    /**
+     * 快手 组出价过高消息模板
+     *
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     * @return
+     */
+    String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name);
 }

+ 14 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IWarningOperationLogService.java

@@ -0,0 +1,14 @@
+package cn.com.ctop.common.module.service;
+
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 预警操作记录
+ * @Author: jeecg-boot
+ * @Date: 2020-11-11
+ * @Version: V1.0
+ */
+public interface IWarningOperationLogService extends IService<WarningOperationLog> {
+
+}

+ 35 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java

@@ -156,4 +156,39 @@ public class MessageTemplateImpl implements IMessageTemplate {
                 .append(obj.getString("end"));
         return text.toString();
     }
+
+
+    /**
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     * @return
+     */
+
+    @Override
+    public String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name) {
+        StringBuilder text = new StringBuilder();
+        text.append("出价方式错误预警").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("下的账户:").append(advertiserId + ",").append("<br/>")
+                .append("广告组id为:").append(unitId).append("<br/>")
+                .append("广告组名称为:").append(unit_name).append("<br/>")
+                .append("出价方式设置错误。").append("<br/>")
+                .append("系统已执行暂停此组操作,请您及时查看!");
+        return text.toString();
+    }
+
+    @Override
+    public String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name) {
+        StringBuilder text = new StringBuilder();
+        text.append("出价过高预警").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("下的账户:").append(advertiserId + ",").append("<br/>")
+                .append("广告组id为:").append(unitId).append("<br/>")
+                .append("广告组名称为:").append(unit_name).append("<br/>")
+                .append("出价设置错过高。").append("<br/>")
+                .append("系统已执行暂停此组操作,请您及时查看!");
+        return text.toString();
+    }
 }

+ 19 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/WarningOperationLogServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import cn.com.ctop.common.module.mapper.WarningOperationLogMapper;
+import cn.com.ctop.common.module.service.IWarningOperationLogService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 预警操作记录
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-11
+ */
+@Service
+public class WarningOperationLogServiceImpl extends ServiceImpl<WarningOperationLogMapper, WarningOperationLog> implements IWarningOperationLogService {
+
+}

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

@@ -15,4 +15,7 @@ public interface IKuaishouTemplateService extends IService<KuaishouTemplate> {
     void getTemplateByAccountId(Long accountId, String accessToken, Integer page);
 
     JSONObject createTemplate(Long accountId, String accessToken, JSONObject requestJson);
+
+
+    JSONObject updateTemplate(Long accountId, String accessToken, JSONObject requestJson);
 }

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

@@ -0,0 +1,31 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface IWarningOperationService {
+    JSONObject getBidTypeAndMaxBid(Long accountId);
+
+    /**
+     * 快手 出价方式 预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+    void kuaiShouWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name);
+
+
+    /**
+     * 出价 过高预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+
+    void kuaiShouBidWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name);
+}

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

@@ -138,6 +138,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private IKuaiShouGroupService getKuaiShouGroupService;
     @Autowired
     private IKuaiShouAdvertiserBaseInfoService KuaiShouAdvertiserBaseInfoService;
+    @Autowired
+    private IWarningOperationService warningOperationService;
 
 
     @Override
@@ -1201,7 +1203,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
         JSONObject param = new JSONObject();
         param.put("advertiser_id", token.getAccountId());
-        param.put("page_size", 200);
+        param.put("page_size", 500);
         param.put("page", page);
         if (startDate != null && endDate != null) {
             param.put("start_date", DateUtils.formatDate(startDate));
@@ -1230,25 +1232,60 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         getGroupListByPage(token, startDate, endDate, page + 1);
     }
 
-
+    static ExecutorService executorBidTypeService = Executors.newFixedThreadPool(20);
+    static ExecutorService executorMaxBidService = Executors.newFixedThreadPool(5);
     private void addGroup(Long advertiserId, JSONArray details) {
+        JSONObject json = warningOperationService.getBidTypeAndMaxBid(advertiserId);
+        Long maxBid = json.getLong("maxBid");// 最高出价
+        Integer bidType = json.getInteger("bidType"); // 出价方式
+        Integer ocpxActionType = json.getInteger("ocpxActionType"); // 优化目标
         if (!Check.isNull(details)) {
             List<KuaiShouGroup> groups = new ArrayList<>();
             for (int i = 0; i < details.size(); i++) {
                 JSONObject detail = JSONObject.parseObject(details.get(i).toString());
                 if (!Check.isNull(detail)) {
-                    KuaiShouGroup group = new KuaiShouGroup();
+                    Integer bid_type = detail.getInteger("bid_type");
+                    Long bid = detail.getLong("bid");
+                    Long cpa_bid = detail.getLong("cpa_bid");
+                    Long day_budget = detail.getLong("day_budget");
+                    Integer ocpx_action_type = detail.getInteger("ocpx_action_type");
                     Long unitId = detail.getLong("unit_id");
+                    String unit_name = detail.getString("unit_name");
+                    Integer status = detail.getInteger("status");
+                    Integer put_status = detail.getInteger("put_status");
+                    if (put_status == 1) { // 组状态为 投放中的
+                        if (status != 15) { // 广告组状态为非暂停
+                            if ((!bidType.equals(bid_type)) || (!ocpxActionType.equals(ocpx_action_type))) { // 出价方式设置非法
+                                if (day_budget > 500 * 1000 || day_budget == 0) { // 预算大于500 或者不限制预算 需要发送通知 并且进行暂停操作
+                                    executorBidTypeService.submit(new Runnable() {
+                                        @Override
+                                        public void run() {
+                                            warningOperationService.kuaiShouWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
+                                        }
+                                    });
+                                }
+                            }
+                            if (bid > maxBid || cpa_bid > maxBid) {
+                                executorMaxBidService.submit(new Runnable() {
+                                    @Override
+                                    public void run() {
+                                        warningOperationService.kuaiShouBidWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
+                                    }
+                                });
+                            }
+                        }
+                    }
+                    KuaiShouGroup group = new KuaiShouGroup();
                     group.setId("" + advertiserId + unitId);
                     group.setAccountId(advertiserId);
                     group.setCampaignId(detail.getLong("campaign_id"));
                     group.setUnitId(unitId);
-                    group.setUnitName(detail.getString("unit_name"));
-                    group.setStatus(detail.getInteger("status"));
-                    group.setPutStatus(detail.getInteger("put_status"));
+                    group.setUnitName(unit_name);
+                    group.setStatus(status);
+                    group.setPutStatus(put_status);
                     group.setCreateChannel(detail.getInteger("create_channel"));
                     group.setReviewDetail(detail.getString("review_detail"));
-                    group.setBidType(detail.getInteger("bid_type"));
+                    group.setBidType(bid_type);
                     group.setBid(detail.getLong("bid"));
                     group.setCpaBid(detail.getLong("cpa_bid"));
                     group.setOcpxActionType(detail.getInteger("ocpx_action_type"));

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

@@ -310,4 +310,138 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
         }
         return null;
     }
+
+
+    /**
+     * 修改定向模板
+     *
+     * @param accountId
+     * @param accessToken
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public JSONObject updateTemplate(Long accountId, String accessToken, JSONObject requestJson) {
+        try {
+            if (Check.isNull(requestJson.getString("templateName"))) {
+                throw new Exception("定向模板名称为必传项");
+            }
+
+            JSONObject param = new JSONObject();
+            param.put("advertiser_id", accountId);
+            param.put("template_name", requestJson.getString("templateName"));
+            JSONObject targetJson = new JSONObject();
+            if (!Check.isNull(requestJson.getJSONArray("region"))) {
+                targetJson.put("region", requestJson.getJSONArray("region"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("districtIds"))) {
+                targetJson.put("district_ids", requestJson.getJSONArray("districtIds"));
+            }
+            if (!Check.isNull(requestJson.getInteger("userType"))) {
+                targetJson.put("user_type", requestJson.getInteger("userType"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
+                targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
+            }
+
+            JSONObject ageJson = new JSONObject();
+            if (!Check.isNull(requestJson.getInteger("min"))) {
+                ageJson.put("min", requestJson.getInteger("min"));
+            }
+            if (!Check.isNull(requestJson.getInteger("max"))) {
+                ageJson.put("max", requestJson.getInteger("max"));
+            }
+            if (!Check.isNull(ageJson)) {
+                targetJson.put("age", ageJson);
+            }
+
+            if (!Check.isNull(requestJson.getInteger("gender"))) {
+                targetJson.put("gender", requestJson.getInteger("gender"));
+            }
+            if (!Check.isNull(requestJson.getInteger("platformOs"))) {
+                targetJson.put("platform_os", requestJson.getInteger("platformOs"));
+            }
+            if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
+                targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
+            }
+            if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
+                targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
+            }
+            if (!Check.isNull(requestJson.getInteger("network"))) {
+                targetJson.put("network", requestJson.getInteger("network"));
+            }
+            if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
+                targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
+                targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
+                targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
+            }
+            if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
+                targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
+                targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
+                targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
+                targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
+                targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
+                targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("population"))) {
+                targetJson.put("population", requestJson.getJSONArray("population"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("paidAudience"))) {
+                targetJson.put("paid_audience", requestJson.getJSONArray("paidAudience"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
+                targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
+            }
+            JSONObject intelliExtendJson = new JSONObject();
+
+            if (!Check.isNull(requestJson.getInteger("isOpen"))) {
+                intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
+                intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
+                intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
+                intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
+            }
+            if (!Check.isNull(intelliExtendJson)) {
+                targetJson.put("intelli_extend", intelliExtendJson);
+            }
+            if (!Check.isNull(targetJson)) {
+                param.put("target", targetJson);
+            }
+
+            Map<String, String> headers = new HashMap<String, String>();
+            headers.put("Access-Token", accessToken);
+            headers.put("Content-Type", " application/json");
+
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
+            System.err.println(param);
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+
+            JSONObject resultJson = JSONObject.parseObject(result);
+            System.err.println(resultJson);
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

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

@@ -0,0 +1,117 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import cn.com.ctop.common.module.mapper.ProjectMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IMessageTemplate;
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.service.IWarningOperationLogService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IWarningOperationService;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class WarningOperationServiceImpl implements IWarningOperationService {
+    @Autowired
+    private ProjectMapper projectMapper;
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+    @Autowired
+    private ISendMessageService sendMessageService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private IWarningOperationLogService warningOperationLogService;
+
+    @Override
+    public JSONObject getBidTypeAndMaxBid(Long accountId) {
+        Long projectId = userAllocationMapper.getProjectIdByAccountId(accountId);
+        if (Check.isNull(projectId)) {
+            log.error("此账户未绑定项目");
+            return null;
+        }
+        JSONObject warningJson = projectMapper.getWarningInfoByProjectId(projectId);
+        return warningJson;
+    }
+
+
+    /**
+     * 快手出价方式预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+
+    @Override
+    public void kuaiShouWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name) {
+
+        String userId = userAllocationMapper.queryUserIdByAccountId(advertiserId);
+        try {
+            String text = messageTemplate.getKuaiShouBidTypeMessage(projectName, advertiserId, unitId, unit_name);
+
+            sendMessageService.sendMessage(userId, text);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserId);
+        updateService.updateUnitStatus(token.getAccessToken(), advertiserId, unitId, 2, "admin");
+        WarningOperationLog warningOperationLog = new WarningOperationLog();
+        warningOperationLog.setAccountId(advertiserId);
+        warningOperationLog.setSubject("出价方式预警");
+        warningOperationLog.setUnitId(unitId);
+        warningOperationLog.setUserId(userId);
+        warningOperationLog.setWarningType(1);
+        warningOperationLogService.save(warningOperationLog);
+
+
+    }
+
+
+    /**
+     * 出价 过高预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+
+    @Override
+    public void kuaiShouBidWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name) {
+        String userId = userAllocationMapper.queryUserIdByAccountId(advertiserId);
+        try {
+            String text = messageTemplate.getKuaiShouBidMessage(projectName, advertiserId, unitId, unit_name);
+
+            sendMessageService.sendMessage(userId, text);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserId);
+        updateService.updateUnitStatus(token.getAccessToken(), advertiserId, unitId, 2, "admin");
+
+        WarningOperationLog warningOperationLog = new WarningOperationLog();
+        warningOperationLog.setAccountId(advertiserId);
+        warningOperationLog.setSubject("出价过高预警");
+        warningOperationLog.setUnitId(unitId);
+        warningOperationLog.setUserId(userId);
+        warningOperationLog.setWarningType(2);
+        warningOperationLogService.save(warningOperationLog);
+
+    }
+}