package com.srs.web.controller.dormitory;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.dormitory.domain.DmsNewRange;
import com.srs.dormitory.service.IDmsNewRangeService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 住宿区间Controller
 *
 * @author srs
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/dormitory/range")
@Api(value = "住宿区间管理", tags = "住宿区间管理")
public class DmsNewRangeController extends BaseController {
    @Autowired
    private IDmsNewRangeService dmsNewRangeService;



    @GetMapping("/listAllRange")
    @ApiOperation("列出所有住宿区间")
    public AjaxResult listAllRange(){
        List<DmsNewRange> list = dmsNewRangeService.selectDmsNewRangeList(null);
        return AjaxResult.success(list);
    }


    /**
     * 查询住宿区间列表
     */
    @GetMapping("/list")
    @ApiOperation("查询住宿区间列表")
    public TableDataInfo list(DmsNewRange dmsNewRange) {
        startPage();
        List<DmsNewRange> list = dmsNewRangeService.selectDmsNewRangeList(dmsNewRange);
        return getDataTable(list);
    }

    /**
     * 导出住宿区间列表
     */
    @Log(title = "住宿区间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出住宿区间列表")
    public void export(HttpServletResponse response, DmsNewRange dmsNewRange) {
        List<DmsNewRange> list = dmsNewRangeService.selectDmsNewRangeList(dmsNewRange);
        ExcelUtil<DmsNewRange> util = new ExcelUtil<DmsNewRange>(DmsNewRange.class);
        util.exportExcel(response, list, "住宿区间数据");
    }

    /**
     * 获取住宿区间详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取住宿区间详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dmsNewRangeService.selectDmsNewRangeById(id));
    }

    /**
     * 新增住宿区间
     */
    @Log(title = "住宿区间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增住宿区间")
    public AjaxResult add(@RequestBody DmsNewRange dmsNewRange) {
        return dmsNewRangeService.insertDmsNewRange(dmsNewRange);
    }

    /**
     * 修改住宿区间
     */
    @Log(title = "住宿区间", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改住宿区间")
    public AjaxResult edit(@RequestBody DmsNewRange dmsNewRange) {
        return dmsNewRangeService.updateDmsNewRange(dmsNewRange);
    }

    /**
     * 删除住宿区间
     */
    @Log(title = "住宿区间", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除住宿区间")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dmsNewRangeService.deleteDmsNewRangeByIds(ids));
    }
}
