package com.pqs9000.controller.business;

import cn.hutool.core.util.StrUtil;
import com.njcn.enums.ProjectEnum;
import com.njcn.pojo.commons.WebItem;
import com.njcn.pojo.system.SubSystem;
import com.njcn.service.system.SystemService;
import com.njcn.utils.XssFilterUtil;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hongawen
 * @date 2018/3/26 22:41
 */
@Controller
@RequestMapping("business")
public class BusinessController {

    @Resource
    private SystemService systemService;

//    @GetMapping("/doBusiness")
//    public ModelAndView main() {
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.setViewName("main");
//        //判断是否需要显示切换系统以及待切换的系统信息
//        List<SubSystem> subSystems = systemService.getActiveSystem();
//        boolean displayFlag = false;
//        for (SubSystem subSystem : subSystems) {
//            if (!subSystem.getSystemEName().equalsIgnoreCase(ProjectEnum.PQS9000.getItem())) {
//                displayFlag = true;
//                modelAndView.addObject("item", subSystem.getSystemEName());
//                modelAndView.addObject("name", subSystem.getSystemEName().toUpperCase() + subSystem.getSystemName());
//            }
//        }
//        modelAndView.addObject("displayFlag", displayFlag);
//        return modelAndView;
//    }

    @GetMapping("/doBusiness")
    public ModelAndView main() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("main");
        //判断是否需要显示切换系统以及待切换的系统信息
        List<SubSystem> subSystems = systemService.getActiveSystem();
        List<WebItem> webItems = new ArrayList<>();
        boolean displayFlag = false;
        for (SubSystem subSystem : subSystems) {
            if (!subSystem.getSystemEName().equalsIgnoreCase(ProjectEnum.PQS9000.getItem())) {
                displayFlag = true;
                WebItem webItem = new WebItem();
                webItem.setItem(subSystem.getSystemEName());
                webItem.setName(subSystem.getSystemEName().toUpperCase() + subSystem.getSystemName());
                webItems.add(webItem);
            }
        }
//        WebItem webItem=new WebItem();
//        webItem.setItem("pqs9300");
//        webItem.setName("PQS9800大屏展示系统");
//        webItems.add(webItem);
        modelAndView.addObject("webItems", webItems);
        modelAndView.addObject("displayFlag", displayFlag);
        return modelAndView;
    }

    //*****************概览********************* start
    @GetMapping("/overview")
    public String overview() {
        return "overview/overview";
    }

    @GetMapping("/excel")
    public String excel() {
        return "report/excel";
    }

    @GetMapping("/pointInfo")
    public String pointInfo() {
        return "business/assessmentsis/pointInfo";
    }


    @GetMapping("/percent")
    public String percent() {
        return "report/percent";
    }

    @GetMapping("/fpyreport")
    public String fpyreport() {
        return "report/fpyReport";
    }

    @GetMapping("/expmodel")
    public String expmodel() {
        return "report/expModel";
    }

    @GetMapping("/platereports")
    public String platereports() {
        return "business/assessmentsis/platereports";
    }

    @GetMapping("/platereport")
    public String platereport() {
        return "business/assessmentsis/platereport";
    }

    @GetMapping("/plateShare")
    public String plateShare() {
        return "business/assessmentsis/plateShare";
    }

    @GetMapping("/excelsetting")
    public String excelSetting() {
        return "report/excelSetting";
    }

    @GetMapping("/devicestatus")
    public String deviceStatus() {
        return "overview/deviceStatus";
    }

    @GetMapping("/onlinerate")
    public String onlineRate() {
        return "overview/onlineRate";
    }

    @GetMapping("/powerquality")
    public String powerquality() {
        return "overview/powerQuality";
    }

    @GetMapping("/dataintegrality")
    public String dataIntegrality() {
        return "overview/dataIntegrality";
    }

    @GetMapping("singleonlinerate")
    public String singleOnlineRate() {
        return "overview/singleOnlineRate";
    }

    @GetMapping("singleintegrality")
    public String singleIntegrality() {
        return "overview/singleIntegrality";
    }

    @GetMapping("frequency")
    public String frequency() {
        return "overview/frequency";
    }

    //****************概览**********************end


    @GetMapping("/monitor")
    public String monitor() {
        return "business/monitor/monitor";
    }

    @GetMapping("/sssj")
    public String sssj() {
        return "business/monitor/actualData";
    }

    @GetMapping("/yxzt")
    public String yxzt() {
        return "business/monitor/yxzt";
    }

    @GetMapping("/wtzb")
    public String wtzb() {
        return "business/monitor/wtzb";
    }

    @GetMapping("/wtqs")
    public String wtqs() {
        return "business/monitor/wtqs";
    }

    @GetMapping("/offlinemonitor")
    public String offlinemonitor() {
        return "business/monitor/offlinemonitor";
    }

    @GetMapping("/offwtqs")
    public String offwtqs() {
        return "business/monitor/offwtqs";
    }

    @GetMapping("offxbpp")
    public String offxbpp() {
        return "business/monitor/offxbpp";
    }

    @GetMapping("/offword")
    public String offword() {
        return "business/monitor/offword";
    }

    @GetMapping("/ploymanage")
    public String ploymanage() {
        return "business/monitor/ploymanage";
    }

    @GetMapping("/upoffploy")
    public String upoffploy() {
        return "business/monitor/upoffploy";
    }

    @RequestMapping(value = "upoffreport")
    public String upoffreport(HttpSession session, String reportIndex, String reportName) {
        reportIndex = XssFilterUtil.dealString(reportIndex);
        reportName = XssFilterUtil.dealString(reportName);
        session.setAttribute("reportIndex", reportIndex);
        session.setAttribute("reportName", reportName);
        return "business/monitor/upoffreport";
    }

    @GetMapping("/ham")
    public String ham() {
        return "business/assessmentsis/harmonic";
    }

    @GetMapping("/his")
    public String his() {
        return "business/assessmentsis/history";
    }

    @GetMapping("/plate")
    public String plate() {
        return "business/assessmentsis/platenormal";
    }

    @GetMapping("/normLimits")
    public String normLimits() {
        return "business/assessmentsis/normLimits";
    }

    @GetMapping("/normlimitdraw")
    public String normlimitdraw() {
        return "business/assessmentsis/normLimitDraw";
    }

    @GetMapping("/abnormlimit")
    public String abnormlimit() {
        return "business/assessmentsis/abnormLimit";
    }

    @GetMapping("/abnormLimits")
    public String abnormLimits() {
        return "business/assessmentsis/abnormLimits";
    }

    @GetMapping("/abnormlimitdraw")
    public String abnormlimitdraw() {
        return "business/assessmentsis/abnormLimitDraw";
    }


    //质量评估
    @GetMapping("/zlpg")
    public String zlpg() {
        return "business/monitor/zlpg";
    }

    //谐波频谱
    @GetMapping("/xbpp")
    public String xbpp() {
        return "business/monitor/xbpp";
    }

    //实时趋势
    @GetMapping("/trend")
    public String trend() {
        return "business/monitor/trend";
    }

    //谐波数据
    @GetMapping("/xbsj")
    public String xbsj() {
        return "business/monitor/xbsj";
    }

    // 跳转终端统计页面
    @RequestMapping(value = "statistics")
    public String statistics() {
        return "business/manage/machineStatistics";
    }

    //间谐波数据
    @GetMapping("/jxbsj")
    public String jxbsj() {
        return "business/monitor/jxbsj";
    }

    //谐波电流幅值数据
    @GetMapping("/xbdl")
    public String xbdl() {
        return "business/monitor/xbdl";
    }


    /*************历史数据*************/
    @GetMapping("/norm")
    public String norm() {
        return "business/assessmentsis/historys";
    }

    /***********谐波频谱************/
    @GetMapping("/harmonic")
    public String harmonic() {
        return "business/assessmentsis/harmonics";
    }

    /********稳态越限统计********/
    @GetMapping("/normlimit")
    public String normlimit() {
        return "business/assessmentsis/normLimit";
    }

    @GetMapping("/platenormal")
    public String platenoraml() {
        return "business/assessmentsis/platenormals";
    }

    //    资源管理下载
    @RequestMapping(value = "sourcemanage")
    public String sourceManage() {
        return "business/manage/sourceManage";
    }

    /******获取波形文件********/
    @RequestMapping(value = "vdwaveform")
    public String vdWaveform(HttpSession session, String eventIndex) {
        eventIndex = XssFilterUtil.dealString(eventIndex);
        session.setAttribute("eventIndex", eventIndex);
        return "business/area/waveform";
    }

    // 跳转终端运行管理页面
    @GetMapping(value = "runtime")
    public ModelAndView runtime(String area,String type, String manufacturer) {
        ModelAndView modelAndView = new ModelAndView();
        if(StrUtil.isNotBlank(manufacturer)){
            if(manufacturer.indexOf("(")!=-1){
                manufacturer=manufacturer.substring(0,manufacturer.indexOf("("));
            }
        }
        modelAndView.setViewName("business/manage/runtime");
        modelAndView.addObject("area", area);
        modelAndView.addObject("type", type);
        modelAndView.addObject("manufacturer", manufacturer);
        return modelAndView;
    }

