quyueting 5 роки тому
батько
коміт
a4340fbb07

+ 84 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldFileController.java

@@ -0,0 +1,84 @@
+package com.hssx.cloudmodel.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.hssx.cloudmodel.entity.User;
+import com.hssx.cloudmodel.entity.vo.UserVO;
+import com.hssx.cloudmodel.service.MouldFileService;
+import com.hssx.cloudmodel.service.MouldService;
+import com.hssx.cloudmodel.service.UserService;
+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;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-08-07
+ */
+@RestController
+@RequestMapping("/mould-file")
+public class MouldFileController {
+
+    @Value("${upload.path}")
+    private String path;
+    @Autowired
+    private MouldFileService mouldFileService;
+    @Autowired
+    private UserService userService;
+    /**
+     * 模具文档的上传
+     * 参数: token 用户身份凭证,projectId 项目id ,file 文件信息
+     *
+     * @return
+     */
+    @ApiOperation("模具文档的上传")
+    @RequestMapping("/uploadFile")
+    @ResponseBody
+    public HttpRespMsg 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 = mouldFileService.addFile(userVO,file,path);
+        return msg;
+    }
+
+
+    @ApiOperation("模具文档的审核")
+    @RequestMapping("/check")
+    @ResponseBody
+    public HttpRespMsg check(@RequestParam Integer mouldFileId,@RequestParam Integer isPass,
+                                  HttpServletResponse response, HttpServletRequest request, UserVO userVO) throws Exception {
+        HttpRespMsg msg = new HttpRespMsg();
+        msg = mouldFileService.check(mouldFileId,isPass, userVO);
+        return msg;
+    }
+
+    /**
+     * 项目文档的列表
+     * 参数: token 用户身份凭证,projectId 项目id
+     *
+     * @return
+     */
+    @ApiOperation("模具文档的列表")
+    @RequestMapping("/list")
+    @ResponseBody
+    public HttpRespMsg list(@RequestParam Integer mouldId,  UserVO userVO){
+        HttpRespMsg msg = mouldFileService.getFileList(mouldId, userVO);
+        return msg;
+    }
+}
+

+ 230 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/entity/MouldFile.java

