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.PayWorkOrderInfoVo;
import com.ruoyi.pay.domain.bo.PayWorkOrderInfoBo;
import com.ruoyi.pay.service.IPayWorkOrderInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单信息
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/workOrderInfo")
public class PayWorkOrderInfoController extends BaseController {

    private final IPayWorkOrderInfoService iPayWorkOrderInfoService;

    /**
     * 查询工单信息列表
     */
    @SaCheckPermission("pay:workOrderInfo:list")
    @GetMapping("/list")
    public TableDataInfo<PayWorkOrderInfoVo> list(PayWorkOrderInfoBo bo, PageQuery pageQuery) {
        return iPayWorkOrderInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工单信息列表
     */
    @SaCheckPermission("pay:workOrderInfo:export")
    @Log(title = "工单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayWorkOrderInfoBo bo, HttpServletResponse response) {
        List<PayWorkOrderInfoVo> list = iPayWorkOrderInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "工单信息", PayWorkOrderInfoVo.class, response);
    }

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

    /**
     * 新增工单信息
     */
    @SaCheckPermission("pay:workOrderInfo:add")
    @Log(title = "工单信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayWorkOrderInfoBo bo) {
        return toAjax(iPayWorkOrderInfoService.insertByBo(bo));
    }

    /**
     * 修改工单信息
     */
    @SaCheckPermission("pay:workOrderInfo:edit")
    @Log(title = "工单信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayWorkOrderInfoBo bo) {
        return toAjax(iPayWorkOrderInfoService.updateByBo(bo));
    }

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