Переглянути джерело

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

tags/v1.0.0^2
chengwang 1 рік тому
джерело
коміт
a52fda1553
2 змінених файлів з 111 додано та 2 видалено
  1. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/section/SectionServiceImpl.java
  2. +109
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/task/AirportTask.java

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/section/SectionServiceImpl.java Переглянути файл

@@ -114,7 +114,7 @@ public class SectionServiceImpl extends BaseServiceImpl<SectionMapper, Section>
//获取当前部门及其子部门列表
String deptId = user.getDeptId();
if (StringUtils.isEmpty(deptId)) {
JsonResult.error(SectionEnum.DEPT_IS_NOT_EXIST.getCode(), SectionEnum.DEPT_IS_NOT_EXIST.getMsg());
return JsonResult.error(SectionEnum.DEPT_IS_NOT_EXIST.getCode(), SectionEnum.DEPT_IS_NOT_EXIST.getMsg());
}
List<String> deptList = deptMapper.selectAllChildListById(deptId);
//根据部门列表查对应的部门路段数据列表
@@ -135,7 +135,7 @@ public class SectionServiceImpl extends BaseServiceImpl<SectionMapper, Section>
.eq(Section::getTenantId, tenantId)
.in(Section::getId, sectionIdList));
if (StringUtils.isEmpty(sectionList)) {
JsonResult.error(SectionEnum.SECTION_LIST_IS_NULL.getCode(), SectionEnum.SECTION_LIST_IS_NULL.getMsg());
return JsonResult.error(SectionEnum.SECTION_LIST_IS_NULL.getCode(), SectionEnum.SECTION_LIST_IS_NULL.getMsg());
}
List<Section> list = new ArrayList<>();
for (Section section : sectionList) {

+ 109
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/task/AirportTask.java Переглянути файл

@@ -0,0 +1,109 @@
package com.tuoheng.admin.task;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.InspectionTypeEnum;
import com.tuoheng.admin.enums.MarkTypeEnum;
import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.service.inspection.IInspectionService;
import com.tuoheng.common.core.enums.ServiceExceptionEnum;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.HttpUtils;
import com.tuoheng.common.core.utils.JacksonUtil;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
* 定时扫描,然后飞行
*/
@Component
@Slf4j
public class AirportTask {

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private IInspectionService inspectionService;

@Autowired
private TenantMapper tenantMapper;

// @Scheduled(fixedRate = 60000)
// @XxlJob("airportTaskHandler")
public void airportTaskHandler() {
//查询当前时间正负1分钟的时间跨度,xxljob执行频率为1分钟1次
long start = new Date().getTime() - 1 * 60000L;
long end = new Date().getTime() + 1 * 60000L;
Date startTime = new Date(start);
Date endTime = new Date(end);

log.info("执行定时执行飞行任务:" + LocalDateTime.now());
List<Inspection> inspectionList = inspectionMapper.selectList(new LambdaQueryWrapper<Inspection>()
.eq(Inspection::getMark, MarkTypeEnum.VALID.getCode())
.between(Inspection::getInspectionTime, startTime, endTime)
//查询巡检方式为机场的任务
.eq(Inspection::getInspectionType, InspectionTypeEnum.AIRPORT.getCode())
//查询未执行任务
.eq(Inspection::getExecutionStatus, 1)
//任务待飞行
.eq(Inspection::getStatus, InspectionStatusEnum.WAIT_FLIGHT.getCode()));

if (StringUtils.isNotEmpty(inspectionList)) {
for (Inspection inspection : inspectionList) {
log.info("执行定时执行飞行任务开始:" + inspection.getId());

JsonResult jsonResult = this.executeTask(inspection);

Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspection.getId());
inspectionUpdate.setExecutionStatus(2);
if (jsonResult.getCode() != 0 && ObjectUtil.isEmpty(jsonResult.getData())) {
// 12任务飞行失败(机场)
inspectionUpdate.setStatus(TaskStatusEnum.FAIL.getCode());
}
inspectionMapper.updateById(inspectionUpdate);

log.info("执行定时执行飞行任务结束");
}
}
}

private JsonResult executeTask(Inspection inspection) {
//读取不同租户的机场平台url
Tenant tenant = tenantMapper.selectById(inspection.getTenantId());
if (ObjectUtil.isEmpty(tenant) && StringUtils.isEmpty(tenant.getAirportUrl())) {
throw new ServiceException(ServiceExceptionEnum.GET_NO_DATA);
}
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_EXECUTE_TASK;
JSONObject jsonObject = new JSONObject();
jsonObject.put("taskId", inspection.getInspectionLine());
jsonObject.put("requestId", String.valueOf(inspection.getId()));
jsonObject.put("code", "gs"); // 与机场平台约定好的
jsonObject.put("tenantName", tenant.getName());

String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST");
if (StringUtils.isEmpty(airPortStr)) {
return JsonResult.error("机场接口返回数据为空");
}
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class);
if (jsonResult.getCode() != 0) {
return JsonResult.error(jsonResult.getMsg());
}
return JsonResult.success();
}
}

Завантаження…
Відмінити
Зберегти