航空处项目

作者: 弹钢琴的崽崽 | 来源:发表于2021-01-05 20:04 被阅读0次

    一. 数据库设计

    1. 飞行计划\实施情况信息表
    2. 飞行计划动态信息表
    3. 飞行动态明细表
    4. 航空处装备状态
    5. 直升机基本情况
    6. 技术通报落实实施情况
    7. 当日战直升机
    8. 技术通报落实情况
    9. 不完好直升机情况

    二. Rest API 契约开发平台的使用

    1. 分页查询列表接口参数

    1.1 基本信息

    请求方式:POST

    接口标识:数据类型:

    1.2 参数定义

    名称:searchable

    参数类型:formData

    数据类型:Searchable

    1.3 返回结果

    1.4 结果MOCK定义

    2. 新增|编辑接口

    2.1 基本信息

    请求方式:POST

    2.2 参数定义

    参数类型:body

    2.3 返回结果

    2.4 结果MOCK定义

    返回实体类id

    3. 详情和删除接口

    3.1 详情注意点:

    请求方式是GET请求;

    参数定义:

    返回结果是定义的实体类或VO类

    3.2 删除注意点:

    请求方式是DELETE请求

    参数为id,参数类型为query

    返回结果:id

    4. 代码生成打包

    引入依赖

    Controller层实现Api接口即可,dao和service层可根据平台工具生成

    三. 后端代码编写

    Rest AIP问题:

    使用Rest AIP契约平台的包由于实体类上没有加与数据库字段对应的一些相关JPA的注解@Column(name = "")所以需要自己也生成实体类并加上注解。

    这就会出现接口的返回类型与契约平台对应不上的问题需要做一个转换

    引入依赖

    <dependency>
        <groupId>com.github.dozermapper</groupId>
        <artifactId>dozer-core</artifactId>
        <version>6.2.0</version>
    </dependency>
    

    a. 写一个配置类

    @Component
    public class GeneralConvertor {
    
        //持有Dozer单例, 避免重复创建DozerMapper消耗资源.
        public static final Mapper mapper = DozerBeanMapperBuilder.buildDefault();
    
        /**
         * List  实体类 转换器
         *
         * @param source 原数据
         * @param clz    转换类型
         * @param <T>
         * @param <S>
         * @return
         */
        public <T, S> List<T> convertor(List<S> source, Class<T> clz) {
            if (source == null) return null;
            List<T> map = new ArrayList<>();
            for (S s : source) {
                map.add(mapper.map(s, clz));
            }
            return map;
        }
    
        /**
         * Set 实体类 深度转换器
         *
         * @param source 原数据
         * @param clz    目标对象
         * @param <T>
         * @param <S>
         * @return
         */
        public <T, S> Set<T> convertor(Set<S> source, Class<T> clz) {
            if (source == null) return null;
            Set<T> set = new TreeSet<>();
            for (S s : source) {
                set.add(mapper.map(s, clz));
            }
            return set;
        }
    
        /**
         * 实体类 深度转换器
         *
         * @param source
         * @param clz
         * @param <T>
         * @param <S>
         * @return
         */
        public <T, S> T convertor(S source, Class<T> clz) {
            if (source == null) return null;
            return mapper.map(source, clz);
        }
    
        public void convertor(Object source, Object object) {
            mapper.map(source, object);
        }
    
        public <T> void copyConvertor(T source, Object object) {
            mapper.map(source, object);
        }
    }
    

    GeneralConvertorconvertor()方法

    代码例:

    @Service
    @Transactional
    public class TSlxfAviationPlanImplemService extends BaseService<AviationPlanImplem, String> implements ITSlxfAviationPlanImplemService {
    
        @Autowired
        private TSlxfAviationPlanImplemRepository slxfAviationPlanImplemRepository;
        @Autowired
        private ITSlxfAviationDynamiService slxfAviationDynamiService;
        @Autowired
        private TSlxfAviationDynamiDetailService slxfAviationDynamiDetailService;
        @Autowired
        private GeneralConvertor generalConvertor;
        /**
         * 分页查询飞行计划|实施情况
         *
         * @param searchable
         * @return
         */
        @Override
        public Page<TSlxfAviationPlanImplem> searchPlanImplem(Searchable searchable) {
            searchable.addSearchFilter("isDelete", SearchOperator.eq,"0");
            searchable.addSort(Sort.Direction.DESC,"planDate");
            Page<AviationPlanImplem> paging = slxfAviationPlanImplemRepository.paging(searchable);
            List<AviationPlanImplem> content = paging.getContent();
            List<TSlxfAviationPlanImplem> convertor = generalConvertor.convertor(content, TSlxfAviationPlanImplem.class);
            return new PageImpl<>(convertor, paging.getPageable(), paging.getTotalElements());
        }
    }
    

    1. 飞行计划-实施-动态信息

    1.1 Controller

    @RestController
    public class AviationPlanImplemController extends BaseRestController<AviationPlanImplem,String> implements AviationPlanApi {
    
        @Autowired
        private ITSlxfAviationPlanImplemService slxfAviationPlanImplemService;
    
        @Autowired
        private ITSlxfAviationDynamiService slxfAviationDynamiService;
    
        /**
         * 分页查询飞行计划情况|实施情况列表
         * @param searchable
         * @return
         */
        @Override
        public Page<TSlxfAviationPlanImplem> searchPlanImplem(Searchable searchable) {
            return slxfAviationPlanImplemService.searchPlanImplem(searchable);
        }
    
        /**
         * 分页查询飞行计划动态明细列表
         * @param searchable
         * @return
         */
        @Override
        public Page<TSlxfAviationDynami> searchDynamic(Searchable searchable) {
            return slxfAviationDynamiService.searchDynamic(searchable);
        }
    
        /**
         * 新增|编辑飞行计划|实施情况
         * @param tSlxfAviationPlanImplem
         * @return
         */
        @Override
        public String savePlanImplem(TSlxfAviationPlanImplem tSlxfAviationPlanImplem) {
            return slxfAviationPlanImplemService.addPlanImplem(tSlxfAviationPlanImplem);
        }
    
        /**
         * 删除飞行计划-实施情况
         * @param id
         * @return
         */
        @Override
        public String deletePlanImplem(String id) {
            slxfAviationPlanImplemService.deletePlanImplem(id);
            return id;
        }
    
        /**
         * 查找飞行计划-实施情况详情
         * @param id
         * @param deptType
         * @param taskType
         * @param planDate
         * @return
         */
        @Override
        public TSlxfAviationPlanImplem findPlanImplem(String id, String deptType, String taskType, String planDate) {
            if(StringUtils.isNotBlank(id)){
                return slxfAviationPlanImplemService.findPlanImplemById(id);
            }
            return slxfAviationPlanImplemService.findByPlanDateAndDeptTypeAndTaskType(planDate, deptType, taskType);
        }
    
        /**
         * 新增飞行动态明细
         * @param dynamiVo
         * @return
         */
        @Override
        public String saveDynami(DynamiVo dynamiVo) {
            return slxfAviationDynamiService.saveDynami(dynamiVo);
        }
    
        /**
         * 根据动态信息id删除动态明细数据
         * @param id
         * @return
         */
        @Override
        public String deleteDynami(String id) {
            slxfAviationDynamiService.deleteDynamiInfo(id);
            return id;
        }
    
        /**
         * 查询飞行动态信息明细详细
         * @param id
         * @return DynamiVo
         */
        @Override
        public DynamiVo findDynami(String id) {
            return slxfAviationDynamiService.findDynamiInfo(id);
        }
    }
    

    1.2 计划|实施Service

    @Service
    @Transactional
    public class TSlxfAviationPlanImplemService extends BaseService<AviationPlanImplem, String> implements ITSlxfAviationPlanImplemService {
    
        @Autowired
        private TSlxfAviationPlanImplemRepository slxfAviationPlanImplemRepository;
        @Autowired
        private ITSlxfAviationDynamiService slxfAviationDynamiService;
        @Autowired
        private TSlxfAviationDynamiDetailService slxfAviationDynamiDetailService;
        @Autowired
        private GeneralConvertor generalConvertor;
        /**
         * 分页查询飞行计划|实施情况
         *
         * @param searchable
         * @return
         */
        @Override
        public Page<TSlxfAviationPlanImplem> searchPlanImplem(Searchable searchable) {
            searchable.addSearchFilter("isDelete", SearchOperator.eq,"0");
            searchable.addSort(Sort.Direction.DESC,"planDate");
            Page<AviationPlanImplem> paging = slxfAviationPlanImplemRepository.paging(searchable);
            List<AviationPlanImplem> content = paging.getContent();
            List<TSlxfAviationPlanImplem> convertor = generalConvertor.convertor(content, TSlxfAviationPlanImplem.class);
            return new PageImpl<>(convertor, paging.getPageable(), paging.getTotalElements());
        }
    
    
        /**
         * 新增|编辑飞行计划|实施情况
         *
         * @param tSlxfAviationPlanImplem
         * @return
         */
        @Override
        public String addPlanImplem(TSlxfAviationPlanImplem tSlxfAviationPlanImplem) {
            // 判断当前日期是否存在(根据计划日期,单位类别,任务类别去查)
            TSlxfAviationPlanImplem slxfAviationPlanImplem = this.findByPlanDateAndDeptTypeAndTaskType(tSlxfAviationPlanImplem.getPlanDate(),
                                                                                                       tSlxfAviationPlanImplem.getDeptType(),tSlxfAviationPlanImplem.getTaskType());
            if(!ObjectUtils.isEmpty(slxfAviationPlanImplem) && StringUtils.isBlank(tSlxfAviationPlanImplem.getId())){
                return "日期数据已存在";
            }
            AviationPlanImplem aviationPlanImplem = new AviationPlanImplem();
            BeanUtils.copyProperties(tSlxfAviationPlanImplem,aviationPlanImplem);
            return slxfAviationPlanImplemRepository.save(aviationPlanImplem).getId();
        }
    
        /**
         * 根据计划日期,单位类别,任务类别去查 用于判断数据重复
         *
         * @param planDate
         * @param deptType
         * @param taskType
         * @return
         */
        @Override
        public TSlxfAviationPlanImplem findByPlanDateAndDeptTypeAndTaskType(String planDate, String deptType, String taskType) {
            AviationPlanImplem byPlanDateAndDeptTypeAndTaskType = slxfAviationPlanImplemRepository.findByPlanDateAndDeptTypeAndTaskType(planDate, deptType, taskType);
            return generalConvertor.convertor(byPlanDateAndDeptTypeAndTaskType, TSlxfAviationPlanImplem.class);
        }
    
        @Override
        public void deletePlanImplem(String id) {
            slxfAviationPlanImplemRepository.deleteById(id);
        }
    
        @Override
        public TSlxfAviationPlanImplem findPlanImplemById(String id) {
            AviationPlanImplem one = slxfAviationPlanImplemRepository.findOne(id);
            return generalConvertor.convertor(one,TSlxfAviationPlanImplem.class);
        }
    
    
        /**
         * 根据日期查询飞行计划情况
         *
         * @param reportDate
         * @return
         */
        @Override
        public List<PlanImplemHomeVo> findPlanDynami(String reportDate) {
            List<PlanImplemHomeVo> planImplemHomeVoList = new ArrayList<>();
            List<AviationPlanImplem> planDynamiList = slxfAviationPlanImplemRepository.findPlanDynamiList(reportDate);
            if (CollUtil.isNotEmpty(planDynamiList)) {
                for (AviationPlanImplem planImplem : planDynamiList) {
                    PlanImplemHomeVo implemHomeVo = new PlanImplemHomeVo();
                    BeanUtils.copyProperties(planImplem,implemHomeVo);
                    List<PlanImplVo> voList = new ArrayList<>();
                    //飞行计划情况
                    PlanImplVo impljh = new PlanImplVo();
                    impljh.setTaskType(TaskTypeEnum.JH.getCode());
                    impljh.setFlyTime(planImplem.getFlyTime());
                    impljh.setEndTime(planImplem.getEndTime());
                    impljh.setFlightCount(planImplem.getFlightCount());
                    impljh.setFlightTime(planImplem.getFlightTime());
                    voList.add(impljh);
                    try {
                        //飞行实施情况
                        AviationDynami slxfAviationDynami = slxfAviationDynamiService.findByDeptTypeAndFlightDate(planImplem.getDeptType(), reportDate);
                        PlanImplVo impls = setPlanImplVo(slxfAviationDynami, planImplem, reportDate);
                        voList.add(impls);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    implemHomeVo.setPlanImplVoList(voList);
                    planImplemHomeVoList.add(implemHomeVo);
                }
            }
            return planImplemHomeVoList;
        }
    
    
        /**
         * 飞行实施情况设置
         *
         * @param slxfAviationDynami 飞行动态
         * @param planImplem
         * @param reportDate
         * @return
         * @throws ParseException
         */
        public PlanImplVo setPlanImplVo(AviationDynami slxfAviationDynami, AviationPlanImplem planImplem, String reportDate) throws ParseException {
            PlanImplVo impasse = new PlanImplVo();
            impasse.setTaskType(TaskTypeEnum.SS.getCode());
            if(ObjectUtil.isNotNull(slxfAviationDynami)){
                String dynamicType = slxfAviationDynami.getDynamicType();
                String reason = slxfAviationDynami.getReason();
                StringBuilder resource = new StringBuilder();
                if (DynamicTypeEnum.YC.getCode().equals(dynamicType)) {
                    resource.append("因").append(reason).append(DynamicTypeEnum.YC.getDesc());
                }
                if (DynamicTypeEnum.QX.getCode().equals(dynamicType)) {
                    resource.append("因").append(reason).append(DynamicTypeEnum.QX.getDesc());
                }
                String str = resource.toString();
                if (DynamicTypeEnum.AJH.getCode().equals(dynamicType)) {
                    String flyTime = reportDate + " " + planImplem.getFlyTime()+":00";
                    Date date = DateUtils.getDate(flyTime, DateConst.HYPHEN_DISPLAY_TIME);
                    str = DynamicTypeEnum.AJH.getDesc();
                    AviationDynamiDetail dynamiDetail = slxfAviationDynamiDetailService.findAviationDynamiDetailMinTime(slxfAviationDynami.getId());
                    //当前时间已经到达开飞时刻
                    if (new Date().getTime() > date.getTime()) {
                        impasse.setFlyTime(dynamiDetail != null ? dynamiDetail.getActualEndTime() : null);
                    }
                    //时间已经到达结束时刻
                    String endTime = reportDate + " " + planImplem.getEndTime()+":00";
                    Date time = DateUtils.getDate(endTime, DateConst.HYPHEN_DISPLAY_TIME);
                    if (new Date().getTime() > time.getTime()) {
                        impasse.setFlyTime(dynamiDetail != null ? dynamiDetail.getActualEndTime() : null);
                        AviationDynamiDetail detail = slxfAviationDynamiDetailService.findDynamiDetailCount(slxfAviationDynami.getId());
                        if (detail != null) {
                            impasse.setEndTime(detail.getActualEndTime());
                            impasse.setFlightCount(detail.getSorties());
                            impasse.setFlightTime(detail.getActualTime());
                        }
                    }
                }
                impasse.setFlyTime(str);
                impasse.setEndTime(str);
                impasse.setFlightCount(str);
                impasse.setFlightTime(str);
            }
            return impasse;
        }
    }
    

    1.3 动态Service(Java处理时间段)

    @Service
    @Transactional
    public class TSlxfAviationDynamiService extends BaseService<AviationDynami, String> implements ITSlxfAviationDynamiService {
    
        private TSlxfAviationDynamiRepository slxfAviationDynamiRepository;
    
        @Autowired
        private TSlxfAviationDynamiDetailService tSlxfAviationDynamiDetailService;
    
        @Autowired
        private GeneralConvertor generalConvertor;
    
        public TSlxfAviationDynamiService(TSlxfAviationDynamiRepository slxfAviationDynamiRepository){
                super(slxfAviationDynamiRepository);
                this.slxfAviationDynamiRepository=slxfAviationDynamiRepository;
        }
    
    
        /**
         * 分页查询飞行计划动态明细列表
         * @param searchable
         * @return
         */
        @Override
        public Page<TSlxfAviationDynami> searchDynamic(Searchable searchable) {
            searchable.addSearchFilter("isDelete", SearchOperator.eq,"0");
            searchable.addSort(Sort.Direction.DESC,"flightDate");
            Page<AviationDynami> paging = slxfAviationDynamiRepository.paging(searchable);
            List<AviationDynami> content = paging.getContent();
            List<TSlxfAviationDynami> convertor = generalConvertor.convertor(content, TSlxfAviationDynami.class);
            return new PageImpl<>(convertor, paging.getPageable(), paging.getTotalElements());
        }
    
        @Override
        public AviationDynami findByDeptTypeAndFlightDate(String deptType, String reportDate) {
            return slxfAviationDynamiRepository.findByDeptTypeAndFlightDate(deptType,reportDate);
        }
    
        /**
         * 根据日期和单位类别查飞行动态 用来判断数据日期是否重复
         * @param flightDate
         * @param deptType
         * @return
         */
        @Override
        public AviationDynami findByFlightDateAndDeptType(String flightDate, String deptType) {
            return slxfAviationDynamiRepository.findByFlightDateAndDeptType(flightDate,deptType);
        }
    
        /**
         * 新增飞行动态明细
         * @param dynamiVo
         * @return
         */
        @Override
        public String saveDynami(DynamiVo dynamiVo) {
            // 判断当前日期是否存在
            AviationDynami aviationDynamidynami = this.findByFlightDateAndDeptType(dynamiVo.getFlightDate(),dynamiVo.getDeptType());
            if(StringUtils.isBlank(dynamiVo.getId())&& ObjectUtils.isNotEmpty(aviationDynamidynami)){
                return "日期数据已存在";
            }
            AviationDynami dynami = new AviationDynami();
            BeanUtils.copyProperties(dynamiVo,dynami);
            AviationDynami save = slxfAviationDynamiRepository.save(dynami);
            DynamiVo dynamiVo1 = new DynamiVo();
            BeanUtils.copyProperties(save,dynamiVo1);
            List<TSlxfAviationDynamiDetail> dynamiDetailList = dynamiVo.getDynamiDetailList();
            List<AviationDynamiDetail> convertor = generalConvertor.convertor(dynamiDetailList, AviationDynamiDetail.class);
            DateFormat df = new SimpleDateFormat("HH:mm");
            for(AviationDynamiDetail dynamiDetail : convertor){
                dynamiDetail.setDynamiId(dynamiVo1.getId());
                // 计划起飞时间
                try {
                    Date end = df.parse(dynamiDetail.getPlanEndTime());
                    Date start = df.parse(dynamiDetail.getPlanStartTime());
                    Double planTime = Double.parseDouble(String.valueOf(end.getTime()-start.getTime()));
                    double hours = planTime/(1000* 60 * 60);
                    String result = String.format("%.1f",hours);
                    dynamiDetail.setPlanTime(result);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                // 实际起飞时间
                try {
                    Date end = df.parse(dynamiDetail.getActualEndTime());
                    Date start = df.parse(dynamiDetail.getActualStartTime());
                    Double actualTime = Double.parseDouble(String.valueOf(end.getTime()-start.getTime()));
                    double hours = actualTime/(1000* 60 * 60);
                    String result = String.format("%.1f",hours);
                    dynamiDetail.setActualTime(result);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            List<AviationDynamiDetail> tSlxfAviationDynamiDetails = tSlxfAviationDynamiDetailService.saveAll(convertor);
            List<TSlxfAviationDynamiDetail> convertor1 = generalConvertor.convertor(tSlxfAviationDynamiDetails, TSlxfAviationDynamiDetail.class);
            dynamiVo1.setDynamiDetailList(convertor1);
            return dynamiVo1.getId();
        }
    
        /**
         * 删除飞行动态详情
         * @param id
         */
        @Override
        public void deleteDynamiInfo(String id) {
            slxfAviationDynamiRepository.deleteById(id);
            tSlxfAviationDynamiDetailService.deleteByDynamiId(id);
        }
    
        /**
         * 查询飞行动态信息明细
         * @param id
         * @return
         */
        @Override
        public DynamiVo findDynamiInfo(String id) {
            AviationDynami dynami = slxfAviationDynamiRepository.findOne(id);
            DynamiVo dynamiVo = new DynamiVo();
            BeanUtils.copyProperties(dynami,dynamiVo);
            List<AviationDynamiDetail> slxfAviationDynamiDetails = tSlxfAviationDynamiDetailService.findByDynamiId(id);
            List<TSlxfAviationDynamiDetail> convertor = generalConvertor.convertor(slxfAviationDynamiDetails, TSlxfAviationDynamiDetail.class);
            dynamiVo.setDynamiDetailList(convertor);
            return dynamiVo;
        }
    }
    

    1.4 Repository

    public interface TSlxfAviationPlanImplemRepository extends BaseRepository<AviationPlanImplem, String> {
    
        /**
         * 根据计划日期,单位类别,任务类别去查 用于判断数据重复
         * @param planDate
         * @param deptType
         * @param taskType
         * @return
         */
        AviationPlanImplem findByPlanDateAndDeptTypeAndTaskType(String planDate, String deptType, String taskType);
    
    
        @NativeQuery("SELECT * FROM T_SLXF_AVIATION_PLAN_IMPLEM m WHERE m.TASK_TYPE = '1' AND m.PLAN_DATE =:reportDate  ORDER BY m.DEPT_TYPE ASC")
        List<AviationPlanImplem> findPlanDynamiList(@Param("reportDate") String reportDate);
    }
    

    2. 装备状态管理

    2.1 Controller

    @RestController
    public class AviationEquipmentController implements AviationEquipmentApi {
    
        @Autowired
        private ITSlxfAviationEquipmentService slxfAviationEquipmentService;
    
    
        /**
         * 分页查询装备动态列表
         * @param searchable
         * @return
         */
        @Override
        public Page<TSlxfAviationEquipment> search(Searchable searchable) {
            return slxfAviationEquipmentService.search(searchable);
        }
    
        /**
         * 删除装备动态信息
         * @param id
         * @return
         */
        @Override
        public String delete(String id) {
            slxfAviationEquipmentService.delete(id);
            return id;
        }
    
        /**
         * 新增/编辑装备状态信息
         * @param equipmentVo
         * @return
         */
        @Override
        public String save(EquipmentVo equipmentVo) {
            return slxfAviationEquipmentService.save(equipmentVo, StateTypeEnum.ZCCZ.getCode());
        }
    
        /**
         * 查询装备状态信息
         * @param id
         * @param deptType
         * @param reportDate
         * @return
         */
        @Override
        public EquipmentVo find(String id, String deptType, String reportDate) {
            if (StringUtils.isNotBlank(id)){
                return slxfAviationEquipmentService.findById(id);
            }
            return slxfAviationEquipmentService.findByDeptTypeAndReportDate(deptType,reportDate);
        }
    }
    

    2.2 Service

    @Service
    @Transactional(rollbackFor = Exception.class)
    public class TSlxfAviationEquipmentService extends BaseService<AviationEquipment, String> implements ITSlxfAviationEquipmentService {
    
        @Autowired
        private TSlxfAviationEquipmentRepository repository;
        @Autowired
        private ITSlxfAviationHelicopterService slxfAviationHelicopterService;
        @Autowired
        private ITSlxfAviationTechnoImplService slxfAviationTechnoImplService;
        @Autowired
        private ITSlxfAviationHelicopterdayService slxfAviationHelicopterdayService;
        @Autowired
        private ITSlxfAviationTechnologyService slxfAviationTechnologyService;
        @Autowired
        private ITSlxfAviationHelicopterbadService slxfAviationHelicopterbadService;
        @Autowired
        private GeneralConvertor generalConvertor;
    
        @Override
        public EquipmentVo findById(String id) {
            AviationEquipment aviationEquipment = repository.findOne(id);
            TSlxfAviationEquipment slxfAviationEquipment = generalConvertor.convertor(aviationEquipment, TSlxfAviationEquipment.class);
            return findeChildTableList(slxfAviationEquipment);
        }
    
        @Override
        public EquipmentVo findByDeptTypeAndReportDate(String deptType, String reportDate) {
            AviationEquipment aviationEquipment = repository.findByDeptTypeAndReportDateAndIsDelete(deptType, reportDate, "0");
            TSlxfAviationEquipment slxfAviationEquipment = generalConvertor.convertor(aviationEquipment, TSlxfAviationEquipment.class);
            return findeChildTableList(slxfAviationEquipment);
        }
    
        @Override
        public Page<TSlxfAviationEquipment> search(Searchable searchable) {
            searchable.addSearchFilter("isDelete", SearchOperator.eq, "0");
            searchable.addSort(Sort.Direction.DESC, "reportDate");
            Page<AviationEquipment> equipmentPage = repository.paging(searchable);
            List<AviationEquipment> aviationEquipmentList = equipmentPage.getContent();
            List<TSlxfAviationEquipment> equipmentList = generalConvertor.convertor(aviationEquipmentList, TSlxfAviationEquipment.class);
            return new PageImpl<>(equipmentList, equipmentPage.getPageable(), equipmentPage.getTotalElements());
        }
    
    
        @Override
        public void delete(String id) {
            repository.deleteEquipmentById(id);
        }
    
        @Override
        public String save(EquipmentVo equipmentVo, String code) {
            AviationEquipment aviationEquipment = generalConvertor.convertor(equipmentVo.getAviationEquipment(), AviationEquipment.class);
            AviationEquipment equipment = repository.findByDeptTypeAndReportDateAndIsDelete(aviationEquipment.getDeptType(), aviationEquipment.getReportDate(), "0");
            if (StringUtils.isBlank(aviationEquipment.getId()) && ObjectUtil.isNotNull(equipment)) {
                return "日期数据已存在!";
            }
            aviationEquipment = repository.save(aviationEquipment);
            String equipmentId = aviationEquipment.getId();
            //保存直升机基本情况
            slxfAviationHelicopterService.saveAviationHelicopterList(equipmentId, equipmentVo.getAviationHelicopterList(), code);
            //保存技术通报落实实施情况
            slxfAviationTechnoImplService.saveAviationTechnoImplList(equipmentId, equipmentVo.getAviationTechnoImplList(), code);
            //保存当日战直升机
            slxfAviationHelicopterdayService.saveAviationHelicopterdayList(equipmentId, equipmentVo.getAviationHelicopterdayList(), code);
            //保存技术通报落实情况
            slxfAviationTechnologyService.saveAviationTechnologyList(equipmentId, equipmentVo.getAviationTechnologyList(), code);
            //保存不完好直升机情况
            slxfAviationHelicopterbadService.saveAviationHelicopterbadList(equipmentId, equipmentVo.getAviationHelicopterbadList(), code);
            return equipmentId;
        }
    
    
        /**
         * 根据主表信息查询所有的子表信息
         *
         * @param aviationEquipment
         * @return
         */
        public EquipmentVo findeChildTableList(TSlxfAviationEquipment aviationEquipment) {
            String equipmentId = aviationEquipment.getId();
            EquipmentVo equipmentVo = new EquipmentVo();
            equipmentVo.setAviationEquipment(aviationEquipment);
            List<AviationHelicopter> aviationHelicopterList = slxfAviationHelicopterService.findByEquipmentId(equipmentId);
            equipmentVo.setAviationHelicopterList(generalConvertor.convertor(aviationHelicopterList, TSlxfAviationHelicopter.class));
            List<AviationTechnoImpl> aviationTechnoList = slxfAviationTechnoImplService.findByEquipmentId(equipmentId);
            equipmentVo.setAviationTechnoImplList(generalConvertor.convertor(aviationTechnoList, TSlxfAviationTechnoImpl.class));
            List<AviationHelicopterday> aviationHelicopterdayList = slxfAviationHelicopterdayService.findByEquipmentId(equipmentId);
            equipmentVo.setAviationHelicopterdayList(generalConvertor.convertor(aviationHelicopterdayList, TSlxfAviationHelicopterday.class));
            List<AviationTechnology> aviationTechnologyList = slxfAviationTechnologyService.findByEquipmentId(equipmentId);
            equipmentVo.setAviationTechnologyList(generalConvertor.convertor(aviationTechnologyList, TSlxfAviationTechnology.class));
            List<AviationHelicopterbad> aviationHelicopterbadList = slxfAviationHelicopterbadService.findByEquipmentId(equipmentId);
            equipmentVo.setAviationHelicopterbadList(generalConvertor.convertor(aviationHelicopterbadList, TSlxfAviationHelicopterbad.class));
            return equipmentVo;
        }
    
        /**
         * 根据日期查询直升机状态详情
         *
         * @param reportDate
         * @return
         */
        @Override
        public List<AviationHomeVo> findHelicopterState(String reportDate) {
            List<AviationHomeVo> aviationHomeVoList = repository.findHelicopterState(reportDate);
            if (CollUtil.isNotEmpty(aviationHomeVoList)) {
                for (AviationHomeVo homeVo : aviationHomeVoList) {
                    if (StringUtils.isNotBlank(homeVo.getHelicopterState())) {
                        AviationHelicopterbad helicopter = slxfAviationHelicopterbadService.findByEquipmentIdAndFlightNumber(homeVo.getEquipmentId(), homeVo.getFlightNumber());
                        if (helicopter != null) {
                            homeVo.setFlightCount(helicopter.getBadReason());
                            homeVo.setAvailableTime(helicopter.getCompleteTime());
                            homeVo.setTask(helicopter.getTeamOn());
                        }
                    }
                }
            }
            return aviationHomeVoList;
        }
    
    
        /**
         * 根据日期区间查询直升机完好率
         *
         * @param startTime
         * @param endTime
         * @return
         */
        @Override
        public String getHelicopterPipe(String startTime, String endTime) {
            Map<String, Object> map = repository.getHelicopterPipe(startTime, endTime);
            return map.get("WHL").toString();
        }
    
    
        /**
         * 查询各个状态直升机统计
         *
         * @param reportDate
         * @return
         */
        @Override
        public Map<String, Object> getHelicopterStatistical(String reportDate) {
            Map<String, Object> result = new LinkedHashMap<>();
            Map<String, Object> map = repository.getHelicopterStatisticalWhCount(reportDate);
            result.put(HelicopterStatisticalEnum.WH.getDesc(), map.get("WH"));
            List<Map<String, Object>> listMap = repository.getHelicopterBadCount(reportDate);
            if (CollUtil.isNotEmpty(listMap)) {
                for (Map<String, Object> str : listMap) {
                    String code = CodeInfoUtils.getLabel("DM_HELICOPTER_STATE", str.get("CODE").toString());
                    result.put(code, str.get("VALUE"));
                }
            }
            return result;
        }
    }
    

    2.3 Repository

    public interface TSlxfAviationEquipmentRepository extends BaseRepository<AviationEquipment, String> {
    
        @NativeQuery("SELECT *  FROM VW_SLXF_HELICOPTER v WHERE v.REPORT_DATE =:reportDate  ORDER BY v.helicopter_state desc")
        List<AviationHomeVo> findHelicopterState(@Param("reportDate") String reportDate);
    
        @NativeQuery("SELECT (sum(a.total)-sum(a.bad)) /sum(a.total) as whl FROM\n" +
                "( SELECT e.id,e.REPORT_DATE,\n" +
                "(SELECT count(1) FROM T_SLXF_AVIATION_HELICOPTERBAD b WHERE b.EQUIPMENT_ID = e.id)as bad,\n" +
                "(SELECT count(1) FROM T_SLXF_AVIATION_HELICOPTER h WHERE h.EQUIPMENT_ID = e.id)as total \n" +
                "FROM T_SLXF_AVIATION_EQUIPMENT e )a WHERE a.REPORT_DATE BETWEEN :startTime AND :endTime")
        Map<String, Object> getHelicopterPipe(@Param("startTime") String startTime, @Param("endTime") String endTime);
    
        @Modifying
        @NativeQuery("UPDATE T_SLXF_AVIATION_EQUIPMENT SET IS_DELETE ='1' WHERE id =:id ")
        void deleteEquipmentById(@Param("id") String id);
    
        AviationEquipment findByDeptTypeAndReportDateAndIsDelete(String value, String nowDay, String s);
    
        @NativeQuery("SELECT (sum(a.total) -sum(a.bad))as wh  FROM\n" +
                "(SELECT e.id,e.REPORT_DATE,\n" +
                "(SELECT count(1) FROM T_SLXF_AVIATION_HELICOPTERBAD b WHERE b.EQUIPMENT_ID = e.id)as bad,\n" +
                "(SELECT count(1) FROM T_SLXF_AVIATION_HELICOPTER h WHERE h.EQUIPMENT_ID = e.id)as total\n" +
                "FROM T_SLXF_AVIATION_EQUIPMENT e\n" +
                ")a  WHERE a.REPORT_DATE =:reportDate ")
        Map<String, Object> getHelicopterStatisticalWhCount(@Param("reportDate") String reportDate);
    
        @NativeQuery("SELECT  b.bad_reason as code ,count(1)as value FROM T_SLXF_AVIATION_HELICOPTERBAD b\n" +
                "LEFT JOIN T_SLXF_AVIATION_EQUIPMENT e ON e.id = b.EQUIPMENT_ID\n" +
                "WHERE e.REPORT_DATE =:reportDate  GROUP BY b.bad_reason ")
        List<Map<String, Object>> getHelicopterBadCount(@Param("reportDate") String reportDate);
    }
    

    3. 首页数据统计

    3.1 Controller

    @RestController
    public class AviationHomeController implements AviationHomeApi {
    
        @Autowired
        private ITSlxfAviationEquipmentService slxfAviationEquipmentService;
        @Autowired
        private ITSlxfAviationPlanImplemService slxfAviationPlanImplemService;
    
    
        /**
         * 根据日期查询飞行计划情况
         *
         * @param reportDate
         * @return
         */
        @Override
        public List<PlanImplemHomeVo> findPlanDynami(String reportDate) {
            return slxfAviationPlanImplemService.findPlanDynami(reportDate);
        }
    
        /**
         * 根据日期查询直升机状态详情
         *
         * @param reportDate
         * @return
         */
        @Override
        public List<AviationHomeVo> findHelicopterState(String reportDate) {
            return slxfAviationEquipmentService.findHelicopterState(reportDate);
        }
    
        /**
         * 根据日期区间查询直升机完好率
         * @param startTime
         * @param endTime
         * @return
         */
        @Override
        public String getHelicopterPipe(String startTime, String endTime) {
            return slxfAviationEquipmentService.getHelicopterPipe(startTime,endTime);
        }
    
        /**
         * 查询各个状态直升机统计
         * @param reportDate
         * @return
         */
        @Override
        public Map<String, Object> getHelicopterStatistical(String reportDate) {
            return slxfAviationEquipmentService.getHelicopterStatistical(reportDate);
        }
    }
    

    4. 定时任务

    @Component
    public class AviationEquipmentJob {
    
        @Autowired
        private TSlxfAviationEquipmentRepository slxfAviationEquipmentRepository;
        @Autowired
        private ITSlxfAviationEquipmentService slxfAviationEquipmentService;
    
        /**
         * 每天凌晨2点执行 新增装备动态信息
         */
        @Scheduled(cron = "0 0 2 * * ?")
        public void work() {
            //获取今日
            String nowDay = DateUtils.getDateFormat(DateConst.HYPHEN_DISPLAY_DATE);
            //获取昨天的日期
            String yesterday = DateUtils.getDateFormat(DateUtil.yesterday(), DateConst.HYPHEN_DISPLAY_DATE);
            List<CodeRecord> recordList = CodeInfoUtils.getCodeListByCodeDicId("DM_AVIATION_DEPT_TYPE");
            if (CollUtil.isNotEmpty(recordList)) {
                for (CodeRecord record : recordList) {
                    AviationEquipment nowEquipment = slxfAviationEquipmentRepository.findByDeptTypeAndReportDateAndIsDelete(record.getValue(), nowDay,"0");
                    if (ObjectUtil.isNull(nowEquipment)) {
                        AviationEquipment yesterEquipment = slxfAviationEquipmentRepository.findByDeptTypeAndReportDateAndIsDelete(record.getValue(), yesterday,"0");
                        if (ObjectUtil.isNotNull(yesterEquipment)) {
                            EquipmentVo equipmentVo = slxfAviationEquipmentService.findById(yesterEquipment.getId());
                            slxfAviationEquipmentService.save(setEquipmentVo(equipmentVo, nowDay), StateTypeEnum.DSRW.getCode());
                        }
                    }
                }
            }
        }
    
        /**
         *  设置装备状态相关参数
         * @param equipmentVo
         * @param dateTime
         * @return
         */
        public EquipmentVo setEquipmentVo(EquipmentVo equipmentVo, String dateTime) {
            TSlxfAviationEquipment aviationEquipment = equipmentVo.getAviationEquipment();
            aviationEquipment.setId(null);
            aviationEquipment.setReportDate(dateTime);
            aviationEquipment.setCreateTime(DateUtils.getDateFormat(DateConst.DB_STORE_TIME));
            equipmentVo.setAviationEquipment(aviationEquipment);
            return equipmentVo;
        }
    
    }
    

    相关文章

      网友评论

        本文标题:航空处项目

        本文链接:https://www.haomeiwen.com/subject/nnwwoktx.html