package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.entity.UserPersonal;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.PersionalUserAuthListModel;
import com.lightinit.hsdataplatform.model.admin.PersionalUserSearchModel;
import com.lightinit.hsdataplatform.model.admin.RegisterUserStatisticsModel;
import com.lightinit.hsdataplatform.model.admin.UserRegisterListModel;
import com.lightinit.hsdataplatform.service.admin.IUserPersonalService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/admin/userpersonal_mgr")
public class UserPersonalMgrController {
    @Autowired
    private IUserPersonalService userPersonalService;

    /**
     * 实名认证页
     * @return
     */
    @RequestMapping("authUserIndex.htm")
    @ResponseBody
    public ModelAndView index(){
       ModelAndView modelAndView = new ModelAndView("admin/userpersonal_mgr/authUserIndex");
        return modelAndView;
    }
    /**
     * 查询
     * @return
     */
    @RequestMapping("authUserList.action")
    @ResponseBody
    public ModelAndView getAuthUserList(PersionalUserSearchModel inputModel, @RequestParam(defaultValue ="1") int pageNo){
        ModelAndView modelAndView = new ModelAndView("/admin/userpersonal_mgr/authUserList");
        BaseExample.Page pager = new BaseExample.Page(pageNo,10);
        inputModel.setPage(pager);
        List<PersionalUserAuthListModel> outputModel=userPersonalService.getAuthUserList(inputModel);
        pager.setTotal(userPersonalService.queryAuthUserCount(inputModel));
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }
    @RequestMapping("detail.htm/{id}")
    public ModelAndView detail(@PathVariable Long id){
        ModelAndView modelAndView = new ModelAndView("/admin/userpersonal_mgr/detail");
        modelAndView.addObject("busiModel",userPersonalService.queryOne(id));
        return modelAndView;
    }

    /**
     * 注册用户查询页
     *
     * @return
     */
    @RequestMapping("registerUserIndex.htm")
    public ModelAndView registerUserIndex() {
        ModelAndView modelAndView = new ModelAndView("/admin/userpersonal_mgr/registerUserIndex");
        return modelAndView;
    }


    @RequestMapping("registerUserList.action")
    @ResponseBody
    public ModelAndView registerUserList(String phone, @RequestParam(defaultValue = "1") int pageNo) {
        ModelAndView modelAndView = new ModelAndView("/admin/userpersonal_mgr/registerUserList");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List<UserRegisterListModel> outputModel = userPersonalService.getRegisterUserList(phone, pager);
        pager.setTotal(userPersonalService.queryRegisterUserCount(phone));
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager", pager);
        return modelAndView;
    }


    //按年统计注册用户数，最后给出总数
    @RequestMapping("registerUserStatisticsIndex.htm")
    public ModelAndView registerUserStatisticsIndex() {
        ModelAndView modelAndView = new ModelAndView("/admin/userpersonal_mgr/registerUserStatisticsIndex");
        return modelAndView;
    }


    @RequestMapping("registerUserStatistics.action")
    @ResponseBody
    public ModelAndView registerUserStatistics(){
        ModelAndView modelAndView = new ModelAndView("/admin/userpersonal_mgr/registerUserStatisticsList");
        List<RegisterUserStatisticsModel> list=userPersonalService.registerUserStatistics();
        modelAndView.addObject("list",list);
        return modelAndView;
    }

    //图表，折线，选择年份，按月统计注册用户数
    @RequestMapping("registerUserGraphIndex.htm")
    public ModelAndView registerUserGraphIndex() {
        ModelAndView modelAndView = new ModelAndView("/admin/userpersonal_mgr/registerUserGraphIndex");
        return modelAndView;
    }

    @RequestMapping("registerUserGraph.action")
    @ResponseBody
    public ResultState registerUserGraph(String year) {
        ResultState resultState=userPersonalService.registerUserGraph(year);
        return resultState;
    }
}
