package com.srs.web.controller.dormitory;

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

import com.srs.dormitory.domain.DmsDormitoryRecords;
import com.srs.dormitory.service.IDmsDormitoryRecordsService;
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 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;
import org.springframework.web.multipart.MultipartFile;

/**
 * 宿舍费用Controller
 *
 * @author srs
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/dormitory/records")
@Api(value = "宿舍费用管理", tags = "宿舍费用管理")
public class DmsDormitoryRecordsController extends BaseController {
    @Autowired
    private IDmsDormitoryRecordsService dmsDormitoryRecordsService;

    /**
     * 查询宿舍费用列表
     */
//@PreAuthorize("@ss.hasPermi('system:records:list')")
@GetMapping("/list")
@ApiOperation("查询宿舍费用列表")
    public TableDataInfo list(DmsDormitoryRecords dmsDormitoryRecords)
    {
        startPage();
        List<DmsDormitoryRecords> list = dmsDormitoryRecordsService.selectDmsDormitoryRecordsList(dmsDormitoryRecords);
        return getDataTable(list);
    }

    /**
     * 导出宿舍费用列表
     */
//    @PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "宿舍费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出宿舍费用列表")
    public void export(HttpServletResponse response, DmsDormitoryRecords dmsDormitoryRecords)
    {
        List<DmsDormitoryRecords> list = dmsDormitoryRecordsService.selectDmsDormitoryRecordsList(dmsDormitoryRecords);
        ExcelUtil<DmsDormitoryRecords> util = new ExcelUtil<DmsDormitoryRecords>(DmsDormitoryRecords.class);
        util.exportExcel(response, list, "宿舍费用数据");
    }

    /**
     * 获取宿舍费用详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取宿舍费用详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsDormitoryRecordsService.selectDmsDormitoryRecordsById(id));
    }

    /**
     * 新增宿舍费用
     */
//    @PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "宿舍费用", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增宿舍费用")
    public AjaxResult add(@RequestBody DmsDormitoryRecords dmsDormitoryRecords)
    {
        return toAjax(dmsDormitoryRecordsService.insertDmsDormitoryRecords(dmsDormitoryRecords));
    }

    /**
     * 修改宿舍费用
     */
//    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "宿舍费用", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改宿舍费用")
    public AjaxResult edit(@RequestBody DmsDormitoryRecords dmsDormitoryRecords)
    {
        return toAjax(dmsDormitoryRecordsService.updateDmsDormitoryRecords(dmsDormitoryRecords));
    }

    /**
     * 删除宿舍费用
     */
//    @PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "宿舍费用", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除宿舍费用")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsDormitoryRecordsService.deleteDmsDormitoryRecordsByIds(ids));
    }

    @PostMapping("/import")
    @ApiOperation("导入宿舍费用")
    public  AjaxResult importData(MultipartFile file) throws Exception{
        ExcelUtil<DmsDormitoryRecords> util = new ExcelUtil<>(DmsDormitoryRecords.class);
        List<DmsDormitoryRecords> dormitoryRecordsList = util.importExcel(file.getInputStream());
        return dmsDormitoryRecordsService.importData(dormitoryRecordsList);
    }
}
