package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.dictionary.DicCompanyAuthResult;
import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.CompanyUserDataModel;
import com.lightinit.hsdataplatform.model.admin.CompanyUserListModel;
import com.lightinit.hsdataplatform.model.admin.CompanyUserSearchModel;
import com.lightinit.hsdataplatform.service.admin.IUserCompanyService;
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/usercompany_mgr")
public class UserCompanyMgrController {

    @Autowired
    private IUserCompanyService userCompanyService;
    @RequestMapping("/index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("/admin/usercompany_mgr/index");
        modelAndView.addObject("dicCompanyState", DicCompanyAuthResult.getInstance().getDicMap());
        return modelAndView;
    }

    @RequestMapping("list.action")
    public ModelAndView list(CompanyUserSearchModel inputModel, @RequestParam(defaultValue = "1") int  pageNo){
        ModelAndView modelAndView = new ModelAndView("admin/usercompany_mgr/list");
        BaseExample.Page pager = new BaseExample.Page(pageNo,10);
        inputModel.setPage(pager);
        List<CompanyUserListModel> outputModel=userCompanyService.queryList(inputModel);
        pager.setTotal(userCompanyService.queryCount(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/usercompany_mgr/detail");
        modelAndView.addObject("busiModel",userCompanyService.queryOne(id));
        return modelAndView;
    }

    @RequestMapping("auth.htm/{id}")
    public ModelAndView auth(@PathVariable Long id){
        ModelAndView modelAndView = new ModelAndView("admin/usercompany_mgr/auth");
        modelAndView.addObject("busiModel",userCompanyService.queryOne(id));
        return modelAndView;
    }

    @RequestMapping("auth.action")
    @ResponseBody
    public ResultState auth(CompanyUserDataModel inputModel,int param){
        ResultState resultState = userCompanyService.edit(inputModel, param);
        return resultState;
    }
}
