package cn.gistack.sm.patrol.feign;
|
|
import cn.gistack.sm.intelligentCall.constant.ZtConstant;
|
import cn.gistack.sm.intelligentCall.service.CallService;
|
import cn.gistack.sm.patrol.entity.PatrolTask;
|
import cn.gistack.sm.patrol.service.IPatrolTaskService;
|
import cn.gistack.sm.sjztmd.entity.PatrolResponsiblePerson;
|
import cn.gistack.sm.sjztmd.service.IAttResManagePersonService;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import lombok.AllArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springblade.core.tenant.annotation.NonDS;
|
import org.springblade.core.tool.utils.DateUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpMethod;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.util.MultiValueMap;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.client.RestTemplate;
|
import springfox.documentation.annotations.ApiIgnore;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
/**
|
* @ClassName SM服务Feign实现类
|
* @Description TODO
|
* @Author zhongrj
|
* @Date 2023-06-03
|
*/
|
@NonDS
|
@ApiIgnore
|
@RestController
|
@AllArgsConstructor
|
@Slf4j
|
public class PatrolTaskImplClient implements PatrolTaskClient {
|
|
//本地测试
|
private static final String LOCAL = "https://sk.hubeishuiyi.cn";
|
//线上
|
private static final String ONLINE = "http://10.42.6.192";
|
private final IPatrolTaskService patrolTaskService;
|
private final IAttResManagePersonService attResManagePersonService;
|
|
@Autowired
|
private RestTemplate restTemplate;
|
|
/**
|
* 超汛限(包含汛限值0)
|
*/
|
private static final String GET_OVER_RZ =ONLINE + "/services/1234567890ABCDEFGHIJKLMN/over_z_last/patr_person/api?start_over=0&pageNo=1&pageSize=2000";
|
/**
|
* 病险水库
|
*/
|
private static final String GET_ILL_RESERVOIR =ONLINE + "/services/1234567890ABCDEFGHIJKLMN/res/main_st/rsvr?eng_scal=&res_nm=&is_danger=true&res_cds=&is_video=&flag=&data_sta=&gate=&is_order=1&label=&bas_nm=&pageNo=1&pageSize=10000";
|
|
|
/**
|
* 给巡查责任人定时创建任务执行器
|
* @param processDefinitionId
|
* @param taskType
|
* @param title
|
* @param content
|
* @return
|
*/
|
@Override
|
@GetMapping(CREATE_TASK_JOB_HANDLER)
|
public List<Integer> createTaskJobHandler(String processDefinitionId,
|
String taskType,
|
String title,
|
String content) {
|
List<PatrolResponsiblePerson> patrolResponsiblePersonList = attResManagePersonService.getPatrolResponsiblePersonAll();
|
List<Integer> taskJob = createTaskJob(processDefinitionId, taskType, title, content, patrolResponsiblePersonList);
|
return taskJob;
|
}
|
|
@Override
|
@GetMapping(CREATE_TASK_JOB_BY_CONDITION_HANDLER)
|
public List<Integer> createTaskJobByConditionHandler(String processDefinitionId, String taskType, String title, String content) {
|
|
List<String> reservoirList = new ArrayList<>();
|
|
//获取病险水库数据
|
JSONArray overList = apiRequestResult(null, GET_OVER_RZ);
|
for (int i = 0; i < overList.size(); i++) {
|
JSONObject reservoir = overList.getJSONObject(i);
|
reservoirList.add(reservoir.getString("res_cd"));
|
}
|
|
JSONArray illList = apiRequestData(null, GET_ILL_RESERVOIR);
|
for (int i = 0; i < illList.size(); i++) {
|
JSONObject reservoir = illList.getJSONObject(i);
|
reservoirList.add(reservoir.getString("res_cd"));
|
}
|
|
List<PatrolResponsiblePerson> patrolResponsiblePersonList = attResManagePersonService.getPatrolResponsiblePersonByResCdList(reservoirList);
|
|
List<Integer> taskJob = createTaskJob(processDefinitionId, taskType, title, content, patrolResponsiblePersonList);
|
|
return taskJob;
|
}
|
|
|
/**
|
* 请求中台接口,返回resultList结果集
|
* @param params
|
* @return
|
*/
|
private JSONArray apiRequestResult(Map<String, Object> params,String url) {
|
//设置请求头
|
HttpHeaders headers = new HttpHeaders();
|
headers.add(ZtConstant.header_key, ZtConstant.header_value);
|
//封装请求头
|
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
|
try {
|
//有请求头,有参数请求
|
ResponseEntity<String> responseEntity =
|
restTemplate.exchange(url,
|
HttpMethod.GET,
|
formEntity,
|
String.class);
|
JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
|
JSONArray jsonArray = JSONArray.parseArray(jsonObject.get("resultList").toString());
|
// 返回
|
return jsonArray;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
/**
|
* 请求中台接口,返回data结果集
|
* @param params
|
* @return
|
*/
|
private JSONArray apiRequestData(Map<String, Object> params,String url) {
|
//设置请求头
|
HttpHeaders headers = new HttpHeaders();
|
headers.add(ZtConstant.header_key, ZtConstant.header_value);
|
//封装请求头
|
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
|
try {
|
//有请求头,有参数请求
|
ResponseEntity<String> responseEntity =
|
restTemplate.exchange(url,
|
HttpMethod.GET,
|
formEntity,
|
String.class);
|
JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
|
JSONObject data = JSON.parseObject(jsonObject.get("data").toString());
|
|
JSONArray dataList = data.getJSONArray("data");
|
|
// 返回
|
return dataList;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
|
|
/**
|
* 创建任务的方法
|
* @param processDefinitionId
|
* @param taskType
|
* @param title
|
* @param content
|
* @param patrolResponsiblePersonList
|
* @return
|
*/
|
public List<Integer> createTaskJob(String processDefinitionId,
|
String taskType,
|
String title,
|
String content,List<PatrolResponsiblePerson> patrolResponsiblePersonList){
|
AtomicInteger failureCount = new AtomicInteger();
|
patrolResponsiblePersonList.forEach(item -> {
|
log.info("当前创建任务对象:" + JSON.toJSONString(item));
|
try {
|
PatrolTask patrolTask = new PatrolTask();
|
patrolTask.setProcessDefinitionId(processDefinitionId);
|
patrolTask.setToUserId(item.getUserId());
|
patrolTask.setProjectId(item.getResGuid());
|
patrolTask.setReservoirName(item.getName());
|
// 开始时间-结束时间
|
patrolTask.setStartTime(DateUtil.format(new Date(),"yyyy-MM-dd 00:00:00"));
|
patrolTask.setEndTime(DateUtil.format(new Date(),"yyyy-MM-dd 23:59:59"));
|
// 标题格式 月-日 水库名称 每日巡检任务
|
patrolTask.setTitle(DateUtil.format(new Date(),"MM-dd") + item.getName() + "-" + title);
|
patrolTask.setContent(DateUtil.format(new Date(),"yyyyMMdd") +content);
|
patrolTask.setTaskType(taskType);
|
// 创建任务
|
patrolTaskService.startProcess(patrolTask);
|
} catch (Exception e) {
|
log.error("创建任务失败:" + e.getMessage());
|
log.error("创建任务失败对象:" + JSON.toJSONString(item));
|
failureCount.getAndIncrement();
|
}
|
|
});
|
List<Integer> list = new ArrayList<>();
|
list.add(patrolResponsiblePersonList.size());
|
list.add(failureCount.get());
|
// 返回
|
return list;
|
}
|
|
|
}
|