From dea7ac55f057052225e3362df74bdf557cffd06c Mon Sep 17 00:00:00 2001 From: hsdllcw Date: Tue, 13 May 2025 09:52:04 +0800 Subject: [PATCH] =?UTF-8?q?[test]=20=E6=89=B9=E9=87=8F=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7VIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/ISysUserServiceTest.kt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/ruoyi-modules/ruoyi-system/src/test/kotlin/com/ruoyi/system/service/ISysUserServiceTest.kt b/ruoyi-modules/ruoyi-system/src/test/kotlin/com/ruoyi/system/service/ISysUserServiceTest.kt index 513c65204..4b96f5e0e 100644 --- a/ruoyi-modules/ruoyi-system/src/test/kotlin/com/ruoyi/system/service/ISysUserServiceTest.kt +++ b/ruoyi-modules/ruoyi-system/src/test/kotlin/com/ruoyi/system/service/ISysUserServiceTest.kt @@ -1,11 +1,16 @@ package com.ruoyi.system.service import com.alibaba.fastjson.JSONObject +import com.ruoyi.common.core.utils.StringUtils +import com.ruoyi.common.core.utils.uuid.IdUtils +import com.ruoyi.common.security.utils.SecurityUtils import com.ruoyi.system.RuoYiSystemApplication +import com.ruoyi.system.api.domain.SysUser import org.junit.runner.RunWith import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.junit4.SpringJUnit4ClassRunner +import java.io.File import kotlin.test.Test @RunWith(SpringJUnit4ClassRunner::class) @@ -18,4 +23,52 @@ class ISysUserServiceTest { fun findByPhoneNumberStartingWithTest() { println(JSONObject.toJSONString(iSysUserService.findByPhoneNumberStartingWith("1"))) } + + @Test + fun batchSetVIP() { + File("/home/hsdllcw/Desktop/嘉迪课堂会员登记表.csv").readLines().map { + it.split(",").let { item -> + mapOf( + "phone" to item[3], + "name" to item[1], + "date" to item[4] + ) + } + }.filter { Regex("\\d+").matches(it["phone"]!!) }.forEach { + print(it) + if (iSysUserService.findByPhoneNumberStartingWith(it["phone"]).firstOrNull()?.also { user -> + setVIP(user, it) + } == null) { + registerByPhoneNumber(it) + println("==========${it["name"]}已注册为VIP==============") + } + } + } + private fun setVIP(user:SysUser, it: Map) { + if (user.roles?.any { role -> role.roleKey == "live-vip" } == true) { + println(":vip") + if (StringUtils.isEmpty(user.remark)) { + user.remark = "${it["name"]}-会员开通时间(${it["date"]})" + iSysUserService.updateUser(user) + } + } else { + println(":普通用户") + user.roleIds = arrayOf(2, 101) + iSysUserService.updateUser(user) + println("\n==========${it["name"]}已设置为VIP==============") + } + } + + private fun registerByPhoneNumber(it: Map) { + val sysUser = SysUser() + sysUser.userName = IdUtils.randomUUID().replace("-".toRegex(), "").substring(0, 30) + sysUser.nickName = "嘉迪" + it["phone"]?.substring((it["phone"]?.length?:0) - 4) + sysUser.phonenumber = it["phone"] + sysUser.password = SecurityUtils.encryptPassword(IdUtils.randomUUID()) + sysUser.deptId = 204 + sysUser.roleIds = arrayOf(2, 101) + sysUser.remark = "${it["name"]}-会员开通时间(${it["date"]})" + iSysUserService.registerUser(sysUser) + setVIP(sysUser, it) + } } \ No newline at end of file