PatentDigProjectFilesService.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package cn.cslg.pas.service.business;
  2. import cn.cslg.pas.common.dto.business.PatentDigProjectFilesDTO;
  3. import cn.cslg.pas.common.dto.business.UpdatePatentDigProjectFilesDTO;
  4. import cn.cslg.pas.common.model.cronModel.Personnel;
  5. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  6. import cn.cslg.pas.common.model.cronModel.Records;
  7. import cn.cslg.pas.common.model.request.GroupRequest;
  8. import cn.cslg.pas.common.model.request.QueryRequest;
  9. import cn.cslg.pas.common.utils.CacheUtils;
  10. import cn.cslg.pas.common.utils.LoginUtils;
  11. import cn.cslg.pas.common.vo.business.PatentDigProjectFilesVO;
  12. import cn.cslg.pas.domain.business.PatentDigProjectFiles;
  13. import cn.cslg.pas.exception.UnLoginException;
  14. import cn.cslg.pas.exception.XiaoShiException;
  15. import cn.cslg.pas.factorys.businessFactory.Business;
  16. import cn.cslg.pas.mapper.PatentDigProjectFilesMapper;
  17. import cn.cslg.pas.service.permissions.PermissionService;
  18. import cn.cslg.pas.service.query.FormatQueryService;
  19. import com.alibaba.fastjson.JSONObject;
  20. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  21. import org.springframework.beans.BeanUtils;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import java.io.IOException;
  26. import java.util.ArrayList;
  27. import java.util.List;
  28. /**
  29. * 专利挖掘项目文件Service层
  30. * @Author xiexiang
  31. * @Date 2023/11/8
  32. */
  33. @Service
  34. public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFilesMapper, PatentDigProjectFiles> implements Business {
  35. @Autowired
  36. private CacheUtils cacheUtils;
  37. @Autowired
  38. private LoginUtils loginUtils;
  39. @Autowired
  40. private FormatQueryService formatQueryService;
  41. @Autowired
  42. private PatentDigProjectFilesMapper patentDigProjectFilesMapper;
  43. @Autowired
  44. private PermissionService permissionService;
  45. @Override
  46. public Object queryMessage(QueryRequest queryRequest) throws Exception {
  47. //根据专题库/报告id查询自定义栏位
  48. List<String> sqls = formatQueryService.reSqls(queryRequest,"patentDigProjectFiles");
  49. //根据sql查询自定义栏位信息
  50. List<PatentDigProjectFilesVO> patentDigProjectFilesVOS = patentDigProjectFilesMapper.getPatentDigProjectFiles(sqls.get(0), sqls.get(1), sqls.get(2));
  51. //查询总数
  52. Long total = patentDigProjectFilesMapper.getPatentDigProjectFilesCount(sqls.get(0));
  53. //装载自定义栏位信息
  54. this.loadPatentDigProjectFiles(patentDigProjectFilesVOS);
  55. //装载返回信息
  56. Records records = new Records();
  57. records.setCurrent(queryRequest.getCurrent());
  58. records.setSize(queryRequest.getSize());
  59. records.setData(patentDigProjectFilesVOS);
  60. records.setTotal(total);
  61. return records;
  62. }
  63. @Override
  64. public Object addMessage(Object object, List<MultipartFile> files) {
  65. return null;
  66. }
  67. @Override
  68. public Object deleteMessage(List<Integer> ids) throws IOException {
  69. return null;
  70. }
  71. @Override
  72. public Object updateMessage(Object object, List<MultipartFile> files) {
  73. return null;
  74. }
  75. @Override
  76. public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
  77. return null;
  78. }
  79. @Override
  80. public Object addMessage(Object object) {
  81. if (object.equals(null)) {
  82. throw new XiaoShiException("传入参数不能为空");
  83. }
  84. PatentDigProjectFilesDTO patentDigProjectFilesDTO = (PatentDigProjectFilesDTO) object;
  85. if (patentDigProjectFilesDTO.getProjectId() == null) {
  86. throw new XiaoShiException("projectId不能为空");
  87. }
  88. if (patentDigProjectFilesDTO.getFileGuid() == null && patentDigProjectFilesDTO.getFileGuid().equals("")) {
  89. throw new XiaoShiException("文件名guid不能为空");
  90. }
  91. // if (patentDigProjectFilesDTO.getType()==null) {
  92. // throw new XiaoShiException("文件类型不能为空");
  93. // }
  94. PatentDigProjectFiles patentDigProjectFiles = new PatentDigProjectFiles();
  95. BeanUtils.copyProperties(patentDigProjectFilesDTO, patentDigProjectFiles);
  96. //获取登陆人信息 用于设置创建人
  97. PersonnelVO personnelVO = new PersonnelVO();
  98. try {
  99. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  100. } catch (Exception e) {
  101. throw new UnLoginException("未登录");
  102. }
  103. patentDigProjectFiles.setCreateId(personnelVO.getId());
  104. patentDigProjectFiles.insert();
  105. return patentDigProjectFiles.getId();
  106. }
  107. @Override
  108. public Object updateMessage(Object object) {
  109. if (object == null) {
  110. throw new XiaoShiException("传入参数不能为空");
  111. }
  112. UpdatePatentDigProjectFilesDTO updatePatentDigProjectFilesDTO = (UpdatePatentDigProjectFilesDTO) object;
  113. if (updatePatentDigProjectFilesDTO.getProjectId() == null) {
  114. throw new XiaoShiException("projectId不能为空");
  115. }
  116. // if (updatePatentDigProjectFilesDTO.getType() == null) {
  117. // throw new XiaoShiException("文件类型不能为空");
  118. // }
  119. PatentDigProjectFiles patentDigProjectFiles = this.getById(updatePatentDigProjectFilesDTO.getId());
  120. BeanUtils.copyProperties(updatePatentDigProjectFilesDTO, patentDigProjectFiles);
  121. patentDigProjectFiles.updateById();
  122. return patentDigProjectFiles.getId();
  123. }
  124. /**
  125. * 装载
  126. * @param patentDigProjectFilesVOS
  127. */
  128. private void loadPatentDigProjectFiles(List<PatentDigProjectFilesVO> patentDigProjectFilesVOS) throws IOException {
  129. List<String> createIds = new ArrayList<>();
  130. patentDigProjectFilesVOS.forEach(
  131. item -> {
  132. if (item.getCreateId() != null) {
  133. createIds.add(item.getCreateId());
  134. }
  135. }
  136. );
  137. List<Personnel> personnels = new ArrayList<>();
  138. //查询创建人名称
  139. if (createIds.size() != 0) {
  140. String res = permissionService.getPersonnelByIdsFromPCS(createIds);
  141. JSONObject jsonObject = JSONObject.parseObject(res);
  142. personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
  143. }
  144. for (PatentDigProjectFilesVO patentDigProjectFilesVO : patentDigProjectFilesVOS) {
  145. //装载人员信息
  146. Personnel personnel = personnels.stream().filter(item -> item.getId().equals(patentDigProjectFilesVO.getCreateId())).findFirst().orElse(null);
  147. if (personnel != null) {
  148. patentDigProjectFilesVO.setCreateName(personnel.getPersonnelName());
  149. } else {
  150. throw new XiaoShiException("未获取到当前登陆人信息");
  151. }
  152. }
  153. }
  154. }