From 17bc8f1442183aa0753df19f24fd1caf5d383139 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Thu, 9 Jun 2022 15:29:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/ShangTangTaskProperties.java | 22 +++++ .../impl/TAbilityApplicationServiceImpl.java | 2 +- .../controller/ShangTangController.java | 39 --------- .../taskList/service/ShangTangService.java | 18 +++-- .../taskList/task/InsertTaskListJob.java | 80 +++++++++++++++++++ .../processForm/TAbilityApplicationDao.xml | 2 +- .../main/resources/shangtangtask.properties | 8 ++ 7 files changed, 123 insertions(+), 48 deletions(-) create mode 100644 renren-admin/src/main/java/io/renren/common/interceptor/ShangTangTaskProperties.java create mode 100644 renren-admin/src/main/java/io/renren/modules/taskList/task/InsertTaskListJob.java create mode 100644 renren-admin/src/main/resources/shangtangtask.properties diff --git a/renren-admin/src/main/java/io/renren/common/interceptor/ShangTangTaskProperties.java b/renren-admin/src/main/java/io/renren/common/interceptor/ShangTangTaskProperties.java new file mode 100644 index 00000000..f00e5ab5 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/common/interceptor/ShangTangTaskProperties.java @@ -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; +} diff --git a/renren-admin/src/main/java/io/renren/modules/processForm/service/impl/TAbilityApplicationServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/processForm/service/impl/TAbilityApplicationServiceImpl.java index 3856e406..a5476383 100644 --- a/renren-admin/src/main/java/io/renren/modules/processForm/service/impl/TAbilityApplicationServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/processForm/service/impl/TAbilityApplicationServiceImpl.java @@ -82,7 +82,7 @@ public class TAbilityApplicationServiceImpl extends CrudServiceImpl key = (Map) 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 key1 = (Map) 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); -// } -// } -// } -// } -// } } } diff --git a/renren-admin/src/main/java/io/renren/modules/taskList/service/ShangTangService.java b/renren-admin/src/main/java/io/renren/modules/taskList/service/ShangTangService.java index 3677e901..6bfaf40b 100644 --- a/renren-admin/src/main/java/io/renren/modules/taskList/service/ShangTangService.java +++ b/renren-admin/src/main/java/io/renren/modules/taskList/service/ShangTangService.java @@ -1,7 +1,9 @@ package io.renren.modules.taskList.service; import com.alibaba.fastjson.JSONObject; +import io.renren.common.interceptor.ShangTangTaskProperties; import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -17,11 +19,13 @@ public class ShangTangService { @Resource private RestTemplate restTemplate; + @Autowired + private ShangTangTaskProperties shangTangTaskProperties; //1.登录 //2.获取token public String shangtangToken() { - String url = "http://10.132.191.54:10270/whale-open-api/tenant/token"; + String url = shangTangTaskProperties.getToken_url(); Map map = new HashMap<>(); map.put("accessKey", "a1ddCV7z7Jhv0SBGx5O3hblO"); @@ -43,7 +47,7 @@ public class ShangTangService { //订阅任务下发接口 public JSONObject subscribe() { 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(); headers.setContentType(MediaType.APPLICATION_JSON); @@ -52,7 +56,7 @@ public class ShangTangService { headers.add("tid", "default"); Map 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("subscribeType", 3); // map.put("taskId","serial"); @@ -73,7 +77,7 @@ public class ShangTangService { //事件模板分页查询接口 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"; + String url = shangTangTaskProperties.getTemplate_url(); HttpHeaders headers = new HttpHeaders(); headers.add("token", token); @@ -94,14 +98,14 @@ public class ShangTangService { //场景任务列表查询接口 public JSONObject tasklist(String eventType) { 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(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add("token", token); headers.add("tid", "default"); - //需要传的参数 +// 需要传的参数 // "eventType": "${appletId}-${eventType}", // 事件唯一标识 // "pageNum": "integer (int32)", // "pageSize": "integer (int32)", @@ -129,7 +133,7 @@ public class ShangTangService { //场景任务详情查询接口 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 = shangTangTaskProperties.getTasklistdetail_url() + taskSerial; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); diff --git a/renren-admin/src/main/java/io/renren/modules/taskList/task/InsertTaskListJob.java b/renren-admin/src/main/java/io/renren/modules/taskList/task/InsertTaskListJob.java new file mode 100644 index 00000000..39f7e8e8 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/modules/taskList/task/InsertTaskListJob.java @@ -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 jobj = Optional.ofNullable(shangTangService.template()); + Optional datajobj = Optional.ofNullable(jobj.orElse(new JSONObject()).getJSONObject("data")); + Optional tamplateList = Optional.ofNullable(datajobj.orElse(new JSONObject()).getJSONArray("dataList")); + tamplateList.orElse(new JSONArray()).parallelStream().forEach(index -> { + Map key = (Map) index; + String eventType = (String) key.get("eventType"); + String eventCnName = (String) key.get("eventCnName"); + JSONObject taskListBody = shangTangService.tasklist(eventType); + if (taskListBody.isEmpty()) { + return; + } + Optional taskdatajobj = Optional.ofNullable(taskListBody.getJSONObject("data")); + taskdatajobj.ifPresent(task -> { + Optional taskdatajobjJSONArray = Optional.ofNullable(task.getJSONArray("dataList")); + taskdatajobjJSONArray.orElse(new JSONArray()).stream().forEach(index_ -> { + Map key1 = (Map) index_; + String taskSerial = (String) key1.get("taskSerial"); + Integer taskStatus = (Integer) key1.get("taskStatus"); + + Optional 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); + }); + }); + }); + } +} diff --git a/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml b/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml index 5ec6d8df..ede4e848 100644 --- a/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml +++ b/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml @@ -114,7 +114,7 @@ t_ability_application WHERE 1 = 1 - AND del_flag = 0 + AND (approve_status = '审核中' OR approve_status = '通过') AND user_id = #{userId} AND resource_id = #{resourceId} diff --git a/renren-admin/src/main/resources/shangtangtask.properties b/renren-admin/src/main/resources/shangtangtask.properties new file mode 100644 index 00000000..790fc552 --- /dev/null +++ b/renren-admin/src/main/resources/shangtangtask.properties @@ -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/ \ No newline at end of file