OtherReferencesService.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package cn.cslg.pas.service.business;
  2. import cn.cslg.pas.common.dto.business.OtherReferencesDTO;
  3. import cn.cslg.pas.common.model.cronModel.Personnel;
  4. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  5. import cn.cslg.pas.common.utils.CacheUtils;
  6. import cn.cslg.pas.common.utils.LoginUtils;
  7. import cn.cslg.pas.common.utils.StringUtils;
  8. import cn.cslg.pas.common.vo.business.LitigationHistoryVO;
  9. import cn.cslg.pas.common.vo.business.OtherReferencesVO;
  10. import cn.cslg.pas.domain.business.AssoOtherReferencesFile;
  11. import cn.cslg.pas.domain.business.LitigationHistory;
  12. import cn.cslg.pas.domain.business.OtherReferences;
  13. import cn.cslg.pas.exception.XiaoShiException;
  14. import cn.cslg.pas.mapper.OtherReferencesMapper;
  15. import cn.cslg.pas.service.permissions.PermissionService;
  16. import com.alibaba.fastjson.JSONObject;
  17. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  18. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.BeanUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import java.io.IOException;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. /**
  28. * 其他参考资料
  29. * @Author xiexiang
  30. * @Date 2024/1/17
  31. */
  32. @Slf4j
  33. @Service
  34. public class OtherReferencesService extends ServiceImpl<OtherReferencesMapper, OtherReferences> {
  35. @Autowired
  36. private LoginUtils loginUtils;
  37. @Autowired
  38. private CacheUtils cacheUtils;
  39. @Autowired
  40. private PermissionService permissionService;
  41. @Autowired
  42. private AssoOtherReferencesFileService assoReferencesFileService;
  43. /**
  44. * 新增or更新其他参考资料
  45. * @param otherReferencesDTO
  46. * @return
  47. */
  48. public Integer saveOrUpdate(OtherReferencesDTO otherReferencesDTO){
  49. if (otherReferencesDTO == null) {
  50. throw new XiaoShiException("入参为空");
  51. }
  52. Integer id = otherReferencesDTO.getId();
  53. List<String> fileGuids = otherReferencesDTO.getFileGuids();
  54. OtherReferences otherReferences = new OtherReferences();
  55. if (id != null) {
  56. //update
  57. otherReferences = this.getById(id);
  58. BeanUtils.copyProperties(otherReferencesDTO, otherReferences);
  59. otherReferences.updateById();
  60. //先删除 后添加
  61. LambdaQueryWrapper<AssoOtherReferencesFile> queryWrapper = new LambdaQueryWrapper<>();
  62. queryWrapper.eq(AssoOtherReferencesFile::getOtherReferencesId, id);
  63. assoReferencesFileService.remove(queryWrapper);
  64. if (!fileGuids.isEmpty()) {
  65. List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids);
  66. }
  67. } else {
  68. BeanUtils.copyProperties(otherReferencesDTO, otherReferences);
  69. PersonnelVO personnelVO = new PersonnelVO();
  70. try {
  71. personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  72. } catch (Exception e) {
  73. throw new XiaoShiException("未查询到当前登陆人");
  74. }
  75. otherReferences.setCreateId(personnelVO.getId());
  76. otherReferences.insert();
  77. if (!fileGuids.isEmpty()) {
  78. //先删除 后添加
  79. List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids);
  80. }
  81. }
  82. return otherReferences.getId();
  83. }
  84. /**
  85. * 新增文件与其他参考资料关联
  86. * @param id
  87. * @param fileGuids
  88. * @return
  89. */
  90. public List<Integer> addFile(Integer id, List<String> fileGuids){
  91. List<Integer> ids = new ArrayList<>();
  92. if (!fileGuids.isEmpty()) {
  93. List<AssoOtherReferencesFile> assoOtherReferencesFiles = new ArrayList<>();
  94. fileGuids.forEach(item -> {
  95. AssoOtherReferencesFile assoOtherReferencesFile = new AssoOtherReferencesFile();
  96. assoOtherReferencesFile.setOtherReferencesId(id);
  97. assoOtherReferencesFile.setFileGuid(item);
  98. assoOtherReferencesFiles.add(assoOtherReferencesFile);
  99. });
  100. assoReferencesFileService.saveBatch(assoOtherReferencesFiles);
  101. }
  102. return ids;
  103. }
  104. /**
  105. * 查询
  106. * @param patentNo
  107. * @return
  108. * @throws IOException
  109. */
  110. public List<OtherReferencesVO> getOtherReferences(String patentNo) throws IOException {
  111. if (patentNo == null || StringUtils.isEmpty(patentNo)) {
  112. throw new XiaoShiException("入参为空");
  113. }
  114. List<OtherReferencesVO> otherReferencesVOS = new ArrayList<>();
  115. LambdaQueryWrapper<OtherReferences> queryWrapper = new LambdaQueryWrapper<>();
  116. queryWrapper.eq(OtherReferences::getPatentNo, patentNo);
  117. List<OtherReferences> otherReferencesList = this.list(queryWrapper);
  118. if (!otherReferencesList.isEmpty()) {
  119. otherReferencesList.forEach(item -> {
  120. OtherReferencesVO otherReferencesVO = new OtherReferencesVO();
  121. BeanUtils.copyProperties(item, otherReferencesVO);
  122. otherReferencesVOS.add(otherReferencesVO);
  123. });
  124. this.loadOtherReferencesVOS(otherReferencesVOS);
  125. }
  126. return otherReferencesVOS;
  127. }
  128. /**
  129. * 装载查询其他参考资料
  130. * @param otherReferencesVOS
  131. * @throws IOException
  132. */
  133. public void loadOtherReferencesVOS(List<OtherReferencesVO> otherReferencesVOS) throws IOException {
  134. List<String> createIds = new ArrayList<>();
  135. otherReferencesVOS.forEach(item -> {
  136. if (item.getCreateId() != null) {
  137. createIds.add(item.getCreateId());
  138. }
  139. });
  140. List<Personnel> personnels = new ArrayList<>();
  141. //查询发起人名称
  142. if (createIds.size() != 0) {
  143. String res = permissionService.getPersonnelByIdsFromPCS(createIds);
  144. JSONObject jsonObject = JSONObject.parseObject(res);
  145. personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
  146. }
  147. //装载信息
  148. for (OtherReferencesVO otherReferencesVO : otherReferencesVOS) {
  149. //装载人员信息
  150. Personnel personnel = personnels.stream().filter(item -> item.getId().equals(otherReferencesVO.getCreateId())).findFirst().orElse(null);
  151. if (personnel != null) {
  152. otherReferencesVO.setCreateName(personnel.getPersonnelName());
  153. }
  154. LambdaQueryWrapper<AssoOtherReferencesFile> queryWrapper = new LambdaQueryWrapper<>();
  155. queryWrapper.eq(AssoOtherReferencesFile::getOtherReferencesId, otherReferencesVO.getId());
  156. List<AssoOtherReferencesFile> assoOtherReferencesFiles = assoReferencesFileService.list(queryWrapper);
  157. if (!assoOtherReferencesFiles.isEmpty()) {
  158. List<String> fileGuids = assoOtherReferencesFiles.stream().map(AssoOtherReferencesFile::getFileGuid).collect(Collectors.toList());
  159. otherReferencesVO.setFileGuids(fileGuids);
  160. }
  161. }
  162. }
  163. /**
  164. * 删除其他参考资料
  165. * @param ids
  166. * @return
  167. */
  168. public List<Integer> deleteOtherReferences(List<Integer> ids) {
  169. if (!ids.isEmpty()) {
  170. //先删除附件
  171. LambdaQueryWrapper<AssoOtherReferencesFile> queryWrapper = new LambdaQueryWrapper<>();
  172. queryWrapper.in(AssoOtherReferencesFile::getOtherReferencesId, ids);
  173. assoReferencesFileService.remove(queryWrapper);
  174. this.removeBatchByIds(ids);
  175. }
  176. return ids;
  177. }
  178. }