package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.entity.SmsSwitch;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.PersionalUserAuthListModel;
import com.lightinit.hsdataplatform.model.admin.PersionalUserSearchModel;
import com.lightinit.hsdataplatform.service.admin.ISmsSwitchService;
import org.apache.commons.lang.StringUtils;
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;

/**
 * @Author: sunxiang
 * @Date: 2019/3/4 18:13
 * @Description:
 **/
@Controller
@RequestMapping("/admin/smsswitch")
public class SmsSwitchController {

    @Autowired
    private ISmsSwitchService smsSwitchService;
    @RequestMapping("smsswitch.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("admin/sms/index");
        return modelAndView;
    }

    //列表
    @RequestMapping("smsswitchList.action")
    @ResponseBody
    public ModelAndView getSmsSwitchList(@RequestParam(defaultValue ="1") int pageNo){
        ModelAndView modelAndView = new ModelAndView("admin/sms/list");
        BaseExample.Page pager = new BaseExample.Page(pageNo,10);
        List<SmsSwitch> outputModel=smsSwitchService.getSmsSwitchList(pager);
        pager.setTotal(smsSwitchService.querySmsSwitchCount());
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }

    //增
    @RequestMapping("add.action")
    public String add(SmsSwitch inputModel){
        if(StringUtils.isEmpty(inputModel.getFuncCode())){
            return "redirect:smsswitch.htm";
        }
        smsSwitchService.add(inputModel);
        return "redirect:smsswitch.htm";
    }
    //删
    @RequestMapping("delete.action/{id}")
    @ResponseBody
    public ResultState deleteById(@PathVariable long id){
        ResultState resultState = smsSwitchService.deleteById(id);
        return resultState;
    }
    //详情
    @RequestMapping("detail.htm/{id}")
    public ModelAndView  detail(@PathVariable Long id){
        ModelAndView modelAndView = new ModelAndView("admin/sms/detail");
        SmsSwitch smsSwitch=smsSwitchService.querySmsSwitchById(id);
        modelAndView.addObject("smsSwitch",smsSwitch);
        return modelAndView;
    }

    @RequestMapping("update.action")
    public String updateById(SmsSwitch inputModel){
        smsSwitchService.updateById(inputModel);
        return "redirect:smsswitch.htm";
    }
}
