|
@@ -327,75 +327,78 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
@Override
|
|
|
public HttpRespMsg addPartFile(UserVO userVO, String path, MultipartFile[] files) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
-// User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
-// if (user != null) {
|
|
|
-// List<Part> partLists = partMapper.selectList(new QueryWrapper<Part>().eq("mould_id", userVO.getMouldId()));
|
|
|
-// if (files.length > 0) {
|
|
|
-// for (MultipartFile file : files) {
|
|
|
-// MouldFile partFile = new MouldFile();
|
|
|
-// partFile.setModelId(userVO.getMouldId());
|
|
|
-// partFile.setBlongType(1);
|
|
|
-// partFile.setUploaderId(user.getId());
|
|
|
-// projectFile.setUploader(user.getUsername());
|
|
|
-// projectFile.setProjectId(userVO.getProjectId());
|
|
|
-// File dir = null;
|
|
|
-// dir = new File(path);
|
|
|
-// // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
-// if (!dir.exists()) {
|
|
|
-// dir.mkdirs();
|
|
|
-// }
|
|
|
-// String fileName = "";
|
|
|
-// if (file != null && !file.isEmpty()) {
|
|
|
-// fileName = file.getOriginalFilename();
|
|
|
-// String fileNamePrex = fileName.substring(0,fileName.lastIndexOf("."));
|
|
|
-// String[] split = fileNamePrex.split("\\+");
|
|
|
-// for (Part part : partLists) {
|
|
|
-// if(split[0] == part.getPartNo()) {
|
|
|
-// partFile.setPartId(part.getId());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// projectFile.setFileName(fileName);
|
|
|
-// projectFile.setFileSize(FileUtil.getReadableFileSize(file.getSize()));
|
|
|
-// System.out.println("上传文件名称" + file.getName() + ", dir = " + dir.getAbsolutePath());
|
|
|
-// int pos = fileName.lastIndexOf(".");
|
|
|
-// String rand = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
-// String sufix = fileName.substring(pos);
|
|
|
-// fileName = rand + sufix;
|
|
|
-// projectFile.setFileType(sufix);//文件后缀
|
|
|
-// projectFile.setUrl("/upload/"+fileName);
|
|
|
-// File saveFile = new File(dir, fileName);
|
|
|
-// projectFileMapper.insert(projectFile);
|
|
|
-// try {
|
|
|
-// saveFile.createNewFile();
|
|
|
-// file.transferTo(saveFile);
|
|
|
-// } catch (IOException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// projectFile = null;
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// projectFile = null;
|
|
|
-// }
|
|
|
-// //添加上传记录
|
|
|
-// ProjectOperationDynamics dynamics = new ProjectOperationDynamics();
|
|
|
-// dynamics.setContent(Constant.UPLOAD);
|
|
|
-// dynamics.setFileName(file.getOriginalFilename());
|
|
|
-// dynamics.setOperatorId(user.getId());
|
|
|
-// dynamics.setOperator(user.getUsername());
|
|
|
-// dynamics.setProjectId(userVO.getProjectId());
|
|
|
-// projectOperationDynamicsMapper.insert(dynamics);
|
|
|
-// }
|
|
|
-// msg.data = projectFile;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// msg.setError("上传文件不可为空");
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// msg.setError("用户不存在或者未登录");
|
|
|
-// }
|
|
|
- return null;
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
|
|
|
+ if (user != null) {
|
|
|
+ List<Part> partLists = partMapper.selectList(new QueryWrapper<Part>().eq("mould_id", userVO.getMouldId()));
|
|
|
+ if (files.length > 0) {
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ MouldFile partFile = new MouldFile();
|
|
|
+ partFile.setModelId(userVO.getMouldId());
|
|
|
+ partFile.setBlongType(1);
|
|
|
+ File dir = null;
|
|
|
+ dir = new File(path);
|
|
|
+ // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ String fileName = "";
|
|
|
+ if (file != null && !file.isEmpty()) {
|
|
|
+ fileName = file.getOriginalFilename();
|
|
|
+ String fileNamePrex = fileName.substring(0, fileName.lastIndexOf("."));
|
|
|
+ String[] split = fileNamePrex.split("\\+");
|
|
|
+ for (Part part : partLists) {
|
|
|
+ if (split[0] == part.getPartNo()) {
|
|
|
+ partFile.setPartId(part.getId());
|
|
|
+ }
|
|
|
+ if (Constant.PART_FILE_2D.equals(split[1])) {
|
|
|
+ partFile.setDwgType(0);
|
|
|
+ }
|
|
|
+ if (Constant.PART_FILE_3D.equals(split[1])) {
|
|
|
+ partFile.setDwgType(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ partFile.setFileName(fileName);
|
|
|
+ partFile.setFileSize(FileUtil.getReadableFileSize(file.getSize()));
|
|
|
+ System.out.println("上传文件名称" + file.getName() + ", dir = " + dir.getAbsolutePath());
|
|
|
+ int pos = fileName.lastIndexOf(".");
|
|
|
+ String rand = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String sufix = fileName.substring(pos);
|
|
|
+ fileName = rand + sufix;
|
|
|
+ partFile.setFileType(sufix);//文件后缀
|
|
|
+ partFile.setFileUrl("/upload/" + fileName);
|
|
|
+ File saveFile = new File(dir, fileName);
|
|
|
+ mouldFileMapper.insert(partFile);
|
|
|
+ try {
|
|
|
+ saveFile.createNewFile();
|
|
|
+ file.transferTo(saveFile);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ partFile = null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ partFile = null;
|
|
|
+ }
|
|
|
+ //添加上传记录
|
|
|
+ MouldOperationDynamics dynamics = new MouldOperationDynamics();
|
|
|
+ dynamics.setContent(Constant.UPLOAD);
|
|
|
+ dynamics.setFileName(file.getOriginalFilename());
|
|
|
+ dynamics.setOperatorId(user.getId());
|
|
|
+ dynamics.setOperatorName(user.getUsername());
|
|
|
+ dynamics.setMouldId(userVO.getMouldId());
|
|
|
+ mouldOperationDynamicsMapper.insert(dynamics);
|
|
|
+ }
|
|
|
+ msg.data = partFile;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError("上传文件不可为空");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError("用户不存在或者未登录");
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public Map<String, Object> feedBackDirectMultiDownload(HttpServletRequest request, HttpServletResponse response, String downloadPath, Mould vo, List<MouldFile> mouldFiles) throws IOException {
|
|
|
//压缩文件初始设置
|
|
|
String path = downloadPath;
|
|
@@ -429,9 +432,9 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- //以上,临时压缩文件创建完成
|
|
|
- //进行浏览器下载
|
|
|
- //获得浏览器代理信息
|
|
|
+//以上,临时压缩文件创建完成
|
|
|
+//进行浏览器下载
|
|
|
+//获得浏览器代理信息
|
|
|
final String userAgent = request.getHeader("USER-AGENT");
|
|
|
//判断浏览器代理并分别设置响应给浏览器的编码格式
|
|
|
String finalFileName = null;
|