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