Commit e5229021 by wanghuiyun

王辉云 添加count

parent 06d7e2c3
......@@ -13,6 +13,8 @@ HELP.md
.sts4-cache
### IntelliJ IDEA ###
/target
*/target/
.idea
*.iws
*.iml
......
......@@ -28,14 +28,17 @@ import java.util.*;
@Service
public class companyName {
public List<String> 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);
public Map<String,Object> nameList(String region, String type, String modality, String nameNum, String goodName, Integer from, Integer size) throws Exception {
Map<String, Object> stringObjectMap = querycompanyNanme(goodName, nameNum, from, size);
List<String> querycompanyNanme = (List<String>) stringObjectMap.get("companyName");
List<String> nameList = new ArrayList<>();
for (String str : querycompanyNanme) {
for (String str : querycompanyNanme){
JSONObject responseObj = JSONObject.parseObject(str);
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 {
*
* @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.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("elastic", "w3OL+51eo*)c=^7"));
......@@ -76,11 +79,14 @@ public class companyName {
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = restClient.search(searchRequest, RequestOptions.DEFAULT);
List<String> result = new LinkedList<>();
SearchHits searchHits = searchResponse.getHits();
searchHits.forEach(i -> {
SearchHits searchHits=searchResponse.getHits();
HashMap<String, Object> hashMap = new HashMap<>();
searchHits.forEach(i->{
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;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
import java.util.Map;
@RestController
......@@ -51,7 +52,7 @@ public class uploadossapi {
*/
@ResponseBody
@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 {
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