package com.ruoyi.zhushi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhushi.entity.AppDTO;
import com.ruoyi.zhushi.entity.DkAttendanceGroupDTO;
import com.ruoyi.zhushi.entity.DkCheckInConfigDTO;
import com.ruoyi.zhushi.service.DkAttendanceGroupService;
import com.ruoyi.zhushi.service.DkConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打卡考勤组
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dk/attendanceGroup")
@Slf4j
public class DkAttendanceGroupController extends BaseController {


    @Autowired
    private DkAttendanceGroupService dkAttendanceGroupService;

    // 查询打卡配置列表
    @GetMapping("/list")
    public TableDataInfo<DkAttendanceGroupDTO> list(DkAttendanceGroupDTO dkAttendanceGroupDTO) {
        return dkAttendanceGroupService.queryPageList(dkAttendanceGroupDTO);
    }

    // 新增打卡配置
    @PostMapping("/add")
    @Log(title = "考勤组", businessType = BusinessType.INSERT)
    public R<String> addOrUpdate(@RequestBody DkAttendanceGroupDTO dkAttendanceGroupDTO) {
        return R.ok(dkAttendanceGroupService.addOrUpdate(dkAttendanceGroupDTO));
    }

    // 删除打卡配置
    @DeleteMapping("/del/{id}")
    @Log(title = "考勤组", businessType = BusinessType.DELETE)
    public R<Void> del(@PathVariable Long id) {
        return toAjax(dkAttendanceGroupService.del(id));
    }

    // 删除用户配置
    @DeleteMapping("/delUser/{id}")
    @Log(title = "考勤组-用户", businessType = BusinessType.DELETE)
    public R<Void> delUser(@PathVariable long id) {
        return toAjax(dkAttendanceGroupService.deleteConfig(id));
    }

    // 查询用户打卡配置
    @GetMapping("/queryAttendanceGroup")
    public R<List<DkAttendanceGroupDTO>> queryAttendanceGroup() {
        return R.ok(dkAttendanceGroupService.queryAttendanceGroup());
    }
}
