|
@@ -3,14 +3,24 @@ package com.zhongzheng.modules.order.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
import com.zhongzheng.modules.bank.mapper.QuestionMapper;
|
|
|
+import com.zhongzheng.modules.goods.domain.Goods;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
+import com.zhongzheng.modules.grade.domain.ClassGradeUser;
|
|
|
+import com.zhongzheng.modules.grade.service.IClassGradeService;
|
|
|
+import com.zhongzheng.modules.grade.service.IClassGradeUserService;
|
|
|
+import com.zhongzheng.modules.grade.vo.ClassGradeVo;
|
|
|
import com.zhongzheng.modules.order.bo.OrderGoodsAddBo;
|
|
|
import com.zhongzheng.modules.order.bo.OrderGoodsEditBo;
|
|
|
import com.zhongzheng.modules.order.bo.OrderGoodsQueryBo;
|
|
|
+import com.zhongzheng.modules.order.domain.Order;
|
|
|
import com.zhongzheng.modules.order.domain.OrderGoods;
|
|
|
import com.zhongzheng.modules.order.mapper.OrderGoodsMapper;
|
|
|
import com.zhongzheng.modules.order.service.IOrderGoodsService;
|
|
|
+import com.zhongzheng.modules.order.service.IOrderService;
|
|
|
import com.zhongzheng.modules.order.vo.OrderGoodsVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -18,6 +28,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
@@ -36,6 +47,18 @@ public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGo
|
|
|
@Autowired
|
|
|
private OrderGoodsMapper orderGoodsMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGoodsService iGoodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IClassGradeUserService iClassGradeUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IClassGradeService iClassGradeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderService iOrderService;
|
|
|
+
|
|
|
@Override
|
|
|
public OrderGoodsVo queryById(String orderSn){
|
|
|
OrderGoods db = this.baseMapper.selectById(orderSn);
|
|
@@ -93,11 +116,34 @@ public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGo
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean updateByEditBo(OrderGoodsEditBo bo) {
|
|
|
OrderGoods update = BeanUtil.toBean(bo, OrderGoods.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
update.setUpdateTime(DateUtils.getNowTime());
|
|
|
update.setGoodsInputData(JSON.toJSONString(bo.getGoodsInputData()));
|
|
|
+ OrderGoods db = this.baseMapper.selectById(bo.getOrderGoodsId());
|
|
|
+ //新的班级ID变化
|
|
|
+ if(bo.getGradeId()!=null&&db.getGradeId()!=bo.getGradeId()){
|
|
|
+ //修改班级
|
|
|
+ Goods goods = iGoodsService.getOne(new LambdaQueryWrapper<Goods>().eq(Goods::getGoodsId,bo.getGoodsId()));
|
|
|
+ //视频商品安排班级
|
|
|
+ if(goods.getGoodsType()==1){
|
|
|
+ Order order = iOrderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderSn,bo.getOrderSn()));
|
|
|
+ //加入新班级
|
|
|
+ joinGrade(bo.getOrderGoodsId(),bo.getGradeId(),order.getUserId());
|
|
|
+ //移除旧班级
|
|
|
+ ClassGradeUser classGradeUser =iClassGradeUserService.getOne(new LambdaQueryWrapper<ClassGradeUser>()
|
|
|
+ .eq(ClassGradeUser::getUserId,order.getUserId()).eq(ClassGradeUser::getGradeId,db.getGradeId()
|
|
|
+ ).eq(ClassGradeUser::getStatus,1));
|
|
|
+ if(classGradeUser==null){
|
|
|
+ throw new CustomException("原班级查无你的信息");
|
|
|
+ }
|
|
|
+ classGradeUser.setStatus(0);
|
|
|
+ classGradeUser.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iClassGradeUserService.updateById(classGradeUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
return this.updateById(update);
|
|
|
}
|
|
|
|
|
@@ -117,4 +163,33 @@ public class OrderGoodsServiceImpl extends ServiceImpl<OrderGoodsMapper, OrderGo
|
|
|
}
|
|
|
return this.removeByIds(ids);
|
|
|
}
|
|
|
+
|
|
|
+ public boolean joinGrade(Long orderGoodsId,Long gradeId,Long userId){
|
|
|
+ ClassGradeVo classGradeVo = iClassGradeService.queryById(gradeId);
|
|
|
+ if(classGradeVo==null){
|
|
|
+ throw new CustomException("班级不存在");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<ClassGradeUser> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.eq(ClassGradeUser::getGradeId,gradeId);
|
|
|
+ lqw.eq(ClassGradeUser::getStatus,1);
|
|
|
+ int studentNum = iClassGradeUserService.count(lqw);
|
|
|
+ //预留0空位避免超人数
|
|
|
+ if(classGradeVo.getStudentUpper()-studentNum<1){
|
|
|
+ //班级还有剩位,直接加入班级
|
|
|
+ throw new CustomException("班级人数已满");
|
|
|
+ }
|
|
|
+ //进入班级
|
|
|
+ ClassGradeUser classGradeUser = new ClassGradeUser();
|
|
|
+ classGradeUser.setUserId(userId);
|
|
|
+ classGradeUser.setGradeId(gradeId);
|
|
|
+ classGradeUser.setStatus(1);
|
|
|
+ classGradeUser.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ classGradeUser.setFromType(2);
|
|
|
+ classGradeUser.setOrderGoodsId(orderGoodsId);
|
|
|
+ classGradeUser.setCreateTime(DateUtils.getNowTime());
|
|
|
+ classGradeUser.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iClassGradeUserService.save(classGradeUser);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|