123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- package cn.cslg.pas.service.business;
- import cn.cslg.pas.common.dto.business.OtherPatentInfoDTO;
- 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.model.cronModel.Records;
- import cn.cslg.pas.common.model.cronModel.SystemFile;
- 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.OtherReferencesVO;
- import cn.cslg.pas.domain.business.AssoOtherPatentInfoFile;
- import cn.cslg.pas.domain.business.OtherReferences;
- import cn.cslg.pas.domain.business.ReviewHistory;
- import cn.cslg.pas.exception.XiaoShiException;
- import cn.cslg.pas.mapper.OtherReferencesMapper;
- import cn.cslg.pas.service.common.FileManagerService;
- import cn.cslg.pas.service.permissions.PermissionService;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- 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 AssoOtherPatentInfoFileService assoOtherPatentInfoFileService;
- @Autowired
- private FileManagerService fileManagerService;
- /**
- * 新增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();
- Integer type = 1;
- if (id != null) {
- //update
- otherReferences = this.getById(id);
- BeanUtils.copyProperties(otherReferencesDTO, otherReferences);
- otherReferences.updateById();
- //先删除 后添加
- LambdaQueryWrapper<AssoOtherPatentInfoFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(AssoOtherPatentInfoFile::getOtherPatentInfoId, id)
- .eq(AssoOtherPatentInfoFile::getType, type);
- assoOtherPatentInfoFileService.remove(queryWrapper);
- if (fileGuids != null && !fileGuids.isEmpty()) {
- List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids, type);
- }
- } 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.setTenantId(personnelVO.getTenantId());
- otherReferences.insert();
- if (fileGuids != null && !fileGuids.isEmpty()) {
- //先删除 后添加
- List<Integer> fileIds = this.addFile(otherReferences.getId(), fileGuids, type);
- }
- }
- return otherReferences.getId();
- }
- /**
- * 新增文件与其他参考资料关联
- * @param id
- * @param fileGuids
- * @param type
- * @return
- */
- public List<Integer> addFile(Integer id, List<String> fileGuids, Integer type){
- List<Integer> ids = new ArrayList<>();
- if (!fileGuids.isEmpty()) {
- List<AssoOtherPatentInfoFile> assoOtherPatentInfoFiles = new ArrayList<>();
- fileGuids.forEach(item -> {
- AssoOtherPatentInfoFile assoOtherPatentInfoFile = new AssoOtherPatentInfoFile();
- assoOtherPatentInfoFile.setOtherPatentInfoId(id);
- assoOtherPatentInfoFile.setType(type);
- assoOtherPatentInfoFile.setFileGuid(item);
- assoOtherPatentInfoFiles.add(assoOtherPatentInfoFile);
- });
- assoOtherPatentInfoFileService.saveBatch(assoOtherPatentInfoFiles);
- ids = assoOtherPatentInfoFiles.stream().map(AssoOtherPatentInfoFile::getId).collect(Collectors.toList());
- }
- return ids;
- }
- /**
- * 分页查询
- * @param otherPatentInfoDTO
- * @return
- * @throws IOException
- */
- public Records getOtherReferences(OtherPatentInfoDTO otherPatentInfoDTO) throws IOException {
- List<OtherReferencesVO> otherReferencesVOS = new ArrayList<>();
- String patentNo = otherPatentInfoDTO.getPatentNo();
- if (patentNo == null || StringUtils.isEmpty(patentNo)) {
- throw new XiaoShiException("入参为空");
- }
- Integer current = otherPatentInfoDTO.getCurrent();
- Integer size = otherPatentInfoDTO.getSize();
- Page<OtherReferences> page = new Page<>(current, size);
- PersonnelVO personnelVO = new PersonnelVO();
- try {
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- } catch (Exception e) {
- throw new XiaoShiException("未查询到当前登陆人");
- }
- LambdaQueryWrapper<OtherReferences> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(OtherReferences::getPatentNo, patentNo)
- .eq(OtherReferences::getTenantId, personnelVO.getTenantId());
- IPage<OtherReferences> otherReferencesPage = this.page(page, queryWrapper);
- List<OtherReferences> otherReferencesList = otherReferencesPage.getRecords();
- long total = otherReferencesPage.getTotal();
- if (!otherReferencesList.isEmpty()) {
- otherReferencesList.forEach(item -> {
- OtherReferencesVO otherReferencesVO = new OtherReferencesVO();
- BeanUtils.copyProperties(item, otherReferencesVO);
- otherReferencesVOS.add(otherReferencesVO);
- });
- this.loadOtherReferencesVOS(otherReferencesVOS);
- }
- Records records = new Records();
- records.setTotal(total);
- records.setCurrent((long)current);
- records.setSize((long) size);
- records.setData(otherReferencesVOS);
- return records;
- }
- /**
- * 装载查询其他参考资料
- * @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<AssoOtherPatentInfoFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(AssoOtherPatentInfoFile::getOtherPatentInfoId, otherReferencesVO.getId())
- .eq(AssoOtherPatentInfoFile::getType, 1);
- List<AssoOtherPatentInfoFile> assoOtherPatentInfoFiles = assoOtherPatentInfoFileService.list(queryWrapper);
- if (!assoOtherPatentInfoFiles.isEmpty()) {
- List<String> fileGuids = assoOtherPatentInfoFiles.stream().map(AssoOtherPatentInfoFile::getFileGuid).collect(Collectors.toList());
- otherReferencesVO.setFileGuids(fileGuids);
- List<SystemFile> systemFiles = new ArrayList<>();
- if (fileGuids.size() != 0) {
- String res = fileManagerService.getSystemFileFromFMS(fileGuids);
- systemFiles = JSONObject.parseArray(res, SystemFile.class);
- }
- if (!systemFiles.isEmpty()) {
- otherReferencesVO.setSystemFileList(systemFiles);
- }
- }
- }
- }
- /**
- * 删除其他参考资料
- * @param ids
- * @return
- */
- public List<Integer> deleteOtherReferences(List<Integer> ids) {
- if (!ids.isEmpty()) {
- //先删除附件
- LambdaQueryWrapper<AssoOtherPatentInfoFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(AssoOtherPatentInfoFile::getOtherPatentInfoId, ids)
- .eq(AssoOtherPatentInfoFile::getType, 1);
- assoOtherPatentInfoFileService.remove(queryWrapper);
- this.removeBatchByIds(ids);
- }
- return ids;
- }
- }
|