Browse Source

提交自动生成报告

tags/V1.3.3^2
wanjing 11 months ago
parent
commit
8bdd3cb0c7
7 changed files with 285 additions and 119 deletions
  1. +7
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/UpdateFlyerService.java
  2. +9
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateInspectionStatusService.java
  3. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/IReportServiceImpl.java
  4. +98
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportByAutoService.java
  5. +129
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportByManualService.java
  6. +6
    -115
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportService.java
  7. +34
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportServiceImpl.java

+ 7
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/flyer/UpdateFlyerService.java View File

@@ -9,6 +9,7 @@ import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.mapper.ReportMapper;
import com.tuoheng.admin.request.inspection.UpdateTaskByCodeRequest;
import com.tuoheng.admin.service.report.generate.GenerateReportService;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.JacksonUtil;
import com.tuoheng.common.core.utils.JsonResult;
@@ -44,6 +45,9 @@ public class UpdateFlyerService {
@Autowired
private OffLineCompleteService offLineCompleteService;

@Autowired
private GenerateReportService generateReportService;

/**
* 修改任务(修改任务状态和飞手信息)
*
@@ -71,6 +75,9 @@ public class UpdateFlyerService {
// 飞行完成
log.info("修改任务状态和飞手信息业务接口:飞行完成");
this.updateComplete(request, inspection);

// 任务完成后自动生成报告
generateReportService.generateByAuto(inspection.getId());
}

// 直播

+ 9
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateInspectionStatusService.java View File

@@ -9,6 +9,7 @@ import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.request.inspection.MissionStatusRequest;
import com.tuoheng.admin.service.report.generate.GenerateReportService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +35,9 @@ public class UpdateInspectionStatusService {
@Autowired
private UpdateWaittStatusService updateWaittStatusService;

@Autowired
private GenerateReportService generateReportService;

/**
* 添加任务
*
@@ -55,13 +59,16 @@ public class UpdateInspectionStatusService {
}

if (AirPortTaskStatusEnum.FLIGHT.getCode() == missionStatusRequest.getStatus()) {
log.info("修改任务状态业务接口:修改执行中状态");
log.info("修改任务状态业务接口:执行中,inspectionId={}", inspection.getId());
status = InspectionStatusEnum.IN_FLIGHT.getCode();
updateFlightStatusService.updateFlightStatus(inspection, missionStatusRequest);
} else if (AirPortTaskStatusEnum.WAIT.getCode() == missionStatusRequest.getStatus()) {
log.info("修改任务状态业务接口:修改待执行状态");
log.info("修改任务状态业务接口:飞行结束");
status = InspectionStatusEnum.FLIGHT_COMPLETED.getCode();
updateWaittStatusService.updateWaittStatus(inspection);

// 任务完成后自动生成报告
generateReportService.generateByAuto(inspection.getId());
}

this.updateEmergencyStatus(inspection, status);

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/IReportServiceImpl.java View File

@@ -3,7 +3,7 @@ package com.tuoheng.admin.service.report;
import com.tuoheng.admin.request.report.QueryReportPageListRequest;
import com.tuoheng.admin.service.report.export.ExportInspectionHandleReportService;
import com.tuoheng.admin.service.report.export.ExportInspectionReportService;
import com.tuoheng.admin.service.report.generate.GenerateReportService;
import com.tuoheng.admin.service.report.generate.GenerateReportByManualService;
import com.tuoheng.admin.service.report.query.QueryInspectionHandleReportService;
import com.tuoheng.admin.service.report.query.QueryInspectionReportService;
import com.tuoheng.admin.service.report.query.QueryReportPageListService;
@@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletResponse;
public class IReportServiceImpl implements IReportService{

@Autowired
private GenerateReportService generateReportService;
private GenerateReportByManualService generateReportService;

@Autowired
private QueryReportPageListService queryReportPageListService;

+ 98
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportByAutoService.java View File

@@ -0,0 +1,98 @@
package com.tuoheng.admin.service.report.generate;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.conver.ReportConverMapper;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.entity.Report;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.code.report.GenerateReportCodeEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.mapper.ReportMapper;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* 任务完成自动生成报告业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2023-11-30
*/
@Slf4j
@Service
public class GenerateReportByAutoService {

@Autowired
private ReportMapper reportMapper;

@Autowired
private InspectionMapper inspectionMapper;

/**
* 生成报告
*
* @return
*/
public JsonResult generate(String inspectionId) {
log.info("进入任务完成自动生成报告, inspectionId={}", inspectionId);
Report report = this.buildReport(inspectionId);

JsonResult result = this.addReport(report);
if (0 != result.getCode()) {
log.info("自动生成报告业务:添加报告记录失败:{}", result.getMsg());
throw new ServiceException("自动生成报告业务:添加报告记录失败");
}
return JsonResult.success();
}

/**
*
* 生成报告实体
*
* @param inspectionId
*/
private Report buildReport(String inspectionId) {
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>()
.eq(Inspection::getId, inspectionId)
.eq(Inspection::getMark, MarkEnum.VALID.getCode()));
Report report = ReportConverMapper.INSTANCE.fromInspectionToReport(inspection);
// 任务编号:XJBG+日期+3位排序数字
String code = DateUtils.generateCode("XJBG");
report.setId("");
report.setReportCode(code);
report.setTenantId(inspection.getTenantId());
report.setInspectionId(inspection.getId());
report.setInspectionCode(inspection.getCode());
report.setInspectionName(inspection.getName());
report.setCreateUser("");
report.setCreateTime(DateUtils.now());
return report;
}

/**
*
* 添加报告
* 每次生成报告,将上一次生成的报告给覆盖,因此直接将上次的删除,重新添加一条
*
* @param report
*/
private JsonResult addReport(Report report) {
Report reportTmp = reportMapper.selectOne(Wrappers.<Report>lambdaQuery()
.eq(Report::getInspectionId, report.getInspectionId())
.eq(Report::getMark, MarkEnum.VALID.getCode()));
if (null != reportTmp) {
reportMapper.deleteById(reportTmp.getId());
}
Integer rowCount = reportMapper.insert(report);
if (rowCount <= 0) {
log.info("自动生成报告业务:添加报告记录失败");
return JsonResult.error(GenerateReportCodeEnum.GENERATE_IS_FAILED.getCode(), GenerateReportCodeEnum.GENERATE_IS_FAILED.getMsg());
}
return JsonResult.success();
}
}

