package com.srs.web.controller.dormitory;

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

import cn.hutool.db.meta.Table;
import com.srs.dormitory.domain.Dto.DmsSearch;
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.DmsDormitoryCheck;
import com.srs.dormitory.service.IDmsDormitoryCheckService;
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 LSD
 * @date 2024-12-06
 */
@RestController
@RequestMapping("/dmsDormitoryCheck/dormitoryCheck")
@Api(value = "查寝管理管理", tags = "查寝管理管理")
public class DmsDormitoryCheckController extends BaseController {
    @Autowired
    private IDmsDormitoryCheckService dmsDormitoryCheckService;





    @PostMapping("/sendMail/{checkId}")
    @ApiOperation("发送查寝通知邮件")
    public AjaxResult sendMail(@PathVariable Long checkId) {
        return dmsDormitoryCheckService.sendMail(checkId);
    }


    @GetMapping("/listDorm")
    @ApiOperation("列出宿舍")
    public TableDataInfo listDorm(DmsSearch param){
        List<Map<String, Object>> list = dmsDormitoryCheckService.listDorm(param);
        list.forEach(x->{
            x.put("dorm_name",x.get("park_name").toString()+x.get("building_name").toString()+x.get("room_no").toString());
        });
        return getDataTable(list);
    }

    /**
     * 查询查寝管理列表
     */
    @PreAuthorize("@ss.hasPermi('dmsDormitoryCheck:dormitoryCheck:list')")
    @GetMapping("/list")
    @ApiOperation("查询查寝管理列表")
    public TableDataInfo list(DmsDormitoryCheck dmsDormitoryCheck)
    {
        startPage();
        List<DmsDormitoryCheck> list = dmsDormitoryCheckService.selectDmsDormitoryCheckList(dmsDormitoryCheck);
        return getDataTable(list);
    }

    /**
     * 导出查寝管理列表
     */
    @PreAuthorize("@ss.hasPermi('dmsDormitoryCheck:dormitoryCheck:export')")
    @Log(title = "查寝管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出查寝管理列表")
    public void export(HttpServletResponse response, DmsDormitoryCheck dmsDormitoryCheck)
    {
        List<DmsDormitoryCheck> list = dmsDormitoryCheckService.selectDmsDormitoryCheckList(dmsDormitoryCheck);
        ExcelUtil<DmsDormitoryCheck> util = new ExcelUtil<DmsDormitoryCheck>(DmsDormitoryCheck.class);
        util.exportExcel(response, list, "查寝管理数据");
    }

    /**
     * 获取查寝管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dmsDormitoryCheck:dormitoryCheck:query')")
    @GetMapping(value = "/{checkId}")
    @ApiOperation("获取查寝管理详细信息")
    public AjaxResult getInfo(@PathVariable("checkId") Long checkId)
    {
        return success(dmsDormitoryCheckService.selectDmsDormitoryCheckByCheckId(checkId));
    }

    /**
     * 新增查寝管理
     */
    @PreAuthorize("@ss.hasPermi('dmsDormitoryCheck:dormitoryCheck:add')")
    @Log(title = "查寝管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增查寝管理")
    public AjaxResult add(@RequestBody DmsDormitoryCheck dmsDormitoryCheck)
    {
        return toAjax(dmsDormitoryCheckService.insertDmsDormitoryCheck(dmsDormitoryCheck));
    }

    /**
     * 修改查寝管理
     */
    @PreAuthorize("@ss.hasPermi('dmsDormitoryCheck:dormitoryCheck:edit')")
    @Log(title = "查寝管理", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改查寝管理")
    public AjaxResult edit(@RequestBody DmsDormitoryCheck dmsDormitoryCheck)
    {
        return toAjax(dmsDormitoryCheckService.updateDmsDormitoryCheck(dmsDormitoryCheck));
    }

    /**
     * 删除查寝管理
     */
    @PreAuthorize("@ss.hasPermi('dmsDormitoryCheck:dormitoryCheck:remove')")
    @Log(title = "查寝管理", businessType = BusinessType.DELETE)
    @PostMapping("/{checkIds}")
    @ApiOperation("删除查寝管理")
    public AjaxResult remove(@PathVariable Long[] checkIds)
    {
        return toAjax(dmsDormitoryCheckService.deleteDmsDormitoryCheckByCheckIds(checkIds));
    }
}
