| 
					
				 | 
			
			
				@@ -48,6 +48,7 @@ import com.fs.his.mapper.FsUserIntegralLogsMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.his.mapper.FsUserMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.his.param.WxSendRedPacketParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.his.service.IFsStorePaymentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.fs.his.service.IFsUserIntegralLogsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.his.service.IFsUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.his.service.IFsUserWxService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.fs.his.utils.ConfigUtil; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -253,6 +254,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private BalanceRollbackErrorMapper balanceRollbackErrorMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IFsUserIntegralLogsService iFsUserIntegralLogsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1253,7 +1257,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 尝试获取锁,等待时间5秒,锁过期时间30秒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            boolean isLocked = lock.tryLock(5, 60, TimeUnit.SECONDS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            boolean isLocked = lock.tryLock(5, 300, TimeUnit.SECONDS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (!isLocked) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 logger.warn("获取锁失败,用户ID:{},视频ID:{}", param.getUserId(), param.getVideoId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return R.error("操作频繁,请稍后再试!"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1378,45 +1382,19 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 准备发送红包参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         WxSendRedPacketParam packetParam = new WxSendRedPacketParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //判断是否走服务号openId发红包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (user.getMpOpenId()!=null&&!isNewWxMerchant){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             packetParam.setOpenId(user.getMpOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //修复数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //查询是否绑定小程序 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (fsUserWx ==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (user.getCourseMaOpenId()==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    logger.error(" 【转账openId参数错误】:{}", user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    return R.error("openId参数错误,请清理缓存后重新授权!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                packetParam.setOpenId(user.getCourseMaOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    handleFsUserWx(user,param.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    logger.error(" 【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId(),e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return R.error("openId参数错误,请清理缓存重新授权"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 packetParam.setOpenId(fsUserWx.getOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        packetParam.setOpenId(user.getMpOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        // 来源是小程序切换openId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if (param.getSource() == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            //处理多小程序问题 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            if (fsUserWx ==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    handleFsUserWx(user,param.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    logger.error("【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                packetParam.setOpenId(fsUserWx.getOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            //查出公司绑定openid并赋值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //判断服务号配置是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (StringUtils.isNotEmpty(config.getMpAppId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             packetParam.setMpAppId(config.getMpAppId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1564,20 +1542,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (user.getMpOpenId()!=null&&!isNewWxMerchant){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 packetParam.setOpenId(user.getMpOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //修复数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //查询是否绑定小程序 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 FsUserWx fsUserWx = fsUserWxService.selectByAppIdAndUserId(param.getAppId(),user.getUserId(),1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (fsUserWx ==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (user.getCourseMaOpenId()==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        logger.error(" 【转账openId参数错误】:{}", user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        return R.error("openId参数错误,请清理缓存后重新授权!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    packetParam.setOpenId(user.getCourseMaOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        handleFsUserWx(user,param.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        logger.error(" 【更新或插入用户与小程序的绑定关系失败】:{}", user.getUserId(),e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    return R.error("openId参数错误,请清理缓存重新授权"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     packetParam.setOpenId(fsUserWx.getOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3244,5 +3212,73 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return fsUserCourseVideoMapper.getChooseCourseVideoListByMap(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public R sendAppReward(FsCourseSendRewardUParam param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 获取用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return R.error("会员被停用,无权限,请联系客服!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUserId(), param.getQwExternalId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (log == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return R.error("无记录"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (log.getRewardType() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return R.error("奖励已发放"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 获取配置信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String json = configService.selectConfigByKey("course.config"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 更新用户积分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FsUser userMap=new FsUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userMap.setUserId(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer appAnswerIntegral = config.getAppAnswerIntegral(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (appAnswerIntegral == null ){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            appAnswerIntegral = config.getAnswerIntegral(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userMap.setIntegral(user.getIntegral()+(appAnswerIntegral==null?0:appAnswerIntegral)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        fsUserMapper.updateFsUser(userMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CompletableFuture.runAsync(() -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            FsUserIntegralLogs integralLogs = new FsUserIntegralLogs(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            integralLogs.setIntegral(config.getAppAnswerIntegral().longValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            integralLogs.setUserId(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            integralLogs.setBalance(userMap.getIntegral()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            integralLogs.setLogType(17); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            integralLogs.setBusinessId(StringUtils.isNotEmpty(log.getLogId().toString()) ? log.getLogId().toString() : null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            integralLogs.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            integralLogs.setNickName(user.getNickName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            integralLogs.setPhone(user.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //integralLogs.setId(integralLogsService.getFsUserIntegralLogsInsertId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        fsUserIntegralLogsMapper.insertFsUserIntegralLogs(integralLogs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            iFsUserIntegralLogsService.insertFsUserIntegralLogsMySql(integralLogs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            iFsUserIntegralLogsService.insertFsUserIntegralLogs(integralLogs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //asyncAddIntegralLogs.saveLogAsync(integralLogs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 更新观看记录的奖励类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.setRewardType(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            courseWatchLogMapper.updateFsCourseWatchLog(log); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //转换红包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            FsCourseRedPacketLog redPacketLog = new FsCourseRedPacketLog(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setCourseId(param.getCourseId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setOutBatchNo(integralLogs.getId().toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setCompanyId(param.getCompanyId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setUserId(param.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setVideoId(param.getVideoId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setCompanyUserId(param.getCompanyUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setAmount(BigDecimal.valueOf(config.getAppAnswerIntegral()).divide(BigDecimal.valueOf(1000))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setRemark("点播答题领取积分转"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLog.setWatchLogId(log.getLogId() != null ? log.getLogId() : null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redPacketLogMapper.insertFsCourseRedPacketLog(redPacketLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return R.ok("奖励发放成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |