package com.ruoyi.finance.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.finance.domain.vo.FinanceServiceFeeVo;
import com.ruoyi.finance.domain.bo.FinanceServiceFeeBo;
import com.ruoyi.finance.service.IFinanceServiceFeeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 劳务费
 *
 * @author ruoyi
 * @date 2024-06-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/finance/serviceFee")
public class FinanceServiceFeeController extends BaseController {

    private final IFinanceServiceFeeService iFinanceServiceFeeService;

    /**
     * 查询劳务费列表
     */
    @SaCheckPermission("finance:serviceFee:list")
    @GetMapping("/list")
    public TableDataInfo<FinanceServiceFeeVo> list(FinanceServiceFeeBo bo, PageQuery pageQuery) {
        return iFinanceServiceFeeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出劳务费列表
     */
    @SaCheckPermission("finance:serviceFee:export")
    @Log(title = "劳务费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FinanceServiceFeeBo bo, HttpServletResponse response) {
        List<FinanceServiceFeeVo> list = iFinanceServiceFeeService.queryList(bo);
        ExcelUtil.exportExcel(list, "劳务费", FinanceServiceFeeVo.class, response);
    }

    /**
     * 获取劳务费详细信息
     *
     * @param serviceFeeId 主键
     */
    @SaCheckPermission("finance:serviceFee:query")
    @GetMapping("/{serviceFeeId}")
    public R<FinanceServiceFeeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long serviceFeeId) {
        return R.ok(iFinanceServiceFeeService.queryById(serviceFeeId));
    }

    /**
     * 新增劳务费
     */
    @SaCheckPermission("finance:serviceFee:add")
    @Log(title = "劳务费", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FinanceServiceFeeBo bo) {
        return toAjax(iFinanceServiceFeeService.insertByBo(bo));
    }

    /**
     * 修改劳务费
     */
    @SaCheckPermission("finance:serviceFee:edit")
    @Log(title = "劳务费", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FinanceServiceFeeBo bo) {
        return toAjax(iFinanceServiceFeeService.updateByBo(bo));
    }

    /**
     * 删除劳务费
     *
     * @param serviceFeeIds 主键串
     */
    @SaCheckPermission("finance:serviceFee:remove")
    @Log(title = "劳务费", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceFeeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] serviceFeeIds) {
        return toAjax(iFinanceServiceFeeService.deleteWithValidByIds(Arrays.asList(serviceFeeIds), true));
    }
}
