Explorar o código

修改项目列表

%!s(int64=5) %!d(string=hai) anos
pai
achega
d9bf8536fe

+ 8 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/ProjectController.java

@@ -3,18 +3,25 @@ package com.hssx.cloudmodel.controller;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.hssx.cloudmodel.entity.Project;
 import com.hssx.cloudmodel.entity.User;
+import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.service.ProjectService;
 import com.hssx.cloudmodel.service.UserService;
 import com.hssx.cloudmodel.util.HttpRespMsg;
 import com.hssx.cloudmodel.util.PageUtil;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
 
 
 /**
@@ -99,5 +106,6 @@ public class ProjectController {
         msg = projectService.getListByUser(token);
         return msg;
     }
+
 }
 

+ 36 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/ProjectFileController.java

@@ -1,9 +1,24 @@
 package com.hssx.cloudmodel.controller;
 
 
+import com.hssx.cloudmodel.entity.vo.UserVO;
+import com.hssx.cloudmodel.service.ProjectFileService;
+import com.hssx.cloudmodel.util.HttpRespMsg;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
 
 /**
  * <p>
@@ -17,5 +32,26 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/projectfile")
 public class ProjectFileController {
 
+    @Value("${upload.path}")
+    private String path;
+    @Autowired
+    private ProjectFileService projectFileService;
+
+    /**
+     * 项目文档的上传
+     * 参数: token 用户身份凭证,项目id
+     *
+     * @return
+     */
+    @ApiOperation("项目文档的上传")
+    @RequestMapping("/uploadFile")
+    @ResponseBody
+    public Object uploadFile(@RequestParam(required = false) MultipartFile file,
+                             HttpServletResponse response, HttpServletRequest request, UserVO userVO) throws Exception {
+        System.out.println("开始上传文件" + "file+" + file.getOriginalFilename());
+        HttpRespMsg msg = new HttpRespMsg();
+        msg = projectFileService.addFile(userVO,file,path);
+        return msg;
+    }
 }
 

+ 1 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/entity/vo/UserVO.java

@@ -11,7 +11,6 @@ import lombok.Data;
  * Version: 1.0
  */
 @Data
-@Builder
 public class UserVO extends User {
     private String companyName;
     private String roleName;
@@ -19,6 +18,7 @@ public class UserVO extends User {
     private Integer searchType;//搜索类型0-模具编号,1-模具名称
     private Integer projectId;
     private Integer companyId;
+    private String token;
     private Integer isManager = 0;
     private String powers;
 }

+ 4 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/ProjectFileService.java

@@ -2,6 +2,9 @@ package com.hssx.cloudmodel.service;
 
 import com.hssx.cloudmodel.entity.ProjectFile;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.hssx.cloudmodel.entity.vo.UserVO;
+import com.hssx.cloudmodel.util.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * <p>
@@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface ProjectFileService extends IService<ProjectFile> {
 
+    HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path);
 }

+ 65 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/ProjectFileServiceImpl.java

@@ -1,10 +1,22 @@
 package com.hssx.cloudmodel.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.hssx.cloudmodel.entity.ProjectFile;
+import com.hssx.cloudmodel.entity.User;
+import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.mapper.ProjectFileMapper;
+import com.hssx.cloudmodel.mapper.UserMapper;
 import com.hssx.cloudmodel.service.ProjectFileService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hssx.cloudmodel.util.FileUtil;
