package com.ruoyi.xq.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
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.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xq.domain.AuthOrder;
import com.ruoyi.xq.dto.admin.authOrder.AuthOrderAdminVo;
import com.ruoyi.xq.service.AuthOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 实名认证订单
 *
 * @author 77
 * @date 2024-04-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xq/authOrder")
public class AuthOrderController extends BaseController {

    private final AuthOrderService authOrderService;

    /**
     * 查询实名认证订单列表
     */
    @SaCheckPermission("xq:authOrder:list")
    @GetMapping("/list")
    public TableDataInfo<AuthOrderAdminVo> list(AuthOrderAdminVo bo, PageQuery pageQuery) {
        Page<AuthOrderAdminVo> page = authOrderService.pageAdmin(pageQuery, bo);
        return TableDataInfo.build(page);
    }

    /**
     * 获取实名认证订单详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xq:authOrder:query")
    @GetMapping("/{id}")
    public R<AuthOrder> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(authOrderService.getById(id));
    }

    /**
     * 新增实名认证订单
     */
    @SaCheckPermission("xq:authOrder:add")
    @Log(title = "实名认证订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AuthOrder bo) {
        return toAjax(authOrderService.save(bo));
    }

    /**
     * 修改实名认证订单
     */
    @SaCheckPermission("xq:authOrder:edit")
    @Log(title = "实名认证订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AuthOrder bo) {
        return toAjax(authOrderService.updateById(bo));
    }

    /**
     * 删除实名认证订单
     *
     * @param ids 主键串
     */
    @SaCheckPermission("xq:authOrder:remove")
    @Log(title = "实名认证订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(authOrderService.removeBatchByIds(Arrays.asList(ids)));
    }
}
