Ver Fonte

修改代码逻辑

syh há 5 anos atrás
pai
commit
814aab95a3
21 ficheiros alterados com 707 adições e 197 exclusões
  1. 1 1
      .gitignore
  2. 16 0
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/ResultMapUtils.java
  3. 85 0
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/StatusCode.java
  4. 9 23
      jeecg-boot-module-system/src/main/java/org/jeecg/JeecgOneToMainUtil.java
  5. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java
  6. 4 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ByteDanceAdvertiserPostController.java
  7. 30 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ByteDanceTemplateController.java
  8. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/ByteDanceCampaign.java
  9. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/ByteDanceCampaignTemplate.java
  10. 0 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IByteDanceAdvertiserDataService.java
  11. 7 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IByteDanceCampaignTemplateService.java
  12. 3 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IByteDanceCreativeService.java
  13. 2 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IBytedanceAdvertisePlanTemplateService.java
  14. 10 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IFileInfoService.java
  15. 2 114
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceAdvertiserDataServiceImpl.java
  16. 184 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceCampaignTemplateServiceImpl.java
  17. 189 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceCreativeServiceImpl.java
  18. 29 17
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/BytedanceAdvertisePlanTemplateServiceImpl.java
  19. 118 21
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/FileInfoServiceImpl.java
  20. 2 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysCategoryService.java
  21. 13 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysCategoryServiceImpl.java

+ 1 - 1
.gitignore

@@ -32,4 +32,4 @@ gen
 # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
 hs_err_pid*
 **/target/
-application-dev.yml
+#application-dev.yml

+ 16 - 0
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/ResultMapUtils.java

@@ -0,0 +1,16 @@
+package org.jeecg.common.util;
+
+import java.util.Map;
+
+public class ResultMapUtils {
+    private static final String MAP_CODE = "code";
+    private static final String MAP_MESSAGE = "message";
+    private static final String MAP_SUCCESS = "success";
+
+    public static void setResultMap(Map<String, Object> map, Integer statusCode) {
+        map.put(MAP_CODE, statusCode);
+        map.put(MAP_MESSAGE, StatusCode.getDesc(statusCode));
+        map.put(MAP_SUCCESS, StatusCode.getFlag(statusCode));
+    }
+
+}

+ 85 - 0
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/StatusCode.java

