MouldMaintainServiceImpl.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package com.hssx.cloudmodel.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.github.pagehelper.PageHelper;
  4. import com.github.pagehelper.PageInfo;
  5. import com.hssx.cloudmodel.constant.Constant;
  6. import com.hssx.cloudmodel.entity.*;
  7. import com.hssx.cloudmodel.entity.vo.MouldFileVO;
  8. import com.hssx.cloudmodel.entity.vo.MouldVO;
  9. import com.hssx.cloudmodel.entity.vo.UserVO;
  10. import com.hssx.cloudmodel.mapper.*;
  11. import com.hssx.cloudmodel.service.MouldMaintainService;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import com.hssx.cloudmodel.util.FileUtil;
  14. import com.hssx.cloudmodel.util.HttpRespMsg;
  15. import com.hssx.cloudmodel.util.PageUtil;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.web.multipart.MultipartFile;
  18. import javax.annotation.Resource;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.UUID;
  24. /**
  25. * @author 吴涛涛
  26. * @since 2019-08-13
  27. */
  28. @Service
  29. public class MouldMaintainServiceImpl extends ServiceImpl<MouldMaintainMapper, MouldMaintain> implements MouldMaintainService {
  30. @Resource
  31. UserMapper userMapper;
  32. @Resource
  33. MouldMaintainMapper mouldMaintainMapper;
  34. @Resource
  35. CompanyMapper companyMapper;
  36. @Resource
  37. CustomCompanyMapper customCompanyMapper;
  38. @Resource
  39. MouldMapper mouldMapper;
  40. @Resource
  41. ProjectApproveMapper projectApproveMapper;
  42. @Resource
  43. ProjectMapper projectMapper;
  44. @Resource
  45. ProjectUserMapper projectUserMapper;
  46. @Override
  47. public HttpRespMsg addMaintain(MultipartFile file, String path, MouldMaintain mouldMaintain, String token) {
  48. HttpRespMsg msg = new HttpRespMsg();
  49. Mould mould = mouldMapper.selectById(mouldMaintain.getMouldId());
  50. User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
  51. if (user != null) {
  52. if (file != null && !file.isEmpty()) {
  53. File dir = null;
  54. dir = new File(path);
  55. // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
  56. if (!dir.exists()) {
  57. dir.mkdirs();
  58. }
  59. String fileName = "";
  60. if (file != null && !file.isEmpty()) {
  61. fileName = file.getOriginalFilename();
  62. mouldMaintain.setFileName(fileName);
  63. mouldMaintain.setFileSize(FileUtil.getReadableFileSize(file.getSize()));
  64. System.out.println("上传文件名称" + file.getName() + ", dir = " + dir.getAbsolutePath());
  65. int pos = fileName.lastIndexOf(".");
  66. String rand = UUID.randomUUID().toString().replaceAll("-", "");
  67. String sufix = fileName.substring(pos);
  68. fileName = rand + sufix;
  69. mouldMaintain.setMaintainUserId(user.getId());
  70. mouldMaintain.setMaintainUserName(user.getUsername());
  71. mouldMaintain.setFileUrl("/upload/" + fileName);
  72. if(mould.getProjectId() != null){
  73. mouldMaintain.setProjectId(mould.getProjectId());
  74. }
  75. File saveFile = new File(dir, fileName);
  76. mouldMaintainMapper.insert(mouldMaintain);
  77. try {
  78. saveFile.createNewFile();
  79. file.transferTo(saveFile);
  80. } catch (IOException e) {
  81. e.printStackTrace();
  82. mouldMaintain = null;
  83. } catch (Exception e) {
  84. e.printStackTrace();
  85. mouldMaintain = null;
  86. }
  87. }
  88. msg.data = mouldMaintain;
  89. }
  90. }
  91. return msg;
  92. }
  93. @Override
  94. public HttpRespMsg getList(UserVO userVO, PageUtil page) {
  95. HttpRespMsg msg = new HttpRespMsg();
  96. List<Integer> proIds = new ArrayList<>();
  97. User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", userVO.getToken()));
  98. List<MouldMaintain> mouldMaintains = new ArrayList<>();
  99. if (currentUser != null) {
  100. PageHelper.startPage(page.getPageNum(), page.getPageSize());
  101. mouldMaintains = mouldMaintainMapper.selectList(new QueryWrapper<MouldMaintain>().eq("mould_id",userVO.getMouldId()));
  102. // //资产方管理员,获取他公司下的所有模具
  103. // PageHelper.startPage(page.getPageNum(), page.getPageSize());
  104. // if (Constant.SYS_ID == currentUser.getParentId()) {
  105. // QueryWrapper<Project> qw = new QueryWrapper<>();
  106. // List<Project> projects = projectMapper.selectList(qw.eq("creator_id", currentUser.getId()));
  107. // for (Project pro : projects) {
  108. // proIds.add(pro.getId());
  109. // }
  110. // mouldMaintains = mouldMaintainMapper.selectListByProject(proIds);
  111. // } else if (Constant.SYS_PARENT_ID == currentUser.getParentId()) {
  112. // //系统管理员
  113. // mouldMaintains = mouldMaintainMapper.selectList(new QueryWrapper<MouldMaintain>());
  114. // } else {
  115. // QueryWrapper<Project> qw = new QueryWrapper<>();
  116. // qw.eq("manager_id", currentUser.getId());
  117. // List<Project> projects = projectMapper.selectList(qw);
  118. // if (projects.size() > 0) {
  119. // for (Project project : projects) {
  120. // proIds.add(project.getId());
  121. // }
  122. // }
  123. //// //充当普通人员参与的项目
  124. // List<ProjectUser> projectUsers = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("user_id",currentUser.getId()));
  125. // if (projectUsers.size() > 0) {
  126. // for (ProjectUser projectUser : projectUsers) {
  127. // proIds.add(projectUser.getProjectId());
  128. // }
  129. // }
  130. // //充当审批人员参与的项目
  131. // List<ProjectApprove> projectss = projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>().eq("approver_id", currentUser.getId()));
  132. // if (projectss.size() > 0) {
  133. // for (ProjectApprove projectUser : projectss) {
  134. // proIds.add(projectUser.getProjectId());
  135. // }
  136. // }
  137. // mouldMaintains = mouldMaintainMapper.selectListByProject(proIds);
  138. // }
  139. PageInfo<MouldMaintain> pageInfos = new PageInfo<>(mouldMaintains);
  140. msg.data = pageInfos;
  141. } else {
  142. msg.setError("用户不存在或者未登录");
  143. }
  144. return msg;
  145. }
  146. }