屮...
This commit is contained in:
parent
2a21a57ede
commit
37229a1743
|
@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("STapi/project")
|
||||
|
@ -29,74 +30,106 @@ public class ShangTangController {
|
|||
private TaskListControllerDao taskListControllerDao;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 事件模板分页查询接口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("tamplate")
|
||||
@ApiOperation("事件模板分页查询接口")
|
||||
public JSONObject tamplate(){
|
||||
|
||||
public JSONObject tamplate() {
|
||||
return shangTangService.template();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时插入场景任务列表
|
||||
*
|
||||
*/
|
||||
@RequestMapping("insertTaskList")
|
||||
@ApiOperation("场景任务列表插入")
|
||||
@Scheduled(cron = "0 */1 * * * ?")
|
||||
@Transactional
|
||||
public void insertTaskList(){
|
||||
public void insertTaskList() {
|
||||
|
||||
taskListControllerDao.deleteAll();
|
||||
|
||||
JSONObject jobj = this.tamplate();
|
||||
JSONObject datajobj = jobj.getJSONObject("data");
|
||||
JSONArray tamplateList = datajobj.getJSONArray("dataList");
|
||||
//JSONArray tamplateList = jobj.getJSONArray("data");//构建JSONArray数组
|
||||
|
||||
for (int i = 0 ; i < tamplateList.size();i++) {
|
||||
Map<String, Object> key = (Map<String, Object>) tamplateList.get(i);
|
||||
Optional<JSONObject> jobj = Optional.ofNullable(this.tamplate());
|
||||
Optional<JSONObject> datajobj = Optional.ofNullable(jobj.orElse(new JSONObject()).getJSONObject("data"));
|
||||
Optional<JSONArray> tamplateList = Optional.ofNullable(datajobj.orElse(new JSONObject()).getJSONArray("dataList"));
|
||||
tamplateList.orElse(new JSONArray()).parallelStream().forEach(index -> {
|
||||
Map<String, Object> key = (Map<String, Object>) index;
|
||||
String eventType = (String) key.get("eventType");
|
||||
String eventCnName = (String)key.get("eventCnName");
|
||||
JSONObject taskListBody = shangTangService.tasklist(eventType);
|
||||
if (taskListBody.size()>0){
|
||||
JSONObject taskdatajobj = taskListBody.getJSONObject("data");
|
||||
if (taskdatajobj!=null){
|
||||
JSONArray taskdatajobjJSONArray = taskdatajobj.getJSONArray("dataList");
|
||||
if (taskdatajobjJSONArray!=null){
|
||||
for (int j = 0 ; j < taskdatajobjJSONArray.size();j++) {
|
||||
Map<String, Object> key1 = (Map<String, Object>)taskdatajobjJSONArray.get(j);
|
||||
|
||||
String taskSerial = (String) key1.get("taskSerial");
|
||||
Integer taskStatus = (Integer) key1.get("taskStatus");
|
||||
|
||||
JSONObject taskDetailObj = shangTangService.tasklistDetail(taskSerial);
|
||||
JSONObject taskDetail = taskDetailObj.getJSONObject("data");
|
||||
|
||||
TaskListControllerEntity taskListobj = new TaskListControllerEntity();
|
||||
|
||||
if (taskDetail!=null){
|
||||
String taskName = taskDetail.getString("taskName");
|
||||
taskListobj .setTaskName(taskName);
|
||||
}else{
|
||||
taskListobj .setTaskName("任务停止");
|
||||
}
|
||||
|
||||
taskListobj .setTaskSerial(taskSerial);
|
||||
taskListobj.setTaskStatus(taskStatus);
|
||||
|
||||
taskListobj .setEventType(eventType);
|
||||
taskListobj .setEventCnName(eventCnName);
|
||||
taskListControllerDao.insert(taskListobj);
|
||||
}
|
||||
}
|
||||
}
|
||||
String eventCnName = (String) key.get("eventCnName");
|
||||
JSONObject taskListBody = shangTangService.tasklist(eventType);
|
||||
if (taskListBody.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Optional<JSONObject> taskdatajobj = Optional.ofNullable(taskListBody.getJSONObject("data"));
|
||||
taskdatajobj.ifPresent(task -> {
|
||||
Optional<JSONArray> taskdatajobjJSONArray = Optional.ofNullable(task.getJSONArray("dataList"));
|
||||
taskdatajobjJSONArray.orElse(new JSONArray()).stream().forEach(index_ -> {
|
||||
Map<String, Object> key1 = (Map<String, Object>) index_;
|
||||
String taskSerial = (String) key1.get("taskSerial");
|
||||
Integer taskStatus = (Integer) key1.get("taskStatus");
|
||||
|
||||
Optional<JSONObject> taskDetailObj = Optional.ofNullable(shangTangService.tasklistDetail(taskSerial));
|
||||
JSONObject taskDetail = taskDetailObj.orElse(new JSONObject()).getJSONObject("data");
|
||||
|
||||
TaskListControllerEntity taskListobj = new TaskListControllerEntity();
|
||||
|
||||
if (taskDetail != null) {
|
||||
String taskName = taskDetail.getString("taskName");
|
||||
taskListobj.setTaskName(taskName);
|
||||
} else {
|
||||
taskListobj.setTaskName("任务停止");
|
||||
}
|
||||
|
||||
taskListobj.setTaskSerial(taskSerial);
|
||||
taskListobj.setTaskStatus(taskStatus);
|
||||
|
||||
taskListobj.setEventType(eventType);
|
||||
taskListobj.setEventCnName(eventCnName);
|
||||
taskListControllerDao.insert(taskListobj);
|
||||
});
|
||||
});
|
||||
});
|
||||
// for (int i = 0; i < tamplateList.orElse(new JSONArray()).size(); i++) {
|
||||
// Map<String, Object> key = (Map<String, Object>) tamplateList.get().get(i);
|
||||
// String eventType = (String) key.get("eventType");
|
||||
// String eventCnName = (String) key.get("eventCnName");
|
||||
// JSONObject taskListBody = shangTangService.tasklist(eventType);
|
||||
// if (taskListBody.size() > 0) {
|
||||
// JSONObject taskdatajobj = taskListBody.getJSONObject("data");
|
||||
// if (taskdatajobj != null) {
|
||||
// JSONArray taskdatajobjJSONArray = taskdatajobj.getJSONArray("dataList");
|
||||
// if (taskdatajobjJSONArray != null) {
|
||||
// for (int j = 0; j < taskdatajobjJSONArray.size(); j++) {
|
||||
// Map<String, Object> key1 = (Map<String, Object>) taskdatajobjJSONArray.get(j);
|
||||
//
|
||||
// String taskSerial = (String) key1.get("taskSerial");
|
||||
// Integer taskStatus = (Integer) key1.get("taskStatus");
|
||||
//
|
||||
// JSONObject taskDetailObj = shangTangService.tasklistDetail(taskSerial);
|
||||
// JSONObject taskDetail = taskDetailObj.getJSONObject("data");
|
||||
//
|
||||
// TaskListControllerEntity taskListobj = new TaskListControllerEntity();
|
||||
//
|
||||
// if (taskDetail != null) {
|
||||
// String taskName = taskDetail.getString("taskName");
|
||||
// taskListobj.setTaskName(taskName);
|
||||
// } else {
|
||||
// taskListobj.setTaskName("任务停止");
|
||||
// }
|
||||
//
|
||||
// taskListobj.setTaskSerial(taskSerial);
|
||||
// taskListobj.setTaskStatus(taskStatus);
|
||||
//
|
||||
// taskListobj.setEventType(eventType);
|
||||
// taskListobj.setEventCnName(eventCnName);
|
||||
// taskListControllerDao.insert(taskListobj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,15 +20,15 @@ public class ShangTangService {
|
|||
|
||||
//1.登录
|
||||
//2.获取token
|
||||
public String shangtangToken () {
|
||||
public String shangtangToken() {
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/tenant/token";
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("accessKey","a1ddCV7z7Jhv0SBGx5O3hblO");
|
||||
map.put("secretKey","glIixzORLgoFJz0VdF1aXICR");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("accessKey", "a1ddCV7z7Jhv0SBGx5O3hblO");
|
||||
map.put("secretKey", "glIixzORLgoFJz0VdF1aXICR");
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
try {
|
||||
responseEntity = restTemplate.postForEntity(url,map,JSONObject.class);
|
||||
responseEntity = restTemplate.postForEntity(url, map, JSONObject.class);
|
||||
JSONObject body = responseEntity.getBody();
|
||||
JSONObject data = body.getJSONObject("data");
|
||||
String token = data.getString("token");
|
||||
|
@ -41,7 +41,7 @@ public class ShangTangService {
|
|||
}
|
||||
|
||||
//订阅任务下发接口
|
||||
public JSONObject subscribe(){
|
||||
public JSONObject subscribe() {
|
||||
String token = this.shangtangToken();
|
||||
String url = "https://10.132.191.54:10270/whale-open-api/subscribe";
|
||||
|
||||
|
@ -49,39 +49,40 @@ public class ShangTangService {
|
|||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
headers.add("token", token);
|
||||
headers.add("tid","default");
|
||||
headers.add("tid", "default");
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("callBackUrl","https://15.2.23.163:7010/STapi/project/receive");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("callBackUrl", "https://15.2.23.163:7010/STapi/project/receive");
|
||||
// map.put("certPubKey","");
|
||||
map.put("subscribeType",3);
|
||||
map.put("subscribeType", 3);
|
||||
// map.put("taskId","serial");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(map), headers);
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.POST,entity,JSONObject.class);
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.POST, entity, JSONObject.class);
|
||||
JSONObject body = responseEntity.getBody();
|
||||
return body;
|
||||
}catch (Exception e){
|
||||
log.info( "[subscribe] exception:{}",e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.info("[subscribe] exception:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//事件模板分页查询接口
|
||||
public JSONObject template(){
|
||||
public JSONObject template() {
|
||||
String token = this.shangtangToken();
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event/template?pageNum=1&pageSize=1000";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("token",token);
|
||||
headers.add("tid","default");
|
||||
headers.add("token", token);
|
||||
headers.add("tid", "default");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url,HttpMethod.GET,new HttpEntity<>(headers),JSONObject.class);
|
||||
JSONObject jsonObject = responseEntity.getBody();
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(headers), JSONObject.class);
|
||||
JSONObject jsonObject = responseEntity.getBody();
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
log.info("[template] exception:{}", e.getMessage());
|
||||
|
@ -91,7 +92,7 @@ public class ShangTangService {
|
|||
}
|
||||
|
||||
//场景任务列表查询接口
|
||||
public JSONObject tasklist(String eventType){
|
||||
public JSONObject tasklist(String eventType) {
|
||||
String token = this.shangtangToken();
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event-task/list";
|
||||
|
||||
|
@ -99,7 +100,7 @@ public class ShangTangService {
|
|||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
headers.add("token", token);
|
||||
headers.add("tid","default");
|
||||
headers.add("tid", "default");
|
||||
//需要传的参数
|
||||
// "eventType": "${appletId}-${eventType}", // 事件唯一标识
|
||||
// "pageNum": "integer (int32)",
|
||||
|
@ -107,43 +108,43 @@ public class ShangTangService {
|
|||
// "taskName": "string", //任务名称
|
||||
// "taskSerial": "string", //任务serial
|
||||
// "taskStatus": "1:运行中,2:已结束,3:异常,4:待启动,5:已停止"
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("eventType",eventType);
|
||||
map.put("pageNum",1);
|
||||
map.put("pageSize",100);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("eventType", eventType);
|
||||
map.put("pageNum", 1);
|
||||
map.put("pageSize", 100);
|
||||
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(map), headers);
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.POST,entity,JSONObject.class);
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.POST, entity, JSONObject.class);
|
||||
JSONObject taskListBody = responseEntity.getBody();
|
||||
return taskListBody;
|
||||
}catch (Exception e){
|
||||
log.info( "[tasklist] exception:{}",e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.info("[tasklist] exception:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//场景任务详情查询接口
|
||||
public JSONObject tasklistDetail(String taskSerial){
|
||||
public JSONObject tasklistDetail(String taskSerial) {
|
||||
String token = this.shangtangToken();
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event-task/"+taskSerial;
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event-task/" + taskSerial;
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
headers.add("token", token);
|
||||
headers.add("tid","default");
|
||||
headers.add("tid", "default");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
HttpEntity<String> entity = new HttpEntity<>( headers);
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.GET,entity,JSONObject.class);
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, JSONObject.class);
|
||||
JSONObject taskListDetailBody = responseEntity.getBody();
|
||||
return taskListDetailBody;
|
||||
}catch (Exception e){
|
||||
log.info( "[tasklist] exception:{}",e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.info("[tasklist] exception:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue