硬编码改为配置文件
This commit is contained in:
parent
f6a72a41db
commit
17bc8f1442
|
@ -0,0 +1,22 @@
|
||||||
|
package io.renren.common.interceptor;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@PropertySource("classpath:shangtangtask.properties")
|
||||||
|
@ConfigurationProperties(prefix = "st")
|
||||||
|
public class ShangTangTaskProperties {
|
||||||
|
private String accessKey;
|
||||||
|
private String secretKey;
|
||||||
|
private String token_url;
|
||||||
|
private String subscribe_url;
|
||||||
|
private String subscribe_callback_url;
|
||||||
|
private String template_url;
|
||||||
|
private String tasklist_url;
|
||||||
|
private String tasklistdetail_url;
|
||||||
|
}
|
|
@ -82,7 +82,7 @@ public class TAbilityApplicationServiceImpl extends CrudServiceImpl<TAbilityAppl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long countUserResourceApply(Long userId, Long resourceId) {
|
public Long countUserResourceApply(Long userId, Long resourceId) {
|
||||||
return null;
|
return baseDao.countUserResourceApply(userId, resourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -91,44 +91,5 @@ public class ShangTangController {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package io.renren.modules.taskList.service;
|
package io.renren.modules.taskList.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.renren.common.interceptor.ShangTangTaskProperties;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
@ -17,11 +19,13 @@ public class ShangTangService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RestTemplate restTemplate;
|
private RestTemplate restTemplate;
|
||||||
|
@Autowired
|
||||||
|
private ShangTangTaskProperties shangTangTaskProperties;
|
||||||
|
|
||||||
//1.登录
|
//1.登录
|
||||||
//2.获取token
|
//2.获取token
|
||||||
public String shangtangToken() {
|
public String shangtangToken() {
|
||||||
String url = "http://10.132.191.54:10270/whale-open-api/tenant/token";
|
String url = shangTangTaskProperties.getToken_url();
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("accessKey", "a1ddCV7z7Jhv0SBGx5O3hblO");
|
map.put("accessKey", "a1ddCV7z7Jhv0SBGx5O3hblO");
|
||||||
|
@ -43,7 +47,7 @@ public class ShangTangService {
|
||||||
//订阅任务下发接口
|
//订阅任务下发接口
|
||||||
public JSONObject subscribe() {
|
public JSONObject subscribe() {
|
||||||
String token = this.shangtangToken();
|
String token = this.shangtangToken();
|
||||||
String url = "https://10.132.191.54:10270/whale-open-api/subscribe";
|
String url = shangTangTaskProperties.getSubscribe_url();
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
@ -52,7 +56,7 @@ public class ShangTangService {
|
||||||
headers.add("tid", "default");
|
headers.add("tid", "default");
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("callBackUrl", "https://15.2.23.163:7010/STapi/project/receive");
|
map.put("callBackUrl", shangTangTaskProperties.getSubscribe_callback_url());
|
||||||
// map.put("certPubKey","");
|
// map.put("certPubKey","");
|
||||||
map.put("subscribeType", 3);
|
map.put("subscribeType", 3);
|
||||||
// map.put("taskId","serial");
|
// map.put("taskId","serial");
|
||||||
|
@ -73,7 +77,7 @@ public class ShangTangService {
|
||||||
//事件模板分页查询接口
|
//事件模板分页查询接口
|
||||||
public JSONObject template() {
|
public JSONObject template() {
|
||||||
String token = this.shangtangToken();
|
String token = this.shangtangToken();
|
||||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event/template?pageNum=1&pageSize=1000";
|
String url = shangTangTaskProperties.getTemplate_url();
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.add("token", token);
|
headers.add("token", token);
|
||||||
|
@ -94,14 +98,14 @@ public class ShangTangService {
|
||||||
//场景任务列表查询接口
|
//场景任务列表查询接口
|
||||||
public JSONObject tasklist(String eventType) {
|
public JSONObject tasklist(String eventType) {
|
||||||
String token = this.shangtangToken();
|
String token = this.shangtangToken();
|
||||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event-task/list";
|
String url = shangTangTaskProperties.getTasklist_url();
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
headers.add("token", token);
|
headers.add("token", token);
|
||||||
headers.add("tid", "default");
|
headers.add("tid", "default");
|
||||||
//需要传的参数
|
// 需要传的参数
|
||||||
// "eventType": "${appletId}-${eventType}", // 事件唯一标识
|
// "eventType": "${appletId}-${eventType}", // 事件唯一标识
|
||||||
// "pageNum": "integer (int32)",
|
// "pageNum": "integer (int32)",
|
||||||
// "pageSize": "integer (int32)",
|
// "pageSize": "integer (int32)",
|
||||||
|
@ -129,7 +133,7 @@ public class ShangTangService {
|
||||||
//场景任务详情查询接口
|
//场景任务详情查询接口
|
||||||
public JSONObject tasklistDetail(String taskSerial) {
|
public JSONObject tasklistDetail(String taskSerial) {
|
||||||
String token = this.shangtangToken();
|
String token = this.shangtangToken();
|
||||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event-task/" + taskSerial;
|
String url = shangTangTaskProperties.getTasklistdetail_url() + taskSerial;
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
package io.renren.modules.taskList.task;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.renren.modules.job.task.ITask;
|
||||||
|
import io.renren.modules.taskList.dao.TaskListControllerDao;
|
||||||
|
import io.renren.modules.taskList.entity.TaskListControllerEntity;
|
||||||
|
import io.renren.modules.taskList.service.ShangTangService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商汤 场景任务列表插入
|
||||||
|
*/
|
||||||
|
@Component("insertTaskListJob")
|
||||||
|
public class InsertTaskListJob implements ITask {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(InsertTaskListJob.class);
|
||||||
|
@Autowired
|
||||||
|
private ShangTangService shangTangService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskListControllerDao taskListControllerDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行定时任务接口
|
||||||
|
*
|
||||||
|
* @param params 参数,多参数使用JSON数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run(String params) {
|
||||||
|
logger.info("insertTaskList!");
|
||||||
|
taskListControllerDao.deleteAll();
|
||||||
|
Optional<JSONObject> jobj = Optional.ofNullable(shangTangService.template());
|
||||||
|
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.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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -114,7 +114,7 @@
|
||||||
t_ability_application
|
t_ability_application
|
||||||
WHERE
|
WHERE
|
||||||
1 = 1
|
1 = 1
|
||||||
AND del_flag = 0
|
AND (approve_status = '审核中' OR approve_status = '通过')
|
||||||
AND user_id = #{userId}
|
AND user_id = #{userId}
|
||||||
AND resource_id = #{resourceId}
|
AND resource_id = #{resourceId}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
st.accessKey=a1ddCV7z7Jhv0SBGx5O3hblO
|
||||||
|
st.secretKey=glIixzORLgoFJz0VdF1aXICR
|
||||||
|
st.token_url=http://10.132.191.54:10270/whale-open-api/tenant/token
|
||||||
|
st.subscribe_url=https://10.132.191.54:10270/whale-open-api/subscribe
|
||||||
|
st.subscribe_callback_url=https://15.2.23.163:7010/STapi/project/receive
|
||||||
|
st.template_url=http://10.132.191.54:10270/whale-open-api/scenario/event/template?pageNum=1&pageSize=1000
|
||||||
|
st.tasklist_url=http://10.132.191.54:10270/whale-open-api/scenario/event-task/list
|
||||||
|
st.tasklistdetail_url=http://10.132.191.54:10270/whale-open-api/scenario/event-task/
|
Loading…
Reference in New Issue