+ 129
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportByManualService.java View File

@@ -0,0 +1,129 @@
package com.tuoheng.admin.service.report.generate;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.conver.ReportConverMapper;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.code.report.GenerateReportCodeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.utils.DateUtils;
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.Service;

/**
* 生成报告业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2023-11-30
*/
@Slf4j
@Service
public class GenerateReportByManualService {

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private InspectionFileMapper inspectionFileMapper;

@Autowired
private InspectionFileHandleMapper inspectionFileHandleMapper;

@Autowired
private ReportMapper reportMapper;

/**
* 生成报告
*
* @return
*/
public JsonResult generate(String id) {
log.info("进入生成报告业务");
String userId = CurrentUserUtil.getUserId();
String tenantId = CurrentUserUtil.getTenantId();

JsonResult result = this.check(id);
if (0 != result.getCode()) {
log.info("生成报告业务:校验参数失败:{}", result.getMsg());
return result;
}
Inspection inspection = (Inspection) result.getData();

Report report = this.buildReport(userId, tenantId, inspection);

result = this.addReport(report);
if (0 != result.getCode()) {
log.info("生成报告业务:添加报告记录失败:{}", result.getMsg());
return result;
}

return JsonResult.success(report);
}

/**
* 检查
*
* @param id
* @return
*/
private JsonResult check(String id) {
if (StringUtils.isEmpty(id)) {
return JsonResult.error(GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getCode(), GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getMsg());
}
Inspection inspection = inspectionMapper.selectOne(Wrappers.<Inspection>lambdaQuery()
.eq(Inspection::getId, id)
.eq(Inspection::getMark, 1));
if (null == inspection) {
return JsonResult.error(GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg());
}
return JsonResult.success(inspection);
}

/**
*
* 生成报告实体
*
* @param inspection
*/
private Report buildReport(String userId, String tenantId, Inspection inspection) {
Report report = ReportConverMapper.INSTANCE.fromInspectionToReport(inspection);
// 任务编号:XJBG+日期+3位排序数字
String code = DateUtils.generateCode("XJBG");
report.setId("");
report.setReportCode(code);
report.setTenantId(tenantId);
report.setInspectionId(inspection.getId());
report.setInspectionCode(inspection.getCode());
report.setInspectionName(inspection.getName());
report.setCreateUser(userId);
report.setCreateTime(DateUtils.now());
return report;
}

/**
*
* 添加报告
* 每次生成报告,将上一次生成的报告给覆盖,因此直接将上次的删除,重新添加一条
*
* @param report
*/
private JsonResult addReport(Report report) {
Report reportTmp = reportMapper.selectOne(Wrappers.<Report>lambdaQuery()
.eq(Report::getInspectionId, report.getInspectionId())
.eq(Report::getMark, 1));
if (null != reportTmp) {
reportMapper.deleteById(reportTmp.getId());

}
Integer rowCount = reportMapper.insert(report);
if (rowCount <= 0) {
log.info("生成报告业务:添加报告记录失败");
return JsonResult.error(GenerateReportCodeEnum.GENERATE_IS_FAILED.getCode(), GenerateReportCodeEnum.GENERATE_IS_FAILED.getMsg());
}
return JsonResult.success();
}
}

