package com.srs.web.controller.dormitory;

import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.dormitory.domain.Dto.BedDto;
import com.srs.dormitory.service.IDmsDormitoryBedService;
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.List;

/**
 * <p>
 * 宿舍床位表 前端控制器
 * </p>
 *
 * @author 猪油骨
 * @since 2023-07-14
 */
@Api(tags = "床位信息")
@RestController
@RequestMapping("/dormitory/dms-dormitory-bed")
public class DmsDormitoryBedController extends BaseController {
    @Autowired
    private IDmsDormitoryBedService dmsDormitoryBedService;


    /***
     * 根据宿舍id查询床位信息
     * @author zhy
     * @date 2023-08-15 10:41:18
     * @return
     **/
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-bed:list')")
    @ApiOperation("根据宿舍id查看床位详细信息")
    @GetMapping("/info/{id}")
    public AjaxResult getBedsByDormId(@ApiParam(value = "宿舍ID") @PathVariable Long id){
        return dmsDormitoryBedService.getBedsByDormId(id);
    }

    /***
     * 通过登录用户的ksh获取宿舍信息
     * @author zhy
     * @date 2023-08-15 10:41:18
     * @return
     **/
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-bed:query')")
    @ApiOperation("通过登录用户的ksh获取宿舍信息")
    @GetMapping("/getOwnRoomInfo")
    public AjaxResult getOwnRoomInfo(){
        String ksh = getUsername();
        return dmsDormitoryBedService.getOwnRoomInfo(ksh);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-bed:query')")
    @ApiOperation("查看床位详细信息")
    @GetMapping("/{id}")
    public AjaxResult getBedInfo(@ApiParam(value = "床位ID") @PathVariable Long id){
        return dmsDormitoryBedService.getCphDormitoryBedDetail(id);
    }

//    @ApiOperation("查看宿舍床位")
//    @GetMapping("/dormitory/{id}")
//    public AjaxResult getBedByDormitoryId(@ApiParam(value = "宿舍ID") @PathVariable Long id){
//        return dmsDormitoryBedService.getCphDormitoryByDormitoryId(id);
//    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-bed:add')")
    @ApiOperation(value = "添加床位",notes = "不需要传id",response = BedDto.class)
    @PostMapping("/add")
    public AjaxResult addDmsDormitoryBed(@RequestBody BedDto bedDto){
        return dmsDormitoryBedService.addDmsDormitoryBed(bedDto,getUsername());
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-bed:remove')")
    @ApiOperation("根据id删除床位")
    @PostMapping("/{id}")
    public AjaxResult deleteDmsDormitoryBed(@PathVariable Long id){
        return dmsDormitoryBedService.deleteById(id);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-bed:remove')")
    @ApiOperation("批量删除床位")
    @PostMapping("/delete")
    public AjaxResult batchDeleteDmsDormitoryBed(@RequestBody List<Long> ids){
        return dmsDormitoryBedService.batchDeleteDormitoryBed(ids);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-bed:edit')")
    @ApiOperation(value = "修改床位",response = BedDto.class)
    @PostMapping("/update")
    public AjaxResult updateDmsDormitoryBed(@RequestBody BedDto bedDto){
        return dmsDormitoryBedService.updateDmsDormitoryBed(bedDto,getUsername());
    }
}
