|
@@ -0,0 +1,397 @@
|
|
|
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
|
+import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalPackage;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalPackageMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalPackageService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 自动投放-定向包详情
|
|
|
+ *
|
|
|
+ * @author jeecg-boot
|
|
|
+ * @version V1.0
|
|
|
+ * @date 2021-04-20
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouDirectionalPackageMapper, KuaishouDirectionalPackage> implements IKuaishouDirectionalPackageService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> createDirectionalPackage(String accessToken, JSONObject requestJson) {
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ String message = "";
|
|
|
+ int flag = -1;
|
|
|
+ try {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", requestJson.getLong("accountId"));
|
|
|
+ param.put("template_name", requestJson.getString("templateName"));
|
|
|
+ JSONObject targetJson = new JSONObject();
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
+ targetJson.put("region", requestJson.getJSONArray("region"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("districtIds"))) {
|
|
|
+ targetJson.put("district_ids", requestJson.getJSONArray("districtIds"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("userType"))) {
|
|
|
+ targetJson.put("user_type", requestJson.getInteger("userType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
|
|
|
+ targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject ageJson = new JSONObject();
|
|
|
+ if (!Check.isNull(requestJson.getInteger("min"))) {
|
|
|
+ ageJson.put("min", requestJson.getInteger("min"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("max"))) {
|
|
|
+ ageJson.put("max", requestJson.getInteger("max"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(ageJson)) {
|
|
|
+ targetJson.put("age", ageJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getInteger("gender"))) {
|
|
|
+ targetJson.put("gender", requestJson.getInteger("gender"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("platformOs"))) {
|
|
|
+ targetJson.put("platform_os", requestJson.getInteger("platformOs"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
|
|
|
+ targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
|
|
|
+ targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("network"))) {
|
|
|
+ targetJson.put("network", requestJson.getInteger("network"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
|
|
|
+ targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
|
|
|
+ targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
|
|
|
+ targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
|
|
|
+ targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
|
|
|
+ targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
|
|
|
+ targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
|
|
|
+ targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
|
|
|
+ targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
|
|
|
+ targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("population"))) {
|
|
|
+ targetJson.put("population", requestJson.getJSONArray("population"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("paidAudience"))) {
|
|
|
+ targetJson.put("paid_audience", requestJson.getJSONArray("paidAudience"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
+ targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
+ }
|
|
|
+ JSONObject intelliExtendJson = new JSONObject();
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
+ intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
|
|
|
+ intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
|
|
|
+ intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
|
|
|
+ intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(intelliExtendJson)) {
|
|
|
+ targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetJson)) {
|
|
|
+ param.put("target", targetJson);
|
|
|
+ }
|
|
|
+ JSONObject behaviorInterest = new JSONObject();
|
|
|
+ JSONObject behavior = new JSONObject();
|
|
|
+ JSONObject interest = new JSONObject();
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("keyword"))) {
|
|
|
+ behavior.put("keyword", requestJson.getJSONArray("keyword"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("label"))) {
|
|
|
+ behavior.put("label", requestJson.getJSONArray("label"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("strengthType"))) {
|
|
|
+ behavior.put("strength_type", requestJson.getInteger("strengthType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("timeType"))) {
|
|
|
+ behavior.put("time_type", requestJson.getInteger("timeType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("sceneType"))) {
|
|
|
+ behavior.put("scene_type", requestJson.getJSONArray("sceneType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("interestLabel"))) {
|
|
|
+ interest.put("label", requestJson.getJSONArray("interestLabel"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(behavior)) {
|
|
|
+ behaviorInterest.put("behavior", behavior);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(interest)) {
|
|
|
+ behaviorInterest.put("interest", interest);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(behaviorInterest)) {
|
|
|
+ param.put("behavior_interest", behaviorInterest);
|
|
|
+ }
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ message = resultJson.getString("message");
|
|
|
+ if (code == 0) {
|
|
|
+ flag = code;
|
|
|
+ JSONObject data = resultJson.getJSONObject("data");
|
|
|
+ requestJson.put("templateId", data.getLong("template_id"));
|
|
|
+ requestJson.put("dataStatus", 1);
|
|
|
+ } else {
|
|
|
+ requestJson.put("dataStatus", 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ requestJson.put("dataStatus", 0);
|
|
|
+ message = "返回结果为空";
|
|
|
+ }
|
|
|
+ requestJson.put("message", message);
|
|
|
+ KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
+ this.save(kuaishouDirectionalPackage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ returnJson.put("code", -1);
|
|
|
+ returnJson.put("message", e.getMessage());
|
|
|
+ }
|
|
|
+ if (flag == 0) {
|
|
|
+ return Result.ok(message);
|
|
|
+ } else {
|
|
|
+ return Result.error(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> updateDirectionalPackage(String accessToken, JSONObject requestJson) {
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ String message = "";
|
|
|
+ int flag = -1;
|
|
|
+ try {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("template_id", requestJson.getLong("templateId"));
|
|
|
+ param.put("advertiser_id", requestJson.getLong("accountId"));
|
|
|
+ if (!Check.isNull(requestJson.getString("templateName"))) {
|
|
|
+ param.put("template_name", requestJson.getString("templateName"));
|
|
|
+ }
|
|
|
+ JSONObject targetJson = new JSONObject();
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("region"))) {
|
|
|
+ targetJson.put("region", requestJson.getJSONArray("region"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("districtIds"))) {
|
|
|
+ targetJson.put("district_ids", requestJson.getJSONArray("districtIds"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("userType"))) {
|
|
|
+ targetJson.put("user_type", requestJson.getInteger("userType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
|
|
|
+ targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getInteger("min")) && !Check.isNull(requestJson.getInteger("max"))) {
|
|
|
+ JSONObject ageJson = new JSONObject();
|
|
|
+ ageJson.put("min", requestJson.getInteger("min"));
|
|
|
+ ageJson.put("max", requestJson.getInteger("max"));
|
|
|
+ targetJson.put("age", ageJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getInteger("gender"))) {
|
|
|
+ targetJson.put("gender", requestJson.getInteger("gender"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("platformOs"))) {
|
|
|
+ targetJson.put("platform_os", requestJson.getInteger("platformOs"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
|
|
|
+ targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
|
|
|
+ targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("network"))) {
|
|
|
+ targetJson.put("network", requestJson.getInteger("network"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
|
|
|
+ targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
|
|
|
+ targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
|
|
|
+ targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
|
|
|
+ targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
|
|
|
+ targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
|
|
|
+ targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
|
|
|
+ targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
|
|
|
+ targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
|
|
|
+ targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("population"))) {
|
|
|
+ targetJson.put("population", requestJson.getJSONArray("population"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("paidAudience"))) {
|
|
|
+ targetJson.put("paid_audience", requestJson.getJSONArray("paidAudience"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
|
|
|
+ targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getInteger("isOpen"))) {
|
|
|
+ JSONObject intelliExtendJson = new JSONObject();
|
|
|
+ intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
|
|
|
+
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
|
|
|
+ intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
|
|
|
+ intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
|
|
|
+ intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(intelliExtendJson)) {
|
|
|
+ targetJson.put("intelli_extend", intelliExtendJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetJson)) {
|
|
|
+ param.put("target", targetJson);
|
|
|
+ }
|
|
|
+ JSONObject behaviorInterest = new JSONObject();
|
|
|
+ JSONObject behavior = new JSONObject();
|
|
|
+ JSONObject interest = new JSONObject();
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("keyword"))) {
|
|
|
+ behavior.put("keyword", requestJson.getJSONArray("keyword"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("label"))) {
|
|
|
+ behavior.put("label", requestJson.getJSONArray("label"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("strengthType"))) {
|
|
|
+ behavior.put("strength_type", requestJson.getInteger("strengthType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getInteger("timeType"))) {
|
|
|
+ behavior.put("time_type", requestJson.getInteger("timeType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("sceneType"))) {
|
|
|
+ behavior.put("scene_type", requestJson.getJSONArray("sceneType"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(requestJson.getJSONArray("interestLabel"))) {
|
|
|
+ interest.put("label", requestJson.getJSONArray("interestLabel"));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(behavior)) {
|
|
|
+ behaviorInterest.put("behavior", behavior);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(interest)) {
|
|
|
+ behaviorInterest.put("interest", interest);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(behaviorInterest)) {
|
|
|
+ param.put("behavior_interest", behaviorInterest);
|
|
|
+ }
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_UPDATE;
|
|
|
+ log.info("入参:" + param);
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ message = resultJson.getString("message");
|
|
|
+ if (code == 0) {
|
|
|
+ flag = code;
|
|
|
+ JSONObject data = resultJson.getJSONObject("data");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
|
|
|
+ this.saveOrUpdate(kuaishouDirectionalPackage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ returnJson.put("code", -1);
|
|
|
+ returnJson.put("message", e.getMessage());
|
|
|
+ }
|
|
|
+ if (flag == 0) {
|
|
|
+ return Result.ok(message);
|
|
|
+ } else {
|
|
|
+ return Result.error(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize) {
|
|
|
+
|
|
|
+ PageHelper.startPage(pageNo, pageSize, false);
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> getRelatedAccountGroup(Long projectId,Long templateId, Integer type, Integer pageNo, Integer pageSize) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> pushDirectionalPackage(Long accountId, Long templateId, JSONArray ids) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> getHistory(Long projectId, Long templateId, Integer pageNo, Integer pageSize) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> getAccountByProjectId(Long projectId, Integer pageNo, Integer pageSize) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|