@@ -0,0 +1,230 @@
+package com.hssx.cloudmodel.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-08-07
+ */
+@TableName("tb_mould_file")
+public class MouldFile extends Model<MouldFile> {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 上传人id
+     */
+    @TableField("uplodtor_id")
+    private Integer uplodtorId;
+
+    /**
+     * 上传人名字
+     */
+    @TableField("uploadtor")
+    private String uploadtor;
+
+    /**
+     * 上传时间
+     */
+    @TableField("indate")
+    private LocalDateTime indate;
+
+    /**
+     * 模具id
+     */
+    @TableField("model_id")
+    private Integer modelId;
+
+    /**
+     * 项目名称
+     */
+    @TableField("project_id")
+    private Integer projectId;
+
+    /**
+     * 文件地址
+     */
+    @TableField("file_url")
+    private String fileUrl;
+
+    /**
+     * 文件名称
+     */
+    @TableField("file_name")
+    private String fileName;
+
+    /**
+     * 所述文件类型,0-模具文档 1-模具产品验收 2-磨具保养作业操作方案 2-模具保养 3-模具更新 4-模具报废
+     */
+    @TableField("blong_type")
+    private Integer blongType;
+
+    /**
+     * 说明
+     */
+    @TableField("content")
+    private String content;
+
+    /**
+     * 审批状态: 0-待审核,1-资产方审核通过,2-生产方审核通过,3-双方审核通过,-1资产方审核不通过,-2生产方审核不通过
+     */
+    @TableField("state")
+    private Integer state;
+
+    /**
+     * 文件类型
+     */
+    @TableField("file_type")
+    private String fileType;
+
+    /**
+     * 文件大小
+     */
+    @TableField("file_size")
+    private String fileSize;
+
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getUplodtorId() {
+        return uplodtorId;
+    }
+
+    public void setUplodtorId(Integer uplodtorId) {
+        this.uplodtorId = uplodtorId;
+    }
+
+    public String getUploadtor() {
+        return uploadtor;
+    }
+
+    public void setUploadtor(String uploadtor) {
+        this.uploadtor = uploadtor;
+    }
+
+    public LocalDateTime getIndate() {
+        return indate;
+    }
+
+    public void setIndate(LocalDateTime indate) {
+        this.indate = indate;
+    }
+
+    public Integer getModelId() {
+        return modelId;
+    }
+
+    public void setModelId(Integer modelId) {
+        this.modelId = modelId;
+    }
+
+    public Integer getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(Integer projectId) {
+        this.projectId = projectId;
+    }
+
+    public String getFileUrl() {
+        return fileUrl;
+    }
+
+    public void setFileUrl(String fileUrl) {
+        this.fileUrl = fileUrl;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public Integer getBlongType() {
+        return blongType;
+    }
+
+    public void setBlongType(Integer blongType) {
+        this.blongType = blongType;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public Integer getState() {
+        return state;
+    }
+
+    public void setState(Integer state) {
+        this.state = state;
+    }
+
+    public String getFileType() {
+        return fileType;
+    }
+
+    public void setFileType(String fileType) {
+        this.fileType = fileType;
+    }
+
+    public String getFileSize() {
+        return fileSize;
+    }
+
+    public void setFileSize(String fileSize) {
+        this.fileSize = fileSize;
+    }
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+    @Override
+    public String toString() {
+        return "MouldFile{" +
+        "id=" + id +
+        ", uplodtorId=" + uplodtorId +
+        ", uploadtor=" + uploadtor +
+        ", indate=" + indate +
+        ", modelId=" + modelId +
+        ", projectId=" + projectId +
+        ", fileUrl=" + fileUrl +
+        ", fileName=" + fileName +
+        ", blongType=" + blongType +
+        ", content=" + content +
+        ", state=" + state +
+        ", fileType=" + fileType +
+        ", fileSize=" + fileSize +
+        "}";
+    }
+}

+ 16 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/mapper/MouldFileMapper.java

@@ -0,0 +1,16 @@
+package com.hssx.cloudmodel.mapper;
+
+import com.hssx.cloudmodel.entity.MouldFile;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-08-07
+ */
+public interface MouldFileMapper extends BaseMapper<MouldFile> {
+
+}

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

@@ -0,0 +1,24 @@
+package com.hssx.cloudmodel.service;
+
+import com.hssx.cloudmodel.entity.MouldFile;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.hssx.cloudmodel.entity.ProjectFile;
+import com.hssx.cloudmodel.entity.vo.UserVO;
+import com.hssx.cloudmodel.util.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-08-07
+ */
+public interface MouldFileService extends IService<MouldFile> {
+    HttpRespMsg addFile(UserVO userVO, MultipartFile file, String path);
+    HttpRespMsg check(Integer mouldFileId, Integer isPass, UserVO userVO);
+    HttpRespMsg dowloadFile(MouldFile projectFile, String token);
+
+    HttpRespMsg getFileList(int mouldId, UserVO userVO);
+}

+ 170 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -0,0 +1,170 @@
+package com.hssx.cloudmodel.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.hssx.cloudmodel.constant.Constant;
+import com.hssx.cloudmodel.entity.MouldFile;
+import com.hssx.cloudmodel.entity.ProjectFile;
+import com.hssx.cloudmodel.entity.ProjectOperationDynamics;
+import com.hssx.cloudmodel.entity.User;
+import com.hssx.cloudmodel.entity.vo.UserVO;
+import com.hssx.cloudmodel.mapper.MouldFileMapper;
+import com.hssx.cloudmodel.mapper.ProjectFileMapper;
+import com.hssx.cloudmodel.mapper.ProjectOperationDynamicsMapper;
+import com.hssx.cloudmodel.mapper.UserMapper;
+import com.hssx.cloudmodel.service.MouldFileService;
+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.List;
+import java.util.UUID;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2019-08-07
+ */
+@Service
+public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile> implements MouldFileService {
+
+
+    @Resource
+    UserMapper userMapper;
+    @Resource
+    MouldFileMapper mouldFileMapper;
+    @Resource
+    ProjectOperationDynamicsMapper projectOperationDynamicsMapper;
+
+    @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()) {
+                MouldFile projectFile = new MouldFile();
+                projectFile.setUplodtorId(user.getId());
+                projectFile.setUploadtor(user.getUsername());
+                projectFile.setModelId(userVO.getMouldId());
+                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.setFileUrl("/upload/"+fileName);
+                    projectFile.setBlongType(0);
+                    if (user.getSubordinateType() == 0) {
+                        //上传人为资产方,自动审核通过
+                        projectFile.setState(1);
+                    } else if (user.getSubordinateType() == 1) {
+                        //上传人为生产方,自动审核通过
+                        projectFile.setState(2);
+                    } else {
+                        projectFile.setState(0);
+                    }
+
+                    File saveFile = new File(dir, fileName);
+                    mouldFileMapper.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("当前用户不存在或者未登录");
+        }
+        return msg;
+    }
+
+    @Override
+    public HttpRespMsg check(Integer mouldFileId, Integer isPass, UserVO userVO) {
+        HttpRespMsg msg = new HttpRespMsg();
+        User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
+        MouldFile mf = new MouldFile();
+        mf.setId(mouldFileId);
+        MouldFile oldData = mouldFileMapper.selectById(mouldFileId);
+        if(user != null){
+            if (user.getSubordinateType() == 0) {
+                //资产方
+                if (isPass == 1) {
+                    if (oldData.getState() == 2) {//生产方也审核通过了
+                        mf.setState(3);
+                    } else {
+                        mf.setState(1);
+                    }
+                } else {
+                    mf.setState(-1);
+                }
+                mouldFileMapper.updateById(mf);
+            } else if (user.getSubordinateType() == 1) {
+                //生产方
+                if (isPass == 1) {
+                    if (oldData.getState() == 1) {//资产方也审核通过了
+                        mf.setState(3);
+                    } else {
+                        mf.setState(2);
+                    }
+                } else {
+                    mf.setState(-2);
+                }
+                mouldFileMapper.updateById(mf);
+            } else {
+                msg.setError("只有生产方和资产方才能审核, subordinteType = " + user.getSubordinateType() + ", 无效!");
+            }
+
+
+        }
+        return msg;
+    }
+
+    @Override
+    public HttpRespMsg dowloadFile(MouldFile projectFile, String token) {
+        HttpRespMsg msg = new HttpRespMsg();
+        User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
+        return null;
+    }
+
+    @Override
+    public HttpRespMsg getFileList(int mouldId, UserVO userVO) {
+        HttpRespMsg msg = new HttpRespMsg();
+        User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
+        List<MouldFile> list = mouldFileMapper.selectList(new QueryWrapper<MouldFile>().eq("model_id", mouldId).orderByDesc("id"));
+        msg.data = list;
+        return msg;
+    }
+}

+ 27 - 0
cloud-model/src/main/resources/mapper/MouldFileMapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.hssx.cloudmodel.mapper.MouldFileMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.hssx.cloudmodel.entity.MouldFile">
+        <id column="id" property="id" />
+        <result column="uplodtor_id" property="uplodtorId" />
+        <result column="uploadtor" property="uploadtor" />
+        <result column="indate" property="indate" />
+        <result column="model_id" property="modelId" />
+        <result column="project_id" property="projectId" />
+        <result column="file_url" property="fileUrl" />
+        <result column="file_name" property="fileName" />
+        <result column="blong_type" property="blongType" />
+        <result column="content" property="content" />
+        <result column="state" property="state" />
+        <result column="file_type" property="fileType" />
+        <result column="file_size" property="fileSize" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, uplodtor_id, uploadtor, indate, model_id, project_id, file_url, file_name, blong_type, content, state, file_type, file_size
+    </sql>
+
+</mapper>