package com.srs.web.controller.dormitory;

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

import com.srs.dormitory.domain.Dto.SetNeedCardDto;
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.DmsNeedCardStu;
import com.srs.dormitory.service.IDmsNeedCardStuService;
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 2025-07-08
 */
@RestController
@RequestMapping("/dormitory/needCardStu")
@Api(value = "打卡设置管理", tags = "打卡设置管理")
public class DmsNeedCardStuController extends BaseController {
    @Autowired
    private IDmsNeedCardStuService dmsNeedCardStuService;

    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:listFdy')")
    @PostMapping("/sendTodayNeedCardMsg")
    @ApiOperation("辅导员向今日需要打卡的学生发送信息")
    public AjaxResult sendTodayNeedCardMsg(){
        return dmsNeedCardStuService.sendTodayNeedCardMsg();
    }


    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:listFdy')")
    @PostMapping("/setNeedCardByClass")
    @ApiOperation("辅导员设置班级学生需要打卡")
    public AjaxResult setNeedCardByClass(@RequestBody SetNeedCardDto param){
        return dmsNeedCardStuService.setNeedCardByClass(param);
    }



    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:listFdy')")
    @PostMapping("/cardNeedCard/{id}")
    @ApiOperation("辅导员帮学生打卡")
    public AjaxResult cardNeedCard(@PathVariable Long id) {
        return dmsNeedCardStuService.cardNeedCard(id);
    }


    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:listFdy')")
    @PostMapping("/cancelNeedCard/{id}")
    @ApiOperation("辅导员标记学生不需要打卡")
    public AjaxResult cancelNeedCard(@PathVariable Long id) {
        return dmsNeedCardStuService.cancelNeedCard(id);
    }



    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:listFdy')")
    @GetMapping("/listFdy")
    @ApiOperation("辅导员查询打卡设置列表")
    public TableDataInfo listFdy(DmsNeedCardStu params) {
        params.setFdyNo(getUsername());
        startPage();
        List<DmsNeedCardStu> list = dmsNeedCardStuService.listView(params);
        return getDataTable(list);
    }



    /**
     * 查询打卡设置列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:list')")
    @GetMapping("/list")
    @ApiOperation("查询打卡设置列表")
    public TableDataInfo list(DmsNeedCardStu dmsNeedCardStu) {
        startPage();
        List<DmsNeedCardStu> list = dmsNeedCardStuService.selectDmsNeedCardStuList(dmsNeedCardStu);
        return getDataTable(list);
    }

    /**
     * 导出打卡设置列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:export')")
    @Log(title = "打卡设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出打卡设置列表")
    public void export(HttpServletResponse response, DmsNeedCardStu dmsNeedCardStu) {
        List<DmsNeedCardStu> list = dmsNeedCardStuService.selectDmsNeedCardStuList(dmsNeedCardStu);
        ExcelUtil<DmsNeedCardStu> util = new ExcelUtil<DmsNeedCardStu>(DmsNeedCardStu.class);
        util.exportExcel(response, list, "打卡设置数据");
    }

    /**
     * 获取打卡设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取打卡设置详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dmsNeedCardStuService.selectDmsNeedCardStuById(id));
    }

    /**
     * 新增打卡设置
     */
    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:add')")
    @Log(title = "打卡设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增打卡设置")
    public AjaxResult add(@RequestBody DmsNeedCardStu dmsNeedCardStu) {
        return toAjax(dmsNeedCardStuService.insertDmsNeedCardStu(dmsNeedCardStu));
    }

    /**
     * 修改打卡设置
     */
    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:edit')")
    @Log(title = "打卡设置", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改打卡设置")
    public AjaxResult edit(@RequestBody DmsNeedCardStu dmsNeedCardStu) {
        return toAjax(dmsNeedCardStuService.updateDmsNeedCardStu(dmsNeedCardStu));
    }

    /**
     * 删除打卡设置
     */
    @PreAuthorize("@ss.hasPermi('dormitory:needCardStu:remove')")
    @Log(title = "打卡设置", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除打卡设置")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dmsNeedCardStuService.deleteDmsNeedCardStuByIds(ids));
    }
}
