|
|
@@ -5,6 +5,7 @@ import com.grkj.data.dao.RoleDao
|
|
|
import com.grkj.data.dao.SysMenuDao
|
|
|
import com.grkj.data.dao.UserDao
|
|
|
import com.grkj.data.data.MainDomainData
|
|
|
+import com.grkj.data.enums.LoginResultEnum
|
|
|
import com.grkj.data.enums.RoleEnum
|
|
|
import com.grkj.data.enums.RoleFunctionalPermissionsEnum
|
|
|
import com.grkj.data.model.dos.SysUserCharacteristicDo
|
|
|
@@ -43,10 +44,10 @@ class UserRepository @Inject constructor(
|
|
|
|
|
|
override fun loginWithAccount(
|
|
|
username: String, password: String
|
|
|
- ): Boolean {
|
|
|
+ ): LoginResultEnum {
|
|
|
val sysUserDo = userDao.getUserInfoByUsername(username)
|
|
|
if (sysUserDo == null) {
|
|
|
- return false
|
|
|
+ return LoginResultEnum.USERNAME_PASSWORD_NOT_EXISTS
|
|
|
}
|
|
|
val matched = BCryptUtils.matchPassword(password, sysUserDo.password ?: "")
|
|
|
logger.info("密码是否匹配:${password},${sysUserDo.password},${matched}")
|
|
|
@@ -66,14 +67,15 @@ class UserRepository @Inject constructor(
|
|
|
logger.info("用户信息:{}", MainDomainData.userInfo.toString())
|
|
|
logger.info("用户角色:{}", MainDomainData.roleKeys)
|
|
|
logger.info("用户权限:{}", MainDomainData.permissions)
|
|
|
+ return LoginResultEnum.USERNAME_PASSWORD_LOGIN_SUCCESS
|
|
|
}
|
|
|
- return matched
|
|
|
+ return LoginResultEnum.USERNAME_OR_PASSWORD_ERROR
|
|
|
}
|
|
|
|
|
|
- override fun loginWithCard(cardnfc: String): Boolean {
|
|
|
+ override fun loginWithCard(cardnfc: String): LoginResultEnum {
|
|
|
val userId = hardwareDao.getUserIdByCardNfc(cardnfc)?.toString()
|
|
|
if (userId == null) {
|
|
|
- return false
|
|
|
+ return LoginResultEnum.JOB_CARD_LOGIN_FAILED
|
|
|
} else {
|
|
|
val sysUserDo = userDao.getUserInfoByUserId(userId)
|
|
|
if (sysUserDo != null) {
|
|
|
@@ -89,8 +91,9 @@ class UserRepository @Inject constructor(
|
|
|
logger.info("用户信息:{}", MainDomainData.userInfo.toString())
|
|
|
logger.info("用户角色:{}", MainDomainData.roleKeys)
|
|
|
logger.info("用户权限:{}", MainDomainData.permissions)
|
|
|
+ return LoginResultEnum.JOB_CARD_LOGIN_SUCCESS
|
|
|
}
|
|
|
- return userDao.getUserInfoByUserId(userId) != null
|
|
|
+ return LoginResultEnum.JOB_CARD_LOGIN_FAILED
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -110,61 +113,69 @@ class UserRepository @Inject constructor(
|
|
|
userDao.updateUserInfo(userId, nickName, phone)
|
|
|
}
|
|
|
|
|
|
- override fun checkCard(cardNo: String): Boolean {
|
|
|
+ override fun checkCard(cardNo: String): LoginResultEnum {
|
|
|
val userId = hardwareDao.getUserIdByCardNfc(cardNo)?.toString()
|
|
|
- return userId?.let {
|
|
|
+ if (userId == null) {
|
|
|
+ return LoginResultEnum.JOB_CARD_LOGIN_FAILED
|
|
|
+ } else {
|
|
|
val sysUserDo = userDao.getUserInfoByUserId(userId)
|
|
|
- sysUserDo != null
|
|
|
- } == true
|
|
|
- }
|
|
|
-
|
|
|
- override suspend fun loginWithFingerprint(fingerprint: String): Boolean = coroutineScope {
|
|
|
- val fingerprintDataList = userDao.getFingerprintData()
|
|
|
- if (fingerprintDataList.isEmpty()) return@coroutineScope false
|
|
|
-
|
|
|
- /* ① 并发计算匹配分数 */
|
|
|
- val deferred = fingerprintDataList.map { fpData ->
|
|
|
- async(Dispatchers.Default) {
|
|
|
- if (fpData.content.isEmpty()) return@async null
|
|
|
- val score =
|
|
|
- BiometricVerifier.verifyFingerprint(fingerprint, fpData.content) // suspend
|
|
|
- if (score >= 40) Pair(fpData, score) else null
|
|
|
+ if (sysUserDo != null) {
|
|
|
+ return LoginResultEnum.JOB_CARD_LOGIN_SUCCESS
|
|
|
}
|
|
|
}
|
|
|
+ return LoginResultEnum.JOB_CARD_LOGIN_FAILED
|
|
|
+ }
|
|
|
|
|
|
- /* ② 找到最高分(若无满足阈值则 null) */
|
|
|
- val bestMatch = deferred.awaitAll()
|
|
|
- .filterNotNull()
|
|
|
- .maxByOrNull { it.second } // second == score
|
|
|
+ override suspend fun loginWithFingerprint(fingerprint: String): LoginResultEnum =
|
|
|
+ coroutineScope {
|
|
|
+ val fingerprintDataList = userDao.getFingerprintData()
|
|
|
+ if (fingerprintDataList.isEmpty()) return@coroutineScope LoginResultEnum.FINGERPRINTER_VERIFY_FAILED
|
|
|
+
|
|
|
+ /* ① 并发计算匹配分数 */
|
|
|
+ val deferred = fingerprintDataList.map { fpData ->
|
|
|
+ async(Dispatchers.Default) {
|
|
|
+ if (fpData.content.isEmpty()) return@async null
|
|
|
+ val score =
|
|
|
+ BiometricVerifier.verifyFingerprint(fingerprint, fpData.content) // suspend
|
|
|
+ if (score >= 40) Pair(fpData, score) else null
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- /* ③ 若匹配成功,加载用户信息 */
|
|
|
- if (bestMatch != null) {
|
|
|
- val fpData = bestMatch.first
|
|
|
- val sysUserDo = userDao.getUserInfoByUserId(fpData.userId.toString())
|
|
|
- if (sysUserDo != null) {
|
|
|
- // —— 缓存域数据 —— //
|
|
|
- MainDomainData.userInfo = sysUserDo
|
|
|
- MainDomainData.userCardList = hardwareDao.getIsJobCardByUserId(sysUserDo.userId)
|
|
|
- MainDomainData.roleKeys =
|
|
|
- roleDao.getRoleDataByUserId(sysUserDo.userId).joinToString(",") { it.roleKey }
|
|
|
- MainDomainData.permissions =
|
|
|
- sysMenuDao.getPermissionsByRoleIds(
|
|
|
- roleDao.getRoleDataByUserId(sysUserDo.userId).map { it.roleId }
|
|
|
- )
|
|
|
- MainDomainData.userBiometricDataVo = userDao.getUserBiometricData(sysUserDo.userId)
|
|
|
-
|
|
|
- logger.info("用户信息: {}", MainDomainData.userInfo)
|
|
|
- logger.info("用户角色: {}", MainDomainData.roleKeys)
|
|
|
- logger.info("用户权限: {}", MainDomainData.permissions)
|
|
|
- return@coroutineScope true
|
|
|
+ /* ② 找到最高分(若无满足阈值则 null) */
|
|
|
+ val bestMatch = deferred.awaitAll()
|
|
|
+ .filterNotNull()
|
|
|
+ .maxByOrNull { it.second } // second == score
|
|
|
+
|
|
|
+ /* ③ 若匹配成功,加载用户信息 */
|
|
|
+ if (bestMatch != null) {
|
|
|
+ val fpData = bestMatch.first
|
|
|
+ val sysUserDo = userDao.getUserInfoByUserId(fpData.userId.toString())
|
|
|
+ if (sysUserDo != null) {
|
|
|
+ // —— 缓存域数据 —— //
|
|
|
+ MainDomainData.userInfo = sysUserDo
|
|
|
+ MainDomainData.userCardList = hardwareDao.getIsJobCardByUserId(sysUserDo.userId)
|
|
|
+ MainDomainData.roleKeys =
|
|
|
+ roleDao.getRoleDataByUserId(sysUserDo.userId)
|
|
|
+ .joinToString(",") { it.roleKey }
|
|
|
+ MainDomainData.permissions =
|
|
|
+ sysMenuDao.getPermissionsByRoleIds(
|
|
|
+ roleDao.getRoleDataByUserId(sysUserDo.userId).map { it.roleId }
|
|
|
+ )
|
|
|
+ MainDomainData.userBiometricDataVo =
|
|
|
+ userDao.getUserBiometricData(sysUserDo.userId)
|
|
|
+
|
|
|
+ logger.info("用户信息: {}", MainDomainData.userInfo)
|
|
|
+ logger.info("用户角色: {}", MainDomainData.roleKeys)
|
|
|
+ logger.info("用户权限: {}", MainDomainData.permissions)
|
|
|
+ return@coroutineScope LoginResultEnum.FINGERPRINTER_VERIFY_SUCCESS
|
|
|
+ }
|
|
|
}
|
|
|
+ LoginResultEnum.FINGERPRINTER_VERIFY_FAILED
|
|
|
}
|
|
|
- false
|
|
|
- }
|
|
|
|
|
|
- override suspend fun checkFingerprint(fingerprint: String): Boolean = coroutineScope {
|
|
|
+ override suspend fun checkFingerprint(fingerprint: String): LoginResultEnum = coroutineScope {
|
|
|
val fingerprintDataList = userDao.getFingerprintData()
|
|
|
- if (fingerprintDataList.isEmpty()) return@coroutineScope false
|
|
|
+ if (fingerprintDataList.isEmpty()) return@coroutineScope LoginResultEnum.FINGERPRINTER_VERIFY_FAILED
|
|
|
|
|
|
/* ① 并发计算匹配分数 */
|
|
|
val deferred = fingerprintDataList.map { fpData ->
|
|
|
@@ -183,24 +194,22 @@ class UserRepository @Inject constructor(
|
|
|
if (bestMatch != null) {
|
|
|
val fpData = bestMatch.first
|
|
|
val sysUserDo = userDao.getUserInfoByUserId(fpData.userId.toString())
|
|
|
- sysUserDo != null
|
|
|
+ LoginResultEnum.FINGERPRINTER_VERIFY_SUCCESS
|
|
|
} else {
|
|
|
- false
|
|
|
+ LoginResultEnum.FINGERPRINTER_VERIFY_FAILED
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun loginWithFace(face: String): Boolean {
|
|
|
+ override fun loginWithFace(face: String): LoginResultEnum {
|
|
|
val faceDataList = userDao.getFaceData()
|
|
|
if (faceDataList.isEmpty()) {
|
|
|
- return false
|
|
|
+ return LoginResultEnum.FACE_VERIFY_FAILED
|
|
|
}
|
|
|
- var hasFace = false
|
|
|
var userId: String? = null
|
|
|
for (faceData in faceDataList) {
|
|
|
if (faceData.content.isNotEmpty()) {
|
|
|
val fileData = faceData.content.file().readText()
|
|
|
if (BiometricVerifier.verifyFaceArcSoft(face, fileData)) {
|
|
|
- hasFace = true
|
|
|
userId = faceData.userId.toString()
|
|
|
break
|
|
|
}
|
|
|
@@ -221,28 +230,24 @@ class UserRepository @Inject constructor(
|
|
|
logger.info("用户信息:{}", MainDomainData.userInfo.toString())
|
|
|
logger.info("用户角色:{}", MainDomainData.roleKeys)
|
|
|
logger.info("用户权限:{}", MainDomainData.permissions)
|
|
|
- hasFace = true
|
|
|
+ return LoginResultEnum.FACE_VERIFY_SUCCESS
|
|
|
} else {
|
|
|
- hasFace = false
|
|
|
+ return LoginResultEnum.FACE_VERIFY_FAILED
|
|
|
}
|
|
|
- } else {
|
|
|
- hasFace = false
|
|
|
}
|
|
|
- return hasFace
|
|
|
+ return LoginResultEnum.FACE_VERIFY_FAILED
|
|
|
}
|
|
|
|
|
|
- override fun checkFace(face: String): Boolean {
|
|
|
+ override fun checkFace(face: String): LoginResultEnum {
|
|
|
val faceDataList = userDao.getFaceData()
|
|
|
if (faceDataList.isEmpty()) {
|
|
|
- return false
|
|
|
+ return LoginResultEnum.FACE_VERIFY_FAILED
|
|
|
}
|
|
|
- var hasFace = false
|
|
|
var userId: String? = null
|
|
|
for (faceData in faceDataList) {
|
|
|
if (faceData.content.isNotEmpty()) {
|
|
|
val fileData = faceData.content.file().readText()
|
|
|
if (BiometricVerifier.verifyFaceArcSoft(face, fileData)) {
|
|
|
- hasFace = true
|
|
|
userId = faceData.userId.toString()
|
|
|
break
|
|
|
}
|
|
|
@@ -250,15 +255,13 @@ class UserRepository @Inject constructor(
|
|
|
}
|
|
|
if (userId != null) {
|
|
|
val sysUserDo = userDao.getUserInfoByUserId(userId)
|
|
|
- hasFace = if (sysUserDo != null) {
|
|
|
- true
|
|
|
+ if (sysUserDo != null) {
|
|
|
+ return LoginResultEnum.FACE_VERIFY_SUCCESS
|
|
|
} else {
|
|
|
- false
|
|
|
+ return LoginResultEnum.FACE_VERIFY_FAILED
|
|
|
}
|
|
|
- } else {
|
|
|
- hasFace = false
|
|
|
}
|
|
|
- return hasFace
|
|
|
+ return LoginResultEnum.FACE_VERIFY_FAILED
|
|
|
}
|
|
|
|
|
|
override fun logout(): Boolean {
|