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.TpWechatUserBo;
import org.dromara.work.domain.vo.TpWechatUserVo;
import org.dromara.work.service.ITpWechatUserService;
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/wechatUser")
public class TpWechatUserController extends BaseController {

    private final ITpWechatUserService tpWechatUserService;

    /**
     * 查询微信使用人修改历史列表
     */
    @SaCheckPermission("work:wechatUser:list")
    @GetMapping("/list")
    public TableDataInfo<TpWechatUserVo> list(TpWechatUserBo bo, PageQuery pageQuery) {
        return tpWechatUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出微信使用人修改历史列表
     */
    @SaCheckPermission("work:wechatUser:export")
    @Log(title = "微信使用人修改历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TpWechatUserBo bo, HttpServletResponse response) {
        List<TpWechatUserVo> list = tpWechatUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "微信使用人修改历史", TpWechatUserVo.class, response);
    }

    /**
     * 获取微信使用人修改历史详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("work:wechatUser:query")
    @GetMapping("/{id}")
    public R<TpWechatUserVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tpWechatUserService.queryById(id));
    }

    /**
     * 新增微信使用人修改历史
     */
    @SaCheckPermission("work:wechatUser:add")
    @Log(title = "微信使用人修改历史", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TpWechatUserBo bo) {
        return toAjax(tpWechatUserService.insertByBo(bo));
    }

    /**
     * 修改微信使用人修改历史
     */
    @SaCheckPermission("work:wechatUser:edit")
    @Log(title = "微信使用人修改历史", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TpWechatUserBo bo) {
        return toAjax(tpWechatUserService.updateByBo(bo));
    }

    /**
     * 删除微信使用人修改历史
     *
     * @param ids 主键串
     */
    @SaCheckPermission("work:wechatUser:remove")
    @Log(title = "微信使用人修改历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tpWechatUserService.deleteWithValidByIds(List.of(ids), true));
    }
}
