package com.srs.web.controller.dormitory;

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

import com.srs.common.core.domain.entity.SysDept;
import com.srs.system.service.ISysDeptService;
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.DmsCheckLog;
import com.srs.dormitory.service.IDmsCheckLogService;
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-12-29
 */
@RestController
@RequestMapping("/dormitory/checklog")
@Api(value = "查寝推送日志管理", tags = "查寝推送日志管理")
public class DmsCheckLogController extends BaseController {
    @Autowired
    private IDmsCheckLogService dmsCheckLogService;

    @Autowired
    public ISysDeptService _deptService;


    @PreAuthorize("@ss.hasPermi('dormitory:checklog:listXw')")
    @GetMapping("/listXw")
    @ApiOperation("学务查询查寝推送日志列表")
    public TableDataInfo listXw(DmsCheckLog dmsCheckLog)
    {
        SysDept dept = _deptService.selectDeptById(getDeptId());
        if (dept == null) {
            return getDataTable(new ArrayList<>());
        }
        dmsCheckLog.deptName = dept.getDeptName();
        startPage();
        List<DmsCheckLog> list = dmsCheckLogService.listView(dmsCheckLog);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('dormitory:checklog:listFdy')")
    @GetMapping("/listFdy")
    @ApiOperation("辅导员查询查寝推送日志列表")
    public TableDataInfo listFdy(DmsCheckLog dmsCheckLog)
    {
        dmsCheckLog.setTNo(getUsername());
        startPage();
        List<DmsCheckLog> list = dmsCheckLogService.listView(dmsCheckLog);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('dormitory:checklog:listStu')")
    @GetMapping("/listStu")
    @ApiOperation("查询查寝推送日志列表")
    public TableDataInfo listStu(DmsCheckLog dmsCheckLog)
    {
        dmsCheckLog.setStuNo(getUsername());
        startPage();
        List<DmsCheckLog> list = dmsCheckLogService.listView(dmsCheckLog);
        return getDataTable(list);
    }


    /**
     * 查询查寝推送日志列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:checklog:list')")
    @GetMapping("/list")
    @ApiOperation("查询查寝推送日志列表")
    public TableDataInfo list(DmsCheckLog dmsCheckLog)
    {
        startPage();
        List<DmsCheckLog> list = dmsCheckLogService.selectDmsCheckLogList(dmsCheckLog);
        return getDataTable(list);
    }

    /**
     * 导出查寝推送日志列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:checklog:export')")
    @Log(title = "查寝推送日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出查寝推送日志列表")
    public void export(HttpServletResponse response, DmsCheckLog dmsCheckLog)
    {
        List<DmsCheckLog> list = dmsCheckLogService.selectDmsCheckLogList(dmsCheckLog);
        ExcelUtil<DmsCheckLog> util = new ExcelUtil<DmsCheckLog>(DmsCheckLog.class);
        util.exportExcel(response, list, "查寝推送日志数据");
    }

    /**
     * 获取查寝推送日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('dormitory:checklog:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取查寝推送日志详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsCheckLogService.selectDmsCheckLogById(id));
    }

    /**
     * 新增查寝推送日志
     */
    @PreAuthorize("@ss.hasPermi('dormitory:checklog:add')")
    @Log(title = "查寝推送日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增查寝推送日志")
    public AjaxResult add(@RequestBody DmsCheckLog dmsCheckLog)
    {
        return toAjax(dmsCheckLogService.insertDmsCheckLog(dmsCheckLog));
    }

    /**
     * 修改查寝推送日志
     */
    @PreAuthorize("@ss.hasPermi('dormitory:checklog:edit')")
    @Log(title = "查寝推送日志", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改查寝推送日志")
    public AjaxResult edit(@RequestBody DmsCheckLog dmsCheckLog)
    {
        return toAjax(dmsCheckLogService.updateDmsCheckLog(dmsCheckLog));
    }

    /**
     * 删除查寝推送日志
     */
    @PreAuthorize("@ss.hasPermi('dormitory:checklog:remove')")
    @Log(title = "查寝推送日志", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除查寝推送日志")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsCheckLogService.deleteDmsCheckLogByIds(ids));
    }
}
