Browse Source

Merge remote-tracking branch 'origin/saas_2022_05_17_activity' into saas_2022_05_17_activity

zouxuan 3 years ago
parent
commit
ba21a1cf10

+ 8 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -473,6 +473,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 
     //获取该直播间所有数据写入数据库-并清理缓存
     private void insertAndCleanLiveData(String roomUid, Integer speakerId) {
+        log.info("insertAndCleanLiveData >>>> roomUid : {}", roomUid);
         Date now = new Date();
         //总观看人数
         List<ImLiveBroadcastRoomMember> memberList = new ArrayList<>();
@@ -507,6 +508,7 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
         if (speakerCache.isExists()) {
             ImLiveBroadcastRoomData liveData = new ImLiveBroadcastRoomData();
             RoomSpeakerInfo speakerInfo = speakerCache.get();
+            log.info("insertAndCleanLiveData >>>> speakerInfo : {}", JSONObject.toJSONString(speakerInfo));
             liveData.setTenantId(speakerInfo.getTenantId());
             liveData.setRoomUid(roomUid);
             liveData.setLikeNum(like);
@@ -1191,17 +1193,20 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
      * @param nowMinutes 现在观看时长
      */
     private int getLookMinutes(Date startDT, Date endDT, Integer nowMinutes) {
+        if (Objects.isNull(nowMinutes)) {
+            nowMinutes = 0;
+        }
         if (Objects.isNull(startDT)) {
-            return 0;
+            return nowMinutes;
         }
         if (startDT.getTime() > endDT.getTime()) {
-            return 0;
+            return nowMinutes;
         }
         //课程结束时间-课程开始时间
         long durationTime = endDT.getTime() - startDT.getTime();
         //相差多少分钟
         int minutesBetween = new Long(durationTime / 1000 / 60).intValue();
-        minutesBetween += Objects.isNull(nowMinutes) ? 0 : nowMinutes;
+        minutesBetween += nowMinutes;
         return Math.max(minutesBetween, 0);
     }
 

+ 48 - 27
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TempLittleArtistTrainingCampServiceImpl.java

@@ -75,19 +75,7 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
     public void add(TempLittleArtistTrainingCampDto dto) {
         SysUser user = getUser();
         Date now = DateUtil.toDate(LocalDate.now().toString());
-        if (dto.getApplyEndDate().getTime() < now.getTime()) {
-            throw new BizException("报名结束时间不能小于今天");
-        }
-        if (dto.getApplyStartDate().getTime() > dto.getApplyEndDate().getTime()) {
-            throw new BizException("报名开始时间不能大于结束时间");
-        }
-        if (dto.getTrainStartDate().getTime() > dto.getTrainEndDate().getTime()) {
-            throw new BizException("训练开始时间不能大于训练结束时间");
-        }
-        //报名结束时间必需小于训练开始时间
-        if (dto.getTrainStartDate().getTime() < dto.getApplyEndDate().getTime()) {
-            throw new BizException("报名结束时间必需小于训练开始时间");
-        }
+        checkDateTime(dto, now);
         TempLittleArtistTrainingCamp entity = new TempLittleArtistTrainingCamp();
         BeanUtils.copyProperties(dto, entity);
         entity.setState(TempLittleArtistTrainingCamp.NOT_START);
@@ -107,9 +95,16 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
     @Override
     public void update(TempLittleArtistTrainingCampDto dto) {
         SysUser user = getUser();
+        Date now = DateUtil.toDate(LocalDate.now().toString());
+        checkDateTime(dto, now);
         TempLittleArtistTrainingCamp entity = Optional.ofNullable(dto.getId())
                 .map(this::getById)
                 .orElseThrow(() -> new BizException("训练营不存在"));
+        int count = tempLittleArtistTrainingCampUserRelationService.count(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
+                .eq(TempLittleArtistTrainingCampUserRelation::getActivityId, entity.getId()));
+        if (count > 0) {
+            throw new BizException("训练营已有学生报名,无法删除");
+        }
         entity.setName(dto.getName());
         entity.setApplyStartDate(dto.getApplyStartDate());
         entity.setApplyEndDate(dto.getApplyEndDate());
@@ -122,6 +117,25 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
     }
 
     /**
+     * 校验时间
+     */
+    private void checkDateTime(TempLittleArtistTrainingCampDto dto, Date now) {
+        if (dto.getApplyEndDate().getTime() < now.getTime()) {
+            throw new BizException("报名结束时间不能小于今天");
+        }
+        if (dto.getApplyStartDate().getTime() > dto.getApplyEndDate().getTime()) {
+            throw new BizException("报名开始时间不能大于结束时间");
+        }
+        if (dto.getTrainStartDate().getTime() > dto.getTrainEndDate().getTime()) {
+            throw new BizException("训练开始时间不能大于训练结束时间");
+        }
+        //报名结束时间必需小于训练开始时间
+        if (dto.getTrainStartDate().getTime() < dto.getApplyEndDate().getTime()) {
+            throw new BizException("报名结束时间必需小于训练开始时间");
+        }
+    }
+
+    /**
      * 删除训练营
      */
     @Transactional(rollbackFor = Exception.class)
@@ -130,6 +144,11 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
         TempLittleArtistTrainingCamp entity = Optional.ofNullable(id)
                 .map(this::getById)
                 .orElseThrow(() -> new BizException("训练营不存在"));
+        int count = tempLittleArtistTrainingCampUserRelationService.count(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
+                .eq(TempLittleArtistTrainingCampUserRelation::getActivityId, entity.getId()));
+        if (count > 0) {
+            throw new BizException("训练营已有学生报名,无法删除");
+        }
         entity.setDelFlag(1);
         this.updateById(entity);
     }
@@ -295,15 +314,14 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
         Map<String, Object> result = new HashMap<>();
         result.put("user", userRelation);
         if (CollectionUtils.isNotEmpty(campList)) {
-            campList.sort(Comparator.comparing(TempLittleArtistTrainingCamp::getApplyStartDate));
-        }
-        if (CollectionUtils.isNotEmpty(campList)) {
-            campList.forEach(a -> {
-                int count = tempLittleArtistTrainingCampUserRelationService.count(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
-                        .eq(TempLittleArtistTrainingCampUserRelation::getActivityId, a.getId())
-                );
-                a.setUserCount(count);
-            });
+            campList = campList.stream()
+                    .peek(a -> {
+                        int count = tempLittleArtistTrainingCampUserRelationService.count(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
+                                .eq(TempLittleArtistTrainingCampUserRelation::getActivityId, a.getId()));
+                        a.setUserCount(count);
+                    })
+                    .sorted(Comparator.comparing(TempLittleArtistTrainingCamp::getApplyStartDate))
+                    .collect(Collectors.toList());
         }
         result.put("campList", campList);
         return result;
@@ -445,23 +463,26 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
         SysUser user = getUser();
         //查询训练营人员关系
         TempLittleArtistTrainingCampUserRelation campUser = tempLittleArtistTrainingCampUserRelationService.getOne(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
-                .eq(TempLittleArtistTrainingCampUserRelation::getUserId, user.getId()));
+                .eq(TempLittleArtistTrainingCampUserRelation::getUserId, user.getId())
+                .eq(TempLittleArtistTrainingCampUserRelation::getState, TempLittleArtistTrainingCampUserRelation.APPLY)
+        );
         if (Objects.isNull(campUser)) {
             return null;
         }
-        //查询训练营
+        //查询在训练中的训练营
         TempLittleArtistTrainingCamp camp = this.getOne(Wrappers.<TempLittleArtistTrainingCamp>lambdaQuery()
                 .eq(TempLittleArtistTrainingCamp::getId, campUser.getActivityId())
+                .eq(TempLittleArtistTrainingCamp::getState, TempLittleArtistTrainingCamp.ING)
                 .eq(TempLittleArtistTrainingCamp::getDelFlag, 0));
         if (Objects.isNull(camp)) {
             return null;
         }
-
+        LocalDate now = LocalDate.now();
         TempCampUserTrainingPlayTimeVo vo = new TempCampUserTrainingPlayTimeVo();
         Map<String, Object> param = new HashMap<>();
         param.put("userId", user.getId());
-        param.put("startTime", DateUtil.dateToString(camp.getTrainStartDate()) + " 00:00:00");
-        param.put("endTime", DateUtil.dateToString(camp.getTrainEndDate()) + " 23:59:59");
+        param.put("startTime", now + " 00:00:00");
+        param.put("endTime", now + " 23:59:59");
         Integer playTime = baseMapper.queryUserTrainingPlayTime(param);
         vo.setPlayTime(playTime);
         vo.setTrainStartDate(camp.getTrainStartDate());

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TempLittleArtistTrainingCampUserRelationServiceImpl.java

@@ -50,6 +50,11 @@ public class TempLittleArtistTrainingCampUserRelationServiceImpl extends Service
     @Override
     public void add(Integer campId) {
         SysUser user = getUser();
+        TempLittleArtistTrainingCampUserRelation one = this.getOne(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
+                .eq(TempLittleArtistTrainingCampUserRelation::getUserId, user.getId()));
+        if (Objects.nonNull(one) && Objects.nonNull(one.getActivityId())) {
+            throw new BizException("您已登记训练营!");
+        }
         int count = this.count(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaUpdate()
                 .set(TempLittleArtistTrainingCampUserRelation::getActivityId, campId));
         if (count == 2000) {

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/TempLittleArtistTrainingCampMapper.xml

@@ -132,7 +132,7 @@
             <if test="param.search != null ">
                 AND (
                 d.`id_` LIKE CONCAT('%', #{param.search},'%')
-                OR d.`name_` LIKE CONCAT('%', #{param.search},'%')
+                OR d.`username_` LIKE CONCAT('%', #{param.search},'%')
                 OR d.`phone_` LIKE CONCAT('%', #{param.search},'%')
                 )
             </if>