package ${fullPackage};

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
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 com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import ${_fullClass.convert};
import ${_fullClass.domain};
import ${_fullClass.query};
import ${_fullClass.service};
import ${_fullClass.vo};
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * ${functionName}Controller
 *
 * @author ${author}
 * @date ${datetime}
 */
@Api(description ="${functionName}接口列表")
@RestController
@RequestMapping("/${moduleName}/${className}")
public class ${_className.controller} extends BaseController {
    @Autowired
    private ${_className.service} service;
    @Autowired
    private ${_className.convert} convert;

    @ApiOperation("查询${functionName}列表")
    @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<${_className.domain}>> list(@RequestBody ${_className.query} query, Pageable page) {
        List<${_className.domain}> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("导出${functionName}列表")
    @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
    @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(${_className.query} query) {
        List<${ClassName}> list = service.selectList(query, null);
        ExcelUtil<${_className.vo}> util = new ExcelUtil<>(${_className.vo}.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "${functionName}数据"));
    }

    @ApiOperation("获取${functionName}详细信息")
    @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
    @GetMapping(value = "/{${pkColumn.javaField}}")
    public ResponseEntity<${ClassName}> getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) {
        return ResponseEntity.ok(service.selectBy${pkColumn.capJavaField}(${pkColumn.javaField}));
    }

    @ApiOperation("新增${functionName}")
    @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
    @Log(title = "${functionName}", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody ${ClassName} ${className}) {
        return ResponseEntity.ok(service.insert(${className}));
    }

    @ApiOperation("修改${functionName}")
    @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
    @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody ${ClassName} ${className}) {
        return ResponseEntity.ok(service.update(${className}));
    }

    @ApiOperation("删除${functionName}")
    @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
    @Log(title = "${functionName}", businessType = BusinessType.DELETE)
	@DeleteMapping("/{${pkColumn.javaField}s}")
    public ResponseEntity<Integer> remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) {
        return ResponseEntity.ok(service.deleteBy${pkColumn.capJavaField}s(${pkColumn.javaField}s));
    }
}
