|
@@ -0,0 +1,182 @@
|
|
|
+package cn.cslg.pas.service.novelty;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.dto.*;
|
|
|
+import cn.cslg.pas.common.dto.NoveltyProjectDTO.NoveltyRetrieveRecordDTO;
|
|
|
+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.NoveltyProjectVO.QueryTemplateVO;
|
|
|
+import cn.cslg.pas.common.vo.NoveltyProjectVO.RetrieveRecordVO;
|
|
|
+import cn.cslg.pas.domain.business.RetrieveRecord;
|
|
|
+import cn.cslg.pas.domain.business.novelty.AssoRetrieveRecordProject;
|
|
|
+import cn.cslg.pas.domain.business.novelty.NoveltyReportTemplate;
|
|
|
+import cn.cslg.pas.mapper.RetrieveRecordMapper;
|
|
|
+import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+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.RequiredArgsConstructor;
|
|
|
+import lombok.experimental.Accessors;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 检索记录
|
|
|
+ * @Author xiexiang
|
|
|
+ * @Date 2024/9/27
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
+public class SearchRecordService extends ServiceImpl<RetrieveRecordMapper, RetrieveRecord> {
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AssoRetrieveRecordProjectService assoRetrieveRecordProjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PermissionService permissionService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询检索记录
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Records querySearchRecord(QuerySearchRecordDTO querySearchRecordDTO) throws IOException {
|
|
|
+ Records records = new Records();
|
|
|
+ Long total = null;
|
|
|
+ List<RetrieveRecord> retrieveRecordList = new ArrayList<>();
|
|
|
+ List<RetrieveRecordVO> retrieveRecordVOS = new ArrayList<>();
|
|
|
+ if (querySearchRecordDTO.getProjectId() != null) {
|
|
|
+ LambdaQueryWrapper<AssoRetrieveRecordProject> assoQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ assoQueryWrapper.eq(AssoRetrieveRecordProject::getProjectId, querySearchRecordDTO.getProjectId());
|
|
|
+ List<AssoRetrieveRecordProject> assoRetrieveRecordProjects = assoRetrieveRecordProjectService.list();
|
|
|
+
|
|
|
+ if (!assoRetrieveRecordProjects.isEmpty()) {
|
|
|
+ List<Integer> retrieveIds = assoRetrieveRecordProjects.stream()
|
|
|
+ .map(AssoRetrieveRecordProject::getRetrieveRecordId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ LambdaQueryWrapper<RetrieveRecord> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(RetrieveRecord::getId, retrieveIds)
|
|
|
+ .orderByDesc(RetrieveRecord::getRetrieveTime)
|
|
|
+ .orderByDesc(RetrieveRecord::getCreateTime);
|
|
|
+ IPage<RetrieveRecord> retrieveRecords = this.page(new Page<>(querySearchRecordDTO.getCurrent(), querySearchRecordDTO.getSize()), queryWrapper);
|
|
|
+ retrieveRecordList = retrieveRecords.getRecords();
|
|
|
+ if (!retrieveRecordList.isEmpty()) {
|
|
|
+ retrieveRecordVOS = this.loadRetrieveRecords(retrieveRecordList);
|
|
|
+ }
|
|
|
+ total = retrieveRecords.getTotal();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ records.setData(retrieveRecordVOS);
|
|
|
+ records.setCurrent(querySearchRecordDTO.getCurrent());
|
|
|
+ records.setSize(querySearchRecordDTO.getSize());
|
|
|
+ records.setTotal(total);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载检索记录返回VO
|
|
|
+ * @param retrieveRecordList
|
|
|
+ */
|
|
|
+ private List<RetrieveRecordVO> loadRetrieveRecords(List<RetrieveRecord> retrieveRecordList) throws IOException {
|
|
|
+ List<RetrieveRecordVO> retrieveRecordVOS = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(retrieveRecordList)) {
|
|
|
+ List<String> createIds = new ArrayList<>();
|
|
|
+ List<Personnel> personnels = new ArrayList<>();
|
|
|
+
|
|
|
+ retrieveRecordList.forEach(item -> {
|
|
|
+ if (item.getCreateId() != null) {
|
|
|
+ createIds.add(item.getCreateId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //查询创建人名称
|
|
|
+ if (!CollectionUtils.isEmpty(createIds)) {
|
|
|
+ String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(res);
|
|
|
+ personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (RetrieveRecord retrieveRecord : retrieveRecordList) {
|
|
|
+ RetrieveRecordVO retrieveRecordVO = new RetrieveRecordVO();
|
|
|
+ BeanUtils.copyProperties(retrieveRecord, retrieveRecordVO);
|
|
|
+ //装载人员信息
|
|
|
+ Personnel personnel = personnels.stream().filter(item -> item.getId().equals(retrieveRecord.getCreateId())).findFirst().orElse(null);
|
|
|
+ if (personnel != null) {
|
|
|
+ retrieveRecordVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ }
|
|
|
+ retrieveRecordVOS.add(retrieveRecordVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return retrieveRecordVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增检索记录
|
|
|
+ *
|
|
|
+ * @param noveltyRetrieveRecordDTO
|
|
|
+ */
|
|
|
+ public Integer addSearchRecord(NoveltyRetrieveRecordDTO noveltyRetrieveRecordDTO) {
|
|
|
+ RetrieveRecord retrieveRecord = new RetrieveRecord();
|
|
|
+ BeanUtils.copyProperties(noveltyRetrieveRecordDTO, retrieveRecord);
|
|
|
+
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ retrieveRecord.setCreateId(personnelVO.getId());
|
|
|
+ retrieveRecord.setTenantId(personnelVO.getTenantId());
|
|
|
+
|
|
|
+ retrieveRecord.setIfBySystem(true);
|
|
|
+ retrieveRecord.insert();
|
|
|
+ return retrieveRecord.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新检索记录表
|
|
|
+ *
|
|
|
+ * @param noveltyRetrieveRecordDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer updateSearchRecord(NoveltyRetrieveRecordDTO noveltyRetrieveRecordDTO) {
|
|
|
+ Integer id = noveltyRetrieveRecordDTO.getId();
|
|
|
+ //根据传入对象的id查询出实体类
|
|
|
+ RetrieveRecord retrieveRecord = this.getById(id);
|
|
|
+ BeanUtils.copyProperties(noveltyRetrieveRecordDTO, retrieveRecord);
|
|
|
+ retrieveRecord.setUpdateTime(new Date());
|
|
|
+ retrieveRecord.updateById();
|
|
|
+ return retrieveRecord.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除检索记录
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Integer> deleteSearchRecord(List<Integer> retrieveIds) {
|
|
|
+ if (!retrieveIds.isEmpty()) {
|
|
|
+ //删除关联关系
|
|
|
+ LambdaQueryWrapper<AssoRetrieveRecordProject> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(AssoRetrieveRecordProject::getRetrieveRecordId, retrieveIds);
|
|
|
+ assoRetrieveRecordProjectService.remove(queryWrapper);
|
|
|
+ //删除记录
|
|
|
+ this.removeBatchByIds(retrieveIds);
|
|
|
+ }
|
|
|
+ return retrieveIds;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|