Преглед на файлове

1.7.5认证通版本功能优化

JiangChongBo преди 2 години
родител
ревизия
523156212b

+ 28 - 0
src/main/java/com/caimei/controller/admin/auth/AuthApi.java

@@ -10,6 +10,7 @@ import com.caimei.model.po.CmBrandAuthPo;
 import com.caimei.model.po.SysUser;
 import com.caimei.model.vo.*;
 import com.caimei.service.auth.AuthService;
+import com.caimei.utils.OSSUtils;
 import com.caimei.utils.SmsUtils;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
@@ -788,4 +789,31 @@ public class AuthApi {
         return authService.getAuthPartylist(authUserId);
     }
 
+    /**
+     * 删除视频
+     * @param videoID
+     * @return
+     */
+     @GetMapping("/del/video")
+    public ResponseJson delVideo(Integer videoID){
+        //删除阿里云存储视频
+         String ossName = authService.getOssNameAuthId(videoID);
+         OSSUtils.deleteSingleFile(ossName);
+         //删除视频信息
+         authService.deleteVideoByAuthId(videoID);
+         return ResponseJson.success();
+    }
+
+    /**
+     * 下载视频
+     * @param fileId
+     * @param response
+     * @return
+     */
+    @GetMapping("/downLoad/chose/zip")
+    public ResponseJson downLoadChoseZip(String fileId,HttpServletResponse response) {
+
+         return authService.downLoadChoseZip(fileId,response);
+    }
+
 }

+ 4 - 0
src/main/java/com/caimei/mapper/cmMapper/AuthMapper.java

@@ -160,5 +160,9 @@ public interface AuthMapper {
 
     void savaDyCommand(Integer authId,@Param("content")String content);
 
+    String getOssNameId(Integer videoID);
 
+    void deleteVideoById(Integer videoID);
+
+    ChallengeRoundVo getChallengeRoundInfo(Integer videoID);
 }

+ 22 - 0
src/main/java/com/caimei/service/auth/AuthService.java

@@ -262,4 +262,26 @@ public interface AuthService {
      * 保存抖音口令
      */
    void savaDyCommand(Integer authId,String content);
+
+    /**
+     * 根据authId获取ossName
+     * @param videoID
+     * @return
+     */
+    String getOssNameAuthId(Integer videoID);
+
+    /**
+     * 删除视频
+     * @param videoID
+     */
+    void deleteVideoByAuthId(Integer videoID);
+
+    /**
+     * 下载视频
+     * @param fileId
+     * @param response
+     * @return
+     */
+    ResponseJson downLoadChoseZip(String fileId,HttpServletResponse response);
+
 }

+ 99 - 3
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -15,9 +15,7 @@ import com.caimei.service.auth.AuthProductService;
 import com.caimei.service.auth.AuthService;
 import com.caimei.service.auth.ShopService;
 import com.caimei.service.auth.UploadService;
