فهرست منبع

落地页功能

zhaoxian 4 سال پیش
والد
کامیت
7ba499e754
16فایلهای تغییر یافته به همراه973 افزوده شده و 3 حذف شده
  1. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java
  2. 11 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml
  3. 9 3
      module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java
  4. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java
  5. 29 0
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouLandpageJob.java
  6. 339 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouLandpagePackageController.java
  7. 119 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouLandpagePackage.java
  8. 63 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouLandpagePackageRel.java
  9. 29 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouLandpagePackageMapper.java
  10. 20 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouLandpagePackageRelMapper.java
  11. 92 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouLandpagePackageMapper.xml
  12. 12 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouLandpagePackageRelMapper.xml
  13. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouLandpagePackageRelService.java
  14. 38 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouLandpagePackageService.java
  15. 19 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouLandpagePackageRelServiceImpl.java
  16. 172 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouLandpagePackageServiceImpl.java

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

@@ -44,4 +44,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<UserAllocation> listByMediaId(@Param("mediaId")String mediaId, @Param("accountStatus")Integer accountStatus);
 
     List<JSONObject> getAccountListByProjectList(@Param("list") List list);
+
+    List<Long> getValidProjectIds(@Param("mediaId")  Integer mediaId);
 }

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

@@ -12,6 +12,7 @@
         ctop_user_allocation a
         left join ctop_project b on a.project_id = b.id
         where b.id = #{projectId}
+        and account_status = 0
     </select>
 
     <select id="queryAdvertiserId" resultType="String">
@@ -71,6 +72,16 @@
     </select>
 
 
+    <select id="getValidProjectIds" resultType="java.lang.Long">
+        SELECT project_id FROM ctop_user_allocation t1
+        where account_status = 0
+        <if test="mediaId != null">
+              AND media_id = #{mediaId}
+        </if>
+        GROUP BY project_id
+    </select>
+
+
     <select id="getAccountIdListByUserId" resultType="com.alibaba.fastjson.JSONObject">
     SELECT
     t1.account_id as 'accountId',

+ 9 - 3
module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -1,7 +1,6 @@
 package cn.com.ctop.common.module.service;
 
 import cn.com.ctop.common.module.entity.UserAllocation;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -18,7 +17,7 @@ public interface IUserAllocationService extends IService<UserAllocation> {
 
     UserAllocation getByAccountId(Long accountId);
 
-    List<UserAllocation> getByParams(Long projectId, String systemType,Integer accountStatus);
+    List<UserAllocation> getByParams(Long projectId, String systemType, Integer accountStatus);
 
     Map<String, Object> getPangolinAccountListByParams(String userId, JSONObject data);
 
@@ -38,7 +37,7 @@ public interface IUserAllocationService extends IService<UserAllocation> {
 
     List<JSONObject> getAccountIdsByUserId(String userId);
 
-    List<UserAllocation> getUserAllocations(String mediaId ,int switchType);
+    List<UserAllocation> getUserAllocations(String mediaId, int switchType);
 
     JSONObject getSwitchStatusByAccount(Long accountId);
 
@@ -46,5 +45,12 @@ public interface IUserAllocationService extends IService<UserAllocation> {
 
     Map<Long, List<JSONObject>> getAccountListByProjectList(List<JSONObject> projectList);
 
+    /**
+     * 获取有效的项目ID集合
+     *
+     * @param mediaId 平台类型 1 头条 2快手
+     * @throws
+     */
+    List<Long> getValidProjectIds(Integer mediaId);
 
 }

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

@@ -175,4 +175,9 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         }
         return map;
     }
+
+    @Override
+    public List<Long> getValidProjectIds(Integer mediaId) {
+        return userAllocationMapper.getValidProjectIds(mediaId);
+    }
 }

+ 29 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouLandpageJob.java

