package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.SrsStudent;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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 com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.comprehensive.domain.SrsDormitory;
import com.srs.comprehensive.service.ISrsDormitoryService;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 宿舍信息Controller
 * 
 * @author srs
 * @date 2023-06-27
 */
@RestController
@RequestMapping("/system/dormitory")
public class SrsDormitoryController extends BaseController
{
    @Autowired
    private ISrsDormitoryService srsDormitoryService;

    /**
     * 查询宿舍信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:dormitory:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsDormitory srsDormitory)
    {
        startPage();
        List<SrsDormitory> list = srsDormitoryService.selectSrsDormitoryList(srsDormitory);
        return getDataTable(list);
    }

    /**
     * 导出宿舍信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:dormitory:export')")
    @Log(title = "宿舍信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsDormitory srsDormitory)
    {
        List<SrsDormitory> list = srsDormitoryService.selectSrsDormitoryList(srsDormitory);
        ExcelUtil<SrsDormitory> util = new ExcelUtil<SrsDormitory>(SrsDormitory.class);
        util.exportExcel(response, list, "宿舍信息数据");
    }


    /**
     * 下载导入模板
     * @param response
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<SrsDormitory> util = new ExcelUtil<SrsDormitory>(SrsDormitory.class);
        util.importTemplateExcel(response, "宿舍信息数据");
    }
    /**
     * 导入
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @Log(title = "宿舍信息", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:dormitory:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<SrsDormitory> util = new ExcelUtil<SrsDormitory>(SrsDormitory.class);
        List<SrsDormitory> dormitoryList = util.importExcel(file.getInputStream());
        String message = srsDormitoryService.importDormitory(dormitoryList, updateSupport, getUsername());
        return success(message);
    }
    /**
     * 获取宿舍信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:dormitory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsDormitoryService.selectSrsDormitoryById(id));
    }

    /**
     * 新增宿舍信息
     */
//    @PreAuthorize("@ss.hasPermi('system:dormitory:add')")
    @Log(title = "宿舍信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsDormitory srsDormitory)
    {
        return toAjax(srsDormitoryService.insertSrsDormitory(srsDormitory));
    }

    /**
     * 修改宿舍信息
     */
//    @PreAuthorize("@ss.hasPermi('system:dormitory:edit')")
    @Log(title = "宿舍信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrsDormitory srsDormitory)
    {
        return toAjax(srsDormitoryService.updateSrsDormitory(srsDormitory));
    }

    /**
     * 删除宿舍信息
     */
//    @PreAuthorize("@ss.hasPermi('system:dormitory:remove')")
    @Log(title = "宿舍信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsDormitoryService.deleteSrsDormitoryByIds(ids));
    }
}
