AdminUtilsController.java 9.29 KB
package com.bsth.controller.realcontrol;

import java.util.*;

import com.bsth.data.BasicData;
import com.bsth.service.SectionService;
import com.bsth.service.StationService;
import com.bsth.data.directive.DayOfDirectives;
import com.bsth.data.directive.DirectivesPstThread;
import com.bsth.data.directive.GatewayHttpUtils;
import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess;
import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader;
import com.bsth.data.gpsdata_v2.load.SocketClientLoader;
import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
import com.bsth.data.msg_queue.DirectivePushQueue;
import com.bsth.data.msg_queue.WebSocketPushQueue;
import com.bsth.data.pilot80.PilotReport;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.service.SystemParamService;
import com.bsth.util.MailUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bsth.websocket.handler.SendUtils;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;

/**
 * Created by panzhao on 2017/4/14.
 */
@RestController
@RequestMapping("adminUtils")
public class AdminUtilsController {


    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    DayOfSchedule dayOfSchedule;

    @Autowired
    GeoCacheData geoCacheData;

    @Autowired
    DayOfDirectives dayOfDirectives;

    @Autowired
    SendUtils sendUtils;

    @Autowired
    PilotReport pilotReport;

    @Autowired
    private MailUtils mailUtils;

    @Autowired
    private BasicData.BasicDataLoader basicDataLoader;

    @Autowired
    private SectionService sectionService;

    @Autowired
    private StationService stationService;

    @Autowired
    private SystemParamService systemParamService;

    @Autowired
    private SocketClientLoader socketClientLoader;

    @Autowired
    private GatewayHttpLoader gatewayHttpLoader;

    @Autowired
    private GatewayHttpUtils gatewayHttpUtils;

    /**
     * 出现重复班次的车辆
     *
     * @param
     * @RequestMapping(value = "/schRepeat", method = RequestMethod.POST)
     * public void schRepeat(@RequestParam String nbbm){
     * logger.info("前端通知,车辆 " + nbbm + "出现重复班次,开始检测...");
     * List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(nbbm);
     * logger.info("检测前,车辆班次数量:" + list.size());
     * <p>
     * Map<Long, ScheduleRealInfo> map = new HashMap<>();
     * for(ScheduleRealInfo sch : list){
     * if(map.containsKey(sch.getId())){
     * logger.info("检测到重复ID: " + sch.getId());
     * }
     * map.put(sch.getId(), sch);
     * }
     * <p>
     * logger.info("检测后,车辆班次数量:" + list.size());
     * if(map.values().size() > 0){
     * dayOfSchedule.replaceByNbbm(nbbm, map.values());
     * }
     * }
     */

/*    @RequestMapping(value = "/directivePushQueue")
    public void directivePushQueue(){
        DirectivePushQueue.start();
    }*/
    @RequestMapping(value = "/directiveQueueSize")
    public void directiveQueueSize() {
        DirectivePushQueue.size();
    }

    /*@RequestMapping(value = "/webSocketPushQueue")
    public void webSocketPushQueue(){
        WebSocketPushQueue.start();
    }*/

    @RequestMapping(value = "/webSocketQueueSize")
    public void webSocketQueueSize() {
        WebSocketPushQueue.size();
    }

    @RequestMapping(value = "/setHttpFlag")
    public void setHttpFlag(@RequestParam int flag) {
        if (flag != 0 && flag != -1)
            return;
        GpsDataLoaderThread.setFlag(flag);
    }

    @RequestMapping(value = "/updateCacheBuff")
    public void updateCacheBuff() {
        geoCacheData.loadData();
    }

    @RequestMapping(value = "/reCalcLpSch")
    public void reCalcLpSch() {
        dayOfSchedule._test_reCalcLpSch();
    }

    @RequestMapping(value = "/findSchByLpName")
    public List<ScheduleRealInfo> findSchByLpName(@RequestParam String lpName) {
        return dayOfSchedule.getLpScheduleMap().get(lpName);
    }

    @RequestMapping(value = "/findSchByNbbm")
    public List<ScheduleRealInfo> findSchByNbbm(@RequestParam String nbbm) {
        return dayOfSchedule.findByNbbm(nbbm);
    }

    @RequestMapping(value = "/executeCurr")
    public ScheduleRealInfo executeCurr(@RequestParam String nbbm) {
        return dayOfSchedule.executeCurr(nbbm);
    };

