package com.hotwj.platform.resourceManagement.temporary.controller;

import com.hotwj.platform.resourceManagement.temporary.domain.bo.HotTemporaryBo;
import com.hotwj.platform.resourceManagement.temporary.domain.vo.HotTemporaryVo;
import com.hotwj.platform.resourceManagement.temporary.service.IHotTemporaryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前端缓存信息
 *
 * @author shihongwei
 * @date 2026-03-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/resourceManagement/temporary")
@Tag(name = "前端缓存信息", description = "前端缓存信息管理")
public class HotTemporaryController extends BaseController {

    private final IHotTemporaryService hotTemporaryService;

    /**
     * 查询前端缓存信息列表
     */
    //@SaCheckPermission("resourceManagement:temporary:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询前端缓存信息列表")
    public TableDataInfo<HotTemporaryVo> list(HotTemporaryBo bo, PageQuery pageQuery) {
        return hotTemporaryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出前端缓存信息列表
     */
    //@SaCheckPermission("resourceManagement:temporary:export")
    @Log(title = "前端缓存信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出前端缓存信息列表")
    public void export(HotTemporaryBo bo, HttpServletResponse response) {
        List<HotTemporaryVo> list = hotTemporaryService.queryList(bo);
        ExcelUtil.exportExcel(list, "前端缓存信息", HotTemporaryVo.class, response);
    }

    /**
     * 获取前端缓存信息详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("resourceManagement:temporary:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取前端缓存信息详细信息")
    public R<HotTemporaryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @Parameter(name = "id", description = "主键", required = true, example = "1")
                                     @PathVariable String id) {
        return R.ok(hotTemporaryService.queryById(id));
    }

    /**
     * 新增前端缓存信息
     */
    //@SaCheckPermission("resourceManagement:temporary:add")
    @Log(title = "前端缓存信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增前端缓存信息")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotTemporaryBo bo) {
        return toAjax(hotTemporaryService.insertByBo(bo));
    }

    /**
     * 修改前端缓存信息
     */
    //@SaCheckPermission("resourceManagement:temporary:edit")
    @Log(title = "前端缓存信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改前端缓存信息")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotTemporaryBo bo) {
        return toAjax(hotTemporaryService.updateByBo(bo));
    }

    /**
     * 删除前端缓存信息
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("resourceManagement:temporary:remove")
    @Log(title = "前端缓存信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除前端缓存信息")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable String[] ids) {
        return toAjax(hotTemporaryService.deleteWithValidByIds(List.of(ids), true));
    }
}
