|
@@ -0,0 +1,206 @@
|
|
|
+package com.zhongzheng.modules.course.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.course.bo.*;
|
|
|
+import com.zhongzheng.modules.course.domain.*;
|
|
|
+import com.zhongzheng.modules.course.mapper.CourseTopicMapper;
|
|
|
+import com.zhongzheng.modules.course.service.*;
|
|
|
+import com.zhongzheng.modules.course.vo.CourseTopicGoodsVo;
|
|
|
+import com.zhongzheng.modules.course.vo.CourseTopicVo;
|
|
|
+import com.zhongzheng.modules.goods.domain.Goods;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
+import com.zhongzheng.modules.wx.service.IWxLoginService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 【请填写功能名称】Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2022-09-13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CourseTopicServiceImpl extends ServiceImpl<CourseTopicMapper, CourseTopic> implements ICourseTopicService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseEducationTypeService iCourseEducationTypeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseProjectTypeService iCourseProjectTypeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseBusinessService iCourseBusinessService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseTopicGoodsService iCourseTopicGoodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGoodsService iGoodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWxLoginService wxLoginService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CourseTopicVo queryById(Long topicId){
|
|
|
+ CourseTopic db = this.baseMapper.selectById(topicId);
|
|
|
+ return BeanUtil.toBean(db, CourseTopicVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CourseTopicVo> queryList(CourseTopicQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<CourseTopic> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getEducationId() != null, CourseTopic::getEducationId, bo.getEducationId());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getEducationName()), CourseTopic::getEducationName, bo.getEducationName());
|
|
|
+ lqw.eq(bo.getProjectId() != null, CourseTopic::getProjectId, bo.getProjectId());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getProjectName()), CourseTopic::getProjectName, bo.getProjectName());
|
|
|
+ lqw.eq(bo.getBusinessId() != null, CourseTopic::getBusinessId, bo.getBusinessId());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getBusinessName()), CourseTopic::getBusinessName, bo.getBusinessName());
|
|
|
+ lqw.eq(bo.getGoodsId() != null, CourseTopic::getGoodsId, bo.getGoodsId());
|
|
|
+ lqw.eq(bo.getType() != null, CourseTopic::getType, bo.getType());
|
|
|
+ lqw.eq( CourseTopic::getStatus, 1);
|
|
|
+ List<CourseTopicVo> courseTopicVos = entity2Vo(this.list(lqw));
|
|
|
+ courseTopicVos.forEach(item -> {
|
|
|
+ //todo 小程序二维码和PC链接
|
|
|
+ String enCode = wxLoginService.getTopicEnCode(item.getTopicId());
|
|
|
+ item.setEnCode(enCode);
|
|
|
+ });
|
|
|
+ return courseTopicVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<CourseTopicVo> entity2Vo(Collection<CourseTopic> collection) {
|
|
|
+ List<CourseTopicVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, CourseTopicVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<CourseTopic> page = (Page<CourseTopic>)collection;
|
|
|
+ Page<CourseTopicVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(CourseTopicAddBo bo) {
|
|
|
+ CourseTopic add = BeanUtil.toBean(bo, CourseTopic.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ //获取信息
|
|
|
+ CourseEducationType educationType = iCourseEducationTypeService.getById(bo.getEducationId());
|
|
|
+ if (ObjectUtils.isNotNull(educationType)){
|
|
|
+ add.setEducationName(educationType.getEducationName());
|
|
|
+ }
|
|
|
+ CourseProjectType projectType = iCourseProjectTypeService.getById(bo.getProjectId());
|
|
|
+ if (ObjectUtils.isNotNull(projectType)){
|
|
|
+ add.setProjectName(projectType.getProjectName());
|
|
|
+ }
|
|
|
+ CourseBusiness business = iCourseBusinessService.getById(bo.getBusinessId());
|
|
|
+ if (ObjectUtils.isNotNull(business)){
|
|
|
+ add.setBusinessName(business.getBusinessName());
|
|
|
+ }
|
|
|
+ Goods goods = iGoodsService.getById(bo.getGoodsId());
|
|
|
+ if (ObjectUtils.isNotNull(goods)){
|
|
|
+ add.setGoodsType(goods.getGoodsType());
|
|
|
+ }
|
|
|
+ add.setStatus(1);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(CourseTopicEditBo bo) {
|
|
|
+ CourseTopic update = BeanUtil.toBean(bo, CourseTopic.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(CourseTopic entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addGoods(List<CourseTopicGoodsAddBo> bo) {
|
|
|
+ List<CourseTopicGoods> goodsList = bo.stream().map(item -> {
|
|
|
+ CourseTopicGoods tbTopic = new CourseTopicGoods();
|
|
|
+ BeanUtil.copyProperties(item, tbTopic);
|
|
|
+ Goods goods = iGoodsService.getById(item.getGoodsId());
|
|
|
+ tbTopic.setStandPrice(goods.getStandPrice());
|
|
|
+ tbTopic.setLowestPrice(goods.getLowestPrice());
|
|
|
+ tbTopic.setLinePrice(goods.getLinePrice());
|
|
|
+ tbTopic.setStatus(1);
|
|
|
+ tbTopic.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ tbTopic.setCreateTime(DateUtils.getNowTime());
|
|
|
+ return tbTopic;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return iCourseTopicGoodsService.saveBatch(goodsList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CourseTopicVo getGoodsInfo(Integer topicId) {
|
|
|
+ CourseTopic courseTopic = getById(topicId);
|
|
|
+ if (ObjectUtils.isNull(courseTopic)){
|
|
|
+ throw new CustomException("专题页信息获取失败");
|
|
|
+ }
|
|
|
+ CourseTopicVo courseTopicVo = new CourseTopicVo();
|
|
|
+ BeanUtil.copyProperties(courseTopic,courseTopicVo);
|
|
|
+ if (ObjectUtils.isNotNull(courseTopicVo.getGoodsId())){
|
|
|
+ Goods goods = iGoodsService.getById(courseTopicVo.getGoodsId());
|
|
|
+ courseTopicVo.setGoodsName(goods.getGoodsName());
|
|
|
+ courseTopicVo.setGoodsCoverUrl(goods.getCoverUrl());
|
|
|
+ }
|
|
|
+ return courseTopicVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CourseTopicGoodsVo> getGoodsList(CourseTopicGoodsQueryBo bo) {
|
|
|
+ List<CourseTopicGoods> list = iCourseTopicGoodsService.list(new LambdaQueryWrapper<CourseTopicGoods>()
|
|
|
+ .eq(CourseTopicGoods::getTopicId, bo.getTopicId())
|
|
|
+ .eq(CourseTopicGoods::getType, bo.getType())
|
|
|
+ .eq(CourseTopicGoods::getSubjectType, bo.getSubjectType())
|
|
|
+ .eq(CourseTopicGoods::getStatus, 1));
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return list.stream().map(item ->{
|
|
|
+ CourseTopicGoodsVo vo = new CourseTopicGoodsVo();
|
|
|
+ BeanUtil.copyProperties(item, vo);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+}
|