package com.miaxis.pc.controller.school;

import com.miaxis.school.domain.SchoolClassType;
import com.miaxis.school.dto.SchoolClassTypePcDTO;
import com.miaxis.school.service.ISchoolClassTypeService;
import com.miaxis.common.annotation.Log;
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 com.miaxis.school.vo.SchoolClassTypePcVO;
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.Arrays;
import java.util.List;


/**
 * 【pc驾校班型】Controller
 *
 * @author wwl
 * @date 2021-01-15
 */
@RestController
@RequestMapping("/school/classType")
@Api(tags={"【pc-驾校班型】"})
public class PcSchoolClassTypeController extends BaseController{

    @Autowired
    private ISchoolClassTypeService schoolClassTypeService;

    /**
     * 查询驾校班型列表
     */
    @PreAuthorize("@ss.hasPermi('school:classType: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<SchoolClassTypePcVO> list(@ModelAttribute SchoolClassTypePcDTO schoolClassTypePcDTO){
        startPage();
        List<SchoolClassTypePcVO> list = schoolClassTypeService.queryList(schoolClassTypePcDTO);
        return toResponsePageInfo(list);
    }


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

    /**
     * 新增驾校班型
     */
    @PreAuthorize("@ss.hasPermi('school:classType:add')")
    @Log(title = "驾校班型", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增驾校班型")
    public Response<Integer> add(@RequestBody SchoolClassType schoolClassType){
        return toResponse(schoolClassTypeService.save(schoolClassType) ? 1 : 0);
    }

    /**
     * 修改驾校班型
     */
    @PreAuthorize("@ss.hasPermi('school:classType:edit')")
    @Log(title = "驾校班型", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改驾校班型")
    public Response<Integer> edit(@RequestBody SchoolClassType schoolClassType){
        return toResponse(schoolClassTypeService.updateById(schoolClassType) ? 1 : 0);
    }

    /**
     * 删除驾校班型
     */
    @PreAuthorize("@ss.hasPermi('school:class:type: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(schoolClassTypeService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
