2 Revize bdc6060494 ... 88fe289e1d

Autor SHA1 Zpráva Datum
  maqingyang 88fe289e1d Merge remote-tracking branch 'origin/develop' into develop před 1 rokem
  maqingyang c4c9f6702a modified some files před 1 rokem

+ 73 - 21
src/main/java/com/kexun/controller/FileUploadController.java

@@ -1,7 +1,11 @@
 package com.kexun.controller;
+import org.apache.commons.io.FileUtils;
 
 //import ch.qos.logback.core.rolling.helper.FileStoreUtil;
 //import ch.qos.logback.core.util.FileUtil;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.kexun.common.FileUploadUtil;
 import com.kexun.common.utils.Result;
 import com.kexun.entity.SysUser;
@@ -49,27 +53,79 @@ public class FileUploadController {
     @Value("${config.fileupload.warpath}")
     private String warPath;
 
+    @PostMapping("/filechange")
+    public Result filechange(@RequestParam Integer index, @RequestParam MultipartFile chunk, @RequestParam String name, @RequestParam Integer chunksLength, @RequestParam String uid
+            , @RequestParam String output_list, SysUser sysUser, @RequestParam long id
+    ) throws IOException {
+        String filename = name.split("\\.")[0];
+        String filefmt = name.split("\\.")[1];
+        String fullFileName = String.join("-", new String[]{filename, uid, index + "", "." + filefmt});
+        String filePath=fileuploadPath + "/" + sysUser.getUserName() + "/" +filename+"."+filefmt;
+        log.info("filename:" + fullFileName);
+        File dir = new File(fileuploadPath + "/" + sysUser.getUserName() + "/");
+
+        if (!dir.exists())
+            dir.mkdirs();
+
+        File file = new File(fileuploadPath + "/" + sysUser.getUserName() + "/" + fullFileName);
+        FileCopyUtils.copy(chunk.getInputStream(), new FileOutputStream(file));
+        FileUploadUtil.put(uid, index, chunksLength, fullFileName, fileuploadPath + "/" + sysUser.getUserName() + "/");
+        // 检测所有文件是否上传完成
+        boolean isAllChunksUploaded = FileUploadUtil.isAllChunksUploaded(uid);
+        //当前步骤这一步一定完成
+        try {
+            if (isAllChunksUploaded) {
+                FileUploadUtil.mergeChunks(name, uid);
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            throw new RuntimeException(ex.getMessage());
+        }
+
+        UserModel model=userModelService.findByID(id);
+        String oldFilePath=model.getFilePath();
+        File oldFile = new File(oldFilePath);
+
+        if (oldFile.exists()) {
+            try {
+                FileUtils.forceDelete(oldFile);
+                System.out.println("file delete success");
+            } catch (IOException e) {
+                System.out.println("file delete fail: " + e.getMessage());
+            }
+        }
+        else {
+            System.out.println("file not exist");
+        }
+
+        model.setFilePath(filePath);
+        userModelService.updateById(model);
+
+
+        return Result.success();
+    }
+
     //上传用户模型及审批结果
     @PostMapping("/fileupload")
     @ResponseBody
     public Result upload2(@RequestParam Integer index, @RequestParam MultipartFile chunk, @RequestParam String name, @RequestParam Integer chunksLength, @RequestParam String uid
             , @RequestParam String model_name, @RequestParam String model_type, @RequestParam String output_list, SysUser sysUser
     ) throws IOException {
-        int type=Integer.parseInt(model_type);
-        if(type==1 || type==2)
-        {
+        int type = Integer.parseInt(model_type);
+        if (type == 1 || type == 2) {
             String filename = name.split("\\.")[0];
             String filefmt = name.split("\\.")[1];
-            String fullFileName = String.join("-", new String[] {filename, uid, index + "", "." + filefmt});
+            String fullFileName = String.join("-", new String[]{filename, uid, index + "", "." + filefmt});
+            String filePath=fileuploadPath + "/" + sysUser.getUserName() + "/" +filename+"."+filefmt;
             log.info("filename:" + fullFileName);
-            File dir = new File(fileuploadPath+ "/" +sysUser.getUserName()+"/");
+            File dir = new File(fileuploadPath + "/" + sysUser.getUserName() + "/");
 
             if (!dir.exists())
                 dir.mkdirs();
 
-            File file = new File(fileuploadPath + "/" +sysUser.getUserName()+"/"+ fullFileName);
+            File file = new File(fileuploadPath + "/" + sysUser.getUserName() + "/" + fullFileName);
             FileCopyUtils.copy(chunk.getInputStream(), new FileOutputStream(file));
-            FileUploadUtil.put(uid, index, chunksLength, fullFileName, fileuploadPath+ "/" +sysUser.getUserName()+"/");
+            FileUploadUtil.put(uid, index, chunksLength, fullFileName, fileuploadPath + "/" + sysUser.getUserName() + "/");
             // 检测所有文件是否上传完成
             boolean isAllChunksUploaded = FileUploadUtil.isAllChunksUploaded(uid);
             //当前步骤这一步一定完成
@@ -91,24 +147,22 @@ public class FileUploadController {
 
 
             //model 数据库连接接口
-            String userName=sysUser.getUserName();
-            UserModel new_model=new UserModel();
+            String userName = sysUser.getUserName();
+            UserModel new_model = new UserModel();
             new_model.setCreateBy(userName);
             new_model.setModelName(model_name);
             new_model.setModelType(type);
             new_model.setStatus("暂停使用");
 //            new_model.setOtherData(name);
 //            new_model.setOutputList(output_list);
-            new_model.setFilePath(fileuploadPath + "/" +sysUser.getUserName()+"/"+ fullFileName);
+            new_model.setFilePath(filePath);
             userModelService.save(new_model);
 
-        }
-        else
-        {
+        } else {
             // http请求
             String filename = name.split("\\.")[0];
             String filefmt = name.split("\\.")[1];
-            String fullFileName = String.join("-", new String[] {filename, uid, index + "", "." + filefmt});
+            String fullFileName = String.join("-", new String[]{filename, uid, index + "", "." + filefmt});
             log.info("filename:" + fullFileName);
             File dir = new File(warPath);
             if (!dir.exists())
@@ -129,22 +183,20 @@ public class FileUploadController {
             }
 
             //审批
-            UserApproval approval=new UserApproval();
+            UserApproval approval = new UserApproval();
             approval.setUserName(sysUser.getUserName());
             approval.setApprovalId((long) 1);
 
 
             approval.setData(model_name.split(";")[0]);
 
-            String url_address=model_name.split(";")[1];
+            String url_address = model_name.split(";")[1];
 
             userApprovalService.save(approval);
 
 
-
-
-            String userName=sysUser.getUserName();
-            UserModel new_model=new UserModel();
+            String userName = sysUser.getUserName();
+            UserModel new_model = new UserModel();
             new_model.setCreateBy(userName);
             new_model.setModelName(model_name);
             new_model.setModelType(type);
@@ -154,7 +206,7 @@ public class FileUploadController {
             new_model.setFilePath(warPath + "/" + fullFileName);
             userModelService.save(new_model);
         }
-        return  Result.success();
+        return Result.success();
     }
 
     @GetMapping("/get")

+ 27 - 1
src/main/java/com/kexun/controller/ModelController.java

@@ -8,6 +8,7 @@ import com.kexun.common.utils.Result;
 import com.kexun.entity.*;
 import com.kexun.service.*;
 //import com.sun.xml.internal.bind.v2.TODO;
+import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -529,7 +530,17 @@ public class ModelController {
         return Result.success();
 
     }
-
+    //mqy add changeModelName
+    @PostMapping("changeModelName")
+    public Result changeModelName(@RequestBody String json){
+        JSONObject req=JSON.parseObject(json);
+        long modelNo= Long.parseLong(req.getString("modelNo"));
+        String modelName=req.getString("modelName");
+        System.out.println(modelNo);
+        System.out.println(modelName);
+        userModelService.changeModelName(modelName,modelNo);
+        return Result.success("ok");
+    }
     //yuan修改组合对应模型号
     @PostMapping("combineReleModel")
     public Result combineReleModel(@RequestBody String json,SysUser sysUser)
@@ -596,6 +607,21 @@ public class ModelController {
 //            userFieldService.updateById(field);
 //        }
 
+        UserModel model=userModelService.findByID(id);
+        String oldFilePath=model.getFilePath();
+        File oldFile = new File(oldFilePath);
+
+        if (oldFile.exists()) {
+            try {
+                FileUtils.forceDelete(oldFile);
+                System.out.println("file delete success");
+            } catch (IOException e) {
+                System.out.println("file delete fail: " + e.getMessage());
+            }
+        }
+        else {
+            System.out.println("file not exist");
+        }
 
         userModelService.removeModelByID(id);
         return Result.success();

+ 2 - 1
src/main/java/com/kexun/mapper/UserModelMapper.java

@@ -2,7 +2,8 @@ package com.kexun.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.kexun.entity.UserModel;
+import org.springframework.data.repository.query.Param;
 
 public interface UserModelMapper extends BaseMapper<UserModel> {
-
+    void changeModelNameQuery(@Param("modelName") String modelName, @Param("modelNo") long modelNo);
 }

+ 2 - 0
src/main/java/com/kexun/service/UserModelService.java

@@ -13,4 +13,6 @@ public interface UserModelService extends IService<UserModel> {
     UserModel findByUserAndModel(String user_name,String model_name);
     UserModel findByID(long id);
     void removeModelByID(long id);
+
+    void changeModelName(String modelName,long modelNo);
 }

+ 8 - 2
src/main/java/com/kexun/service/impl/UserModelServiceImpl.java

@@ -3,16 +3,19 @@ package com.kexun.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.kexun.entity.UserModel;
+import com.kexun.mapper.CooperatorProductMapper;
 import com.kexun.mapper.UserModelMapper;
 import com.kexun.service.UserModelService;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.List;
 @Service
 public class UserModelServiceImpl extends ServiceImpl<UserModelMapper,UserModel>
         implements UserModelService
 {
-
+    @Resource
+    UserModelMapper userModelMapper;
     @Override
     public List<UserModel> findByUserName(String user_name) {
 
@@ -51,6 +54,9 @@ public class UserModelServiceImpl extends ServiceImpl<UserModelMapper,UserModel>
         QueryWrapper<UserModel> wrapper=new QueryWrapper<UserModel>().eq("id",id);
         remove(wrapper);
     }
-
+    @Override
+    public void changeModelName(String modelName,long modelNo){
+        userModelMapper.changeModelNameQuery(modelName,modelNo);
+    }
 
 }

+ 6 - 0
src/main/resources/mapper/UserModelMapper.xml

@@ -25,4 +25,10 @@
         id,create_by,model_name,
         model_no,status,model_type,model_rule,file_path,create_time
     </sql>
+
+    <select id="changeModelNameQuery" >
+        UPDATE model
+        SET model.model_name=#{modelName}
+        WHERE model.model_no=#{modelNo}
+    </select>
 </mapper>