package com.pqs9300.controller;

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.AppConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
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 AppConfig appConfig;

    @Resource
    private SystemService systemService;

    @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.PQS9300.getItem())) {
                displayFlag = true;
                WebItem webItem=new WebItem();
                webItem.setItem(subSystem.getSystemEName());
                webItem.setName(subSystem.getSystemEName().toUpperCase() + subSystem.getSystemName());
                webItems.add(webItem);
            }
        }
        modelAndView.addObject("webItems",webItems);
        modelAndView.addObject("displayFlag", displayFlag);
        return modelAndView;
    }


    /**
     * 首页
     */
    @GetMapping("/index")
    public String Index() {
        return "index";
    }

    /**
    * @Author chendaofei
    * @Description 跳转预警策略配置页面
    * @Date 9:47 2020/6/17
    **/
    @GetMapping("/earlywaring")
    public String EarlyWarning() {
        return "business/strategy/earlywarning";
    }
    /**
     * @Author chendaofei
     * @Description 打开预警策略新增页面
     * @Date 9:47 2020/6/17
     **/
    @GetMapping("/earlyup")
    public String Earlyup() {
        return "business/strategy/earlyup";
    }

    /**
     * @Author chendaofei
     * @Description 打开预警策略绑定页面
     * @Date 9:47 2020/6/17
     **/
    @GetMapping("/earlybind")
    public String Earlybind() {
        return "business/strategy/earlybind";
    }

    /**
     * @Author chendaofei
     * @Description 跳转告警策略配置页面
     * @Date 9:47 2020/6/17
     **/
    @GetMapping("/alarmwarning")
    public String Alarmwarning() {
        return "business/strategy/alarmwarning";
    }

    /**
     * @Author chendaofei
     * @Description 打开预警策略新增页面
     * @Date 9:47 2020/6/17
     **/
    @GetMapping("/alarmup")
    public String Alarmup() {
        return "business/strategy/alarmup";
    }

    /**
     * @Author chendaofei
     * @Description 打开预警策略绑定页面
     * @Date 9:47 2020/6/17
     **/
    @GetMapping("/alarmbind")
    public String Alarmbind() {
        return "business/strategy/alarmbind";
    }

    /**
     * @Author dhj
     * @Description 跳转技术监督
     * @Date 9:47 2020/6/19
     **/
    @GetMapping("/technical")
    public String Technical() {
        return "business/technical/technicalMange";
    }

    /**
     * @Author gbl
     * @Description 新建技术监督
     **/
    @GetMapping("/addtechnical")
    public String addTechnical() {
        return "business/technical/addTechnical";
    }
    
    /**
     * @Author gbl
     * @Description 技术监督详情
     **/
    @GetMapping("/technicaldetail")
    public String technicalDetail(HttpSession session,String supIndex) {
        session.setAttribute("supIndex", supIndex);
        return "business/technical/technicalDetail";
    }
    
    /**
     * @Author gbl
     * @Description 技术监督详情
     **/
    @GetMapping("/modtechnical")
    public String modTechnical(HttpSession session,String supIndex) {
        session.setAttribute("supIndex", supIndex);
        return "business/technical/modTechnical";
    }


    /**
     * @Author dhj
     * @Description 波形
     * @Date 9:47 2020/6/19
     **/
    @GetMapping("/waveform")
    public String Waveform() {
        return "business/technical/waveform";
    }

    /**
     * @Author dhj
     * @Description 报表
     * @Date 9:47 2020/6/19
     **/
    @GetMapping("/excel")
    public String excel(HttpSession session,String lineIndex,String time) {
        session.setAttribute("lineIndex", lineIndex);
        session.setAttribute("time", time);
        return "business/report/excel";
    }
    
  /**
     * 跳转404页面
     */
    @RequestMapping(value = "404")
    public String notFound() {
        return "business/error/404";
    }


    @PostMapping("getWebsocketURL")
    @ResponseBody
    public String getWebSocketURL() {
        String socketUrl=appConfig.getWebsocket();
        return socketUrl;
    }

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

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