+ 6
- 115
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportService.java View File

@@ -1,136 +1,27 @@
package com.tuoheng.admin.service.report.generate;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.conver.ReportConverMapper;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.InspectionFileStatusEnum;
import com.tuoheng.admin.enums.code.report.GenerateReportCodeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.service.report.query.GetInspectionFileStatusList;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.utils.DateUtils;
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.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* 生成报告业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2022-12-09
* @date 2023-11-30
*/
@Slf4j
@Service
public class GenerateReportService {

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private InspectionFileMapper inspectionFileMapper;

@Autowired
private InspectionFileHandleMapper inspectionFileHandleMapper;

@Autowired
private ReportMapper reportMapper;

/**
* 生成报告
*
* @return
*/
public JsonResult generate(String id) {
log.info("进入生成报告业务");
String userId = CurrentUserUtil.getUserId();
String tenantId = CurrentUserUtil.getTenantId();

JsonResult result = this.check(id);
if (0 != result.getCode()) {
log.info("生成报告业务:校验参数失败:{}", result.getMsg());
return result;
}
Inspection inspection = (Inspection) result.getData();

Report report = this.buildReport(userId, tenantId, inspection);

result = this.addReport(report);
if (0 != result.getCode()) {
log.info("生成报告业务:添加报告记录失败:{}", result.getMsg());
return result;
}

return JsonResult.success(report);
}
public interface GenerateReportService {

/**
* 检查
* 手动生成报告
*
* @param id
* @return
*/
private JsonResult check(String id) {
if (StringUtils.isEmpty(id)) {
return JsonResult.error(GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getCode(), GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getMsg());
}
Inspection inspection = inspectionMapper.selectOne(Wrappers.<Inspection>lambdaQuery()
.eq(Inspection::getId, id)
.eq(Inspection::getMark, 1));
if (null == inspection) {
return JsonResult.error(GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg());
}
return JsonResult.success(inspection);
}
JsonResult generateByManual(String id);

/**
*
* 生成报告实体
*
* @param inspection
*/
private Report buildReport(String userId, String tenantId, Inspection inspection) {
Report report = ReportConverMapper.INSTANCE.fromInspectionToReport(inspection);
// 任务编号:XJBG+日期+3位排序数字
String code = DateUtils.generateCode("XJBG");
report.setId("");
report.setReportCode(code);
report.setTenantId(tenantId);
report.setInspectionId(inspection.getId());
report.setInspectionCode(inspection.getCode());
report.setInspectionName(inspection.getName());
report.setCreateUser(userId);
report.setCreateTime(DateUtils.now());
return report;
}

/**
*
* 添加报告
* 每次生成报告,将上一次生成的报告给覆盖,因此直接将上次的删除,重新添加一条
*
* @param report
* 自动生成工单
*/
private JsonResult addReport(Report report) {
Report reportTmp = reportMapper.selectOne(Wrappers.<Report>lambdaQuery()
.eq(Report::getInspectionId, report.getInspectionId())
.eq(Report::getMark, 1));
if (null != reportTmp) {
reportMapper.deleteById(reportTmp.getId());
JsonResult generateByAuto(String id);

}
Integer rowCount = reportMapper.insert(report);
if (rowCount <= 0) {
log.info("生成报告业务:添加报告记录失败");
return JsonResult.error(GenerateReportCodeEnum.GENERATE_IS_FAILED.getCode(), GenerateReportCodeEnum.GENERATE_IS_FAILED.getMsg());
}
return JsonResult.success();
}
}

+ 34
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/generate/GenerateReportServiceImpl.java View File

@@ -0,0 +1,34 @@
package com.tuoheng.admin.service.report.generate;

import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* 生成报告业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2023-11-30
*/
@Slf4j
@Service
public class GenerateReportServiceImpl implements GenerateReportService {

@Autowired
private GenerateReportByManualService generateReportByManualService;

@Autowired
private GenerateReportByAutoService generateReportByAutoService;

@Override
public JsonResult generateByManual(String id) {
return generateReportByManualService.generate(id);
}

@Override
public JsonResult generateByAuto(String id) {
return generateReportByAutoService.generate(id);
}
}

Loading…
Cancel
Save