package com.miaxis.pc.controller.school;

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.school.domain.SchoolInfo;
import com.miaxis.school.dto.SchoolInfoPcDTO;
import com.miaxis.school.service.ISchoolInfoService;
import com.miaxis.school.vo.SchoolInfoDetailPcVO;
import com.miaxis.school.vo.SchoolInfoPcVO;
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 wwl
 * @date 2021-01-18
 */
@RestController
@RequestMapping("/school/info")
@Api(tags={"【pc-驾校】"})
public class PcSchoolInfoController 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<SchoolInfoPcVO> list(@ModelAttribute SchoolInfoPcDTO schoolInfoPcDTO){
        startPage();
        List<SchoolInfoPcVO> list = schoolInfoService.queryList(schoolInfoPcDTO);
        return toResponsePageInfo(list);
    }


    /**
     * 获取驾校详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:info:query')")
    @GetMapping(value = "/{inscode}")
    @ApiOperation("获取驾校详细信息")
    public Response<SchoolInfoDetailPcVO> getSchoolInfoDetail(
            @ApiParam(name = "inscode", value = "驾校全国统一编号", required = true)
            @PathVariable("inscode") String inscode
    ){
        return Response.success(schoolInfoService.getSchoolInfoDetail(inscode));
    }

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

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

    /**
     * 删除驾校(逻辑删除)
     */
    @PreAuthorize("@ss.hasPermi('school:info:remove')")
    @Log(title = "驾校", businessType = BusinessTypeEnum.UPDATE)
	@PostMapping("/{inscodes}")
    @ApiOperation("删除驾校(逻辑删除)")
    public  Response<Integer> updateByInscode(
            @ApiParam(name = "inscodes", value = "驾校全国统一编号集合参数", required = true)
            @PathVariable String[] inscodes
    ){
        return toResponse(schoolInfoService.updateByInscode(inscodes) ? 1 : 0);
    }
}
