|
@@ -0,0 +1,133 @@
|
|
|
+package com.zhongzheng.modules.course.service.impl;
|
|
|
+
|
|
|
+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.CourseHandoutsBusinessAddBo;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseEducationTier;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseHandoutsBusiness;
|
|
|
+import com.zhongzheng.modules.course.service.ICourseHandoutsBusinessService;
|
|
|
+import com.zhongzheng.modules.course.vo.CourseHandoutsBusinessVo;
|
|
|
+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 com.zhongzheng.modules.course.bo.CourseHandoutsAddBo;
|
|
|
+import com.zhongzheng.modules.course.bo.CourseHandoutsQueryBo;
|
|
|
+import com.zhongzheng.modules.course.bo.CourseHandoutsEditBo;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseHandouts;
|
|
|
+import com.zhongzheng.modules.course.mapper.CourseHandoutsMapper;
|
|
|
+import com.zhongzheng.modules.course.vo.CourseHandoutsVo;
|
|
|
+import com.zhongzheng.modules.course.service.ICourseHandoutsService;
|
|
|
+
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 讲义列Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2021-11-02
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CourseHandoutsServiceImpl extends ServiceImpl<CourseHandoutsMapper, CourseHandouts> implements ICourseHandoutsService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseHandoutsBusinessService courseHandoutsBusinessService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CourseHandoutsVo queryById(Long handoutsId){
|
|
|
+ CourseHandouts db = this.baseMapper.selectById(handoutsId);
|
|
|
+ return BeanUtil.toBean(db, CourseHandoutsVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CourseHandoutsVo> queryList(CourseHandoutsQueryBo bo) {
|
|
|
+
|
|
|
+ return entity2Vo(baseMapper.queryList(bo));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<CourseHandoutsVo> entity2Vo(Collection<CourseHandouts> collection) {
|
|
|
+ List<CourseHandoutsVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, CourseHandoutsVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<CourseHandouts> page = (Page<CourseHandouts>)collection;
|
|
|
+ Page<CourseHandoutsVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ for (CourseHandoutsVo courseHandoutsVo : voList) {
|
|
|
+ List<CourseHandoutsBusinessVo> courseHandoutsBusinessVos = baseMapper.selectEntity(courseHandoutsVo.getHandoutsId());
|
|
|
+ courseHandoutsVo.setCourseHandoutsBusinessVo(courseHandoutsBusinessVos);
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(CourseHandoutsAddBo bo) {
|
|
|
+ CourseHandouts add = BeanUtil.toBean(bo, CourseHandouts.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ add.setEncoder(ServletUtils.getEncoded("JYLB"));
|
|
|
+ boolean save = this.save(add);
|
|
|
+ for (CourseHandoutsBusinessAddBo courseHandoutsBusinessAddBo : bo.getCourseHandoutsBusinessAddBos()) {
|
|
|
+ CourseHandoutsBusiness addBusiness = BeanUtil.toBean(courseHandoutsBusinessAddBo, CourseHandoutsBusiness.class);
|
|
|
+ addBusiness.setHandoutsId(add.getHandoutsId());
|
|
|
+ addBusiness.setCreateTime(DateUtils.getNowTime());
|
|
|
+ addBusiness.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ courseHandoutsBusinessService.save(addBusiness);
|
|
|
+ }
|
|
|
+ return save;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(CourseHandoutsEditBo bo) {
|
|
|
+ CourseHandouts update = BeanUtil.toBean(bo, CourseHandouts.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ LambdaQueryWrapper<CourseHandoutsBusiness> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(CourseHandoutsBusiness::getHandoutsId,bo.getHandoutsId());
|
|
|
+ courseHandoutsBusinessService.remove(lqw);
|
|
|
+ for (CourseHandoutsBusinessAddBo courseHandoutsBusinessAddBo : bo.getCourseHandoutsBusinessAddBos()) {
|
|
|
+ CourseHandoutsBusiness addBusiness = BeanUtil.toBean(courseHandoutsBusinessAddBo, CourseHandoutsBusiness.class);
|
|
|
+ addBusiness.setHandoutsId(bo.getHandoutsId());
|
|
|
+ addBusiness.setCreateTime(DateUtils.getNowTime());
|
|
|
+ addBusiness.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ courseHandoutsBusinessService.save(addBusiness);
|
|
|
+ }
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(CourseHandouts entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+}
|