package com.cloud.control.controller;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.cloud.control.service.ClusterService;
|
import com.cloud.control.service.TaskService;
|
import com.cloud.model.common.Result;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.http.MediaType;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
@Slf4j
|
@RestController
|
@RequestMapping(value = "data/api-c/task")
|
@Api(value = "data/api-c/task" ,description = "布控列表查询")
|
public class TaskController {
|
|
@Autowired
|
private TaskService taskService;
|
@Autowired
|
private ClusterService clusterService;
|
|
private SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
|
private SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
@RequestMapping(value = "findTaskList",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "任务列表",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"startTime\":\"\",\"endTime\":\"\",\"likeName\":\"\",\"status\":1," +
|
"\"source\":\"\",\"page\":1,\"size\":4,\"sortName\":\"可空/name-- 布控任务 /startTime 开始时间/endTime结束时间/status 布控状态 " +
|
"/personCount 布控人数/ source来源/scope 范围/ createBy 操作人\",\"sortType\":\"desc/asc\"}",dataType = "Map")
|
public Result findTaskListByPage(@RequestBody Map<String,Object> requMap) throws ParseException {
|
String startStr = (String) requMap.get("startTime");
|
Date startTime = null;
|
if (!StringUtils.isBlank(startStr)){
|
startTime = sdfTime.parse(startStr);
|
}
|
String endStr = (String) requMap.get("endTime");
|
Date endTime = null;
|
if (!StringUtils.isBlank(endStr)){
|
endTime = sdfTime.parse(endStr);
|
}
|
String likeName = (String) requMap.get("likeName");
|
Integer status = (Integer) requMap.get("status");
|
String source = (String) requMap.get("source");
|
Integer page = (Integer) requMap.get("page");
|
Integer size = (Integer) requMap.get("size");
|
String sortName = (String) requMap.get("sortName");
|
// name-- 布控任务 startTime -- 开始时间 endTime -- status 布控状态 -- personCount 布控人数
|
// source scope createBy 操作人
|
String sortType = (String) requMap.get("sortType"); //
|
if (startTime != null && startTime.toString().isEmpty()){ startTime = null; }
|
if (endTime != null && endTime.toString().isEmpty()){ endTime = null;}
|
if (StringUtils.isBlank(likeName)){ likeName = null;}
|
if (StringUtils.isBlank(source)){ source = null;}
|
if (page == null){ page = 1;}
|
if (size == null) {size = 10;}
|
if (sortType == null || sortType.equalsIgnoreCase("desc")){ sortType= "desc";}
|
else {sortType = "asc";}
|
int from = (page - 1)* size;
|
JSONObject respTask = taskService.queryTaskListByPage(startTime, endTime, likeName, status, source,
|
from, size,sortName,sortType);
|
return Result.ok("查询布控任务列表成功。", respTask);
|
}
|
|
@RequestMapping(value = "findSourceList",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "来源列表",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
public Result findSourceList() throws ParseException {
|
JSONObject respTask = taskService.querySoureList();
|
return Result.ok("查询布控任务列表成功。", respTask);
|
}
|
|
@RequestMapping(value = "findOneTask",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "查询任务信息",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"taskId\":\"id\"}")
|
public Result findOneTask(@RequestBody Map<String,String> reqMap) throws ParseException {
|
String taskId = reqMap.get("taskId");
|
if (StringUtils.isBlank(taskId)){
|
throw new IllegalArgumentException("taskId 为空");
|
}
|
JSONObject respTask = taskService.queryTaskById(taskId);
|
return Result.ok("查询布控任务列表成功。", respTask);
|
}
|
|
@RequestMapping(value = "findScopeDetailByTaskId",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "查询布控范围列表详情",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"taskId\":\"id\"}")
|
public Result findScopeDetailByTaskId(@RequestBody Map<String,String> reqMap) throws ParseException {
|
String taskId = reqMap.get("taskId");
|
if (StringUtils.isBlank(taskId)){
|
throw new IllegalArgumentException("taskId 为空");
|
}
|
JSONArray respTask = taskService.queryTaskScopeDetailById(taskId);
|
return Result.ok("查询布控范围列表详情。", respTask);
|
}
|
|
/**
|
* 测试使用
|
* @return
|
*/
|
@RequestMapping(value = "findAllNode",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "测试使用 查询全部节点数据",
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
public Result findAllNode(@RequestBody Map<String,Object> reqMap){
|
// Date date = (Date) reqMap.get("date");
|
// log.info(date+"时间类型接收");
|
Result allNode = clusterService.findAllNode();
|
return allNode;
|
}
|
|
/**
|
* 前端创建布控任务
|
* @return
|
*/
|
@RequestMapping(value = "addTask",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "前端创建布控任务",
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"taskName\":\"\",\"threshold\":69,\"startTime\":\"yyyy/MM/dd HH:mm:ss\"," +
|
"\"endTime\":\"yyyy/MM/dd HH:mm:ss\",\"Ids\":[\"devid1\",\"devid2\"]}")
|
public Result addTask(@RequestBody Map<String,Object> reqMap) throws ParseException {
|
String taskName = (String) reqMap.get("taskName");
|
Integer threshold = (Integer) reqMap.get("threshold");
|
String start = (String) reqMap.get("startTime");
|
Date startTime = sdfTime.parse(start);
|
String end = (String) reqMap.get("endTime");
|
Date endTime = sdfTime.parse(end);
|
List<String> devIds = (List<String>) reqMap.get("Ids");
|
if (StringUtils.isBlank(taskName) || threshold == null || startTime == null || endTime == null || devIds == null || devIds.size() <1){
|
String reqParamMsg = "taskName:"+taskName+"threshold:"+threshold+"startTime:"+startTime+"endTime:"+endTime+"devIds:"+devIds.toString();
|
return Result.error(new IllegalArgumentException(reqParamMsg+"参数为空"));
|
}
|
JSONObject jsonObj = taskService.addTaskForIndevice(null,taskName, threshold, startTime, endTime,
|
devIds,false,null);
|
if (jsonObj.getString("code")!=null){
|
return Result.custom("布控任务已存在",40010,false,jsonObj);
|
}
|
if (jsonObj.getBoolean("result")){
|
return Result.ok(jsonObj.getString("msg"),jsonObj);
|
}else {
|
return Result.error(new RuntimeException(jsonObj.getString("msg")));
|
}
|
}
|
|
/**
|
* 前端修改布控任务
|
* @return
|
*/
|
@RequestMapping(value = "updateTask",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "前端修改布控任务",
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"taskName\":\"\",\"id\":\"taskId\",\"threshold\":69,\"startTime\":\"yyyy/MM/dd HH:mm:ss\"," +
|
"\"endTime\":\"yyyy/MM/dd HH:mm:ss\",\"nowDevIds\":[\"devId1\",\"devId2\"]}")
|
public Result updateTask(@RequestBody Map<String,Object> reqMap) throws ParseException {
|
String taskName = (String) reqMap.get("taskName");
|
String uuid = (String) reqMap.get("id");
|
Integer threshold = (Integer) reqMap.get("threshold");
|
String start = (String) reqMap.get("startTime");
|
Date startTime = sdfTime.parse(start);
|
String end = (String) reqMap.get("endTime");
|
Date endTime = sdfTime.parse(end);
|
List<String> nowDevIds = (List<String>) reqMap.get("nowDevIds");
|
if (StringUtils.isBlank(uuid) ){
|
String reqParamMsg = "taskName:"+taskName+"threshold:"+threshold+"startTime:"
|
+startTime+"endTime:"+endTime+"nowDevIds:"+nowDevIds.toString();
|
return Result.error(new IllegalArgumentException(reqParamMsg+"参数为空"));
|
}
|
JSONObject jsonObj = taskService.updateTask(uuid,taskName, threshold, startTime, endTime, nowDevIds);
|
if (jsonObj.getBoolean("result")){
|
return Result.ok(jsonObj.getString("msg"),jsonObj);
|
}else {
|
return Result.error(new RuntimeException(jsonObj.getString("msg")));
|
}
|
}
|
|
/**
|
* 前端停止布控任务
|
* @return
|
*/
|
@RequestMapping(value = "stopTask",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "停止布控任务",
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"id\":\"taskId\"}")
|
public Result stopTask(@RequestBody Map<String,Object> reqMap){
|
String uuid = (String) reqMap.get("id");
|
// String taskName = (String) reqMap.get("taskName");
|
if (StringUtils.isBlank(uuid) ){
|
String reqParamMsg = "uuid:"+uuid;
|
return Result.error(new IllegalArgumentException(reqParamMsg+"参数为空"));
|
}
|
JSONObject jsonObj = taskService.stopTask(uuid); // taskName
|
if (jsonObj.getBoolean("result")){
|
return Result.ok(jsonObj.getString("msg"),jsonObj);
|
}else{
|
return Result.error(new RuntimeException(jsonObj.getString("msg")));
|
}
|
}
|
|
/**
|
* 前端删除布控任务
|
* @return
|
*/
|
@RequestMapping(value = "delTask",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "删除布控任务 ",
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"id\":\"taskId\"}")
|
public Result delTask(@RequestBody Map<String,Object> reqMap){
|
String uuid = (String) reqMap.get("id");
|
// String taskName = (String) reqMap.get("taskName");
|
// List<String> devIds = (List<String>) reqMap.get("devIds");
|
if (StringUtils.isBlank(uuid)){ // || devIds == null || devIds.size() <1
|
String reqParamMsg = "uuid:"+uuid; // +"devIds:"+devIds.toString()
|
return Result.error(new IllegalArgumentException(reqParamMsg+"参数为空"));
|
}
|
JSONObject jsonObj = taskService.delTask(uuid); // devIds taskName
|
if (jsonObj.getBoolean("result")){
|
return Result.ok(jsonObj.getString("msg"),jsonObj);
|
}else{
|
return Result.error(new RuntimeException(jsonObj.getString("msg")));
|
}
|
}
|
|
/**
|
* c 调用 创建 布控任务
|
* @return
|
*/
|
@RequestMapping(value = "addTaskByNode",method = RequestMethod.POST)
|
@ApiOperation(value = "",notes = "c 调用创建布控报警底库任务",
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE,httpMethod = "POST")
|
@ApiImplicitParam(value = "{\"TableName\":\"\",\"SyncType\":\"1/0\",\"threshold\":60,\"StartTime\":\"yyyy/MM/dd HH:mm:ss\"," +
|
" \"EndTime\":\"yyyy/MM/dd HH:mm:ss\",\"enabled\":\"1\",\"cluId\":\"\",\"devId\":\"\",\"uuid\":\"\"}")
|
public Result addTaskByNode(@RequestBody Map<String,Object> reqMap) throws ParseException {
|
String taskName = (String) reqMap.get("TableName");
|
String syncType = (String) reqMap.get("SyncType");
|
Integer threshold = (Integer) reqMap.get("threshold");
|
String start = (String) reqMap.get("StartTime");
|
Date startTime = sdfDate.parse(start);
|
String end =(String) reqMap.get("EndTime");
|
Date endTime = sdfDate.parse(end);
|
String enabled = (String) reqMap.get("enabled");
|
String cluId = (String) reqMap.get("cluId");
|
String devId = (String) reqMap.get("devId");
|
String uuid = (String) reqMap.get("uuid");
|
if (StringUtils.isBlank(taskName) || threshold == null || startTime == null || endTime == null || StringUtils.isBlank(cluId)
|
|| StringUtils.isBlank(devId)|| StringUtils.isBlank(uuid)){
|
String reqParamMsg = "taskName:"+taskName+"threshold:"+threshold+"startTime:"+startTime+"endTime:"+endTime+
|
"cluId:"+cluId.toString()+"devId:"+devId;
|
return Result.error(new IllegalArgumentException(reqParamMsg+"参数为空"));
|
}
|
JSONObject jsonObj = taskService.addTaskByNode(uuid,taskName, threshold, startTime, endTime,syncType, enabled,cluId,devId);
|
if (jsonObj.getBoolean("result")){
|
return Result.ok(jsonObj.getString("msg"),jsonObj);
|
}else {
|
return Result.error(new RuntimeException(jsonObj.getString("msg")));
|
}
|
}
|
|
@RequestMapping(value = "getAddToCtlTree")
|
@ApiOperation(value = "获取加入布控树", notes = "获取加入布控树", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
public Result getAddToCtlTree(){
|
try {
|
return Result.ok("查询成功", taskService.getAddToCtlTree());
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(e);
|
}
|
}
|
|
}
|