package com.ruoyi.web.controller.clock;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ClockUserInfo;
import com.ruoyi.system.service.IClockUserInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 打卡人员信息Controller
 *
 * @author ruoyi
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/system/info")
public class ClockUserInfoController extends BaseController
{
    @Autowired
    private IClockUserInfoService clockUserInfoService;

/**
 * 查询打卡人员信息列表
 */
@PreAuthorize("@ss.hasPermi('system:info:list')")
@GetMapping("/list")
    public TableDataInfo list(ClockUserInfo clockUserInfo)
    {
        startPage();
        List<ClockUserInfo> list = clockUserInfoService.selectClockUserInfoList(clockUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出打卡人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "打卡人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClockUserInfo clockUserInfo)
    {
        List<ClockUserInfo> list = clockUserInfoService.selectClockUserInfoList(clockUserInfo);
        ExcelUtil<ClockUserInfo> util = new ExcelUtil<ClockUserInfo>(ClockUserInfo.class);
        util.exportExcel(response, list, "打卡人员信息数据");
    }

    /**
     * 获取打卡人员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(clockUserInfoService.selectClockUserInfoByUserId(userId));
    }

    /**
     * 新增打卡人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "打卡人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClockUserInfo clockUserInfo)
    {
        return toAjax(clockUserInfoService.insertClockUserInfo(clockUserInfo));
    }

    /**
     * 修改打卡人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "打卡人员信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ClockUserInfo clockUserInfo)
    {
        return toAjax(clockUserInfoService.updateClockUserInfo(clockUserInfo));
    }

    /**
     * 删除打卡人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "打卡人员信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(clockUserInfoService.deleteClockUserInfoByUserIds(userIds));
    }
}
