소스 검색

系统改版

yumeng 5 년 전
부모
커밋
21be43a323
22개의 변경된 파일510개의 추가작업 그리고 52개의 파일을 삭제
  1. 12 0
      jeecg-boot-module-system/src/main/java/org/jeecg/JeecgApplication.java
  2. 7 7
      jeecg-boot-module-system/src/main/java/org/jeecg/JeecgOneToMainUtil.java
  3. 34 1
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/controller/MaterialInfoController.java
  4. 75 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialUploadController.java
  5. 37 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java
  6. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/Project.java
  7. 1 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouMaterialsLoadJob.java
  8. 2 13
      module-common/pom.xml
  9. 7 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/MaterialInfo.java
  10. 7 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java
  11. 3 1
      module-common/src/main/java/cn/com/ctop/common/module/mapper/MaterialInfoMapper.java
  12. 18 1
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MaterialInfoMapper.xml
  13. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialInfoService.java
  14. 18 8
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java
  15. 1 1
      module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java
  16. 4 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/LoadFileUtil.java
  17. 17 0
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/IMaterialUploadService.java
  18. 239 0
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java
  19. 5 13
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouController.java
  20. 4 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouImageGet.java
  21. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  22. 15 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/JeecgApplication.java

@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.MultipartConfigFactory;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
@@ -12,6 +13,7 @@ import org.springframework.core.env.Environment;
 import org.springframework.web.client.RestTemplate;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
+import javax.servlet.MultipartConfigElement;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
@@ -45,4 +47,14 @@ public class JeecgApplication {
         return new RestTemplate();
     }
 
+    @Bean
+    public MultipartConfigElement multipartConfigElement() {
+        MultipartConfigFactory factory = new MultipartConfigFactory();
+        //  单个数据大小
+        factory.setMaxFileSize("10240KB"); // KB,MB
+        /// 总上传数据大小
+        factory.setMaxRequestSize("102400KB");
+        return factory.createMultipartConfig();
+    }
+
 }

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