-import com.caimei.utils.Base64Util;
-import com.caimei.utils.ImageUtils;
-import com.caimei.utils.Md5Util;
+import com.caimei.utils.*;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
@@ -46,6 +44,7 @@ import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
+import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -54,6 +53,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.swing.*;
@@ -1449,4 +1449,100 @@ public class AuthServiceImpl implements AuthService {
     public void savaDyCommand(Integer authId,String content){
          authMapper.savaDyCommand(authId,content);
     }
+
+    /**
+     * 根据authId获取ossName
+     * @param videoID
+     * @return
+     */
+    @Override
+    public String getOssNameAuthId(Integer videoID){
+        return authMapper.getOssNameId(videoID);
+    }
+
+    /**
+     * 根据authId删除视频
+     * @param videoID
+     * @return
+     */
+    @Override
+    public void deleteVideoByAuthId(Integer videoID){
+
+        authMapper.deleteVideoById(videoID);
+    }
+    @Override
+    public ResponseJson downLoadChoseZip(String fileId,HttpServletResponse response){
+        if (fileId.contains(",")) {
+            String[] split = fileId.split(",");
+            ArrayList<ChallengeRoundVo> fileTreeVos = new ArrayList<>();
+            for (String s : split) {
+                ChallengeRoundVo file = authMapper.getChallengeRoundInfo(Integer.valueOf(s));
+                fileTreeVos.add(file);
+            }
+            //有package则在服务器固定路径new file.mkdir
+            UUID uuid = UUID.randomUUID();
+            String zipPath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/" + uuid;
+            String filePath = zipPath;
+            if ("dev".equals(active)) {
+                zipPath = "D:\\caimei-workSpace\\file\\" + uuid;
+                filePath = zipPath;
+            }
+            boolean mkdirs = new File(filePath).mkdirs();
+            Assert.isTrue(mkdirs, "文件夹创建失败");
+            for (ChallengeRoundVo challengeRoundVo : fileTreeVos) {
+                    //普通文件直接下载到临时文件夹uuid下
+                    String fileName = "";
+                    if ("dev".equals(active)) {
+                        fileName = zipPath + "\\"+challengeRoundVo.getId() ;
+                    } else {
+                        fileName = zipPath + "/"+challengeRoundVo.getId() ;
+                    }
+                    OSSUtils.downFileByFilePath("authFile/", challengeRoundVo.getOssName(), fileName);
+//                else {
+//                    //文件夹在uuid文件夹下创建自己包名的文件夹
+//                    String param = fileTreeVo.getId() + "," + authUserId;
+//                    String myPath = "";
+//                    myPath = filePath + "/" + fileTreeVo.getFileName();
+//                    if ("dev".equals(active)) {
+//                        myPath = filePath + "\\" + fileTreeVo.getFileName();
+//                    }
+//                    boolean dirs = new File(myPath).mkdirs();
+//                    Assert.isTrue(dirs, "文件夹创建失败");
+//                    recursion(param, myPath);
+//                }
+            }
+
+            //压缩
+            FileZipUtils.compress(zipPath, "", true);
+            String s = zipPath + ".zip";
+            String fileName = uuid + ".zip";
+            File file = new File(s);
+            try {
+                if (file.exists()) {
+                    FileInputStream fileInputStream = new FileInputStream(file);
+                    ServletOutputStream outputStream = response.getOutputStream();
+                    // 设置下载文件的mineType,告诉浏览器下载文件类型
+//                                int i = fileName.lastIndexOf(".");
+//                                String substring = fileName.substring(i + 1, filePath.length());
+                    response.setContentType("application/zip");
+                    // 设置一个响应头,无论是否被浏览器解析,都下载
+                    response.setHeader("Content-disposition", "attachment; filename=" + fileName);
+                    byte[] bytes = new byte[1024];
+                    int len;
+                    while ((len = fileInputStream.read(bytes)) != -1) {
+                        outputStream.write(bytes, 0, len);
+                    }
+                    fileInputStream.close();
+                    outputStream.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            file.delete();
+            FileZipUtils.deleteFile(new File(zipPath));
+        }
+        return null;
+
+    }
+
 }

+ 15 - 0
src/main/resources/mapper/AuthMapper.xml

@@ -742,4 +742,19 @@
         on cr.authId=cba.id
         where cr.authUserId=#{authUserId}
     </select>
+    <select id="getOssNameId" resultType="java.lang.String">
+        select ossName
+        from cm_challenge_round cr
+        where cr.id=#{videoID}
+    </select>
+    <delete id="deleteVideoById">
+        delete
+        from cm_challenge_round
+        where id = #{videoID}
+    </delete>
+    <select id="getChallengeRoundInfo" resultType="com.caimei.model.vo.ChallengeRoundVo">
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId, cr.authId,cr.dyCommand
+        from cm_challenge_round cr
+        where cr.id=#{videoID}
+    </select>
 </mapper>