Parcourir la source

Merge remote-tracking branch 'origin/master'

syh il y a 5 ans
Parent
commit
d54125a045
13 fichiers modifiés avec 275 ajouts et 205 suppressions
  1. 7 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java
  2. 9 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaiShouAccountReportCtrl.java
  3. 6 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KsVideoReportMapper.xml
  4. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaiShouYiCheReportMapper.xml
  5. 18 8
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportDailyAccountMapper.xml
  6. 70 122
      module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/FileUtil.java
  7. 3 8
      module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/controller/ShiwanFileUploadController.java
  8. 4 0
      module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/mapper/xml/ShiwanFileUploadMapper.xml
  9. 124 48
      module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/service/ShiwanFileUploadServiceImpl.java
  10. 2 1
      module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/service/impl/IShiwanFileUploadService.java
  11. 9 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAccountReportCtrl.java
  12. 11 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceAccountReportMapper.xml
  13. 11 11
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceVideoReportMapper.xml

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

@@ -520,6 +520,13 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     returnMap.put("code", -1);
                     returnMap.put("success", false);
                     returnMap.put("message", resultJson.getString("message"));
+                    if (resultJson.getString("message").equals("该账户下创意不存在")) {
+                        Map<String, Object> deleteMap = new HashMap<>();
+                        deleteMap.put("creative_id", creativeId);
+                        creativeMapper.deleteByMap(deleteMap);
+                    }
+
+
                 }
             } else {
                 log.error("修改广告创意返回结果为空,advertiserId:{},creativeId:{}", advertiserId, creativeId);

+ 9 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaiShouAccountReportCtrl.java

@@ -51,6 +51,9 @@ public class KuaiShouAccountReportCtrl {
         String mediaId = requestBody.getString("mediaId");
         BigDecimal discount = requestBody.getBigDecimal("discount");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
+        if(accounts.isEmpty()){
+            return resultBody;
+        }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
         try {
@@ -80,6 +83,9 @@ public class KuaiShouAccountReportCtrl {
         String mediaId = requestBody.getString("mediaId");
         BigDecimal discount = requestBody.getBigDecimal("discount");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
+        if(accounts.isEmpty()){
+            return result;
+        }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
         int hour= requestBody.getInteger("hour");
@@ -117,6 +123,9 @@ public class KuaiShouAccountReportCtrl {
         columns.add(1,"authName");
         String mediaId = requestBody.getString("mediaId");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
+        if(accounts.isEmpty()){
+            return;
+        }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
         String target= requestBody.getString("target");

+ 6 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KsVideoReportMapper.xml

@@ -6,9 +6,9 @@
         SELECT * from (SELECT
         t1.signature,
         t1.photo_url as url,
-        (SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.clip_id=u.id where t3.material_id=t1.signature limit 1) AS clip,
-        (SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.shot_id=u.id where t3.material_id=t1.signature limit 1) AS shot,
-        (SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.plan_id=u.id where t3.material_id=t1.signature limit 1) AS plan,
+        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.clip_id=u.id where t3.material_id=t1.signature limit 1),'') AS clip,
+        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.shot_id=u.id where t3.material_id=t1.signature limit 1),'') AS shot,
+        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.plan_id=u.id where t3.material_id=t1.signature limit 1),'') AS plan,
         t1.cover_url as converUrl,
         t2.material_name AS materialName,
         (SELECT project_name FROM ctop_project t4 WHERE t4.id = t3.project_id) AS projectName,
@@ -30,9 +30,9 @@
         </if>
         GROUP BY t1.signature
         ) t
-        WHERE (t.clip LIKE '%${clip}%' or t.clip is null)
-        AND (t.shot LIKE '%${shot}%' or t.shot is null)
-        AND (t.plan LIKE '%${plan}%' or t.plan is null)
+        WHERE (t.clip LIKE '%${clip}%')
+        AND (t.shot LIKE '%${shot}%')
+        AND (t.plan LIKE '%${plan}%')
         ORDER BY ${target} ${order}
     </select>
 

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaiShouYiCheReportMapper.xml

@@ -444,7 +444,7 @@
             and t1.stat_date = #{statDate}
         </if>
         ) t2
-        WHERE t2.campaignName in(581,582,583,584,552,553,554,680,681,845,846,847,848,849,850,1070,1071,1072,1066,1069,1064)
+        WHERE t2.campaignName in(68,441,469,470,481,581,582,583,584,552,553,554,680,681,845,846,847,848,849,850,1070,1071,1072,1066,1069,1063,1064)
 
     </select>
 

+ 18 - 8
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportDailyAccountMapper.xml

@@ -545,7 +545,7 @@
         a.account_id as 'accountId',
         b.auth_name as 'authName',
         b.project_id as 'projectId',
-        (select  project_name from ctop_project where  id = b.project_id) as 'projectName',
+        (select project_name from ctop_project where id = b.project_id) as 'projectName',
         round(sum(a.charge),2) as 'charge',
         sum(a.photo_show) as 'photoShow', -- 封面曝光数
         sum(a.photo_click) as 'photoClick', -- 封面点击数
