/*
 * Copyright (c) 2023 - present Dromara, All rights reserved.
 *
 *   https://visor.dromara.org
 *   https://visor.dromara.org.cn
 *   https://visor.orionsec.cn
 *
 * Members:
 *   Jiahang Li - ljh1553488six@139.com - author
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ${package.Controller};

import cn.orionsec.kit.lang.define.wrapper.DataGrid;
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;
#if($meta.enableOperatorLog)
import org.dromara.visor.framework.biz.operator.log.core.annotation.OperatorLog;
#end
import org.dromara.visor.framework.common.validator.group.Page;
import org.dromara.visor.framework.log.core.annotation.IgnoreLog;
#if($meta.enableDemoApi)
import org.dromara.visor.framework.web.core.annotation.DemoDisableApi;
#end
import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
import ${package.Service}.*;
#foreach($pkg in ${customModuleFilePackages})
import ${pkg}.*;
#end
#if(${superControllerClassPackage})
import ${superControllerClassPackage};
#end
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}")
#if(${superControllerClass})
public class ${table.controllerName} extends ${superControllerClass} {
#else
public class ${table.controllerName} {
#end

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

    #if($meta.enableDemoApi)
    @DemoDisableApi
    #end
    #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.enableDemoApi)
    @DemoDisableApi
    #end
    #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);
    }

    @PostMapping("/count")
    @Operation(summary = "${apiComment.queryCount}")
    @PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
    public Long get${type}Count(@Validated @RequestBody ${type}QueryRequest request) {
        return ${typeLower}Service.get${type}Count(request);
    }

    #if($meta.enableDemoApi)
    @DemoDisableApi
    #end
    #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.enableDemoApi)
    @DemoDisableApi
    #end
    #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);
    }

}

