package com.pqs9000.controller.user;
import com.njcn.mapper.user.ManageListMapper;
import com.njcn.pojo.commons.HttpResult;
import com.njcn.service.user.ManageListService;
import com.njcn.utils.AppConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping(value ="/manage")
public class ManageListController {

    @Autowired
    ManageListService mService;
    @Autowired
    ManageListMapper mlm;
    @Autowired
    private AppConfig appConfig;
    // 日志记录
    private static final Logger logger = LoggerFactory.getLogger(ManageListController.class);
    @RequestMapping(value = "getManage", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getManage(HttpServletRequest request) {
        HttpResult result = new HttpResult();
        List<List> users = mService.getManage();
        if (users.isEmpty()) {
            result.setCode(500);
            result.setMessage("没有获取到资源信息列表");
            logger.error("获取资源信息失败");
        } else {
            result.setCode(200);
            result.setBody(users);
            result.setMessage("获取资源信息列表成功");
            logger.info("获取资源信息成功");
        }
        return result;
    }

    @RequestMapping(value = "getBasemang", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getBasemang(HttpServletRequest request) {
        HttpResult result = new HttpResult();
        List<List> users = mService.getBasemang(appConfig.getSysTypeWt());
        if (users.isEmpty()) {
            result.setCode(500);
            result.setMessage("没有获取到资源信息列表");
            logger.error("获取资源信息失败");
        } else {
            result.setCode(200);
            result.setBody(users);
            result.setMessage("获取资源信息列表成功");
            logger.info("获取资源信息成功");
        }
        return result;
    }
    @RequestMapping(value = "getReport", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getReport(HttpServletRequest request) {
        HttpResult result = new HttpResult();
        List<List> users = mService.getReport(appConfig.getSysTypeWt());
        if (users.isEmpty()) {
            result.setCode(500);
            result.setMessage("没有获取到资源信息列表");
            logger.error("获取资源信息失败");
        } else {
            result.setCode(200);
            result.setBody(users);
            result.setMessage("获取资源信息列表成功");
            logger.info("获取资源信息成功");
        }
        return result;
    }
    @RequestMapping(value = "getSub", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getSub(HttpServletRequest request) {
        HttpResult result = new HttpResult();
        List<List> users = mService.getSub(appConfig.getSysTypeWt());
        if (users.isEmpty()) {
            result.setCode(500);
            result.setMessage("没有获取到资源信息列表");
            logger.error("获取资源信息失败");
        } else {
            result.setCode(200);
            result.setBody(users);
            result.setMessage("获取资源信息列表成功");
            logger.info("获取资源信息成功");
        }
        return result;
    }
}
