package org.dromara.work.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
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.dromara.work.domain.bo.TpWechatNumBo;
import org.dromara.work.domain.vo.TpWechatNumVo;
import org.dromara.work.service.ITpWechatNumService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 更新好友数记录
 *
 * @author Maosw
 * @date 2024-08-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/work/wechatNum")
public class TpWechatNumController extends BaseController {

    private final ITpWechatNumService tpWechatNumService;

    /**
     * 查询更新好友数记录列表
     */
    @SaCheckPermission("work:wechatNum:list")
    @GetMapping("/list")
    public TableDataInfo<TpWechatNumVo> list(TpWechatNumBo bo, PageQuery pageQuery) {
        return tpWechatNumService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出更新好友数记录列表
     */
    @SaCheckPermission("work:wechatNum:export")
    @Log(title = "更新好友数记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TpWechatNumBo bo, HttpServletResponse response) {
        List<TpWechatNumVo> list = tpWechatNumService.queryList(bo);
        ExcelUtil.exportExcel(list, "更新好友数记录", TpWechatNumVo.class, response);
    }

    /**
     * 获取更新好友数记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("work:wechatNum:query")
    @GetMapping("/{id}")
    public R<TpWechatNumVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tpWechatNumService.queryById(id));
    }

    /**
     * 新增更新好友数记录
     */
    @SaCheckPermission("work:wechatNum:add")
    @Log(title = "更新好友数记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TpWechatNumBo bo) {
        return toAjax(tpWechatNumService.insertByBo(bo));
    }

    /**
     * 修改更新好友数记录
     */
    @SaCheckPermission("work:wechatNum:edit")
    @Log(title = "更新好友数记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TpWechatNumBo bo) {
        return toAjax(tpWechatNumService.updateByBo(bo));
    }

    /**
     * 删除更新好友数记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("work:wechatNum:remove")
    @Log(title = "更新好友数记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tpWechatNumService.deleteWithValidByIds(List.of(ids), true));
    }
}
