package com.ruoyi.hezhi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbMemberSign;
import com.ruoyi.hezhi.service.ITbMemberSignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 用户签到Controller
 *
 * @author ruoyi
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/hezhi/memberSign")
public class TbMemberSignController extends BaseController
{
    @Autowired
    private ITbMemberSignService tbMemberSignService;

    /**
     * 查询用户签到列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSign:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMemberSign tbMemberSign)
    {
        startPage();
        List<TbMemberSign> list = tbMemberSignService.selectTbMemberSignList(tbMemberSign);
        return getDataTable(list);
    }

    /**
     * 导出用户签到列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSign:export')")
    @Log(title = "用户签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMemberSign tbMemberSign)
    {
        List<TbMemberSign> list = tbMemberSignService.selectTbMemberSignList(tbMemberSign);
        ExcelUtil<TbMemberSign> util = new ExcelUtil<TbMemberSign>(TbMemberSign.class);
        util.exportExcel(response, list, "用户签到数据");
    }

    /**
     * 获取用户签到详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSign:query')")
    @GetMapping(value = "/{memberSignId}")
    public AjaxResult getInfo(@PathVariable("memberSignId") Long memberSignId)
    {
        return success(tbMemberSignService.selectTbMemberSignByMemberSignId(memberSignId));
    }

    /**
     * 新增用户签到
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSign:add')")
    @Log(title = "用户签到", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMemberSign tbMemberSign)
    {
        return toAjax(tbMemberSignService.insertTbMemberSign(tbMemberSign));
    }

    /**
     * 修改用户签到
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSign:edit')")
    @Log(title = "用户签到", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMemberSign tbMemberSign)
    {
        return toAjax(tbMemberSignService.updateTbMemberSign(tbMemberSign));
    }

    /**
     * 删除用户签到
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSign:remove')")
    @Log(title = "用户签到", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberSignIds}")
    public AjaxResult remove(@PathVariable Long[] memberSignIds)
    {
        return toAjax(tbMemberSignService.deleteTbMemberSignByMemberSignIds(memberSignIds));
    }
}
