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.NjRuleConfigDTO;
import com.ruoyi.zhushi.service.NjRuleConfigService;
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.*;

/**
 * 年假规则配置
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nj/rule/config")
@Slf4j
public class NjRuleConfigController extends BaseController {

    @Autowired
    private NjRuleConfigService njRuleConfigService;


    /**
     * 查询规则
      * @param njRuleConfigDTO
     * @param pageQuery
     * @return
     */
    @GetMapping("/queryRuleConfig")
    public TableDataInfo<NjRuleConfigDTO> queryRule(NjRuleConfigDTO njRuleConfigDTO, PageQuery pageQuery) {
        return njRuleConfigService.queryRuleConfig(njRuleConfigDTO, pageQuery);
    }

    /**
     * 新增规则
     * @param njRuleConfigDTO
     * @return
     */
    @PostMapping("/addRuleConfig")
    @Log(title = "年假规则新增或者修改", businessType = BusinessType.UPDATE)
    public R<Boolean> addRule(@RequestBody NjRuleConfigDTO njRuleConfigDTO) {
        return R.ok(njRuleConfigService.addRule(njRuleConfigDTO));
    }

    /**
     * 删除规则
     * @param id
     * @return
     */
    @GetMapping("/delRule")
    @Log(title = "年假规则", businessType = BusinessType.DELETE)
    public R<Integer> delRule(@RequestParam("id") long id) {
        return R.ok(njRuleConfigService.delRule(id));
    }

    /**
     *  删除这个规则下选择的用户
     * @param id 用户id
     * @return
     */
    @DeleteMapping("/delUser/{id}")
    @Log(title = "年假规则关联用户", businessType = BusinessType.DELETE)
    public R<Void> delUser(@PathVariable Long id) {
        return toAjax(njRuleConfigService.delUser(id));
    }
}
