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.ApplicationListDto;
import com.srs.dormitory.domain.Dto.HolidayStayApplicationDto;
import com.srs.dormitory.service.IDmsHolidayStayApplicationService;
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.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月31日
 */
@Api(tags = "假期留宿申请表管理")
@RestController
@RequestMapping("/dormitory/dms-holiday-stay-application")
public class DmsHolidayStayApplicationController extends BaseController {
    @Autowired
    private IDmsHolidayStayApplicationService dmsHolidayStayApplicationService;

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-holiday-stay-application:add')")
    @ApiOperation("提交假期留宿申请表")
    @PostMapping("/add")
    public AjaxResult addHolidayStayApplication(@RequestBody @Validated HolidayStayApplicationDto applicationDto){
        return dmsHolidayStayApplicationService.addHolidayStayApplication(applicationDto);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-holiday-stay-application:query')")
    @ApiOperation("查看假期留宿申请表详情")
    @GetMapping("/{id}")
    public AjaxResult getHolidayStayApplication(@ApiParam(value = "假期留宿申请ID") @PathVariable Long id){
        return dmsHolidayStayApplicationService.getHolidayStayApplication(id);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-holiday-stay-application:remove')")
    @ApiOperation("删除假期留宿申请表")
    @PostMapping("/delete/{id}")
    public AjaxResult deleteHolidayStayApplication(@PathVariable Long id){
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return dmsHolidayStayApplicationService.batchDeleteHolidayStayApplication(ids);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-holiday-stay-application:remove')")
    @ApiOperation("批量删除假期留宿申请表")
    @PostMapping("/batch/delete")
    public AjaxResult batchDeleteHolidayStayApplication(@RequestBody List<Long> ids){
        return dmsHolidayStayApplicationService.batchDeleteHolidayStayApplication(ids);
    }

    @ApiOperation("假期留宿申请表列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ApplicationListDto dto){
        startPage();
        List<Map<String ,Object>> list = dmsHolidayStayApplicationService.getList(dto);
        return getDataTable(list);
    }

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

