package org.dromara.main.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.domain.bo.MainBackOrderBo;
import org.dromara.main.domain.vo.MainBackOrderVo;
import org.dromara.main.service.IMainBackOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/backOrder")
public class MainBackOrderController extends BaseController {

    private final IMainBackOrderService mainBackOrderService;

    /**
     * 查询背调订单列表
     */
    @SaCheckPermission("system:backOrder:list")
    @GetMapping("/list")
    public TableDataInfo<MainBackOrderVo> list(MainBackOrderBo bo, PageQuery pageQuery) {
        return mainBackOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 完成背调订单
     */
    @SaCheckPermission("system:backOrder:complete")
    @PutMapping("/{id}/complete")
    public R<Void> complete(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return toAjax(mainBackOrderService.completeOrder(id));
    }
}
