package ${package}.${moduleName}.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import ${package}.${moduleName}.model.${className};
import ${package}.${moduleName}.service.I${className}Service;
import com.central.common.model.PageResult;
import com.central.common.model.Result;

/**
 * ${comments}
 *
 * @author ${author}
 * @date ${datetime}
 */
@Slf4j
@RestController
@RequestMapping("/${pathName}")
@Api(tags = "${comments}")
public class ${className}Controller {
    @Autowired
    private I${className}Service ${classname}Service;

    /**
     * 列表
     */
    @ApiOperation(value = "查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
    })
    @GetMapping
    public PageResult list(@RequestParam Map<String, Object> params) {
        return ${classname}Service.findList(params);
    }

    /**
     * 查询
     */
    @ApiOperation(value = "查询")
    @GetMapping("/{${pk.attrname}}")
    public Result findUserById(@PathVariable Long ${pk.attrname}) {
        ${className} model = ${classname}Service.getById(${pk.attrname});
        return Result.succeed(model, "查询成功");
    }

    /**
     * 新增or更新
     */
    @ApiOperation(value = "保存")
    @PostMapping
    public Result save(@RequestBody ${className} ${classname}) {
        ${classname}Service.saveOrUpdate(${classname});
        return Result.succeed("保存成功");
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long ${pk.attrname}) {
        ${classname}Service.removeById(${pk.attrname});
        return Result.succeed("删除成功");
    }
}