@@ -595,7 +595,7 @@
         ) as 'eventNextDayStayCost' -- 次日留存成本
         from
         ctop_kuaishou_report_daily_account a
-        left join  ctop_user_allocation b on a.account_id = b.account_id
+        left join ctop_user_allocation b on a.account_id = b.account_id
         where
         a.stat_date &gt;= #{startDate}
         and
@@ -637,6 +637,11 @@
         ) as 'responsibleName',
         (
         select realname from sys_user where id = (
+        select sale_id from ctop_project where id = b.project_id
+        )
+        ) as 'saleName',
+        (
+        select realname from sys_user where id = (
         select design_responsible_id from ctop_project where id = b.project_id
         )
         ) as 'designResponsibleName',
@@ -702,7 +707,7 @@
                  open="(" close=")">
             #{item}
         </foreach>
-        group by b.project_id  order by sum(a.charge) desc
+        group by b.project_id order by sum(a.charge) desc
     </select>
 
     <!-- 计划汇总 -->
@@ -713,7 +718,7 @@
         #{yn} as 'yn',
         concat(#{startDate}, '~' ,#{endDate}) as 'statDate',
         b.project_id as 'projectId',
-        (select  project_name  from ctop_project where  id = b.project_id) as 'projectName',
+        (select project_name from ctop_project where id = b.project_id) as 'projectName',
         b.auth_name as 'authName',
         a.account_id as 'accountId',
         a.campaign_id as 'campaignId', -- 计划id
@@ -809,7 +814,7 @@
         #{yn} as 'yn',
         concat(#{startDate}, '~' ,#{endDate}) as 'statDate',
         b.project_id as 'projectId',
-        (select  project_name  from ctop_project where  id = b.project_id) as 'projectName',
+        (select project_name from ctop_project where id = b.project_id) as 'projectName',
         a.account_id as 'accountId',
         b.auth_name as 'authName',
         a.campaign_id as 'campaignId', -- 计划id
@@ -991,7 +996,7 @@
         #{yn} as 'yn',
         concat(#{startDate}, '~' ,#{endDate}) as 'statDate',
         b.project_id as 'projectId',
-        (select  project_name  from ctop_project where  id = b.project_id) as 'projectName',
+        (select project_name from ctop_project where id = b.project_id) as 'projectName',
         a.account_id as 'accountId',
         b.auth_name as 'authName',
         a.creative_id as 'creativeId',
@@ -1052,7 +1057,7 @@
         (select material_type from ctop_kuaishou_video_get where photo_id = c.photo_id limit 1) as materialType
         from
         ctop_kuaishou_report_daily_creative a
-        left join ctop_user_allocation  b on a.account_id = b.account_id
+        left join ctop_user_allocation b on a.account_id = b.account_id
         left join ctop_kuaishou_creative c on a.creative_id = c.creative_id
         where
         a.stat_date &gt;= #{startDate}
@@ -1153,6 +1158,11 @@
         ) as 'responsibleName',
         (
         select realname from sys_user where id = (
+        select sale_id from ctop_project where id = b.project_id
+        )
+        ) as 'saleName',
+        (
+        select realname from sys_user where id = (
         select design_responsible_id from ctop_project where id = b.project_id
         )
         ) as 'designResponsibleName',
@@ -1218,7 +1228,7 @@
                  open="(" close=")">
             #{item}
         </foreach>
-        group by b.project_id  order by sum(a.charge) desc
+        group by b.project_id order by sum(a.charge) desc
 
     </select>
 

+ 70 - 122
module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/FileUtil.java

@@ -16,13 +16,10 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URL;
 import java.util.Date;
-import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
 /**
- * TODO
- *
  * @ClassName ZipUtil
  * @Author ZHAOXA
  * @date 2020-10-23 10:05
@@ -96,7 +93,7 @@ public class FileUtil {
                     return null;
                 }
             }
-            realPath = locationPath.concat("/").concat(fileName);
+            realPath = locationPath.concat(fileName);
             os = new FileOutputStream(realPath);
             int bytesRead = 0;
             byte[] buffer = new byte[8192];
@@ -104,6 +101,7 @@ public class FileUtil {
                 os.write(buffer, 0, bytesRead);
                 os.flush();
             }
+
         } catch (Exception e) {
             log.error(" ========== 文件下载到本地异常:", e);
             return null;
@@ -112,133 +110,16 @@ public class FileUtil {
                 if (os != null) {
                     os.close();
                 }
-            } catch (IOException e) {
-                log.error("Close OutputStream error", e);
-            }
-            try {
                 if (is != null) {
                     is.close();
                 }
             } catch (IOException e) {
-                log.error("Close InputStream error", e);
-            }
-        }
-        return realPath;
-    }
-
-
-    /**
-     * //创建zip方法,其中的参数ZipFileName是压缩后文件,inputFile要压缩的文件。
-     *
-     * @param
-     * @return void
-     * @throws
-     * @author ZHAOXA
-     */
-    public static void zip(String ZipFileName, File inputFile) throws IOException {
-        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(ZipFileName));//创建了输出流,这里ZipOutputStream()的参数是FileOutPutStream的原因是因为ZIP压缩的对象是文件。
-        zip(out, inputFile, "");//调用zip方法,实现了zip的重载。这次的参数是本方法中定义过的输出流out,要压缩的文件:inputFile以及文件最后的存储目录base
-        log.info("压缩中....");
-        out.close();
-        log.info("压缩完成!");
-    }
-
-    public static void zip(ZipOutputStream out, File f, String base) throws IOException {//方法重载
-        if (f.isDirectory()) {//判断要压缩的文件是否是文件夹
-            File[] fl = f.listFiles();//如果是文件夹就对把该文件夹中的文件的路径以文件数组的形式获得
-            if (base.length() != 0) {//判断最后要存储的路径是否已存在
-                out.putNextEntry(new ZipEntry(base + "/"));//如果已经存在,写入此目录的entry
-            }
-            for (int i = 0; i < fl.length; i++) {//遍历文件数组
-                zip(out, fl[i], base + fl[i]);//将文件数组中的文件添加到已经创建的ZIP中。
-            }
-        } else {
-            out.putNextEntry(new ZipEntry(base));//如果base为空。那么就创建新的进入点
-            //创建FileInputStream对象
-            FileInputStream in = new FileInputStream(f);//创建该输入流的原因是为了后边判断该流是否到达尾部
-            int b;
-            System.out.println(base);
-            while ((b = in.read()) != -1) {
-                out.write(b);//在没有到达尾部的情况下向已经创建的ZIP中添加
-            }
-            in.close();//关闭流
-        }
-    }
-
-    /**
-     * 文件压缩方法
-     *
-     * @param list
-     * @param zipfilename
-     * @param basePath
-     * @param vid
-     * @throws
-     * @Title: listToZip
-     * @date 2020年1月20日
-     */
-    public static String listToZip(List<String> list, String localPath, String zipfilename) {
-        FileInputStream is = null;
-        ZipOutputStream zos = null;
-        String realPath = localPath + "/newFiles/" + zipfilename;
-        try {
-            if (list != null && list.size() > 0) {
-                File f = new File(localPath, "newFiles");
-                if (!f.exists()) {
-                    boolean mkdirFlag = f.mkdirs();
-                    if (!mkdirFlag) {
-                        log.error(" ==========压缩, 创建临时文件夹失败 ========== ");
-                        return null;
-                    }
-                }
-                // 创建zip文件输出流
-                zos = new ZipOutputStream(new FileOutputStream(new File(realPath)));
-                File file = null;
-                String path = "";
-                for (int i = 0; i < list.size(); i++) {
-                    path = list.get(i);
-                    // file 拿到待压缩文件
-                    file = new File(path);
-                    if (file.exists()) {
-                        // 创建源文件输入流
-                        is = new FileInputStream(file);
-                        zos.putNextEntry(new ZipEntry(file.getName()));
-                        byte[] buf = new byte[2048];
-                        int length = -1;
-                        while ((length = is.read(buf)) != -1) {
-                            zos.write(buf, 0, length);
-                            zos.flush();
-                        }
-                        zos.closeEntry();
-                        is.close();
-                      /*  if (file.delete()) {
-                            // 删除图片
-                            log.debug("[ ===== File deleted successfully ===== ]");
-                        }*/
-                    } else {
-                        log.warn("[ ======= {} 源文件不存在 ======= ]", path);
-                        return null;
-                    }
-                }
-            }
-        } catch (Exception e) {
-            log.error("[ ==========压缩文件异常 ========== ]", e);
-            return null;
-        } finally {
-            try {
-                if (is != null) {
-                    is.close();
-                }
-                if (zos != null) {
-                    zos.close();
-                }
-            } catch (IOException e) {
-                log.error("[ ==========关闭IO流失败========== ]", e);
+                e.printStackTrace();
             }
         }
         return realPath;
     }
 
-
     /**
      * 通过MultipartFile获取本地下载路径
      *
@@ -284,4 +165,71 @@ public class FileUtil {
         return path + fileName;
     }
 
+
+    /**
+     * @param zipSavePath 压缩好的zip包存放路径
+     * @param sourceFile  待压缩的文件(单个文件或者整个文件目录)
+     * @return
+     * @author
+     */
+    public static String zipCompress(String zipSavePath, File sourceFile) {
+        try {
+            //创建zip输出流
+            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipSavePath));
+            File[] fileList = sourceFile.listFiles();
+            //如果文件夹为空,则只需在目的地zip文件中写入一个目录进入点
+            if (fileList.length != 0) {
+                for (File file : fileList) {
+                    compress(zos, file, file.getName());
+                }
+                zos.close();
+            }
+        } catch (Exception e) {
+            log.error("压缩文件异常 : {}, zipSavePath={}, sourceFile={}", e, zipSavePath, sourceFile.getName());
+        }
+        return zipSavePath;
+    }
+
+    /**
+     * 递归压缩文件
+     *
+     * @param
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
+    private static void compress(ZipOutputStream zos, File sourceFile, String fileName) throws Exception {
+        if (sourceFile.isDirectory()) {
+            //如果是文件夹,取出文件夹中的文件(或子文件夹)
+            File[] fileList = sourceFile.listFiles();
+            if (fileList.length == 0)//如果文件夹为空,则只需在目的地zip文件中写入一个目录进入点
+            {
+                zos.putNextEntry(new ZipEntry(fileName + "/"));
+            } else//如果文件夹不为空,则递归调用compress,文件夹中的每一个文件(或文件夹)进行压缩
+            {
+                for (File file : fileList) {
+                    compress(zos, file, fileName + "/" + file.getName());
+                }
+            }
+        } else {
+            if (!sourceFile.exists()) {
+                zos.putNextEntry(new ZipEntry("/"));
+                zos.closeEntry();
+            } else {
+                //单个文件,直接将其压缩到zip包中
+                zos.putNextEntry(new ZipEntry(fileName));
+                FileInputStream fis = new FileInputStream(sourceFile);
+                byte[] buf = new byte[1024];
+                int len;
+                //将源文件写入到zip文件中
+                while ((len = fis.read(buf)) != -1) {
+                    zos.write(buf, 0, len);
+                }
+                zos.closeEntry();
+                fis.close();
+            }
+        }
+    }
+
+
 }

+ 3 - 8
module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/controller/ShiwanFileUploadController.java

@@ -105,15 +105,10 @@ public class ShiwanFileUploadController {
 
 
     @PostMapping("/createNewZipFile")
-    public Result<Object> createNewZipFile(@RequestBody MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType) {
+    public Result<Object> createNewZipFile(@RequestBody MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType, String isCreate, String newFileName) {
         Result<Object> result = new Result<>();
         try {
-            ShiwanFileUpload entity = shiwanFileUploadService.createNewZipFile(file, id, updateName, userId, accountId, fileType);
-            if (Check.isNull(entity)) {
-                result = Result.error("上传失败");
-            }
-            Object obj = entity;
-            result = Result.ok(obj);
+            return shiwanFileUploadService.createNewZipFile(file, id, updateName, userId, accountId, fileType, isCreate, newFileName);
         } catch (Exception e) {
             log.error("生成新的试玩素材ZIP包异常", e);
             result = Result.error(-1, "上传失败");
@@ -123,7 +118,7 @@ public class ShiwanFileUploadController {
 
     @GetMapping("/selectListByParentId")
     public Result<List<ShiwanFileUpload>> selectListByParentId(String id) {
-        Result<List<ShiwanFileUpload>> result = new Result<List<ShiwanFileUpload>>();
+        Result<List<ShiwanFileUpload>> result = new Result<>();
         ShiwanFileUpload shiwanFileUploadEntity = shiwanFileUploadService.getById(id);
         if (shiwanFileUploadEntity == null) {
             result.error500("未找到对应实体");

+ 4 - 0
module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/mapper/xml/ShiwanFileUploadMapper.xml

@@ -23,6 +23,10 @@
         <if test="parentId != null and parentId != '' ">
             and parent_id = #{parentId}
         </if>
+        <if test="signature != null and signature != '' ">
+            and signature = #{signature}
+        </if>
+        LIMIT 1
     </select>
     <select id="selectListByParentId" resultType="cn.com.ctop.shiwan.modules.entity.ShiwanFileUpload">
         SELECT

+ 124 - 48
module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/service/ShiwanFileUploadServiceImpl.java

@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xxl.job.core.enums.NoEn;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -51,38 +52,51 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
 
     @Override
     public ShiwanFileUpload saveOrUpdateFile(MultipartFile file, String userId, Long accountId, String fileType, Long parentId, String uuid) {
-        ShiwanFileUpload existFiles = getExistFiles(userId, accountId, file.getOriginalFilename(), fileType, parentId);
         StringBuffer path = new StringBuffer();
-        String uuids = UUID.randomUUID().toString();
-        path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(uuids).append("/");
-        log.info("----------服务器下载地址:{}", path.toString());
+        path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(UUID.randomUUID().toString()).append("/");
+        log.info("-------下载到服务器地址:{}", path.toString());
         ShiwanFileUpload shiwanFileUpload = null;
-        String newUrl = FileUtil.approvalFile(file, path.toString());
+        String newFileUrl = FileUtil.approvalFile(file, path.toString());
         String md5 = null;
         try {
-            md5 = LoadFileUtil.getMD5(newUrl);
+            md5 = LoadFileUtil.getMD5(newFileUrl);
         } catch (IOException e) {
             log.error("获取MD5签名失败", e);
         }
+        ShiwanFileUpload existFiles = getExistFiles(userId, accountId, file.getOriginalFilename(), fileType, parentId, md5);
         if (!Check.isNull(existFiles)) {
+            long start = System.currentTimeMillis();
             existFiles.setSignature(md5);
-            shiwanFileUpload = updateFile(file, existFiles);
+            try {
+                shiwanFileUpload = updateFile(file, existFiles);
+            } catch (IOException e) {
+                log.error("更新文件,上传SOC异常", e);
+            }
             if (!Check.isNull(shiwanFileUpload)) {
-                List<String> urlList = unzipFiles(shiwanFileUpload, path.toString());
+                List<String> urlList = unzipFiles(shiwanFileUpload, path.toString(), newFileUrl);
                 saveInnerFiles(shiwanFileUpload, urlList);
             }
+            long end = System.currentTimeMillis();
+            log.info("文件更新完成,耗时:{} ms", (end - start));
         } else {
+            long start = System.currentTimeMillis();
             ShiwanFileUpload fileUpload = new ShiwanFileUpload();
             fileUpload.setSignature(md5);
             fileUpload.setUserId(userId);
             fileUpload.setAccountId(accountId);
             fileUpload.setFileType(fileType);
-            fileUpload.setParentId(parentId);
-            shiwanFileUpload = saveFile(file, fileUpload, uuid);
+            try {
+                //新增zip包
+                shiwanFileUpload = saveFile(file, fileUpload, null);
+            } catch (IOException e) {
+                log.error("新增文件,上传SOC异常", e);
+            }
             if (!Check.isNull(shiwanFileUpload)) {
-                List<String> urlList = unzipFiles(shiwanFileUpload, path.toString());
+                List<String> urlList = unzipFiles(shiwanFileUpload, path.toString(), newFileUrl);
                 saveInnerFiles(shiwanFileUpload, urlList);
             }
+            long end = System.currentTimeMillis();
+            log.info("文件新增完成,耗时:{} ms", (end - start));
         }
         return shiwanFileUpload;
     }
@@ -95,7 +109,7 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
      * @throws
      * @author ZHAOXA
      */