@@ -0,0 +1,29 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class KuaishouLandpageJob {
+    @Autowired
+    private IKuaishouLandpagePackageService landpagePackageService;
+    @Autowired
+    private IUserAllocationService userAllocationService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(3);
+
+    @XxlJob("kuaishouCampaignJob")
+    public void execute() {
+        //获取快手有效的账户
+        List<Long> list = userAllocationService.getValidProjectIds(2);
+        list.forEach(projectId -> executorService.submit(() -> landpagePackageService.synchronousData(projectId)));
+        XxlJobHelper.log("快手落地页数据更新");
+    }
+}

+ 339 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouLandpagePackageController.java

@@ -0,0 +1,339 @@
+package cn.com.ctop.kuaishou.modules.ai.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.QueryGenerator;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackage;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.pagehelper.PageHelper;
+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.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.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 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 2021-05-11
+ */
+@Slf4j
+@Api(tags = "落地页账户项目关联表")
+@RestController
+@RequestMapping("/kuaishouLandpagePackage")
+public class KuaishouLandpagePackageController {
+    @Autowired
+    private IKuaishouLandpagePackageService kuaishouLandpagePackageService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param kuaishouLandpagePackage
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "落地页账户项目关联表-分页列表查询")
+    @ApiOperation(value = "落地页账户项目关联表-分页列表查询", notes = "落地页账户项目关联表-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<Object> queryPageList(KuaishouLandpagePackage kuaishouLandpagePackage, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        try {
+            return kuaishouLandpagePackageService.queryPageList(kuaishouLandpagePackage, pageNo, pageSize);
+        } catch (Exception e) {
+            log.error("查询落地页列表异常", e);
+        }
+        return Result.error("查询落地页列表失败");
+    }
+
+    /**
+     * 同步项目下落地页和账户关联数据
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @GetMapping(value = "/synchronousData")
+    public Result<Object> synchronousData(KuaishouLandpagePackage kuaishouLandpagePackage) {
+        try {
+            if (Check.isNull(kuaishouLandpagePackage.getProjectId())) {
+                return Result.error("请选择项目");
+            }
+            return kuaishouLandpagePackageService.synchronousData(kuaishouLandpagePackage.getProjectId());
+        } catch (Exception e) {
+            log.error("同步落地页数据异常", e);
+        }
+        return Result.error("同步落地页数据失败");
+    }
+
+    /**
+     * 查询相关账户
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @GetMapping(value = "/getRelatedAccounts")
+    public Result<Object> getRelatedAccounts(Long siteId, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        try {
+            if (Check.isNull(siteId)) {
+                return Result.error("缺少参数");
+            }
+            PageHelper.startPage(pageNo, pageSize);
+            return kuaishouLandpagePackageService.getRelatedAccounts(siteId);
+        } catch (Exception e) {
+            log.error("查询异常", e);
+        }
+        return Result.error("查询失败");
+
+    }
+
+    /**
+     * 查询相关组
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @GetMapping(value = "/getRelatedGroups")
+    public Result<Object> getRelatedGroups(Long siteId, Long accountId, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        try {
+            if (Check.isNull(siteId)) {
+                return Result.error("缺少参数");
+            }
+            PageHelper.startPage(pageNo, pageSize);
+            return kuaishouLandpagePackageService.getRelatedGroups(siteId, accountId);
+        } catch (Exception e) {
+            log.error("查询异常", e);
+        }
+        return Result.error("查询失败");
+
+    }
+
+    /**
+     * 查询相关组
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @GetMapping(value = "/createLandPageAndUnit")
+    public Result<Object> createLandPageAndUnit(Long siteId, Long creativeId, Long unitId, Long accountId) {
+        try {
+            kuaishouLandpagePackageService.createLandPageAndUnit(siteId, creativeId, unitId, accountId);
+        } catch (Exception e) {
+            log.error("查询异常", e);
+        }
+        return Result.ok("ok");
+
+    }
+
+    /**
+     * 添加
+     *
+     * @param kuaishouLandpagePackage
+     * @return
+     */
+    @AutoLog(value = "落地页账户项目关联表-添加")
+    @ApiOperation(value = "落地页账户项目关联表-添加", notes = "落地页账户项目关联表-添加")
+    @PostMapping(value = "/add")
+    public Result<KuaishouLandpagePackage> add(@RequestBody KuaishouLandpagePackage kuaishouLandpagePackage) {
+        Result<KuaishouLandpagePackage> result = new Result<>();
+        try {
+            kuaishouLandpagePackageService.save(kuaishouLandpagePackage);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param kuaishouLandpagePackage
+     * @return
+     */
+    @AutoLog(value = "落地页账户项目关联表-编辑")
+    @ApiOperation(value = "落地页账户项目关联表-编辑", notes = "落地页账户项目关联表-编辑")
+    @PutMapping(value = "/edit")
+    public Result<KuaishouLandpagePackage> edit(@RequestBody KuaishouLandpagePackage kuaishouLandpagePackage) {
+        Result<KuaishouLandpagePackage> result = new Result<KuaishouLandpagePackage>();
+        KuaishouLandpagePackage kuaishouLandpagePackageEntity = kuaishouLandpagePackageService.getById(kuaishouLandpagePackage.getId());
+        if (kuaishouLandpagePackageEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = kuaishouLandpagePackageService.updateById(kuaishouLandpagePackage);
+            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 {
+            kuaishouLandpagePackageService.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<KuaishouLandpagePackage> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<KuaishouLandpagePackage> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.kuaishouLandpagePackageService.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<KuaishouLandpagePackage> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<KuaishouLandpagePackage> result = new Result<>();
+        KuaishouLandpagePackage kuaishouLandpagePackage = kuaishouLandpagePackageService.getById(id);
+        if (kuaishouLandpagePackage == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(kuaishouLandpagePackage);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<KuaishouLandpagePackage> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                KuaishouLandpagePackage kuaishouLandpagePackage = JSON.parseObject(deString, KuaishouLandpagePackage.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(kuaishouLandpagePackage, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<KuaishouLandpagePackage> pageList = kuaishouLandpagePackageService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "落地页账户项目关联表列表");
+        mv.addObject(NormalExcelConstants.CLASS, KuaishouLandpagePackage.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<KuaishouLandpagePackage> listKuaishouLandpagePackages = ExcelImportUtil.importExcel(file.getInputStream(), KuaishouLandpagePackage.class, params);
+                kuaishouLandpagePackageService.saveBatch(listKuaishouLandpagePackages);
+                return Result.ok("文件导入成功!数据行数:" + listKuaishouLandpagePackages.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("文件导入失败!");
+    }
+
+}

+ 119 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouLandpagePackage.java

@@ -0,0 +1,119 @@
+package cn.com.ctop.kuaishou.modules.ai.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+/**
+ * 落地页账户项目关联表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-05-11
+ */
+@Data
+@TableName("ctop_kuaishou_landpage_package")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_landpage_package对象", description = "落地页账户项目关联表")
+public class KuaishouLandpagePackage {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 项目ID
+     */
+    @Excel(name = "项目ID", width = 15)
+    @ApiModelProperty(value = "项目ID")
+    private Long projectId;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+    /**
+     * 落地页名称
+     */
+    @Excel(name = "落地页名称", width = 15)
+    @ApiModelProperty(value = "落地页名称")
+    private String landpageName;
+    /**
+     * 落地页ID
+     */
+    @Excel(name = "落地页ID", width = 15)
+    @ApiModelProperty(value = "落地页ID")
+    private Long siteId;
+    /**
+     * 落地页URL
+     */
+    @Excel(name = "落地页URL", width = 15)
+    @ApiModelProperty(value = "落地页URL")
+    private String url;
+    /**
+     * 落地页类型	0:站内;1:联盟
+     */
+    @Excel(name = "落地页类型	0:站内;1:联盟", width = 15)
+    @ApiModelProperty(value = "落地页类型	0:站内;1:联盟")
+    private Integer bizType;
+    /**
+     * 应用ID
+     */
+    @Excel(name = "应用ID", width = 15)
+    @ApiModelProperty(value = "应用ID")
+    private Long appId;
+    /**
+     * 组件数据
+     */
+    @Excel(name = "组件数据", width = 15)
+    @ApiModelProperty(value = "组件数据")
+    private String comps;
+    /**
+     * 落地页创建时间
+     */
+    @Excel(name = "落地页创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "落地页创建时间")
+    private Date landpageCreateTime;
+    /**
+     * 落地页修改时间
+     */
+    @Excel(name = "落地页修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "落地页修改时间")
+    private Date landpageUpdateTime;
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 63 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouLandpagePackageRel.java

@@ -0,0 +1,63 @@
+package cn.com.ctop.kuaishou.modules.ai.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+/**
+ * 落地页-广告组关联表
+ * @author jeecg-boot
+ * @date   2021-05-11
+ * @version V1.0
+ */
+@Data
+@TableName("ctop_kuaishou_landpage_package_rel")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="ctop_kuaishou_landpage_package_rel对象", description="落地页-广告组关联表")
+public class KuaishouLandpagePackageRel {
+    
+	/**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;
+	/**落地页id*/
+	@Excel(name = "落地页id", width = 15)
+    @ApiModelProperty(value = "落地页id")
+	private Long siteId;
+	/**创意ID集*/
+	@Excel(name = "创意ID集", width = 15)
+    @ApiModelProperty(value = "创意ID集")
+	private String creativeArr;
+	/**创建时间*/
+	@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+	private Date createTime;
+	/**修改时间*/
+	@Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+	private Date updateTime;
+}

+ 29 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouLandpagePackageMapper.java

@@ -0,0 +1,29 @@
+package cn.com.ctop.kuaishou.modules.ai.mapper;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackage;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 落地页账户项目关联表
+ *
+ * @author: jeecg-boot
+ * @date: 2021-05-11
+ * @cersion: V1.0
+ */
+public interface KuaishouLandpagePackageMapper extends BaseMapper<KuaishouLandpagePackage> {
+
+    void replaceBatch(@Param("landpagePackageList") List<KuaishouLandpagePackage> landpagePackageList);
+
+    void deleteByAccountId(@Param("accountId") Long accountId);
+
+    List<JSONObject> queryPageList(@Param("accountId") Long accountId,@Param("projectId") Long projectId);
+
+    List<JSONObject> getRelatedAccounts(@Param("siteId") Long siteId);
+
+    List<JSONObject> getRelatedGroups(@Param("siteId") Long siteId, @Param("accountId") Long accountId);
+
+}

+ 20 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouLandpagePackageRelMapper.java

@@ -0,0 +1,20 @@
+package cn.com.ctop.kuaishou.modules.ai.mapper;
+
+import java.util.List;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackageRel;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 落地页-广告组关联表
+ * @author: jeecg-boot
+ * @date:   2021-05-11
+ * @cersion: V1.0
+ */
+public interface KuaishouLandpagePackageRelMapper extends BaseMapper<KuaishouLandpagePackageRel> {
+
+    JSONObject queryByUnitId(@Param("siteId") Long siteId,@Param("unitId") Long unitId,@Param("accountId") Long accountId);
+
+}

+ 92 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouLandpagePackageMapper.xml

@@ -0,0 +1,92 @@
+<?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.ai.mapper.KuaishouLandpagePackageMapper">
+
+
+    <insert id="replaceBatch">
+        replace into ctop_kuaishou_landpage_package(
+        id,
+        project_id,
+        account_id,
+        landpage_name,
+        site_id,
+        url,
+        biz_type,
+        app_id,
+        comps,
+        landpage_create_time,
+        landpage_update_time
+        )
+        values
+        <foreach collection="landpagePackageList" item="landpage" separator=",">
+            (
+            #{landpage.id},
+            #{landpage.projectId},
+            #{landpage.accountId},
+            #{landpage.landpageName},
+            #{landpage.siteId},
+            #{landpage.url},
+            #{landpage.bizType},
+            #{landpage.appId},
+            #{landpage.comps},
+            #{landpage.landpageCreateTime},
+            #{landpage.landpageUpdateTime}
+            )
+        </foreach>
+    </insert>
+
+    <delete id="deleteByAccountId">
+        delete
+        from ctop_kuaishou_landpage_package
+        where account_id = #{accountId}
+    </delete>
+
+    <select id="queryPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.project_id 'projectId',
+        t1.account_id 'accountId',
+        t1.site_id 'siteId',
+        t1.landpage_name 'landpageName',
+        t2.project_name 'projectName',
+        t3.auth_name 'authName',
+        t1.landpage_update_time 'landpageUpdateTime',
+        (SELECT COUNT(1) FROM ctop_kuaishou_landpage_package WHERE site_id = t1.site_id) as 'accountCount',
+        (SELECT COUNT(1) FROM ctop_kuaishou_landpage_package_rel WHERE site_id = t1.site_id) as 'unitCount'
+        FROM ctop_kuaishou_landpage_package t1
+        LEFT JOIN ctop_project t2 ON t1.project_id = t2.id
+        LEFT JOIN ctop_user_allocation t3 ON t1.account_id = t3.account_id
+        WHERE 1=1
+        <if test="projectId!=null">
+            AND t1.project_id =#{projectId}
+        </if>
+        <if test="accountId!=null">
+            AND t1.account_id =#{accountId}
+        </if>
+        ORDER BY t1.landpage_update_time desc
+    </select>
+
+    <select id="getRelatedAccounts" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t2.auth_name 'authName', (SELECT COUNT(1)
+                                         FROM ctop_kuaishou_landpage_package
+                                         WHERE account_id = t1.account_id) 'count'
+        FROM ctop_kuaishou_landpage_package t1
+                 LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where t1.account_id IN (
+            SELECT DISTINCT account_id
+            FROM ctop_kuaishou_landpage_package
+            WHERE site_id = #{siteId}
+        )
+        GROUP BY t1.account_id
+    </select>
+
+    <select id="getRelatedGroups" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t2.auth_name 'authName', t3.unit_name 'unitName'
+        FROM ctop_kuaishou_landpage_package_rel t1
+        INNER JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        INNER JOIN ctop_kuaishou_group t3 ON t1.unit_id = t3.unit_id
+        where t1.site_id = #{siteId}
+        <if test="accountId!=null">
+            AND t1.account_id = #{accountId}
+        </if>
+    </select>
+</mapper>

+ 12 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouLandpagePackageRelMapper.xml

@@ -0,0 +1,12 @@
+<?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.ai.mapper.KuaishouLandpagePackageRelMapper">
+
+    <select id="queryByUnitId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT id,creative_arr
+        FROM ctop_kuaishou_landpage_package_rel
+        WHERE unit_id = #{unitId}
+          AND site_id = #{siteId}
+          AND account_id = #{accountId}
+    </select>
+</mapper>

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

@@ -0,0 +1,14 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackageRel;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 落地页-广告组关联表
+ * @Author: jeecg-boot
+ * @Date:   2021-05-11
+ * @Version: V1.0
+ */
+public interface IKuaishouLandpagePackageRelService extends IService<KuaishouLandpagePackageRel> {
+
+}

+ 38 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouLandpagePackageService.java

@@ -0,0 +1,38 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+
+import java.util.List;
+
+/**
+ * @Description: 落地页账户项目关联表
+ * @Author: jeecg-boot
+ * @Date: 2021-05-11
+ * @Version: V1.0
+ */
+public interface IKuaishouLandpagePackageService extends IService<KuaishouLandpagePackage> {
+
+    Result<Object> queryPageList(KuaishouLandpagePackage kuaishouLandpagePackage, Integer pageNo, Integer pageSize);
+
+    Result<Object> synchronousData(Long projectId);
+
+    Result<Object> getRelatedAccounts(Long siteId);
+
+    Result<Object> getRelatedGroups(Long siteId, Long accountId);
+
+    /**
+     * 绑定落地页与广告组的关系
+     *
+     * @param siteId     落地页Id
+     * @param creativeId 创意ID
+     * @param unitId     广告组ID
+     * @param accountId  账户ID
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
+    void createLandPageAndUnit(Long siteId, Long creativeId, Long unitId, Long accountId);
+
+}

+ 19 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouLandpagePackageRelServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackageRel;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouLandpagePackageRelMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageRelService;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * 落地页-广告组关联表
+ * @author jeecg-boot
+ * @date   2021-05-11
+ * @version V1.0
+ */
+@Service
+public class KuaishouLandpagePackageRelServiceImpl extends ServiceImpl<KuaishouLandpagePackageRelMapper, KuaishouLandpagePackageRel> implements IKuaishouLandpagePackageRelService {
+
+}

+ 172 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouLandpagePackageServiceImpl.java

@@ -0,0 +1,172 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackage;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouLandpagePackageRel;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouLandpagePackageMapper;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouLandpagePackageRelMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
+import com.alibaba.fastjson.JSON;
+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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 落地页账户项目关联表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-05-11
+ */
+@Service
+public class KuaishouLandpagePackageServiceImpl extends ServiceImpl<KuaishouLandpagePackageMapper, KuaishouLandpagePackage> implements IKuaishouLandpagePackageService {
+
+    @Autowired
+    private KuaishouLandpagePackageMapper landpagePackageMapper;
+    @Autowired
+    private KuaishouLandpagePackageRelMapper landpagePackageRelMapper;
+    @Autowired
+    private KuaishouLandpagePackageRelServiceImpl landpagePackageRelService;
+
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
+    @Override
+    public Result<Object> queryPageList(KuaishouLandpagePackage kuaishouLandpagePackage, Integer pageNo, Integer pageSize) {
+        PageHelper.startPage(pageNo, pageSize);
+        List<JSONObject> list = landpagePackageMapper.queryPageList(kuaishouLandpagePackage.getAccountId(), kuaishouLandpagePackage.getProjectId());
+        return Result.ok(new PageInfo<JSONObject>(list));
+    }
+
+    @Override
+    public Result<Object> synchronousData(Long projectId) {
+        try {
+            List<UserAllocation> userAllocations = userAllocationMapper.selectAccountListByProjectId(projectId);
+            for (UserAllocation userAllocation : userAllocations) {
+                Long accountId = userAllocation.getAccountId();
+                CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+                String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.PAGE_LIST;
+                Map<String, String> headers = new HashMap<>();
+                headers.put("Content-Type", "application/json");
+                headers.put("Access-Token", oauthToken.getAccessToken());
+                Map<String, Object> param = new HashMap<>();
+                param.put("advertiser_id", accountId);
+                param.put("page_size", 500);
+                String result = HttpUtils.httpPostRequest(url, param, headers);
+                JSONObject resultJson = JSON.parseObject(result);
+                if (!Check.isNull(resultJson)) {
+                    if (resultJson.getInteger("code") == 0) {
+                        JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+                        if (!Check.isNull(details)) {
+                            List<KuaishouLandpagePackage> landpagePackageList = new ArrayList<>();
+                            for (int i = 0; i < details.size(); i++) {
+                                JSONObject jsonObject = details.getJSONObject(i);
+                                KuaishouLandpagePackage landpagePackage = getEntity(jsonObject);
+                                landpagePackage.setAccountId(accountId);
+                                landpagePackage.setProjectId(projectId);
+                                landpagePackageList.add(landpagePackage);
+                            }
+                            if (!Check.isNull(landpagePackageList)) {
+                                landpagePackageMapper.deleteByAccountId(accountId);
+                                landpagePackageMapper.replaceBatch(landpagePackageList);
+                            }
+
+                        }
+                    } else {
+                        log.error(resultJson.getString("message")+",accountId:"+accountId);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("同步项目下落地页和账户关联数据异常", e);
+            return Result.error("同步项目下落地页和账户关联数据异常");
+        }
+        return Result.ok("同步成功");
+    }
+
+    /**
+     * 处理对象参数
+     */
+    private KuaishouLandpagePackage getEntity(JSONObject jsonObject) {
+        KuaishouLandpagePackage landpagePackage = new KuaishouLandpagePackage();
+        landpagePackage.setLandpageName(jsonObject.getString("name"));
+        landpagePackage.setSiteId(jsonObject.getLong("id"));
+        landpagePackage.setUrl(jsonObject.getString("url"));
+        landpagePackage.setBizType(jsonObject.getInteger("biz_type"));
+        landpagePackage.setLandpageCreateTime(jsonObject.getSqlDate("create_time"));
+        landpagePackage.setLandpageUpdateTime(jsonObject.getSqlDate("update_time"));
+        JSONArray compsArr = jsonObject.getJSONArray("comps");
+        if (!Check.isNull(compsArr)) {
+            landpagePackage.setComps(JSONObject.toJSONString(compsArr));
+            for (int j = 0; j < compsArr.size(); j++) {
+                JSONObject compJson = compsArr.getJSONObject(j);
+                JSONObject props = compJson.getJSONObject("props");
+                if (!Check.isNull(props)) {
+                    landpagePackage.setAppId(props.getLong("appId"));
+                }
+            }
+        }
+        return landpagePackage;
+    }
+
+    @Override
+    public Result<Object> getRelatedAccounts(Long siteId) {
+        List<JSONObject> list = landpagePackageMapper.getRelatedAccounts(siteId);
+        return Result.ok(new PageInfo<JSONObject>(list));
+    }
+
+    @Override
+    public Result<Object> getRelatedGroups(Long siteId, Long accountId) {
+        List<JSONObject> list = landpagePackageMapper.getRelatedGroups(siteId,accountId);
+        return Result.ok(new PageInfo<JSONObject>(list));
+    }
+
+    @Override
+    public void createLandPageAndUnit(Long siteId, Long creativeId, Long unitId, Long accountId) {
+        try {
+            JSONObject entity = landpagePackageRelMapper.queryByUnitId(siteId, unitId, accountId);
+            if (Check.isNull(entity)) {
+                KuaishouLandpagePackageRel rel = new KuaishouLandpagePackageRel();
+                rel.setUnitId(unitId);
+                rel.setAccountId(accountId);
+                rel.setSiteId(siteId);
+                JSONArray creativeArr = new JSONArray();
+                creativeArr.add(creativeId);
+                rel.setCreativeArr(JSONObject.toJSONString(creativeArr));
+                landpagePackageRelService.save(rel);
+            } else {
+                //不为空,落地页已经绑定过广告组,判断是否是新的创意
+                JSONArray creative_arr = entity.getJSONArray("creative_arr");
+                if (!creative_arr.contains(creativeId)) {
+                    //不包含创意,则添加并更新进数据表中
+                    KuaishouLandpagePackageRel rel = new KuaishouLandpagePackageRel();
+                    creative_arr.add(creativeId);
+                    rel.setCreativeArr(JSONObject.toJSONString(creative_arr));
+                    rel.setId(entity.getLong("id"));
+                    landpagePackageRelMapper.updateById(rel);
+                }
+            }
+        } catch (Exception e) {
+            log.error("绑定落地页与广告组异常", e);
+        }
+    }
+}