package net.ferrum.web.controller.business;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import net.ferrum.common.annotation.RepeatSubmit;
import net.ferrum.common.annotation.Log;
import net.ferrum.common.core.controller.BaseController;
import net.ferrum.common.core.domain.PageQuery;
import net.ferrum.common.core.domain.R;
import net.ferrum.common.core.validate.AddGroup;
import net.ferrum.common.core.validate.EditGroup;
import net.ferrum.common.core.validate.QueryGroup;
import net.ferrum.common.enums.BusinessType;
import net.ferrum.common.utils.poi.ExcelUtil;
import net.ferrum.business.domain.vo.QsSpecAttributeTypesVo;
import net.ferrum.business.domain.bo.QsSpecAttributeTypesBo;
import net.ferrum.business.service.IQsSpecAttributeTypesService;
import net.ferrum.common.core.page.TableDataInfo;

/**
 * 规格类型
 *
 * @author ruoyi
 * @date 2025-07-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/specAttributeTypes")
public class QsSpecAttributeTypesController extends BaseController {

    private final IQsSpecAttributeTypesService iQsSpecAttributeTypesService;

    /**
     * 查询规格类型列表
     */
    @SaCheckPermission("business:specAttributeTypes:list")
    @GetMapping("/list")
    public TableDataInfo<QsSpecAttributeTypesVo> list(QsSpecAttributeTypesBo bo, PageQuery pageQuery) {
        return iQsSpecAttributeTypesService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出规格类型列表
     */
    @SaCheckPermission("business:specAttributeTypes:export")
    @Log(title = "规格类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(QsSpecAttributeTypesBo bo, HttpServletResponse response) {
        List<QsSpecAttributeTypesVo> list = iQsSpecAttributeTypesService.queryList(bo);
        ExcelUtil.exportExcel(list, "规格类型", QsSpecAttributeTypesVo.class, response);
    }

    /**
     * 获取规格类型详细信息
     *
     * @param typeId 主键
     */
    @SaCheckPermission("business:specAttributeTypes:query")
    @GetMapping("/{typeId}")
    public R<QsSpecAttributeTypesVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long typeId) {
        return R.ok(iQsSpecAttributeTypesService.queryById(typeId));
    }

    /**
     * 新增规格类型
     */
    @SaCheckPermission("business:specAttributeTypes:add")
    @Log(title = "规格类型", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody QsSpecAttributeTypesBo bo) {
        return toAjax(iQsSpecAttributeTypesService.insertByBo(bo));
    }

    /**
     * 修改规格类型
     */
    @SaCheckPermission("business:specAttributeTypes:edit")
    @Log(title = "规格类型", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody QsSpecAttributeTypesBo bo) {
        return toAjax(iQsSpecAttributeTypesService.updateByBo(bo));
    }

    /**
     * 删除规格类型
     *
     * @param typeIds 主键串
     */
    @SaCheckPermission("business:specAttributeTypes:remove")
    @Log(title = "规格类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] typeIds) {
        return toAjax(iQsSpecAttributeTypesService.deleteWithValidByIds(Arrays.asList(typeIds), true));
    }
}
