|
@@ -4,12 +4,17 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.course.bo.CourseChapterSectionListAddBo;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseChapterSection;
|
|
|
import com.zhongzheng.modules.course.mapper.CourseChapterMapper;
|
|
|
import com.zhongzheng.modules.goods.bo.GoodsAddBo;
|
|
|
+import com.zhongzheng.modules.goods.bo.GoodsCourseAddBo;
|
|
|
import com.zhongzheng.modules.goods.bo.GoodsEditBo;
|
|
|
import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
|
|
|
import com.zhongzheng.modules.goods.domain.Goods;
|
|
|
+import com.zhongzheng.modules.goods.domain.GoodsCourse;
|
|
|
import com.zhongzheng.modules.goods.mapper.GoodsMapper;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsCourseService;
|
|
|
import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -18,9 +23,11 @@ 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;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -36,6 +43,9 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
@Autowired
|
|
|
private GoodsMapper goodsMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGoodsCourseService iGoodsCourseService;
|
|
|
+
|
|
|
@Override
|
|
|
public GoodsVo queryById(Long goodsId){
|
|
|
Goods db = this.baseMapper.selectById(goodsId);
|
|
@@ -99,20 +109,48 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean insertByAddBo(GoodsAddBo bo) {
|
|
|
Goods add = BeanUtil.toBean(bo, Goods.class);
|
|
|
add.setCode(ServletUtils.getEncoded("SP"));
|
|
|
validEntityBeforeSave(add);
|
|
|
add.setCreateTime(DateUtils.getNowTime());
|
|
|
add.setUpdateTime(DateUtils.getNowTime());
|
|
|
- return this.save(add);
|
|
|
+ boolean result = this.save(add);
|
|
|
+ if(bo.getCourseList()!=null){
|
|
|
+ Collection<GoodsCourse> coll = new HashSet<>();
|
|
|
+ for(int i=0;i<bo.getCourseList().size();i++){
|
|
|
+ GoodsCourseAddBo item = bo.getCourseList().get(i);
|
|
|
+ GoodsCourse addItem = new GoodsCourse();
|
|
|
+ addItem.setGoodsId(add.getGoodsId());
|
|
|
+ addItem.setCourseId(item.getCourseId());
|
|
|
+ addItem.setSort(item.getSort());
|
|
|
+ coll.add(addItem);
|
|
|
+ }
|
|
|
+ iGoodsCourseService.saveBatch(coll);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean updateByEditBo(GoodsEditBo bo) {
|
|
|
Goods update = BeanUtil.toBean(bo, Goods.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ if(bo.getCourseList()!=null){
|
|
|
+ iGoodsCourseService.remove(new LambdaQueryWrapper<GoodsCourse>().eq(GoodsCourse::getGoodsId, bo.getGoodsId()));
|
|
|
+ Collection<GoodsCourse> coll = new HashSet<>();
|
|
|
+ for(int i=0;i<bo.getCourseList().size();i++){
|
|
|
+ GoodsCourseAddBo item = bo.getCourseList().get(i);
|
|
|
+ GoodsCourse addItem = new GoodsCourse();
|
|
|
+ addItem.setGoodsId(update.getGoodsId());
|
|
|
+ addItem.setCourseId(item.getCourseId());
|
|
|
+ addItem.setSort(item.getSort());
|
|
|
+ coll.add(addItem);
|
|
|
+ }
|
|
|
+ iGoodsCourseService.saveBatch(coll);
|
|
|
+ }
|
|
|
return this.updateById(update);
|
|
|
}
|
|
|
|