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.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import io.swagger.annotations.ApiOperation;


import ${package}.domain.${className}DO;
import ${package}.service.${className}Service;
import com.java2nb.common.utils.PageBean;
import com.java2nb.common.utils.Query;
import com.java2nb.common.utils.R;

/**
 * ${comments}
 *
 * @author ${author}
 * @email ${email}
 * @date ${datetime}
 */

@Controller
@RequestMapping("/${pathName}/${classname}")
public class ${className}Controller {
    @Autowired
    private ${className}Service ${classname}Service;

    @GetMapping()
    @RequiresPermissions("${pathName}:${classname}:${classname}")
    String ${className}() {
        return "${pathName}/${classname}/${classname}";
    }

    @ApiOperation(value = "获取${comments}列表", notes = "获取${comments}列表")
    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("${pathName}:${classname}:${classname}")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<${className}DO> ${classname}List = ${classname}Service.list(query);
        int total = ${classname}Service.count(query);
        PageBean pageBean = new PageBean(${classname}List, total);
        return R.ok().put("data", pageBean);
    }

    @ApiOperation(value = "新增${comments}页面", notes = "新增${comments}页面")
    @GetMapping("/add")
    @RequiresPermissions("${pathName}:${classname}:add")
    String add() {
        return "${pathName}/${classname}/add";
    }

    @ApiOperation(value = "修改${comments}页面", notes = "修改${comments}页面")
    @GetMapping("/edit/{${pk.attrname}}")
    @RequiresPermissions("${pathName}:${classname}:edit")
    String edit(@PathVariable("${pk.attrname}") ${pk.javaType} ${pk.attrname}, Model model) {
            ${className}DO ${classname} = ${classname}Service.get(${pk.attrname});
        model.addAttribute("${classname}", ${classname});
        return "${pathName}/${classname}/edit";
    }

    @ApiOperation(value = "查看${comments}页面", notes = "查看${comments}页面")
    @GetMapping("/detail/{${pk.attrname}}")
    @RequiresPermissions("${pathName}:${classname}:detail")
    String detail(@PathVariable("${pk.attrname}") ${pk.javaType} ${pk.attrname}, Model model) {
			${className}DO ${classname} = ${classname}Service.get(${pk.attrname});
        model.addAttribute("${classname}", ${classname});
        return "${pathName}/${classname}/detail";
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增${comments}", notes = "新增${comments}")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("${pathName}:${classname}:add")
    public R save( ${className}DO ${classname}) {
        if (${classname}Service.save(${classname}) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改${comments}", notes = "修改${comments}")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("${pathName}:${classname}:edit")
    public R update( ${className}DO ${classname}) {
            ${classname}Service.update(${classname});
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除${comments}", notes = "删除${comments}")
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("${pathName}:${classname}:remove")
    public R remove( ${pk.javaType} ${pk.attrname}) {
        if (${classname}Service.remove(${pk.attrname}) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "批量删除${comments}", notes = "批量删除${comments}")
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("${pathName}:${classname}:batchRemove")
    public R remove(@RequestParam("ids[]") ${pk.javaType}[] ${pk.attrname}s) {
            ${classname}Service.batchRemove(${pk.attrname}s);
        return R.ok();
    }

}
