123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- package cn.cslg.pas.service.business;
- import cn.cslg.pas.common.dto.business.PatentDigProjectFilesDTO;
- import cn.cslg.pas.common.dto.business.UpdatePatentDigProjectFilesDTO;
- 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.request.GroupRequest;
- import cn.cslg.pas.common.model.request.QueryRequest;
- import cn.cslg.pas.common.utils.CacheUtils;
- import cn.cslg.pas.common.utils.LoginUtils;
- import cn.cslg.pas.common.vo.business.PatentDigProjectFilesVO;
- import cn.cslg.pas.domain.business.PatentDigProjectFiles;
- import cn.cslg.pas.exception.UnLoginException;
- import cn.cslg.pas.exception.XiaoShiException;
- import cn.cslg.pas.factorys.businessFactory.Business;
- import cn.cslg.pas.mapper.PatentDigProjectFilesMapper;
- import cn.cslg.pas.service.permissions.PermissionService;
- import cn.cslg.pas.service.query.FormatQueryService;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 专利挖掘项目文件Service层
- * @Author xiexiang
- * @Date 2023/11/8
- */
- @Service
- public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFilesMapper, PatentDigProjectFiles> implements Business {
- @Autowired
- private CacheUtils cacheUtils;
- @Autowired
- private LoginUtils loginUtils;
- @Autowired
- private FormatQueryService formatQueryService;
- @Autowired
- private PatentDigProjectFilesMapper patentDigProjectFilesMapper;
- @Autowired
- private PermissionService permissionService;
- @Override
- public Object queryMessage(QueryRequest queryRequest) throws Exception {
- //根据专题库/报告id查询自定义栏位
- List<String> sqls = formatQueryService.reSqls(queryRequest,"patentDigProjectFiles");
- //根据sql查询自定义栏位信息
- List<PatentDigProjectFilesVO> patentDigProjectFilesVOS = patentDigProjectFilesMapper.getPatentDigProjectFiles(sqls.get(0), sqls.get(1), sqls.get(2));
- //查询总数
- Long total = patentDigProjectFilesMapper.getPatentDigProjectFilesCount(sqls.get(0));
- //装载自定义栏位信息
- this.loadPatentDigProjectFiles(patentDigProjectFilesVOS);
- //装载返回信息
- Records records = new Records();
- records.setCurrent(queryRequest.getCurrent());
- records.setSize(queryRequest.getSize());
- records.setData(patentDigProjectFilesVOS);
- records.setTotal(total);
- return records;
- }
- @Override
- public Object addMessage(Object object, List<MultipartFile> files) {
- return null;
- }
- @Override
- public Object deleteMessage(List<Integer> ids) throws IOException {
- return null;
- }
- @Override
- public Object updateMessage(Object object, List<MultipartFile> files) {
- return null;
- }
- @Override
- public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
- return null;
- }
- @Override
- public Object addMessage(Object object) {
- if (object.equals(null)) {
- throw new XiaoShiException("传入参数不能为空");
- }
- PatentDigProjectFilesDTO patentDigProjectFilesDTO = (PatentDigProjectFilesDTO) object;
- if (patentDigProjectFilesDTO.getProjectId() == null) {
- throw new XiaoShiException("projectId不能为空");
- }
- if (patentDigProjectFilesDTO.getFileGuid() == null && patentDigProjectFilesDTO.getFileGuid().equals("")) {
- throw new XiaoShiException("文件名guid不能为空");
- }
- // if (patentDigProjectFilesDTO.getType()==null) {
- // throw new XiaoShiException("文件类型不能为空");
- // }
- PatentDigProjectFiles patentDigProjectFiles = new PatentDigProjectFiles();
- BeanUtils.copyProperties(patentDigProjectFilesDTO, patentDigProjectFiles);
- //获取登陆人信息 用于设置创建人
- PersonnelVO personnelVO = new PersonnelVO();
- try {
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- } catch (Exception e) {
- throw new UnLoginException("未登录");
- }
- patentDigProjectFiles.setCreateId(personnelVO.getId());
- patentDigProjectFiles.insert();
- return patentDigProjectFiles.getId();
- }
- @Override
- public Object updateMessage(Object object) {
- if (object == null) {
- throw new XiaoShiException("传入参数不能为空");
- }
- UpdatePatentDigProjectFilesDTO updatePatentDigProjectFilesDTO = (UpdatePatentDigProjectFilesDTO) object;
- if (updatePatentDigProjectFilesDTO.getProjectId() == null) {
- throw new XiaoShiException("projectId不能为空");
- }
- // if (updatePatentDigProjectFilesDTO.getType() == null) {
- // throw new XiaoShiException("文件类型不能为空");
- // }
- PatentDigProjectFiles patentDigProjectFiles = this.getById(updatePatentDigProjectFilesDTO.getId());
- BeanUtils.copyProperties(updatePatentDigProjectFilesDTO, patentDigProjectFiles);
- patentDigProjectFiles.updateById();
- return patentDigProjectFiles.getId();
- }
- /**
- * 装载
- * @param patentDigProjectFilesVOS
- */
- private void loadPatentDigProjectFiles(List<PatentDigProjectFilesVO> patentDigProjectFilesVOS) throws IOException {
- List<String> createIds = new ArrayList<>();
- patentDigProjectFilesVOS.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 (PatentDigProjectFilesVO patentDigProjectFilesVO : patentDigProjectFilesVOS) {
- //装载人员信息
- Personnel personnel = personnels.stream().filter(item -> item.getId().equals(patentDigProjectFilesVO.getCreateId())).findFirst().orElse(null);
- if (personnel != null) {
- patentDigProjectFilesVO.setCreateName(personnel.getPersonnelName());
- } else {
- throw new XiaoShiException("未获取到当前登陆人信息");
- }
- }
- }
- }
|