|
@@ -0,0 +1,123 @@
|
|
|
+package com.zhongzheng.modules.goods.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.goods.bo.GoodsAddBo;
|
|
|
+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.mapper.GoodsMapper;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
+import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
+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.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商品Service业务层处理
|
|
|
+ *
|
|
|
+ * @author hjl
|
|
|
+ * @date 2021-10-12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GoodsVo queryById(Long goodsId){
|
|
|
+ Goods db = this.baseMapper.selectById(goodsId);
|
|
|
+ return BeanUtil.toBean(db, GoodsVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GoodsVo> queryList(GoodsQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<Goods> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getYear() != null, Goods::getYear, bo.getYear());
|
|
|
+ lqw.eq(bo.getSupplier() != null, Goods::getSupplier, bo.getSupplier());
|
|
|
+ lqw.eq(bo.getGoodsType() != null, Goods::getGoodsType, bo.getGoodsType());
|
|
|
+ lqw.eq(bo.getEducationTypeId() != null, Goods::getEducationTypeId, bo.getEducationTypeId());
|
|
|
+ lqw.eq(bo.getBusinessId() != null, Goods::getBusinessId, bo.getBusinessId());
|
|
|
+ lqw.eq(bo.getSchoolId() != null, Goods::getSchoolId, bo.getSchoolId());
|
|
|
+ lqw.eq(bo.getMajorId() != null, Goods::getMajorId, bo.getMajorId());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getGoodsName()), Goods::getGoodsName, bo.getGoodsName());
|
|
|
+ lqw.eq(bo.getStandPrice() != null, Goods::getStandPrice, bo.getStandPrice());
|
|
|
+ lqw.eq(bo.getLowestPrice() != null, Goods::getLowestPrice, bo.getLowestPrice());
|
|
|
+ lqw.eq(bo.getStatus() != null, Goods::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(bo.getValidityStartTime() != null, Goods::getValidityStartTime, bo.getValidityStartTime());
|
|
|
+ lqw.eq(bo.getValidityEndTime() != null, Goods::getValidityEndTime, bo.getValidityEndTime());
|
|
|
+ lqw.eq(bo.getStudyStartTime() != null, Goods::getStudyStartTime, bo.getStudyStartTime());
|
|
|
+ lqw.eq(bo.getStudyEndTime() != null, Goods::getStudyEndTime, bo.getStudyEndTime());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getCertificateIds()), Goods::getCertificateIds, bo.getCertificateIds());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getIntroduce()), Goods::getIntroduce, bo.getIntroduce());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getSuitableObject()), Goods::getSuitableObject, bo.getSuitableObject());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getBuyNote()), Goods::getBuyNote, bo.getBuyNote());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getPcDetailHtml()), Goods::getPcDetailHtml, bo.getPcDetailHtml());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getMobileDetailHtml()), Goods::getMobileDetailHtml, bo.getMobileDetailHtml());
|
|
|
+ lqw.eq(bo.getGoodsStatus() != null, Goods::getGoodsStatus, bo.getGoodsStatus());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getCoverUrl()), Goods::getCoverUrl, bo.getCoverUrl());
|
|
|
+ lqw.eq(bo.getClassHours() != null, Goods::getClassHours, bo.getClassHours());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getStandPriceJson()), Goods::getStandPriceJson, bo.getStandPriceJson());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<GoodsVo> entity2Vo(Collection<Goods> collection) {
|
|
|
+ List<GoodsVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, GoodsVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<Goods> page = (Page<Goods>)collection;
|
|
|
+ Page<GoodsVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(GoodsAddBo bo) {
|
|
|
+ Goods add = BeanUtil.toBean(bo, Goods.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(GoodsEditBo bo) {
|
|
|
+ Goods update = BeanUtil.toBean(bo, Goods.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(Goods entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+}
|