liweifan %!s(int64=3) %!d(string=hai) anos
pai
achega
14097765a3

+ 10 - 8
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentTotalServiceImpl.java

@@ -10,6 +10,7 @@ import com.yonge.cooleshow.biz.dal.entity.Student;
 import com.yonge.cooleshow.biz.dal.entity.StudentStar;
 import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
 import com.yonge.cooleshow.common.enums.CacheNameEnum;
+import org.redisson.api.RBucket;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -99,7 +100,6 @@ public class StudentTotalServiceImpl extends ServiceImpl<StudentTotalDao, Studen
                 studentTotal.setMusicSheetNum(null == musicTotal.getMusicSheetNum() ? 0 : musicTotal.getMusicSheetNum());
             }
 
-            //todo 缺少累计练习天数 累计练习时长 累计评测次数
             resultList.add(studentTotal);
             redissonClient.getBucket(CacheNameEnum.STUDENT_TOTAL.getRedisKey(studentTotal.getUserId()))
                     .set(studentTotal);
@@ -110,14 +110,17 @@ public class StudentTotalServiceImpl extends ServiceImpl<StudentTotalDao, Studen
 
     @Override
     public StudentTotal getTotalById(Long id) {
-        StudentTotal total = (StudentTotal) redissonClient.getBucket(CacheNameEnum.STUDENT_TOTAL.getRedisKey(id))
-                .get();
-        if (null == total) {
+        RBucket<Object> bucket = redissonClient.getBucket(CacheNameEnum.STUDENT_TOTAL.getRedisKey(id));
+        if (bucket.isExists()) {
+            return (StudentTotal) bucket.get();
+        } else {
             //去数据库查询
-            total = totalStudentTotalById(id);
-            redissonClient.getBucket(CacheNameEnum.STUDENT_TOTAL.getRedisKey(id)).set(total);
+            StudentTotal total = totalStudentTotalById(id);
+            if (null != total) {
+                bucket.set(total);
+            }
+            return total;
         }
-        return total;
     }
 
     @Override
@@ -156,7 +159,6 @@ public class StudentTotalServiceImpl extends ServiceImpl<StudentTotalDao, Studen
             }
         }
 
-        //todo 缺少累计练习天数 累计练习时长 累计评测次数
         redissonClient.getBucket(CacheNameEnum.STUDENT_TOTAL.getRedisKey(studentTotal.getUserId()))
                 .set(studentTotal);
 

+ 17 - 18
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherTotalServiceImpl.java

@@ -10,6 +10,7 @@ import com.yonge.cooleshow.biz.dal.entity.*;
 import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
 import com.yonge.cooleshow.common.enums.CacheNameEnum;
 import com.yonge.cooleshow.biz.dal.service.LiveRoomService;
+import org.redisson.api.RBucket;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -99,12 +100,8 @@ public class TeacherTotalServiceImpl extends ServiceImpl<TeacherTotalDao, Teache
             TeacherTotalVo courseTotal = teacherCourseMap.get(teacher.getUserId());
             if (null != courseTotal) {
                 //课时数
-                if (null != courseTotal.getExpTime()) {
-                    teacherTotal.setExpTime(courseTotal.getExpTime());
-                }
-                if (null != courseTotal.getUnExpTime()) {
-                    teacherTotal.setUnExpTime(courseTotal.getUnExpTime());
-                }
+                teacherTotal.setExpTime(courseTotal.getExpTime());
+                teacherTotal.setUnExpTime(courseTotal.getUnExpTime());
                 //星级
                 Double starGrade = courseTotal.getStarGrade();
                 if (null != starGrade) {
@@ -126,7 +123,6 @@ public class TeacherTotalServiceImpl extends ServiceImpl<TeacherTotalDao, Teache
                     .set(teacherTotal);
         }
         //统计信息入库
-        //批量入库
         saveOrUpdateBatch(resultList);
         return resultList;
     }