@@ -23,33 +23,33 @@ public class JeecgOneToMainUtil {
 		//第一步:设置主表配置
 		MainTableVo mainTable = new MainTableVo();
         //表名
-        mainTable.setTableName("sys_category");
+        mainTable.setTableName("ctop_material_info");
         //实体名
-        mainTable.setEntityName("Category");
+        mainTable.setEntityName("MaterialInfo");
         //包名
         mainTable.setEntityPackage("ctop");
         //描述
-        mainTable.setFtlDescription("主分类信息");
+        mainTable.setFtlDescription("素材库");
 		
 		//第二步:设置子表集合配置
 		List<SubTableVo> subTables = new ArrayList<SubTableVo>();
 		//[1].子表一
 		SubTableVo po = new SubTableVo();
         //表名
-        po.setTableName("sys_category");
+        po.setTableName("ctop_material_ascription");
         //实体名
-        po.setEntityName("Category");
+        po.setEntityName("MaterialAscription");
         //包名
         po.setEntityPackage("ctop");
         //描述
-        po.setFtlDescription("子分类信息");
+        po.setFtlDescription("素材归属");
 		//子表外键参数配置
 		/*说明: 
 		 * a) 子表引用主表主键ID作为外键,外键字段必须以_ID结尾;
 		 * b) 主表和子表的外键字段名字,必须相同(除主键ID外);
 		 * c) 多个外键字段,采用逗号分隔;
 		*/
-        po.setForeignKeys(new String[]{"pid"});
+        po.setForeignKeys(new String[]{"material_id"});
 		subTables.add(po);
 		mainTable.setSubTables(subTables);
 		

+ 34 - 1
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/controller/MaterialInfoController.java

@@ -1,9 +1,12 @@
-package cn.com.ctop.manage.modules.material.controller;
+package org.jeecg.modules.ctop.controller;
 
 
 import cn.com.ctop.common.module.entity.MaterialInfo;
 import cn.com.ctop.common.module.service.IMaterialInfoService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.FileEntity;
+import cn.com.ctop.common.module.utils.FileUploadTool;
+import cn.com.ctop.common.module.utils.LoadFileUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -35,6 +38,7 @@ import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.text.ParseException;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -60,6 +64,26 @@ public class MaterialInfoController {
     }
 
 
+    @RequestMapping(value = "/getMd5", consumes = "multipart/form-data;charset=utf-8")
+    public String getMd5(@RequestParam("multipartFile") MultipartFile multipartFile, HttpServletRequest request) throws IOException {
+
+        Map<String, Object> returnMap = new HashMap<>();
+        try {
+            String savaPath = "D:\\tets1\\image";
+            FileUploadTool fileUploadTool = new FileUploadTool();
+            FileEntity entity;
+            entity = fileUploadTool.createFile(multipartFile, request, savaPath);
+
+            String path = entity.getPath();
+            String md5 = LoadFileUtil.getMD5(path);
+            return md5;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
     @GetMapping(value = "/getDetail")
     public JSONObject getDetail(String materialId) {
 
@@ -77,6 +101,8 @@ public class MaterialInfoController {
      * @param req
      * @return
      */
+
+
     @AutoLog(value = "素材信息-分页列表查询")
     @ApiOperation(value = "素材信息-分页列表查询", notes = "素材信息-分页列表查询")
     @GetMapping(value = "/list")
@@ -88,6 +114,12 @@ public class MaterialInfoController {
         Result<IPage<MaterialInfo>> result = new Result<>();
         Object createTime = materialInfo.getCreateTime();
         materialInfo.setCreateTime(null);
+        if (!Check.isNull(materialInfo.getUserId())) {
+            String roleCode = materialInfoService.getRoleCodeByUserId(materialInfo.getUserId());
+            if ("admin".equals(roleCode) || "operator".equals(roleCode) || "kuaishouOperationManager".equals(roleCode)) {
+                materialInfo.setUserId(null);
+            }
+        }
         QueryWrapper<MaterialInfo> queryWrapper = QueryGenerator.initQueryWrapper(materialInfo, req.getParameterMap());
         if (!Check.isNull(createTime)) {
             try {
@@ -148,6 +180,7 @@ public class MaterialInfoController {
         }
 
         return result;
+
     }
 
     /**

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

@@ -0,0 +1,75 @@
+package org.jeecg.modules.ctop.controller;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.manage.modules.material.service.IMaterialUploadService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 素材归属标
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-11-23
+ */
+@Slf4j
+@Api(tags = "素材归属标")
+@RestController
+@RequestMapping("/ctop/materialUpload")
+public class MaterialUploadController {
+
+    @Autowired
+    private IMaterialUploadService materialUploadService;
+
+    @PostMapping(value = "/uploadAccount")
+    public Map<String, Object> uploadAccount(@RequestBody JSONObject json) {
+        Map<String, Object> returnMap = new HashMap<>();
+        String mediaId = json.getString("mediaId");
+        JSONArray materialArray = json.getJSONArray("materialArray");
+        JSONArray accountArray = json.getJSONArray("accountArray");
+        try {
+            if (Check.isNull(mediaId)) {
+                throw new Exception("请选择项目媒体类型");
+            }
+            if (Check.isNull(materialArray) || Check.isNull(accountArray)) {
+                throw new Exception("请选择账号或素材");
+            }
+            Thread thread = new Thread() {
+                @Override
+                public void run() {
+                    try {
+                        materialUploadService.uploadAccount(mediaId, materialArray, accountArray);
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            };
+            thread.start();
+
+            returnMap.put("success", true);
+            returnMap.put("message", "开始上传文件");
+            returnMap.put("code", 0);
+
+        } catch (Exception e) {
+            returnMap.put("success", false);
+            returnMap.put("message", e.getMessage());
+        }
+
+
+        return returnMap;
+
+    }
+
+
+}

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

@@ -1,7 +1,9 @@
 package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.StringUtils;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -16,6 +18,8 @@ import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.ctop.entity.Project;
+import org.jeecg.modules.ctop.service.IProjectService;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -38,9 +42,10 @@ import java.util.Map;
 
 /**
  * 用户分配
+ *
  * @author jeecg-boot
- * @date 2019-08-08
  * @version V1.0
+ * @date 2019-08-08
  */
 @Slf4j
 @Api(tags = "用户分配")
@@ -49,6 +54,37 @@ import java.util.Map;
 public class UserAllocationController {
     @Autowired
     private IUserAllocationService userAllocationService;
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private IProjectService projectService;
+
+
+    @GetMapping(value = "/getAccountList")
+    public Result<List<UserAllocation>> queryPageList(String userId, Long projectId) {
+        Result<List<UserAllocation>> result = new Result<>();
+        try {
+
+            QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("user_id", userId);
+            queryWrapper.eq("project_id", projectId);
+            Project project = projectService.getById(projectId);
+            if (!Check.isNull(project)) {
+                queryWrapper.eq("media_id", project.getMediaId());
+            }
+
+            List<UserAllocation> userAllocations = userAllocationMapper.selectList(queryWrapper);
+            result.setSuccess(true);
+            result.setResult(userAllocations);
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.success("查询失败");
+        }
+
+        return result;
+
+    }
+
 
     /**
      * 分页列表查询

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

@@ -55,7 +55,7 @@ public class Project {
      */
     @Excel(name = "创建人", width = 15)
     @ApiModelProperty(value = "创建人")
-    private String createBy;
+    private String userId;
     /**
      * 负责人id
      */

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

@@ -42,6 +42,7 @@ public class KuaishouMaterialsLoadJob implements Job {
                         kuaishouInterfaceService.getCreativeList(token);
                         //2:获取全量视频素材数据
                         kuaishouInterfaceService.getVideoList(token);
+
                     } catch (Exception e) {
                         e.printStackTrace();
                     } finally {

+ 2 - 13
module-common/pom.xml

@@ -68,17 +68,6 @@
         </dependency>
 
 
-        <!--<dependency>
-            <groupId>org.jeecgframework.boot</groupId>
-            <artifactId>jeecg-boot-base-common</artifactId>
-            <version>2.0.2</version>
-        </dependency>-->
-        <!--<dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-csv</artifactId>
-            <version>1.5</version>
-            <scope>compile</scope>
-        </dependency>-->
         <dependency>
             <groupId>net.sourceforge.javacsv</groupId>
             <artifactId>javacsv</artifactId>
@@ -87,7 +76,7 @@
 
     </dependencies>
     <build>
-
+<!--
         <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>
@@ -96,7 +85,7 @@
                     <includeSystemScope>true</includeSystemScope>
                 </configuration>
             </plugin>
-        </plugins>
+        </plugins>-->
 
 
         <resources>

+ 7 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/MaterialInfo.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.common.module.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -97,6 +98,12 @@ public class MaterialInfo {
     private String refuseFile;
 
     /**
+     * 创意文案
+     */
+    private String creativeCopywriter;
+
+
+    /**
      * createTime
      */
     @ApiModelProperty(value = "createTime")

+ 7 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java

@@ -59,7 +59,14 @@ public class UserAllocation {
     @ApiModelProperty(value = "广告主ID")
     private String advertiserId;
 
+    /**
+     * 项目id
+     */
     private Long projectId;
+
+    /**
+     * 项目名称
+     */
     private String projectName;
 
     /**

+ 3 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/MaterialInfoMapper.java

@@ -17,5 +17,7 @@ public interface MaterialInfoMapper extends BaseMapper<MaterialInfo> {
 
     String selectUserNameById(@Param("auditorId") String auditorId);
 
-    String selectCountByMap(@Param("requestMap") Map<String, Object> requestMap);
+    Integer selectCountByMap(Map<String, Object> requestMap);
+
+    String getRoleCodeByUserId(@Param("userId") String userId);
 }

+ 18 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MaterialInfoMapper.xml

@@ -7,7 +7,7 @@
     </select>
 
 
-    <select id="selectCountByMap" parameterType="java.util.Map" resultType="java.lang.String">
+    <select id="selectCountByMap" parameterType="java.util.Map" resultType="java.lang.Integer">
 
         select count(1)
         from ctop_material_info
@@ -23,5 +23,22 @@
 
     </select>
 
+    <select id="getRoleCodeByUserId" resultType="java.lang.String">
+   SELECT
+    role_code
+    FROM
+    sys_role
+    WHERE
+    id = (
+    SELECT
+    t2.role_id
+    FROM
+    sys_user t1
+    LEFT JOIN sys_user_role t2 ON t1.id = t2.user_id
+    WHERE
+    t1.id = #{userId,jdbcType=VARCHAR}
+    )
+    </select>
+
 
 </mapper>

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

@@ -23,4 +23,6 @@ public interface IMaterialInfoService extends IService<MaterialInfo> {
     JSONObject getDetail(String materialId);
 
     JSONObject report(String userId);
+
+    String getRoleCodeByUserId(String userId);
 }

+ 18 - 8
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -72,7 +72,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
     }
 
     public boolean imgLocation(String fileName) throws IOException {
-        String reg = "(mp4|flv|avi|rm|rmvb|wmv)";
+        String reg = "(mp4|flv|avi|rm|rmvb|wmv|MP4)";
         Pattern p = Pattern.compile(reg);
         return p.matcher(fileName).find();
     }
@@ -96,8 +96,13 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
             MaterialInfo info = new MaterialInfo();
             info.setId(jsonObject.getString("code"));
             info.setCode(jsonObject.getString("code"));
-            info.setWatermarkUrl("https:" + jsonObject.getString("watermarkUrl"));
-            info.setUrl("https:" + jsonObject.getString("url"));
+
+            if (!Check.isNull(jsonObject.getString("watermarkUrl"))) {
+                info.setWatermarkUrl("https:" + jsonObject.getString("watermarkUrl"));
+            }
+            if (!Check.isNull(jsonObject.getString("url"))) {
+                info.setUrl("https:" + jsonObject.getString("url"));
+            }
             info.setUserId(jsonObject.getString("userId"));
             info.setProjectId(jsonObject.getLong("projectId"));
             info.setWatermarkCode(jsonObject.getString("watermarkCode"));
@@ -122,7 +127,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
                 materialAscription.setMaterialId(info.getId());
                 materialAscription.setClipId(ascription.getString("clipId")); // 剪辑人
                 materialAscription.setShotId(ascription.getString("shotId")); // 拍摄人id
-                materialAscription.setPlaneId(ascription.getString("planId")); // 策划id
+                materialAscription.setPlanId(ascription.getString("planId")); // 策划id
                 materialAscription.setPlaneId(ascription.getString("planeId")); //平面id
                 materialAscriptionMapper.deleteByMap(deleteMap);
                 int i = materialAscriptionMapper.insert(materialAscription);
@@ -213,19 +218,19 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
             Map<String, Object> requestMap = new HashMap<>();
             requestMap.put("userId", userId);
 
-            String totalCount = materialInfoMapper.selectCountByMap(requestMap);
+            Integer totalCount = materialInfoMapper.selectCountByMap(requestMap);
             json.put("total", totalCount);
 
             requestMap.put("status", 0);
-            String waitAudit = materialInfoMapper.selectCountByMap(requestMap);
+            Integer waitAudit = materialInfoMapper.selectCountByMap(requestMap);
             json.put("waitAudit", waitAudit);
 
             requestMap.put("status", 1);
-            String passAudit = materialInfoMapper.selectCountByMap(requestMap);
+            Integer passAudit = materialInfoMapper.selectCountByMap(requestMap);
             json.put("passAudit", passAudit);
 
             requestMap.put("status", 2);
-            String refuseAudit = materialInfoMapper.selectCountByMap(requestMap);
+            Integer refuseAudit = materialInfoMapper.selectCountByMap(requestMap);
             json.put("refuseAudit", refuseAudit);
         } catch (Exception e) {
             e.printStackTrace();
@@ -235,6 +240,11 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         return json;
     }
 
+    @Override
+    public String getRoleCodeByUserId(String userId) {
+        return materialInfoMapper.getRoleCodeByUserId(userId);
+    }
+
 
     @Autowired
     private MaterialParameterMapper materialParameterMapper;

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

@@ -74,7 +74,7 @@ public class KuaishouInterfaceConstant {
     /**
      * 图片文件上传
      */
-    public static final String IMAGE_UPLOAD = "/rest/openapi/v1/file/ad/image/upload";
+    public static final String IMAGE_UPLOAD = "/rest/openapi/v2/file/ad/image/upload";
     /**
      * 创建应用
      */

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/LoadFileUtil.java

@@ -105,5 +105,9 @@ public class LoadFileUtil {
         return DigestUtils.md5Hex(new FileInputStream(path));
     }
 
+    public static String getMD5ByFile(FileInputStream inputStream) throws IOException {
+        return DigestUtils.md5Hex(inputStream);
+    }
+
 
 }

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

@@ -0,0 +1,17 @@
+package cn.com.ctop.manage.modules.material.service;
+
+import com.alibaba.fastjson.JSONArray;
+
+import java.io.IOException;
+
+public interface IMaterialUploadService {
+
+    /**
+     * 同步素材到账号下
+     *
+     * @param mediaId
+     * @param materialArray
+     * @param accountArray
+     */
+    void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray) throws IOException;
+}

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

@@ -0,0 +1,239 @@
+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.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
+import cn.com.ctop.common.module.service.IFileInfoService;
+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.service.IKuaishouInterfaceService;
+import cn.com.ctop.manage.modules.material.service.IMaterialUploadService;
+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.core.io.FileSystemResource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Slf4j
+@Service
+public class MaterialUploadServiceImpl implements IMaterialUploadService {
+    static ExecutorService executorService = Executors.newFixedThreadPool(3);
+
+
+    @Autowired
+    private CtopOauthTokenMapper oauthTokenMapper;
+    @Autowired
+    private MaterialInfoMapper materialInfoMapper;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private IFileInfoService fileInfoService;
+
+
+    /**
+     * 同步素材到账号下
+     *
+     * @param mediaId
+     * @param materialArray
+     * @param accountArray
+     */
+
+    @Override
+    public void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+        try {
+            if ("2".equals(mediaId)) {
+                this.KuaiShouUpload(mediaId, materialArray, accountArray);
+            } else if ("1".equals(mediaId)) {
+                this.TouTiaoUpload(mediaId, materialArray, accountArray);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+
+    private void TouTiaoUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+        for (int j = 0; j < materialArray.size(); j++) {
+            String materialId = materialArray.getString(j);
+            MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
+            if (Check.isNull(materialInfo)) {
+                continue;
+            }
+            try {
+
+                for (int i = 0; i < accountArray.size(); i++) {
+                    Long accountId = accountArray.getLong(i);
+                    QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
+                    tokenQueryWrapper.eq("account_id", accountId);
+                    tokenQueryWrapper.eq("media_id", mediaId);
+                    tokenQueryWrapper.orderByDesc("create_time");
+                    tokenQueryWrapper.last("limit 1");
+                    CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(tokenQueryWrapper);
+                    if (Check.isNull(ctopOauthToken)) {
+                        continue;
+                    }
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                System.err.println(Thread.currentThread().getName());
+                                if ("VIDEO".equals(materialInfo.getType())) {
+                                    fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), materialInfo.getUrl());
+
+                                } else if ("IMAGE".equals(materialInfo.getType())) {
+                                    fileInfoService.uploadImageToBytedance(String.valueOf(accountId), materialInfo.getUrl());
+                                }
+
+
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    });
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+
+        }
+
+
+    }
+
+
+    private void KuaiShouUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+        for (int j = 0; j < materialArray.size(); j++) {
+            String materialId = materialArray.getString(j);
+            MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
+            if (Check.isNull(materialInfo)) {
+                continue;
+            }
+            try {
+                String localUrl = LoadFileUtil.downLoadFromUrl(materialInfo.getUrl(), "D:\\tets1\\video");
+                FileSystemResource resource = new FileSystemResource(new File(localUrl));
+                Map<String, String> headerMap = new HashMap<>();
+                headerMap.put("Content-Type", "multipart/form-data");
+                JSONObject requestJson = new JSONObject();
+                requestJson.put("file", resource);
+                requestJson.put("signature", materialInfo.getCode());
+                for (int i = 0; i < accountArray.size(); i++) {
+                    Long accountId = accountArray.getLong(i);
+                    QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
+                    tokenQueryWrapper.eq("account_id", accountId);
+                    tokenQueryWrapper.eq("media_id", mediaId);
+                    tokenQueryWrapper.orderByDesc("create_time");
+                    tokenQueryWrapper.last("limit 1");
+                    CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(tokenQueryWrapper);
+                    if (Check.isNull(ctopOauthToken)) {
+                        continue;
+                    }
+                    requestJson.put("advertiser_id", accountId);
+                    headerMap.put("Access-Token", ctopOauthToken.getAccessToken());
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                System.err.println(Thread.currentThread().getName());
+                                String url = "";
+                                if ("VIDEO".equals(materialInfo.getType())) {
+                                    url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_UPLOAD;
+
+                                } else if ("IMAGE".equals(materialInfo.getType())) {
+                                    url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
+                                    requestJson.put("type", "2");
+                                    requestJson.put("upload_type", "1");
+                                }
+
+                                String result = exceptInfoForRestTemplate(url, 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)) {
+                                            if ("IMAGE".equals(materialInfo.getType())) {
+                                                kuaishouInterfaceService.imageGet(accountId, ctopOauthToken.getAccessToken(), dataJson.getString("image_token"));
+                                            } else if ("VIDEO".equals(materialInfo.getType())) {
+                                                kuaishouInterfaceService.videoGet(accountId, ctopOauthToken.getAccessToken(), dataJson.getString("photo_id"), dataJson.getString("signature"));
+                                            }
+                                        }
+
+                                        log.info("素材同步完成,accountId:{},code:{}", accountId, materialInfo.getCode());
+                                    } else {
+                                        log.error("同步素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+                                    }
+                                }
+
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    });
+
+                }
+                /*boolean isTrue = LoadFileUtil.delFile(localUrl);
+                if (isTrue) {
+                    log.info("删除本地缓存素材成功,code:{}", materialInfo.getCode());
+                }*/
+
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+
+        }
+
+
+    }
+
+
+
+
+    @Autowired
+    private RestTemplate rest;
+
+    private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
+        try {
+            MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
+            if (!Check.isNullMap(paramMap)) {
+                for (String key : paramMap.keySet()) {
+                    param.add(key, paramMap.get(key));
+                }
+                HttpHeaders headers = new HttpHeaders();
+                if (!Check.isNullMap(headerMap)) {
+                    for (String key : headerMap.keySet()) {
+                        headers.add(key, headerMap.get(key));
+                    }
+                }
+                HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
+                ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
+                return responseEntity.getBody();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 5 - 13
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouController.java

@@ -2,6 +2,10 @@ package cn.com.ctop.kuaishou.modules.batch.controller;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.FileEntity;
+import cn.com.ctop.common.module.utils.FileUploadTool;
+import cn.com.ctop.common.module.utils.LoadFileUtil;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -117,24 +121,11 @@ public class KuaiShouController {
     }
 
 
-    @RequestMapping("/video/get")
-    public void videoGet() {
 
-        String accessToken = "360d43b49553684a011d6607322582b1";
-        Long advertiserId = 23212L;
-        String photoId = "5249789805735604135";
-        /*FileUploadTool fileUploadTool = new FileUploadTool();
-        FileEntity entity = new FileEntity();
-
-        entity = fileUploadTool.createFile(multipartFile, request);
-        System.err.println(entity);*/
 
 
-        kuaishouInterfaceService.videoGet(advertiserId, accessToken, photoId);
 
 
-    }
-
     @RequestMapping("/image/get")
     public void imageGet() {
 
@@ -243,4 +234,5 @@ public class KuaiShouController {
     }
 
 
+
 }

+ 4 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouImageGet.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.batch.entity;
 
+import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -29,9 +30,9 @@ public class KuaiShouImageGet {
     /**
      * id
      */
-    @TableId
+    @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
-    private String id;
+    private Long id;
     /**
      * 账户ID
      */
@@ -68,6 +69,7 @@ public class KuaiShouImageGet {
     @Excel(name = "图片格式", width = 15)
     @ApiModelProperty(value = "图片格式")
     private String format;
+    private String signature;
     /**
      * 图片 token
      */

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

@@ -151,7 +151,7 @@ public interface IKuaishouInterfaceService {
      * @param accessToken
      * @param photoId
      */
-    void videoGet(Long advertiserId, String accessToken, String photoId);
+    void videoGet(Long advertiserId, String accessToken, String photoId, String signature);
 
     /**
      * 获取图片信息

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

@@ -1943,7 +1943,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * @param accessToken
      */
     @Override
-    public void videoGet(Long advertiserId, String accessToken, String photoId) {
+    public void videoGet(Long advertiserId, String accessToken, String photoId, String signature) {
         try {
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_GET;
             JSONObject param = new JSONObject();
@@ -1966,12 +1966,15 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             if (!Check.isNull(dataJson)) {
                                 KuaiShouVideoGet videoGet = new KuaiShouVideoGet();
                                 videoGet.setAccountId(advertiserId);
+                                videoGet.setId(advertiserId + photoId);
                                 videoGet.setWidth(dataJson.getInteger("width"));
                                 videoGet.setHeight(dataJson.getInteger("height"));
                                 videoGet.setUrl(dataJson.getString("url"));
                                 videoGet.setPhotoId(dataJson.getString("photo_id"));
                                 videoGet.setCoverUrl(dataJson.getString("cover_url"));
-                                videoGetMapper.insert(videoGet);
+                                videoGet.setSignature(signature);
+                                kuaiShouVideoGetService.saveOrUpdate(videoGet);
+
                             }
                         }
                     }
@@ -2017,7 +2020,14 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         imageGet.setHeight(dataJson.getLong("height"));
                         imageGet.setSize(dataJson.getLong("size"));
                         imageGet.setFormat(dataJson.getString("format"));
+                        String signature = dataJson.getString("signature");
+                        imageGet.setSignature(signature);
                         imageGet.setImageToken(dataJson.getString("image_token"));
+                        Map<String, Object> deleteMap = new HashMap<>();
+                        deleteMap.put("account_id", advertiserId);
+                        deleteMap.put("signature", signature);
+                        imageGetMapper.deleteByMap(deleteMap);
+
                         imageGetMapper.insert(imageGet);
                     }
                 } else {
@@ -2115,11 +2125,14 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 log.error("下载文件到本地文件夹失败,filePath:{},accountId:{}", filePath, advertiserId);
                 throw new Exception("下载文件到本地失败");
             }
+            String signature = LoadFileUtil.getMD5(localUrl);
             Long startTime = System.currentTimeMillis();
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
             JSONObject requestJson = new JSONObject();
             requestJson.put("advertiser_id", advertiserId);
+            requestJson.put("signature", signature);
             requestJson.put("type", type);
+            requestJson.put("upload_type", 1);
             Map<String, String> headerMap = new HashMap<String, String>();
             headerMap.put("Content-Type", "multipart/form-data");
             headerMap.put("Access-Token", accessToken);