Blizzard 1 anno fa
parent
commit
90dc192760

+ 2 - 2
blade-service-api/wt-okr-api/src/main/java/com/wtkj/dto/SearchProjectFileDTO.java

@@ -19,13 +19,13 @@ public class SearchProjectFileDTO implements Serializable {
 
 	@JsonSerialize(using = ToStringSerializer.class)
 	@NotNull(message = "deptId can't be null")
-	private Long deptId;
+	private Long topDeptId;
 
 	private Long projectId;
 
 	private Long createUser;
 
-	private String title;
+	private String text;
 
 	private Integer current;
 

+ 1 - 1
blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/Project.java

@@ -88,7 +88,7 @@ public class Project extends BaseEntity {
 
 	@TableField("img_id")
 	@ApiModelProperty(value = "项目图片文件ID")
-	private Integer imgId;
+	private Long imgId;
 
 
 

+ 17 - 1
blade-service/wt-okr/src/main/java/com/wtkj/controller/ResourceController.java

@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.wtkj.dto.SearchProjectFileDTO;
 import com.wtkj.dto.UploadInnerFileDTO;
+import com.wtkj.entity.FileAndFolder;
 import com.wtkj.entity.InnerFileAndFolder;
 import com.wtkj.service.ICommonService;
 import com.wtkj.service.IInnerFileAndFolderService;
+import com.wtkj.wrapper.FileAndFolderWrapper;
 import com.wtkj.wrapper.InnerFileAndFolderWrapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -117,7 +119,21 @@ public class ResourceController {
 	@ApiOperationSupport(order = 7)
 	@ApiOperation(value = "项目资料", notes = "")
 	public R searchProjectFile(@RequestBody SearchProjectFileDTO dto) {
-		return R.data(null);
+		Query query = new Query();
+		query.setSize(dto.getSize());
+		query.setCurrent(dto.getCurrent());
+		IPage<FileAndFolder> page = commonService.esSearch(dto, Condition.getPage(query));
+		return R.data(FileAndFolderWrapper.build().pageVO(page));
+	}
+
+	/**
+	 * 打开文件
+	 */
+	@PostMapping("/open-search-file")
+	@ApiOperationSupport(order = 8)
+	@ApiOperation(value = "打开搜索结果文件", notes = "")
+	public R openSearch(@RequestParam Long projectId, @RequestParam Long fileId, @RequestParam String text) {
+		return R.data(commonService.openSearchFile(projectId, fileId, text));
 	}
 
 }

+ 3 - 1
blade-service/wt-okr/src/main/java/com/wtkj/handler/EsFileHandler.java

@@ -72,6 +72,8 @@ public class EsFileHandler {
 					document.setId(IdWorker.getIdStr());
 					document.setContent(content);
 					document.setFileId(fileId);
+					document.setFileName(file.getTitle());
+					document.setCreateUser(file.getCreateUser());
 					document.setCurrentPage(currentPage);
 					document.setProjectId(projectId);
 
@@ -84,7 +86,7 @@ public class EsFileHandler {
 						.must(new TermQueryBuilder("fileId", fileId))
 						.must(new TermQueryBuilder("currentPage", currentPage));
 					searchSourceBuilder.query(boolQuery);
-					searchSourceBuilder.from((0));
+					searchSourceBuilder.from(0);
 					searchSourceBuilder.size(1);
 					request.source(searchSourceBuilder);
 					SearchResponse response = client.search(request, RequestOptions.DEFAULT);

+ 5 - 0
blade-service/wt-okr/src/main/java/com/wtkj/handler/es/Document.java

@@ -22,6 +22,11 @@ public class Document implements Serializable {
 	@JsonSerialize(using = ToStringSerializer.class)
 	private Long fileId;
 
+	private String fileName;
+
+	@JsonSerialize(using = ToStringSerializer.class)
+	private Long createUser;
+
 	private String content;
 
 	private Integer currentPage;

+ 1 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/ProjectAuthMapper.java

@@ -13,4 +13,5 @@ import java.util.List;
 public interface ProjectAuthMapper extends BaseMapper<ProjectAuth> {
 	List<ProjectAuth> selectByDeptAndUser(Long topDept, Long deptId, Long userId);
 
+	List<ProjectAuth> selectByUser(Long userId);
 }

+ 7 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/ProjectAuthMapper.xml

@@ -15,4 +15,11 @@
             and user_id = #{param3}
         </if>
     </select>
+
+    <select id="selectByUser" resultType="com.wtkj.entity.ProjectAuth">
+        select * from blade_project_auth where is_deleted = 0
+        <if test="param != null">
+            and user_id = #{param}
+        </if>
+    </select>
 </mapper>

+ 7 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/ICommonService.java

@@ -1,7 +1,10 @@
 package com.wtkj.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.wtkj.dto.SearchProjectFileDTO;
 import com.wtkj.dto.UploadFileDTO;
 import com.wtkj.dto.UploadInnerFileDTO;
+import com.wtkj.entity.FileAndFolder;
 
 import java.util.List;
 
@@ -23,4 +26,8 @@ public interface ICommonService {
 	boolean delete(List<Long> ids);
 
 	boolean uploadInnerFile(List<UploadInnerFileDTO> files);
+
+	IPage<FileAndFolder> esSearch(SearchProjectFileDTO dto, IPage<FileAndFolder> page);
+
+	Object openSearchFile(Long projectId, Long fileId, String text);
 }

+ 1 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/IProjectAuthService.java

@@ -13,4 +13,5 @@ import java.util.List;
 public interface IProjectAuthService extends BaseService<ProjectAuth> {
 	List<ProjectAuth> getByDeptAndUser(Long topDept, Long deptId, Long userId);
 
+	List<ProjectAuth> getByUserId(Long userId);
 }

+ 134 - 7
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/CommonServiceImpl.java

@@ -1,19 +1,30 @@
 package com.wtkj.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.wtkj.dto.SearchProjectFileDTO;
 import com.wtkj.dto.UploadFileDTO;
 import com.wtkj.dto.UploadInnerFileDTO;
 import com.wtkj.entity.FileAndFolder;
 import com.wtkj.entity.FileAndFolderHistory;
 import com.wtkj.entity.InnerFileAndFolder;
-import com.wtkj.service.ICommonService;
-import com.wtkj.service.IFileAndFolderHistoryService;
-import com.wtkj.service.IFileAndFolderService;
-import com.wtkj.service.IInnerFileAndFolderService;
+import com.wtkj.entity.ProjectAuth;
+import com.wtkj.handler.es.Document;
+import com.wtkj.service.*;
 import com.wutong.file.feign.IFileClient;
 import com.wutong.file.vo.FileVO;
 import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.SearchHits;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
@@ -23,10 +34,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
 
+import static com.wtkj.config.MagicValue.PROJECT_RESOURCE_INDEX;
 import static com.wtkj.config.MagicValue.TWO;
 
 /**
@@ -42,6 +53,8 @@ public class CommonServiceImpl implements ICommonService {
 	private final IFileAndFolderService fileAndFolderService;
 	private final IFileAndFolderHistoryService historyService;
 	private final IInnerFileAndFolderService innerFileAndFolderService;
+	private final IProjectAuthService projectAuthService;
+	private final RestHighLevelClient client;
 
 
 	@Override
@@ -232,4 +245,118 @@ public class CommonServiceImpl implements ICommonService {
 
 
 	}
+
+	@SneakyThrows
+	@Override
+	public IPage<FileAndFolder> esSearch(SearchProjectFileDTO dto, IPage<FileAndFolder> page) {
+		LambdaQueryWrapper<FileAndFolder> lqw = new LambdaQueryWrapper<>();
+		Long deptId = dto.getTopDeptId();
+		String text = dto.getText();
+		Long projectId = dto.getProjectId();
+		Long createUser = dto.getCreateUser();
+		Set<Long> projectIds = new HashSet<>();
+		if (projectId != null && projectId > 0L) {
+			projectIds.add(projectId);
+		} else {
+			//如果projectId为空 则查询机构下所有项目
+			//此机构下的项目
+			List<ProjectAuth> auths = projectAuthService.getByDeptAndUser(deptId, null, null);
+			if (!CollectionUtils.isEmpty(auths)) {
+				Set<Long> ids = auths.stream().map(ProjectAuth::getProjectId).filter(Objects::nonNull).collect(Collectors.toSet());
+				projectIds.addAll(ids);
+			}
+		}
+
+		// select * from xxx where projectId in (...) and create_user = #{createUser} and (title like %text% or content like %text%)
+
+		SearchRequest request = new SearchRequest();
+		request.indices(PROJECT_RESOURCE_INDEX);
+		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+
+		// 1.创建BoolQueryBuilder
+		BoolQueryBuilder condition = QueryBuilders.boolQuery();
+
+		//2. 添加must子句
+		condition.must(QueryBuilders.termsQuery("projectId", projectIds));
+		if (createUser != null) {
+			condition.must(QueryBuilders.termQuery("createUser", createUser));
+		}
+		if (StringUtil.isNotBlank(text)) {
+			// 3.添加should子句
+			condition.should(QueryBuilders.matchQuery("title", text));
+			condition.should(QueryBuilders.matchQuery("content", text));
+		}
+		searchSourceBuilder.query(condition);
+		searchSourceBuilder.from(0);
+		searchSourceBuilder.size(100);
+		request.source(searchSourceBuilder);
+
+		//执行查询
+		SearchResponse response = client.search(request, RequestOptions.DEFAULT);
+		Set<Document> set = new HashSet<>();
+		if (response != null) {
+			SearchHits hits = response.getHits();
+			int size = hits.getHits().length;
+			for (int i = 0; i < size; i++) {
+				String str = hits.getHits()[i].getSourceAsString();
+				Document document = JSON.parseObject(str, Document.class);
+				set.add(document);
+			}
+		}
+		if (!CollectionUtils.isEmpty(set)) {
+			Set<Long> fileIds = set.stream().map(Document::getFileId).collect(Collectors.toSet());
+			lqw.in(FileAndFolder::getBladeFileId, fileIds);
+		}
+		return fileAndFolderService.page(page, lqw);
+	}
+
+	@SneakyThrows
+	@Override
+	public Object openSearchFile(Long projectId, Long fileId, String text) {
+		Long userId = AuthUtil.getUserId();
+		List<ProjectAuth> list = projectAuthService.getByUserId(userId);
+		if (!CollectionUtils.isEmpty(list)) {
+			Set<Long> collect = list.stream().map(ProjectAuth::getProjectId).collect(Collectors.toSet());
+			if (!collect.contains(projectId)) {
+				throw new ServiceException("对不起,你暂未拥有此项目权限");
+			}
+		}
+
+		SearchRequest request = new SearchRequest();
+		request.indices(PROJECT_RESOURCE_INDEX);
+		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+
+		// 1.创建BoolQueryBuilder
+		BoolQueryBuilder condition = QueryBuilders.boolQuery();
+
+		//2. 添加must子句
+		condition.must(QueryBuilders.termQuery("projectId", projectId));
+		condition.must(QueryBuilders.termQuery("fileId", fileId));
+		condition.must(QueryBuilders.matchQuery("title", text));
+
+		searchSourceBuilder.query(condition);
+		searchSourceBuilder.from(0);
+		searchSourceBuilder.size(100);
+		request.source(searchSourceBuilder);
+
+		searchSourceBuilder.query(condition);
+		searchSourceBuilder.from(0);
+		searchSourceBuilder.size(100);
+		request.source(searchSourceBuilder);
+
+		//执行查询
+		SearchResponse response = client.search(request, RequestOptions.DEFAULT);
+		Set<Document> set = new HashSet<>();
+		if (response != null) {
+			SearchHits hits = response.getHits();
+			int size = hits.getHits().length;
+			for (int i = 0; i < size; i++) {
+				String str = hits.getHits()[i].getSourceAsString();
+				Document document = JSON.parseObject(str, Document.class);
+				set.add(document);
+			}
+		}
+
+		return null;
+	}
 }

+ 5 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/ProjectAuthServiceImpl.java

@@ -22,4 +22,9 @@ public class ProjectAuthServiceImpl extends BaseServiceImpl<ProjectAuthMapper, P
 		return baseMapper.selectByDeptAndUser(topDept, deptId, userId);
 	}
 
+	@Override
+	public List<ProjectAuth> getByUserId(Long userId) {
+		return baseMapper.selectByUser(userId);
+	}
+
 }

+ 1 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/ProjectServiceImpl.java

@@ -196,6 +196,7 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectMapper, Project>
 			if (deptCategory.equals(3)) {
 				//是业主 --> 主管单位是topDept
 				lqw.eq(Project::getCompetentUnit, topDept);
+				lqw.eq(Project::getYear, year);
 				List<Project> list = this.list(lqw);
 				if (!CollectionUtils.isEmpty(list)) {
 					Set<Long> projectIds = list.stream().map(Project::getId).collect(Collectors.toSet());

+ 1 - 1
blade-service/wt-okr/src/main/java/com/wtkj/wrapper/ProjectWrapper.java

@@ -45,7 +45,7 @@ public class ProjectWrapper extends BaseEntityWrapper<Project, ProjectVO> {
 				vo.setCurrentStageName(byId.getName());
 			}
 		}
-		Integer imgId = entity.getImgId();
+		Long imgId = entity.getImgId();
 		if (imgId != null) {
 			R<FileVO> byId = fileClient.findById(imgId);
 			if (byId.isSuccess()) {