@@ -0,0 +1,85 @@
+package org.jeecg.common.util;
+
+public enum StatusCode {
+    /**
+     * 0   请求成功
+     * -101 参数异常
+     * -102 服务器异常
+     * -103 数据不存在
+     * -104 渠道不存在
+     * -105 规则尚未配置
+     * -106 规则为空
+     * -107 同盾数据为空
+     * -108 模型服务异常
+     * -109 深度搜索服务异常
+     * -201 探针数据为空
+     */
+    COMMON_SUCCESS("success", 0, true),
+    COMMON_PARAM_ERROR("参数异常", -1, false),
+    BYTEDANCE_VIDEO_UPLOAD_FAIL("今日头条视频文件上传失败", -201, false),
+    IMAGE_NUMBER_SHORTAGE("今日头条图片文件上传失败", -202, false),
+    BYTEDANCE_IMAGE_UPLOAD_FAIL("今日头条图片文件上传失败", -203, false),
+    COMMON_SERVER_ERROR("server error", -102, false),
+    COMMON_DATA_HAS_EXIST_ERROR("data has exist", -103, false),
+    COMMON_CHANNEL_NOT_EXIST_ERROR("channel not exist", -104, false),
+    COMMON_RULEENGINE_HAS_NOT_CONFIGURED_ERROR("ruleEngine has not configured", -105, false),
+    COMMON_RULE_PACKAGE_IS_NULL_ERROR("rulepackage is null", -106, false),
+    COMMON_TONGDUN_DATA_IS_NULL_ERROR("tongdun data is null", -107, false),
+    COMMON_MODEL_SERVICE_ERROR("model service error", -108, false),
+    COMMON_DEEPSEARCH_ERROR("deep search error", -109, false),
+    COMMON_APPLICATION_MOBILE_IS_NULL_ERROR("application mobile is null", -110, false),
+    COMMON_TANZHEN_DATA_IS_NULL_ERROR("tanzhen data is null", -201, false),
+    COMMON_RULE_ERROR_APPLICATION_IS_NULL("there is no error application", -202, false);
+    private String desc;
+    private int code;
+    private boolean flag;
+
+    StatusCode(String desc, int code, boolean flag) {
+        this.desc = desc;
+        this.code = code;
+        this.flag = flag;
+    }
+
+    public static String getDesc(int code) {
+        for (StatusCode error : StatusCode.values()) {
+            if (error.getCode() == code) {
+                return error.getDesc();
+            }
+        }
+        return null;
+    }
+
+    public static Boolean getFlag(int code) {
+        for (StatusCode error : StatusCode.values()) {
+            if (error.getCode() == code) {
+                return error.getFlag();
+            }
+        }
+        return null;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public boolean getFlag() {
+        return flag;
+    }
+
+    public void setFlag(boolean flag) {
+        this.flag = flag;
+    }
+
+}

+ 9 - 23
jeecg-boot-module-system/src/main/java/org/jeecg/JeecgOneToMainUtil.java

@@ -22,41 +22,27 @@ public class JeecgOneToMainUtil {
 	public static void main(String[] args) {
 		//第一步:设置主表配置
 		MainTableVo mainTable = new MainTableVo();
-		mainTable.setTableName("jeecg_order_main");//表名
-		mainTable.setEntityName("TestOrderMain");	 //实体名
-		mainTable.setEntityPackage("test2");	 //包名
-		mainTable.setFtlDescription("订单");	 //描述
+        mainTable.setTableName("sys_category");//表名
+        mainTable.setEntityName("Category");     //实体名
+        mainTable.setEntityPackage("ctop");     //包名
+        mainTable.setFtlDescription("主分类信息");     //描述
 		
 		//第二步:设置子表集合配置
 		List<SubTableVo> subTables = new ArrayList<SubTableVo>();
 		//[1].子表一
 		SubTableVo po = new SubTableVo();
-		po.setTableName("jeecg_order_customer");//表名
-		po.setEntityName("TestOrderCustom");	    //实体名
-		po.setEntityPackage("test2");	        //包名
-		po.setFtlDescription("客户明细");       //描述
+        po.setTableName("sys_category");//表名
+        po.setEntityName("ChildCategory");        //实体名
+        po.setEntityPackage("ctop");            //包名
+        po.setFtlDescription("子分类信息");       //描述
 		//子表外键参数配置
 		/*说明: 
 		 * a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
 		 * b) 主表和子表的外键字段名字,必须相同(除主键ID外);
 		 * c) 多个外键字段,采用逗号分隔;
 		*/
-		po.setForeignKeys(new String[]{"order_id"});
+        po.setForeignKeys(new String[]{"pid"});
 		subTables.add(po);
-		//[2].子表二
-		SubTableVo po2 = new SubTableVo();
-		po2.setTableName("jeecg_order_ticket");		//表名
-		po2.setEntityName("TestOrderTicket");			//实体名
-		po2.setEntityPackage("test2"); 				//包名
-		po2.setFtlDescription("产品明细");			//描述
-		//子表外键参数配置
-		/*说明: 
-		 * a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
-		 * b) 主表和子表的外键字段名字,必须相同(除主键ID外);
-		 * c) 多个外键字段,采用逗号分隔;
-		*/
-		po2.setForeignKeys(new String[]{"order_id"});
-		subTables.add(po2);
 		mainTable.setSubTables(subTables);
 		
 		//第三步:一对多(父子表)数据模型,代码生成

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -92,6 +92,7 @@ public class ShiroConfig {
 		filterChainDefinitionMap.put("/toutiao/dictitem/list", "anon");
 		filterChainDefinitionMap.put("/toutiao/advertiser/**", "anon");
         filterChainDefinitionMap.put("/toutiao/industry/list", "anon");
+        filterChainDefinitionMap.put("/template/bytedance/industry/list", "anon");
 		//文件上传接口
 		filterChainDefinitionMap.put("/upload/**", "anon");
 

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

@@ -255,7 +255,7 @@ public class ByteDanceAdvertiserPostController {
      */
     @RequestMapping("/advertiser/video/add")
     public Map<String, Object> advertiserVideoAdd(String accountId, String videoUrl) {
-        return fileInfoService.uploadVideoToTemplate(accountId, videoUrl, "bytedance");
+        return fileInfoService.uploadVideoToBytedance(accountId, videoUrl);
     }
 
     /**
@@ -266,12 +266,12 @@ public class ByteDanceAdvertiserPostController {
      */
     @RequestMapping("/advertiser/image/add")
     public Map<String, Object> advertiserImageAdd(String accountId, String imageUrl) {
-        return fileInfoService.uploadImageToTemplate(accountId, imageUrl, "bytedance");
+        return fileInfoService.uploadImageToBytedance(accountId, imageUrl);
     }
 
     @RequestMapping("/industry/list")
-    public Map<String, Object> industryList(String accountId) {
-        return fileInfoService.getIndustryList(accountId);
+    public Map<String, Object> industryList(String accountId, Integer level) {
+        return fileInfoService.getIndustryList(accountId, level);
     }
 
     @Autowired

+ 30 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ByteDanceTemplateController.java

@@ -1,13 +1,12 @@
 package org.jeecg.modules.ctop.controller;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.subject.Subject;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.ctop.entity.*;
 import org.jeecg.modules.ctop.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +45,21 @@ public class ByteDanceTemplateController {
     }
 
     /**
+     * 广告组模板
+     * 完成
+     *
+     * @param template
+     * @return
+     */
+    @PostMapping("creative/insert")
+    public Map<String, Object> creativeInsert(@RequestBody JSONObject template) {
+        return creativeService.insertBatch(template);
+    }
+
+    @Autowired
+    private IByteDanceCreativeService creativeService;
+
+    /**
      * 投放目标
      *
      * @param template
@@ -153,6 +167,19 @@ public class ByteDanceTemplateController {
     }
 
     /**
+     * @param req
+     * @return
+     * @功能:获取头条行业信息列表
+     */
+    @GetMapping(value = "/bytedance/industry/list")
+    public JSONArray campaignPageList(HttpServletRequest req) {
+        return fileInfoService.getByteDanceIndustryList(req);
+    }
+
+    @Autowired
+    private IFileInfoService fileInfoService;
+
+    /**
      * @param pageNo
      * @param pageSize
      * @param req

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/ByteDanceCampaign.java

@@ -175,7 +175,7 @@ public class ByteDanceCampaign {
 		this.name = template.getCampaignName();
 		this.budgetMode = template.getCampaignBudget();
 		this.budget = new BigDecimal(template.getBudgetDaily());
-		this.landingType = template.getPromotionPurpuse();
+        this.landingType = template.getPromotionPurpose();
 		this.toutiaoId = token.getAccountId();
 		this.templateId = template.getId();
 	}

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/ByteDanceCampaignTemplate.java

@@ -42,7 +42,7 @@ public class ByteDanceCampaignTemplate {
     @Excel(name = "投放目标", width = 15)
     @ApiModelProperty(value = "投放目标")
     @Dict(dicCode = "toutiao_promotion_purpose_type")
-    private String promotionPurpuse;
+    private String promotionPurpose;
     /**
      * 投放方式
      */

+ 0 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IByteDanceAdvertiserDataService.java

@@ -18,8 +18,6 @@ public interface IByteDanceAdvertiserDataService {
 
     Map<String, Object> getAdvertiserCreativeMaterial(String accountId, String creativeIds);
 
-    Map<String, Object> advertiserCampaignCreate(String accountId, String campaignName, String budgetMode, Integer budget, String landingType);
-
     Map<String, Object> advertiserCampaignUpdateStatus(String accountId, String campaignIds, String optStatus);
 
     Map<String, Object> advertiserCampaignUpdate(String accountId, Long campaignId, String budgetMode, Integer budget,String campaignName);
@@ -33,6 +31,4 @@ public interface IByteDanceAdvertiserDataService {
     Map<String, Object> advertiserCreativeUpdateStatus(String accountId, String ids, String optStatus);
 
     Map<String, Object> advertiserCustomAudienceSelect(String accountId);
-
-    Map<String, Object> campaignCreate(CTopOauthToken token, ByteDanceCampaignTemplate template);
 }

+ 7 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IByteDanceCampaignTemplateService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.ctop.entity.ByteDanceCampaignTemplate;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.ctop.entity.CTopOauthToken;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
@@ -19,4 +20,10 @@ public interface IByteDanceCampaignTemplateService extends IService<ByteDanceCam
     Map<String, Object> insertTemplate(ByteDanceCampaignTemplate template);
 
     Result<IPage<ByteDanceCampaignTemplate>> getList(ByteDanceCampaignTemplate template, Integer pageNo, Integer pageSize, HttpServletRequest req);
+
+    Map<String, Object> campaignCreate(CTopOauthToken token, ByteDanceCampaignTemplate template);
+
+    Map<String, Object> campaignCreate(String getAccountId, Long campaignId, String getName);
+
+    Map<String, Object> campaignCreate(String accountId, String campaignName, String budgetMode, Integer budget, String landingType);
 }

+ 3 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IByteDanceCreativeService.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.ctop.service;
 
+import com.alibaba.fastjson.JSONObject;
 import org.jeecg.modules.ctop.entity.ByteDanceCreative;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -14,4 +15,6 @@ import java.util.Map;
 public interface IByteDanceCreativeService extends IService<ByteDanceCreative> {
 
     Map<String, Object> creativeCreate(String accountId, Long campaignId, String dataString);
+
+    Map<String, Object> insertBatch(JSONObject template);
 }

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IBytedanceAdvertisePlanTemplateService.java

@@ -14,4 +14,6 @@ import java.util.Map;
 public interface IBytedanceAdvertisePlanTemplateService extends IService<BytedanceAdvertisePlanTemplate> {
 
     Map<String, Object> insertTemplate(BytedanceAdvertisePlanTemplate template, String accountId);
+
+    Map<String, Object> planCreate(Long campaignId, String getAccountId, String deliveryRange, Long userorentationId, Long budgetId, Long deliverytargetId, String getName);
 }

+ 10 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IFileInfoService.java

@@ -1,8 +1,11 @@
 package org.jeecg.modules.ctop.service;
 
+import com.alibaba.fastjson.JSONArray;
+import io.swagger.models.auth.In;
 import org.jeecg.modules.ctop.entity.FileInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 /**
@@ -13,9 +16,13 @@ import java.util.Map;
  */
 public interface IFileInfoService extends IService<FileInfo> {
 
-    Map<String, Object> uploadVideoToTemplate(String accountId, String videoUrl, String templatename);
+    Map<String, Object> uploadVideoToBytedance(String accountId, String videoUrl);
 
-    Map<String, Object> uploadImageToTemplate(String accountId, String imageFileId, String templatename);
+    Map<String, Object> upload3ImagesToBytedance(String accountId, String imageFileUrls);
 
-    Map<String, Object> getIndustryList(String accountId);
+    Map<String, Object> uploadImageToBytedance(String accountId, String imageFileId);
+
+    Map<String, Object> getIndustryList(String accountId, Integer level);
+
+    JSONArray getByteDanceIndustryList(HttpServletRequest req);
 }

+ 2 - 114
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -244,87 +244,6 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
     }
 
     @Override
-    public Map<String, Object> advertiserCampaignCreate(String accountId, String campaignName, String budgetMode, Integer budget, String landingType) {
-        Map<String, Object> resultMap = new HashMap<>();
-        CTopOauthToken token = getOAuthTokenByAccountId(accountId);
-        //2: 根据token以及用户id获取用户信息数据
-        JSONObject params = new JSONObject();
-        params.put("advertiser_id", token.getAccountId());
-        params.put("campaign_name", campaignName);
-        params.put("budget_mode", budgetMode);
-        params.put("budget", budget);
-        params.put("landing_type", landingType);
-        JSONObject result = createCampaign(params, token.getAccessToken());
-        Integer code = result.getInteger("code");
-
-        if (null == code || !code.equals(0)) {
-            logger.info("创建广告组接口异常==》accountId:{},message:{}", accountId, result.getString("message"));
-            resultMap.put("code", -1);
-            resultMap.put("message", "创建广告组接口异常");
-            return resultMap;
-        }
-        JSONObject data = result.getJSONObject("data");
-        if (null == data) {
-            logger.info("广告组创建异常==》accountId:{},message:{}", accountId, result.getString("message"));
-            resultMap.put("code", -1);
-            resultMap.put("message", "广告组创建异常");
-            return resultMap;
-        }
-        Long id = data.getLong("campaign_id");
-        ByteDanceCampaign campaign = new ByteDanceCampaign(id, token, campaignName, budgetMode, budget, landingType);
-        //清除清数据,插入新数据
-        campaignMapper.insert(campaign);
-        resultMap.put("code", 0);
-        resultMap.put("message", "广告组创建成功");
-        return resultMap;
-    }
-
-    public JSONObject createCampaign(JSONObject data, String token) {
-        // 请求地址
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_create");
-
-        // 构造请求
-        HttpPost httpEntity = new HttpPost(url);
-
-        httpEntity.setHeader("Access-Token", token);
-
-        CloseableHttpResponse response = null;
-        CloseableHttpClient client = null;
-
-        try {
-            client = HttpClientBuilder.create().build();
-            httpEntity.setEntity(new StringEntity(data.toJSONString(), ContentType.APPLICATION_JSON));
-
-            response = client.execute(httpEntity);
-            if (response != null && response.getStatusLine().getStatusCode() == 200) {
-                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-                StringBuffer result = new StringBuffer();
-                String line = "";
-                while ((line = bufferedReader.readLine()) != null) {
-                    result.append(line);
-                }
-                bufferedReader.close();
-                return JSONObject.parseObject(result.toString());
-            }
-
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                if (response != null) {
-                    response.close();
-                }
-                client.close();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-        return null;
-    }
-
-    @Override
     public Map<String, Object> advertiserCampaignUpdateStatus(String accountId, String campaignIds, String optStatus) {
         Map<String, Object> resultMap = new HashMap<>();
         JSONArray ids = new JSONArray();
@@ -692,40 +611,9 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         return resultMap;
     }
 
-    @Override
-    public Map<String, Object> campaignCreate(CTopOauthToken token, ByteDanceCampaignTemplate template) {
-        Map<String, Object> resultMap = new HashMap<>();
-        //2: 根据token以及用户id获取用户信息数据
-        JSONObject params = new JSONObject();
-        params.put("advertiser_id", token.getAccountId());
-        params.put("campaign_name", template.getCampaignName());
-        params.put("budget_mode", template.getCampaignBudget());
-        params.put("budget", template.getBudgetDaily());
-        params.put("landing_type", template.getPromotionPurpuse());
-        JSONObject result = createCampaign(params, token.getAccessToken());
-        Integer code = result.getInteger("code");
+    @Autowired
+    private ByteDanceCampaignTemplateMapper campaignTemplateMapper;
 
-        if (null == code || !code.equals(0)) {
-            logger.info("创建广告组接口异常==》accountId:{},message:{}", token.getAccountId(), result.getString("message"));
-            resultMap.put("code", -1);
-            resultMap.put("message", result.getString("message"));
-            return resultMap;
-        }
-        JSONObject data = result.getJSONObject("data");
-        if (null == data) {
-            logger.info("广告组创建异常==》accountId:{},message:{}", token.getAccountId(), result.getString("message"));
-            resultMap.put("code", -1);
-            resultMap.put("message", "广告组创建异常");
-            return resultMap;
-        }
-        Long id = data.getLong("campaign_id");
-        ByteDanceCampaign campaign = new ByteDanceCampaign(id, token, template);
-        //清除清数据,插入新数据
-        campaignMapper.insert(campaign);
-        resultMap.put("code", 0);
-        resultMap.put("message", "广告组创建成功");
-        return resultMap;
-    }
 
     @Autowired
     private ByteDanceCustomAudienceMapper audienceMapper;

+ 184 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceCampaignTemplateServiceImpl.java

@@ -1,8 +1,17 @@
 package org.jeecg.modules.ctop.service.impl;
 
+import cn.com.ctop.common.utils.PropertiesUtils;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
@@ -10,18 +19,27 @@ import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.ctop.entity.ByteDanceCampaign;
 import org.jeecg.modules.ctop.entity.ByteDanceCampaignTemplate;
 import org.jeecg.modules.ctop.entity.CTopOauthToken;
+import org.jeecg.modules.ctop.mapper.ByteDanceCampaignMapper;
 import org.jeecg.modules.ctop.mapper.ByteDanceCampaignTemplateMapper;
 import org.jeecg.modules.ctop.service.IByteDanceAdvertiserDataService;
 import org.jeecg.modules.ctop.service.IByteDanceCampaignTemplateService;
 import org.jeecg.modules.ctop.service.ICTopOauthTokenService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.logging.SimpleFormatter;
 
 /**
  * @Description: 今日头条广告组模板信息
@@ -31,14 +49,19 @@ import java.util.Map;
  */
 @Service
 public class ByteDanceCampaignTemplateServiceImpl extends ServiceImpl<ByteDanceCampaignTemplateMapper, ByteDanceCampaignTemplate> implements IByteDanceCampaignTemplateService {
-
+    private static final Logger logger = LoggerFactory.getLogger(ByteDanceCampaignTemplateServiceImpl.class);
     @Override
     public Map<String, Object> insertTemplate(ByteDanceCampaignTemplate template) {
         Map<String, Object> resultMap = new HashMap<>();
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         CTopOauthToken token = tokenService.getOAuthTokenByAccountId(user.getId());
         campaignTemplateMapper.insert(template);
-        return advertiserDataService.campaignCreate(token, template);
+        //新增数据
+        //        return advertiserDataService.campaignCreate(token, template);
+        resultMap.put("success", true);
+        resultMap.put("message", "广告组模板创建成功");
+        resultMap.put("code", 0);
+        return resultMap;
     }
 
     @Autowired
@@ -55,8 +78,167 @@ public class ByteDanceCampaignTemplateServiceImpl extends ServiceImpl<ByteDanceC
         return result;
     }
 
+    @Override
+    public Map<String, Object> campaignCreate(String accountId, String campaignName, String budgetMode, Integer budget, String landingType) {
+        Map<String, Object> resultMap = new HashMap<>();
+        CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
+        //2: 根据token以及用户id获取用户信息数据
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id", token.getAccountId());
+        params.put("campaign_name", campaignName);
+        params.put("budget_mode", budgetMode);
+        params.put("budget", budget);
+        params.put("landing_type", landingType);
+        JSONObject result = createCampaign(params, token.getAccessToken());
+        Integer code = result.getInteger("code");
+
+        if (null == code || !code.equals(0)) {
+            logger.info("创建广告组接口异常==》accountId:{},message:{}", accountId, result.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", "创建广告组接口异常");
+            return resultMap;
+        }
+        JSONObject data = result.getJSONObject("data");
+        if (null == data) {
+            logger.info("广告组创建异常==》accountId:{},message:{}", accountId, result.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", "广告组创建异常");
+            return resultMap;
+        }
+        Long id = data.getLong("campaign_id");
+        ByteDanceCampaign campaign = new ByteDanceCampaign(id, token, campaignName, budgetMode, budget, landingType);
+        //清除清数据,插入新数据
+        campaignMapper.insert(campaign);
+        resultMap.put("code", 0);
+        resultMap.put("message", "广告组创建成功");
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> campaignCreate(CTopOauthToken token, ByteDanceCampaignTemplate template) {
+        Map<String, Object> resultMap = new HashMap<>();
+        //2: 根据token以及用户id获取用户信息数据
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id", token.getAccountId());
+        params.put("campaign_name", template.getCampaignName());
+        params.put("budget_mode", template.getCampaignBudget());
+        params.put("budget", template.getBudgetDaily());
+        params.put("landing_type", template.getPromotionPurpose());
+        JSONObject result = createCampaign(params, token.getAccessToken());
+        Integer code = result.getInteger("code");
+
+        if (null == code || !code.equals(0)) {
+            logger.info("创建广告组接口异常==》accountId:{},message:{}", token.getAccountId(), result.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", result.getString("message"));
+            return resultMap;
+        }
+        JSONObject data = result.getJSONObject("data");
+        if (null == data) {
+            logger.info("广告组创建异常==》accountId:{},message:{}", token.getAccountId(), result.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", "广告组创建异常");
+            return resultMap;
+        }
+        Long id = data.getLong("campaign_id");
+        ByteDanceCampaign campaign = new ByteDanceCampaign(id, token, template);
+        //清除清数据,插入新数据
+        campaignMapper.insert(campaign);
+        resultMap.put("code", 0);
+        resultMap.put("message", "广告组创建成功");
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> campaignCreate(String getAccountId, Long campaignId, String name) {
+        ByteDanceCampaignTemplate template = campaignTemplateMapper.selectById(campaignId);
+        CTopOauthToken token = tokenService.getOAuthTokenByAccountId(getAccountId);
+        Map<String, Object> resultMap = new HashMap<>();
+        //2: 根据token以及用户id获取用户信息数据
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id", token.getAccountId());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_hh_mm_ss");
+        params.put("campaign_name", name + sdf.format(name + "_广告组_" + new Date()) + "汇创思拓_" + System.currentTimeMillis());
+        params.put("budget_mode", template.getCampaignBudget());
+        params.put("budget", template.getBudgetDaily());
+        params.put("landing_type", template.getPromotionPurpose());
+        JSONObject result = createCampaign(params, token.getAccessToken());
+        Integer code = result.getInteger("code");
+
+        if (null == code || !code.equals(0)) {
+            logger.info("创建广告组接口异常==》accountId:{},message:{}", token.getAccountId(), result.getString("message"));
+            resultMap.put("success", false);
+            resultMap.put("code", -1);
+            resultMap.put("message", result.getString("message"));
+            return resultMap;
+        }
+        JSONObject data = result.getJSONObject("data");
+        if (null == data) {
+            logger.info("广告组创建异常==》accountId:{},message:{}", token.getAccountId(), result.getString("message"));
+            resultMap.put("success", false);
+            resultMap.put("code", -1);
+            resultMap.put("message", "广告组创建异常");
+            return resultMap;
+        }
+        Long id = data.getLong("campaign_id");
+        ByteDanceCampaign campaign = new ByteDanceCampaign(id, token, template);
+        //清除清数据,插入新数据
+        campaignMapper.insert(campaign);
+        resultMap.put("campaignId", id);
+        resultMap.put("success", true);
+        resultMap.put("code", 0);
+        resultMap.put("message", "广告组创建成功");
+        return resultMap;
+    }
+
+    public JSONObject createCampaign(JSONObject data, String token) {
+        // 请求地址
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_create");
+        // 构造请求
+        HttpPost httpEntity = new HttpPost(url);
+
+        httpEntity.setHeader("Access-Token", token);
+
+        CloseableHttpResponse response = null;
+        CloseableHttpClient client = null;
+
+        try {
+            client = HttpClientBuilder.create().build();
+            httpEntity.setEntity(new StringEntity(data.toJSONString(), ContentType.APPLICATION_JSON));
+
+            response = client.execute(httpEntity);
+            if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                StringBuffer result = new StringBuffer();
+                String line = "";
+                while ((line = bufferedReader.readLine()) != null) {
+                    result.append(line);
+                }
+                bufferedReader.close();
+                return JSONObject.parseObject(result.toString());
+            }
+
+        } catch (ClientProtocolException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (response != null) {
+                    response.close();
+                }
+                client.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+
     @Autowired
     private ByteDanceCampaignTemplateMapper campaignTemplateMapper;
     @Autowired
     private ICTopOauthTokenService tokenService;
+    @Autowired
+    private ByteDanceCampaignMapper campaignMapper;
 }

+ 189 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ByteDanceCreativeServiceImpl.java

@@ -1,7 +1,9 @@
 package org.jeecg.modules.ctop.service.impl;
 
 import cn.com.ctop.common.utils.PropertiesUtils;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import io.swagger.models.auth.In;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
@@ -12,8 +14,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
 import org.jeecg.modules.ctop.entity.ByteDanceCreative;
 import org.jeecg.modules.ctop.entity.CTopOauthToken;
 import org.jeecg.modules.ctop.mapper.ByteDanceCreativeMapper;
-import org.jeecg.modules.ctop.service.IByteDanceCreativeService;
-import org.jeecg.modules.ctop.service.ICTopOauthTokenService;
+import org.jeecg.modules.ctop.service.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,17 +51,202 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
         String message = result.getString("message");
         if (null == code || code != 0) {
             logger.info("广告创意创建失败,accountId:{},message:{}", accountId, message);
+            resultMap.put("success", false);
             resultMap.put("code", -1);
             resultMap.put("message", message);
             return resultMap;
         }
         JSONObject dataObject = result.getJSONObject("data");
-//        Long adId = dataObject.getLong("ad_id");
+        resultMap.put("success", true);
         resultMap.put("code", 0);
         resultMap.put("message", "广告创意创建成功");
         return resultMap;
     }
 
+    @Autowired
+    private IFileInfoService fileInfoService;
+    @Autowired
+    private IByteDanceCampaignTemplateService campaignTemplateService;
+    @Autowired
+    private IBytedanceAdvertisePlanTemplateService planTemplateService;
+
+    @Override
+    public Map<String, Object> insertBatch(JSONObject template) {
+        System.out.println(template.toJSONString());
+        String getName = template.getString("name");
+        String getAccountId = template.getLong("accountId") + "";
+        Long campaignTemplateId = template.getLong("campaignId");
+        String deliveryRange = template.getString("deliveryRange");
+        Long userorentationId = template.getLong("userorentationId");
+        Long budgetId = template.getLong("budgetId");
+        Long deliverytargetId = template.getLong("deliverytargetId");
+        //1:创建广告组
+        Map<String, Object> campaignResult = campaignTemplateService.campaignCreate(getAccountId, campaignTemplateId, getName);
+        Boolean createSuccess = (Boolean) campaignResult.get("success");
+        if (null == createSuccess || !createSuccess) {
+            return campaignResult;
+        }
+        Long campaignId = (Long) campaignResult.get("campaignId");
+        //2:创建广告计划
+        Map<String, Object> planResult = planTemplateService.planCreate(campaignId, getAccountId, deliveryRange, userorentationId, budgetId, deliverytargetId, getName);
+        createSuccess = (Boolean) planResult.get("success");
+        if (null == createSuccess || !createSuccess) {
+            return planResult;
+        }
+        Long planId = (Long) campaignResult.get("planId");
+        //3:创建广告创意
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_VIDEO">横版视频</a-radio-button>
+        JSONArray horizonImageIds = new JSONArray();
+        String horizonVideoId = "";
+        String horizonVideoCoverImageId = "";
+
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_VIDEO_VERTICAL">竖版视频</a-radio-button>
+        String verticalVideoId = "";
+        String verticalVideoCoverImageId = "";
+
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_GROUP">组图</a-radio-button>
+        JSONArray groupImageIds = new JSONArray();
+
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_SMALL">小图</a-radio-button>
+        JSONArray smallImageIds = new JSONArray();
+
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_LARGE_VERTICAL">大图竖图</a-radio-button>
+        JSONArray verticalImageIds = new JSONArray();
+
+//        creative_display_mode
+        JSONObject data = new JSONObject();
+        data.put("ad_id", planId);
+        String advertiseLoaction = template.getString("advertiseLocation");
+        //优选广告位
+        if (null != advertiseLoaction && "great".equals(advertiseLoaction)) {
+            data.put("smart_inventory", 1);
+        } else {
+            data.put("smart_inventory", 0);
+        }
+        //按媒体指定位置
+        if (null != advertiseLoaction && "media".equals(advertiseLoaction)) {
+            JSONArray inventoryType = template.getJSONArray("inventoryType");
+            data.put("inventory_type", inventoryType);
+        }
+        //按场景指定位置
+        if (null != advertiseLoaction && "sence".equals(advertiseLoaction)) {
+            data.put("scene_inventory", template.getString("sceneInventory"));
+        }
+        JSONArray creatives = new JSONArray();
+
+        //<a-radio-button value="">大图横图</a-radio-button>
+        String horizonImageUrl = template.getString("horizonImageUrl");
+        String horizonImageCreativeText = template.getString("horizonImageCreativeText");
+        if (null != horizonImageUrl && !"".equals(horizonImageUrl) && null != horizonImageCreativeText && !"".equals(horizonImageCreativeText)) {
+            JSONObject creative = new JSONObject();
+            creative.put("image_mode", "CREATIVE_IMAGE_MODE_LARGE");
+//            Map<String,Object> getImageResult = fileInfoService.uploadImageToBytedance(getAccountId,horizonImageUrl);
+//            JSONArray imageArray = (JSONArray) getImageResult.get("imageIds");
+//            web.business.image/201908015d0dd63849aa78f142989c70
+            JSONArray imageArray = new JSONArray();
+            imageArray.add("web.business.image/201908015d0dd63849aa78f142989c70");
+            creative.put("image_ids", imageArray);
+            creative.put("title", horizonImageCreativeText);
+            creatives.add(creative);
+        }
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_VIDEO">横版视频</a-radio-button>
+        String horizonVideoUrl = template.getString("horizonVideoUrl");
+        String horizonVideoCoverImageUrl = template.getString("horizonVideoCoverImageUrl");
+        String horizonVideoCreativeText = template.getString("horizonVideoCreativeText");
+        if (null != horizonVideoUrl && !"".equals(horizonVideoUrl) && null != horizonVideoCoverImageUrl && !"".equals(horizonVideoCoverImageUrl) && null != horizonVideoCreativeText && !"".equals(horizonVideoCreativeText)) {
+            JSONObject creative = new JSONObject();
+            creative.put("image_mode", "CREATIVE_IMAGE_MODE_VIDEO");
+            Map<String, Object> getImageResult = fileInfoService.uploadImageToBytedance(getAccountId, horizonVideoCoverImageUrl);
+            JSONArray imageArray = (JSONArray) getImageResult.get("imageIds");
+            Map<String, Object> getVideoResult = fileInfoService.uploadVideoToBytedance(getAccountId, horizonVideoCreativeText);
+            String videoId = (String) getVideoResult.get("videoId");
+            creative.put("image_id", imageArray.getString(0));
+            creative.put("video_id", videoId);
+            creative.put("title", horizonVideoCreativeText);
+            creatives.add(creative);
+        }
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_VIDEO_VERTICAL">竖版视频</a-radio-button>
+        String verticalVideoUrl = template.getString("verticalVideoUrl");
+        String verticalVideoCoverImageUrl = template.getString("verticalVideoCoverImageUrl");
+        String verticalVideoCreativeText = template.getString("verticalVideoCreativeText");
+        if (null != verticalVideoUrl && !"".equals(verticalVideoUrl) && null != verticalVideoCoverImageUrl && !"".equals(verticalVideoCoverImageUrl) && null != verticalVideoCreativeText && !"".equals(verticalVideoCreativeText)) {
+            JSONObject creative = new JSONObject();
+            creative.put("image_mode", "CREATIVE_IMAGE_MODE_VIDEO_VERTICAL");
+            Map<String, Object> getImageResult = fileInfoService.uploadImageToBytedance(getAccountId, verticalVideoCoverImageUrl);
+            JSONArray imageArray = (JSONArray) getImageResult.get("imageIds");
+            Map<String, Object> getVideoResult = fileInfoService.uploadVideoToBytedance(getAccountId, verticalVideoUrl);
+            String videoId = (String) getVideoResult.get("videoId");
+            creative.put("image_id", imageArray.getString(0));
+            creative.put("video_id", videoId);
+            creative.put("title", verticalVideoCreativeText);
+            creatives.add(creative);
+        }
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_GROUP">组图</a-radio-button>
+        String groupImageUrl = template.getString("groupImageUrl");
+        String groupImageCreativeText = template.getString("groupImageCreativeText");
+        if (null != groupImageUrl && !"".equals(groupImageUrl) && null != groupImageCreativeText && !"".equals(groupImageCreativeText)) {
+            JSONObject creative = new JSONObject();
+            creative.put("image_mode", "CREATIVE_IMAGE_MODE_GROUP");
+            Map<String, Object> getImageResult = fileInfoService.uploadImageToBytedance(getAccountId, groupImageUrl);
+            JSONArray imageArray = (JSONArray) getImageResult.get("imageIds");
+            creative.put("image_ids", imageArray);
+            creative.put("title", groupImageCreativeText);
+            creatives.add(creative);
+        }
+
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_SMALL">小图</a-radio-button>
+        String smallImageUrl = template.getString("smallImageUrl");
+        String smallImageCreativeText = template.getString("smallImageCreativeText");
+        if (null != smallImageUrl && !"".equals(smallImageUrl) && null != smallImageCreativeText && !"".equals(smallImageCreativeText)) {
+            JSONObject creative = new JSONObject();
+            creative.put("image_mode", "CREATIVE_IMAGE_MODE_SMALL");
+            Map<String, Object> getImageResult = fileInfoService.uploadImageToBytedance(getAccountId, smallImageUrl);
+            JSONArray imageArray = (JSONArray) getImageResult.get("imageIds");
+            creative.put("image_ids", imageArray);
+            creative.put("title", smallImageCreativeText);
+            creatives.add(creative);
+        }
+
+        //<a-radio-button value="CREATIVE_IMAGE_MODE_LARGE_VERTICAL">大图竖图</a-radio-button>
+        String verticalImageUrl = template.getString("verticalImageUrl");
+        String verticalImageCreativeText = template.getString("verticalImageCreativeText");
+        if (null != verticalImageUrl && !"".equals(verticalImageUrl) && null != verticalImageCreativeText && !"".equals(verticalImageCreativeText)) {
+            JSONObject creative = new JSONObject();
+            creative.put("image_mode", "CREATIVE_IMAGE_MODE_LARGE_VERTICAL");
+//            Map<String,Object> getImageResult = fileInfoService.uploadImageToBytedance(getAccountId,verticalImageUrl);
+//            JSONArray imageArray = (JSONArray) getImageResult.get("imageIds");
+            JSONArray imageArray = new JSONArray();
+            imageArray.add("web.business.image/201908025d0d9292d0662227454294d5");
+            creative.put("image_ids", imageArray);
+            creative.put("title", verticalImageCreativeText);
+            creatives.add(creative);
+        }
+
+
+        data.put("creatives", creatives);
+
+        //应用下载详情页
+        data.put("web_url", template.getString("webUrl"));
+        //应用名
+        data.put("app_name", template.getString("appName"));
+        //广告评论
+        data.put("is_comment_disable ", template.getIntValue("isCommentDisable"));
+        //创意展现方式
+        data.put("creative_display_mode ", template.getString("creativeDisplayMode"));
+        //创意分类
+        JSONArray categorys = template.getJSONArray("adCategory");
+        String thirdIndustryId = categorys.getString(2);
+        data.put("third_industry_id", Integer.parseInt(thirdIndustryId));
+        //创意标签
+        data.put("ad_keywords", template.getJSONArray("adKeywords"));
+        //创意标题
+        data.put("title", "测试创意标题123" + System.currentTimeMillis());
+        return creativeCreate(getAccountId, planId, data.toJSONString());
+    }
+
+    @Autowired
+    private IByteDanceAdvertiserDataService advertiserDataService;
+
     public JSONObject createCreative(JSONObject data, String token) {
 
         // 构造请求

+ 29 - 17
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/BytedanceAdvertisePlanTemplateServiceImpl.java

@@ -3,6 +3,8 @@ package org.jeecg.modules.ctop.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.ResultMapUtils;
+import org.jeecg.common.util.StatusCode;
 import org.jeecg.modules.ctop.entity.*;
 import org.jeecg.modules.ctop.mapper.*;
 import org.jeecg.modules.ctop.service.IByteDanceAdvertisePlanService;
@@ -28,24 +30,36 @@ public class BytedanceAdvertisePlanTemplateServiceImpl extends ServiceImpl<Byted
     @Override
     public Map<String, Object> insertTemplate(BytedanceAdvertisePlanTemplate template, String accountId) {
         Map<String, Object> resultMap = new HashMap<>();
-        accountId = "74099510334";
-        template = templateMapper.selectById(2);
-        CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
-//        template.setStatus(1);
-//        templateMapper.insert(template);
-        //同步线上广告计划信息
-        ByteDanceBudgetTemplate budgetTemplate = budgetTemplateMapper.selectById(template.getBudgetTemplateId());
-        BytedanceDeliveryTargetTemplate deliveryTargetTemplate = deliveryTargetTemplateMapper.selectById(template.getDeliveryTargetTemplateId());
-        ByteDanceUserOrientationTemplate userOrientationTemplate = userOrientationTemplateMapper.selectById(template.getUserOrentationTemplateId());
-        ByteDanceCampaign campaign = campaignMapper.selectById(template.getCampaignTemplateId());
+        template.setStatus(1);
+        templateMapper.insert(template);
+        ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
+        return resultMap;
+    }
+
+    /**
+     * @param campaignId
+     * @param getAccountId
+     * @param deliveryRange
+     * @param userorentationId
+     * @param budgetId
+     * @param deliverytargetId
+     * @return
+     */
+    @Override
+    public Map<String, Object> planCreate(Long campaignId, String getAccountId, String deliveryRange, Long userorentationId, Long budgetId, Long deliverytargetId, String getName) {
+        CTopOauthToken token = tokenService.getOAuthTokenByAccountId(getAccountId);
+        ByteDanceBudgetTemplate budgetTemplate = budgetTemplateMapper.selectById(budgetId);
+        BytedanceDeliveryTargetTemplate deliveryTargetTemplate = deliveryTargetTemplateMapper.selectById(deliverytargetId);
+        ByteDanceUserOrientationTemplate userOrientationTemplate = userOrientationTemplateMapper.selectById(userorentationId);
+        ByteDanceCampaign campaign = campaignMapper.selectById(campaignId);
         JSONObject data = new JSONObject();
         //广告组id
-        data.put("campaign_id", template.getCampaignTemplateId());
+        data.put("campaign_id", campaignId);
         //投放范围
-        data.put("delivery_range", template.getDeliveryRange());
+        data.put("delivery_range", deliveryRange);
         //(1):投放目标
         //投放目标 转化量,点击量,展示量相关 未找到
-//        data.put("")
+//       data.put("")
         //下载方式 下载链接/落地页链接
         data.put("download_type", deliveryTargetTemplate.getDownloadType());
         if (null != deliveryTargetTemplate.getDownloadType() && !"".equals(deliveryTargetTemplate.getDownloadType()) && "DOWNLOAD_URL".equals(deliveryTargetTemplate.getDownloadType())) {
@@ -89,10 +103,8 @@ public class BytedanceAdvertisePlanTemplateServiceImpl extends ServiceImpl<Byted
         //过滤已转化用户类型 只有投放目标为转化量时,才需要该字段
         data.put("hide_if_converted", budgetTemplate.getFilterType());
 
-        data.put("name", template.getName());
-
-        return advertisePlanService.advertiserPlanCreate(token, template.getCampaignTemplateId(), data.toJSONString());
-//        return resultMap;
+        data.put("name", getName + "_计划_" + System.currentTimeMillis());
+        return advertisePlanService.advertiserPlanCreate(token, campaignId, data.toJSONString());
     }
 
     @Autowired

+ 118 - 21
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/FileInfoServiceImpl.java

@@ -2,9 +2,13 @@ package org.jeecg.modules.ctop.service.impl;
 
 import cn.com.ctop.common.utils.PropertiesUtils;
 import cn.com.ctop.toutiao.common.BytedanceInterfaceConstant;
+import com.alibaba.druid.support.spring.stat.annotation.Stat;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import constant.KuaishouInterfaceConstant;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.ClientProtocolException;
@@ -17,23 +21,29 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
 import org.apache.http.entity.mime.content.FileBody;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.jeecg.modules.ctop.entity.ByteDanceImageInfo;
-import org.jeecg.modules.ctop.entity.ByteDanceVideoInfo;
-import org.jeecg.modules.ctop.entity.CTopOauthToken;
-import org.jeecg.modules.ctop.entity.FileInfo;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.ResultMapUtils;
+import org.jeecg.common.util.StatusCode;
+import org.jeecg.modules.ctop.entity.*;
 import org.jeecg.modules.ctop.mapper.ByteDanceImageInfoMapper;
 import org.jeecg.modules.ctop.mapper.ByteDanceVideoInfoMapper;
 import org.jeecg.modules.ctop.mapper.FileInfoMapper;
 import org.jeecg.modules.ctop.service.ICTopOauthTokenService;
 import org.jeecg.modules.ctop.service.IFileInfoService;
+import org.jeecg.modules.system.entity.SysCategory;
+import org.jeecg.modules.system.mapper.SysCategoryMapper;
+import org.jeecg.modules.system.service.ISysCategoryService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletRequest;
 import java.io.*;
 import java.net.URI;
+import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -47,7 +57,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
     private static final Logger logger = LoggerFactory.getLogger(FileInfoServiceImpl.class);
 
     @Override
-    public Map<String, Object> uploadVideoToTemplate(String accountId, String videoUrl, String templatename) {
+    public Map<String, Object> uploadVideoToBytedance(String accountId, String videoUrl) {
         Map<String, Object> resultMap = new HashMap<>();
         //TODO查询是否已经上传过头条平台
         CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
@@ -57,15 +67,44 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         String message = resultObject.getString("message");
         if (null == code || code != 0) {
             logger.info("视频文件上传失败,accountId:{},message:{}", accountId, message);
-            resultMap.put("code", -1);
-            resultMap.put("message", "视频文件上传失败");
+            ResultMapUtils.setResultMap(resultMap, StatusCode.BYTEDANCE_VIDEO_UPLOAD_FAIL.getCode());
             return resultMap;
         }
         JSONObject data = resultObject.getJSONObject("data");
         ByteDanceVideoInfo videoInfo = new ByteDanceVideoInfo(data, token);
         videoInfoMapper.insert(videoInfo);
-        resultMap.put("code", 0);
-        resultMap.put("message", "视频文件上传成功");
+        ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
+        resultMap.put("videoId", videoInfo.getId());
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> upload3ImagesToBytedance(String accountId, String imageFileUrls) {
+        Map<String, Object> resultMap = new HashMap<>();
+        String[] imageUrls = imageFileUrls.split(",");
+        if (null == imageUrls || imageUrls.length < 3) {
+            ResultMapUtils.setResultMap(resultMap, StatusCode.IMAGE_NUMBER_SHORTAGE.getCode());
+            return resultMap;
+        }
+        CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
+        JSONArray imageIds = new JSONArray();
+        for (int i = 0; i < imageUrls.length; i++) {
+            JSONObject resultObject = uploadAdImage(token.getAccessToken(), imageUrls[i], token.getAccountId() + "");
+            System.out.println(resultObject);
+            Integer code = resultObject.getInteger("code");
+            String message = resultObject.getString("message");
+            if (null == code || code != 0) {
+                logger.info("图片文件上传失败,accountId:{},message:{}", accountId, message);
+                ResultMapUtils.setResultMap(resultMap, StatusCode.BYTEDANCE_VIDEO_UPLOAD_FAIL.getCode());
+                return resultMap;
+            }
+            JSONObject data = resultObject.getJSONObject("data");
+            ByteDanceVideoInfo videoInfo = new ByteDanceVideoInfo(data, token);
+            videoInfoMapper.insert(videoInfo);
+            imageIds.add(videoInfo.getId());
+        }
+        ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
+        resultMap.put("imageIds", imageIds);
         return resultMap;
     }
 
@@ -75,42 +114,99 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
     private ByteDanceImageInfoMapper imageInfoMapper;
 
     @Override
-    public Map<String, Object> uploadImageToTemplate(String accountId, String imageUrl, String templatename) {
+    public Map<String, Object> uploadImageToBytedance(String accountId, String imageUrl) {
         Map<String, Object> resultMap = new HashMap<>();
         CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
         JSONObject resultObject = uploadAdImage(token.getAccessToken(), imageUrl, token.getAccountId() + "");
-        System.out.println(resultObject);
         Integer code = resultObject.getInteger("code");
         String message = resultObject.getString("message");
         if (null == code || code != 0) {
             logger.info("图片文件上传失败,accountId:{},message:{}", accountId, message);
-            resultMap.put("code", -1);
-            resultMap.put("message", "图片文件上传失败");
+            ResultMapUtils.setResultMap(resultMap, StatusCode.BYTEDANCE_IMAGE_UPLOAD_FAIL.getCode());
             return resultMap;
         }
         JSONObject data = resultObject.getJSONObject("data");
         ByteDanceImageInfo imageInfo = new ByteDanceImageInfo(data, token);
         imageInfoMapper.insert(imageInfo);
-        resultMap.put("code", 0);
-        resultMap.put("message", "图片文件上传成功");
+        ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
+        JSONArray array = new JSONArray();
+        array.add(imageInfo.getId());
+        resultMap.put("imageIds", array);
         return resultMap;
     }
 
     @Override
-    public Map<String, Object> getIndustryList(String accountId) {
+    public Map<String, Object> getIndustryList(String accountId, Integer level) {
         Map<String, Object> resultMap = new HashMap<>();
         CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
-        JSONObject result = searchIndustry(token);
+        JSONObject result = searchIndustry(token, level);
+        JSONArray list = result.getJSONObject("data").getJSONArray("list");
+        for (int i = 0; i < list.size(); i++) {
+            JSONObject object = list.getJSONObject(i);
+            SysCategory category = new SysCategory();
+            String firstCode = object.getInteger("second_industry_id") + "";
+            QueryWrapper<SysCategory> wrapper = new QueryWrapper();
+            wrapper.eq("code", firstCode);
+            SysCategory parent = sysCategoryMapper.selectOne(wrapper);
+            category.setPid(parent.getId());
+            category.setName(object.getString("third_industry_name"));
+            category.setCode(object.getInteger("third_industry_id") + "");
+            category.setCreateBy("admin");
+            category.setCreateTime(new Date());
+            category.setSysOrgCode("A01");
+            sysCategoryMapper.insert(category);
+        }
         resultMap.put("code", 0);
         resultMap.put("message", "数据获取成功");
         resultMap.put("data", result);
         return resultMap;
     }
 
-    public JSONObject searchIndustry(CTopOauthToken token) {
+    @Override
+    public JSONArray getByteDanceIndustryList(HttpServletRequest req) {
+        JSONArray result = new JSONArray();
+        String pid = "6c6b0ad4f49b65f3943528e8a35d74fc";
+        List<SysCategory> categories = categoryService.getListByPid(pid);
+        for (SysCategory category : categories) {
+            JSONObject object = new JSONObject();
+            object.put("value", category.getCode());
+            object.put("label", category.getName());
+            JSONArray childListArray = new JSONArray();
+            List<SysCategory> childList = categoryService.getListByPid(category.getId());
+            for (SysCategory child : childList) {
+                JSONObject childObject = new JSONObject();
+                childObject.put("value", child.getCode());
+                childObject.put("label", child.getName());
+                JSONArray secendChildListArray = new JSONArray();
+                List<SysCategory> secendChildList = categoryService.getListByPid(child.getId());
+                for (SysCategory secendChild : secendChildList) {
+                    JSONObject secendChildObject = new JSONObject();
+                    secendChildObject.put("value", secendChild.getCode());
+                    secendChildObject.put("label", secendChild.getName());
+                    secendChildListArray.add(secendChildObject);
+                }
+                childObject.put("children", secendChildListArray);
+                childListArray.add(childObject);
+            }
+            object.put("children", childListArray);
+            result.add(object);
+        }
+        return result;
+    }
+
+
+    @Autowired
+    private ISysCategoryService categoryService;
+
+    @Autowired
+    private SysCategoryMapper sysCategoryMapper;
+
+    public JSONObject searchIndustry(CTopOauthToken token, Integer level) {
         // 请求地址
         String url = "https://ad.toutiao.com/open_api/2/tools/industry/get/";
-
+        if (null != level) {
+            url += "?level=" + level;
+        }
         // 构造请求
         HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
             @Override
@@ -163,7 +259,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         // 其他参数
         entityBuilder.addTextBody("advertiser_id", advertiserId);
         entityBuilder.addTextBody("upload_type", BytedanceInterfaceConstant.UPLOAD_TYPE_BY_URL);
-        entityBuilder.addTextBody("image_url", imageUrl);
+        entityBuilder.addTextBody("image_url", "https:" + imageUrl);
 
         HttpEntity entity = entityBuilder.build();
         CloseableHttpResponse response = null;
@@ -210,6 +306,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         httpPost.setHeader("Access-Token", accessToken);
         // 文件参数
         try {
+            videoUrl = "https:" + videoUrl;
             URI uri = new URI(videoUrl);
             FileBody file = new FileBody(new File(uri));
             MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create().addPart("video_file", file);

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysCategoryService.java

@@ -22,6 +22,8 @@ public interface ISysCategoryService extends IService<SysCategory> {
 	void addSysCategory(SysCategory sysCategory);
 	
 	void updateSysCategory(SysCategory sysCategory);
+
+    List<SysCategory> getListByPid(String pid);
 	
 	/**
 	  * 根据父级编码加载分类字典的数据

+ 13 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysCategoryServiceImpl.java

@@ -2,6 +2,10 @@ package org.jeecg.modules.system.service.impl;
 
 import java.util.List;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.jeecg.common.constant.CacheConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.system.entity.SysCategory;
@@ -52,6 +56,15 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
 		baseMapper.updateById(sysCategory);
 	}
 
+    @Override
+    public List<SysCategory> getListByPid(String pid) {
+        QueryWrapper<SysCategory> wrapper = new QueryWrapper<>();
+        wrapper.eq("pid", pid).orderByDesc("create_time");
+        Page<SysCategory> page = new Page<>(1, 1000);
+        IPage<SysCategory> pageList = this.page(page, wrapper);
+        return pageList.getRecords();
+    }
+
 	@Override
 	public List<TreeSelectModel> queryListByCode(String pcode) throws JeecgBootException{
 		String pid = ROOT_PID_VALUE;