package org.dromara.work.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
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.work.domain.bo.TpOrderBigBo;
import org.dromara.work.domain.vo.TpOrderBigVo;
import org.dromara.work.service.ITpOrderBigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单大图
 *
 * @author Maosw
 * @date 2024-08-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/work/orderBig")
public class TpOrderBigController extends BaseController {

    private final ITpOrderBigService tpOrderBigService;

    /**
     * 查询订单大图列表
     */
    @SaCheckPermission("work:orderBig:list")
    @GetMapping("/list")
    public TableDataInfo<TpOrderBigVo> list(TpOrderBigBo bo, PageQuery pageQuery) {
        return tpOrderBigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出订单大图列表
     */
    @SaCheckPermission("work:orderBig:export")
    @Log(title = "订单大图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TpOrderBigBo bo, HttpServletResponse response) {
        List<TpOrderBigVo> list = tpOrderBigService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单大图", TpOrderBigVo.class, response);
    }

    /**
     * 获取订单大图详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("work:orderBig:query")
    @GetMapping("/{id}")
    public R<TpOrderBigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tpOrderBigService.queryById(id));
    }

    /**
     * 新增订单大图
     */
    @SaCheckPermission("work:orderBig:add")
    @Log(title = "订单大图", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TpOrderBigBo bo) {
        return toAjax(tpOrderBigService.insertByBo(bo));
    }

    /**
     * 修改订单大图
     */
    @SaCheckPermission("work:orderBig:edit")
    @Log(title = "订单大图", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TpOrderBigBo bo) {
        return toAjax(tpOrderBigService.updateByBo(bo));
    }

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