package com.srs.web.controller.dormitory;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.DmsDormitoryFloor;
import com.srs.dormitory.domain.Dto.FloorDto;
import com.srs.dormitory.service.IDmsDormitoryFloorService;
import com.srs.dormitory.utils.DmsOperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

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


    @ApiOperation("所有楼层列表")
    @GetMapping("/listAllFloor")
    public AjaxResult listAllFloor(){
        List<DmsDormitoryFloor> list = dmsDormitoryFloorService.list();
        return AjaxResult.success(list);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-floor:list')")
    @ApiOperation("楼层列表")
    @PostMapping("/list")
    public TableDataInfo dmsDormitoryFloorList(@RequestParam(required = false) Long buildingId){
        startPage();
        List<Map<String,Object>> list = dmsDormitoryFloorService.getDormitoryFloorList(buildingId);
        return getDataTable(list);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-floor:query')")
    @ApiOperation("楼层详情")
    @GetMapping("/{id}")
    public AjaxResult getDmsDormitoryFloorInfo(@ApiParam(value = "楼层ID") @PathVariable Long id){
        return dmsDormitoryFloorService.getDmsDormitoryFloorInfo(id);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-floor:add')")
    @ApiOperation(value = "添加宿舍楼层",notes = "id不用填写",response = FloorDto.class)
    @PostMapping("/add")
    public AjaxResult addDmsDormitoryFloor(@RequestBody FloorDto floorDto){
        return dmsDormitoryFloorService.addDmsDormitoryFloor(floorDto,getUsername());
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-floor:edit')")
    @ApiOperation(value = "修改宿舍楼层信息",response = FloorDto.class)
    @PostMapping("/update")
    public AjaxResult updateDmsDormitoryFloor(@RequestBody FloorDto floorDto){
        return dmsDormitoryFloorService.updateDmsDormitoryFloor(floorDto,getUsername());
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-floor:remove')")
    @ApiOperation("删除宿舍楼层")
    @PostMapping("/delete/{id}")
    public AjaxResult deleteDmsDormitoryFloor(@PathVariable Long id){
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return dmsDormitoryFloorService.batchDeleteDmsDormitoryFloor(ids);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-floor:remove')")
    @ApiOperation(value = "批量删除宿舍楼层")
    @PostMapping("/delete")
    public AjaxResult batchDeleteDmsDormitoryFloor(@RequestBody List<Long> ids){
        return dmsDormitoryFloorService.batchDeleteDmsDormitoryFloor(ids);
    }

}
