5 роки тому
батько
коміт
0eb913dbf2

+ 8 - 10
cloud-model/src/main/java/com/hssx/cloudmodel/controller/PartController.java

@@ -58,37 +58,35 @@ public class PartController {
         msg = partService.importPartExcel(file, userVO);
         return msg;
     }
+
     /**
      * 单个零件添加
      * 参数: token 用户身份凭证, mouldId 模具id ,partNo 零件编号,partName 零件名称,partLife 零件寿命 单位:年
      * 修改:需多传 id 零件id
+     *
      * @throws Exception
      */
     @ApiOperation("单个零件添加")
     @RequestMapping(value = "/addOrUpdate")
     @ResponseBody
-    public HttpRespMsg addOrUpdate(
-            Part part,
-            UserVO userVO) {
+    public HttpRespMsg addOrUpdate(Part part, UserVO userVO) {
         HttpRespMsg msg = new HttpRespMsg();
-        msg = partService.add(part,
-                userVO);
+        msg = partService.add(part, userVO);
         return msg;
     }
+
     /**
      * 单个零件添加
      * 参数: token 用户身份凭证, mouldId 模具id
+     *
      * @throws Exception
      */
     @ApiOperation("零件列表")
     @RequestMapping(value = "/list")
     @ResponseBody
-    public HttpRespMsg list(
-            Part part,
-            UserVO userVO) {
+    public HttpRespMsg list(Part part, UserVO userVO) {
         HttpRespMsg msg = new HttpRespMsg();
-        msg = partService.getList(
-                userVO);
+        msg = partService.getList(userVO);
         return msg;
     }
 }

+ 73 - 70
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -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;

+ 7 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/PartServiceImpl.java

@@ -54,6 +54,7 @@ public class PartServiceImpl extends ServiceImpl<PartMapper, Part> implements Pa
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
         if(user != null){
+            List<Part> parts = partMapper.selectList(new QueryWrapper<Part>().eq("mould_id",userVO.getMouldId()));
             try {
                 File f = null;
                 if ("".equals(file) || file.getSize() <= 0) {
@@ -90,6 +91,12 @@ public class PartServiceImpl extends ServiceImpl<PartMapper, Part> implements Pa
                             return msg;
                         } else if (y == 0) {
                             //零件编号
+                            for (Part p : parts) {
+                                if(value.equals(p.getPartNo())){
+                                    msg.setError("第"+j+"行的零件编号:"+value+"已被占用,请修改后重新上传");
+                                    return msg;
+                                }
+                            }
                             part.setPartNo(value);
                         } else if (y == 1) {
                             //零件名称