Commit e5229021 by wanghuiyun

王辉云 添加count

parent 06d7e2c3
...@@ -13,6 +13,8 @@ HELP.md ...@@ -13,6 +13,8 @@ HELP.md
.sts4-cache .sts4-cache
### IntelliJ IDEA ### ### IntelliJ IDEA ###
/target
*/target/
.idea .idea
*.iws *.iws
*.iml *.iml
......
...@@ -28,14 +28,17 @@ import java.util.*; ...@@ -28,14 +28,17 @@ import java.util.*;
@Service @Service
public class companyName { public class companyName {
public List<String> nameList(String region, String type, String modality, String nameNum, String goodName, Integer from, Integer size) throws Exception { public Map<String,Object> nameList(String region, String type, String modality, String nameNum, String goodName, Integer from, Integer size) throws Exception {
List<String> querycompanyNanme = querycompanyNanme(goodName, nameNum, from, size); Map<String, Object> stringObjectMap = querycompanyNanme(goodName, nameNum, from, size);
List<String> querycompanyNanme = (List<String>) stringObjectMap.get("companyName");
List<String> nameList = new ArrayList<>(); List<String> nameList = new ArrayList<>();
for (String str : querycompanyNanme) { for (String str : querycompanyNanme){
JSONObject responseObj = JSONObject.parseObject(str); JSONObject responseObj = JSONObject.parseObject(str);
nameList.add(region + responseObj.getString("company_name") + type + modality); nameList.add(region + responseObj.getString("company_name") + type + modality);
} }
return nameList; stringObjectMap.remove("companyName");
stringObjectMap.put("companyName",nameList);
return stringObjectMap;
} }
/** /**
...@@ -43,7 +46,7 @@ public class companyName { ...@@ -43,7 +46,7 @@ public class companyName {
* *
* @return * @return
*/ */
public static List<String> querycompanyNanme(String fieldKey, String fieldnum, Integer from, Integer size) throws Exception { public static Map<String,Object> querycompanyNanme(String fieldKey, String fieldnum, Integer from, Integer size) throws Exception {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("elastic", "w3OL+51eo*)c=^7")); new UsernamePasswordCredentials("elastic", "w3OL+51eo*)c=^7"));
...@@ -76,11 +79,14 @@ public class companyName { ...@@ -76,11 +79,14 @@ public class companyName {
searchRequest.source(searchSourceBuilder); searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = restClient.search(searchRequest, RequestOptions.DEFAULT); SearchResponse searchResponse = restClient.search(searchRequest, RequestOptions.DEFAULT);
List<String> result = new LinkedList<>(); List<String> result = new LinkedList<>();
SearchHits searchHits = searchResponse.getHits(); SearchHits searchHits=searchResponse.getHits();
searchHits.forEach(i -> { HashMap<String, Object> hashMap = new HashMap<>();
searchHits.forEach(i->{
result.add(i.getSourceAsString()); result.add(i.getSourceAsString());
}); });
return result; hashMap.put("companyName",result);
hashMap.put("count",searchHits.getTotalHits().value);
return hashMap;
} }
} }
...@@ -9,6 +9,7 @@ import javax.validation.Valid; ...@@ -9,6 +9,7 @@ import javax.validation.Valid;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
...@@ -51,7 +52,7 @@ public class uploadossapi { ...@@ -51,7 +52,7 @@ public class uploadossapi {
*/ */
@ResponseBody @ResponseBody
@RequestMapping(value = "/getNames",method = RequestMethod.POST) @RequestMapping(value = "/getNames",method = RequestMethod.POST)
public List<String> companyName(@RequestBody @Valid String baseinfo) throws Exception { public Map<String,Object> companyName(@RequestBody @Valid String baseinfo) throws Exception {
try { try {
JSONObject jsonObject = JSONObject.parseObject(baseinfo); JSONObject jsonObject = JSONObject.parseObject(baseinfo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment