Bladeren bron

Merge branch 'master' of http://47.100.37.243:10080/ZHOU/yunsu

# Conflicts:
#	cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java
5 jaren geleden
bovenliggende
commit
93a3c447a8

+ 40 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldFileController.java

@@ -12,6 +12,7 @@ import com.hssx.cloudmodel.service.UserService;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import com.hssx.cloudmodel.util.PageUtil;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -38,6 +39,7 @@ import java.util.zip.ZipOutputStream;
  * @since 2019-08-07
  */
 @Controller
+@Slf4j
 @RequestMapping("/mouldfile")
 public class MouldFileController {
 
@@ -50,6 +52,43 @@ public class MouldFileController {
     @Autowired
     private UserService userService;
 
+
+
+    /**
+     * 模具文档的下载
+     * id 所要下载的文件id ,
+     * @return
+     */
+    @GetMapping("/download/{id}")
+    public HttpRespMsg download(@PathVariable("id") Integer id,
+                         HttpServletRequest request,HttpServletResponse resp) throws IOException {
+        HttpRespMsg msg = new HttpRespMsg();
+        MouldFile model = mouldFileService.getById(id);// 文件实体
+        msg.data = model;
+        FileInputStream fis = null;
+        try {
+            String fileName = model.getFileName();
+            String filePath = path+model.getFileUrl().substring("/upload/".length());
+            fis = new FileInputStream(filePath);
+            resp.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            resp.setCharacterEncoding("UTF-8");
+            resp.setHeader("Content-Disposition",
+                    "attachment;filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
+            byte[] b = new byte[1024];
+            int len;
+            while ((len = fis.read(b)) > 0) {
+                resp.getOutputStream().write(b, 0, len);
+            }
+        } catch (Exception e) {
+
+            msg.setError("文件[ {} ]下载错误");
+        } finally {
+            resp.getOutputStream().flush();
+            resp.getOutputStream().close();
+            fis.close();
+        }
+        return msg;
+    }
     /**
      * 模具文档的上传
      * 参数: token 用户身份凭证,
@@ -129,7 +168,7 @@ public class MouldFileController {
     @RequestMapping("/list")
     @ResponseBody
     public HttpRespMsg list(@RequestParam Integer mouldId, @RequestParam Integer blongType, UserVO userVO) {
-        HttpRespMsg msg = mouldFileService.getFileList(mouldId, blongType, userVO);
+        HttpRespMsg msg = mouldFileService.getFileList(mouldId, blongType, userVO,path);
         return msg;
     }
 

+ 1 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/service/MouldFileService.java

@@ -26,7 +26,7 @@ public interface MouldFileService extends IService<MouldFile> {
     HttpRespMsg check(Integer mouldFileId, Integer isPass, UserVO userVO);
     HttpRespMsg dowloadFile(MouldFile projectFile, String token);
     HttpRespMsg getAllFileList(int mouldId, UserVO userVO);
-    HttpRespMsg getFileList(int mouldId, Integer blongType, UserVO userVO);
+    HttpRespMsg getFileList(int mouldId, Integer blongType, UserVO userVO,String path);
     HttpRespMsg delFile(MouldFile mouldFile);
     HttpRespMsg getListByUserAndProjectId(UserVO userVO, PageUtil page);
     HttpRespMsg dowloadFileList(UserVO userVO, HttpServletRequest request, HttpServletResponse response,String downloadPath,String path) throws IOException;

+ 4 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -447,7 +447,7 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
     }
 
     @Override
-    public HttpRespMsg getFileList(int mouldId, Integer blongType, UserVO userVO) {
+    public HttpRespMsg getFileList(int mouldId, Integer blongType, UserVO userVO,String path) {
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
         List<MouldFile> list = new ArrayList<>();
@@ -458,6 +458,9 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
 //        }else{
             list = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", mouldId).eq("blong_type", blongType).orderByDesc("id"));
 //        }
+        for (MouldFile mouldFile : list) {
+            mouldFile.setFileUrl(path+mouldFile.getFileUrl().substring("/upload/".length()));
+        }
         msg.data = list;
         return msg;
     }

+ 2 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/util/FileUtil.java

@@ -18,9 +18,10 @@ public class FileUtil {
 			return String.format("%.1fGB", (size*1.0f/1024/1024/1024));
 		}
 	}
-	
 	public static void main(String[] args) {
 		long l = 1024 * 1024 * 1 * 1024;
 		System.out.println(getReadableFileSize(l));
+		String substring = "/upload/af9db74095354187b5ee17bce73b6b82.jpg".substring("/upload/".length());
+		System.out.println(substring);
 	}
 }