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.TblTaxiOrderVo;
import org.dromara.system.domain.bo.TblTaxiOrderBo;
import org.dromara.system.service.ITblTaxiOrderService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 打车订单
 *
 * @author Lion Li
 * @date 2024-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/taxiOrder")
public class TblTaxiOrderController extends BaseController {

    private final ITblTaxiOrderService tblTaxiOrderService;

    /**
     * 查询打车订单列表
     */
    //@SaCheckPermission("system:taxiOrder:list")
    @GetMapping("/list")
    public TableDataInfo<TblTaxiOrderVo> list(TblTaxiOrderBo bo, PageQuery pageQuery) {
        return tblTaxiOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出打车订单列表
     */
    //@SaCheckPermission("system:taxiOrder:export")
    @Log(title = "打车订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TblTaxiOrderBo bo, HttpServletResponse response) {
        List<TblTaxiOrderVo> list = tblTaxiOrderService.queryList(bo);
        ExcelUtil.exportExcel(list, "打车订单", TblTaxiOrderVo.class, response);
    }

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

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

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

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