@@ -188,19 +184,22 @@ public class TeacherTotalServiceImpl extends ServiceImpl<TeacherTotalDao, Teache
 
     @Override
     public TeacherTotal getTotalById(Long id) {
-        TeacherTotal total = (TeacherTotal) redissonClient.getBucket(CacheNameEnum.TEACHER_TOTAL.getRedisKey(id))
-                .get();
-        if (null == total) {
+        RBucket<Object> bucket = redissonClient.getBucket(CacheNameEnum.TEACHER_TOTAL.getRedisKey(id));
+        if (bucket.isExists()) {
+            return (TeacherTotal) bucket.get();
+        } else {
             //去数据库查询
-            total = totalTeacherTotalById(id);
-            redissonClient.getBucket(CacheNameEnum.TEACHER_TOTAL.getRedisKey(id)).set(total);
+            TeacherTotal total = totalTeacherTotalById(id);
+            if(null != total){
+                bucket.set(total);
+            }
+            return total;
         }
-        return total;
     }
 
     @Override
     public void updateTotalCache(TeacherTotal teacherTotal) {
-        if(null != teacherTotal && null != teacherTotal.getUserId()){
+        if (null != teacherTotal && null != teacherTotal.getUserId()) {
             redissonClient.getBucket(CacheNameEnum.TEACHER_TOTAL.getRedisKey(teacherTotal.getUserId())).set(teacherTotal);
         }
     }
@@ -241,9 +240,9 @@ public class TeacherTotalServiceImpl extends ServiceImpl<TeacherTotalDao, Teache
                 .eq(LiveRoom::getRoomState, 0)
                 .eq(LiveRoom::getType, "TEMP"));
 
-        if(CollectionUtils.isEmpty(templist)){
+        if (CollectionUtils.isEmpty(templist)) {
             teacherTotal.setLiveFlag(false);
-        }else {
+        } else {
             teacherTotal.setLiveFlag(true);
         }
 
@@ -261,9 +260,9 @@ public class TeacherTotalServiceImpl extends ServiceImpl<TeacherTotalDao, Teache
                 .set(teacherTotal);
 
         TeacherTotal old = getById(id);
-        if(null != old){
+        if (null != old) {
             updateById(teacherTotal);
-        }else{
+        } else {
             save(teacherTotal);
         }
         return teacherTotal;

+ 10 - 18
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserAccountServiceImpl.java

@@ -10,12 +10,14 @@ import com.yonge.cooleshow.biz.dal.entity.UserAccountRecord;
 import com.yonge.cooleshow.biz.dal.entity.UserOrder;
 import com.yonge.cooleshow.biz.dal.enums.InOrOutEnum;
 import com.yonge.cooleshow.biz.dal.service.UserOrderService;
+import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes;
 import com.yonge.cooleshow.common.enums.CacheNameEnum;
 import com.yonge.cooleshow.biz.dal.enums.FrozenTypeEnum;
 import com.yonge.cooleshow.biz.dal.service.UserAccountRecordService;
 import com.yonge.cooleshow.biz.dal.vo.res.AccountTotal;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.base.exception.BizException;
+import com.yonge.toolset.payment.util.DistributedLock;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
@@ -46,6 +48,7 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
     private RedissonClient redissonClient;
     @Autowired
     private UserOrderService orderService;
+
     @Override
     public UserAccountVo detail(Long id) {
         UserAccountVo detail = baseMapper.detail(id);
@@ -67,17 +70,13 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
                 || null == accountRecordDto.getInOrOut() || null == accountRecordDto.getBizType()) {
             return HttpResponseResult.failed("缺少参数");
         }
-        String lockName = CacheNameEnum.LOCK_CHANGE_ACCOUNT.getRedisKey(accountRecordDto.getUserId());
 
-        RLock lock = redissonClient.getLock(lockName);
-        if (Objects.isNull(lock)) {
-            log.info("callIfLockCanGet lock is null lockName : {}", lockName);
-            return HttpResponseResult.failed("账户变更失败");
-        }
-        ExecutorService executor = Executors.newCachedThreadPool();
         try {
-            if (lock.tryLock(10L, 60L, TimeUnit.SECONDS)) {
-                return doAccountChange(accountRecordDto);
+            HttpResponseResult<UserAccountRecord> res = DistributedLock.of(redissonClient)
+                    .runIfLockToFunction(CacheNameEnum.LOCK_CHANGE_ACCOUNT.getRedisKey(accountRecordDto.getUserId())
+                            , this::doAccountChange, accountRecordDto, 10L);
+            if (null != res) {
+                return res;
             } else {
                 return HttpResponseResult.failed("账户变更失败");
             }
@@ -85,13 +84,7 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
             return HttpResponseResult.failed(e.getMessage());
         } catch (Exception e) {
             e.printStackTrace();
-            log.error("callIfLockCanGet error lockKey {}", lockName);
-            return HttpResponseResult.failed("账户变更失败");
-        } finally {
-            executor.shutdown();
-            if (lock.getHoldCount() != 0) {
-                lock.unlock();
-            }
+            return HttpResponseResult.failed("付款失败");
         }
     }
 
@@ -143,7 +136,6 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
     }
 
     private HttpResponseResult<UserAccountRecord> doAccountChange(UserAccountRecordDto accountRecordDto) {
-        UserAccountVo detail = detail(accountRecordDto.getUserId());
         //收入要校验金额
         if (InOrOutEnum.IN.equals(accountRecordDto.getInOrOut())) {
             UserOrder userOrder = orderService.getOne(Wrappers.<UserOrder>lambdaQuery()
@@ -173,6 +165,7 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
             baseMapper.changeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode());
         }
 
+        UserAccountVo detail = detail(accountRecordDto.getUserId());
         if (detail.getAmountTotal().doubleValue() < 0
                 || detail.getAmountUsable().doubleValue() < 0 || detail.getAmountFrozen().doubleValue() < 0) {
             throw new BizException("账户变更失败");
@@ -181,7 +174,6 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
             //插入账户变更记录
             accountRecordDto.setAccountId(accountRecordDto.getUserId());
             accountRecordDto.setAccountBalance(detail.getAmountUsable());
-
             userAccountRecordService.save(accountRecordDto);
         }
         return HttpResponseResult.succeed(accountRecordDto);

+ 2 - 3
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -85,12 +85,11 @@
             sum(if(b.end_time_ &gt; now(),1,0)) as unfinshHours
         from student t
         left join course_schedule_student_payment a on t.user_id_ = a.user_id_
-        left join course_schedule b on a.course_id_ = b.id_ and b.lock_ = 0 and b.type_ in ('PRACTICE','PIANO_ROOM_CLASS')
-        <where>
+        left join course_schedule b on a.course_id_ = b.id_
+        where b.lock_ = 0 and b.type_ in ('PRACTICE','PIANO_ROOM_CLASS')
             <if test="userId != null and userId != ''">
                 and t.user_id_ = #{userId}
             </if>
-        </where>
         group by t.user_id_
     </select>
 

+ 1 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/TeacherStyleVideoMapper.xml

@@ -115,7 +115,7 @@
 		<if test="param.auditVersion != null">
 			and #{param.auditVersion} = t.audit_version_
 		</if>
-		order by ta.live_flag_ desc,(ta.fans_num_ * 0.3 + t.browse_ * 0.3 + ta.exp_time_) desc
+		order by ta.live_flag_ desc,(ta.fans_num_ * 0.3 + t.browse_ * 0.3 + ta.exp_time_ * 0.4) desc
 	</select>
 
 	<update id="addVideoBrowse">

+ 3 - 9
toolset/toolset-base/src/main/java/com/yonge/toolset/base/BaseApplication.java

@@ -17,12 +17,12 @@ import java.util.function.Function;
  */
 public class BaseApplication {
 
-	public static ConfigurableApplicationContext run(String appName, Class source, String... args) {
+	public static ConfigurableApplicationContext run(String appName, Class<?> source, String... args) {
 		SpringApplicationBuilder builder = createSpringApplicationBuilder(appName, source, args);
 		return builder.run(args);
 	}
 
-	public static SpringApplicationBuilder createSpringApplicationBuilder(String appName, Class source, String... args) {
+	public static SpringApplicationBuilder createSpringApplicationBuilder(String appName, Class<?> source, String... args) {
 		Assert.hasText(appName, "[appName]服务名不能为空");
 		// 读取环境变量,使用spring boot的规则
 		ConfigurableEnvironment environment = new StandardEnvironment();
@@ -33,13 +33,7 @@ public class BaseApplication {
 		// 获取配置的环境变量
 		String[] activeProfiles = environment.getActiveProfiles();
 		// 判断环境:dev、test、prod
-		List<String> profiles = Arrays.asList(activeProfiles);
-		// 预设的环境
-		List<String> presetProfiles = new ArrayList<>(Arrays.asList(BaseAppConstant.DEV_CODE, BaseAppConstant.TEST_CODE, BaseAppConstant.PROD_CODE));
-		// 交集
-		presetProfiles.retainAll(profiles);
-		// 当前使用
-		List<String> activeProfileList = new ArrayList<>(profiles);
+		List<String> activeProfileList = Arrays.asList(activeProfiles);
 		Function<Object[], String> joinFun = StringUtils::arrayToCommaDelimitedString;
 		SpringApplicationBuilder builder = new SpringApplicationBuilder(source);
 		String profile;