package com.miaxis.app.controller.school;

import com.miaxis.app.school.domain.SchoolRegion;
import com.miaxis.app.school.dto.SchoolRegionDTO;
import com.miaxis.app.school.dto.SchoolRegionVO;
import com.miaxis.app.school.service.ISchoolRegionService;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【驾校训练场】Controller
 *
 * @author zhangbin
 * @date 2020-12-28
 */
@RestController
@RequestMapping(Constants.OPEN_PREFIX+"/school/region")
@Api(tags={"【app-驾校训练场】"})
public class SchoolRegionController extends BaseController{
    @Autowired
    private ISchoolRegionService schoolRegionService;

    /**
     * 查询驾校训练场列表
     */
    @PreAuthorize("@ss.hasPermi('school:region: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<SchoolRegion> list(@ModelAttribute SchoolRegion schoolRegion){
        startPage();
        List<SchoolRegion> list = schoolRegionService.selectSchoolRegionList(schoolRegion);
        return toResponsePageInfo(list);
    }

    /**
     * 查询驾校训练场列表(图片距离)
     */
    @GetMapping("/urllist")
    @ApiOperation("查询驾校训练场列表(图片距离)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<SchoolRegionVO> list(@ModelAttribute SchoolRegionDTO schoolRegionDTO){
        startPage();
        List<SchoolRegionVO> list = schoolRegionService.selectSchoolRegionUrlList(schoolRegionDTO);
        return toResponsePageInfo(list);
    }


    /**
     * 导出驾校训练场列表
     */
   // @PreAuthorize("@ss.hasPermi('school:region:export')")
    @Log(title = "驾校训练场", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出驾校训练场列表Excel")
    public Response<String> export(@ModelAttribute SchoolRegion schoolRegion){
        List<SchoolRegion> list = schoolRegionService.selectSchoolRegionList(schoolRegion);
        ExcelUtil<SchoolRegion> util = new ExcelUtil<SchoolRegion>(SchoolRegion.class);
        return util.exportExcel(list, "region");
    }

    /**
     * 获取驾校训练场详细信息
     */
    //@PreAuthorize("@ss.hasPermi('school:region:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取驾校训练场详细信息")
    public Response<SchoolRegion> getInfo(
            @ApiParam(name = "id", value = "驾校训练场参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(schoolRegionService.selectSchoolRegionById(id));
    }

    /**
     * 新增驾校训练场
     */
    //@PreAuthorize("@ss.hasPermi('school:region:add')")
    @Log(title = "驾校训练场", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增驾校训练场")
    public Response<Integer> add(@RequestBody SchoolRegion schoolRegion){
        return toResponse(schoolRegionService.insertSchoolRegion(schoolRegion));
    }

    /**
     * 修改驾校训练场
     */
    //@PreAuthorize("@ss.hasPermi('school:region:edit')")
    @Log(title = "驾校训练场", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改驾校训练场")
    public Response<Integer> edit(@RequestBody SchoolRegion schoolRegion){
        return toResponse(schoolRegionService.updateSchoolRegion(schoolRegion));
    }

    /**
     * 删除驾校训练场
     */
    //@PreAuthorize("@ss.hasPermi('school:region: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(schoolRegionService.deleteSchoolRegionByIds(ids));
    }
}
