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.PayBaohuoEmployeeVo;
import com.ruoyi.pay.domain.bo.PayBaohuoEmployeeBo;
import com.ruoyi.pay.service.IPayBaohuoEmployeeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 包活工单员工关联
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/baohuoEmployee")
public class PayBaohuoEmployeeController extends BaseController {

    private final IPayBaohuoEmployeeService iPayBaohuoEmployeeService;

    /**
     * 查询包活工单员工关联列表
     */
    @SaCheckPermission("pay:baohuoEmployee:list")
    @GetMapping("/list")
    public TableDataInfo<PayBaohuoEmployeeVo> list(PayBaohuoEmployeeBo bo, PageQuery pageQuery) {
        return iPayBaohuoEmployeeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出包活工单员工关联列表
     */
    @SaCheckPermission("pay:baohuoEmployee:export")
    @Log(title = "包活工单员工关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayBaohuoEmployeeBo bo, HttpServletResponse response) {
        List<PayBaohuoEmployeeVo> list = iPayBaohuoEmployeeService.queryList(bo);
        ExcelUtil.exportExcel(list, "包活工单员工关联", PayBaohuoEmployeeVo.class, response);
    }

    /**
     * 获取包活工单员工关联详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pay:baohuoEmployee:query")
    @GetMapping("/{id}")
    public R<PayBaohuoEmployeeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iPayBaohuoEmployeeService.queryById(id));
    }

    /**
     * 新增包活工单员工关联
     */
    @SaCheckPermission("pay:baohuoEmployee:add")
    @Log(title = "包活工单员工关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayBaohuoEmployeeBo bo) {
        return toAjax(iPayBaohuoEmployeeService.insertByBo(bo));
    }

    /**
     * 修改包活工单员工关联
     */
    @SaCheckPermission("pay:baohuoEmployee:edit")
    @Log(title = "包活工单员工关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayBaohuoEmployeeBo bo) {
        return toAjax(iPayBaohuoEmployeeService.updateByBo(bo));
    }

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