package com.ruoyi.zhushi.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
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.NjBalanceManageDetailDTO;
import com.ruoyi.zhushi.service.NjBalanceManageDetailService;
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 javax.validation.constraints.NotEmpty;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

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

    @Autowired
    private NjBalanceManageDetailService njBalanceManageDetailService;

    // 查询年假申请信息
    @GetMapping("/query")
    public TableDataInfo<NjBalanceManageDetailDTO> query(NjBalanceManageDetailDTO njBalanceManageDetailDTO, PageQuery pageQuery) {
        return njBalanceManageDetailService.queryPageList(njBalanceManageDetailDTO, pageQuery);
    }


    // 年假申请
    @PostMapping("/apply")
    @Log(title = "年假余额申请", businessType = BusinessType.UPDATE)
    public R<Void> insert(@Validated(AddGroup.class) @RequestBody NjBalanceManageDetailDTO njBalanceManageDetailDTO) {
        return toAjax(njBalanceManageDetailService.insert(njBalanceManageDetailDTO));
    }


    @SaIgnore
    @GetMapping("/calendar_query")
    public List<Map<String, String>> calendarQuery() {
        return njBalanceManageDetailService.calendarQuery();
    }


    /**
     * 撤销年假申请
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    @Log(title = "年假余额申请撤销", businessType = BusinessType.UPDATE)
    public R<Void> cancelByIds(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(njBalanceManageDetailService.cancelByIds(Arrays.asList(ids)));
    }
}
