yumeng 5 years ago
parent
commit
066ef9698b
23 changed files with 413 additions and 116 deletions
  1. 12 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialInfoController.java
  2. 5 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialUploadController.java
  3. 0 5
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java
  4. 4 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/MaterialImageInfoMapper.java
  5. 11 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MaterialImageInfoMapper.xml
  6. 1 1
      module-common/src/main/java/cn/com/ctop/common/module/service/IFileInfoService.java
  7. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialImageInfoService.java
  8. 9 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java
  9. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/service/ISendMessageService.java
  10. 23 14
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/FileInfoServiceImpl.java
  11. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialImageInfoServiceImpl.java
  12. 57 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java
  13. 26 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/SendMessageServiceImpl.java
  14. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java
  15. 1 1
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/IMaterialUploadService.java
  16. 54 55
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadImageServiceImpl.java
  17. 23 11
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java
  18. 120 3
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java
  19. 3 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IBatchService.java
  20. 8 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  21. 7 20
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java
  22. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java
  23. 31 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

+ 12 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialInfoController.java

@@ -324,6 +324,10 @@ public class MaterialInfoController {
      */
     @Autowired
     private IProjectService projectService;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private ISendMessageService sendMessageService;
 
     @AutoLog(value = "素材信息-编辑")
     @ApiOperation(value = "素材信息-编辑", notes = "素材信息-编辑")
@@ -390,6 +394,14 @@ public class MaterialInfoController {
             if (ok) {
                 result.success("修改成功!");
             }
+
+            Integer status = materialInfo.getStatus();
+            // 如果状态为2 审核拒绝 给上传人发送消息
+            if (status == 2) {
+                Project project = projectService.getById(materialInfoEntity.getProjectId());
+                String text = messageTemplate.getMaterialRejectTemplate(project.getProjectName(), materialInfoEntity.getMaterialName(), materialInfo.getRefuseReason());
+                sendMessageService.sendMessage(materialInfoEntity.getUserId(), text);
+            }
         }
 
         return result;

+ 5 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialUploadController.java

@@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -44,8 +46,10 @@ public class MaterialUploadController {
             if (Check.isNull(materialArray) || Check.isNull(accountArray)) {
                 throw new Exception("请选择账号或素材");
             }
+            LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
 
-            new Thread(() -> materialUploadService.uploadAccount(mediaId, materialArray, accountArray)).start();
+
+            new Thread(() -> materialUploadService.uploadAccount(mediaId, materialArray, accountArray, sysUser.getId())).start();
             returnMap.put("success", true);
             returnMap.put("message", "开始上传文件");
             returnMap.put("code", 0);

+ 0 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java

@@ -149,11 +149,6 @@ public class UserAllocationController {
             QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("project_id", projectId);
 
-           /* if (!Check.isNull(project)) {
-            Project project = projectService.getById(projectId);
-                queryWrapper.eq("media_id", project.getMediaId());
-            }*/
-
             String roleCode = sysRoleService.getRoleCodeByUserId(userId);
             if (!CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode) && !"kuaishouOperationManager".equals(roleCode) && !"designTeamLeader".equals(roleCode) && !"touTiaoOperationManager".equals(roleCode)) {
                 queryWrapper.eq("user_id", userId);

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/MaterialImageInfoMapper.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.MaterialImageInfo;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -16,4 +18,6 @@ public interface MaterialImageInfoMapper extends BaseMapper<MaterialImageInfo> {
     void insertSelective(MaterialImageInfo materialImageInfo);
 
     List<String> getCodeList();
+
+    List<JSONObject> getUrlList(@Param("videoId") String videoId);
 }

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

@@ -120,4 +120,15 @@
      SELECT DISTINCT(code)  from  ctop_material_image_info
     </select>
 
+    <select id="getUrlList" resultType="com.alibaba.fastjson.JSONObject">
+
+        SELECT t.url as 'imageUrl',t.`code` as 'signature'  from (
+        SELECT url,`code` from ctop_material_image_info
+        WHERE video_id = #{videoId}
+        UNION ALL
+        SELECT url,signature  from ctop_material_cut_frame WHERE video_signature = #{videoId}
+        ) t
+
+    </select>
+
 </mapper>

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/IFileInfoService.java

@@ -16,7 +16,7 @@ import java.util.Map;
  */
 public interface IFileInfoService extends IService<FileInfo> {
 
-    void uploadVideoToBytedance(String accountId, String videoUrl);
+    void uploadVideoToBytedance(String accountId, String videoUrl, String userId,String materialName);
 
     Map<String, Object> uploadImageToBytedance(String accountId, String imageFileId);
 

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialImageInfoService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.service;
 
 import cn.com.ctop.common.module.entity.MaterialImageInfo;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -26,4 +27,5 @@ public interface IMaterialImageInfoService extends IService<MaterialImageInfo> {
 
     List<String> getCodeList();
 
+    List<JSONObject> getUrlList(String videoId);
 }

+ 9 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java

@@ -0,0 +1,9 @@
+package cn.com.ctop.common.module.service;
+
+public interface IMessageTemplate {
+
+    String getMaterialSyncTemplate(String projectName, Long accountId, String accountName, String materialName, String reason);
+
+
+    String getMaterialRejectTemplate(String projectName, String materialName, String refuseReason);
+}

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

@@ -0,0 +1,5 @@
+package cn.com.ctop.common.module.service;
+
+public interface ISendMessageService {
+    void sendMessage(String id, String text);
+}

+ 23 - 14
module-common/src/main/java/cn/com/ctop/common/module/service/impl/FileInfoServiceImpl.java

@@ -2,10 +2,11 @@ package cn.com.ctop.common.module.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.FileInfo;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.FileInfoMapper;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
-import cn.com.ctop.common.module.service.IFileInfoService;
+import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.BytedanceInterfaceConstant;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import com.alibaba.fastjson.JSONArray;
@@ -53,14 +54,31 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
     FileInfoMapper fileInfoMapper;
     @Resource
     private ICtopOauthTokenService ctopOauthTokenService;
+    @Autowired
+    private IUserAllocationService userAllocationService;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private ISendMessageService sendMessageService;
 
     @Override
-    public void uploadVideoToBytedance(String accountId, String videoUrl) {
+    public void uploadVideoToBytedance(String accountId, String videoUrl, String userId, String materialName) {
         try {
             CtopOauthToken token = ctopOauthTokenService.getOauthTokenByAccountId(accountId);
-            uploadAdvideo(token, videoUrl, token.getAccountId() + "");
             JSONObject jsonObject = videoUpload(token, videoUrl);
-            log.info("头条上传素材返回信息:{},accountId:{}", jsonObject, accountId);
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 0) {
+                    log.info("头条上传素材成功,返回信息:{},accountId:{}", jsonObject, accountId);
+                } else {
+                    UserAllocation allocation = userAllocationService.getByAccountId(Long.valueOf(accountId));
+                    String message = messageTemplate.getMaterialSyncTemplate(allocation.getProjectName(), Long.valueOf(accountId), allocation.getAuthName(), materialName, jsonObject.getString("message"));
+                    sendMessageService.sendMessage(userId, message);
+                }
+
+            }
+
+
         } catch (Exception e) {
             log.error("头条上传视频文件失败,accountId:{}", accountId);
             log.error(e.getMessage(), e);
@@ -207,15 +225,6 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         }
     }
 
-    public void uploadAdvideo(CtopOauthToken token, String videoUrl, String advertiserId) {
-        //1:下载文件到本地
-
-
-        //文件上传
-        // JSONObject bytedanceObject = videoUpload(token, advertiserId, videoPath);
-        // log.info("头条上传返回信息:{},accountId:{}", bytedanceObject, advertiserId);
-
-    }
 
     private JSONObject videoUpload(CtopOauthToken token, String videoPath) {
         CloseableHttpResponse response = null;

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

@@ -128,4 +128,9 @@ public class MaterialImageInfoServiceImpl extends ServiceImpl<MaterialImageInfoM
         return materialImageInfoMapper.getCodeList();
     }
 
+    @Override
+    public List<JSONObject> getUrlList(String videoId) {
+        return materialImageInfoMapper.getUrlList(videoId);
+    }
+
 }

+ 57 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java

@@ -0,0 +1,57 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.service.IMessageTemplate;
+import cn.com.ctop.common.module.utils.Check;
+import org.springframework.stereotype.Service;
+
+@Service
+public class MessageTemplateImpl implements IMessageTemplate {
+
+
+    /**
+     * 同步素材失败
+     *
+     * @param projectName
+     * @param accountId
+     * @param accountName
+     * @param materialName
+     * @param reason
+     * @return
+     */
+    @Override
+    public String getMaterialSyncTemplate(String projectName, Long accountId, String accountName, String materialName, String reason) {
+        StringBuilder text = new StringBuilder();
+        text.append("素材同步失败").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("下的账户:").append(accountId + ",").append("<br/>")
+                .append("授权名称为:" + accountName).append("<br/>")
+                .append("同步素材失败。").append("<br/>")
+                .append("素材名称为:").append(materialName).append("<br/>")
+                .append("失败原因:").append(reason);
+        return text.toString();
+    }
+
+
+    /**
+     * 素材库素材驳回
+     *
+     * @param projectName
+     * @param materialName
+     * @param refuseReason
+     * @return
+     */
+    @Override
+    public String getMaterialRejectTemplate(String projectName, String materialName, String refuseReason) {
+        StringBuilder text = new StringBuilder();
+        text.append("素材驳回通知").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("素材名称为:").append(materialName).append("<br/>")
+                .append("已被驳回。").append("<br/>");
+        if (!Check.isNull(refuseReason)) {
+            text.append("驳回原因为:").append(refuseReason).append("</br>");
+
+        }
+        text.append("请您联系相关同学及时调整");
+        return text.toString();
+    }
+}

+ 26 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/SendMessageServiceImpl.java

@@ -0,0 +1,26 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.mapper.MailLogMapper;
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.CorpWexinUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class SendMessageServiceImpl implements ISendMessageService {
+    @Autowired
+    private MailLogMapper mailLogMapper;
+
+    @Override
+    public void sendMessage(String userId, String text) {
+        String weChatId = mailLogMapper.getWChatIdByUserId(userId);
+        if (!Check.isNull(weChatId)) {
+            CorpWexinUtils.sendMessageByWeChatId(weChatId, text);
+            log.info("消息发送成功,userId:{}", userId);
+        }
+    }
+
+}

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -114,6 +114,11 @@ public class KuaishouInterfaceConstant {
      */
     public static final String CONVERT_LIST = "/rest/openapi/v1/tool/convert/list";
 
+    /**
+     * 获取可选的动态词包
+     */
+    public static final String CREATIVE_WORD = "/rest/openapi/v1/tool/creative_word/list";
+
 
     /**
      * 获取定向标签

+ 1 - 1
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/IMaterialUploadService.java

@@ -11,5 +11,5 @@ public interface IMaterialUploadService {
      * @param materialArray
      * @param accountArray
      */
-    void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray);
+    void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray,String userId);
 }

