package org.dromara.work.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.work.domain.vo.TpDynamicsNumVo;
import org.dromara.work.domain.bo.TpDynamicsNumBo;
import org.dromara.work.service.ITpDynamicsNumService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 动态点赞收藏
 *
 * @author Maosw
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/work/dynamicsNum")
public class TpDynamicsNumController extends BaseController {

    private final ITpDynamicsNumService tpDynamicsNumService;

    /**
     * 查询动态点赞收藏列表
     */
    @SaCheckPermission("work:dynamicsNum:list")
    @GetMapping("/list")
    public TableDataInfo<TpDynamicsNumVo> list(TpDynamicsNumBo bo, PageQuery pageQuery) {
        return tpDynamicsNumService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出动态点赞收藏列表
     */
    @SaCheckPermission("work:dynamicsNum:export")
    @Log(title = "动态点赞收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TpDynamicsNumBo bo, HttpServletResponse response) {
        List<TpDynamicsNumVo> list = tpDynamicsNumService.queryList(bo);
        ExcelUtil.exportExcel(list, "动态点赞收藏", TpDynamicsNumVo.class, response);
    }

    /**
     * 获取动态点赞收藏详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("work:dynamicsNum:query")
    @GetMapping("/{id}")
    public R<TpDynamicsNumVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tpDynamicsNumService.queryById(id));
    }

    /**
     * 新增动态点赞收藏
     */
    @SaCheckPermission("work:dynamicsNum:add")
    @Log(title = "动态点赞收藏", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TpDynamicsNumBo bo) {
        return toAjax(tpDynamicsNumService.insertByBo(bo));
    }

    /**
     * 修改动态点赞收藏
     */
    @SaCheckPermission("work:dynamicsNum:edit")
    @Log(title = "动态点赞收藏", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TpDynamicsNumBo bo) {
        return toAjax(tpDynamicsNumService.updateByBo(bo));
    }

    /**
     * 删除动态点赞收藏
     *
     * @param ids 主键串
     */
    @SaCheckPermission("work:dynamicsNum:remove")
    @Log(title = "动态点赞收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tpDynamicsNumService.deleteWithValidByIds(List.of(ids), true));
    }
}
