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.enums.BusinessType;
import com.ruoyi.zhushi.entity.*;
import com.ruoyi.zhushi.service.NjBalanceManageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 打卡控制台
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nj/balance/manage")
@Slf4j
public class NjBalanceManageController extends BaseController {

    @Autowired
    private NjBalanceManageService njBalanceManageService;

    // 查询当前用户考勤组
    @GetMapping("/query")
    public TableDataInfo<NjBalanceManageDTO> query(NjBalanceManageDTO njBalanceManageDTO, PageQuery pageQuery) {
        return njBalanceManageService.queryPageList(njBalanceManageDTO, pageQuery);
    }


    // 生成年假信息
    @GetMapping("/generateYearBalance")
    public void generateYearBalance() {
        njBalanceManageService.generateYearBalance();
    }


    // 根据用户id获取年假余额
    @GetMapping("/getUnUsedDayByUserId")
    public BigDecimal getUnUsedDayByUserId(@RequestParam("userId") long userId){
        return njBalanceManageService.getUnUsedDayByUserId(userId);
    }

    // 手动更新年假数据
    @PutMapping("/update")
    @Log(title = "年假手动更新", businessType = BusinessType.UPDATE)
    public R<Integer> update(@RequestBody NjBalanceManageDTO njBalanceManageDTO){
        return R.ok(njBalanceManageService.update(njBalanceManageDTO));
    }
}
