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.dromara.zhishu.domain.CourierLog;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.zhishu.domain.vo.CourierLogVo;
import org.dromara.zhishu.domain.bo.CourierLogBo;
import org.dromara.zhishu.service.ICourierLogService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 快递日志
 *
 * @author yxy
 * @date 2026-03-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhishu/courierLog")
public class CourierLogController extends BaseController {

    private final ICourierLogService courierLogService;

    /**
     * 查询快递日志列表
     */
    @SaCheckPermission("zhishu:courierLog:list")
    @GetMapping("/list")
    public TableDataInfo<CourierLog> list(CourierLogBo bo, PageQuery pageQuery) {
        return courierLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出快递日志列表
     */
    @SaCheckPermission("zhishu:courierLog:export")
    @Log(title = "快递日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CourierLogBo bo, HttpServletResponse response) {
        List<CourierLogVo> list = courierLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "快递日志", CourierLogVo.class, response);
    }

    /**
     * 获取快递日志详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zhishu:courierLog:query")
    @GetMapping("/{id}")
    public R<CourierLogVo> getInfo(@NotNull(message = "主键不能为空")
                                   @PathVariable Long id) {
        return R.ok(courierLogService.queryById(id));
    }

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