package org.dromara.zhishu.controller;

import java.util.List;
import java.util.Map;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.zhishu.domain.SynchronizationShopLog;
import org.dromara.zhishu.domain.bo.SynchronizationShopLogBo;
import org.dromara.zhishu.domain.vo.SynchronizationShopLogVo;
import org.dromara.zhishu.service.ISynchronizationShopLogService;
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.common.mybatis.core.page.TableDataInfo;

/**
 * 同步店铺商品库存日志
 *
 * @author yxy
 * @date 2026-04-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhishu/synchronizationShopLog")
public class SynchronizationShopLogController extends BaseController {

    private final ISynchronizationShopLogService synchronizationShopLogService;

    /**
     * 查询同步店铺商品库存日志列表
     */
    @SaCheckPermission("zhishu:synchronizationShopLog:list")
    @GetMapping("/list")
    public TableDataInfo<Map<String, Object>> list(SynchronizationShopLogBo bo, PageQuery pageQuery) {
        return synchronizationShopLogService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/getLogList")
    public List<SynchronizationShopLogVo> getLogList(SynchronizationShopLogBo bo){
        return synchronizationShopLogService.queryList(bo);
    }

    /**
     * 导出同步店铺商品库存日志列表
     */
    @SaCheckPermission("zhishu:synchronizationShopLog:export")
    @Log(title = "同步店铺商品库存日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SynchronizationShopLogBo bo, HttpServletResponse response) {
        List<SynchronizationShopLogVo> list = synchronizationShopLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "同步店铺商品库存日志", SynchronizationShopLogVo.class, response);
    }

    /**
     * 获取同步店铺商品库存日志详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zhishu:synchronizationShopLog:query")
    @GetMapping("/{id}")
    public R<SynchronizationShopLogVo> getInfo(@NotNull(message = "主键不能为空")
                                               @PathVariable Long id) {
        return R.ok(synchronizationShopLogService.queryById(id));
    }
}