package org.dromara.zhishu.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.zhishu.domain.vo.TShopOrderDetailVo;
import org.dromara.zhishu.domain.bo.TShopOrderDetailBo;
import org.dromara.zhishu.service.ITShopOrderDetailService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 订单详情
 *
 * @author Lion Li
 * @date 2025-03-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhishu/shopOrderDetail")
public class TShopOrderDetailController extends BaseController {

    private final ITShopOrderDetailService tShopOrderDetailService;

    /**
     * 查询订单详情列表
     */
    @SaCheckPermission("zhishu:shopOrderDetail:list")
    @GetMapping("/list")
    public TableDataInfo<TShopOrderDetailVo> list(TShopOrderDetailBo bo, PageQuery pageQuery) {
        return tShopOrderDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出订单详情列表
     */
    @SaCheckPermission("zhishu:shopOrderDetail:export")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TShopOrderDetailBo bo, HttpServletResponse response) {
        List<TShopOrderDetailVo> list = tShopOrderDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单详情", TShopOrderDetailVo.class, response);
    }

    /**
     * 获取订单详情详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zhishu:shopOrderDetail:query")
    @GetMapping("/{id}")
    public R<TShopOrderDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tShopOrderDetailService.queryById(id));
    }

    /**
     * 新增订单详情
     */
    @SaCheckPermission("zhishu:shopOrderDetail:add")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TShopOrderDetailBo bo) {
        return toAjax(tShopOrderDetailService.insertByBo(bo));
    }

    /**
     * 修改订单详情
     */
    @SaCheckPermission("zhishu:shopOrderDetail:edit")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TShopOrderDetailBo bo) {
        return toAjax(tShopOrderDetailService.updateByBo(bo));
    }

    /**
     * 删除订单详情
     *
     * @param ids 主键串
     */
    @SaCheckPermission("zhishu:shopOrderDetail:remove")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tShopOrderDetailService.deleteWithValidByIds(List.of(ids), true));
    }
}
