package com.miaxis.pc.controller.school;

import com.miaxis.school.domain.SchoolEvaluate;
import com.miaxis.school.service.ISchoolEvaluateService;

import java.util.List;
import java.util.Arrays;
import io.swagger.annotations.*;
import com.miaxis.common.core.domain.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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 com.miaxis.common.utils.poi.ExcelUtil;
import com.miaxis.common.core.page.ResponsePageInfo;

/**
 * 【驾校评价】Controller
 *
 * @author wwl
 * @date 2021-01-15
 */
@RestController
@RequestMapping("/school/evaluate")
@Api(tags={"【pc-驾校评价】"})
public class PcSchoolEvaluateController extends BaseController{

    @Autowired
    private ISchoolEvaluateService schoolEvaluateService;

    /**
     * 查询驾校评价列表
     */
    @PreAuthorize("@ss.hasPermi('school:evaluate:list')")
    @GetMapping("/list")
    @ApiOperation("查询驾校评价列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<SchoolEvaluate> list(@ModelAttribute SchoolEvaluate schoolEvaluate){
        startPage();
        List<SchoolEvaluate> list = schoolEvaluateService.queryList(schoolEvaluate);
        return toResponsePageInfo(list);
    }

    /**
     * 导出驾校评价列表
     */
    @PreAuthorize("@ss.hasPermi('school:evaluate:export')")
    @Log(title = "驾校评价", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出驾校评价列表Excel")
    public Response<String> export(@ModelAttribute SchoolEvaluate schoolEvaluate){
        List<SchoolEvaluate> list = schoolEvaluateService.queryList(schoolEvaluate);
        ExcelUtil<SchoolEvaluate> util = new ExcelUtil<SchoolEvaluate>(SchoolEvaluate.class);
        return util.exportExcel(list, "evaluate");
    }

    /**
     * 获取驾校评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:evaluate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取驾校评价详细信息")
    public Response<SchoolEvaluate> getInfo(
            @ApiParam(name = "id", value = "驾校评价参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(schoolEvaluateService.getById(id));
    }

    /**
     * 新增驾校评价
     */
    @PreAuthorize("@ss.hasPermi('school:evaluate:add')")
    @Log(title = "驾校评价", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增驾校评价")
    public Response<Integer> add(@RequestBody SchoolEvaluate schoolEvaluate){
        return toResponse(schoolEvaluateService.save(schoolEvaluate) ? 1 : 0);
    }

    /**
     * 修改驾校评价
     */
    @PreAuthorize("@ss.hasPermi('school:evaluate:edit')")
    @Log(title = "驾校评价", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改驾校评价")
    public Response<Integer> edit(@RequestBody SchoolEvaluate schoolEvaluate){
        return toResponse(schoolEvaluateService.updateById(schoolEvaluate) ? 1 : 0);
    }

    /**
     * 删除驾校评价
     */
    @PreAuthorize("@ss.hasPermi('school:evaluate:remove')")
    @Log(title = "驾校评价", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除驾校评价")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "驾校评价ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(schoolEvaluateService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
