OtherReferencesService.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package cn.cslg.pas.service.business;
  2. import cn.cslg.pas.common.dto.business.OtherPatentInfoDTO;
  3. import cn.cslg.pas.common.dto.business.OtherReferencesDTO;
  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.cronModel.SystemFile;
  8. import cn.cslg.pas.common.utils.CacheUtils;
  9. import cn.cslg.pas.common.utils.LoginUtils;
  10. import cn.cslg.pas.common.utils.StringUtils;
  11. import cn.cslg.pas.common.vo.business.OtherReferencesVO;
  12. import cn.cslg.pas.domain.business.AssoOtherPatentInfoFile;
  13. import cn.cslg.pas.domain.business.OtherReferences;
  14. import cn.cslg.pas.domain.business.ReviewHistory;
  15. import cn.cslg.pas.exception.XiaoShiException;
  16. import cn.cslg.pas.mapper.OtherReferencesMapper;
  17. import cn.cslg.pas.service.common.FileManagerService;
  18. import cn.cslg.pas.service.permissions.PermissionService;
  19. import com.alibaba.fastjson.JSONObject;
  20. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  21. import com.baomidou.mybatisplus.core.metadata.IPage;
  22. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  23. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import java.io.IOException;
  29. import java.util.ArrayList;
  30. import java.util.List;
  31. import java.util.stream.Collectors;
  32. /**
  33. * 其他参考资料
  34. * @Author xiexiang
  35. * @Date 2024/1/17
  36. */
  37. @Slf4j
  38. @Service
  39. public class OtherReferencesService extends ServiceImpl<OtherReferencesMapper, OtherReferences> {
  40. @Autowired
  41. private LoginUtils loginUtils;
  42. @Autowired
  43. private CacheUtils cacheUtils;
  44. @Autowired
  45. private PermissionService permissionService;
  46. @Autowired
  47. private AssoOtherPatentInfoFileService assoOtherPatentInfoFileService;
  48. @Autowired
  49. private FileManagerService fileManagerService;
  50. /**
  51. * 新增or更新其他参考资料
  52. * @param otherReferencesDTO
  53. * @return
  54. */
  55. public Integer saveOrUpdate(OtherReferencesDTO otherReferencesDTO){
  56. if (otherReferencesDTO == null) {
  57. throw new XiaoShiException("入参为空");
  58. }
  59. Integer id = otherReferencesDTO.getId();
  60. List<String> fileGuids = otherReferencesDTO.getFileGuids();
  61. OtherReferences otherReferences = new OtherReferences();
  62. Integer type = 1;
  63. if (id != null) {
  64. //update
  65. otherReferences = this.getById(id);
  66. BeanUtils.copyProperties(otherReferencesDTO, otherReferences);
  67. otherReferences.updateById();
  68. //先删除 后添加
  69. LambdaQueryWrapper<AssoOtherPatentInfoFile> queryWrapper = new LambdaQueryWrapper<>();
  70. queryWrapper.eq(AssoOtherPatentInfoFile::getOtherPatentInfoId, id)
  71. .eq(AssoOtherPatentInfoFile::getType, type);
  72. assoOtherPatentInfoFileService.remove(queryWrapper);
  73. if (fileGuids != null && !fileGuids.isEmpty()) {
  74. List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids, type);
  75. }
  76. } else {
  77. BeanUtils.copyProperties(otherReferencesDTO, otherReferences);
  78. PersonnelVO personnelVO = new PersonnelVO();
  79. try {
  80. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  81. } catch (Exception e) {
  82. throw new XiaoShiException("未查询到当前登陆人");
  83. }
  84. otherReferences.setCreateId(personnelVO.getId());
  85. otherReferences.setTenantId(personnelVO.getTenantId());
  86. otherReferences.insert();
  87. if (fileGuids != null && !fileGuids.isEmpty()) {
  88. //先删除 后添加
  89. List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids, type);
  90. }
  91. }
  92. return otherReferences.getId();
  93. }
  94. /**
  95. * 新增文件与其他参考资料关联
  96. * @param id
  97. * @param fileGuids
  98. * @param type
  99. * @return
  100. */
  101. public List<Integer> addFile(Integer id, List<String> fileGuids, Integer type){
  102. List<Integer> ids = new ArrayList<>();
  103. if (!fileGuids.isEmpty()) {
  104. List<AssoOtherPatentInfoFile> assoOtherPatentInfoFiles = new ArrayList<>();
  105. fileGuids.forEach(item -> {
  106. AssoOtherPatentInfoFile assoOtherPatentInfoFile = new AssoOtherPatentInfoFile();
  107. assoOtherPatentInfoFile.setOtherPatentInfoId(id);
  108. assoOtherPatentInfoFile.setType(type);
  109. assoOtherPatentInfoFile.setFileGuid(item);
  110. assoOtherPatentInfoFiles.add(assoOtherPatentInfoFile);
  111. });
  112. assoOtherPatentInfoFileService.saveBatch(assoOtherPatentInfoFiles);
  113. ids = assoOtherPatentInfoFiles.stream().map(AssoOtherPatentInfoFile::getId).collect(Collectors.toList());
  114. }
  115. return ids;
  116. }
  117. /**
  118. * 分页查询
  119. * @param otherPatentInfoDTO
  120. * @return
  121. * @throws IOException
  122. */
  123. public Records getOtherReferences(OtherPatentInfoDTO otherPatentInfoDTO) throws IOException {
  124. List<OtherReferencesVO> otherReferencesVOS = new ArrayList<>();
  125. String patentNo = otherPatentInfoDTO.getPatentNo();
  126. if (patentNo == null || StringUtils.isEmpty(patentNo)) {
  127. throw new XiaoShiException("入参为空");
  128. }
  129. Integer current = otherPatentInfoDTO.getCurrent();
  130. Integer size = otherPatentInfoDTO.getSize();
  131. Page<OtherReferences> page = new Page<>(current, size);
  132. PersonnelVO personnelVO = new PersonnelVO();
  133. try {
  134. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  135. } catch (Exception e) {
  136. throw new XiaoShiException("未查询到当前登陆人");
  137. }
  138. LambdaQueryWrapper<OtherReferences> queryWrapper = new LambdaQueryWrapper<>();
  139. queryWrapper.eq(OtherReferences::getPatentNo, patentNo)
  140. .eq(OtherReferences::getTenantId, personnelVO.getTenantId());
  141. IPage<OtherReferences> otherReferencesPage = this.page(page, queryWrapper);
  142. List<OtherReferences> otherReferencesList = otherReferencesPage.getRecords();
  143. long total = otherReferencesPage.getTotal();
  144. if (!otherReferencesList.isEmpty()) {
  145. otherReferencesList.forEach(item -> {
  146. OtherReferencesVO otherReferencesVO = new OtherReferencesVO();
  147. BeanUtils.copyProperties(item, otherReferencesVO);
  148. otherReferencesVOS.add(otherReferencesVO);
  149. });
  150. this.loadOtherReferencesVOS(otherReferencesVOS);
  151. }
  152. Records records = new Records();
  153. records.setTotal(total);
  154. records.setCurrent((long)current);
  155. records.setSize((long) size);
  156. records.setData(otherReferencesVOS);
  157. return records;
  158. }
  159. /**
  160. * 装载查询其他参考资料
  161. * @param otherReferencesVOS
  162. * @throws IOException
  163. */
  164. public void loadOtherReferencesVOS(List<OtherReferencesVO> otherReferencesVOS) throws IOException {
  165. List<String> createIds = new ArrayList<>();
  166. otherReferencesVOS.forEach(item -> {
  167. if (item.getCreateId() != null) {
  168. createIds.add(item.getCreateId());
  169. }
  170. });
  171. List<Personnel> personnels = new ArrayList<>();
  172. //查询发起人名称
  173. if (createIds.size() != 0) {
  174. String res = permissionService.getPersonnelByIdsFromPCS(createIds);
  175. JSONObject jsonObject = JSONObject.parseObject(res);
  176. personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
  177. }
  178. //装载信息
  179. for (OtherReferencesVO otherReferencesVO : otherReferencesVOS) {
  180. //装载人员信息
  181. Personnel personnel = personnels.stream().filter(item -> item.getId().equals(otherReferencesVO.getCreateId())).findFirst().orElse(null);
  182. if (personnel != null) {
  183. otherReferencesVO.setCreateName(personnel.getPersonnelName());
  184. }
  185. LambdaQueryWrapper<AssoOtherPatentInfoFile> queryWrapper = new LambdaQueryWrapper<>();
  186. queryWrapper.eq(AssoOtherPatentInfoFile::getOtherPatentInfoId, otherReferencesVO.getId())
  187. .eq(AssoOtherPatentInfoFile::getType, 1);
  188. List<AssoOtherPatentInfoFile> assoOtherPatentInfoFiles = assoOtherPatentInfoFileService.list(queryWrapper);
  189. if (!assoOtherPatentInfoFiles.isEmpty()) {
  190. List<String> fileGuids = assoOtherPatentInfoFiles.stream().map(AssoOtherPatentInfoFile::getFileGuid).collect(Collectors.toList());
  191. otherReferencesVO.setFileGuids(fileGuids);
  192. List<SystemFile> systemFiles = new ArrayList<>();
  193. if (fileGuids.size() != 0) {
  194. String res = fileManagerService.getSystemFileFromFMS(fileGuids);
  195. systemFiles = JSONObject.parseArray(res, SystemFile.class);
  196. }
  197. if (!systemFiles.isEmpty()) {
  198. otherReferencesVO.setSystemFileList(systemFiles);
  199. }
  200. }
  201. }
  202. }
  203. /**
  204. * 删除其他参考资料
  205. * @param ids
  206. * @return
  207. */
  208. public List<Integer> deleteOtherReferences(List<Integer> ids) {
  209. if (!ids.isEmpty()) {
  210. //先删除附件
  211. LambdaQueryWrapper<AssoOtherPatentInfoFile> queryWrapper = new LambdaQueryWrapper<>();
  212. queryWrapper.in(AssoOtherPatentInfoFile::getOtherPatentInfoId, ids)
  213. .eq(AssoOtherPatentInfoFile::getType, 1);
  214. assoOtherPatentInfoFileService.remove(queryWrapper);
  215. this.removeBatchByIds(ids);
  216. }
  217. return ids;
  218. }
  219. }