From 752e00503f672ddfe2066afb6c235721a3a912b5 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 19 十一月 2024 10:25:55 +0800
Subject: [PATCH] 2024.11.19 各项修正

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/AuthServiceImpl.kt |  118 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 97 insertions(+), 21 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/AuthServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/AuthServiceImpl.kt
index 7262457..8303530 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/AuthServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/AuthServiceImpl.kt
@@ -7,6 +7,7 @@
 import cn.flightfeather.supervision.infrastructure.utils.PinYin
 import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
 import cn.flightfeather.supervision.lightshare.service.AuthService
+import cn.flightfeather.supervision.lightshare.vo.AuthSceneIndVo
 import cn.flightfeather.supervision.lightshare.vo.AuthSceneRestVo
 import cn.flightfeather.supervision.lightshare.vo.AuthSceneVo
 import cn.flightfeather.supervision.lightshare.vo.BaseResponse
@@ -14,6 +15,7 @@
 import org.springframework.stereotype.Service
 import org.springframework.transaction.annotation.Transactional
 import tk.mybatis.mapper.entity.Example
+import java.util.*
 
 @Service
 class AuthServiceImpl(
@@ -25,7 +27,9 @@
     private val fumePurifyDeviceMapper: FumePurifyDeviceMapper,
     private val monitorDeviceMapper: MonitorDeviceMapper,
     private val restaurantBaseInfoMapper: RestaurantBaseInfoMapper,
-    private val vehicleBaseInfoMapper: VehicleBaseInfoMapper
+    private val vehicleBaseInfoMapper: VehicleBaseInfoMapper,
+    private val industrialBaseInfoMapper: IndustrialBaseInfoMapper,
+    private val vocPurifyDeviceMapper: VocPurifyDeviceMapper,
 ): AuthService {
 
     @Transactional
@@ -43,6 +47,17 @@
             bInfo.ciGuid = company.ciGuid
             bInfo.ciName = company.ciName
             baseInfoMapper.updateByPrimaryKeySelective(bInfo)
+        } else if (bInfo == null) {
+            val userInfo = userinfoMapper.selectByPrimaryKey(wxUser.uiGuid)
+            val baseInfo = BaseInfo().apply {
+                biGuid = wxUser.uiGuid
+                biName = userInfo?.realname
+                ciGuid = company.ciGuid
+                ciName = company.ciName
+                biCreateTime = Date()
+                biExtension1 = userInfo?.acountname
+            }
+            baseInfoMapper.insertSelective(baseInfo)
         }
         if (wxUser.ciGuid != company.ciGuid) {
             wxUser.ciGuid = company.ciGuid
@@ -61,25 +76,34 @@
         var bInfo = if (wxUser.uiGuid == null) null else baseInfoMapper.selectByPrimaryKey(wxUser.uiGuid)
         if (bInfo == null) {
             val cInfo = if (wxUser.ciGuid == null) null else companyMapper.selectByPrimaryKey(wxUser.ciGuid)
-            val name = getUName(asVo.biName ?: "")
-            //鏂板缓鍦烘櫙璐﹀彿鍙婂満鏅俊鎭�
-            val newUser = Userinfo().apply {
-                guid = UUIDGenerator.generate16ShortUUID()
-                acountname = name
-                realname = asVo.biName
-                password = "123456"
-                usertypeid = 3
-                usertype = "浼佷笟"
-                isenable = true
-                if (asVo.biLocation.isNotEmpty()) extension1 = asVo.biLocation[2]
-                extension2 = sceneType.toString()
+            val user = userinfoMapper.selectByPrimaryKey(wxUser.uiGuid)
+            if (user == null) {
+                val name = getUName(asVo.biName ?: "")
+                //鏂板缓鍦烘櫙璐﹀彿鍙婂満鏅俊鎭�
+                val user = Userinfo().apply {
+                    guid = UUIDGenerator.generate16ShortUUID()
+                    acountname = name
+                    realname = asVo.biName
+                    password = "123456"
+                    usertypeid = 3
+                    usertype = "浼佷笟"
+                    isenable = true
+                    if (asVo.biLocation.isNotEmpty()) extension1 = asVo.biLocation[2]
+                    extension2 = sceneType.toString()
+                }
+                userinfoMapper.insert(user)
+            } else {
+                user.apply {
+                    realname = asVo.biName
+                    if (asVo.biLocation.isNotEmpty()) extension1 = asVo.biLocation[2]
+                }
+                userinfoMapper.updateByPrimaryKeySelective(user)
             }
-            bInfo = asVo.toNewBaseInfo(newUser, cInfo)
-            userinfoMapper.insert(newUser)
+            bInfo = asVo.toNewBaseInfo(user, cInfo)
             baseInfoMapper.insert(bInfo)
         } else {
             val userInfo = userinfoMapper.selectByPrimaryKey(bInfo.biGuid)
-            userInfo.apply {
+            userInfo?.apply {
                 realname = asVo.biName
                 if (asVo.biLocation.isNotEmpty()) extension1 = asVo.biLocation[2]
             }
@@ -136,7 +160,18 @@
                 val info = gson.fromJson(sceneInfo, AuthSceneVo::class.java)
             }
             SceneType.Industrial.value -> {
-                val info = gson.fromJson(sceneInfo, AuthSceneVo::class.java)
+                val info = gson.fromJson(sceneInfo, AuthSceneIndVo::class.java)
+                //宸ヤ笟浼佷笟鍩烘湰淇℃伅褰曞叆
+                var rbInfo = industrialBaseInfoMapper.selectByPrimaryKey(userId)
+                if (rbInfo == null) {
+                    rbInfo = info.toNewIndInfo(userId)
+                    industrialBaseInfoMapper.insert(rbInfo)
+                } else {
+                    info.updateIndInfo(rbInfo)
+                    industrialBaseInfoMapper.updateByPrimaryKeySelective(rbInfo)
+                }
+//                industrialBaseInfoMapper
+//                vocPurifyDeviceMapper
             }
             SceneType.VehicleRepair.value -> {
                 val info = gson.fromJson(sceneInfo, AuthSceneVo::class.java)
@@ -150,6 +185,8 @@
     override fun authPersonal(wxUserId: String, personalInfo: PersonalInfo): BaseResponse<String> {
         val wxUser = userInfoWxMapper.selectByPrimaryKey(wxUserId) ?: return BaseResponse(false, "鐢ㄦ埛寰俊id涓嶅瓨鍦�")
         personalInfo.piExtension3 = AuthenticationStatus.YES.des
+        personalInfo.piWxId = wxUserId
+        personalInfo.piSceneId = wxUser.uiGuid
         if (personalInfo.piGuid == null) {
             personalInfo.piGuid = UUIDGenerator.generate16ShortUUID()
             personalInfoMapper.insert(personalInfo)
@@ -180,12 +217,16 @@
                 }
             }
             //鍒ゆ柇涓汉淇℃伅鏄惁璁よ瘉
-            if (wxUser.piGuid != null) {
-                personalInfoMapper.selectByPrimaryKey(wxUser.piGuid)?.let { p ->
+            if (wxUser.uiGuid != null) {
+                personalInfoMapper.selectByExample(Example(PersonalInfo::class.java).apply {
+                    createCriteria().andEqualTo("piSceneId", wxUser.uiGuid)
+                        .andEqualTo("piWxId", wxUser.uiOpenId)
+                })?.takeIf { it.isNotEmpty() }?.get(0)?.let { p ->
                     if (p.piExtension3 == AuthenticationStatus.YES.des) status[2] = true
                 }
             }
-        }else if (userId != null) {
+        }
+        if (userId != null) {
             val user = userinfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false, "璇ュ満鏅处鎴蜂笉瀛樺湪")
             val baseInfo = baseInfoMapper.selectByPrimaryKey(userId)
             //鍒ゆ柇浼佷笟淇℃伅鏄惁璁よ瘉
@@ -197,7 +238,37 @@
             //鍒ゆ柇鍦烘櫙淇℃伅鏄惁璁よ瘉
             if (baseInfo?.biExtension3 == AuthenticationStatus.YES.des) status[1] = true
             //鍒ゆ柇涓汉淇℃伅鏄惁璁よ瘉
-            // TODO: 2022/10/11 姝ゅ垎鏀笅鏆傛椂鏃犱釜浜鸿璇�
+            userInfoWxMapper.selectByExample(Example(UserInfoWx::class.java).apply {
+                createCriteria().andEqualTo("uiGuid", userId)
+            })?.takeIf { it.isNotEmpty() }?.get(0)?.let {
+                personalInfoMapper.selectByExample(Example(PersonalInfo::class.java).apply {
+                    createCriteria().andEqualTo("piSceneId", it.uiGuid)
+                        .andEqualTo("piWxId", it.uiOpenId)
+                })?.takeIf { it.isNotEmpty() }?.get(0)?.let { p ->
+                    if (p.piExtension3 == AuthenticationStatus.YES.des) status[2] = true
+                }
+            }
+        }
+
+        return BaseResponse(true, data = status)
+    }
+
+    override fun sceneAuthStatus(userId: String?): BaseResponse<List<Boolean>> {
+        val status = mutableListOf(false, false, false)
+        val base = baseInfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false, "璇ュ井淇¤处鎴蜂笉瀛樺湪")
+        //鍒ゆ柇浼佷笟淇℃伅鏄惁璁よ瘉
+        if (base.ciGuid != null) {
+            companyMapper.selectByPrimaryKey(base.ciGuid)?.let { c ->
+                if (c.ciExtension3 == AuthenticationStatus.YES.des) status[0] = true
+            }
+        }
+        //鍒ゆ柇鍦烘櫙淇℃伅鏄惁璁よ瘉
+        if (base.biExtension3 == AuthenticationStatus.YES.des) status[1] = true
+        //鍒ゆ柇涓汉淇℃伅鏄惁璁よ瘉
+        personalInfoMapper.selectByExample(Example(PersonalInfo::class.java).apply {
+            createCriteria().andEqualTo("piSceneId", base.biGuid)
+        })?.takeIf { it.isNotEmpty() }?.get(0)?.let { p ->
+            if (p.piExtension3 == AuthenticationStatus.YES.des) status[2] = true
         }
 
         return BaseResponse(true, data = status)
@@ -221,4 +292,9 @@
         if (repeated) uName = UUIDGenerator.generateShortUUID()
         return uName
     }
+
+    override fun getUnAuthedUsers(): BaseResponse<List<Userinfo?>> {
+        val res = userinfoMapper.getUnAuthedUsers()
+        return BaseResponse(true, data = res)
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3