package org.dromara.system.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.system.domain.vo.TblGoodsOrderVo;
import org.dromara.system.domain.bo.TblGoodsOrderBo;
import org.dromara.system.service.ITblGoodsOrderService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 寄货订单
 *
 * @author Lion Li
 * @date 2024-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/goodsOrder")
public class TblGoodsOrderController extends BaseController {

    private final ITblGoodsOrderService tblGoodsOrderService;

    /**
     * 查询寄货订单列表
     */
    //@SaCheckPermission("system:goodsOrder:list")
    @GetMapping("/list")
    public TableDataInfo<TblGoodsOrderVo> list(TblGoodsOrderBo bo, PageQuery pageQuery) {
        return tblGoodsOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出寄货订单列表
     */
    //@SaCheckPermission("system:goodsOrder:export")
    @Log(title = "寄货订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TblGoodsOrderBo bo, HttpServletResponse response) {
        List<TblGoodsOrderVo> list = tblGoodsOrderService.queryList(bo);
        ExcelUtil.exportExcel(list, "寄货订单", TblGoodsOrderVo.class, response);
    }

    /**
     * 获取寄货订单详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("system:goodsOrder:query")
    @GetMapping("/{id}")
    public R<TblGoodsOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tblGoodsOrderService.queryById(id));
    }

    /**
     * 新增寄货订单
     */
    //@SaCheckPermission("system:goodsOrder:add")
    @Log(title = "寄货订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TblGoodsOrderBo bo) {
        return toAjax(tblGoodsOrderService.insertByBo(bo));
    }

    /**
     * 修改寄货订单
     */
    //@SaCheckPermission("system:goodsOrder:edit")
    @Log(title = "寄货订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TblGoodsOrderBo bo) {
        return toAjax(tblGoodsOrderService.updateByBo(bo));
    }

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