|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.TempLittleArtistTrainingCampDao;
|
|
import com.ym.mec.biz.dal.dao.TempLittleArtistTrainingCampDao;
|
|
@@ -15,6 +16,7 @@ import com.ym.mec.biz.dal.vo.TempCampUserTrainingDetailVo;
|
|
|
import com.ym.mec.biz.dal.vo.TempCampUserTrainingPlayTimeVo;
|
|
import com.ym.mec.biz.dal.vo.TempCampUserTrainingPlayTimeVo;
|
|
|
import com.ym.mec.biz.dal.vo.TempCampUserVo;
|
|
import com.ym.mec.biz.dal.vo.TempCampUserVo;
|
|
|
import com.ym.mec.biz.dal.vo.TempUserTrainingTimeDetailVo;
|
|
import com.ym.mec.biz.dal.vo.TempUserTrainingTimeDetailVo;
|
|
|
|
|
+import com.ym.mec.biz.service.ImGroupService;
|
|
|
import com.ym.mec.biz.service.TempLittleArtistTrainingCampService;
|
|
import com.ym.mec.biz.service.TempLittleArtistTrainingCampService;
|
|
|
import com.ym.mec.biz.service.TempLittleArtistTrainingCampUserRelationService;
|
|
import com.ym.mec.biz.service.TempLittleArtistTrainingCampUserRelationService;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
import com.ym.mec.common.exception.BizException;
|
|
@@ -36,8 +38,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -55,6 +59,8 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private TempLittleArtistTrainingCampUserRelationService tempLittleArtistTrainingCampUserRelationService;
|
|
private TempLittleArtistTrainingCampUserRelationService tempLittleArtistTrainingCampUserRelationService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ImGroupService imGroupService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public TempLittleArtistTrainingCampDao getDao() {
|
|
public TempLittleArtistTrainingCampDao getDao() {
|
|
@@ -289,15 +295,14 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("user", userRelation);
|
|
result.put("user", userRelation);
|
|
|
if (CollectionUtils.isNotEmpty(campList)) {
|
|
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);
|
|
result.put("campList", campList);
|
|
|
return result;
|
|
return result;
|
|
@@ -307,6 +312,7 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
* 定时任务-修改训练营状态-每天0点执行一次
|
|
* 定时任务-修改训练营状态-每天0点执行一次
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void checkCampState() {
|
|
public void checkCampState() {
|
|
|
//查询未结束 并 未删除的训练营
|
|
//查询未结束 并 未删除的训练营
|
|
|
List<TempLittleArtistTrainingCamp> campList = this.list(Wrappers.<TempLittleArtistTrainingCamp>lambdaQuery()
|
|
List<TempLittleArtistTrainingCamp> campList = this.list(Wrappers.<TempLittleArtistTrainingCamp>lambdaQuery()
|
|
@@ -320,7 +326,7 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
Map<String, List<TempLittleArtistTrainingCamp>> stateMap = WrapperUtil.groupList(campList, TempLittleArtistTrainingCamp::getState);
|
|
Map<String, List<TempLittleArtistTrainingCamp>> stateMap = WrapperUtil.groupList(campList, TempLittleArtistTrainingCamp::getState);
|
|
|
//未开始 NOT_START 修改为 报名中 APPLY
|
|
//未开始 NOT_START 修改为 报名中 APPLY
|
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.NOT_START, TempLittleArtistTrainingCamp::getApplyStartDate, TempLittleArtistTrainingCamp.APPLY);
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.NOT_START, TempLittleArtistTrainingCamp::getApplyStartDate, TempLittleArtistTrainingCamp.APPLY);
|
|
|
- //报名中 APPLY 修改为 筹备中 READY
|
|
|
|
|
|
|
+ //报名中 APPLY 修改为 筹备中 READY 如果报名结束日期+1天正好等于训练开始时间 并 训练时间正好是今天那么直接变更为进行中状态,那么直接修改为进行中状态
|
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.APPLY, TempLittleArtistTrainingCamp::getApplyEndDate, TempLittleArtistTrainingCamp.READY);
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.APPLY, TempLittleArtistTrainingCamp::getApplyEndDate, TempLittleArtistTrainingCamp.READY);
|
|
|
//筹备中 READY 修改为 进行中 ING
|
|
//筹备中 READY 修改为 进行中 ING
|
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.READY, TempLittleArtistTrainingCamp::getTrainStartDate, TempLittleArtistTrainingCamp.ING);
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.READY, TempLittleArtistTrainingCamp::getTrainStartDate, TempLittleArtistTrainingCamp.ING);
|
|
@@ -328,6 +334,8 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.ING, TempLittleArtistTrainingCamp::getTrainEndDate, TempLittleArtistTrainingCamp.END);
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.ING, TempLittleArtistTrainingCamp::getTrainEndDate, TempLittleArtistTrainingCamp.END);
|
|
|
//修改数据
|
|
//修改数据
|
|
|
campList.forEach(this::updateById);
|
|
campList.forEach(this::updateById);
|
|
|
|
|
+ //对今天开始训练的人进行分组
|
|
|
|
|
+ this.studentGrouping(now);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -344,6 +352,20 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
List<TempLittleArtistTrainingCamp> list = stateMap.get(oldState);
|
|
List<TempLittleArtistTrainingCamp> list = stateMap.get(oldState);
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
list.forEach(camp -> {
|
|
list.forEach(camp -> {
|
|
|
|
|
+ //报名中的状态
|
|
|
|
|
+ if (oldState.equals(TempLittleArtistTrainingCamp.APPLY)) {
|
|
|
|
|
+ //报名结束日期+1天
|
|
|
|
|
+ long appleEndAddTime = DateUtil.addDays(camp.getApplyEndDate(), 1).getTime();
|
|
|
|
|
+ //训练开始时间
|
|
|
|
|
+ long trainStartTime = camp.getTrainStartDate().getTime();
|
|
|
|
|
+ //今天
|
|
|
|
|
+ long nowTime = DateUtil.toDate(LocalDate.now().toString()).getTime();
|
|
|
|
|
+ //报名结束日期+1天正好等于训练开始时间 并 训练时间正好是今天那么直接变更为进行中状态
|
|
|
|
|
+ if (appleEndAddTime == trainStartTime && nowTime == trainStartTime) {
|
|
|
|
|
+ camp.setState(TempLittleArtistTrainingCamp.ING);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (now.getTime() >= dateField.apply(camp).getTime()) {
|
|
if (now.getTime() >= dateField.apply(camp).getTime()) {
|
|
|
camp.setState(newState);
|
|
camp.setState(newState);
|
|
|
}
|
|
}
|
|
@@ -352,6 +374,69 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 对开始训练的的学员进行分组
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void studentGrouping(Date now) {
|
|
|
|
|
+ now = Optional.ofNullable(now).orElse(DateUtil.stringToDate(LocalDate.now() + " 00:00:00"));
|
|
|
|
|
+ //待数据修改后-查询训练开始时间为今天并且没有分组并且状态为进行中的数据
|
|
|
|
|
+ List<TempLittleArtistTrainingCamp> groupCampList = this.list(Wrappers.<TempLittleArtistTrainingCamp>lambdaQuery()
|
|
|
|
|
+ .eq(TempLittleArtistTrainingCamp::getDelFlag, 0)
|
|
|
|
|
+ .eq(TempLittleArtistTrainingCamp::getState, TempLittleArtistTrainingCamp.ING)
|
|
|
|
|
+ .isNull(TempLittleArtistTrainingCamp::getImGroupIds)
|
|
|
|
|
+ .eq(TempLittleArtistTrainingCamp::getTrainStartDate, now)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollectionUtils.isEmpty(groupCampList)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String groupType = "TRAINING";
|
|
|
|
|
+ //每个房间最大人数
|
|
|
|
|
+ BigDecimal maxUserNum = new BigDecimal("1");
|
|
|
|
|
+ //key-训练营id value-训练营集合
|
|
|
|
|
+ groupCampList.forEach(camp -> {
|
|
|
|
|
+ List<String> imGroupIds = new ArrayList<>();
|
|
|
|
|
+ //查询该训练营 已报名且没分组的学员
|
|
|
|
|
+ List<Integer> userList = baseMapper.queryUserGroup(camp.getId());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(userList)) {
|
|
|
|
|
+ return;//训练营没人报名
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> userStrList = userList.stream().map(String::valueOf).collect(Collectors.toList());
|
|
|
|
|
+ //报名人数
|
|
|
|
|
+ int totalUserNum = userStrList.size();
|
|
|
|
|
+ BigDecimal applyNum = new BigDecimal(totalUserNum + "");
|
|
|
|
|
+ //如果人数小于最大人数 则直接分组
|
|
|
|
|
+ if (maxUserNum.intValue() >= applyNum.intValue()) {
|
|
|
|
|
+ //分组
|
|
|
|
|
+ String groupId = imGroupService.createGroup(userStrList, camp.getName() + "-1群", groupType);
|
|
|
|
|
+ imGroupIds.add(groupId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //分组数 ->报名人数 ➗ 每组最大人数 有小数就向上取整 1.01 -> 2
|
|
|
|
|
+ BigDecimal groupNum = applyNum.divide(maxUserNum, 0, RoundingMode.UP);
|
|
|
|
|
+ //每组分配人数 向下取整 1.01 -> 2
|
|
|
|
|
+ BigDecimal groupUserNum = applyNum.divide(groupNum, 0, RoundingMode.DOWN);
|
|
|
|
|
+ //切分人数
|
|
|
|
|
+ List<List<String>> partition = Lists.partition(userStrList, groupUserNum.intValue());
|
|
|
|
|
+ //群号
|
|
|
|
|
+ AtomicInteger i = new AtomicInteger(1);
|
|
|
|
|
+ partition.forEach(list -> {
|
|
|
|
|
+ String groupId = imGroupService.createGroup(list, camp.getName() + "-" + i.get() + "群", groupType);
|
|
|
|
|
+ //修改
|
|
|
|
|
+ tempLittleArtistTrainingCampUserRelationService.update(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaUpdate()
|
|
|
|
|
+ .set(TempLittleArtistTrainingCampUserRelation::getImGroupId, groupId)
|
|
|
|
|
+ .eq(TempLittleArtistTrainingCampUserRelation::getActivityId, camp.getId())
|
|
|
|
|
+ .in(TempLittleArtistTrainingCampUserRelation::getUserId, list)
|
|
|
|
|
+ .isNull(TempLittleArtistTrainingCampUserRelation::getImGroupId));
|
|
|
|
|
+ imGroupIds.add(groupId);
|
|
|
|
|
+ i.getAndIncrement();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ camp.setImGroupIds(String.join(",", imGroupIds));
|
|
|
|
|
+ this.updateById(camp);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 云教练训练是否达标
|
|
* 云教练训练是否达标
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
@@ -359,23 +444,26 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
SysUser user = getUser();
|
|
SysUser user = getUser();
|
|
|
//查询训练营人员关系
|
|
//查询训练营人员关系
|
|
|
TempLittleArtistTrainingCampUserRelation campUser = tempLittleArtistTrainingCampUserRelationService.getOne(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
|
|
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)) {
|
|
if (Objects.isNull(campUser)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- //查询训练营
|
|
|
|
|
|
|
+ //查询在训练中的训练营
|
|
|
TempLittleArtistTrainingCamp camp = this.getOne(Wrappers.<TempLittleArtistTrainingCamp>lambdaQuery()
|
|
TempLittleArtistTrainingCamp camp = this.getOne(Wrappers.<TempLittleArtistTrainingCamp>lambdaQuery()
|
|
|
.eq(TempLittleArtistTrainingCamp::getId, campUser.getActivityId())
|
|
.eq(TempLittleArtistTrainingCamp::getId, campUser.getActivityId())
|
|
|
|
|
+ .eq(TempLittleArtistTrainingCamp::getState, TempLittleArtistTrainingCamp.ING)
|
|
|
.eq(TempLittleArtistTrainingCamp::getDelFlag, 0));
|
|
.eq(TempLittleArtistTrainingCamp::getDelFlag, 0));
|
|
|
if (Objects.isNull(camp)) {
|
|
if (Objects.isNull(camp)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
TempCampUserTrainingPlayTimeVo vo = new TempCampUserTrainingPlayTimeVo();
|
|
TempCampUserTrainingPlayTimeVo vo = new TempCampUserTrainingPlayTimeVo();
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
param.put("userId", user.getId());
|
|
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);
|
|
Integer playTime = baseMapper.queryUserTrainingPlayTime(param);
|
|
|
vo.setPlayTime(playTime);
|
|
vo.setPlayTime(playTime);
|
|
|
vo.setTrainStartDate(camp.getTrainStartDate());
|
|
vo.setTrainStartDate(camp.getTrainStartDate());
|