Bläddra i källkod

批量逻辑调整

yumeng 5 år sedan
förälder
incheckning
1729b442a8

+ 0 - 61
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouAppListJob.java

@@ -1,61 +0,0 @@
-package org.jeecg.modules.ctop.job;
-
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
-import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import lombok.extern.slf4j.Slf4j;
-import org.quartz.Job;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * 获取广告计划分时报表
- */
-@Slf4j
-public class KuaishouAppListJob implements Job {
-    @Autowired
-    private IKuaishouInterfaceService kuaishouInterfaceService;
-
-    @Autowired
-    private ICtopOauthTokenService oauthTokenService;
-
-
-    static ExecutorService executorService = Executors.newFixedThreadPool(2);
-
-    @Override
-    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
-
-        Thread thread = new Thread() {
-            @Override
-            public void run() {
-                List<CtopOauthToken> tokens = oauthTokenService.selectKuaiShouToken();
-                for (CtopOauthToken token : tokens) {
-                    if (Check.isNull(token)) {
-                        continue;
-                    }
-                    executorService.submit(new Runnable() {
-                        @Override
-                        public void run() {
-                            try {
-                                kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
-                            } catch (Exception e) {
-                                e.printStackTrace();
-                            }
-                        }
-                    });
-                }
-
-            }
-
-        };
-        thread.start();
-
-
-    }
-}

