@@ -164,7 +164,7 @@ public class ThMission extends BaseEntity implements Serializable { | |||
private Double progressbar; | |||
/** | |||
* 执行状态,1:执行过,2:未执行 | |||
* 执行状态,1:未执行,2:已执行 | |||
*/ | |||
private Integer executionStatus; | |||
@@ -21,10 +21,7 @@ import com.tuoheng.admin.service.IThInspectionService; | |||
import com.tuoheng.common.common.BaseServiceImpl; | |||
import com.tuoheng.common.config.CommonConfig; | |||
import com.tuoheng.common.exception.ServiceException; | |||
import com.tuoheng.common.utils.HttpUtils; | |||
import com.tuoheng.common.utils.JacksonUtil; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.RedisUtils; | |||
import com.tuoheng.common.utils.*; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import groovy.util.logging.Slf4j; | |||
import org.apache.poi.ss.formula.functions.T; | |||
@@ -65,7 +62,7 @@ public class ThInspectionServiceImpl extends BaseServiceImpl<ThInspectionMapper, | |||
public List<InspectionVO> track(Integer id) { | |||
LambdaQueryWrapper<ThInspection> lambdaQueryWrapper=new LambdaQueryWrapper<>(); | |||
lambdaQueryWrapper.eq(ThInspection::getMissionId,id).orderByDesc(ThInspection::getCreateTime); | |||
lambdaQueryWrapper.eq(ThInspection::getMissionId,id).orderByAsc(ThInspection::getCreateTime); | |||
//lambdaQueryWrapper.eq(ThInspection::getTenantId, ShiroUtils.getTenantId()); | |||
List<InspectionVO> result=new ArrayList<>(); | |||
List<ThInspection> thInspections = inspectionMapper.selectList(lambdaQueryWrapper); | |||
@@ -132,44 +129,29 @@ public class ThInspectionServiceImpl extends BaseServiceImpl<ThInspectionMapper, | |||
Assert.notNull(thMission,"任务不能为空!"); | |||
taskId=thMission.getInspectionLine().toString(); | |||
int status = (Integer)redisUtils.get("status"); | |||
//1:开,2:关 | |||
if(status==1) { | |||
//这边需要配置到yml文件里面 | |||
String url = CommonConfig.airportUrl + "/api/airportInterface/executeTask"; | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("taskId", taskId); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
assert jsonResult != null; | |||
return JsonResult.error(JSONObject.parseArray(JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData())).get("data").toString(), AirExecuteTaskVO.class), "执行任务失败!"); | |||
} else if (ObjectUtil.isEmpty(jsonResult.getData()) && jsonResult.getCode() != 0) { | |||
return JsonResult.error(jsonResult.getMsg()); | |||
} else { | |||
ThMission thMissionUpdate=new ThMission(UpdateOrCreateEnum.UPDATE.getCode()); | |||
thMissionUpdate.setId(thMission.getId()); | |||
//修改执行时间为当前 | |||
thMissionUpdate.setExecutionStartTime(new Date()); | |||
missionMapper.updateById(thMissionUpdate); | |||
//返回执行结果 | |||
return JsonResult.success(jsonResult.getMsg()); | |||
} | |||
}else{ | |||
if(ObjectUtil.isEmpty(pushAndPull)){ | |||
//如果是空,好歹给个通道 | |||
pushAndPull.setPullUrl("rtmp://live.play.t-aaron.com/live/THSAq_hd"); | |||
pushAndPull.setPushUrl("rtmp://live.push.t-aaron.com/live/THSAq"); | |||
} | |||
MissionStatusRequest missionStatusRequest=new MissionStatusRequest(); | |||
missionStatusRequest.setId(thMission.getInspectionLine()); | |||
missionStatusRequest.setPushUrl(pushAndPull.getPushUrl()); | |||
missionStatusRequest.setPullUrl(pushAndPull.getPullUrl()); | |||
missionStatusRequest.setStatus(2); | |||
//修改任务状态,任务开始飞行 | |||
boolean b = missionService.updateStatus(missionStatusRequest); | |||
return JsonResult.success(thMission.getInspectionLine()); | |||
//这边需要配置到yml文件里面 | |||
String url = CommonConfig.airportUrl + "/api/airportInterface/executeTask"; | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("taskId", taskId); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
if(StringUtils.isEmpty(airPortStr)){ | |||
return JsonResult.error("机场接口返回数据为空"); | |||
} | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
assert jsonResult != null; | |||
return JsonResult.error(JSONObject.parseArray(JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData())).get("data").toString(), AirExecuteTaskVO.class), "执行任务失败!"); | |||
} else if (ObjectUtil.isEmpty(jsonResult.getData()) && jsonResult.getCode() != 0) { | |||
return JsonResult.error(jsonResult.getMsg()); | |||
} else { | |||
ThMission thMissionUpdate=new ThMission(UpdateOrCreateEnum.UPDATE.getCode()); | |||
thMissionUpdate.setId(thMission.getId()); | |||
//修改执行时间为当前 | |||
thMissionUpdate.setExecutionStartTime(new Date()); | |||
missionMapper.updateById(thMissionUpdate); | |||
//返回执行结果 | |||
return JsonResult.success(jsonResult.getMsg()); | |||
} | |||
} | |||
@@ -5,10 +5,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.domain.ThMission; | |||
import com.tuoheng.admin.enums.MarkTypeEnum; | |||
import com.tuoheng.admin.enums.TaskStatusEnum; | |||
import com.tuoheng.admin.enums.UpdateOrCreateEnum; | |||
import com.tuoheng.admin.mapper.ThMissionMapper; | |||
import com.tuoheng.admin.service.IMissionService; | |||
import com.tuoheng.admin.service.IThInspectionService; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.scheduling.annotation.Scheduled; | |||
@@ -33,28 +35,37 @@ public class ScheduledTask { | |||
private final static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
/* @Scheduled(fixedRate = 3000) | |||
@Scheduled(fixedRate = 1000) | |||
public void scheduledTask() { | |||
log.info("执行定时执行飞行任务:" + LocalDateTime.now()); | |||
List<ThMission> thMissions = missionMapper.selectList(new LambdaQueryWrapper<ThMission>() | |||
.eq(ThMission::getMark, MarkTypeEnum.VALID.getCode()) | |||
.ge(ThMission::getExecutionStartTime, dateformat.format(new Date())) | |||
.ge(ThMission::getExecutionStatus, 1) | |||
.eq(ThMission::getExecutionStartTime, dateformat.format(new Date())) | |||
//查询未执行任务 | |||
.eq(ThMission::getExecutionStatus, 1) | |||
.eq(ThMission::getStatus, TaskStatusEnum.WAIT.getCode())); | |||
log.info("一秒钟一次"); | |||
log.info("执行定时执行飞行任务,一秒钟一次"); | |||
if(StringUtils.isNotEmpty(thMissions)){ | |||
for (ThMission thMission : thMissions) { | |||
log.info("执行定时执行飞行任务:" + thMission.getId()); | |||
JsonResult jsonResult = inspectionService.executeTask(String.valueOf(thMission.getId()), null); | |||
log.info("执行定时执行飞行任务result:" + jsonResult); | |||
thMission.setExecutionStatus(2); | |||
for (ThMission thMission : thMissions) { | |||
JsonResult jsonResult = inspectionService.executeTask(String.valueOf(thMission.getId())); | |||
thMission.setExecutionStatus(2); | |||
if(jsonResult.getCode()!=0 && ObjectUtil.isEmpty(jsonResult.getData())){ | |||
thMission.setStatus(TaskStatusEnum.FAIL.getCode()); | |||
ThMission thMissionUpdate = new ThMission(UpdateOrCreateEnum.UPDATE.getCode()); | |||
thMissionUpdate.setId(thMission.getId()); | |||
thMissionUpdate.setExecutionStatus(2); | |||
if(jsonResult.getCode()!=0 && ObjectUtil.isEmpty(jsonResult.getData())){ | |||
thMission.setStatus(TaskStatusEnum.FAIL.getCode()); | |||
} | |||
missionMapper.updateById(thMissionUpdate); | |||
} | |||
missionMapper.updateById(thMission); | |||
} | |||
}*/ | |||
} | |||
} |
@@ -71,6 +71,7 @@ public class HttpUtils { | |||
* @return | |||
*/ | |||
public static String doSend(String urlStr, JSONObject data, Map<String, String> properties, String method){ | |||
StringBuilder result = new StringBuilder(); | |||
try { | |||
log.info("请求url={}", urlStr); | |||
log.info("请求体数据data={}", data.toJSONString()); | |||
@@ -82,7 +83,7 @@ public class HttpUtils { | |||
connection.setDoOutput(true); // 设置该连接是可以输出的 | |||
//设置连接超时时间和读取超时时间 | |||
connection.setConnectTimeout(15000); | |||
connection.setReadTimeout(60000); | |||
connection.setReadTimeout(60000 * 2); | |||
//设置请求方式 | |||
connection.setRequestMethod(method); | |||
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); | |||
@@ -99,17 +100,22 @@ public class HttpUtils { | |||
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); | |||
String line = null; | |||
StringBuilder result = new StringBuilder(); | |||
while ((line = br.readLine()) != null) { // 读取数据 | |||
result.append(line).append("\n"); | |||
} | |||
connection.disconnect(); | |||
log.info(result.toString()); | |||
return result.toString(); | |||
log.info("recv - {}", result); | |||
} catch (ConnectException e) { | |||
log.error("调用HttpUtils.sendGet ConnectException, url=" + urlStr + ",param=" + data, e); | |||
} catch (SocketTimeoutException e) { | |||
log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + urlStr + ",param=" + data, e); | |||
} catch (IOException e) { | |||
log.error("调用HttpUtils.sendGet IOException, url=" + urlStr + ",param=" + data, e); | |||
} catch (Exception e) { | |||
log.error("post请求失败,{}",e.getMessage()); | |||
return "post请求失败!"; | |||
log.error("调用HttpsUtil.sendGet Exception, url=" + urlStr + ",param=" + data, e); | |||
} | |||
return result.toString(); | |||
} | |||
public static String sendSSLPost(String url, String param) { |