//    // 跳转到终端状态更新列表
//    @GetMapping(value = "terminallog")
//    public String terminallog() {
//        return "business/manage/terminalLogManage";
//    }

    // 跳转通讯测试页面
    @RequestMapping(value = "communicate")
    public String communicate() {
        return "business/manage/communicate";
    }

    //帮助中心
    @RequestMapping(value = "userhelp")
    public String userHelp(HttpSession session, String parameter) {
        parameter = XssFilterUtil.dealString(parameter);
        session.setAttribute("parameter", parameter);
        return "business/manage/userHelp";
    }

    /**
     * 跳转404页面
     */
    @RequestMapping(value = "404")
    public String notFound() {
        return "business/error/404";
    }

    @RequestMapping("/userDetail")
    public String userDetail(HttpSession session, String userIndex) {
        userIndex = XssFilterUtil.dealString(userIndex);
        session.setAttribute("userIndex", userIndex);
        return "userDetail";
    }

    /**
     * 跳转到修改密码
     */
    @RequestMapping("updatePassWord")
    public String updatePassWord(HttpSession session, String userIndex) {
        userIndex = XssFilterUtil.dealString(userIndex);
        session.setAttribute("userIndex", userIndex);
        return "updatePassWord";
    }

    /**
     * 暂降列表页面多条件筛选按钮弹出页面
     *
     * @author cdf
     * @date 2021/1/20
     */
    @RequestMapping("vdlistquery")
    public String vdlistquery() {
        return "business/area/vdListQuery";
    }

    /**
     * 跳转到监测点台账信息
     */
    @RequestMapping("lineledger")
    public String lineLedger() {
        return "business/manage/lineLedger";
    }


    /**
     *  跳转到监测点gis地理信息图
     */
    @RequestMapping("tomonitorscope")
    public String monitorScope() {
        return "business/area/monitorScope";
    }

    /**
     *  跳转到时间选择控件
     */
    @RequestMapping("timerange")
    public String timeRange() {
        return "business/manage/timeRange";
    }

    /**
     *  跳转到数据完整性详情界面
     */
    @RequestMapping("integralityDetail")
    public ModelAndView integralityDetail(String startTime, String endTime, String timeType, String lineId) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("business/manage/integralityDetail");
        modelAndView.addObject("startTime", startTime);
        modelAndView.addObject("endTime", endTime);
        modelAndView.addObject("timeType", timeType);
        modelAndView.addObject("lineId", lineId);
        return modelAndView;
    }

    /**
     *  跳转按地市统计监测点运行状态、前置机统计
     */
    @RequestMapping("statisticalAnalysis")
    public String statisticalAnalysis() {
        return "business/manage/statisticalAnalysis";
    }

}
