package com.ruoyi.web.controller.info;

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.info.order.domain.vo.OrderWorkerChangeRecordVo;
import com.ruoyi.info.order.domain.bo.OrderWorkerChangeRecordBo;
import com.ruoyi.info.order.service.IOrderWorkerChangeRecordService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 订单更换分配护工记录Controller
 *
 * @author ruoyi
 * @date 2025-09-29
 */
@Validated
@Api(value = "订单更换分配护工记录控制器", tags = {"订单更换分配护工记录管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/order/orderWorkerChangeRecord")
public class OrderWorkerChangeRecordController extends BaseController {

    private final IOrderWorkerChangeRecordService iOrderWorkerChangeRecordService;

    /**
     * 分页查询订单更换分配护工记录列表
     */
    @ApiOperation("查询订单更换分配护工记录列表")
    @SaCheckPermission("order:orderWorkerChangeRecord:list")
    @GetMapping("/page")
    public TableDataInfo<OrderWorkerChangeRecordVo> page(@Validated(QueryGroup.class) OrderWorkerChangeRecordBo bo, PageQuery pageQuery) {
        return iOrderWorkerChangeRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取订单更换分配护工记录详细信息
     */
    @ApiOperation("获取订单更换分配护工记录详细信息")
    @SaCheckPermission("order:orderWorkerChangeRecord:query")
    @GetMapping("/info/{id}")
    public R<OrderWorkerChangeRecordVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iOrderWorkerChangeRecordService.queryById(id));
    }

    /**
     * 新增订单更换分配护工记录
     */
    @ApiOperation("新增订单更换分配护工记录")
    @SaCheckPermission("order:orderWorkerChangeRecord:add")
    @Log(title = "订单更换分配护工记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OrderWorkerChangeRecordBo bo) {
        return toAjax(iOrderWorkerChangeRecordService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改订单更换分配护工记录
     */
    @ApiOperation("修改订单更换分配护工记录")
    @SaCheckPermission("order:orderWorkerChangeRecord:edit")
    @Log(title = "订单更换分配护工记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OrderWorkerChangeRecordBo bo) {
        return toAjax(iOrderWorkerChangeRecordService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除订单更换分配护工记录
     */
    @ApiOperation("删除订单更换分配护工记录")
    @SaCheckPermission("order:orderWorkerChangeRecord:remove")
    @Log(title = "订单更换分配护工记录", businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iOrderWorkerChangeRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 导出订单更换分配护工记录列表
     */
    @ApiOperation("导出订单更换分配护工记录列表")
    @SaCheckPermission("order:orderWorkerChangeRecord:export")
    @Log(title = "订单更换分配护工记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated OrderWorkerChangeRecordBo bo, HttpServletResponse response) {
        List<OrderWorkerChangeRecordVo> list = iOrderWorkerChangeRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单更换分配护工记录", OrderWorkerChangeRecordVo.class, response);
    }

}
