|
@@ -7,13 +7,17 @@ import com.hhwy.qbeqsjy.common.Constants;
|
|
import com.hhwy.qbeqsjy.common.HttpClient;
|
|
import com.hhwy.qbeqsjy.common.HttpClient;
|
|
import com.hhwy.qbeqsjy.common.TimeTool;
|
|
import com.hhwy.qbeqsjy.common.TimeTool;
|
|
import com.hhwy.qbeqsjy.domain.AjaxResult;
|
|
import com.hhwy.qbeqsjy.domain.AjaxResult;
|
|
-import com.hhwy.qbeqsjy.dto.BusinessDTO;
|
|
|
|
|
|
+import com.hhwy.qbeqsjy.dto.CtrlDTO;
|
|
|
|
+import com.hhwy.qbeqsjy.dto.SubmitDTO;
|
|
|
|
+import com.hhwy.qbeqsjy.task.CtrlTask;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.*;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
@@ -21,6 +25,8 @@ public class CtrlService {
|
|
|
|
|
|
@Value("${from.areacode}")
|
|
@Value("${from.areacode}")
|
|
private String fromAreaCode;
|
|
private String fromAreaCode;
|
|
|
|
+ @Value("${sys.id}")
|
|
|
|
+ private String sysId;
|
|
@Value("${to.areacode}")
|
|
@Value("${to.areacode}")
|
|
private String toAreaCode;
|
|
private String toAreaCode;
|
|
@Value("${to.sys}")
|
|
@Value("${to.sys}")
|
|
@@ -31,6 +37,8 @@ public class CtrlService {
|
|
private String servVer;
|
|
private String servVer;
|
|
@Value("${sysuserid}")
|
|
@Value("${sysuserid}")
|
|
private String sysUserId;
|
|
private String sysUserId;
|
|
|
|
+ @Value("${thread.num}")
|
|
|
|
+ private int threadNum;
|
|
@Value("${uniCtrl.add.url}")
|
|
@Value("${uniCtrl.add.url}")
|
|
private String uniCtrlAddUrl;
|
|
private String uniCtrlAddUrl;
|
|
@Value("${uniCtrl.del.url}")
|
|
@Value("${uniCtrl.del.url}")
|
|
@@ -40,112 +48,127 @@ public class CtrlService {
|
|
private HttpClient httpClient = new HttpClient();
|
|
private HttpClient httpClient = new HttpClient();
|
|
|
|
|
|
|
|
|
|
|
|
+ public void ctrl(CtrlDTO ctrlDTO) {
|
|
|
|
+ String taskId = ctrlDTO.getTaskId();
|
|
|
|
+ // 计算每一个线程需要布控的线索数量
|
|
|
|
+ List<Map<String, String>> acconutList = ctrlDTO.getAcconutList();
|
|
|
|
+ int accountsPerThread = acconutList.size() / threadNum;
|
|
|
|
+ // 创建线程池
|
|
|
|
+ ExecutorService executor = Executors.newFixedThreadPool(threadNum);
|
|
|
|
+ // 创建任务集合
|
|
|
|
+// List<Future<List<Map<String, String>>>> futureList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < threadNum; i++) {
|
|
|
|
+ int startIndex = i * accountsPerThread;
|
|
|
|
+ int endIndex = (i == threadNum - 1) ? acconutList.size() : (i + 1) * accountsPerThread;
|
|
|
|
+ // 根据调用方提交的任务对应线索集合和每一个线程需处理线索集合中的起、止索引号创建对应的布控任务类
|
|
|
|
+ Callable<List<Map<String, String>>> task = new CtrlTask(taskId,i + 1, acconutList, startIndex, endIndex);
|
|
|
|
+ // 提交任务
|
|
|
|
+ executor.submit(task);
|
|
|
|
+// Future<List<Map<String, String>>> future = executor.submit(task);
|
|
|
|
+// futureList.add(future);
|
|
|
|
+ }
|
|
|
|
+ executor.shutdown();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 调用烽火【统一布控】接口,下发布控任务
|
|
* 调用烽火【统一布控】接口,下发布控任务
|
|
- * @param businessDTO
|
|
|
|
|
|
+ * @param submitDTO
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AjaxResult ctrl(BusinessDTO businessDTO){
|
|
|
|
- String taskId = businessDTO.getTaskId();
|
|
|
|
- String account = businessDTO.getAccount();
|
|
|
|
- String accountType = businessDTO.getAccountType();
|
|
|
|
- String clueIdSrc = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
|
|
- try{
|
|
|
|
- // 1.调用布控接口,下发布控任务
|
|
|
|
- JSONObject resJSONObj = doCtrl(httpClient, businessDTO);
|
|
|
|
- String statusCode = resJSONObj.getString("statuscode");
|
|
|
|
- String message = resJSONObj.getString("message");
|
|
|
|
- if (Constants.CTRL_PROCESS_SUCESS.equals(statusCode)) {
|
|
|
|
- // 2.布控请求处理成功(不代表实际布控成功,需查询线索布控状态信息)
|
|
|
|
- String clueId = resJSONObj.getString("clue_id");
|
|
|
|
- log.info("【布控请求处理成功】 clueId:{}", clueId);
|
|
|
|
- // 3.查询线索实际布控状态
|
|
|
|
- log.info("【查询线索布控状态】 clueId:{}", clueId);
|
|
|
|
- String status = queryCtrlStatus(httpClient, businessDTO);
|
|
|
|
- if(Constants.CTRL_SUCCESS.equals(status)){
|
|
|
|
- log.info("【线索布控状态: 成功】 clueId:{}", clueId);
|
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
- resultMap.put("clueId", clueId);
|
|
|
|
- return AjaxResult.success(resultMap);
|
|
|
|
- }else if(Constants.CTRL_TODO.equals(status)){
|
|
|
|
- log.info("【线索布控状态: 待布控】 clueId:{}", clueId);
|
|
|
|
- return AjaxResult.success(Constants.CTRL_TODO_MSG);
|
|
|
|
- }else {
|
|
|
|
- log.info("【线索布控状态: 失败】 clueId: {}, 响应码:{}", clueId, status);
|
|
|
|
- return AjaxResult.error(Constants.CTRL_FAIL_MSG);
|
|
|
|
- }
|
|
|
|
- } else if (Constants.CTRL_EXIST.equals(statusCode)){
|
|
|
|
- log.error("【线索已经在控,无需再次发起布控】 clueId:{}", clueIdSrc);
|
|
|
|
- return AjaxResult.success(message);
|
|
|
|
- } else {
|
|
|
|
- // 如果布控请求处理失败,则直接返回异常信息,无需查询线索布控状态
|
|
|
|
- log.error("【线索布控请求处理失败】 clueId:{}, 响应码:{}, 异常信息:{}", clueIdSrc, statusCode, message);
|
|
|
|
- return AjaxResult.error(message);
|
|
|
|
|
|
+ public AjaxResult submitCtrl(SubmitDTO submitDTO){
|
|
|
|
+ String taskId = submitDTO.getTaskId();
|
|
|
|
+ String account = submitDTO.getAccount();
|
|
|
|
+ String accountType = submitDTO.getAccountType();
|
|
|
|
+ String clueIdOrigin = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
|
|
+ // 1.调用布控接口,下发布控任务
|
|
|
|
+ JSONObject resJSONObj = doSubmitCtrl(httpClient, submitDTO);
|
|
|
|
+ String statusCode = resJSONObj.getString("statuscode");
|
|
|
|
+ String message = resJSONObj.getString("message");
|
|
|
|
+ if (Constants.CTRL_PROCESS_SUCESS.equals(statusCode)) {
|
|
|
|
+ // 2.布控请求处理成功(不代表实际布控成功,需查询线索布控状态信息)
|
|
|
|
+ String clueId = resJSONObj.getString("clue_id");
|
|
|
|
+ log.info("【布控请求处理成功】 clueId:{}", clueId);
|
|
|
|
+ // 3.查询线索实际布控状态
|
|
|
|
+ log.info("【查询线索布控状态】 clueId:{}", clueId);
|
|
|
|
+ String status = queryCtrlStatus(httpClient, submitDTO);
|
|
|
|
+ if(Constants.CTRL_SUCCESS.equals(status)){
|
|
|
|
+ log.info("【线索布控状态: 成功】 clueId:{}", clueId);
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ resultMap.put("clueId", clueId);
|
|
|
|
+ // 4.保存布控任务信息到业务库(烽火统一布控接口目前只支持单次调用) --- todo
|
|
|
|
+
|
|
|
|
+ return AjaxResult.success(resultMap); // code:200
|
|
|
|
+ }else if(Constants.CTRL_TODO.equals(status)){
|
|
|
|
+ log.info("【线索布控状态: 待布控】 clueId:{}", clueId);
|
|
|
|
+ return AjaxResult.warn(Constants.CTRL_TODO_MSG); // code:601
|
|
|
|
+ }else {
|
|
|
|
+ log.info("【线索布控状态: 失败】 clueId: {}, 响应码:{}", clueId, status);
|
|
|
|
+ return AjaxResult.error(Constants.CTRL_FAIL_MSG); // code:500
|
|
}
|
|
}
|
|
- } catch (Exception e){
|
|
|
|
- log.error("【下发布控任务发生异常】 异常信息:", e);
|
|
|
|
|
|
+ } else if (Constants.CTRL_EXIST.equals(statusCode)){
|
|
|
|
+ log.error("【线索已经在控,无需再次发起布控】 clueId:{}", clueIdOrigin);
|
|
|
|
+ return AjaxResult.success(message);
|
|
|
|
+ } else {
|
|
|
|
+ // 如果布控请求处理失败,则直接返回异常信息,无需查询线索布控状态
|
|
|
|
+ log.error("【线索布控请求处理失败】 clueId:{}, 响应码:{}, 异常信息:{}", clueIdOrigin, statusCode, message);
|
|
|
|
+ return AjaxResult.error(message);
|
|
}
|
|
}
|
|
- return AjaxResult.error(Constants.SERVER_ERROR_MSG);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 调用烽火【统一布控】接口,下发停控任务
|
|
* 调用烽火【统一布控】接口,下发停控任务
|
|
- * @param businessDTO
|
|
|
|
|
|
+ * @param submitDTO
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AjaxResult stopCtrl(BusinessDTO businessDTO){
|
|
|
|
- String taskId = businessDTO.getTaskId();
|
|
|
|
- String account = businessDTO.getAccount();
|
|
|
|
- String accountType = businessDTO.getAccountType();
|
|
|
|
- String clueIdSrc = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
|
|
- try{
|
|
|
|
- // 调用停控接口
|
|
|
|
- JSONObject responseJSONObj = doStopCtrl(httpClient, businessDTO);
|
|
|
|
- String statusCode = responseJSONObj.getString("statuscode");
|
|
|
|
- String message = responseJSONObj.getString("message");
|
|
|
|
- if (Constants.CTRL_PROCESS_SUCESS.equals(statusCode)) {
|
|
|
|
- String clueId = responseJSONObj.getString("clue_id");
|
|
|
|
- log.info("【线索停控请求处理成功】 clueId:{}", clueId);
|
|
|
|
- log.info("【查询线索停控状态】 clueId:{}", clueId);
|
|
|
|
- String status = queryCtrlStatus(httpClient, businessDTO);
|
|
|
|
- if(Constants.STOP_CTRL_SUCCESS.equals(status)){
|
|
|
|
- log.info("【线索停控状态: 成功】 clueId:{}", clueId);
|
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
- resultMap.put("clueId", clueId);
|
|
|
|
- return AjaxResult.success(resultMap);
|
|
|
|
- }else if(Constants.STOP_CTRL_TODO.equals(status)){
|
|
|
|
- log.info("【线索停控状态: 待停控】 clueId: {}", clueId);
|
|
|
|
- return AjaxResult.success(Constants.STOP_CTRL_TODO_MSG);
|
|
|
|
- }else {
|
|
|
|
- log.info("【线索停控: 失败】 clueId: {}, 响应码:{}", clueId, status);
|
|
|
|
- return AjaxResult.error(Constants.STOP_CTRL_FAIL_MSG);
|
|
|
|
- }
|
|
|
|
- } else if (Constants.STOP_CTRL_EXIST.equals(statusCode)){
|
|
|
|
- log.error("【线索已经停控,无需再次发起停控】 clueId:{}", clueIdSrc);
|
|
|
|
- return AjaxResult.success(message);
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- // 如果停控请求处理失败,则直接返回异常信息,无需查询线索停控状态
|
|
|
|
- log.error("【线索停控请求处理失败】 clueId:{}, 响应码:{}, 异常信息:{}", clueIdSrc, statusCode, message);
|
|
|
|
- return AjaxResult.error(message);
|
|
|
|
|
|
+ public AjaxResult stopCtrl(SubmitDTO submitDTO){
|
|
|
|
+ String taskId = submitDTO.getTaskId();
|
|
|
|
+ String account = submitDTO.getAccount();
|
|
|
|
+ String accountType = submitDTO.getAccountType();
|
|
|
|
+ String clueIdOrigin = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
|
|
+ // 调用停控接口
|
|
|
|
+ JSONObject responseJSONObj = doStopCtrl(httpClient, submitDTO);
|
|
|
|
+ String statusCode = responseJSONObj.getString("statuscode");
|
|
|
|
+ String message = responseJSONObj.getString("message");
|
|
|
|
+ if (Constants.CTRL_PROCESS_SUCESS.equals(statusCode)) {
|
|
|
|
+ String clueId = responseJSONObj.getString("clue_id");
|
|
|
|
+ log.info("【线索停控请求处理成功】 clueId:{}", clueId);
|
|
|
|
+ log.info("【查询线索停控状态】 clueId:{}", clueId);
|
|
|
|
+ String status = queryCtrlStatus(httpClient, submitDTO);
|
|
|
|
+ if(Constants.STOP_CTRL_SUCCESS.equals(status)){
|
|
|
|
+ log.info("【线索停控状态: 成功】 clueId:{}", clueId);
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ resultMap.put("clueId", clueId);
|
|
|
|
+ return AjaxResult.success(resultMap);
|
|
|
|
+ }else if(Constants.STOP_CTRL_TODO.equals(status)){
|
|
|
|
+ log.info("【线索停控状态: 待停控】 clueId: {}", clueId);
|
|
|
|
+ return AjaxResult.warn(Constants.STOP_CTRL_TODO_MSG);
|
|
|
|
+ }else {
|
|
|
|
+ log.info("【线索停控: 失败】 clueId: {}, 响应码:{}", clueId, status);
|
|
|
|
+ return AjaxResult.error(Constants.STOP_CTRL_FAIL_MSG);
|
|
}
|
|
}
|
|
- } catch (Exception e){
|
|
|
|
- log.error("【下发停控任务发生异常】 异常信息:", e);
|
|
|
|
|
|
+ } else if (Constants.STOP_CTRL_EXIST.equals(statusCode)){
|
|
|
|
+ log.error("【线索已经停控,无需再次发起停控】 clueId:{}", clueIdOrigin);
|
|
|
|
+ return AjaxResult.success(message);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ // 如果停控请求处理失败,则直接返回异常信息,无需查询线索停控状态
|
|
|
|
+ log.error("【线索停控请求处理失败】 clueId:{}, 响应码:{}, 异常信息:{}", clueIdOrigin, statusCode, message);
|
|
|
|
+ return AjaxResult.error(message);
|
|
}
|
|
}
|
|
- return AjaxResult.error(Constants.SERVER_ERROR_MSG);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 调用烽火【统一布控】接口, 下发布控请求 - 布控失败时,重试3次
|
|
* 调用烽火【统一布控】接口, 下发布控请求 - 布控失败时,重试3次
|
|
* @param httpClient
|
|
* @param httpClient
|
|
- * @param businessDTO
|
|
|
|
|
|
+ * @param submitDTO
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public JSONObject doCtrl(HttpClient httpClient, BusinessDTO businessDTO) {
|
|
|
|
|
|
+ public JSONObject doSubmitCtrl(HttpClient httpClient, SubmitDTO submitDTO) {
|
|
// 构建请求参数
|
|
// 构建请求参数
|
|
- String resourceIdList = businessDTO.getResourceIdList();
|
|
|
|
|
|
+ String resourceIdList = submitDTO.getResourceIdList();
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
// 将配置文件中的数据资源业务ID转换为烽火盘古平台数据资源编码
|
|
// 将配置文件中的数据资源业务ID转换为烽火盘古平台数据资源编码
|
|
if(StringUtils.isNotBlank(resourceIdList) && resourceIdList.split(",").length > 0){
|
|
if(StringUtils.isNotBlank(resourceIdList) && resourceIdList.split(",").length > 0){
|
|
@@ -162,12 +185,11 @@ public class CtrlService {
|
|
} else {
|
|
} else {
|
|
throw new RuntimeException("待布控数据资源列表为空,布控任务下发失败");
|
|
throw new RuntimeException("待布控数据资源列表为空,布控任务下发失败");
|
|
}
|
|
}
|
|
- String taskId = businessDTO.getTaskId();
|
|
|
|
- String account = businessDTO.getAccount();
|
|
|
|
- String accountType = businessDTO.getAccountType();
|
|
|
|
|
|
+ String taskId = submitDTO.getTaskId();
|
|
|
|
+ String account = submitDTO.getAccount();
|
|
|
|
+ String accountType = submitDTO.getAccountType();
|
|
String clueId = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
String clueId = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
- String sysId = businessDTO.getSysId();
|
|
|
|
- String endCtrlTime = businessDTO.getEndCtrlTime();
|
|
|
|
|
|
+ String endCtrlTime = submitDTO.getEndCtrlTime();
|
|
|
|
|
|
params.put("clue_id", clueId);
|
|
params.put("clue_id", clueId);
|
|
params.put("from_areacode", fromAreaCode);
|
|
params.put("from_areacode", fromAreaCode);
|
|
@@ -204,15 +226,14 @@ public class CtrlService {
|
|
/**
|
|
/**
|
|
* 调用烽火【统一布控】接口, 下发停控请求 - 布控失败时,重试3次
|
|
* 调用烽火【统一布控】接口, 下发停控请求 - 布控失败时,重试3次
|
|
* @param httpClient
|
|
* @param httpClient
|
|
- * @param businessDTO
|
|
|
|
|
|
+ * @param submitDTO
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public JSONObject doStopCtrl(HttpClient httpClient, BusinessDTO businessDTO) {
|
|
|
|
|
|
+ public JSONObject doStopCtrl(HttpClient httpClient, SubmitDTO submitDTO) {
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
- String taskId = businessDTO.getTaskId();
|
|
|
|
- String account = businessDTO.getAccount();
|
|
|
|
- String accountType = businessDTO.getAccountType();
|
|
|
|
- String sysId = businessDTO.getSysId();
|
|
|
|
|
|
+ String taskId = submitDTO.getTaskId();
|
|
|
|
+ String account = submitDTO.getAccount();
|
|
|
|
+ String accountType = submitDTO.getAccountType();
|
|
String clueId = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
String clueId = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
params.put("clue_id", clueId);
|
|
params.put("clue_id", clueId);
|
|
params.put("from_areacode", fromAreaCode);
|
|
params.put("from_areacode", fromAreaCode);
|
|
@@ -239,15 +260,14 @@ public class CtrlService {
|
|
/**
|
|
/**
|
|
* 调用烽火【统一布控】接口, 查询线索布/停控状态 - 查询失败时,重试3次
|
|
* 调用烽火【统一布控】接口, 查询线索布/停控状态 - 查询失败时,重试3次
|
|
* @param httpClient
|
|
* @param httpClient
|
|
- * @param businessDTO 需要查询状态的布控内容
|
|
|
|
|
|
+ * @param submitDTO 需要查询状态的布控内容
|
|
* @return String 布/停控状态
|
|
* @return String 布/停控状态
|
|
*/
|
|
*/
|
|
- public String queryCtrlStatus(HttpClient httpClient, BusinessDTO businessDTO) {
|
|
|
|
|
|
+ public String queryCtrlStatus(HttpClient httpClient, SubmitDTO submitDTO) {
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
- String taskId = businessDTO.getTaskId();
|
|
|
|
- String account = businessDTO.getAccount();
|
|
|
|
- String accountType = businessDTO.getAccountType();
|
|
|
|
- String sysId = businessDTO.getSysId();
|
|
|
|
|
|
+ String taskId = submitDTO.getTaskId();
|
|
|
|
+ String account = submitDTO.getAccount();
|
|
|
|
+ String accountType = submitDTO.getAccountType();
|
|
String clueId = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
String clueId = fromAreaCode.concat(taskId).concat("_").concat(accountType).concat(account);
|
|
params.put("clue_id", clueId);
|
|
params.put("clue_id", clueId);
|
|
params.put("from_areacode", fromAreaCode);
|
|
params.put("from_areacode", fromAreaCode);
|