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.service.IDmsForeignDormitoryService;
import com.srs.dormitory.utils.DmsOperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import liquibase.pro.packaged.M;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 外来人员宿舍关联表 前端控制器
 * </p>
 *
 * @author szz
 * @since 2023年08月04日
 */
@Api(tags = "外来人员宿舍关联表管理")
@RestController
@RequestMapping("/dormitory/dms-foreign-dormitory")
public class DmsForeignDormitoryController extends BaseController {

    @Autowired
    private IDmsForeignDormitoryService dmsForeignDormitoryService;

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-foreign-dormitory:add')")
    @ApiOperation("分配外来人员宿舍")
    @PostMapping("/add")
    public AjaxResult addForeignDormitory(@ApiParam(value = "宿舍ID") @RequestParam Long dormitoryId, @RequestParam(value = "床位ID") Long bedId,
                                          @ApiParam(value = "申请表ID") @RequestParam Long applicationId){
        return dmsForeignDormitoryService.addForeignDormitory(dormitoryId,bedId,applicationId);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-foreign-dormitory:list')")
    @ApiOperation("外来人员宿舍关联列表")
    @PostMapping("/list")
    public TableDataInfo getForeignDormitoryList(@ApiParam(value = "宿舍楼名字") @RequestParam(required = false) String buildingName,
                                                 @ApiParam(value = "申请人姓名") @RequestParam(required = false) String applicationName,
                                                 @ApiParam(value = "校内联系人姓名") @RequestParam(required = false) String contactName){
        List<Map<String,Object>> list = dmsForeignDormitoryService.getForeignDormitoryList(buildingName,applicationName,contactName);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-foreign-dormitory:edit')")
    @ApiOperation("修改外来人员宿舍关联")
    @PostMapping("/update")
    public AjaxResult updateForeignDormitory(@ApiParam(value = "外来人员宿舍关联id") @RequestParam Long id,
                                             @ApiParam(value = "宿舍ID") @RequestParam(required = false) Long dormitoryId,
                                             @ApiParam(value = "床位ID") @RequestParam(required = false) Long bedId){
        return dmsForeignDormitoryService.updateForeignDormitory(id,dormitoryId,bedId);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-foreign-dormitory:remove')")
    @ApiOperation("删除外来人员宿舍关联")
    @PostMapping("/delete/{id}")
    public AjaxResult deleteForeignDormitory(@ApiParam(value = "关联id") @PathVariable Long id){
        return dmsForeignDormitoryService.deleteForeignDormitory(id);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-foreign-dormitory:remove')")
    @ApiOperation("批量删除外来人员宿舍关联")
    @PostMapping("/batch/delete")
    public AjaxResult deleteForeignDormitory(@RequestBody List<Long> ids){
        return dmsForeignDormitoryService.batchDeleteForeignDormitory(ids);
    }

}

