|
@@ -0,0 +1,149 @@
|
|
|
|
+package com.hssx.cloudmodel.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
+import com.hssx.cloudmodel.constant.Constant;
|
|
|
|
+import com.hssx.cloudmodel.entity.*;
|
|
|
|
+import com.hssx.cloudmodel.entity.vo.MouldFileVO;
|
|
|
|
+import com.hssx.cloudmodel.entity.vo.MouldVO;
|
|
|
|
+import com.hssx.cloudmodel.mapper.*;
|
|
|
|
+import com.hssx.cloudmodel.service.MouldMaintainService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.hssx.cloudmodel.util.FileUtil;
|
|
|
|
+import com.hssx.cloudmodel.util.HttpRespMsg;
|
|
|
|
+import com.hssx.cloudmodel.util.PageUtil;
|
|
|
|
+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.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author 吴涛涛
|
|
|
|
+ * @since 2019-08-13
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class MouldMaintainServiceImpl extends ServiceImpl<MouldMaintainMapper, MouldMaintain> implements MouldMaintainService {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ UserMapper userMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ MouldMaintainMapper mouldMaintainMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ CompanyMapper companyMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ CustomCompanyMapper customCompanyMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ MouldMapper mouldMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ ProjectApproveMapper projectApproveMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ ProjectMapper projectMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ ProjectUserMapper projectUserMapper;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg addMaintain(MultipartFile file, String path, MouldMaintain mouldMaintain, String token) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ Mould mould = mouldMapper.selectById(mouldMaintain.getMouldId());
|
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
|
|
|
|
+ if (user != null) {
|
|
|
|
+ if (file != null && !file.isEmpty()) {
|
|
|
|
+ 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();
|
|
|
|
+ mouldMaintain.setFileName(fileName);
|
|
|
|
+ mouldMaintain.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;
|
|
|
|
+ mouldMaintain.setMaintainUserId(user.getId());
|
|
|
|
+ mouldMaintain.setMaintainUserName(user.getUsername());
|
|
|
|
+ mouldMaintain.setFileUrl("/upload/" + fileName);
|
|
|
|
+ if(mould.getProjectId() != null){
|
|
|
|
+ mouldMaintain.setProjectId(mould.getProjectId());
|
|
|
|
+ }
|
|
|
|
+ File saveFile = new File(dir, fileName);
|
|
|
|
+ mouldMaintainMapper.insert(mouldMaintain);
|
|
|
|
+ try {
|
|
|
|
+ saveFile.createNewFile();
|
|
|
|
+ file.transferTo(saveFile);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ mouldMaintain = null;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ mouldMaintain = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ msg.data = mouldMaintain;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getList(String token, PageUtil page) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ List<Integer> proIds = new ArrayList<>();
|
|
|
|
+ User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
|
|
|
|
+ List<MouldMaintain> mouldMaintains = new ArrayList<>();
|
|
|
|
+ if (currentUser != null) {
|
|
|
|
+ //资产方管理员,获取他公司下的所有模具
|
|
|
|
+ PageHelper.startPage(page.getPageNum(), page.getPageSize());
|
|
|
|
+ if (Constant.SYS_ID == currentUser.getParentId()) {
|
|
|
|
+ QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
|
+ List<Project> projects = projectMapper.selectList(qw.eq("creator_id", currentUser.getId()));
|
|
|
|
+ for (Project pro : projects) {
|
|
|
|
+ proIds.add(pro.getId());
|
|
|
|
+ }
|
|
|
|
+ mouldMaintains = mouldMaintainMapper.selectListByProject(proIds);
|
|
|
|
+ } else if (Constant.SYS_PARENT_ID == currentUser.getParentId()) {
|
|
|
|
+ //系统管理员
|
|
|
|
+ mouldMaintains = mouldMaintainMapper.selectList(new QueryWrapper<MouldMaintain>());
|
|
|
|
+ } else {
|
|
|
|
+ QueryWrapper<Project> qw = new QueryWrapper<>();
|
|
|
|
+ qw.eq("manager_id", currentUser.getId());
|
|
|
|
+ List<Project> projects = projectMapper.selectList(qw);
|
|
|
|
+ if (projects.size() > 0) {
|
|
|
|
+ for (Project project : projects) {
|
|
|
|
+ proIds.add(project.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+// //充当普通人员参与的项目
|
|
|
|
+ List<ProjectUser> projectUsers = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().eq("user_id",currentUser.getId()));
|
|
|
|
+ if (projectUsers.size() > 0) {
|
|
|
|
+ for (ProjectUser projectUser : projectUsers) {
|
|
|
|
+ proIds.add(projectUser.getProjectId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //充当审批人员参与的项目
|
|
|
|
+ List<ProjectApprove> projectss = projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>().eq("approver_id", currentUser.getId()));
|
|
|
|
+ if (projectss.size() > 0) {
|
|
|
|
+ for (ProjectApprove projectUser : projectss) {
|
|
|
|
+ proIds.add(projectUser.getProjectId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mouldMaintains = mouldMaintainMapper.selectListByProject(proIds);
|
|
|
|
+ }
|
|
|
|
+ PageInfo<MouldMaintain> pageInfos = new PageInfo<>(mouldMaintains);
|
|
|
|
+ msg.data = pageInfos;
|
|
|
|
+ } else {
|
|
|
|
+ msg.setError("用户不存在或者未登录");
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ }
|