package com.flossom.system.controller;

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

import com.flossom.common.core.domain.entity.WxClockLog;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
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.flossom.system.service.IWxClockLogService;

/**
 * 用户打卡Controller
 *
 * @author flossom
 * @date 2024-02-21
 */
@RestController
@RequestMapping("/clockLog")
public class WxClockLogController extends BaseController {

    @Autowired
    private IWxClockLogService wxClockLogService;

    /**
     * 查询用户打卡列表
     */
    @RequiresPermissions("system:clockLog:list")
    @GetMapping("/list")
    public TableDataInfo list(WxClockLog wxClockLog) {
        startPage();
        List<WxClockLog> list = wxClockLogService.selectWxClockLogList(wxClockLog);
        return getDataTable(list);
    }

    /**
     * 导出用户打卡列表
     */
    @RequiresPermissions("system:clockLog:export")
    @Log(title = "用户打卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxClockLog wxClockLog) {
        List<WxClockLog> list = wxClockLogService.selectWxClockLogList(wxClockLog);
        ExcelUtil<WxClockLog> util = new ExcelUtil<WxClockLog>(WxClockLog.class);
        util.exportExcel(response, list, "用户打卡数据");
    }

    /**
     * 获取用户打卡详细信息
     */
    @RequiresPermissions("system:clockLog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wxClockLogService.selectWxClockLogById(id));
    }

    /**
     * 新增用户打卡
     */
    @RequiresPermissions("system:clockLog:add")
    @Log(title = "用户打卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxClockLog wxClockLog) {
        return toAjax(wxClockLogService.insertWxClockLog(wxClockLog));
    }

    /**
     * 修改用户打卡
     */
    @RequiresPermissions("system:clockLog:edit")
    @Log(title = "用户打卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxClockLog wxClockLog) {
        return toAjax(wxClockLogService.updateWxClockLog(wxClockLog));
    }

    /**
     * 删除用户打卡
     */
    @RequiresPermissions("system:clockLog:remove")
    @Log(title = "用户打卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wxClockLogService.deleteWxClockLogByIds(ids));
    }
}
