123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- package cn.cslg.pas.service.business;
- import cn.cslg.pas.common.dto.business.GetReferencesDTO;
- import cn.cslg.pas.common.dto.business.ReferencesDTO;
- import cn.cslg.pas.common.dto.business.ReferencesUpdateDTO;
- 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.model.request.OrderDTO;
- import cn.cslg.pas.common.utils.CacheUtils;
- import cn.cslg.pas.common.utils.LoginUtils;
- import cn.cslg.pas.common.vo.business.ReferencesVO;
- import cn.cslg.pas.domain.business.Project;
- import cn.cslg.pas.domain.business.References;
- import cn.cslg.pas.domain.business.ReportProject;
- import cn.cslg.pas.exception.UnLoginException;
- import cn.cslg.pas.exception.XiaoShiException;
- import cn.cslg.pas.mapper.ReferencesMapper;
- 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.conditions.query.QueryWrapper;
- 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.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @Author xiexiang
- * @Date 2023/12/19
- */
- @Slf4j
- @Service
- public class ReferencesService extends ServiceImpl<ReferencesMapper, References> {
- @Autowired
- private CacheUtils cacheUtils;
- @Autowired
- private LoginUtils loginUtils;
- @Autowired
- private FileManagerService fileManagerService;
- @Autowired
- private PermissionService permissionService;
- @Autowired
- private ProjectService projectService;
- /**
- * 上传报告文档
- * @param referencesDTO
- * @return
- */
- public Integer add(ReferencesDTO referencesDTO){
- if (referencesDTO != null) {
- //获取登录人信息
- PersonnelVO personnelVO = new PersonnelVO();
- personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
- References references = new References();
- if (StringUtils.isEmpty(referencesDTO.getFileGuid())) {
- throw new XiaoShiException("附件不得为空");
- }
- BeanUtils.copyProperties(referencesDTO, references);
- references.setCreateId(personnelVO.getId());
- references.insert();
- return references.getId();
- } else {
- throw new XiaoShiException("入参为空");
- }
- }
- /**
- * 更新
- * @param referencesUpdateDTO
- * @return
- */
- public Integer update(ReferencesUpdateDTO referencesUpdateDTO){
- if (referencesUpdateDTO != null) {
- Integer id = referencesUpdateDTO.getId();
- References references = this.getById(id);
- BeanUtils.copyProperties(referencesUpdateDTO, references);
- references.updateById();
- return references.getId();
- } else {
- throw new XiaoShiException("入参为空");
- }
- }
- /**
- * 删除
- * @param ids
- */
- public void delete(List<Integer> ids){
- if (!ids.isEmpty()) {
- this.removeBatchByIds(ids);
- }
- }
- /**
- * 查询
- * @param getReferencesDTO
- * @return
- */
- public Records query(GetReferencesDTO getReferencesDTO) {
- //初始化
- Integer projectId = getReferencesDTO.getProjectId();
- String fileName = getReferencesDTO.getFileName();
- Integer pageNum = getReferencesDTO.getCurrent();
- Integer pageSize = getReferencesDTO.getSize();
- List<OrderDTO> orderDTOList = getReferencesDTO.getOrderDTOList();
- //分页配置
- Page<References> page = new Page<>(pageNum, pageSize);
- QueryWrapper<References> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(References::getProjectId, projectId);
- if (fileName != null && !fileName.equals("")) {
- queryWrapper.lambda().like(References::getReferencesName, fileName);
- }
- //添加排序逻辑
- if (!orderDTOList.isEmpty() && orderDTOList.size() == 1) {
- OrderDTO orderDTO = orderDTOList.get(0);
- String orderByField = orderDTO.getOrderBy();
- String column = this.getColumns(orderByField);
- boolean isTrue = orderDTO.getOrderType() == 0 ? true : false;
- if (orderByField != null && !orderByField.equals("")) {
- queryWrapper.orderBy(true, isTrue, column);
- }
- } else {
- queryWrapper.orderBy(true, true, "create_time");
- }
- IPage<References> referencesPage = this.page(page, queryWrapper);
- List<References> references = referencesPage.getRecords();
- List<ReferencesVO> referencesVOS = this.loadReferencesVO(references);
- Records records = new Records();
- records.setData(referencesVOS);
- records.setCurrent((long)pageNum);
- records.setSize((long)pageSize);
- records.setTotal(referencesPage.getTotal());
- return records;
- }
- public List<ReferencesVO> loadReferencesVO(List<References> references){
- List<ReferencesVO> referencesVOS = new ArrayList<>();
- if (!references.isEmpty()) {
- List<String> fileGuids = new ArrayList<>();
- List<String> createIds = new ArrayList<>();
- List<Integer> projectIds = new ArrayList<>();
- references.forEach(item -> {
- if (item.getProjectId() != null) {
- projectIds.add(item.getProjectId());
- }
- if (item.getFileGuid() != null) {
- fileGuids.add(item.getFileGuid());
- }
- if (item.getCreateId() != null) {
- createIds.add(item.getCreateId());
- }
- });
- if (!fileGuids.isEmpty()) {
- List<Personnel> personnels = new ArrayList<>();
- List<SystemFile> systemFiles = new ArrayList<>();
- List<Project> projects = new ArrayList<>();
- try {
- //查询创建人名称
- if (createIds.size() != 0) {
- String res = permissionService.getPersonnelByIdsFromPCS(createIds);
- JSONObject jsonObject = JSONObject.parseObject(res);
- personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
- }
- } catch (Exception e) {
- throw new XiaoShiException("查询创建人信息错误");
- }
- try {
- String res = fileManagerService.getSystemFileFromFMS(fileGuids);
- systemFiles = JSONObject.parseArray(res, SystemFile.class);
- } catch (Exception e) {
- throw new XiaoShiException("查询文件信息错误");
- }
- LambdaQueryWrapper<Project> queryWrapper1 = new LambdaQueryWrapper<>();
- queryWrapper1.in(Project::getId, projectIds);
- projects = projectService.list(queryWrapper1);
- for (References item : references) {
- ReferencesVO referencesVO = new ReferencesVO();
- BeanUtils.copyProperties(item, referencesVO);
- Project project = projects
- .stream()
- .filter(p -> p.getId() != null && p.getId().equals(item.getProjectId()))
- .findFirst()
- .orElse(null);
- if (project !=null) {
- referencesVO.setProjectName(project.getName());
- }
- if (!CollectionUtils.isEmpty(systemFiles)) {
- SystemFile systemFile = systemFiles
- .stream()
- .filter(file -> file.getGuid() != null && file.getGuid().equals(item.getFileGuid()))
- .findFirst()
- .orElse(null);
- if (systemFile != null) {
- referencesVO.setType(systemFile.getType());
- }
- }
- Personnel personnel = personnels
- .stream()
- .filter(person -> person.getId() != null && person.getId().equals(item.getCreateId()))
- .findFirst()
- .orElse(null);
- if (personnel != null) {
- referencesVO.setCreateName(personnel.getPersonnelName());
- }
- referencesVOS.add(referencesVO);
- }
- }
- }
- return referencesVOS;
- }
- public String getColumns(String column){
- Map<String, String> map = new HashMap<>();
- map.put("remark","remark");
- map.put("projectName","project_id");
- map.put("fileGuid","file_guid");
- map.put("referencesName","references_name");
- map.put("createName","create_id");
- map.put("createTime","create_time");
- String reStr = map.get(column);
- return reStr;
- }
- }
|