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.AddDmsOffcampusApplicationDto;
import com.srs.dormitory.domain.Dto.ApplicationListDto;
import com.srs.dormitory.domain.Dto.CheckoutApplicationDto;
import com.srs.dormitory.domain.Dto.StudentDormitoryDto;
import com.srs.dormitory.service.IDmsCheckoutApplicationService;
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-checkout-application")
public class DmsCheckoutApplicationController extends BaseController {
    @Autowired
    private IDmsCheckoutApplicationService dmsDormitoryCheckoutApplicationService;

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-checkout-application:add')")
    @ApiOperation("提交退宿申请")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated AddDmsOffcampusApplicationDto dto){
            return dmsDormitoryCheckoutApplicationService.addDormitoryCheckoutApplication(dto);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-checkout-application:list')")
    @ApiOperation(value = "查看退宿申请列表")
    @PostMapping("/list")
    public TableDataInfo getList(@RequestBody ApplicationListDto dto){
        startPage();
        List<Map<String,Object>> list = dmsDormitoryCheckoutApplicationService.getApplicationList(dto);
        return getDataTable(list);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-checkout-application:query')")
    @ApiOperation("查看退宿申请表详情")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@ApiParam(value = "退宿申请表ID") @PathVariable Long id){
        return dmsDormitoryCheckoutApplicationService.getInfo(id);
    }
//    @PreAuthorize("@ss.hasPermi('dormitory:dms-checkout-application:remove')")
    @ApiOperation("删除退宿申请")
    @PostMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Long id){
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return dmsDormitoryCheckoutApplicationService.batchDelete(ids);
    }

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

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