+ 24 - 16
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -78,6 +78,8 @@ public class BatchController {
     private IKuaiShouImageGetService imageGetService;
     @Autowired
     private IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaishouPopulationService populationService;
 
 
     /**
@@ -97,6 +99,8 @@ public class BatchController {
             }
             SpendVo spendVo = new SpendVo();
             JSONObject fundJson = iKuaishouInterfaceService.fundGet(oauthToken);
+
+
             if (!Check.isNull(fundJson)) {
                 spendVo.setBalance(fundJson.getBigDecimal("balance")); // 余额
             }
@@ -108,6 +112,15 @@ public class BatchController {
             result.setSuccess(true);
             result.setResult(spendVo);
 
+            Thread thread = new Thread() {
+                @Override
+                public void run() {
+                    iKuaishouInterfaceService.getAppList(oauthToken.getAccountId(), oauthToken.getAccessToken());
+                    iKuaishouInterfaceService.getPopulationList(accountId, oauthToken.getAccessToken());
+                }
+            };
+            thread.start();
+
         } catch (Exception e) {
             e.printStackTrace();
             result.setSuccess(false);
@@ -437,26 +450,21 @@ public class BatchController {
 
 
     /**
-     * 获取人群包接口
+     * 获取人群包
      *
      * @param accountId
-     * @returnBatch
+     * @return
      */
     @GetMapping(value = "/getPopulationList")
-    public Result<JSONArray> getAppList(Long accountId) {
-        Result<JSONArray> result = new Result<>();
-        try {
-            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
-            if (Check.isNull(oauthToken)) {
-                throw new Exception("未获取到账户信息");
-            }
-            JSONArray jsonArray = iKuaishouInterfaceService.getPopulationList(accountId, oauthToken.getAccessToken());
-            result.setSuccess(true);
-            result.setResult(jsonArray);
-        } catch (Exception e) {
-            e.printStackTrace();
-            result.setSuccess(false);
-        }
+    public Result<List<KuaishouPopulation>> queryPageList(Long accountId) {
+        Result<List<KuaishouPopulation>> result = new Result();
+        QueryWrapper<KuaishouPopulation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
+        queryWrapper.eq("status", 4);
+        queryWrapper.orderByDesc("put_time");
+        List<KuaishouPopulation> list = populationService.list(queryWrapper);
+        result.setSuccess(true);
+        result.setResult(list);
         return result;
     }
 

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

@@ -0,0 +1,248 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
+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.aspect.annotation.AutoLog;
+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-05-06
+ */
+@Slf4j
+@Api(tags = "人群包列表")
+@RestController
+@RequestMapping("/abc/kuaishouPopulation")
+public class KuaishouPopulationController {
+    @Autowired
+    private IKuaishouPopulationService kuaishouPopulationService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param kuaishouPopulation
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "人群包列表-分页列表查询")
+    @ApiOperation(value = "人群包列表-分页列表查询", notes = "人群包列表-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<KuaishouPopulation>> queryPageList(KuaishouPopulation kuaishouPopulation,
+                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                           HttpServletRequest req) {
+        Result<IPage<KuaishouPopulation>> result = new Result<IPage<KuaishouPopulation>>();
+        QueryWrapper<KuaishouPopulation> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouPopulation, req.getParameterMap());
+        Page<KuaishouPopulation> page = new Page<KuaishouPopulation>(pageNo, pageSize);
+        IPage<KuaishouPopulation> pageList = kuaishouPopulationService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param kuaishouPopulation
+     * @return
+     */
+    @AutoLog(value = "人群包列表-添加")
+    @ApiOperation(value = "人群包列表-添加", notes = "人群包列表-添加")
+    @PostMapping(value = "/add")
+    public Result<KuaishouPopulation> add(@RequestBody KuaishouPopulation kuaishouPopulation) {
+        Result<KuaishouPopulation> result = new Result<KuaishouPopulation>();
+        try {
+            kuaishouPopulationService.save(kuaishouPopulation);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param kuaishouPopulation
+     * @return
+     */
+    @AutoLog(value = "人群包列表-编辑")
+    @ApiOperation(value = "人群包列表-编辑", notes = "人群包列表-编辑")
+    @PutMapping(value = "/edit")
+    public Result<KuaishouPopulation> edit(@RequestBody KuaishouPopulation kuaishouPopulation) {
+        Result<KuaishouPopulation> result = new Result<KuaishouPopulation>();
+        KuaishouPopulation kuaishouPopulationEntity = kuaishouPopulationService.getById(kuaishouPopulation.getId());
+        if (kuaishouPopulationEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = kuaishouPopulationService.updateById(kuaishouPopulation);
+            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 {
+            kuaishouPopulationService.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<KuaishouPopulation> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<KuaishouPopulation> result = new Result<KuaishouPopulation>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.kuaishouPopulationService.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<KuaishouPopulation> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<KuaishouPopulation> result = new Result<KuaishouPopulation>();
+        KuaishouPopulation kuaishouPopulation = kuaishouPopulationService.getById(id);
+        if (kuaishouPopulation == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(kuaishouPopulation);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<KuaishouPopulation> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                KuaishouPopulation kuaishouPopulation = JSON.parseObject(deString, KuaishouPopulation.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(kuaishouPopulation, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<KuaishouPopulation> pageList = kuaishouPopulationService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "人群包列表列表");
+        mv.addObject(NormalExcelConstants.CLASS, KuaishouPopulation.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<KuaishouPopulation> listKuaishouPopulations = ExcelImportUtil.importExcel(file.getInputStream(), KuaishouPopulation.class, params);
+                kuaishouPopulationService.saveBatch(listKuaishouPopulations);
+                return Result.ok("文件导入成功!数据行数:" + listKuaishouPopulations.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("文件导入失败!");
+    }
+
+}

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

@@ -0,0 +1,113 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+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 org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * 人群包列表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-05-06
+ */
+@Data
+@TableName("ctop_kuaishou_population")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_population对象", description = "人群包列表")
+public class KuaishouPopulation {
+
+    /**
+     * 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 orientationId;
+    /**
+     * 人群包名称
+     */
+    @Excel(name = "人群包名称", width = 15)
+    @ApiModelProperty(value = "人群包名称")
+    private String orientationName;
+    /**
+     * 人群数据类型0:非上传人群包1:IMEI2:IDFA3:IMEI_MD54:IDFA_MD55:手机号-MD5
+     */
+    @Excel(name = "人群数据类型0:非上传人群包1:IMEI2:IDFA3:IMEI_MD54:IDFA_MD55:手机号-MD5", width = 15)
+    @ApiModelProperty(value = "人群数据类型0:非上传人群包1:IMEI2:IDFA3:IMEI_MD54:IDFA_MD55:手机号-MD5")
+
+    private Integer populationType;
+    /**
+     * 上传数量
+     */
+    @Excel(name = "上传数量", width = 15)
+    @ApiModelProperty(value = "上传数量")
+    private Long recordSize;
+    /**
+     * 匹配数量
+     */
+    @Excel(name = "匹配数量", width = 15)
+    @ApiModelProperty(value = "匹配数量")
+    private Long matchSize;
+    /**
+     * 覆盖人群
+     */
+    @Excel(name = "覆盖人群", width = 15)
+    @ApiModelProperty(value = "覆盖人群")
+    private Long coverNum;
+
+    private java.lang.Integer status;
+    private java.lang.Integer type;
+    /**
+     * 推送时间
+     */
+    @Excel(name = "推送时间", width = 15, format = "yyyy-MM-dd")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @ApiModelProperty(value = "推送时间")
+    private Date putTime;
+
+
+    private Long thirdPlatformCode;
+    /**
+     * 付费人群包-第3方平台code
+     * <p>
+     * private java.lang.Integer thirdPlatformCode;
+     * /**创建时间
+     */
+    @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 java.util.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;
+}

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

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.batch.mapper;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 人群包列表
+ *
+ * @author: jeecg-boot
+ * @date: 2020-05-06
+ * @cersion: V1.0
+ */
+public interface KuaishouPopulationMapper extends BaseMapper<KuaishouPopulation> {
+
+}

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouPopulationMapper.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.KuaishouPopulationMapper">
+
+</mapper>

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

@@ -439,7 +439,7 @@ public interface IKuaishouInterfaceService {
      * @param accessToken
      * @return
      */
-    JSONArray getPopulationList(Long accountId, String accessToken);
+    void getPopulationList(Long accountId, String accessToken);
 
 
     /**

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

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 人群包列表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-05-06
+ */
+public interface IKuaishouPopulationService extends IService<KuaishouPopulation> {
+
+}

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

@@ -470,7 +470,6 @@ public class BatchServiceImpl implements IBatchService {
             }
 
             JSONObject unitJson = new JSONObject();
-
             unitJson.put("campaign_id", copyToCampaignId);
 
             // 资源位置
@@ -478,7 +477,6 @@ public class BatchServiceImpl implements IBatchService {
             if (!Check.isNull(scene_id)) {
                 unitJson.put("scene_id", scene_id);
             }
-
             // 资源创作方式
             if (!Check.isNull(group.getUnitType())) {
                 if (!Check.isNull(group.getUnitType())) {
@@ -826,7 +824,6 @@ public class BatchServiceImpl implements IBatchService {
             throw new Exception("入参为空");
         }
 
-
         Long accountId = requestJson.getLong("accountId");
         if (Check.isNull(accountId)) {
             throw new Exception("请输入需创建账号");
@@ -842,7 +839,6 @@ public class BatchServiceImpl implements IBatchService {
             throw new Exception("请选择广告组");
         }
 
-
         JSONObject creativeJson = new JSONObject();
         creativeJson.put("advertiser_id", accountId);
         creativeJson.put("unit_id", unitId);
@@ -851,10 +847,7 @@ public class BatchServiceImpl implements IBatchService {
         if (!Check.isNull(requestJson.get("creativeMaterialType"))) {
             creativeJson.put("creative_material_type", requestJson.get("creativeMaterialType"));
         }
-
         String action_bar_text = requestJson.getString("actionBarText");
-        // 视频id
-
         String click_track_url = requestJson.getString("clickTrackUrl");
         JSONObject returnJson = new JSONObject();
         JSONArray successArr = new JSONArray();
@@ -871,34 +864,34 @@ public class BatchServiceImpl implements IBatchService {
                         for (int j = 0; j < imageArr.size(); j++) {
                             JSONObject imageJson = imageArr.getJSONObject(j);
                             if (!Check.isNull(imageJson)) {
-
                                 String name = imageJson.getString("name");
                                 creativeJson.put("action_bar_text", action_bar_text);
                                 creativeJson.put("description", description);
-
                                 creativeJson.put("creative_name", name);
                                 creativeJson.put("photo_id", photo_id);
                                 creativeJson.put("click_track_url", click_track_url);
 
                                 String imageToken = null;
                                 String signature = imageJson.getString("signature");
-                                QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
-                                queryWrapper.eq("account_id", accountId);
-                                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 = this.kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
-                                }
-                                if (Check.isNull(imageToken)) {
-                                    JSONObject failJson = new JSONObject();
-                                    failJson.put("creativeName", name);
-                                    failJson.put("failMessage", "获取图片文件失败");
-                                    failArr.add(failJson);
-                                    continue;
+                                if (!Check.isNull(signature)) {
+                                    QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
+                                    queryWrapper.eq("account_id", accountId);
+                                    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 = this.kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
+                                    }
+                                    if (Check.isNull(imageToken)) {
+                                        JSONObject failJson = new JSONObject();
+                                        failJson.put("creativeName", name);
+                                        failJson.put("failMessage", "获取图片文件失败");
+                                        failArr.add(failJson);
+                                        continue;
+                                    }
                                 }
                                 creativeJson.put("image_token", imageToken);
                                 Map<String, Object> returnUnitMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson);

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

@@ -132,6 +132,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     IKuaiShouImageGetService kuaiShouImageGetService;
     @Autowired
     private IKuaiShouDailyFlowsService kuaiShouDailyFlowsService;
+    @Autowired
+    private IKuaishouPopulationService populationService;
 
 
     @Override
@@ -1872,7 +1874,13 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         Thread thread = new Thread() {
                             @Override
                             public void run() {
-                                getCreativeByCreativeId(accessToken, advertiserId, creativeId);
+                                try {
+                                    Thread.sleep(100);
+                                    getCreativeByCreativeId(accessToken, advertiserId, creativeId);
+                                } catch (InterruptedException e) {
+                                    e.printStackTrace();
+                                }
+
                             }
 
                         };
@@ -2820,8 +2828,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * @param accessToken
      * @return
      */
+
+
     @Override
-    public JSONArray getPopulationList(Long accountId, String accessToken) {
+    public void getPopulationList(Long accountId, String accessToken) {
         try {
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.POPULATION_LIST;
             Map<String, String> headers = new HashMap<>();
@@ -2837,36 +2847,41 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 if (code == 0) {
                     JSONArray dataArr = resultJson.getJSONArray("data");
                     if (!Check.isNull(dataArr)) {
-                        JSONArray returnArr = new JSONArray();
+                        Map<String, Object> deleteMap = new HashMap<>();
+                        deleteMap.put("account_id", accountId);
+                        populationService.removeByMap(deleteMap);
                         for (int i = 0; i < dataArr.size(); i++) {
                             JSONObject dataJson = dataArr.getJSONObject(i);
                             if (!Check.isNull(dataJson)) {
-                                JSONObject returnJson = new JSONObject();
-                                returnJson.put("orientationId", dataJson.getLong("orientation_id"));
-                                returnJson.put("orientationName", dataJson.getString("orientation_name"));
-                                returnJson.put("type", dataJson.getInteger("type"));
-                                returnJson.put("populationType", dataJson.getLong("population_type"));
-                                returnJson.put("recordSize", dataJson.getLong("record_size"));
-                                returnJson.put("matchSize", dataJson.getLong("match_size"));
-                                returnJson.put("coverNum", dataJson.getLong("cover_num"));
-                                returnJson.put("status", dataJson.getInteger("status"));
-                                returnJson.put("createTime", dataJson.getInteger("create_time"));
-                                returnArr.add(returnJson);
+                                KuaishouPopulation population = new KuaishouPopulation();
+                                population.setOrientationId(dataJson.getLong("orientation_id"));
+                                population.setOrientationName(dataJson.getString("orientation_name"));
+                                population.setType(dataJson.getInteger("type"));
+                                population.setPopulationType(dataJson.getInteger("population_type"));
+                                population.setRecordSize(dataJson.getLong("record_size"));
+                                population.setMatchSize(dataJson.getLong("match_size"));
+                                population.setCoverNum(dataJson.getLong("cover_num"));
+                                population.setStatus(dataJson.getInteger("status"));
+                                population.setPutTime(dataJson.getDate("create_time"));
+                                population.setThirdPlatformCode(dataJson.getLong("third_platform_code"));
+                                population.setAccountId(accountId);
+                                populationService.save(population);
+
                             }
                         }
-                        return returnArr;
+
                     }
 
                 } else {
                     log.error("获取人群包管理返回数据为空,accountId:{}", accountId);
-                    return null;
+
                 }
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
 
-        return null;
+
     }
 
 

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

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouPopulationMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 人群包列表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-05-06
+ */
+@Service
+public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulationMapper, KuaishouPopulation> implements IKuaishouPopulationService {
+
+}