EchartsController.java 4.63 KB
package com.bsth.controller;

import com.bsth.data.gpsdata_v2.GpsRealData;
import com.bsth.entity.realcontrol.ChildTaskPlan;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.schedule.SchedulePlanInfo;
import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
import com.bsth.repository.schedule.SchedulePlanInfoRepository;
import com.bsth.service.report.CulateMileageService;
import com.bsth.util.Arith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

@RestController
@RequestMapping("echartsData")
public class EchartsController {

	@Autowired
	ScheduleRealInfoRepository scheduleRealInfoRepository;

	@Autowired
	SchedulePlanInfoRepository schedulePlanRepository;

	@Autowired
	GpsRealData gpsRealData;

	@Autowired
	CulateMileageService culateService;

	@RequestMapping(value = "/home/echarts1")
	public List<Map<String,Object>> schData(@RequestParam String lineCode) {
		LocalDate localDate=LocalDate.now();
		DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
		List<ScheduleRealInfo> list=scheduleRealInfoRepository.scheduleDaily(lineCode, localDate.format(dtf));
		List<Map<String,Object>> result=new ArrayList<>();
		int wzx=0;
		int zzzx=0;
		int yzx=0;
		int ylb=0;
		/**班次状态 0 未执行 1 正在执行 2 已执行 -1 已烂班 */
		for (ScheduleRealInfo scheduleRealInfo : list) {
			if(scheduleRealInfo.getStatus()==0){
				wzx++;
			}else if(scheduleRealInfo.getStatus()==1){
				zzzx++;
			}else if(scheduleRealInfo.getStatus()==2){
				yzx++;
			}else if(scheduleRealInfo.getStatus()==-1){
				ylb++;
			}
		}
		Map<String,Object> map1=new HashMap<>();
		map1.put("value",wzx);
		map1.put("name","未执行");
		result.add(map1);
		Map<String,Object> map2=new HashMap<>();
		map2.put("value",zzzx);
		map2.put("name","正在执行");
		result.add(map2);
		Map<String,Object> map3=new HashMap<>();
		map3.put("value",yzx);
		map3.put("name","已执行");
		result.add(map3);
		Map<String,Object> map4=new HashMap<>();
		map4.put("value",ylb);
		map4.put("name","已烂班");
		result.add(map4);
		return result;
	}

	@RequestMapping(value = "/home/echarts2")
	public List<List<Object>> echarts2(@RequestParam String lineCode) {
		List<List<Object>> result=new ArrayList<>();
		LocalDate localDate=LocalDate.now();
		DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
		List<ScheduleRealInfo> list=scheduleRealInfoRepository.scheduleDaily(lineCode, localDate.format(dtf));

		List<ScheduleRealInfo> lists = new ArrayList<>();
		for (int i = 0; i < list.size(); i++) {
			ScheduleRealInfo s = list.get(i);
			Set<ChildTaskPlan> cts = s.getcTasks();
			if (cts != null && cts.size() > 0) {
				lists.add(s);
			} else {
				if (s.getFcsjActual() != null && s.getZdsjActual() != null) {
					lists.add(s);
				}
			}
		}

		List<String> sjjghL=new ArrayList<>();
		List<String> sjjbhL=new ArrayList<>();
		for (ScheduleRealInfo sch : list) {
			if(!sjjghL.contains(sch.getjGh())){
				sjjghL.add(sch.getjGh());
			}
			if(!sjjbhL.contains(sch.getClZbh())){
				sjjbhL.add(sch.getClZbh());
			}
		}
		List<Object> sj=new ArrayList<>();
		sj.add(culateService.culateSjbc(list, "") + culateService.culateLjbc(list, ""));//实际班次(实际+临加)
		sj.add(sjjghL.size());
		sj.add(sjjbhL.size());
		double ksgl = culateService.culateKsgl(list);//子任务空驶公里
		double jccgl = culateService.culateJccgl(lists);//空驶班次公里
		double sjgl = culateService.culateSjgl(lists);//实际营运公里
		double ljgl = culateService.culateLjgl(lists);//临加公里
		sj.add(Arith.add(Arith.add(ksgl, jccgl), Arith.add(sjgl, ljgl)));//实际总公里
		sj.add(Arith.add(sjgl, ljgl));//实际总营运公里
		sj.add(Arith.add(ksgl, jccgl));//实际非运营公里


		List<SchedulePlanInfo> list2=schedulePlanRepository.findPlanByXlAndDate(lineCode, localDate.format(dtf));
		List<String> jhjghL=new ArrayList<>();
		List<String> jhjbhL=new ArrayList<>();
		for (SchedulePlanInfo sch : list2) {
			if(!jhjghL.contains(sch.getjGh())){
				jhjghL.add(sch.getjGh());
			}
			if(!jhjbhL.contains(sch.getClZbh())){
				jhjbhL.add(sch.getClZbh());
			}
		}
		List<Object> jh=new ArrayList<>();
		jh.add(culateService.culateJhbc(list, ""));//计划班次
		jh.add(jhjghL.size());
		jh.add(jhjbhL.size());
		jh.add(Arith.add(culateService.culateJhgl(list), culateService.culateJhJccgl(list))); //计划总里程
		jh.add(culateService.culateJhgl(list));//计划营运里程
		jh.add(culateService.culateJhJccgl(list));//计划非营运里程

		result.add(sj);
		result.add(jh);
		return result;
	}

}