package com.miaxis.app.controller.school;

import com.miaxis.app.school.domain.SchoolInfo;
import com.miaxis.app.school.dto.SchoolInfoDTO;
import com.miaxis.app.school.dto.SchoolInfoEvalDTO;
import com.miaxis.app.school.dto.SchoolInfoEvalVO;
import com.miaxis.app.school.dto.SchoolInfoVO;
import com.miaxis.app.school.service.ISchoolInfoService;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【驾校】Controller
 *
 * @author miaxis
 * @date 2020-12-24
 */
@RestController
@RequestMapping(Constants.OPEN_PREFIX+"/school/info")
@Api(tags={"【app-驾校】"})
public class SchoolInfoController extends BaseController{
    @Autowired
    private ISchoolInfoService schoolInfoService;

    /**
     * 查询驾校列表
     */
    //@PreAuthorize("@ss.hasPermi('school:info: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<SchoolInfo> list(@ModelAttribute SchoolInfo schoolInfo){
        startPage();
        List<SchoolInfo> list = schoolInfoService.selectSchoolInfoList(schoolInfo);
        return toResponsePageInfo(list);
    }

    /**
     * 查询驾校url列表
     */
    //@PreAuthorize("@ss.hasPermi('school:info:list')")
    @GetMapping("/urlList")
    @ApiOperation("查询驾校url列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<SchoolInfoVO> list(@ModelAttribute SchoolInfoDTO schoolInfoDTO){
        startPage();
        List<SchoolInfoVO> list = schoolInfoService.selectSchoolInfoUrlList(schoolInfoDTO);
        return toResponsePageInfo(list);
    }


    /**
     * 查询驾校信用列表
     */
    //@PreAuthorize("@ss.hasPermi('school:info:list')")
    @GetMapping("/evalList")
    @ApiOperation("查询驾校信用列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<SchoolInfoEvalVO> list(@ModelAttribute SchoolInfoEvalDTO schoolInfoEvalDTO){
        startPage();
        List<SchoolInfoEvalVO> list = schoolInfoService.selectSchoolInfoEvalList(schoolInfoEvalDTO);
        return toResponsePageInfo(list);
    }


    /**
     * 导出驾校列表
     */
   // @PreAuthorize("@ss.hasPermi('school:info:export')")
    @Log(title = "驾校", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出驾校列表Excel")
    public Response<String> export(@ModelAttribute SchoolInfo schoolInfo){
        List<SchoolInfo> list = schoolInfoService.selectSchoolInfoList(schoolInfo);
        ExcelUtil<SchoolInfo> util = new ExcelUtil<SchoolInfo>(SchoolInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取驾校详细信息
     */
    //@PreAuthorize("@ss.hasPermi('school:info:query')")
    @GetMapping(value = "/{inscode}")
    @ApiOperation("获取驾校详细信息")
    public Response<SchoolInfo> getInfo(
            @ApiParam(name = "inscode", value = "驾校参数", required = true)
            @PathVariable("inscode") String inscode
    ){
        return Response.success(schoolInfoService.selectSchoolInfoById(inscode));
    }

    /**
     * 新增驾校
     */
    //@PreAuthorize("@ss.hasPermi('school:info:add')")
    @Log(title = "驾校", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增驾校")
    public Response<Integer> add(@RequestBody SchoolInfo schoolInfo){
        return toResponse(schoolInfoService.insertSchoolInfo(schoolInfo));
    }

    /**
     * 修改驾校
     */
    //@PreAuthorize("@ss.hasPermi('school:info:edit')")
    @Log(title = "驾校", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改驾校")
    public Response<Integer> edit(@RequestBody SchoolInfo schoolInfo){
        return toResponse(schoolInfoService.updateSchoolInfo(schoolInfo));
    }

    /**
     * 删除驾校
     */
    //@PreAuthorize("@ss.hasPermi('school:info:remove')")
    @Log(title = "驾校", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{inscodes}")
    @ApiOperation("删除驾校")
    public  Response<Integer> remove(
            @ApiParam(name = "inscodes", value = "驾校ids参数", required = true)
            @PathVariable String[] inscodes
    ){
        return toResponse(schoolInfoService.deleteSchoolInfoByIds(inscodes));
    }
}