+ 54 - 55
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadImageServiceImpl.java

@@ -1,22 +1,20 @@
 package cn.com.ctop.manage.modules.material.service.impl;
 
-import cn.com.ctop.common.module.entity.MaterialImageInfo;
 import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.service.IMaterialImageInfoService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
-import cn.com.ctop.common.module.utils.LoadFileUtil;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
 import cn.com.ctop.manage.modules.material.service.IMaterialUploadImageService;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.ParseException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.io.FileSystemResource;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
@@ -26,7 +24,6 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
-import java.io.File;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -36,7 +33,7 @@ import java.util.concurrent.Executors;
 @Slf4j
 @Service
 public class MaterialUploadImageServiceImpl implements IMaterialUploadImageService {
-    static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    static ExecutorService executorService = Executors.newFixedThreadPool(8);
     @Value("${oss.replace.replace-value}")
     private String replaceValue;
     @Value("${oss.replace.replace-old-value}")
@@ -55,63 +52,65 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
     @Override
     public void uploadImage(String videoId, Long accountId, String accessToken) {
         try {
-            QueryWrapper<MaterialImageInfo> imageInfoQueryWrapper = new QueryWrapper<>();
-            imageInfoQueryWrapper.eq("video_id", videoId);
-            imageInfoQueryWrapper.eq("status", 0);
-            List<MaterialImageInfo> imageList = materialImageInfoService.list(imageInfoQueryWrapper);
+            List<JSONObject> imageList = materialImageInfoService.getUrlList(videoId);
             if (!Check.isNull(imageList)) {
-                for (MaterialImageInfo imageInfo : imageList) {
-                    QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
-                    imageQueryWrapper.eq("account_id", accountId);
-                    imageQueryWrapper.eq("signature", imageInfo.getCode());
-                    List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
-                    if (!Check.isNull(imageGetList)) {
-                        log.info("此封面已上传");
+                for (int i = 0; i < imageList.size(); i++) {
+                    JSONObject imageInfo = imageList.get(i);
+                    if (Check.isNull(imageInfo)) {
                         continue;
                     }
-                    String url = String.valueOf(imageInfo.getUrl());
-                    String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
-                    FileSystemResource resource = new FileSystemResource(new File(localUrl));
-                    Map<String, String> headerMap = new HashMap<>();
-                    JSONObject requestJson = new JSONObject();
-                    requestJson.put("advertiser_id", accountId);
-                    headerMap.put("Access-Token", accessToken);
-                    headerMap.put("Content-Type", "multipart/form-data");
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
+                            imageQueryWrapper.eq("account_id", accountId);
+                            imageQueryWrapper.eq("signature", imageInfo.getString("signature"));
+                            List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
+                            if (Check.isNull(imageGetList)) {
+                                Map<String, String> headerMap = new HashMap<>();
+                                JSONObject requestJson = new JSONObject();
+                                requestJson.put("advertiser_id", accountId);
+                                headerMap.put("Access-Token", accessToken);
+                                headerMap.put("Content-Type", "multipart/form-data");
 
-                    requestJson.put("file", resource);
-                    requestJson.put("signature", imageInfo.getCode());
-                    requestJson.put("type", "2");
-                    requestJson.put("upload_type", "1");
-                    String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
-                    String result = exceptInfoForRestTemplate(requestUrl, requestJson, headerMap);
-                    JSONObject resultJson = JSONObject.parseObject(result);
-                    if (!Check.isNull(resultJson)) {
-                        if (resultJson.getInteger("code") == 0) {
-                            JSONObject dataJson = resultJson.getJSONObject("data");
-                            if (!Check.isNull(dataJson)) {
-                                String signature = dataJson.getString("signature");
-                                String image_token = dataJson.getString("image_token");
-                                KuaiShouImageGet imageGet = new KuaiShouImageGet();
-                                imageGet.setId(accountId + image_token);
-                                imageGet.setAccountId(accountId);
-                                imageGet.setUrl(dataJson.getString("url"));
-                                imageGet.setWidth(dataJson.getInteger("width"));
-                                imageGet.setHeight(dataJson.getInteger("height"));
-                                imageGet.setSize(dataJson.getInteger("size"));
-                                imageGet.setFormat(dataJson.getString("format"));
-                                Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
-                                if (!Check.isNull(type)) {
-                                    imageGet.setMaterialType(type);
+                                requestJson.put("url", imageInfo.getString("imageUrl"));
+                                requestJson.put("signature", imageInfo.getString("signature"));
+                                requestJson.put("type", "2");
+                                requestJson.put("upload_type", "2");
+                                String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
+                                String result = exceptInfoForRestTemplate(requestUrl, requestJson, headerMap);
+                                JSONObject resultJson = JSONObject.parseObject(result);
+                                if (!Check.isNull(resultJson)) {
+                                    if (resultJson.getInteger("code") == 0) {
+                                        JSONObject dataJson = resultJson.getJSONObject("data");
+                                        if (!Check.isNull(dataJson)) {
+                                            String signature = dataJson.getString("signature");
+                                            String image_token = dataJson.getString("image_token");
+                                            KuaiShouImageGet imageGet = new KuaiShouImageGet();
+                                            imageGet.setId(accountId + image_token);
+                                            imageGet.setAccountId(accountId);
+                                            imageGet.setUrl(dataJson.getString("url"));
+                                            imageGet.setWidth(dataJson.getInteger("width"));
+                                            imageGet.setHeight(dataJson.getInteger("height"));
+                                            imageGet.setSize(dataJson.getInteger("size"));
+                                            imageGet.setFormat(dataJson.getString("format"));
+                                            Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
+                                            if (!Check.isNull(type)) {
+                                                imageGet.setMaterialType(type);
+                                            }
+                                            imageGet.setSignature(signature);
+                                            imageGet.setImageToken(image_token);
+                                            imageGetService.saveOrUpdate(imageGet);
+                                        }
+                                        log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getString("signature"), resultJson);
+                                    } else {
+                                        log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+                                    }
                                 }
-                                imageGet.setSignature(signature);
-                                imageGet.setImageToken(image_token);
-                                imageGetService.saveOrUpdate(imageGet);
                             }
-                            log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getCode(), resultJson);
-                        } else {
-                            log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+
                         }
-                    }
+                    });
                 }
             }
         } catch (Exception e) {

+ 23 - 11
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java

@@ -3,12 +3,12 @@ package cn.com.ctop.manage.modules.material.service.impl;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.MaterialInfo;
 import cn.com.ctop.common.module.entity.MaterialParameter;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
 import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
-import cn.com.ctop.common.module.service.IFileInfoService;
-import cn.com.ctop.common.module.service.IMaterialParameterService;
+import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.LoadFileUtil;
@@ -67,6 +67,12 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     private IKuaiShouVideoGetService kuaiShouVideoGetService;
     @Autowired
     private IMaterialUploadImageService materialUploadImageService;
+    @Autowired
+    private ISendMessageService sendMessageService;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private IUserAllocationService userAllocationService;
 
 
     /**
@@ -78,12 +84,12 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
      */
 
     @Override
-    public void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+    public void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray, String userId) {
         try {
             if ("2".equals(mediaId)) {
-                this.kuaiShouUpload(mediaId, materialArray, accountArray);
+                this.kuaiShouUpload(mediaId, materialArray, accountArray, userId);
             } else if ("1".equals(mediaId)) {
-                this.touTiaoUpload(mediaId, materialArray, accountArray);
+                this.touTiaoUpload(mediaId, materialArray, accountArray, userId);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -93,7 +99,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     }
 
 
-    private void touTiaoUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+    private void touTiaoUpload(String mediaId, JSONArray materialArray, JSONArray accountArray, String userId) {
         for (int j = 0; j < materialArray.size(); j++) {
             String materialId = materialArray.getString(j);
             MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
@@ -110,12 +116,12 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                         continue;
                     }
                     touTiaoExecutorService.submit(new Runnable() {
-                                @Override
-                                public void run() {
+                        @Override
+                        public void run() {
                             try {
                                 log.info("头条文件多线程上传:{},accountId:{}", Thread.currentThread().getName(), accountId);
                                 if ("VIDEO".equals(materialInfo.getType())) {
-                                    fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), localUrl);
+                                    fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), localUrl, userId, materialInfo.getMaterialName());
 
                                 } else if ("IMAGE".equals(materialInfo.getType())) {
                                     fileInfoService.uploadImageToBytedance(String.valueOf(accountId), localUrl);
@@ -138,7 +144,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     }
 
 
-    private void kuaiShouUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+    private void kuaiShouUpload(String mediaId, JSONArray materialArray, JSONArray accountArray, String userId) {
         for (int j = 0; j < materialArray.size(); j++) {
             String materialId = materialArray.getString(j);
             MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
@@ -216,12 +222,16 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                                             videoGet.setPhotoId(photoId);
                                             videoGet.setSignature(signature);
                                             kuaiShouVideoGetService.saveOrUpdate(videoGet);
-                                            materialUploadImageService.uploadImage(videoGet.getId(), accountId, ctopOauthToken.getAccessToken());
+                                            materialUploadImageService.uploadImage(videoGet.getSignature(), accountId, ctopOauthToken.getAccessToken());
 
                                         }
                                         log.info("快手素材同步完成,accountId:{},code:{},返回信息:{}", accountId, materialInfo.getCode(), resultJson);
                                     } else {
                                         log.error("快手同步素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+                                        //  发送消息到上传人
+                                        UserAllocation allocation = userAllocationService.getByAccountId(accountId);
+                                        String message = messageTemplate.getMaterialSyncTemplate(allocation.getProjectName(), accountId, allocation.getAuthName(), materialInfo.getMaterialName(), resultJson.getString("message"));
+                                        sendMessageService.sendMessage(userId, message);
                                     }
                                 }
 
@@ -271,4 +281,6 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
         }
         return null;
     }
+
+
 }

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

@@ -1400,7 +1400,13 @@ public class BatchController {
             if (Check.isNull(requestJson)) {
                 throw new Exception("入参为空");
             }
-            JSONObject unitJson = batchService.updateUnit(requestJson);
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+            JSONObject unitJson = batchService.updateUnit(requestJson, oauthToken);
             result.setSuccess(true);
             result.setResult(unitJson);
         } catch (Exception e) {
@@ -1430,12 +1436,18 @@ public class BatchController {
             if (Check.isNull(unitIds)) {
                 throw new Exception("请选择需要修改的广告组");
             }
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
             JSONObject returnJson = new JSONObject();
             JSONArray failArr = new JSONArray();
             for (int i = 0; i < unitIds.size(); i++) {
                 Long unitId = unitIds.getLong(i);
                 requestJson.put("unitId", unitId);
-                JSONObject unitJson = batchService.updateUnit(requestJson);
+                JSONObject unitJson = batchService.updateUnit(requestJson, oauthToken);
                 if (!Check.isNull(unitJson)) {
                     Integer code = unitJson.getInteger("code");
                     if (code != 0) {
@@ -1476,7 +1488,18 @@ public class BatchController {
             if (Check.isNull(requestJson)) {
                 throw new Exception("入参为空");
             }
-            JSONObject creativeJson = batchService.updateCreative(requestJson);
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入需创建账号");
+            }
+
+
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+            JSONObject creativeJson = batchService.updateCreative(requestJson, oauthToken);
             result.setSuccess(true);
             result.setResult(creativeJson);
         } catch (Exception e) {
@@ -1873,4 +1896,98 @@ public class BatchController {
     }
 
 
+    /**
+     * 批量修改广告创意
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/batchUpdateCreative")
+    public Result<JSONObject> batchUpdateCreative(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参为空");
+            }
+
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入需创建账号");
+            }
+
+
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+
+            JSONArray creativeIds = requestJson.getJSONArray("creativeIds");
+            if (Check.isNull(creativeIds)) {
+                throw new Exception("请选择需要修改的广告创意");
+            }
+            JSONObject creativeJson = requestJson.getJSONObject("creativeJson");
+            JSONObject returnJson = new JSONObject();
+            JSONArray failArr = new JSONArray();
+            for (int i = 0; i < creativeIds.size(); i++) {
+                Long creativeId = creativeIds.getLong(i);
+                creativeJson.put("creativeId", creativeId);
+                JSONObject unitJson = batchService.updateCreative(creativeJson, oauthToken);
+                if (!Check.isNull(unitJson)) {
+                    Integer code = unitJson.getInteger("code");
+                    if (code != 0) {
+                        JSONObject failJson = new JSONObject();
+                        failJson.put("message", unitJson.get("message"));
+                        KuaiShouCreative creative = batchService.getCreativeInfo(requestJson.getLong("accountId"), creativeId);
+                        if (!Check.isNull(creative)) {
+                            failJson.put("creativeName", creative.getCreativeName());
+                        }
+                        failArr.add(failJson);
+                    }
+                }
+            }
+            returnJson.put("totalCount", creativeIds.size());
+            returnJson.put("failCount", failArr.size());
+            returnJson.put("failInfo", failArr);
+
+            result.setSuccess(true);
+            result.setResult(returnJson);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
+     * 获取可选的动态词包
+     *
+     * @param accountId
+     * @return
+     */
+    @GetMapping(value = "/creativeWord")
+    public Result<JSONArray> creativeWord(Long accountId) {
+        Result<JSONArray> result = new Result<>();
+        try {
+            if (Check.isNull(accountId)) {
+                throw new Exception("入参为空");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONArray creativeWordArr = iKuaishouInterfaceService.getCreativeWord(accountId, oauthToken.getAccessToken());
+            result.setResult(creativeWordArr);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
 }

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

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
@@ -109,7 +110,7 @@ public interface IBatchService {
      * @param requestJson
      * @return
      */
-    JSONObject updateUnit(JSONObject requestJson) throws Exception;
+    JSONObject updateUnit(JSONObject requestJson,CtopOauthToken token) throws Exception;
 
     /**
      * 修改广告创意
@@ -117,7 +118,7 @@ public interface IBatchService {
      * @param requestJson
      * @return
      */
-    JSONObject updateCreative(JSONObject requestJson) throws Exception;
+    JSONObject updateCreative(JSONObject requestJson, CtopOauthToken token) throws Exception;
 
 
     /**

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

@@ -494,6 +494,14 @@ public interface IKuaishouInterfaceService {
      */
     List<ConvertVo> getConvertList(Long accountId, String accessToken, Integer type);
 
+    /**
+     * 获取可选的动态词包
+     *
+     * @param accountId
+     * @param accessToken
+     * @return
+     */
+    JSONArray getCreativeWord(Long accountId, String accessToken);
 }
 
 

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

@@ -1001,15 +1001,10 @@ public class BatchServiceImpl implements IBatchService {
      * @return
      */
     @Override
-    public JSONObject updateUnit(JSONObject requestJson) throws Exception {
+    public JSONObject updateUnit(JSONObject requestJson, CtopOauthToken token) throws Exception {
 
-        Long accountId = requestJson.getLong("accountId");
-        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
-        if (Check.isNull(oauthToken)) {
-            throw new Exception("未获取到账户信息");
-        }
         JSONObject unitJson = new JSONObject();
-        unitJson.put("advertiser_id", accountId);
+        unitJson.put("advertiser_id", token.getAccountId());
 
         Long unitId = requestJson.getLong("unitId");
         if (Check.isNull(unitId)) {
@@ -1186,7 +1181,7 @@ public class BatchServiceImpl implements IBatchService {
 
         unitJson.put("target", targetJson);
 
-        JSONObject returnJson = updateService.updateUnit(oauthToken.getAccessToken(), unitJson);
+        JSONObject returnJson = updateService.updateUnit(token.getAccessToken(), unitJson);
         return returnJson;
     }
 
@@ -1197,22 +1192,14 @@ public class BatchServiceImpl implements IBatchService {
      * @return
      */
     @Override
-    public JSONObject updateCreative(JSONObject requestJson) throws Exception {
+    public JSONObject updateCreative(JSONObject requestJson, CtopOauthToken token) throws Exception {
         if (Check.isNull(requestJson)) {
             throw new Exception("入参为空");
         }
 
-        Long accountId = requestJson.getLong("accountId");
-        if (Check.isNull(accountId)) {
-            throw new Exception("请输入需创建账号");
-        }
-        JSONObject creativeJson = new JSONObject();
-        creativeJson.put("advertiser_id", accountId);
 
-        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
-        if (Check.isNull(oauthToken)) {
-            throw new Exception("未获取到账户信息");
-        }
+        JSONObject creativeJson = new JSONObject();
+        creativeJson.put("advertiser_id", token.getAccountId());
 
         Long creativeId = requestJson.getLong("creativeId");
         if (Check.isNull(creativeId)) {
@@ -1269,7 +1256,7 @@ public class BatchServiceImpl implements IBatchService {
         if (!Check.isNull(requestJson.get("impressionUrl"))) {
             creativeJson.put("impression_url", requestJson.get("impressionUrl"));
         }
-        JSONObject returnJson = updateService.updateCreative(oauthToken.getAccessToken(), creativeJson);
+        JSONObject returnJson = updateService.updateCreative(token.getAccessToken(), creativeJson);
 
         return returnJson;
     }

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

@@ -643,7 +643,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     if (!Check.isNull(data)) {
 
                         try {
-                            Thread.sleep(500);
+                            Thread.sleep(200);
                             interfaceService.getCreativeByCreativeId(accessToken, creativeJson.getLong("advertiser_id"), data.getLong("creative_id"));
                         } catch (InterruptedException e) {
                             e.printStackTrace();

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

@@ -1287,13 +1287,18 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 }
             }
             if (!Check.isNull(groups)) {
-                groupMapper.replaceBatch(groups);
+                try {
+                    Thread.sleep(200L);
+                    groupMapper.replaceBatch(groups);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+
             }
         }
     }
 
 
-
     @Override
     public void getCreativeList(CtopOauthToken token, Date startDate, Date endDate) {
         getCreativeListByPage(token.getAccessToken(), token.getAccountId(), startDate, endDate, 1);
@@ -3099,4 +3104,28 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         return convertVoList;
     }
 
+    @Override
+    public JSONArray getCreativeWord(Long accountId, String accessToken) {
+
+        try {
+            log.info("获取动态词包:accountId:{}", accountId);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_WORD;
+            Map<String, String> headers = new HashMap<>();
+            headers.put("Access-Token", accessToken);
+            headers.put("Content-Type", "application/json");
+            JSONObject requestJson = new JSONObject();
+            requestJson.put("advertiser_id", accountId);
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                return resultJson.getJSONArray("data");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
 }