Browse Source

批量功能 程序化创意

yumeng 5 years ago
parent
commit
6351153065

+ 3 - 1
module-common/src/main/java/cn/com/ctop/common/module/enums/MaterialEnum.java

@@ -12,7 +12,9 @@ public enum MaterialEnum {
     VerticalVideo1080mall(1, 1080, 2200),
     VerticalVideoBig(1, 1080, 1920),
     HorizontalVideoSmall(2, 1280, 720),
-    HorizontalVideoBig(2, 1920, 1080);
+    HorizontalVideoBig(2, 1920, 1080),
+    BianlitieImageBig(4, 540, 540),
+    BianLitieImageSmall(4, 450, 450);
 
     private Integer type;
     private Integer width;

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

@@ -2247,9 +2247,10 @@ public class BatchController {
         Result<Boolean> result = new Result<>();
         try {
             String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -30);
             String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, 1);
-            syncPullMaterialService.getSyncVideoList(accountId, nowDate, nowDate);
-            syncPullMaterialService.getSyncSuZaoList(accountId, nowDate, endDate);
+            syncPullMaterialService.getSyncVideoList(accountId, startDate, nowDate);
+            syncPullMaterialService.getSyncSuZaoList(accountId, startDate, endDate);
             Thread.sleep(5 * 1000L);
             result.setSuccess(true);
             result.setResult(true);

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouProgramCreativeController.java

@@ -75,7 +75,6 @@ public class KuaishouProgramCreativeController {
             if (Check.isNull(kuaishouProgramCreative.getAccountId()) || Check.isNull(kuaishouProgramCreative.getUnitId())) {
                 throw new Exception("必填参数不能为空");
             }
-
             CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(kuaishouProgramCreative.getAccountId());
             if (Check.isNull(oauthToken)) {
                 throw new Exception("未获取到账户信息");
@@ -121,6 +120,7 @@ public class KuaishouProgramCreativeController {
 
             JSONObject returnJson = kuaishouProgramCreativeService.createProgramCreative(oauthToken, requestJson);
             result.success("添加成功!");
+
         } catch (Exception e) {
             result.setSuccess(false);
             result.setMessage(e.getMessage());

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

@@ -178,8 +178,9 @@ public class BatchServiceImpl implements IBatchService {
         }
         Integer sceneId = valueOf(scene_id.get(0).toString());
         // 资源创作方式
-        if (!Check.isNull(requestJson.getInteger("unitType"))) {
-            unitJson.put("unit_type", requestJson.getInteger("unitType"));
+        Integer unitType = requestJson.getInteger("unitType");
+        if (!Check.isNull(unitType)) {
+            unitJson.put("unit_type", unitType);
         }
 
         // 转化目标id
@@ -407,6 +408,7 @@ public class BatchServiceImpl implements IBatchService {
                         successJson.put("unitName", unitName);
                         successJson.put("sceneId", scene_id);
                         successJson.put("ocpxActionType", ocpx_action_type);
+                        successJson.put("unitType", unitType);
                         successArr.add(successJson);
 
                         if (!Check.isNull(type) && "copy".equals(type)) {
@@ -1266,9 +1268,7 @@ public class BatchServiceImpl implements IBatchService {
         creativeJson.put("unit_id", unitId);
 
         // 素材类型
-        if (!Check.isNull(requestJson.get("creativeMaterialType"))) {
-            creativeJson.put("creative_material_type", requestJson.get("creativeMaterialType"));
-        }
+
         String action_bar_text = requestJson.getString("actionBarText");
         String click_track_url = requestJson.getString("clickTrackUrl");
         String site_id = requestJson.getString("siteId");
@@ -1282,6 +1282,11 @@ public class BatchServiceImpl implements IBatchService {
         if (!Check.isNull(dataJsons)) {
             for (int i = 0; i < dataJsons.size(); i++) {
                 JSONObject dataJson = dataJsons.getJSONObject(i);
+
+                String creativeMaterialType = dataJson.getString("creativeMaterialType");
+                String shortSlogan = dataJson.getString("shortSlogan");
+
+
                 if (!Check.isNull(dataJsons)) {
                     String description = dataJson.getString("description");
                     String photo_id = dataJson.getString("photoId");
@@ -1296,10 +1301,20 @@ public class BatchServiceImpl implements IBatchService {
                                 creativeJson.put("description", description.trim());
                                 creativeJson.put("creative_name", name);
                                 creativeJson.put("photo_id", photo_id);
-                                creativeJson.put("click_track_url", click_track_url);
+
                                 if (!Check.isNull(site_id)) {
                                     creativeJson.put("site_id", site_id);
                                 }
+                                if (!Check.isNull(creativeMaterialType)) {
+                                    creativeJson.put("creative_material_type", creativeMaterialType);
+                                }
+
+                                if (creativeMaterialType.equals("4")) {
+                                    if (!Check.isNull("shortSlogan")) {
+                                        creativeJson.put("short_slogan", shortSlogan);
+                                    }
+
+                                }
                                 String imageToken = null;
                                 String signature = imageJson.getString("signature");
                                 if (!Check.isNull(signature)) {
@@ -1322,7 +1337,16 @@ public class BatchServiceImpl implements IBatchService {
                                         continue;
                                     }
                                 }
-                                creativeJson.put("image_token", imageToken);
+                                if (creativeMaterialType.equals("4")) {
+                                    JSONArray tokenArr = new JSONArray();
+                                    tokenArr.add(imageToken);
+                                    creativeJson.put("image_tokens", tokenArr);
+                                    creativeJson.put("click_track_url", click_track_url);
+                                    creativeJson.put("impression_url", click_track_url);
+                                } else {
+                                    creativeJson.put("image_token", imageToken);
+                                    creativeJson.put("click_track_url", click_track_url);
+                                }
                                 Map<String, Object> returnUnitMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson, 1);
                                 if (!Check.isNullMap(returnUnitMap)) {
                                     Integer code = (Integer) returnUnitMap.get("code");

+ 60 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouProgramCreativeServiceImpl.java

@@ -5,14 +5,19 @@ 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.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProgramCreative;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouProgramCreativeMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouProgramCreativeService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import lombok.var;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -31,6 +36,12 @@ import java.util.Map;
 @Slf4j
 public class KuaishouProgramCreativeServiceImpl extends ServiceImpl<KuaishouProgramCreativeMapper, KuaishouProgramCreative> implements IKuaishouProgramCreativeService {
 
+    @Autowired
+    private IKuaiShouImageGetService imageGetService;
+    @Autowired
+    private IKuaiShouMaterialUploadService uploadService;
+
+
     @Override
     public void getProgramCreative(Long accountId, Long unitId, String accessToken, String startDate, String endDate, Integer page) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.PROGRAM_LIST;
@@ -58,7 +69,6 @@ public class KuaishouProgramCreativeServiceImpl extends ServiceImpl<KuaishouProg
 
         String result = HttpUtils.httpPostRequest(url, param, headers);
         JSONObject resultJson = JSONObject.parseObject(result);
-        System.err.println(resultJson);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
         if (null == code || code != 0) {
@@ -90,7 +100,7 @@ public class KuaishouProgramCreativeServiceImpl extends ServiceImpl<KuaishouProg
         }
 
         this.saveOrUpdateBatch(programCreativeList);
-        getProgramCreative(accountId, unitId, accessToken, startDate, endDate, page + 1);
+    //    getProgramCreative(accountId, unitId, accessToken, startDate, endDate, page + 1);
 
 
     }
@@ -111,7 +121,7 @@ public class KuaishouProgramCreativeServiceImpl extends ServiceImpl<KuaishouProg
             JSONObject pramsJson = new JSONObject();
             pramsJson.put("advertiser_id", oauthToken.getAccountId());
             pramsJson.put("unit_id", requestJson.getLong("unitId"));
-            pramsJson.put("package_name", requestJson.getLong("packageName"));
+            pramsJson.put("package_name", requestJson.getString("packageName"));
             pramsJson.put("horizontal_photo_ids", requestJson.getJSONArray("horizontalPhotoIds"));
             pramsJson.put("vertical_photo_ids", requestJson.getJSONArray("verticalPhotoIds"));
             pramsJson.put("cover_image_tokens", requestJson.getJSONArray("coverImageTokens"));
@@ -127,7 +137,7 @@ public class KuaishouProgramCreativeServiceImpl extends ServiceImpl<KuaishouProg
                 pramsJson.put("cover_slogans", requestJson.getJSONArray("coverSlogans"));
             }
 
-            pramsJson.put("action_bar", requestJson.getString("actionBar"));
+            pramsJson.put("action_bar", requestJson.getString("actionBarText"));
             pramsJson.put("captions", requestJson.getJSONArray("captions"));
             if (!Check.isNull(requestJson.getString("clickUrl"))) {
                 pramsJson.put("click_url", requestJson.getString("clickUrl"));
@@ -139,7 +149,52 @@ public class KuaishouProgramCreativeServiceImpl extends ServiceImpl<KuaishouProg
             headers.put("Content-Type", "application/json");
             headers.put("Access-Token", oauthToken.getAccessToken());
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.PROGRAM_CREATE;
-            String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+
+
+            JSONArray coverImageTokens = requestJson.getJSONArray("coverImageTokens");
+            JSONArray cover_image_tokens = new JSONArray();
+            requestJson.remove(coverImageTokens);
+            if (!Check.isNull(coverImageTokens)) {
+
+                for (int i = 0; i < coverImageTokens.size(); i++) {
+                    String signature = coverImageTokens.getString(i);
+                    if (Check.isNull(signature)) {
+                        continue;
+                    }
+                    String imageToken = null;
+
+                    if (!Check.isNull(signature)) {
+                        QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
+                        queryWrapper.eq("account_id", oauthToken.getAccountId());
+                        queryWrapper.eq("signature", signature);
+                        queryWrapper.last("limit 1");
+                        KuaiShouImageGet imageGet = imageGetService.getOne(queryWrapper);
+                        if (!Check.isNull(imageGet)) {
+                            imageToken = imageGet.getImageToken();
+                        } else {
+                            String imageUrl = imageGetService.getUrlByCode(signature);
+                            imageToken = uploadService.kuauiShouImageUpload(imageUrl, signature, oauthToken.getAccountId(), oauthToken.getAccessToken());
+                        }
+                        cover_image_tokens.add(imageToken);
+                        /*if (Check.isNull(imageToken)) {
+                            JSONObject failJson = new JSONObject();
+                            failJson.put("creativeName", name);
+                            failJson.put("failMessage", "获取图片文件失败");
+                            failArr.add(failJson);
+                            continue;
+                        }*/
+                    }
+
+
+                }
+
+
+            }
+
+            pramsJson.put("cover_image_tokens", cover_image_tokens);
+
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, pramsJson.toJSONString(), headers);
+            System.err.println(result);
 
         } catch (Exception e) {
             e.printStackTrace();

+ 1 - 1
module-oa/src/main/java/cn/com/ctop/oa/modules/service/impl/WechatCheckinDataServiceImpl.java

@@ -57,7 +57,7 @@ public class WechatCheckinDataServiceImpl extends ServiceImpl<WechatCheckinDataM
                 userArr.add(userId);
                 params.put("useridlist", userArr);
                 params.put("starttime", 1598889600);
-                params.put("endtime", 1600099200);
+                params.put("endtime", 1600927780);
                 String resultStr = HttpUtils.httpPostRequestTest(QYWxConstant.QYWX_CHECKIN_DATA + "?access_token=" + qywxAccessToken.get("accessToken"), params.toJSONString(), null);
                 JSONObject resultJson = JSONObject.parseObject(resultStr);
                 Integer errcode = resultJson.getInteger("errcode");