|
@@ -0,0 +1,148 @@
|
|
|
+package cn.cslg.pas.service;
|
|
|
+
|
|
|
+
|
|
|
+import cn.cslg.pas.common.dto.QuerySearchRecordDTO;
|
|
|
+import cn.cslg.pas.common.dto.business.AddSearchRecordDTO;
|
|
|
+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.utils.CacheUtils;
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.vo.SearchRecordVO;
|
|
|
+import cn.cslg.pas.domain.business.AssoEventFile;
|
|
|
+import cn.cslg.pas.domain.business.SearchRecord;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
+import cn.cslg.pas.mapper.AssoEventFileMapper;
|
|
|
+import cn.cslg.pas.mapper.SearchRecordMapper;
|
|
|
+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.plugins.pagination.Page;
|
|
|
+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 java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 检索记录
|
|
|
+ * lrj
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SearchRecordService extends ServiceImpl<SearchRecordMapper, SearchRecord> {
|
|
|
+ @Autowired
|
|
|
+ private CacheUtils cacheUtils;
|
|
|
+ @Autowired
|
|
|
+ private LoginUtils loginUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PermissionService permissionService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加检索记录
|
|
|
+ *
|
|
|
+ * @param addSearchRecordDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer addSearchRecord(AddSearchRecordDTO addSearchRecordDTO) {
|
|
|
+ if (addSearchRecordDTO == null) {
|
|
|
+ throw new XiaoShiException("请传入数据");
|
|
|
+ }
|
|
|
+ Integer id = addSearchRecordDTO.getId();
|
|
|
+ SearchRecord searchRecord = new SearchRecord();
|
|
|
+ BeanUtils.copyProperties(addSearchRecordDTO, searchRecord);
|
|
|
+ if (id != null) {
|
|
|
+ SearchRecord searchRecord1 = this.getById(id);
|
|
|
+ if (searchRecord1 == null) {
|
|
|
+ throw new XiaoShiException("记录不存在");
|
|
|
+ }
|
|
|
+ searchRecord.setCreateId(searchRecord1.getCreateId());
|
|
|
+ searchRecord.setCreateTime(searchRecord1.getCreateTime());
|
|
|
+ searchRecord.updateById();
|
|
|
+ } else {
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ searchRecord.setCreateId(personnelVO.getId());
|
|
|
+ searchRecord.insert();
|
|
|
+ id = searchRecord.getId();
|
|
|
+ }
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除检索记录
|
|
|
+ *
|
|
|
+ * @param ids 检索记录id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Integer> removeSearchRecords(List<Integer> ids) {
|
|
|
+ if (ids == null) {
|
|
|
+ throw new XiaoShiException("请传入数据");
|
|
|
+ }
|
|
|
+ this.removeBatchByIds(ids);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除检索记录
|
|
|
+ *
|
|
|
+ * @param querySearchRecordDTO 查询检索记录dto
|
|
|
+ * lrj
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Records querySearchRecord(QuerySearchRecordDTO querySearchRecordDTO) {
|
|
|
+ Integer projectId = querySearchRecordDTO.getProjectId();
|
|
|
+ Long size = querySearchRecordDTO.getSize();
|
|
|
+ Long current = querySearchRecordDTO.getCurrent();
|
|
|
+
|
|
|
+ if (projectId == null) {
|
|
|
+ throw new XiaoShiException("请传入报告id");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SearchRecord> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(SearchRecord::getProjectId, projectId);
|
|
|
+ Page<SearchRecord> searchRecordPage = this.page(new Page<>(current, size), queryWrapper);
|
|
|
+ Long total = searchRecordPage.getTotal();
|
|
|
+ List<SearchRecord> searchRecords = searchRecordPage.getRecords();
|
|
|
+ List<SearchRecordVO> vos = this.loadRecord(searchRecords);
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(current);
|
|
|
+ records.setSize(size);
|
|
|
+ records.setTotal(total);
|
|
|
+ records.setData(vos);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<SearchRecordVO> loadRecord(List<SearchRecord> searchRecords) {
|
|
|
+ List<SearchRecordVO> searchRecordVOS = new ArrayList<>();
|
|
|
+ if (searchRecords.size() == 0) {
|
|
|
+ return searchRecordVOS;
|
|
|
+ }
|
|
|
+ List<String> createIds = searchRecords.stream().map(SearchRecord::getCreateId).collect(Collectors.toList());
|
|
|
+ //查询创建人名称
|
|
|
+ List<Personnel> personnels = new ArrayList<>();
|
|
|
+ if (createIds.size() != 0) {
|
|
|
+ try {
|
|
|
+ String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (SearchRecord searchRecord : searchRecords) {
|
|
|
+ SearchRecordVO searchRecordVO = new SearchRecordVO();
|
|
|
+ BeanUtils.copyProperties(searchRecord, searchRecordVO);
|
|
|
+ Personnel personnel = personnels.stream().filter(i -> i.getId().equals(searchRecordVO.getCreateId())).findFirst().orElse(null);
|
|
|
+ if (personnel != null) {
|
|
|
+ searchRecordVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ }
|
|
|
+ searchRecordVOS.add(searchRecordVO);
|
|
|
+ }
|
|
|
+ return searchRecordVOS;
|
|
|
+ }
|
|
|
+}
|