zyp пре 5 дана
родитељ
комит
1436c36361

+ 0 - 1
.gitignore

@@ -8,7 +8,6 @@ target/
 #logback.xml
 application.yml
 
-
 ### STS ###
 .apt_generated
 .classpath

+ 45 - 8
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -991,8 +991,12 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
         if (param.getSource() == 2) {
             //处理多小程序问题
             FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
-            if (fsUserWx ==null || fsUserWx.getOpenId()==null){
-                packetParam.setOpenId(user.getCourseMaOpenId());
+            if (fsUserWx ==null){
+                try {
+                    handleFsUserWx(user,param.getAppId());
+                }catch (Exception e){
+                    logger.error("zyp \n 【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId());
+                }
             }else {
                 packetParam.setOpenId(fsUserWx.getOpenId());
             }
@@ -1101,6 +1105,31 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
 
     }
 
+
+    private void handleFsUserWx(FsUser user, String appId) {
+        // 尝试更新
+        boolean updated = fsUserWxService.lambdaUpdate()
+                .eq(FsUserWx::getFsUserId, user.getUserId())
+                .eq(FsUserWx::getAppId,appId )
+                .eq(FsUserWx::getOpenId, user.getMaOpenId())
+//                .set(FsUserWx::getUnionId, session.getUnionid() == null ? "" : session.getUnionid())
+                .set(FsUserWx::getUpdateTime, new Date())
+                .update();
+
+        // 如果更新失败(记录不存在),则插入
+        if (!updated) {
+            FsUserWx fsUserWx = new FsUserWx();
+            fsUserWx.setType(1);
+            fsUserWx.setFsUserId(user.getUserId());
+            fsUserWx.setAppId(appId);
+            fsUserWx.setOpenId(user.getMaOpenId());
+//            fsUserWx.setUnionId(session.getUnionid() == null ? "" : session.getUnionid());
+            fsUserWx.setCreateTime(new Date());
+            fsUserWx.setUpdateTime(new Date());
+            fsUserWxService.save(fsUserWx);
+        }
+    }
+
     /**
      * 发放红包奖励
      *
@@ -1144,13 +1173,21 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
         // 来源是小程序切换openId
         if (param.getSource() == 2) {
             //处理多小程序问题
-            Company company = companyMapper.selectCompanyById(param.getCompanyId());
-            if (company.getCourseMiniAppId()==null){
-                return R.error("销售公司参数错误,未绑定小程序");
-            }
-            FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(company.getCourseMiniAppId(),user.getUserId(),1);
+//            Company company = companyMapper.selectCompanyById(param.getCompanyId());
+//            if (company.getCourseMiniAppId()==null){
+//                return R.error("销售公司参数错误,未绑定小程序");
+//            }
+            FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1);
             if (fsUserWx ==null || fsUserWx.getOpenId()==null){
-                return R.error("小程序openId参数缺失");
+                packetParam.setOpenId(user.getCourseMaOpenId());
+                try {
+                    handleFsUserWx(user,param.getAppId());
+                }catch (Exception e){
+                    logger.error("zyp \n 【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId());
+                }
+
+            }else {
+                packetParam.setOpenId(fsUserWx.getOpenId());
             }
 
             System.out.println("小程序id"+user.getCourseMaOpenId());

+ 2 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsUserWxServiceImpl.java

@@ -28,6 +28,8 @@ public class FsUserWxServiceImpl extends ServiceImpl<FsUserWxMapper, FsUserWx> i
                         .eq("app_id", appId)
                         .eq("fs_user_id", userId)
                         .eq("type", type)
+                        .orderByDesc("id")
+                        .last("LIMIT 1")
         );
     }
 }