package com.iformall.controller.basic;

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.WxGroup;
import com.iformall.service.WxGroupService;
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("wxGroup")
public class WxGroupController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxGroupService wxGroupService;

    @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 WxGroup wxGroup, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxGroupController::list");
        if (null == wxGroup) wxGroup = new WxGroup();
        final PageInfo<WxGroup> page = wxGroupService.listAsPage(wxGroup, pageNum, pageSize);
        return new ResultData(page);
    }

    @PostMapping("add")
    @SystemControllerLog(description = "集团-添加")
    public ResultData add(@RequestBody WxGroup wxGroup) {
        logger.debug("[" + getIpAddr() + "] WxGroupController::add");
        //Assert.notNull(wxGroup.getName(), "角色名不能为空");
        //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
        wxGroupService.saveOrUpdate(wxGroup);
        return new ResultData();
    }

    @PostMapping("update")
    @SystemControllerLog(description = "集团-更新")
    public ResultData update(@RequestBody WxGroup wxGroup) {
        logger.debug("[" + getIpAddr() + "] WxGroupController::update");
        wxGroupService.saveOrUpdate(wxGroup);
        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() + "] WxGroupController::delete");
        wxGroupService.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() + "] WxGroupController::findById");
        return new ResultData(Result.SUCCESS, "查询成功", wxGroupService.getById(id));
    }


}
