|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
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.entity.SysUser;
|
|
|
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.TempCampUserVo;
|
|
|
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.TempLittleArtistTrainingCampUserRelationService;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
@@ -36,8 +38,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -55,6 +59,8 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
@Autowired
|
|
|
private TempLittleArtistTrainingCampUserRelationService tempLittleArtistTrainingCampUserRelationService;
|
|
|
+ @Autowired
|
|
|
+ private ImGroupService imGroupService;
|
|
|
|
|
|
@Override
|
|
|
public TempLittleArtistTrainingCampDao getDao() {
|
|
@@ -307,6 +313,7 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
* 定时任务-修改训练营状态-每天0点执行一次
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void checkCampState() {
|
|
|
//查询未结束 并 未删除的训练营
|
|
|
List<TempLittleArtistTrainingCamp> campList = this.list(Wrappers.<TempLittleArtistTrainingCamp>lambdaQuery()
|
|
@@ -320,7 +327,7 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
Map<String, List<TempLittleArtistTrainingCamp>> stateMap = WrapperUtil.groupList(campList, TempLittleArtistTrainingCamp::getState);
|
|
|
//未开始 NOT_START 修改为 报名中 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);
|
|
|
//筹备中 READY 修改为 进行中 ING
|
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.READY, TempLittleArtistTrainingCamp::getTrainStartDate, TempLittleArtistTrainingCamp.ING);
|
|
@@ -328,6 +335,8 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
opsState(now, stateMap, TempLittleArtistTrainingCamp.ING, TempLittleArtistTrainingCamp::getTrainEndDate, TempLittleArtistTrainingCamp.END);
|
|
|
//修改数据
|
|
|
campList.forEach(this::updateById);
|
|
|
+ //对今天开始训练的人进行分组
|
|
|
+ this.studentGrouping(now);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -344,6 +353,20 @@ public class TempLittleArtistTrainingCampServiceImpl extends ServiceImpl<TempLit
|
|
|
List<TempLittleArtistTrainingCamp> list = stateMap.get(oldState);
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
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()) {
|
|
|
camp.setState(newState);
|
|
|
}
|
|
@@ -352,6 +375,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
|