package com.pqs9900.controller.user;

import com.njcn.enums.LogTypeEnum;
import com.njcn.mapper.user.WebInfoMapper;
import com.njcn.pojo.commons.HttpResult;
import com.njcn.service.log.UserLogDetailService;
import com.njcn.service.user.WebInfoService;
import com.njcn.utils.AppConfig;
import com.njcn.utils.PubUtils;
import com.njcn.utils.UserUtil;
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.security.auth.login.AccountException;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("webinfo")
public class WebInfoController {
    @Autowired
    private WebInfoService infoService;
    // 日志记录
    private static final Logger logger = LoggerFactory.getLogger(ManageListController.class);

    @Autowired
    private AppConfig appConfig;

    @Autowired
    WebInfoMapper wim;

    @Autowired
    UserUtil uu;
    @Autowired
    UserLogDetailService userLogDetailService;

    @RequestMapping(value = "getWebInfo", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getWebInfo(HttpServletRequest request) throws AccountException {
        HttpResult result = new HttpResult();
        List<List> users = infoService.getWebInfo();
        if (users.isEmpty()) {
            result.setCode(500);
            result.setMessage("没有获取到网站信息列表");
            userLogDetailService.getLog("查询网站信息", "失败", PubUtils.getIpAddr(request), LogTypeEnum.SYSTEM.toString(),0);
            logger.error("获取网站信息失败");
        } else {
            result.setCode(200);
            result.setBody(users);
            result.setMessage("获取网站信息列表成功");
            userLogDetailService.getLog("查询网站信息", "成功", PubUtils.getIpAddr(request), LogTypeEnum.SYSTEM.toString(),0);
            logger.info("获取网站信息成功");
        }
        return result;
    }
}
