package com.imdroid.beidou.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imdroid.beidou.service.CommonExcelService;
import com.imdroid.secapi.dto.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 消息摘要 控制器
 */
@Controller
@RequiredArgsConstructor
public class GnssMsgController extends BasicController implements CommonExcelService<GnssMsg, GnssMsg> {

    private final GnssMsgMapper msgMapper;

    public static final Map<Integer, String> msgTypeMap = new HashMap<>();

    @PostConstruct
    public static void init() {
        msgTypeMap.put(0xd3f0,"自检消息");
        msgTypeMap.put(0xd3f2,"休眠消息");
        msgTypeMap.put(0xd310,"GNSS配置");
        msgTypeMap.put(0xd311,"工作时间配置");
        msgTypeMap.put(0xd312,"单片机配置");
        msgTypeMap.put(0xd313,"DEBUG");
        msgTypeMap.put(0xd31A,"DTU配置");
        msgTypeMap.put(0xd342,"断点续传");
    }
    /**** 推送页面  *****/
    @RequestMapping("/page/gnss_msg")
    public String gnssMsg(Model m, HttpSession session) {
        initModel(m, session);
        m.addAttribute("type_map", msgTypeMap);
        return "/page/gnss_msg";
    }


    /**** 推送数据  *****/
    @RequestMapping("/gnss/msg/list_all")
    @ResponseBody
    public JSONObject listMsg(HttpSession session, Integer page, Integer limit, String searchParams) {
        return this.pageList(session, page, limit, searchParams);
    }

    /**
     * 导出excel
     *
     * @param session      HttpSession
     * @param request HttpServletRequest
     * @param response     HttpServletResponse
     * @throws Exception
     */
    @RequestMapping("/gnss/msg/export")
    @ResponseBody
    public void exportData(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws Exception {
        this.export(session, request, response);
    }

    /**
     * 获取实体类的class
     *
     * @return 实体类的class
     */
    @Override
    public Class<GnssMsg> getEntityClass() {
        return GnssMsg.class;
    }

    /**
     * 获取实体类对应的mybatis mapper
     *
     * @return 实体类对应的mybatis mapper
     */
    @Override
    public BaseMapper<GnssMsg> getMapper() {
        return msgMapper;
    }
}
