package com.xjrsoft.module.room.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.module.room.dto.DistributeRoomBedDto;
import com.xjrsoft.module.room.service.IRoomBedService;
import com.xjrsoft.module.room.vo.DistributeResultClassVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
* @title: 寝室床位
* @Author dzx
* @Date: 2023-12-27
* @Version 1.0
*/
@RestController
@RequestMapping("/room" + "/distributeRoomBed")
@Api(value = "/room"  + "/distributeRoomBed",tags = "分配床位")
@AllArgsConstructor
public class DistributeRoomBedController {


    private final IRoomBedService roomBedService;

    @PutMapping
    @ApiOperation(value = "修改寝室床位")
    @SaCheckPermission("roombed:edit")
    public RT<List<DistributeResultClassVo>> distributeRoomBed(@Valid @RequestBody DistributeRoomBedDto dto){
        Boolean result = roomBedService.distributeRoomBed(dto);
        List<DistributeResultClassVo> list = new ArrayList<>();
        if(result){
            list = roomBedService.getDistributeResult(dto);
            return RT.ok(list);
        }
        return RT.ok(list);
    }
}