123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package cn.cslg.pas.service.business;
- import cn.cslg.pas.common.dto.business.OtherReferencesDTO;
- import cn.cslg.pas.common.model.cronModel.Personnel;
- import cn.cslg.pas.common.model.cronModel.PersonnelVO;
- import cn.cslg.pas.common.utils.CacheUtils;
- import cn.cslg.pas.common.utils.LoginUtils;
- import cn.cslg.pas.common.utils.StringUtils;
- import cn.cslg.pas.common.vo.business.LitigationHistoryVO;
- import cn.cslg.pas.common.vo.business.OtherReferencesVO;
- import cn.cslg.pas.domain.business.AssoOtherReferencesFile;
- import cn.cslg.pas.domain.business.LitigationHistory;
- import cn.cslg.pas.domain.business.OtherReferences;
- import cn.cslg.pas.exception.XiaoShiException;
- import cn.cslg.pas.mapper.OtherReferencesMapper;
- import cn.cslg.pas.service.permissions.PermissionService;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * 其他参考资料
- * @Author xiexiang
- * @Date 2024/1/17
- */
- @Slf4j
- @Service
- public class OtherReferencesService extends ServiceImpl<OtherReferencesMapper, OtherReferences> {
- @Autowired
- private LoginUtils loginUtils;
- @Autowired
- private CacheUtils cacheUtils;
- @Autowired
- private PermissionService permissionService;
- @Autowired
- private AssoOtherReferencesFileService assoReferencesFileService;
- /**
- * 新增or更新其他参考资料
- * @param otherReferencesDTO
- * @return
- */
- public Integer saveOrUpdate(OtherReferencesDTO otherReferencesDTO){
- if (otherReferencesDTO == null) {
- throw new XiaoShiException("入参为空");
- }
- Integer id = otherReferencesDTO.getId();
- List<String> fileGuids = otherReferencesDTO.getFileGuids();
- OtherReferences otherReferences = new OtherReferences();
- if (id != null) {
- //update
- otherReferences = this.getById(id);
- BeanUtils.copyProperties(otherReferencesDTO, otherReferences);
- otherReferences.updateById();
- //先删除 后添加
- LambdaQueryWrapper<AssoOtherReferencesFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(AssoOtherReferencesFile::getOtherReferencesId, id);
- assoReferencesFileService.remove(queryWrapper);
- if (!fileGuids.isEmpty()) {
- List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids);
- }
- } else {
- BeanUtils.copyProperties(otherReferencesDTO, otherReferences);
- PersonnelVO personnelVO = new PersonnelVO();
- try {
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- } catch (Exception e) {
- throw new XiaoShiException("未查询到当前登陆人");
- }
- otherReferences.setCreateId(personnelVO.getId());
- otherReferences.insert();
- if (!fileGuids.isEmpty()) {
- //先删除 后添加
- List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids);
- }
- }
- return otherReferences.getId();
- }
- /**
- * 新增文件与其他参考资料关联
- * @param id
- * @param fileGuids
- * @return
- */
- public List<Integer> addFile(Integer id, List<String> fileGuids){
- List<Integer> ids = new ArrayList<>();
- if (!fileGuids.isEmpty()) {
- List<AssoOtherReferencesFile> assoOtherReferencesFiles = new ArrayList<>();
- fileGuids.forEach(item -> {
- AssoOtherReferencesFile assoOtherReferencesFile = new AssoOtherReferencesFile();
- assoOtherReferencesFile.setOtherReferencesId(id);
- assoOtherReferencesFile.setFileGuid(item);
- assoOtherReferencesFiles.add(assoOtherReferencesFile);
- });
- assoReferencesFileService.saveBatch(assoOtherReferencesFiles);
- }
- return ids;
- }
- /**
- * 查询
- * @param patentNo
- * @return
- * @throws IOException
- */
- public List<OtherReferencesVO> getOtherReferences(String patentNo) throws IOException {
- if (patentNo == null || StringUtils.isEmpty(patentNo)) {
- throw new XiaoShiException("入参为空");
- }
- List<OtherReferencesVO> otherReferencesVOS = new ArrayList<>();
- LambdaQueryWrapper<OtherReferences> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(OtherReferences::getPatentNo, patentNo);
- List<OtherReferences> otherReferencesList = this.list(queryWrapper);
- if (!otherReferencesList.isEmpty()) {
- otherReferencesList.forEach(item -> {
- OtherReferencesVO otherReferencesVO = new OtherReferencesVO();
- BeanUtils.copyProperties(item, otherReferencesVO);
- otherReferencesVOS.add(otherReferencesVO);
- });
- this.loadOtherReferencesVOS(otherReferencesVOS);
- }
- return otherReferencesVOS;
- }
- /**
- * 装载查询其他参考资料
- * @param otherReferencesVOS
- * @throws IOException
- */
- public void loadOtherReferencesVOS(List<OtherReferencesVO> otherReferencesVOS) throws IOException {
- List<String> createIds = new ArrayList<>();
- otherReferencesVOS.forEach(item -> {
- if (item.getCreateId() != null) {
- createIds.add(item.getCreateId());
- }
- });
- List<Personnel> personnels = new ArrayList<>();
- //查询发起人名称
- if (createIds.size() != 0) {
- String res = permissionService.getPersonnelByIdsFromPCS(createIds);
- JSONObject jsonObject = JSONObject.parseObject(res);
- personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
- }
- //装载信息
- for (OtherReferencesVO otherReferencesVO : otherReferencesVOS) {
- //装载人员信息
- Personnel personnel = personnels.stream().filter(item -> item.getId().equals(otherReferencesVO.getCreateId())).findFirst().orElse(null);
- if (personnel != null) {
- otherReferencesVO.setCreateName(personnel.getPersonnelName());
- }
- LambdaQueryWrapper<AssoOtherReferencesFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(AssoOtherReferencesFile::getOtherReferencesId, otherReferencesVO.getId());
- List<AssoOtherReferencesFile> assoOtherReferencesFiles = assoReferencesFileService.list(queryWrapper);
- if (!assoOtherReferencesFiles.isEmpty()) {
- List<String> fileGuids = assoOtherReferencesFiles.stream().map(AssoOtherReferencesFile::getFileGuid).collect(Collectors.toList());
- otherReferencesVO.setFileGuids(fileGuids);
- }
- }
- }
- /**
- * 删除其他参考资料
- * @param ids
- * @return
- */
- public List<Integer> deleteOtherReferences(List<Integer> ids) {
- if (!ids.isEmpty()) {
- //先删除附件
- LambdaQueryWrapper<AssoOtherReferencesFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(AssoOtherReferencesFile::getOtherReferencesId, ids);
- assoReferencesFileService.remove(queryWrapper);
- this.removeBatchByIds(ids);
- }
- return ids;
- }
- }
|