package com.srs.web.controller.dormitory;

import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.dormitory.domain.Dto.AddBuildingDto;
import com.srs.dormitory.domain.Dto.BuildingDto;
import com.srs.dormitory.service.IDmsDormitoryBuildingService;
import com.srs.dormitory.utils.DmsOperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 宿舍楼表 前端控制器
 * </p>
 *
 * @author 猪油骨
 * @since 2023-07-14
 */
@Api(tags = "宿舍楼管理")
@RestController
@RequestMapping("/dormitory/dms-dormitory-building")
public class DmsDormitoryBuildingController extends BaseController {
    @Autowired
    private IDmsDormitoryBuildingService dmsDormitoryBuildingService;

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-building:add')")
    @ApiOperation(value = "添加宿舍楼",notes = "根据填写的单元数和楼层数自动添加单元和楼层",response = AddBuildingDto.class)
    @PostMapping("/add")
    public AjaxResult addDmsDormitoryBuilding(@RequestBody @Validated AddBuildingDto buildingDto){
        return dmsDormitoryBuildingService.addDmsDormitoryBuilding(buildingDto,getUsername());
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-building:query')")
    @ApiOperation("查看宿舍楼详细信息")
    @GetMapping("/{id}")
    public AjaxResult dmsDormitoryBuilding(@PathVariable Long id){
        return dmsDormitoryBuildingService.dmsDormitoryBuilding(id);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-building:list')")
    @ApiOperation(value = "宿舍楼信息列表",notes = "只需要传递parkId园区ID,不传则显示所有宿舍楼")
    @PostMapping("/list")
    public TableDataInfo DmsDormitoryBuildingList(@RequestBody BuildingDto buildingDto){
        startPage();
        return getDataTable(dmsDormitoryBuildingService.getDmsDormitoryBuildingList(buildingDto));
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-building:edit')")
    @ApiOperation(value = "修改宿舍楼信息")
    @PostMapping("/update")
    public AjaxResult updateDmsDormitoryBuilding(@RequestBody BuildingDto buildingDto){
        return dmsDormitoryBuildingService.updateDmsDormitoryBuilding(buildingDto,getUsername());
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-building:remove')")
    @ApiOperation("删除宿舍楼")
    @PostMapping("/delete/{id}")
    public AjaxResult deleteDmsDormitoryBuilding(@PathVariable Long id){
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return dmsDormitoryBuildingService.batchDeleteDmsDormitoryBuilding(ids);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-building:remove')")
    @ApiOperation(value = "批量删除宿舍楼")
    @PostMapping("/delete")
    public AjaxResult batchDeleteDmsDormitoryBuilding(@RequestBody List<Long> ids){
        return dmsDormitoryBuildingService.batchDeleteDmsDormitoryBuilding(ids);
    }
}
