|
@ -10,15 +10,21 @@ import com.yihu.wlyy.statistics.etl.save.es.ElasticFactory;
|
|
|
import com.yihu.wlyy.statistics.util.DateUtil;
|
|
|
import com.yihu.wlyy.statistics.util.ElasticsearchUtil;
|
|
|
import com.yihu.wlyy.statistics.vo.SaveModel;
|
|
|
import io.searchbox.client.JestClient;
|
|
|
import io.searchbox.core.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.nlpcn.es4sql.jdbc.ObjectResult;
|
|
|
import org.nlpcn.es4sql.jdbc.ObjectResultsExtractor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
@ -47,6 +53,13 @@ public class QueryController {
|
|
|
@Autowired
|
|
|
private ElasticsearchUtil elasticsearchUtil;
|
|
|
|
|
|
@Autowired
|
|
|
private ElasticFactory elasticFactory;
|
|
|
@Value("${es.type}")
|
|
|
private String esType;
|
|
|
@Value("${es.index}")
|
|
|
private String esIndex;
|
|
|
|
|
|
@ApiOperation(value = "执行sql")
|
|
|
@RequestMapping(value = "/excuteSQL", method = RequestMethod.GET)
|
|
|
public List<SaveModel> excuteSQL(
|
|
@ -144,4 +157,68 @@ public class QueryController {
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "删除某一天的某一个指标的数据")
|
|
|
@RequestMapping(value = "/deleteQuotaWithId", method = RequestMethod.DELETE)
|
|
|
public String deleteQuota(
|
|
|
@ApiParam(name = "id", value = "指标id", required = true) @RequestParam(value = "id", required = true) String id,
|
|
|
@ApiParam(name = "date", value = "时间(yyyy-MM-dd)", required = true) @RequestParam(value = "date", required = true) String date) {
|
|
|
|
|
|
return deleteData(DateUtil.strToDate(date, "yyyy-MM-dd"),id).toString();
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "删除某一天的数据")
|
|
|
@RequestMapping(value = "/deleteQuota", method = RequestMethod.DELETE)
|
|
|
public String deleteQuota(
|
|
|
@ApiParam(name = "date", value = "时间(yyyy-MM-dd)", required = true) @RequestParam(value = "date", required = true) String date) {
|
|
|
|
|
|
|
|
|
return deleteData(DateUtil.strToDate(date, "yyyy-MM-dd"),null).toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除 某个指标某一天的某个timelevel的数据
|
|
|
*
|
|
|
* @param quotaDate
|
|
|
* @param quotaCode
|
|
|
*/
|
|
|
private net.sf.json.JSONObject deleteData(Date quotaDate, String quotaCode) {
|
|
|
net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject();
|
|
|
try {
|
|
|
JestClient jestClient = elasticFactory.getJestClient();
|
|
|
//先根据条件查找出来
|
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
|
|
|
|
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
|
|
if (quotaDate != null) {
|
|
|
boolQueryBuilder.must(QueryBuilders.matchQuery("quotaDate", quotaDate));
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(quotaCode)) {
|
|
|
boolQueryBuilder.must(QueryBuilders.matchQuery("quotaCode", quotaCode));
|
|
|
}
|
|
|
|
|
|
searchSourceBuilder.query(boolQueryBuilder
|
|
|
).size(500000);//一次取10000条
|
|
|
|
|
|
Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
|
|
|
.build();
|
|
|
SearchResult result = jestClient.execute(search);
|
|
|
List<SaveModel> saveModels = result.getSourceAsObjectList(SaveModel.class);
|
|
|
|
|
|
//根据id批量删除
|
|
|
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
|
|
|
for (SaveModel obj : saveModels) {
|
|
|
Delete index = new Delete.Builder(obj.getId()).build();
|
|
|
bulk.addAction(index);
|
|
|
}
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
jsonObject.put("flag", br.isSucceeded());
|
|
|
jsonObject.put("count", saveModels.size());
|
|
|
return jsonObject;
|
|
|
} catch (Exception e) {
|
|
|
jsonObject.put("flag", false);
|
|
|
jsonObject.put("message", e.getMessage());
|
|
|
return jsonObject;
|
|
|
}
|
|
|
}
|
|
|
}
|