package ${package}.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import ${package}.entity.${className}Entity;
import ${package}.service.${className}Service;
import ${package}.utils.PageUtils;
import ${package}.utils.Query;
import ${package}.utils.R;

/**
 * ${comments}Controller
 *
 * @author ${author}
 * @email ${email}
 * @date ${datetime}
 */
@Controller
@RequestMapping("${pathName}")
public class ${className}Controller {
    @Autowired
    private ${className}Service ${classname}Service;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("${pathName}:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<${className}Entity> ${classname}List = ${classname}Service.queryList(query);
        int total = ${classname}Service.queryTotal(query);

        PageUtils pageUtil = new PageUtils(${classname}List, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{${pk.attrname}}")
    @RequiresPermissions("${pathName}:info")
    @ResponseBody
    public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}) {
        ${className}Entity ${classname} = ${classname}Service.queryObject(${pk.attrname});

        return R.ok().put("${classname}", ${classname});
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("${pathName}:save")
    @ResponseBody
    public R save(@RequestBody ${className}Entity ${classname}) {
        ${classname}Service.save(${classname});

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("${pathName}:update")
    @ResponseBody
    public R update(@RequestBody ${className}Entity ${classname}) {
        ${classname}Service.update(${classname});

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("${pathName}:delete")
    @ResponseBody
    public R delete(@RequestBody ${pk.attrType}[]${pk.attrname}s) {
        ${classname}Service.deleteBatch(${pk.attrname}s);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<${className}Entity> list = ${classname}Service.queryList(params);

        return R.ok().put("list", list);
    }
}
