Commit 9b739c41 authored by litengwei's avatar litengwei

配置文件提交

parent 07d55301
...@@ -28,11 +28,21 @@ import io.swagger.annotations.Api; ...@@ -28,11 +28,21 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Authorization; import io.swagger.annotations.Authorization;
import org.apache.commons.collections.CollectionUtils;
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.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -47,6 +57,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel; ...@@ -47,6 +57,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -71,6 +82,9 @@ public class PlanTaskController extends AbstractBaseController { ...@@ -71,6 +82,9 @@ public class PlanTaskController extends AbstractBaseController {
@Value("${params.isPush:false}") @Value("${params.isPush:false}")
private Boolean isZxj; private Boolean isZxj;
@Autowired
RestHighLevelClient restHighLevelClient;
@Autowired @Autowired
private RemoteSecurityService remoteSecurityService; private RemoteSecurityService remoteSecurityService;
...@@ -112,8 +126,8 @@ public class PlanTaskController extends AbstractBaseController { ...@@ -112,8 +126,8 @@ public class PlanTaskController extends AbstractBaseController {
PlanTaskPageParamUtil.fillPlanTask(queryRequests, params); PlanTaskPageParamUtil.fillPlanTask(queryRequests, params);
params.put("orgCode", reginParams.getPersonIdentity().getBizOrgCode()); params.put("orgCode", reginParams.getPersonIdentity().getBizOrgCode());
params.put("userId", userId); params.put("userId", userId);
params.put("pageSize", pageable.getPageSize()); params.put("size", pageable.getPageSize());
params.put("offset", pageable.getPageNumber() * pageable.getPageSize()); params.put("number", pageable.getPageNumber());
if (ObjectUtils.isEmpty(params.get("orderBy"))) { if (ObjectUtils.isEmpty(params.get("orderBy"))) {
params.put("orderBy", "beginTime desc"); params.put("orderBy", "beginTime desc");
} }
...@@ -380,7 +394,7 @@ public class PlanTaskController extends AbstractBaseController { ...@@ -380,7 +394,7 @@ public class PlanTaskController extends AbstractBaseController {
* *
* @return * @return
*/ */
@Scheduled(cron = "${jobs.cron}") @Scheduled(cron = "${jobs.cron.static}")
@ApiOperation(value = "定时任务生成统计数据", notes = "定时任务生成统计数据") @ApiOperation(value = "定时任务生成统计数据", notes = "定时任务生成统计数据")
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@RequestMapping(value = "/initStatic", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @RequestMapping(value = "/initStatic", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
...@@ -589,29 +603,47 @@ public class PlanTaskController extends AbstractBaseController { ...@@ -589,29 +603,47 @@ public class PlanTaskController extends AbstractBaseController {
@RequestMapping(value = "/queryPlanTaskByIdNew", produces = "application/json;charset=UTF-8", method = RequestMethod.GET) @RequestMapping(value = "/queryPlanTaskByIdNew", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
public ResponseModel<Object> qryPlanTaskByIdNew( public ResponseModel<Object> qryPlanTaskByIdNew(
@ApiParam(value = "巡检计划任务ID", required = true) @RequestParam(required = true) String planTaskId) { @ApiParam(value = "巡检计划任务ID", required = true) @RequestParam(required = true) String planTaskId) {
try {
Map<String, Object> response = new HashMap<String, Object>(); Map<String, Object> rtResponse = new HashMap<String, Object>();
Map task = planTaskService.queryPlanTaskById(Long.parseLong(planTaskId)); SearchRequest request = new SearchRequest();
if (ObjectUtils.isEmpty(task) || ObjectUtils.isEmpty(task.get("planTaskId"))) { request.indices("web_app_plan_task_list");
return ResponseHelperUtil.buildErrorResponse("该计划已刷新,请重新选择!!!"); SearchSourceBuilder builder = new SearchSourceBuilder();
builder.trackTotalHits(true);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(planTaskId)) {
BoolQueryBuilder meBuilder = QueryBuilders.boolQuery();
meBuilder.must(QueryBuilders.matchPhraseQuery("planTaskId", "*" + planTaskId + "*"));
boolMust.must(meBuilder);
} }
List points = planTaskService.getPlanTaskPoints(Long.parseLong(planTaskId));
builder.query(boolMust);
request.source(builder);
String[] userIds = task.get("userId").toString().split(","); SearchResponse response = null;
for (String userId : userIds) {
task.put("userId", userId);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
task.put("checkDate", sdf.format(task.get("checkDate") != null ? sdf.parse(task.get("checkDate").toString()) : new Date()));
response.put("planTask", task);
response.put("points", points);
Object ov= response!=null?ToJson.tojson(response):null;
return ResponseHelper.buildResponse(ov);
} catch (Exception e) {
return ResponseHelperUtil.buildErrorResponse(e.getMessage());
}
long totle = 0;
try {
response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
for (org.elasticsearch.search.SearchHit hit : response.getHits().getHits()) {
System.out.println(hit);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(hit);
JSONObject dto2 = jsonObject.getJSONObject("sourceAsMap");
rtResponse.put("points", dto2.getJSONArray("points"));
dto2.remove("points");
rtResponse.put("planTask", dto2);
}
totle = response.getInternalResponse().hits().getTotalHits().value;
if (totle == 0) {
return ResponseHelperUtil.buildErrorResponse("该计划已刷新,请重新选择!!!");
} else {
Object ov= rtResponse!=null?ToJson.tojson(rtResponse):null;
return ResponseHelper.buildResponse(ov);
}
} catch (IOException e) {
e.printStackTrace();
}
return ResponseHelperUtil.buildErrorResponse("该计划已刷新,请重新选择!!!");
} }
...@@ -938,17 +970,50 @@ public class PlanTaskController extends AbstractBaseController { ...@@ -938,17 +970,50 @@ public class PlanTaskController extends AbstractBaseController {
public ResponseModel<Object> queryPointPlanTaskDetail( public ResponseModel<Object> queryPointPlanTaskDetail(
@ApiParam(value = "巡检计划任务ID", required = true) @RequestParam(required = true) String planTaskId, @ApiParam(value = "巡检计划任务ID", required = true) @RequestParam(required = true) String planTaskId,
@ApiParam(value = "巡检点ID", required = true) @RequestParam(required = true) String pointId) { @ApiParam(value = "巡检点ID", required = true) @RequestParam(required = true) String pointId) {
SearchRequest request = new SearchRequest();
request.indices("web_app_task_detail");
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.trackTotalHits(true);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(planTaskId)) {
BoolQueryBuilder meBuilder = QueryBuilders.boolQuery();
meBuilder.must(QueryBuilders.matchPhraseQuery("planTaskId", "*" + planTaskId + "*"));
boolMust.must(meBuilder);
}
if (!ObjectUtils.isEmpty(pointId)) {
BoolQueryBuilder meBuilder = QueryBuilders.boolQuery();
meBuilder.must(QueryBuilders.matchPhraseQuery("pointId", "*" + planTaskId + "*"));
boolMust.must(meBuilder);
}
builder.query(boolMust);
request.source(builder);
SearchResponse response = null;
long totle = 0;
Map map = null;
try { try {
AppPointCheckRespone result = planTaskService.queryPointPlanTaskDetail(getToken(), getProduct(), getAppKey(), Long.parseLong(planTaskId), Long.parseLong(pointId)); response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
if (ObjectUtils.isEmpty(result)) { for (org.elasticsearch.search.SearchHit hit : response.getHits().getHits()) {
return ResponseHelperUtil.buildErrorResponse("该计划巡检点已更新,请退回重新选择"); System.out.println(hit);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(hit);
JSONObject dto2 = jsonObject.getJSONObject("sourceAsMap");
map = dto2;
} }
Object ov= result!=null?ToJson.tojson(result):null; totle = response.getInternalResponse().hits().getTotalHits().value;
return ResponseHelper.buildResponse(ov); if (totle == 0) {
} catch (Exception e) { return ResponseHelperUtil.buildErrorResponse("该点不存在,请重新选择!!!");
log.error(e.getMessage(), e); } else {
return ResponseHelperUtil.buildErrorResponse(e.getMessage()); Object ov= ToJson.tojson(map);
return ResponseHelper.buildResponse(ov);
}
} catch (IOException e) {
e.printStackTrace();
} }
return ResponseHelperUtil.buildErrorResponse("该点不存在,请重新选择!!!");
} }
/** /**
...@@ -1123,6 +1188,7 @@ public class PlanTaskController extends AbstractBaseController { ...@@ -1123,6 +1188,7 @@ public class PlanTaskController extends AbstractBaseController {
} }
} }
@Scheduled(cron = "${jobs.cron.bak}")
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "巡检当天数据归档", notes = "巡检当天数据归档") @ApiOperation(value = "巡检当天数据归档", notes = "巡检当天数据归档")
@RequestMapping(value = "/sharding/bak", produces = "application/json;charset=UTF-8", method = RequestMethod.GET) @RequestMapping(value = "/sharding/bak", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
......
...@@ -51,6 +51,14 @@ import org.apache.commons.compress.utils.Sets; ...@@ -51,6 +51,14 @@ import org.apache.commons.compress.utils.Sets;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType; import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType; import org.apache.shardingsphere.transaction.core.TransactionType;
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.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -172,6 +180,9 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -172,6 +180,9 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
@Autowired @Autowired
private RepositoryTs repositoryTs; private RepositoryTs repositoryTs;
@Autowired
RestHighLevelClient restHighLevelClient;
private String DB = "amos_tzs_biz."; private String DB = "amos_tzs_biz.";
private String P_STATIC_DAY = "p_static_day"; private String P_STATIC_DAY = "p_static_day";
...@@ -679,6 +690,11 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -679,6 +690,11 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void taskStaticExecution(String runDate) { public void taskStaticExecution(String runDate) {
try {
runDate = DateUtils.dateFormat(new Date(), DateUtils.DATE_PATTERN);
} catch (ParseException e) {
e.printStackTrace();
}
// 判断当天是不是月第一天 // 判断当天是不是月第一天
int date = DateUtils.getDate(new Date()); int date = DateUtils.getDate(new Date());
int month = DateUtils.getMonth(new Date()); int month = DateUtils.getMonth(new Date());
...@@ -719,21 +735,21 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -719,21 +735,21 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
} }
// 插入日统计表 // 插入日统计表
List<Map<String, Object>> listDay = checkMapper.planCount(null, null, String.valueOf(PlanTaskTypeStatusEnum.day.getValue()), null,null,null); List<Map<String, Object>> listDay = checkMapper.planCount(runDate, null, String.valueOf(PlanTaskTypeStatusEnum.day.getValue()), null,null,null);
List<StaticDay> staticDays = listDay.stream().map(e->{ List<StaticDay> staticDays = listDay.stream().map(e->{
String s = JSON.toJSONString(e); String s = JSON.toJSONString(e);
StaticDay staticDay = JSON.parseObject(s, StaticDay.class); StaticDay staticDay = JSON.parseObject(s, StaticDay.class);
return staticDay; return staticDay;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
// 插入周统计表 // 插入周统计表
List<Map<String, Object>> listWeek = checkMapper.planCount(null, null, String.valueOf(PlanTaskTypeStatusEnum.week.getValue()), null,null,null); List<Map<String, Object>> listWeek = checkMapper.planCount(runDate, null, String.valueOf(PlanTaskTypeStatusEnum.week.getValue()), null,null,null);
List<StaticWeek> staticWeeks = listWeek.stream().map(e->{ List<StaticWeek> staticWeeks = listWeek.stream().map(e->{
String s = JSON.toJSONString(e); String s = JSON.toJSONString(e);
StaticWeek staticWeek = JSON.parseObject(s, StaticWeek.class); StaticWeek staticWeek = JSON.parseObject(s, StaticWeek.class);
return staticWeek; return staticWeek;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
// 插入月统计表 // 插入月统计表
List<Map<String, Object>> listMonth = checkMapper.planCount(null, null, String.valueOf(PlanTaskTypeStatusEnum.month.getValue()), null,null,null); List<Map<String, Object>> listMonth = checkMapper.planCount(runDate, null, String.valueOf(PlanTaskTypeStatusEnum.month.getValue()), null,null,null);
List<StaticMonth> staticMonths = listMonth.stream().map(e->{ List<StaticMonth> staticMonths = listMonth.stream().map(e->{
String s = JSON.toJSONString(e); String s = JSON.toJSONString(e);
StaticMonth staticMonth = JSON.parseObject(s, StaticMonth.class); StaticMonth staticMonth = JSON.parseObject(s, StaticMonth.class);
...@@ -1299,42 +1315,62 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -1299,42 +1315,62 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
if(params.containsKey("type")) { if(params.containsKey("type")) {
params.put("type", String.valueOf(PlanTaskTypeStatusEnum.getValue(params.get("type").toString()))); params.put("type", String.valueOf(PlanTaskTypeStatusEnum.getValue(params.get("type").toString())));
} }
long total = planTaskMapper.getPlanTasksCount(params);
if (total == 0) { SearchRequest request = new SearchRequest();
return new PageImpl<>(content, pageParam, total); request.indices("web_app_plan_task_list");
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.trackTotalHits(true);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(params.get("userId"))) {
BoolQueryBuilder meBuilder = QueryBuilders.boolQuery();
meBuilder.must(QueryBuilders.matchPhraseQuery("userId", "*" + params.get("userId") + "*"));
boolMust.must(meBuilder);
}
if (!ObjectUtils.isEmpty(params.get("orgCode"))) {
BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.matchPhraseQuery("orgCode", "*" + params.get("orgCode") + "*"));
boolMust.must(query);
} }
content = planTaskMapper.getPlanTasks(params); if (!ObjectUtils.isEmpty(params.get("finishStatus"))) {
BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.matchPhraseQuery("finishStatus", "*" + params.get("finishStatus") + "*"));
boolMust.must(query);
}
// if (!ObjectUtils.isEmpty(params.get("type"))) {
// BoolQueryBuilder query = QueryBuilders.boolQuery();
// query.must(QueryBuilders.matchPhraseQuery("type", "*" + params.get("type") + "*"));
// boolMust.must(query);
// }
if (!CollectionUtils.isEmpty(content)) { builder.query(boolMust);
// Set<String> userIds = Sets.newHashSet(); builder.sort("checkDate", SortOrder.DESC);
// content.forEach(e -> { builder.from((Integer.parseInt(params.get("number").toString()) - 1) * Integer.parseInt(params.get("size").toString()));
// String userId = e.get("userId").toString(); builder.size(Integer.parseInt(params.get("size").toString()));
// if (StringUtil.isNotEmpty(userId)) { request.source(builder);
// userIds.add(userId);
// }
// });
// List<AgencyUserModel> userModelList = remoteSecurityService.listUserByUserIds(toke, product, appKey, Joiner.on(",").join(userIds));
// Map<String, String> userModelMap = userModelList.stream().collect(Collectors.toMap(AgencyUserModel::getUserId, AgencyUserModel::getRealName, (k1, k2) -> k2));
// List<String> userNames = new ArrayList<>();
// content.forEach(e -> {
// userNames.clear();
// String[] userIds1 = e.get("userId").toString().split(",");
// for (String userId : userIds1) {
// if (!ObjectUtils.isEmpty(userModelMap.get(userId))) {
// userNames.add(userModelMap.get(userId));
// }
// }
// if (userNames.size() > 0) {
// e.put("executiveName", Joiner.on(",").join(userNames));
// } else {
// e.put("executiveName", " ");
// }
// });
content.forEach(e -> {
e.put("executiveName",e.get("userName") );
}); List<Map<String, Object>> list = new LinkedList<>();
return new PageImpl<>(content, pageParam, total); SearchResponse response = null;
long totle = 0;
try {
response = restHighLevelClient.search(request, RequestOptions.DEFAULT);
for (org.elasticsearch.search.SearchHit hit : response.getHits().getHits()) {
System.out.println(hit);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(hit);
JSONObject dto2 = jsonObject.getJSONObject("sourceAsMap");
Map map = dto2;
list.add(map);
}
totle = response.getInternalResponse().hits().getTotalHits().value;
if (!CollectionUtils.isEmpty(list)) {
list.forEach(e -> {
e.put("executiveName",e.get("userName") );
});
}
return new PageImpl<>(list, pageParam, totle);
} catch (IOException e) {
e.printStackTrace();
} }
return new PageImpl<>(new ArrayList<>(), pageParam, 0); return new PageImpl<>(new ArrayList<>(), pageParam, 0);
} }
......
...@@ -566,6 +566,7 @@ ...@@ -566,6 +566,7 @@
p_plan_task pt p_plan_task pt
WHERE WHERE
pt.plan_type = #{type} pt.plan_type = #{type}
AND pt.check_date = #{checkTime}
GROUP BY pt.use_code GROUP BY pt.use_code
</select> </select>
......
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