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.common.utils.poi.ExcelUtil;
import com.miaxis.school.domain.SchoolRegion;
import com.miaxis.school.service.ISchoolRegionService;
import com.miaxis.school.vo.SchoolRegionPcVO;
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;

/**
 * 【场地管理】Controller
 *
 * @author wwl
 * @date 2021-01-19
 */
@RestController
@RequestMapping("/school/region")
@Api(tags={"【app-场地管理】"})
public class PcSchoolRegionController extends BaseController{
    @Autowired
    private ISchoolRegionService schoolRegionService;

    /**
     * pc查询场地管理列表
     */
    @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<SchoolRegionPcVO> list(@ModelAttribute SchoolRegion schoolRegion){
        startPage();
        List<SchoolRegionPcVO> list = schoolRegionService.queryRegionList(schoolRegion);
        return toResponsePageInfo(list);
    }


    /**
     * 获取场地管理详细信息
     */
    @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.getById(id));
    }

    /**
     * 新增场地管理
     */
    @PreAuthorize("@ss.hasPermi('school:region:add')")
    @Log(title = "场地管理", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增场地管理")
    public Response<Integer> add(@RequestBody SchoolRegion schoolRegion){
        return toResponse(schoolRegionService.save(schoolRegion) ? 1 : 0);
    }

    /**
     * 修改场地管理
     */
    @PreAuthorize("@ss.hasPermi('school:region:edit')")
    @Log(title = "场地管理", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改场地管理")
    public Response<Integer> edit(@RequestBody SchoolRegion schoolRegion){
        return toResponse(schoolRegionService.updateById(schoolRegion) ? 1 : 0);
    }

    /**
     * 删除场地管理
     */
    @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.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
