package com.cclotus.register.controller.admin

import com.cclotus.register.domain.WXUser
import com.cclotus.register.service.WXUserService
import com.cclotus.register.vo.WXUserInfoDetail
import com.ruoyi.common.annotation.Log
import com.ruoyi.common.core.controller.BaseController
import com.ruoyi.common.core.domain.AjaxResult
import com.ruoyi.common.core.page.TableDataInfo
import com.ruoyi.common.enums.BusinessType
import com.ruoyi.common.reqParam.PageParam
import com.ruoyi.common.utils.poi.ExcelUtil
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletResponse


@RestController
@RequestMapping("/register/user")
class WXUserController : BaseController() {

    @Autowired
    lateinit var wxUserService: WXUserService

    /**
     * 查询微信用户管理列表
     */
    @GetMapping("/list")
    fun list(wxUser: WXUser, pageParam: PageParam): TableDataInfo {
        return wxUserService.selectWXUserDetailList(wxUser, pageParam)
    }

    /**
     * 导出微信用户管理列表
     */
    @Log(title = "微信用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    fun export(response: HttpServletResponse, wxUser: WXUser) {
        val list = wxUserService.selectWXUserDetailList(wxUser).rows as List<WXUserInfoDetail>
        val util: ExcelUtil<WXUserInfoDetail> = ExcelUtil(WXUserInfoDetail::class.java)
        util.exportExcel(response, list, "微信用户管理数据")
    }

    /**
     * 获取微信用户管理详细信息
     */
    @GetMapping(value = ["/{userId}"])
    fun getInfo(@PathVariable("userId") userId: String): AjaxResult {
        return AjaxResult.success(wxUserService.selectWXUserByUserId(userId))
    }

    /**
     * 删除微信用户管理
     */
    @Log(title = "微信用户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    fun remove(@PathVariable userIds: Array<String>): AjaxResult {
        wxUserService.deleteWXUserByUserIds(userIds)
        return AjaxResult.success()
    }
}

