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.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.zhishu.domain.vo.ZhishuShopGoodsDetailVo;
import org.dromara.zhishu.domain.bo.ZhishuShopGoodsDetailBo;
import org.dromara.zhishu.service.IZhishuShopGoodsDetailService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 商品信息补全表
 *
 * @author yxy
 * @date 2025-06-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhishu/shopGoodsDetail")
public class ZhishuShopGoodsDetailController extends BaseController {

    private final IZhishuShopGoodsDetailService zhishuShopGoodsDetailService;

    /**
     * 查询商品信息补全表列表
     */
    @SaCheckPermission("zhishu:shopGoodsDetail:list")
    @GetMapping("/list")
    public TableDataInfo<ZhishuShopGoodsDetailVo> list(ZhishuShopGoodsDetailBo bo, PageQuery pageQuery) {
        return zhishuShopGoodsDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商品信息补全表列表
     */
    @SaCheckPermission("zhishu:shopGoodsDetail:export")
    @Log(title = "商品信息补全表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZhishuShopGoodsDetailBo bo, HttpServletResponse response) {
        List<ZhishuShopGoodsDetailVo> list = zhishuShopGoodsDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "商品信息补全表", ZhishuShopGoodsDetailVo.class, response);
    }

    /**
     * 获取商品信息补全表详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zhishu:shopGoodsDetail:query")
    @GetMapping("/{id}")
    public R<ZhishuShopGoodsDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(zhishuShopGoodsDetailService.queryById(id));
    }

    /**
     * 新增商品信息补全表
     */
    @SaCheckPermission("zhishu:shopGoodsDetail:add")
    @Log(title = "商品信息补全表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZhishuShopGoodsDetailBo bo) {
        return toAjax(zhishuShopGoodsDetailService.insertByBo(bo));
    }

    /**
     * 修改商品信息补全表
     */
    @SaCheckPermission("zhishu:shopGoodsDetail:edit")
    @Log(title = "商品信息补全表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZhishuShopGoodsDetailBo bo) {
        return toAjax(zhishuShopGoodsDetailService.updateByBo(bo));
    }

    /**
     * 删除商品信息补全表
     *
     * @param ids 主键串
     */
    @SaCheckPermission("zhishu:shopGoodsDetail:remove")
    @Log(title = "商品信息补全表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(zhishuShopGoodsDetailService.deleteWithValidByIds(List.of(ids), true));
    }
}
