package ${packageName}.controller.base;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.dto.AjaxResult;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.${ClassName};
import com.younike.service.service.I${ClassName}Service;
#if($table.crud || $table.sub)
import com.younike.common.core.page.TableResult;
#elseif($table.tree)
#end

/**
 * ${functionName}Controller
 *
 * @author ${author}
 * @date ${datetime}
 */
@RestController
@RequestMapping("/${className}")
public class ${ClassName}Controller extends BaseController {
    @Autowired
    private I${ClassName}Service ${className}Service;

    /**
     * 查询${functionName}列表
     */
    @RequiresPermissions("${permissionPrefix}:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<${ClassName}> page) {

        return ${className}Service.page(page);
    }


    /**
     * 获取${functionName}详细信息
     */
    @RequiresPermissions("${permissionPrefix}:query")
    @GetMapping(value = "/{${pkColumn.javaField}}")
    public APIResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) {
        return ResultGenerator.getSuccessResult(${className}Service.getById(${pkColumn.javaField}));
    }

    /**
     * 新增${functionName}
     */
    @RequiresPermissions("${permissionPrefix}:add")
    @OpLog(title = "${functionName}", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody ${ClassName} ${className}) {
        return ResultGenerator.getSuccessResult(${className}Service.save(${className}));
    }

    /**
     * 修改${functionName}
     */
    @RequiresPermissions("${permissionPrefix}:edit")
    @OpLog(title = "${functionName}", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody ${ClassName} ${className}) {
        return ResultGenerator.getSuccessResult(${className}Service.updateById(${className}));
    }

    /**
     * 删除${functionName}
     */
    @RequiresPermissions("${permissionPrefix}:remove")
    @OpLog(title = "${functionName}", type = BusinessType.DELETE)
    @DeleteMapping("/{${pkColumn.javaField}s}")
    public APIResult remove(@PathVariable List<${pkColumn.javaType}> ${pkColumn.javaField}s) {
        return ResultGenerator.getSuccessResult(${className}Service.removeByIds(${pkColumn.javaField}s));
    }
}
