|
|
@@ -45,9 +45,7 @@ import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
import com.zhongzheng.modules.grade.bo.*;
|
|
|
import com.zhongzheng.modules.grade.domain.ClassGrade;
|
|
|
import com.zhongzheng.modules.grade.domain.StudyCountLog;
|
|
|
-import com.zhongzheng.modules.grade.service.IClassGradeService;
|
|
|
-import com.zhongzheng.modules.grade.service.IStudyCountLogService;
|
|
|
-import com.zhongzheng.modules.grade.service.IUserPeriodStatusService;
|
|
|
+import com.zhongzheng.modules.grade.service.*;
|
|
|
import com.zhongzheng.modules.grade.vo.*;
|
|
|
import com.zhongzheng.modules.order.bo.OrderGoodsQueryBo;
|
|
|
import com.zhongzheng.modules.order.domain.OrderGoods;
|
|
|
@@ -79,7 +77,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.pagehelper.Page;
|
|
|
import com.zhongzheng.modules.grade.domain.ClassGradeUser;
|
|
|
import com.zhongzheng.modules.grade.mapper.ClassGradeUserMapper;
|
|
|
-import com.zhongzheng.modules.grade.service.IClassGradeUserService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
@@ -173,6 +170,8 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
|
|
|
@Value("${officialPush.token}")
|
|
|
private String OFFICIALPUSH_TOKEN;
|
|
|
|
|
|
+ private IUserPeriodService iUserPeriodService;
|
|
|
+
|
|
|
@Override
|
|
|
public ClassGradeUserVo queryById(Long id) {
|
|
|
ClassGradeUser db = this.baseMapper.selectById(id);
|
|
|
@@ -268,6 +267,63 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Boolean changeGradeFree(ClassGradeUserChangeBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getUserId())||Validator.isEmpty(bo.getGradeId())||Validator.isEmpty(bo.getOrderGoodsId())||Validator.isEmpty(bo.getGoodsId())){
|
|
|
+ throw new CustomException("参数缺失");
|
|
|
+ }
|
|
|
+ OrderGoodsVo orderGoodsVo = iOrderGoodsService.queryById(bo.getOrderGoodsId());
|
|
|
+ Long oldGradeId = orderGoodsVo.getGradeId();
|
|
|
+ if(Validator.isEmpty(oldGradeId)){
|
|
|
+ throw new CustomException("参数错误");
|
|
|
+ }
|
|
|
+ UserPeriodQueryBo queryBo = new UserPeriodQueryBo();
|
|
|
+ queryBo.setGradeId(oldGradeId);
|
|
|
+ queryBo.setUserId(bo.getUserId());
|
|
|
+ Long logNum = iUserPeriodService.checkGoodsStudy(queryBo);
|
|
|
+ if(logNum.longValue()>0L){
|
|
|
+ throw new CustomException("已有学习数据,无法换班");
|
|
|
+ }
|
|
|
+ if(bo.getGradeId().longValue()==oldGradeId){
|
|
|
+ throw new CustomException("更换班级和老班级一样");
|
|
|
+ }
|
|
|
+ String requestId = IdUtil.simpleUUID();
|
|
|
+ RedisLockEntity redisLockEntity = new RedisLockEntity();
|
|
|
+ redisLockEntity.setLockKey(RedisLockEntity.KEY_LOCK_GRADE);
|
|
|
+ redisLockEntity.setRequestId(requestId);
|
|
|
+ if (redisCache.lock(redisLockEntity)) {
|
|
|
+ //分新班
|
|
|
+ Long newGradeId = iOrderService.sysChangeGrade(bo.getGoodsId(), bo.getOrderGoodsId(), bo.getGradeId(), bo.getUserId());
|
|
|
+ if (newGradeId > 0) {
|
|
|
+ //老班修改换班状态
|
|
|
+ ClassGradeUser classGradeUser = getOne(new LambdaQueryWrapper<ClassGradeUser>().eq(ClassGradeUser::getUserId, bo.getUserId())
|
|
|
+ .eq(ClassGradeUser::getStatus, 1)
|
|
|
+ .eq(ClassGradeUser::getGradeId, oldGradeId)
|
|
|
+ .last("limit 1"));
|
|
|
+ removeById(classGradeUser.getId());
|
|
|
+
|
|
|
+ OrderGoods orderGoods = new OrderGoods();
|
|
|
+ orderGoods.setOrderGoodsId(bo.getOrderGoodsId());
|
|
|
+ orderGoods.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ orderGoods.setGradeId(newGradeId);
|
|
|
+ iOrderGoodsService.updateById(orderGoods);
|
|
|
+ //记录消耗0次学习机会
|
|
|
+ StudyCountLog studyCountLog = new StudyCountLog();
|
|
|
+ studyCountLog.setGradeId(newGradeId);
|
|
|
+ studyCountLog.setStatus(-1);
|
|
|
+ studyCountLog.setOrderGoodsId(bo.getOrderGoodsId());
|
|
|
+ studyCountLog.setStudyCount(0L);
|
|
|
+ studyCountLog.setUserId(bo.getUserId());
|
|
|
+ studyCountLog.setCreateTime(DateUtils.getNowTime());
|
|
|
+ studyCountLog.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ studyCountLog.setOldGradeId(oldGradeId);
|
|
|
+ iStudyCountLogService.save(studyCountLog);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 系统批量选新班
|
|
|
*
|
|
|
@@ -298,7 +354,7 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
|
|
|
redisLockEntity.setRequestId(requestId);
|
|
|
if (redisCache.lock(redisLockEntity)) {
|
|
|
//分新班
|
|
|
- Long newGradeId = iOrderService.sysChangeGrade(goodsVo.getGoodsName(), item.getGoodsId(), item.getOrderGoodsId(), item.getGradeId(), item.getUserId(), goodsVo.getBusinessId());
|
|
|
+ Long newGradeId = iOrderService.sysChangeGrade(item.getGoodsId(), item.getOrderGoodsId(), item.getGradeId(), item.getUserId());
|
|
|
if (newGradeId > 0) {
|
|
|
//老班修改换班状态
|
|
|
ClassGradeUser classGradeUser = getOne(new LambdaQueryWrapper<ClassGradeUser>().eq(ClassGradeUser::getUserId, item.getUserId())
|
|
|
@@ -324,7 +380,7 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
|
|
|
studyCountLog.setUserId(item.getUserId());
|
|
|
studyCountLog.setCreateTime(DateUtils.getNowTime());
|
|
|
studyCountLog.setUpdateTime(DateUtils.getNowTime());
|
|
|
- studyCountLog.setOldGradeId(item.getUserId());
|
|
|
+ studyCountLog.setOldGradeId(item.getOldGradeId());
|
|
|
iStudyCountLogService.save(studyCountLog);
|
|
|
//老班学习记录去掉
|
|
|
|