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.AddTransferApplicationDto;
import com.srs.dormitory.domain.Dto.ApplicationListDto;
import com.srs.dormitory.service.IDmsTransferApplicationService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 调宿申请表 前端控制器
 * </p>
 *
 * @author szz
 * @since 2023年07月26日
 */
@Api(tags = "调宿申请表管理")
@RestController
@RequestMapping("/dormitory/dms-dormitory-transfer-application")
public class DmsTransferApplicationController extends BaseController {
    @Autowired
    private IDmsTransferApplicationService dmsDormitoryTransferApplicationService;

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-transfer-application:add')")
    @ApiOperation("提交调宿申请")
    @PostMapping("/add")
    public AjaxResult addTransferApplication(@RequestBody @Validated AddTransferApplicationDto applicationDto){
        return dmsDormitoryTransferApplicationService.addTransferApplication(applicationDto);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-transfer-application:remove')")
    @ApiOperation("批量删除调宿申请")
    @PostMapping("/delete")
    public AjaxResult batchDeleteTransferApplication(@RequestBody List<Long> ids){
        return dmsDormitoryTransferApplicationService.batchDeleteTransferApplication(ids);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-transfer-application:remove')")
    @ApiOperation("删除调宿申请")
    @PostMapping("/delete/{id}")
    public AjaxResult deleteTransferApplication(@PathVariable Long id){
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return dmsDormitoryTransferApplicationService.batchDeleteTransferApplication(ids);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-transfer-application:list')")
    @ApiOperation("调宿申请表列表")
    @PostMapping("/list")
    public TableDataInfo getTransferApplicationList(@RequestBody ApplicationListDto dto){
        startPage();
        List<Map<String,Object>> list = dmsDormitoryTransferApplicationService.getTransferApplicationList(dto);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-transfer-application:query')")
    @ApiOperation("查看调宿申请详情")
    @GetMapping("/{id}")
    public AjaxResult getTransferApplicationInfo(@ApiParam(value = "调宿申请表ID") @PathVariable Long id){
        return dmsDormitoryTransferApplicationService.getTransferApplicationInfo(id);
    }

    @ApiOperation("取消申请")
    @GetMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable Long id){
        return dmsDormitoryTransferApplicationService.cancel(id);
    }
}

