package ${packageName}.controller;

import com.miaxis.common.constant.Constants;
import java.util.List;
import java.util.Arrays;
import io.swagger.annotations.*;
import com.miaxis.common.core.domain.Response;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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 org.springframework.web.bind.annotation.ModelAttribute;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.enums.BusinessTypeEnum;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
import com.miaxis.common.utils.poi.ExcelUtil;
#if($table.crud)
import com.miaxis.common.core.page.ResponsePageInfo;
#elseif($table.tree)
#end

/**
 * 【${functionName}】Controller
 *
 * @author ${author}
 * @date ${datetime}
 */
@RestController
@RequestMapping("/${moduleName}/${businessName}")
@Api(tags={"【app-${functionName}】"})
public class ${ClassName}Controller extends BaseController{
    @Autowired
    private I${ClassName}Service ${className}Service;

    /**
     * 查询${functionName}列表
     */
    //@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
    @GetMapping("/list")
    @ApiOperation("查询${functionName}列表")
#if($table.crud)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<${ClassName}> list(@ModelAttribute ${ClassName} ${className}){
        startPage();
        List<${ClassName}> list = ${className}Service.queryList(${className});
        return toResponsePageInfo(list);
    }
#elseif($table.tree)
    public Response<${ClassName}> list(@ModelAttribute ${ClassName} ${className}){
        List<${ClassName}> list = ${className}Service.queryList(${className});
        return Response.success(list);
    }
#end

    /**
     * 导出${functionName}列表
     */
   // @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
    @Log(title = "${functionName}", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出${functionName}列表Excel")
    public Response<String> export(@ModelAttribute ${ClassName} ${className}){
        List<${ClassName}> list = ${className}Service.queryList(${className});
        ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
        return util.exportExcel(list, "${businessName}");
    }

    /**
     * 获取${functionName}详细信息
     */
    //@PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
    @GetMapping(value = "/{${pkColumn.javaField}}")
    @ApiOperation("获取${functionName}详细信息")
    public Response<${ClassName}> getInfo(
            @ApiParam(name = "${pkColumn.javaField}", value = "${functionName}参数", required = true)
            @PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}
    ){
        return Response.success(${className}Service.getById(${pkColumn.javaField}));
    }

    /**
     * 新增${functionName}
     */
    //@PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
    @Log(title = "${functionName}", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增${functionName}")
    public Response<Integer> add(@RequestBody ${ClassName} ${className}){
        return toResponse(${className}Service.save(${className}) ? 1 : 0);
    }

    /**
     * 修改${functionName}
     */
    //@PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
    @Log(title = "${functionName}", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改${functionName}")
    public Response<Integer> edit(@RequestBody ${ClassName} ${className}){
        return toResponse(${className}Service.updateById(${className}) ? 1 : 0);
    }

    /**
     * 删除${functionName}
     */
    //@PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
    @Log(title = "${functionName}", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{${pkColumn.javaField}s}")
    @ApiOperation("删除${functionName}")
    public  Response<Integer> remove(
            @ApiParam(name = "${pkColumn.javaField}s", value = "${functionName}ids参数", required = true)
            @PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s
    ){
        return toResponse(${className}Service.removeByIds(Arrays.asList(${pkColumn.javaField}s)) ? 1 : 0);
    }
}