+import com.hssx.cloudmodel.util.HttpRespMsg;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
 
 /**
  * <p>
@@ -17,4 +29,57 @@ import org.springframework.stereotype.Service;
 @Service
 public class ProjectFileServiceImpl extends ServiceImpl<ProjectFileMapper, ProjectFile> implements ProjectFileService {
 
+    @Resource
+    UserMapper userMapper;
+    @Resource
+    ProjectFileMapper projectFileMapper;
+
+    @Override
+    public HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path) {
+        HttpRespMsg msg = new HttpRespMsg();
+        User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
+        if(user != null){
+            if (file != null && !file.isEmpty()) {
+                ProjectFile projectFile = new ProjectFile();
+                projectFile.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();
+                    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;
+                    }
+                }
+                msg.data = projectFile;
+            }
+        }else{
+            msg.setError("当前用户不存在或者未登录");
+        }
+        return msg;
+    }
 }

+ 26 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/util/FileUtil.java

@@ -0,0 +1,26 @@
+package com.hssx.cloudmodel.util;
+
+public class FileUtil {
+
+	/**
+	 * 获取容易识别的文件大小,比如KB, MB, GB
+	 * @param size
+	 * @return
+	 */
+	public static String getReadableFileSize(long size) {
+		if (size < 1024) {//1K以内
+			return size + "byte";
+		} else if (size < 1024 * 1024) {//1M以内
+			return String.format("%.1fKB", (size*1.0f/1024));
+		} else if (size < 1024 * 1024 * 1024) {//1G以内
+			return String.format("%.1fMB", (size*1.0f/1024/1024));
+		} else {
+			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));
+	}
+}

+ 1 - 1
cloud-model/src/main/resources/application.properties

@@ -34,7 +34,7 @@ spring.thymeleaf.prefix=classpath:/static/
 #spring.redis.port=6379
 ######################################################################################################
 # 文件上传路径
-upload.path=D:/cloud/upload/
+upload.path=D:/mould/upload/
 #######################################################################################################
 # 配置上传文件的大小设置
 # Single file max size  即单个文件大小

+ 49 - 1
cloud-model/src/main/resources/mapper/ProjectMapper.xml

@@ -36,7 +36,7 @@
         <result column="manager" property="manager" />
         <!--以下是分页插件的一对多-->
         <collection property="customCompanies" javaType="java.util.List" ofType="com.hssx.cloudmodel.entity.CustomCompany"
-                    select="queryCustomCompaniesId" column="id" notNullColumn="company_id">
+                    select="queryCustomCompaniesId" column="id">
         </collection>
     </resultMap>
 <!-- 以上一对多的映射-->
@@ -194,4 +194,52 @@
       GROUP BY tbpu.user_id ,tbpu.project_id;
       order by tbpu.user_id
     </select>
+
+    <resultMap id="BaseResultMapPower" type="com.hssx.cloudmodel.entity.vo.ProjectVO">
+        <id column="id" property="id" />
+        <result column="project_name" property="projectName" />
+        <result column="project_id" property="projectId" />
+        <result column="user_id" property="userId" />
+        <result column="company_name" property="companyName" />
+        <result column="powerString" property="powerString" />
+        <collection property="customCompanies" javaType="java.util.List" ofType="com.hssx.cloudmodel.entity.CustomCompany"
+                    select="queryPowerByUserIdAndProject" column="{id,user_id}">
+        </collection>
+    </resultMap>
+    
+    <select id="">
+        SELECT
+        tbpu.user_id ,tbpu.project_id ,GROUP_CONCAT(tbpu.power_type) powerString,
+        tbu.username ,tbc.company_name,
+        tbp.project_name
+        FROM `tb_power` tbpu
+        left join
+        tb_project tbp
+        on tbp.id = tbpu.project_id
+        left join
+        tb_user tbu
+        on tbpu.user_id = tbu.id
+        left join
+        tb_company tbc
+        on tbc.id = tbu.company_id
+        <where>
+            <if test="user.projectId != null">
+                tbpu.project_id = #{user.projectId}
+            </if>
+            <if test="user.companyId != null">
+                tbpu.project_id = #{user.companyId}
+            </if>
+            <if test="user.keyName != null and user.keyName != ''">
+                tbu.username like concat('%',#{user.keyName},'%')
+            </if>
+            <if test="type == 0">
+                tbp.creator_id = #{user.id}
+            </if>
+            <if test="type == 1">
+                tbp.manager_id = #{user.id}
+            </if>
+        </where>
+        GROUP BY tbpu.user_id ,tbpu.project_id;
+        order by tbpu.user_id
+    </select>
 </mapper>