package com.ruoyi.pay.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
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.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pay.domain.vo.PayWorkTimeVo;
import com.ruoyi.pay.domain.bo.PayWorkTimeBo;
import com.ruoyi.pay.service.IPayWorkTimeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工工时时间段
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/workTime")
public class PayWorkTimeController extends BaseController {

    private final IPayWorkTimeService iPayWorkTimeService;

    /**
     * 查询员工工时时间段列表
     */
    @SaCheckPermission("pay:workTime:list")
    @GetMapping("/list")
    public TableDataInfo<PayWorkTimeVo> list(PayWorkTimeBo bo, PageQuery pageQuery) {
        return iPayWorkTimeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出员工工时时间段列表
     */
    @SaCheckPermission("pay:workTime:export")
    @Log(title = "员工工时时间段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayWorkTimeBo bo, HttpServletResponse response) {
        List<PayWorkTimeVo> list = iPayWorkTimeService.queryList(bo);
        ExcelUtil.exportExcel(list, "员工工时时间段", PayWorkTimeVo.class, response);
    }

    /**
     * 获取员工工时时间段详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pay:workTime:query")
    @GetMapping("/{id}")
    public R<PayWorkTimeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iPayWorkTimeService.queryById(id));
    }

    /**
     * 新增员工工时时间段
     */
    @SaCheckPermission("pay:workTime:add")
    @Log(title = "员工工时时间段", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayWorkTimeBo bo) {
        return toAjax(iPayWorkTimeService.insertByBo(bo));
    }

    /**
     * 修改员工工时时间段
     */
    @SaCheckPermission("pay:workTime:edit")
    @Log(title = "员工工时时间段", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayWorkTimeBo bo) {
        return toAjax(iPayWorkTimeService.updateByBo(bo));
    }

    /**
     * 删除员工工时时间段
     *
     * @param ids 主键串
     */
    @SaCheckPermission("pay:workTime:remove")
    @Log(title = "员工工时时间段", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iPayWorkTimeService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
