diff --git a/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeNormalSearchHistoryController.java b/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeNormalSearchHistoryController.java index 1f9f09a7..8383b4f4 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeNormalSearchHistoryController.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeNormalSearchHistoryController.java @@ -1,5 +1,6 @@ package com.jero.modules.laws.home.controller; +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; @@ -20,6 +21,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.formula.functions.T; import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -47,7 +49,7 @@ public class LawsHomeNormalSearchHistoryController extends JeroController query = new LambdaQueryWrapper<>(); + query.eq(LawsHomeNormalSearchHistory::getId,map.get("id")); + query.ne(LawsHomeNormalSearchHistory::getUserId,sysUser.getId()); + long l = lawsHomeNormalSearchHistoryService.count(query); + if(l > 0){ + return Result.error(MessageUtils.getMessage(ResultCommon.HORIZONTAL_TRANSGRESSION)); + } lawsHomeNormalSearchHistoryService.removeById(map.get("id")); return Result.OK(MessageUtils.getMessage(ResultCommon.OK)); } @@ -86,7 +95,7 @@ public class LawsHomeNormalSearchHistoryController extends JeroController query = new LambdaQueryWrapper<>(); + query.in(LawsHomeNormalSearchHistory::getId,Arrays.asList(map.get("id").split(","))); + query.ne(LawsHomeNormalSearchHistory::getUserId,sysUser.getId()); + long l = lawsHomeNormalSearchHistoryService.count(query); + if(l > 0){ + return Result.error(MessageUtils.getMessage(ResultCommon.HORIZONTAL_TRANSGRESSION)); + } lawsHomeNormalSearchHistoryService.removeByIds(Arrays.asList(map.get("id").split(","))); return Result.OK(MessageUtils.getMessage(ResultCommon.OK)); } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeSearchController.java b/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeSearchController.java index 9a905e3d..bf74edce 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeSearchController.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/home/controller/LawsHomeSearchController.java @@ -10,10 +10,13 @@ import com.jero.modules.laws.home.vo.LawsHomeNormalSearchVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Map; /** * @author lqt @@ -34,6 +37,7 @@ public class LawsHomeSearchController { @AutoLog(value = "首页-一般检索(标题)查询",operateType = 1) @ApiOperation(value="首页-一般检索(标题)查询", notes="首页-一般检索(标题)查询") @GetMapping(value = "/getNormalSearchTitlePage") + @RequiresPermissions("dashboard:generalSearch:search") public Result> getNormalSearchTitlePage(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { @@ -43,6 +47,7 @@ public class LawsHomeSearchController { @AutoLog(value = "首页-一般检索(标题)(数据统计)",operateType = 1) @ApiOperation(value="首页-一般检索(标题)(数据统计)", notes="首页-一般检索(标题)(数据统计)") @GetMapping(value = "/getNormalSearchTitleCount") + @RequiresPermissions("dashboard:generalSearch:search") public Result getNormalSearchTitleCount(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO) { return Result.OK(lawsHomeSearchService.getNormalSearchTitleCount(lawsHomeNormalSearchDTO)); } @@ -50,6 +55,7 @@ public class LawsHomeSearchController { @AutoLog(value = "首页-一般检索(全文)查询",operateType = 1) @ApiOperation(value="首页-一般检索(全文)查询", notes="首页-一般检索(全文)查询") @GetMapping(value = "/getNormalSearchAllPage") + @RequiresPermissions("dashboard:generalSearch:search") public Result> getNormalSearchAllPage(LawsHomeNormalSearchDTO homeNormalSearchDTO, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { @@ -59,15 +65,8 @@ public class LawsHomeSearchController { @AutoLog(value = "首页-一般检索(全文)(数据统计)",operateType = 1) @ApiOperation(value="首页-一般检索(全文)(数据统计)", notes="首页-一般检索(全文)(数据统计)") @GetMapping(value = "/getNormalSearchAllCount") + @RequiresPermissions("dashboard:generalSearch:search") public Result getNormalSearchAllCount(LawsHomeNormalSearchDTO homeNormalSearchDTO) { return Result.OK(lawsHomeSearchService.getNormalSearchAllCount(homeNormalSearchDTO)); } - - @AutoLog(value = "首页-一般检索(全文)测试",operateType = 1) - @ApiOperation(value="首页-一般检索(全文)测试", notes="首页-一般检索(全文)测试") - @PostMapping(value = "/getNormalSearchAllUpdate") - public Result getNormalSearchAllUpdate(@RequestBody Map map) { - lawsHomeSearchService.updateEsData(map.get("resourceType"),map.get("ids") ,map.get("opType")); - return Result.OK("操作成功"); - } } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java index d4a56d35..94622b6f 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java @@ -121,6 +121,14 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { public static final String BLANK_SPACE = "\\s+"; + public static final String FILE_TYPE = "pdf,PDF,doc,DOC,docx,DOCX"; + public static final String RELEASE_STATUS = "release_status"; + + public static final String QUERY = "query"; + + public static final String MATCH = "match"; + + @Override @@ -793,7 +801,6 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { // 前缀匹配 缺点是前缀一定不能断开 //情况举例:用户只记得前面那段字 String boost = "boost"; - String query = "query"; Map map21 = new HashMap<>(); Map map31 = new HashMap<>(); Map map41 = new HashMap<>(); @@ -812,7 +819,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { if(CONTENT.equals(field)){ map32.put(boost,0.01); } - map32.put(query, selectValue); + map32.put(QUERY, selectValue); map22.put(field, map32); map42.put("match_phrase_prefix", map22); queryMapJson.add(map42); @@ -825,9 +832,9 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { if(CONTENT.equals(field)){ map33.put(boost,0.01); } - map33.put(query, selectValue); + map33.put(QUERY, selectValue); map23.put(field, map33); - map43.put("match", map23); + map43.put(MATCH, map23); queryMapJson.add(map43); // wildcard模糊查询 @@ -885,11 +892,11 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { } if(CollectionUtils.isNotEmpty(queryMapJson)){ JSONObject object = jeroElasticsearchTemplate.buildBoolQuery(null,null,queryMapJson); - jsonObject.put("query",object); + jsonObject.put(QUERY,object); } LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); JSONObject jsonObjectShould = getJsonObject(loginUser); - jsonObject.put("query",jsonObjectShould); + jsonObject.put(QUERY,jsonObjectShould); //2. 数据查询 JSONObject search = jeroElasticsearchTemplate.search(HomeSearchEnum.INDEX_NAME_DOCUMENT_ZQ.getValue(), HomeSearchEnum.TYPE_NAME_DOCUMENT_ZQ.getValue(), jsonObject); @@ -929,19 +936,19 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { JSONArray queryMapShould = new JSONArray(); Map status1 = new HashMap<>(); Map status1Val = new HashMap<>(); - status1Val.put("release_status", "1"); - status1.put("match", status1Val); + status1Val.put(RELEASE_STATUS, "1"); + status1.put(MATCH, status1Val); queryMapShould.add(status1); JSONArray queryMapMust = new JSONArray(); Map status2 = new HashMap<>(); Map status2Val = new HashMap<>(); - status2Val.put("release_status", "0"); - status2.put("match", status2Val); + status2Val.put(RELEASE_STATUS, "0"); + status2.put(MATCH, status2Val); queryMapMust.add(status2); Map status3 = new HashMap<>(); Map status3Val = new HashMap<>(); status3Val.put("create_by", loginUser.getUsername()); - status3.put("match", status3Val); + status3.put(MATCH, status3Val); queryMapMust.add(status3); JSONObject jsonObjectMust = jeroElasticsearchTemplate.buildBoolQuery(queryMapMust, null, null); queryMapShould.add(jsonObjectMust); @@ -1067,10 +1074,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { @NotNull private List getOssFilesLawsDomesticStandard(LawsDomesticStandard lawsDomesticStandard) { // 从过程稿件从上到下顺序检索;如果文档里有发布稿,只检索发布稿 - LambdaQueryWrapper ossFile = new LambdaQueryWrapper<>(); - ossFile.eq(OSSFile::getStandardId,lawsDomesticStandard.getId()); - ossFile.orderByAsc(OSSFile::getCreateTime); - List list = oSSFileService.list(ossFile); + List list = getOssFiles(lawsDomesticStandard.getId()); List listFile = new ArrayList<>(); if(!CollectionUtils.isEmpty(list)){ LambdaQueryWrapper query = new LambdaQueryWrapper<>(); @@ -1093,6 +1097,14 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { return listFile; } + private List getOssFiles(String id) { + QueryWrapper ossFile = new QueryWrapper<>(); + ossFile.eq("standard_id", id); + ossFile.in("substring_index(file_name,'.',-1)", Arrays.asList(FILE_TYPE.split(","))); + ossFile.orderByAsc(CREATE_TIME); + return oSSFileService.list(ossFile); + } + private int getEndIndex(int startIndex, int batchCount, List listIds) { int endIndex = 0; if (listIds.size() - batchCount < startIndex) { @@ -1161,10 +1173,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { @NotNull private List getOssFilesLawsOverseasStandard(LawsOverseasStandard lawsOverseasStandard) { // 从过程稿件从上到下顺序检索;如果文档里有发布稿,只检索发布稿 - LambdaQueryWrapper ossFile = new LambdaQueryWrapper<>(); - ossFile.eq(OSSFile::getStandardId,lawsOverseasStandard.getId()); - ossFile.orderByAsc(OSSFile::getCreateTime); - List list = oSSFileService.list(ossFile); + List list = getOssFiles(lawsOverseasStandard.getId()); List listFile = new ArrayList<>(); if(CollectionUtils.isEmpty(list)){ return listFile; @@ -1251,10 +1260,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { @NotNull private List getOssFilesLawsEnterpriseStandard(LawsEnterpriseStandard lawsEnterpriseStandard) { // 从过程稿件从上到下顺序检索;如果文档里有发布稿,只检索发布稿 - LambdaQueryWrapper ossFile = new LambdaQueryWrapper<>(); - ossFile.eq(OSSFile::getStandardId,lawsEnterpriseStandard.getId()); - ossFile.orderByAsc(OSSFile::getCreateTime); - List list = oSSFileService.list(ossFile); + List list = getOssFiles(lawsEnterpriseStandard.getId()); List listFile = new ArrayList<>(); if(!CollectionUtils.isEmpty(list)){ LambdaQueryWrapper query = new LambdaQueryWrapper<>(); @@ -1393,7 +1399,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { } map.put("es_create_time",new Date()); map.put("create_by",obj.getCreateBy()); - map.put("release_status",obj.getReleaseStatus()); + map.put(RELEASE_STATUS,obj.getReleaseStatus()); //添加es JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(map, SerializerFeature.WriteMapNullValue)); try {