package com.iformall.controller.msg;

import com.github.pagehelper.PageInfo;
import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.po.WxMsgValidationcodeModel;
import com.iformall.service.WxMsgValidationcodeModelService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wxMsgValidationcodeModel")
public class WxMsgValidationcodeModelController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxMsgValidationcodeModelService wxMsgValidationcodeModelService;

    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    @SystemControllerLog(description = "消息验证模板-列表")
    public ResultData list(@ModelAttribute WxMsgValidationcodeModel wxMsgValidationcodeModel, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxMsgValidationcodeModelController::list");
        if (null == wxMsgValidationcodeModel) wxMsgValidationcodeModel = new WxMsgValidationcodeModel();
        wxMsgValidationcodeModel.setTenantId(getTenantId());
        final PageInfo<WxMsgValidationcodeModel> page = wxMsgValidationcodeModelService.listAsPage(wxMsgValidationcodeModel, pageNum, pageSize);
        return new ResultData(page);
    }

    @PostMapping("add")
    @SystemControllerLog(description = "消息验证模板-添加")
    public ResultData add(@RequestBody WxMsgValidationcodeModel wxMsgValidationcodeModel) {
        logger.debug("[" + getIpAddr() + "] WxMsgValidationcodeModelController::add");
        //Assert.notNull(wxMsgValidationcodeModel.getName(), "角色名不能为空");
        //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
        wxMsgValidationcodeModel.setTenantId(getTenantId());
        return wxMsgValidationcodeModelService.saveOrUpdate(wxMsgValidationcodeModel);
    }

    @PostMapping("update")
    @SystemControllerLog(description = "消息验证模板-更新")
    public ResultData update(@RequestBody WxMsgValidationcodeModel wxMsgValidationcodeModel) {
        logger.debug("[" + getIpAddr() + "] WxMsgValidationcodeModelController::update");
        wxMsgValidationcodeModelService.saveOrUpdate(wxMsgValidationcodeModel);
        return new ResultData();
    }

    @GetMapping("/del")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true)
    @SystemControllerLog(description = "消息验证模板-删除")
    public ResultData delete(String id) {
        logger.debug("[" + getIpAddr() + "] WxMsgValidationcodeModelController::delete");
        wxMsgValidationcodeModelService.deleteById(id);
        return new ResultData(Result.SUCCESS, "删除成功", null);
    }

    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true)
    @SystemControllerLog(description = "消息验证模板-查询")
    public ResultData findById(String id) {
        logger.debug("[" + getIpAddr() + "] WxMsgValidationcodeModelController::findById");
        return new ResultData(Result.SUCCESS, "查询成功", wxMsgValidationcodeModelService.getById(id));
    }


}
