package org.jeecg.modules.homePage.face.impl;

import org.jeecg.modules.checkData.service.IMovementRecordsMasterService;
import org.jeecg.modules.dynamicStaticAnalysis.entity.AnalysisBatch;
import org.jeecg.modules.dynamicStaticAnalysis.service.IAnalysisBatchService;
import org.jeecg.modules.homePage.dto.DiseaseDTO;
import org.jeecg.modules.homePage.face.HomePageFace;
import org.jeecg.modules.homePage.vo.DiseaseVO;
import org.jeecg.modules.homePage.vo.ToDoDetailVO;
import org.jeecg.modules.homePage.vo.ToDoVO;
import org.jeecg.modules.maintenanceWork.service.IWorkBatchService;
import org.jeecg.modules.subwayNetwork.service.ILightRailService;
import org.jeecg.modules.subwayNetwork.vo.SectionStationNode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class HomePageFaceImpl implements HomePageFace {


    @Resource
    private ILightRailService lightRailService;

    @Resource
    private IMovementRecordsMasterService movementRecordsMasterService;

    @Resource
    private IAnalysisBatchService analysisBatchService;

    @Resource
    private IWorkBatchService workBatchService;


    @Override
    public List<SectionStationNode> getTree() {
        return lightRailService.getTree();
    }


    @Override
    public ToDoVO todoList() {
        String currentUserId = null;
        ToDoVO vo = new ToDoVO();

        // 1.查询检查未使用的检查批次
        List<ToDoDetailVO> checkBatchList = movementRecordsMasterService.getTodoList(currentUserId);
        vo.setCheckBatchList(checkBatchList);


        // 2.查询未派工的分析批次&待派工分析结果列表数据中存在不需要派工的记录
        List<ToDoDetailVO> analysisBatchList = analysisBatchService.getTodoList(currentUserId);
        vo.setAnalysisBatchList(analysisBatchList);


        // 3.查询作业状态未完成的维修派工批次
        List<ToDoDetailVO> workBatchList = workBatchService.getTodoList(currentUserId);
        vo.setWorkBatchList(workBatchList);
        return vo;
    }

    @Override
    public List<DiseaseVO> diseaseList(DiseaseDTO dto) {

        AnalysisBatch one = analysisBatchService.lambdaQuery()
                .orderByDesc(AnalysisBatch::getUpdateTime)
                .last("limit 1")
                .one();

        List<DiseaseVO> records = analysisBatchService.diseaseList(one.getId());
        for (DiseaseVO record : records) {
            record.setLineAliasId(one.getLineAliasId());
            if (one.getLineAliasId().equals("1")) {
                record.setLineAliasCode("SDK");
            } else {
                record.setLineAliasCode("XDK");
            }
        }
//
//        // 病害里程，取分
//        List<DiseaseVO> records = new ArrayList<>();
//
//        DiseaseVO vo = new DiseaseVO();
//        vo.setId("1682308697792339970");
//        vo.setLineAliasCode("SDK");
//        vo.setMileage("21556");
//        vo.setOverrunType("左轨向");
//        vo.setOverrunLevel("1");
//        vo.setLongitude("2");
//        vo.setPeakValue("-10.44");
//        vo.setDataDifference("-0.44");
//        records.add(vo);
//
//        DiseaseVO vo2 = new DiseaseVO();
//        vo2.setId("1682308697792339970");
//        vo2.setLineAliasCode("SDK");
//        vo2.setMileage("21556");
//        vo2.setOverrunType("左轨向");
//        vo2.setOverrunLevel("1");
//        vo2.setLongitude("2");
//        vo2.setPeakValue("-10.44");
//        vo2.setDataDifference("-0.44");
//        records.add(vo2);

        return records;
    }
}