    @RequestMapping(value = "/reCalcExecPlan4Nbbm")
    public void reCalcExecPlan4Nbbm(@RequestParam String nbbm) {
        dayOfSchedule.reCalcExecPlan(nbbm);
    };

    @RequestMapping(value = "/reCalcExecPlan4Line")
    public void reCalcExecPlan4Line(@RequestParam String lineCode) {
        Set<String> nbbms = dayOfSchedule.findCarByLineCode(lineCode);
        for (String nbbm : nbbms) {
            dayOfSchedule.reCalcExecPlan(nbbm);
        }
    };

    @RequestMapping(value = "/removeExecPlan")
    public int removeExecPlan(@RequestParam String nbbm) {
        dayOfSchedule.removeExecPlan(nbbm);
        return 1;
    }

    @RequestMapping(value = "/sch_re_calc_id_maps")
    public int reCalcIdMaps() {
        return dayOfSchedule.reCalcIdMaps();
    }

    @RequestMapping(value = "/sch_size_string")
    public String schSizeString() {
        return dayOfSchedule.sizeString();
    }

    @RequestMapping(value = "/containerSize")
    public Map<String, Integer> containerSize() {
        Map<String, Integer> rs = new HashMap<>();
        rs.put("60_size", dayOfDirectives.all60().size());
        rs.put("80_size", pilotReport.findAll().size());
        rs.put("nbbm_sch_size", dayOfSchedule.findAll().size());
        rs.put("lp_sch_size", dayOfSchedule.findAllByLpContainer().size());
        rs.put("id_sch_size", dayOfSchedule.findAllByIdContainer().size());
        rs.put("pst_sch_size", dayOfSchedule.getPstSize());
        rs.put("speeds_size", OverspeedProcess.size());
        return rs;
    }

    @RequestMapping(value = "/websocketRadioText")
    public int radioText(String t, String lineCode) {
        sendUtils.sendRadioText(t, lineCode);
        return 0;
    }

    @Autowired
    DirectivesPstThread directivesPstThread;

    @RequestMapping(value = "/_sd_60_pst")
    public void sd_60_pst() {
        logger.info("手动入库指令....");
        directivesPstThread.run();
    }
    
    @RequestMapping("/changeLogLevel")
    public Map<String, Object> changeLogLevel(@RequestParam String level) {
        Map<String, Object> rs = new HashMap<>();
        rs.put("errCode", 1);
        LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
        context.getLogger("root").setLevel(Level.toLevel(level));
        rs.put("errCode", 0);
        rs.put("errMsg", "成功");

        return rs;
    }

    @RequestMapping("/refreshBasicAll")
    public String refreshBasicAll() {
        Map<String, Object> result = new HashMap<>();
        try {
            basicDataLoader.loadAllData();
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "error";
    }

    @RequestMapping("/reloadSystemParam")
    public String reloadSystemParam() {
        try {
            systemParamService.refresh();

            return "success";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "error";
    }

    @RequestMapping("/applySystemParam")
    public String applySystemParam() {
        try {
            socketClientLoader.afterPropertiesSet();
            gatewayHttpLoader.afterPropertiesSet();
            gatewayHttpUtils.afterPropertiesSet();
            //rfidHttpLoader.afterPropertiesSet();
            //ssoConfig.afterPropertiesSet();

            return "success";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "error";
    }

    @RequestMapping("/reloadAndApplySystemParam")
    public String reloadAndApplySystemParam() {
        try {
            systemParamService.refresh();

            socketClientLoader.afterPropertiesSet();
            gatewayHttpLoader.afterPropertiesSet();
            gatewayHttpUtils.afterPropertiesSet();
            //rfidHttpLoader.afterPropertiesSet();
            //ssoConfig.afterPropertiesSet();

            return "success";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "error";
    }

    @RequestMapping("/section/translateWgs2Bd")
    public String translateWgs2Bd1() {
        Map<String, Object> result = new HashMap<>();
        try {
            //sectionService.translateWgs2Bd();
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "error";
    }

    @RequestMapping("/station/translateWgs2Bd")
    public String translateWgs2Bd2() {
        Map<String, Object> result = new HashMap<>();
        try {
            //stationService.translateWgs2Bd();
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "error";
    }
}