package ${package.Controller};

import com.orion.lang.define.wrapper.DataGrid;
#if($meta.enableOperatorLog)
import com.orion.visor.framework.biz.operator.log.core.annotation.OperatorLog;
#end
import com.orion.visor.framework.common.validator.group.Page;
import com.orion.visor.framework.log.core.annotation.IgnoreLog;
import com.orion.visor.framework.log.core.enums.IgnoreLogMode;
import com.orion.visor.framework.web.core.annotation.RestWrapper;
import ${package.Service}.*;
#foreach($pkg in ${customModuleFilePackages})
import ${pkg}.*;
#end
#if(${superControllerClassPackage})
import ${superControllerClassPackage};
#end
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * $!{table.comment} api
 *
 * @author ${author}
 * @version ${version}
 * @since ${date}
 */
@Tag(name = "${package.ModuleName} - $!{table.comment}服务")
@Slf4j
@Validated
@RestWrapper
@RestController
@RequestMapping("/${package.ModuleName}/${typeHyphen}")
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
#if(${superControllerClass})
public class ${table.controllerName} extends ${superControllerClass} {
#else
public class ${table.controllerName} {
#end

    @Resource
    private ${type}Service ${typeLower}Service;

    #if($meta.enableOperatorLog)
    @OperatorLog(${type}OperatorType.CREATE)
    #end
    @PostMapping("/create")
    @Operation(summary = "${apiComment.create}")
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:create')")
    public Long create${type}(@Validated @RequestBody ${type}CreateRequest request) {
        return ${typeLower}Service.create${type}(request);
    }

    #if($meta.enableOperatorLog)
    @OperatorLog(${type}OperatorType.UPDATE)
    #end
    @PutMapping("/update")
    @Operation(summary = "${apiComment.updateById}")
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
    public Integer update${type}(@Validated @RequestBody ${type}UpdateRequest request) {
        return ${typeLower}Service.update${type}ById(request);
    }

    @IgnoreLog(IgnoreLogMode.RET)
    @GetMapping("/get")
    @Operation(summary = "${apiComment.getById}")
    @Parameter(name = "id", description = "id", required = true)
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
    public ${type}VO get${type}(@RequestParam("id") Long id) {
        return ${typeLower}Service.get${type}ById(id);
    }

    @IgnoreLog(IgnoreLogMode.RET)
    @GetMapping("/batch-get")
    @Operation(summary = "${apiComment.getByIdList}")
    @Parameter(name = "idList", description = "idList", required = true)
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
    public List<${type}VO> get${type}Batch(@RequestParam("idList") List<Long> idList) {
        return ${typeLower}Service.get${type}ByIdList(idList);
    }

    @IgnoreLog(IgnoreLogMode.RET)
    @PostMapping("/list")
    @Operation(summary = "${apiComment.queryList}")
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
    public List<${type}VO> get${type}List(@Validated @RequestBody ${type}QueryRequest request) {
        return ${typeLower}Service.get${type}List(request);
    }

    @IgnoreLog(IgnoreLogMode.RET)
    @PostMapping("/query")
    @Operation(summary = "${apiComment.queryPage}")
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
    public DataGrid<${type}VO> get${type}Page(@Validated(Page.class) @RequestBody ${type}QueryRequest request) {
        return ${typeLower}Service.get${type}Page(request);
    }

    #if($meta.enableOperatorLog)
    @OperatorLog(${type}OperatorType.DELETE)
    #end
    @DeleteMapping("/delete")
    @Operation(summary = "${apiComment.deleteById}")
    @Parameter(name = "id", description = "id", required = true)
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
    public Integer delete${type}(@RequestParam("id") Long id) {
        return ${typeLower}Service.delete${type}ById(id);
    }

    #if($meta.enableOperatorLog)
    @OperatorLog(${type}OperatorType.DELETE)
    #end
    @DeleteMapping("/batch-delete")
    @Operation(summary = "${apiComment.batchDelete}")
    @Parameter(name = "idList", description = "idList", required = true)
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
    public Integer batchDelete${type}(@RequestParam("idList") List<Long> idList) {
        return ${typeLower}Service.delete${type}ByIdList(idList);
    }
    #if($meta.enableExport)

    #if($meta.enableOperatorLog)
    @OperatorLog(${type}OperatorType.EXPORT)
    #end
    @PostMapping("/export")
    @Operation(summary = "${apiComment.export}")
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:export')")
    public void export${type}(@Validated @RequestBody ${type}QueryRequest request,
                              HttpServletResponse response) throws IOException {
        ${typeLower}Service.export${type}(request, response);
    }
    #end

}

