|
@@ -0,0 +1,142 @@
|
|
|
+package com.zhongzheng.modules.goods.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseSectionWatchPer;
|
|
|
+import com.zhongzheng.modules.goods.bo.GoodsCourseTeacherAddBo;
|
|
|
+import com.zhongzheng.modules.goods.bo.GoodsCourseTeacherEditBo;
|
|
|
+import com.zhongzheng.modules.goods.bo.GoodsCourseTeacherItemBo;
|
|
|
+import com.zhongzheng.modules.goods.bo.GoodsCourseTeacherQueryBo;
|
|
|
+import com.zhongzheng.modules.goods.domain.GoodsCourse;
|
|
|
+import com.zhongzheng.modules.goods.domain.GoodsCourseTeacher;
|
|
|
+import com.zhongzheng.modules.goods.mapper.GoodsCourseTeacherMapper;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsCourseService;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsCourseTeacherService;
|
|
|
+import com.zhongzheng.modules.goods.vo.GoodsCourseTeacherVo;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+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 java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商品课程双师资绑定Service业务层处理
|
|
|
+ *
|
|
|
+ * @author hjl
|
|
|
+ * @date 2022-09-14
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class GoodsCourseTeacherServiceImpl extends ServiceImpl<GoodsCourseTeacherMapper, GoodsCourseTeacher> implements IGoodsCourseTeacherService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGoodsCourseService iGoodsCourseService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GoodsCourseTeacherVo queryById(Long id){
|
|
|
+ GoodsCourseTeacher db = this.baseMapper.selectById(id);
|
|
|
+ return BeanUtil.toBean(db, GoodsCourseTeacherVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GoodsCourseTeacherVo> queryList(GoodsCourseTeacherQueryBo bo) {
|
|
|
+ return baseMapper.getList(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<GoodsCourseTeacherVo> entity2Vo(Collection<GoodsCourseTeacher> collection) {
|
|
|
+ List<GoodsCourseTeacherVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, GoodsCourseTeacherVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<GoodsCourseTeacher> page = (Page<GoodsCourseTeacher>)collection;
|
|
|
+ Page<GoodsCourseTeacherVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(GoodsCourseTeacherAddBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getCourseList())||bo.getCourseList().size()<2){
|
|
|
+ throw new CustomException("课程列表错误");
|
|
|
+ }
|
|
|
+ List<Long> idList = new ArrayList<>();
|
|
|
+ for(GoodsCourseTeacherItemBo item : bo.getCourseList()){
|
|
|
+ idList.add(item.getCourseId());
|
|
|
+ if(Validator.isEmpty(item.getAliasName())||Validator.isEmpty(item.getCourseId())){
|
|
|
+ throw new CustomException("课程参数错误");
|
|
|
+ }
|
|
|
+ iGoodsCourseService.update(new LambdaUpdateWrapper<GoodsCourse>()
|
|
|
+ .set(GoodsCourse::getAliasName,item.getAliasName())
|
|
|
+ .eq(GoodsCourse::getGoodsId,bo.getGoodsId()).eq(GoodsCourse::getCourseId,item.getCourseId()));
|
|
|
+ }
|
|
|
+ String courseIds = StringUtils.join(idList,",");
|
|
|
+ GoodsCourseTeacher add = BeanUtil.toBean(bo, GoodsCourseTeacher.class);
|
|
|
+ add.setCourseIds(courseIds);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(GoodsCourseTeacherEditBo bo) {
|
|
|
+ GoodsCourseTeacher update = BeanUtil.toBean(bo, GoodsCourseTeacher.class);
|
|
|
+ if(Validator.isEmpty(bo.getStatus())||bo.getStatus()!=-1){
|
|
|
+ if(Validator.isEmpty(bo.getCourseList())||bo.getCourseList().size()<2){
|
|
|
+ throw new CustomException("课程列表错误");
|
|
|
+ }
|
|
|
+ List<Long> idList = new ArrayList<>();
|
|
|
+ for(GoodsCourseTeacherItemBo item : bo.getCourseList()){
|
|
|
+ idList.add(item.getCourseId());
|
|
|
+ if(Validator.isEmpty(item.getAliasName())||Validator.isEmpty(item.getCourseId())){
|
|
|
+ throw new CustomException("课程参数错误");
|
|
|
+ }
|
|
|
+ iGoodsCourseService.update(new LambdaUpdateWrapper<GoodsCourse>()
|
|
|
+ .set(GoodsCourse::getAliasName,item.getAliasName())
|
|
|
+ .eq(GoodsCourse::getGoodsId,bo.getGoodsId()).eq(GoodsCourse::getCourseId,item.getCourseId()));
|
|
|
+ }
|
|
|
+ String courseIds = StringUtils.join(idList,",");
|
|
|
+ update.setCourseIds(courseIds);
|
|
|
+ }
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(GoodsCourseTeacher entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+}
|