package com.yongqi.xinrenli.controller;

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 com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.yongqi.xinrenli.domain.vo.DbWxUserVo;
import com.yongqi.xinrenli.domain.bo.DbWxUserBo;
import com.yongqi.xinrenli.service.IDbWxUserService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信用户
 *
 * @author zyf
 * @date 2023-03-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xinrenli/wxUser")
public class DbWxUserController extends BaseController {

    private final IDbWxUserService iDbWxUserService;

    /**
     * 查询微信用户列表
     */
    @SaCheckPermission("xinrenli:wxUser:list")
    @GetMapping("/list")
    public TableDataInfo<DbWxUserVo> list(DbWxUserBo bo, PageQuery pageQuery) {
        return iDbWxUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出微信用户列表
     */
    @SaCheckPermission("xinrenli:wxUser:export")
    @Log(title = "微信用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DbWxUserBo bo, HttpServletResponse response) {
        List<DbWxUserVo> list = iDbWxUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "微信用户", DbWxUserVo.class, response);
    }

    /**
     * 获取微信用户详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xinrenli:wxUser:query")
    @GetMapping("/{id}")
    public R<DbWxUserVo> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long id) {
        return R.ok(iDbWxUserService.queryById(id));
    }

    /**
     * 新增微信用户
     */
    @SaCheckPermission("xinrenli:wxUser:add")
    @Log(title = "微信用户", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DbWxUserBo bo) {
        return toAjax(iDbWxUserService.insertByBo(bo));
    }

    /**
     * 修改微信用户
     */
    @SaCheckPermission("xinrenli:wxUser:edit")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DbWxUserBo bo) {
        return toAjax(iDbWxUserService.updateByBo(bo));
    }

    /**
     * 删除微信用户
     *
     * @param ids 主键串
     */
    @SaCheckPermission("xinrenli:wxUser:remove")
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iDbWxUserService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
