package ${packageName}.controller;

import com.qiaoba.common.base.result.AjaxResult;
import com.qiaoba.common.database.entity.PageQuery;
import com.qiaoba.common.database.entity.TableDataInfo;
#if($docFlag)
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
#end
#if($excelFlag)
import javax.servlet.http.HttpServletResponse;
import com.qiaoba.common.poi.util.ExcelUtil;
import ${packageName}.entity.template.${ClassName}Export;
#end
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import ${packageName}.entity.${ClassName};
import ${packageName}.entity.dto.${ClassName}Dto;
import ${packageName}.entity.param.${ClassName}Param;
import ${packageName}.service.${ClassName}Service;


/**
 * ${functionName} Web层
 *
 * @author ${author}
 * @version 1.0
 * @since ${datetime}
 */
@RestController
@RequestMapping("/${moduleName}/${businessName}")
@RequiredArgsConstructor
#if($docFlag)
@Tag(name = "${functionName}管理")
#end
public class ${ClassName}Controller {

    private final ${ClassName}Service ${className}Service;

    #if($docFlag)
    @Operation(summary = "获取列表")
    #else
    /**
    * 获取列表
    */
    #end
    @PreAuthorize("hasAuthority('${permissionPrefix}:list')")
    @GetMapping("/list")
    public TableDataInfo<${ClassName}> list(${ClassName}Param param, PageQuery pageQuery) {
        return ${className}Service.selectPageList(param, pageQuery);
    }

    #if($docFlag)
    @Operation(summary = "获取详情")
    #else
    /**
    * 获取详情
    */
    #end
    @PreAuthorize("hasAuthority('${permissionPrefix}:query')")
    @GetMapping(value = "/{${pkColumn.javaField}}")
    public AjaxResult getInfo(@PathVariable String ${pkColumn.javaField}) {
        return AjaxResult.success(${className}Service.selectById(${pkColumn.javaField}, false));
    }

    #if($docFlag)
    @Operation(summary = "新增${functionName}")
    #else
    /**
    * 新增${functionName}
    */
    #end
    @PreAuthorize("hasAuthority('${permissionPrefix}:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ${ClassName}Dto dto) {
        return AjaxResult.toAjax(${className}Service.insert(dto));

    }

    #if($docFlag)
    @Operation(summary = "修改${functionName}")
    #else
    /**
     * 修改${functionName}
     */
    #end
    @PreAuthorize("hasAuthority('${permissionPrefix}:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ${ClassName}Dto dto) {
        return AjaxResult.toAjax(${className}Service.updateById(dto));

    }

    #if($docFlag)
    @Operation(summary = "删除${functionName}")
    #else
    /**
     * 删除${functionName}
     */
    #end
    @PreAuthorize("hasAuthority('${permissionPrefix}:remove')")
    @DeleteMapping("/{${pkColumn.javaField}s}")
    public AjaxResult remove(@PathVariable List<String> ${pkColumn.javaField}s) {
        return AjaxResult.toAjax(${className}Service.deleteByIds(${pkColumn.javaField}s));
    }

    #if($excelFlag)
    #if($docFlag)
    @Operation(summary = "导出${functionName}")
    #else
    /**
     * 导出${functionName}
     */
    #end
    @PreAuthorize("hasAuthority('${permissionPrefix}:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ${ClassName}Param param) {
        List<${ClassName}> list = ${className}Service.selectList(param);
        ExcelUtil.exportExcel(list, ${ClassName}Export.class, "${functionName}数据", response);
    }

    #end
}