-    private ShiwanFileUpload updateFile(MultipartFile file, ShiwanFileUpload existFiles) {
+    private ShiwanFileUpload updateFile(MultipartFile file, ShiwanFileUpload existFiles) throws IOException {
         ResFileDTO resultFile = null;
         String url = "";
         ShiwanFileUpload fileUpload = new ShiwanFileUpload();
@@ -104,15 +118,23 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
         } else {
             url = "try-play/zip/";
         }
+        InputStream inputStream = null;
         try {
-            resultFile = CosUtils.uploadDetailInputStreamV2(file.getInputStream(), existFiles.getCfileName(), existFiles.getFileSuffix(), file.getSize(), url);
+            inputStream = file.getInputStream();
+            resultFile = CosUtils.uploadDetailInputStreamV2(inputStream, existFiles.getFileName(), existFiles.getFileSuffix(), file.getSize(), url);
         } catch (IOException e) {
             log.error("更新文件,上传COS失败", e);
+        } finally {
+            if (inputStream != null) {
+                inputStream.close();
+            }
         }
         QueryWrapper<ShiwanFileUpload> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("id", existFiles.getId());
-        existFiles.setFileSize(resultFile.getFileSize() + "b");
+        existFiles.setFileSize(resultFile.getFileSize() + "B");
         existFiles.setUploadTime(new Date());
+        existFiles.setFileUrl(resultFile.getFileUrl());
+        existFiles.setCfileName(resultFile.getCFileName());
         shiwanFileUploadMapper.update(existFiles, queryWrapper);
         shiwanFileUploadMapper.deleteByParentId(existFiles.getId());
         return existFiles;
@@ -126,7 +148,7 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
      * @throws
      * @author ZHAOXA
      */
-    private ShiwanFileUpload saveFile(MultipartFile file, ShiwanFileUpload fileUpload, String uuid) {
+    private ShiwanFileUpload saveFile(MultipartFile file, ShiwanFileUpload fileUpload, String uuid) throws IOException {
         String filename = file.getOriginalFilename();
         ResFileDTO resultFile = null;
         String url = "";
@@ -137,10 +159,16 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
             url = "try-play/inner-file/".concat(uuid).concat("/");
         }
         String fileSuffix = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
+        InputStream inputStream = null;
         try {
-            resultFile = CosUtils.uploadDetailInputStream(file.getInputStream(), filename, fileSuffix, file.getSize(), url);
+            inputStream = file.getInputStream();
+            resultFile = CosUtils.uploadDetailInputStreamV2(inputStream, filename, fileSuffix, file.getSize(), url);
         } catch (IOException e) {
             log.error("上传COS异常", e);
+        } finally {
+            if (inputStream != null) {
+                inputStream.close();
+            }
         }
         if (!Check.isNull(resultFile)) {
             fileUpload.setCfileName(resultFile.getCFileName());
@@ -152,7 +180,7 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
                 fileUpload.setFileLevel(NoEn.NO1.valueInt());
             }
             fileUpload.setFileStatus(NoEn.NO1.valueStr());
-            fileUpload.setFileSize(resultFile.getFileSize() + "b");
+            fileUpload.setFileSize(resultFile.getFileSize() + "B");
             fileUpload.setFileUrl(resultFile.getFileUrl());
             fileUpload.setUploadTime(new Date());
             shiwanFileUploadMapper.insert(fileUpload);
@@ -162,31 +190,53 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
 
 
     @Override
-    public ShiwanFileUpload createNewZipFile(MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType) throws IOException {
-        ShiwanFileUpload fileUpload = shiwanFileUploadMapper.selectById(id);
+    public Result<Object> createNewZipFile(MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType, String isCreate, String newFileName) throws IOException {
+        ShiwanFileUpload oldFile = shiwanFileUploadMapper.selectById(id);
+        if (Check.isNull(oldFile)) {
+            return Result.error("查询原文件数据失败");
+        }
         StringBuffer path = new StringBuffer();
         String uuid = UUID.randomUUID().toString();
         path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(uuid).append("/");
         log.info("----------服务器下载地址:{}", path.toString());
         //解压zip文件
-        List<String> urlList = unzipFiles(fileUpload, path.toString());
+        List<String> urlList = unzipFiles(oldFile, path.toString(), null);
+        String newFilePath = "";
         if (null != urlList && urlList.size() > 0) {
             Iterator it = urlList.iterator();
             while (it.hasNext()) {
                 String url = it.next().toString();
                 String fileName = url.substring(url.lastIndexOf("/") + 1);
                 if (updateName.equals(fileName)) {
+                    newFilePath = url.substring(0, url.lastIndexOf("/") + 1);
                     //移除被替换的对象
                     it.remove();
+                    deletelocalFiles(url);
+                    break;
                 }
             }
         }
+        if (Check.isNull(newFilePath)) {
+            return Result.error("被替换文件名称有误");
+        }
         //添加上新的对象
-        String newUrl = FileUtil.approvalFile(file, path.toString());
+        String newUrl = FileUtil.approvalFile(file, newFilePath);
         urlList.add(newUrl);
         //压缩zip文件
-        String newFileName = DateUtils.getNowDate(DateUtils.LONG_FORMAT).concat("_COPYFROM_").concat(fileUpload.getFileName());
-        return createNewZipFiles(urlList, path.toString(), newFileName, updateName, userId, accountId, fileType);
+        if (Check.isNull(newFileName) && NoEn.NO1.valueStr().equals(isCreate)) {
+            newFileName = DateUtils.getNowDate(DateUtils.LONG_FORMAT).concat("_COPY-FROM_").concat(oldFile.getFileName());
+        }
+        ShiwanFileUpload newFile = new ShiwanFileUpload();
+        newFile.setUserId(userId);
+        newFile.setAccountId(accountId);
+        newFile.setFileType(fileType);
+        newFile.setFileName(newFileName);
+        oldFile.setUserId(userId);
+        oldFile.setAccountId(accountId);
+        oldFile.setFileType(fileType);
+        oldFile.setFileName(newFileName);
+        ShiwanFileUpload newZipFiles = createNewZipFiles(urlList, path.toString(), newFile, isCreate, oldFile);
+        return Result.ok(newZipFiles);
     }
 
     @Override
@@ -202,25 +252,28 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
      * @throws
      * @author ZHAOXA
      */
-    private List<String> unzipFiles(ShiwanFileUpload fileUpload, String path) {
+    private List<String> unzipFiles(ShiwanFileUpload fileUpload, String path, String innerZipPath) {
+        long start = System.currentTimeMillis();
         List<String> urlList = new ArrayList<>();
+        //下载到本地服务器
+        if (Check.isNull(innerZipPath)) {
+            innerZipPath = FileUtil.writeFiles(path.concat("oldZip/"), fileUpload.getFileUrl(), fileUpload.getCfileName());
+        }
         try {
-            //下载到本地服务器
-            String innerZipPath = FileUtil.writeFiles(path.concat("oldZip/"), fileUpload.getFileUrl(), fileUpload.getCfileName());
-            log.info("----------zip包解压地址:{}", innerZipPath);
+            log.info("----------zip包下载地址:{}", innerZipPath);
             ZipFile zipFile = new ZipFile(innerZipPath, Charset.forName("GBK"));
             Enumeration<?> enumeration = zipFile.entries();
             ZipEntry zipEntry = null;
-            path.concat("innerFile/");
+            String innerPath = path.concat("innerFiles/");
             while (enumeration.hasMoreElements()) {
                 zipEntry = (ZipEntry) enumeration.nextElement();
                 // 如果是文件夹,就创建个文件夹
                 if (zipEntry.isDirectory()) {
-                    String dirPath = path + zipEntry.getName();
+                    String dirPath = innerPath + zipEntry.getName();
                     File dir = new File(dirPath);
                     dir.mkdirs();
                 } else {
-                    String url = path + zipEntry.getName();
+                    String url = innerPath + zipEntry.getName();
                     // 如果是文件,就先创建一个文件,然后用io流把内容copy过去
                     File targetFile = new File(url);
                     // 保证这个文件的父文件夹必须要存在
@@ -232,20 +285,22 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
                     InputStream is = zipFile.getInputStream(zipEntry);
                     FileOutputStream fos = new FileOutputStream(targetFile);
                     int len;
-                    byte[] buf = new byte[8192];
+                    byte[] buf = new byte[2048];
                     while ((len = is.read(buf)) != -1) {
                         fos.write(buf, 0, len);
                     }
-                    urlList.add(url);
                     // 关流顺序,先打开的后关闭
                     fos.close();
                     is.close();
+                    urlList.add(url);
                 }
             }
-            deletelocalFiles(path.concat("oldZip/").concat(fileUpload.getCfileName()));
         } catch (IOException e) {
-            log.error("解压原zip失败 ", e);
+            log.error("解压原zip文件失败 ", e);
         }
+        deletelocalFiles(innerZipPath);
+        long end = System.currentTimeMillis();
+        log.info("文件解压完成,耗时:{} ms", (end - start));
         return urlList;
     }
 
@@ -257,22 +312,30 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
      * @throws
      * @author ZHAOXA
      */
-    private ShiwanFileUpload createNewZipFiles(List<String> list, String innerFilePath, String zipfilename, String updateName, String userId, Long accountId, String fileType) throws IOException {
-        String zipUrl = FileUtil.listToZip(list, innerFilePath, zipfilename);
-        ShiwanFileUpload shiwanFileUpload = new ShiwanFileUpload();
-        shiwanFileUpload.setUserId(userId);
-        shiwanFileUpload.setAccountId(accountId);
-        shiwanFileUpload.setFileType(fileType);
+    private ShiwanFileUpload createNewZipFiles(List<String> list, String path, ShiwanFileUpload addFile, String isCreate, ShiwanFileUpload updateFile) throws IOException {
+        String zipUrl = FileUtil.zipCompress(path.concat(addFile.getFileName()), new File(path.concat("innerFiles/")));
         try {
-            shiwanFileUpload.setSignature(LoadFileUtil.getMD5(zipUrl));
+            String md5 = LoadFileUtil.getMD5(zipUrl);
+            addFile.setSignature(md5);
+            updateFile.setSignature(md5);
         } catch (IOException e) {
             log.error("获取MD5签名失败", e);
         }
-        //存储新ZIP包
-        ShiwanFileUpload newZipEntity = saveFile(FileUtil.getMulFileByPath(zipUrl), shiwanFileUpload, null);
-        deletelocalFiles(zipUrl);
-        if (!Check.isNull(newZipEntity)) {
-            saveInnerFiles(newZipEntity, list);
+        ShiwanFileUpload newZipEntity = null;
+        //判断是新增还是更新
+        if (NoEn.NO1.valueStr().equals(isCreate)) {
+            //存储新ZIP包
+            newZipEntity = saveFile(FileUtil.getMulFileByPath(zipUrl), addFile, null);
+            deletelocalFiles(zipUrl);
+            if (!Check.isNull(newZipEntity)) {
+                saveInnerFiles(newZipEntity, list);
+            }
+        } else {
+            newZipEntity = updateFile(FileUtil.getMulFileByPath(zipUrl), updateFile);
+            deletelocalFiles(zipUrl);
+            if (!Check.isNull(newZipEntity)) {
+                saveInnerFiles(newZipEntity, list);
+            }
         }
         return newZipEntity;
     }
@@ -293,13 +356,25 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
             shiwanFileUpload.setAccountId(newZipEntity.getAccountId());
             shiwanFileUpload.setFileType(newZipEntity.getFileType());
             shiwanFileUpload.setParentId(newZipEntity.getId());
+            String urlpath = url.substring(0, url.lastIndexOf("/"));
+            String lastFileName = urlpath.substring(urlpath.lastIndexOf("/") + 1);
+            String cosFilePath = "";
+            if ("innerFiles".equals(lastFileName)) {
+                cosFilePath = newZipEntity.getCfileName();
+            } else {
+                cosFilePath = newZipEntity.getCfileName().concat("/").concat(lastFileName);
+            }
             try {
                 shiwanFileUpload.setSignature(LoadFileUtil.getMD5(url));
             } catch (IOException e) {
                 log.error("获取MD5签名失败", e);
             }
             mulFileByPath = FileUtil.getMulFileByPath(url);
-            saveFile(mulFileByPath, shiwanFileUpload, newZipEntity.getCfileName());
+            try {
+                saveFile(mulFileByPath, shiwanFileUpload, cosFilePath);
+            } catch (IOException e) {
+                log.error("新增内部文件,上传SOC异常", e);
+            }
             deletelocalFiles(url);
         }
     }
@@ -327,13 +402,14 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
      * @throws
      * @author ZHAOXA
      */
-    private ShiwanFileUpload getExistFiles(String userId, Long accountId, String fileName, String fileType, Long parentId) {
+    private ShiwanFileUpload getExistFiles(String userId, Long accountId, String fileName, String fileType, Long parentId, String md5) {
         JSONObject job = new JSONObject();
         job.put("useId", userId);
         job.put("accountId", accountId);
         job.put("fileName", fileName);
         job.put("fileType", fileType);
         job.put("parentId", parentId);
+        job.put("signature", md5);
         ShiwanFileUpload fileEntity = shiwanFileUploadMapper.selectEntity(job);
         if (Check.isNull(fileEntity)) {
             return null;

+ 2 - 1
module-shiwan/src/main/java/cn/com/ctop/shiwan/modules/service/impl/IShiwanFileUploadService.java

@@ -2,6 +2,7 @@ package cn.com.ctop.shiwan.modules.service;
 
 import cn.com.ctop.shiwan.modules.entity.ShiwanFileUpload;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
@@ -33,7 +34,7 @@ public interface IShiwanFileUploadService extends IService<ShiwanFileUpload> {
      * @throws
      * @author ZHAOXA
      */
-    ShiwanFileUpload createNewZipFile(MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType) throws IOException;
+    Result<Object> createNewZipFile(MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType, String isCreate, String newFileName) throws IOException;
 
     List<ShiwanFileUpload> selectListByParentId(String id);
 }

+ 9 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAccountReportCtrl.java

@@ -53,6 +53,9 @@ public class BytedanceAccountReportCtrl {
         String mediaId = requestBody.getString("mediaId");
         BigDecimal discount = requestBody.getBigDecimal("discount");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
+        if(accounts.isEmpty()){
+         return resultBody;
+        }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
         try {
@@ -84,6 +87,9 @@ public class BytedanceAccountReportCtrl {
         String mediaId = requestBody.getString("mediaId");
         BigDecimal discount = requestBody.getBigDecimal("discount");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
+        if(accounts.isEmpty()){
+            return result;
+        }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
         int hour= requestBody.getInteger("hour");
@@ -124,6 +130,9 @@ public class BytedanceAccountReportCtrl {
         columns.add(1,"authName");
         String mediaId = requestBody.getString("mediaId");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
+        if(accounts.isEmpty()){
+            return;
+        }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
         String target= requestBody.getString("target");

+ 11 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceAccountReportMapper.xml

@@ -374,6 +374,11 @@
         ) as 'designResponsibleName',
         b.auth_name as 'authName',
         b.project_id as 'projectId',
+        (
+        select realname from sys_user where id = (
+        select sale_id from ctop_project where id = b.project_id
+        )
+        ) as 'saleName',
         (select project_name from ctop_project where id = b.project_id) as 'projectName',
         c.media_id as 'mediaId',
         <include refid="selectSql"></include>
@@ -526,6 +531,12 @@
         select design_responsible_id from ctop_project where id = b.project_id
         )
         ) as 'designResponsibleName',
+
+        (
+        select realname from sys_user where id = (
+        select sale_id from ctop_project where id = b.project_id
+        )
+        ) as 'saleName',
         b.auth_name as 'authName',
         b.project_id as 'projectId',
         (select project_name from ctop_project where id = b.project_id) as 'projectName',

+ 11 - 11
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceVideoReportMapper.xml

@@ -6,9 +6,9 @@
         SELECT * from (SELECT
         t1.signature,
         t2.url,
-        (SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.clip_id=u.id where t3.material_id=t1.signature limit 1) AS clip,
-        (SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.shot_id=u.id where t3.material_id=t1.signature limit 1) AS shot,
-        (SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.plan_id=u.id where t3.material_id=t1.signature limit 1) AS plan,
+        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.clip_id=u.id where t3.material_id=t1.signature limit 1),'') AS clip,
+        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.shot_id=u.id where t3.material_id=t1.signature limit 1),'') AS shot,
+        IFNULL((SELECT u.realname FROM ctop_material_ascription t3 LEFT JOIN sys_user u on t3.plan_id=u.id where t3.material_id=t1.signature limit 1),'') AS plan,
         t2.cover_url as converUrl,
         t2.material_name AS materialName,
         (SELECT project_name FROM ctop_project t4 WHERE t4.id = t3.project_id) AS projectName,
@@ -22,18 +22,18 @@
         t1.stat_datetime >= #{startDate}
         AND t1.stat_datetime &lt;= #{endDate}
         <if test="accountIds != null">
-        AND t1.account_id in
-        <foreach item="item" index="index" collection="accountIds"
-                 open="(" separator="," close=")">
-            #{item}
-        </foreach>
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
         </if>
         AND t2.url!=""
         GROUP BY t1.signature
         ) t
-        WHERE (t.clip LIKE '%${clip}%' or t.clip is null)
-        AND (t.shot LIKE '%${shot}%' or t.shot is null)
-        AND (t.plan LIKE '%${plan}%' or t.plan is null)
+        WHERE (t.clip LIKE '%${clip}%')
+        AND (t.shot LIKE '%${shot}%')
+        AND (t.plan LIKE '%${plan}%')
         ORDER BY ${target} ${order}
     </select>