|
@@ -0,0 +1,424 @@
|
|
|
+package com.zhongzheng.modules.goods.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.domain.CourseBusiness;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseEducationType;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseSubject;
|
|
|
+import com.zhongzheng.modules.course.service.ICourseBusinessService;
|
|
|
+import com.zhongzheng.modules.course.service.ICourseEducationTypeService;
|
|
|
+import com.zhongzheng.modules.course.service.ICourseSubjectService;
|
|
|
+import com.zhongzheng.modules.goods.bo.*;
|
|
|
+import com.zhongzheng.modules.goods.domain.*;
|
|
|
+import com.zhongzheng.modules.goods.mapper.GoodsSpecTemplateMapper;
|
|
|
+import com.zhongzheng.modules.goods.service.*;
|
|
|
+import com.zhongzheng.modules.goods.vo.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 【请填写功能名称】Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2022-09-29
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class GoodsSpecTemplateServiceImpl extends ServiceImpl<GoodsSpecTemplateMapper, GoodsSpecTemplate> implements IGoodsSpecTemplateService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGoodsSpecAttributeService goodsSpecAttributeService;
|
|
|
+ @Autowired
|
|
|
+ public IGoodsSpecService goodsSpecService;
|
|
|
+ @Autowired
|
|
|
+ public IGoodsSpecAttributeRelationService goodsSpecAttributeRelationService;
|
|
|
+ @Autowired
|
|
|
+ public IGoodsService goodsService;
|
|
|
+ @Autowired
|
|
|
+ public ICourseSubjectService courseSubjectService;
|
|
|
+ @Autowired
|
|
|
+ public ICourseEducationTypeService courseEducationTypeService;
|
|
|
+ @Autowired
|
|
|
+ public ICourseBusinessService courseBusinessService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GoodsSpecTemplateVo queryById(Long specTemplateId){
|
|
|
+ GoodsSpecTemplate db = this.baseMapper.selectById(specTemplateId);
|
|
|
+ GoodsSpecTemplateVo vo = BeanUtil.toBean(db, GoodsSpecTemplateVo.class);
|
|
|
+ List<GoodsSpec> specList = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
+ .eq(GoodsSpec::getSpecTemplateId, specTemplateId)
|
|
|
+ .orderByAsc(GoodsSpec::getSort));
|
|
|
+ if (CollectionUtils.isNotEmpty(specList)){
|
|
|
+ List<GoodsSpecVo> specVos = specList.stream().map(item -> {
|
|
|
+ GoodsSpecVo goodsSpecVo = BeanUtil.toBean(item, GoodsSpecVo.class);
|
|
|
+ List<GoodsSpecAttribute> attrList = goodsSpecAttributeService.list(new LambdaQueryWrapper<GoodsSpecAttribute>()
|
|
|
+ .eq(GoodsSpecAttribute::getSpecId, item.getSpecId())
|
|
|
+ .orderByAsc(GoodsSpecAttribute::getSort));
|
|
|
+ if (CollectionUtils.isNotEmpty(attrList)) {
|
|
|
+ List<GoodsSpecAttributeVo> attrVos = attrList.stream().map(x -> BeanUtil.toBean(x, GoodsSpecAttributeVo.class)).collect(Collectors.toList());
|
|
|
+ goodsSpecVo.setSpecAttrList(attrVos);
|
|
|
+ }
|
|
|
+ return goodsSpecVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setSpecList(specVos);
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GoodsSpecTemplateVo> queryList(GoodsSpecTemplateQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<GoodsSpecTemplate> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getCode()), GoodsSpecTemplate::getCode, bo.getCode());
|
|
|
+ lqw.eq(bo.getEducationTypeId() != null, GoodsSpecTemplate::getEducationTypeId, bo.getEducationTypeId());
|
|
|
+ lqw.eq(bo.getBusinessId() != null, GoodsSpecTemplate::getBusinessId, bo.getBusinessId());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getName()), GoodsSpecTemplate::getName, bo.getName());
|
|
|
+ lqw.eq(bo.getStatus() != null, GoodsSpecTemplate::getStatus, bo.getStatus());
|
|
|
+ List<GoodsSpecTemplateVo> vos = entity2Vo(this.list(lqw));
|
|
|
+ if (CollectionUtils.isNotEmpty(vos)){
|
|
|
+ vos.forEach(item -> {
|
|
|
+ CourseEducationType type = courseEducationTypeService.getById(item.getEducationTypeId());
|
|
|
+ if (ObjectUtils.isNotNull(type)){
|
|
|
+ item.setEducationName(type.getEducationName());
|
|
|
+ }
|
|
|
+ CourseBusiness business = courseBusinessService.getById(item.getBusinessId());
|
|
|
+ if (ObjectUtils.isNotNull(business)){
|
|
|
+ item.setBusinessName(business.getAliasName());
|
|
|
+ }
|
|
|
+ int count = goodsSpecService.count(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
+ .eq(GoodsSpec::getSpecTemplateId, item.getSpecTemplateId()));
|
|
|
+ item.setSpecNumber(count);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<GoodsSpecTemplateVo> entity2Vo(Collection<GoodsSpecTemplate> collection) {
|
|
|
+ List<GoodsSpecTemplateVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, GoodsSpecTemplateVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<GoodsSpecTemplate> page = (Page<GoodsSpecTemplate>)collection;
|
|
|
+ Page<GoodsSpecTemplateVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(GoodsSpecTemplateAddBo bo) {
|
|
|
+ GoodsSpecTemplate add = BeanUtil.toBean(bo, GoodsSpecTemplate.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<GoodsSpecAttributeRelationVo> updateByEditBo(GoodsSpecTemplateEditBo bo) {
|
|
|
+ GoodsSpecTemplate goodsSpecTemplate = new GoodsSpecTemplate();
|
|
|
+ BeanUtil.copyProperties(bo,goodsSpecTemplate);
|
|
|
+ goodsSpecTemplate.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ updateById(goodsSpecTemplate);
|
|
|
+ List<GoodsSpecAddBo> specList = bo.getSpecList();
|
|
|
+ List<GoodsSpec> list = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
+ .eq(GoodsSpec::getSpecTemplateId, bo.getSpecTemplateId()));
|
|
|
+ if (CollectionUtils.isEmpty(specList) || specList.stream().anyMatch(x -> ObjectUtils.isNull(x.getSpecId()))){
|
|
|
+ deleteSpecAttr(bo);
|
|
|
+ }else if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ List<Long> collect = list.stream().map(GoodsSpec::getSpecId).collect(Collectors.toList());
|
|
|
+ List<Long> collect1 = specList.stream().filter(x -> ObjectUtils.isNotNull(x.getSpecId())).map(GoodsSpecAddBo::getSpecId).collect(Collectors.toList());
|
|
|
+ if (collect.size() != collect1.size()){
|
|
|
+ //与数据库的规格数量不一样.删除以后重新添加
|
|
|
+ deleteSpecAttr(bo);
|
|
|
+ }else {
|
|
|
+ //只删除或者修改了规格值
|
|
|
+ updateSpecAttr(bo);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ deleteSpecAttr(bo);
|
|
|
+ }
|
|
|
+ specAttrRelList = new ArrayList<>();
|
|
|
+ //组装规格属性列表
|
|
|
+ createSpec(specList,specList.get(0).getSpecAttrList(),0,new ArrayList<>(),goodsSpecTemplate.getSpecTemplateId());
|
|
|
+ return specAttrRelList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateSpecAttr(GoodsSpecTemplateEditBo bo){
|
|
|
+ List<GoodsSpecAddBo> specList = bo.getSpecList();
|
|
|
+ List<Long> attrIds = new ArrayList<>();
|
|
|
+ specList.forEach(item -> {
|
|
|
+ if (CollectionUtils.isNotEmpty(item.getSpecAttrList())){
|
|
|
+ List<Long> collect = item.getSpecAttrList().stream().filter(x -> ObjectUtils.isNotNull(x.getSpecAttributeId())).map(GoodsSpecAttributeAddBo::getSpecAttributeId).collect(Collectors.toList());
|
|
|
+ attrIds.addAll(collect);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Long> specIds = specList.stream().map(GoodsSpecAddBo::getSpecId).collect(Collectors.toList());
|
|
|
+ List<GoodsSpecAttribute> list = goodsSpecAttributeService.list(new LambdaQueryWrapper<GoodsSpecAttribute>()
|
|
|
+ .in(GoodsSpecAttribute::getSpecId, specIds)
|
|
|
+ .notIn(GoodsSpecAttribute::getSpecAttributeId, attrIds));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ list.forEach(item -> {
|
|
|
+ goodsSpecAttributeRelationService.remove(new LambdaQueryWrapper<GoodsSpecAttributeRelation>()
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecTemplateId,bo.getSpecTemplateId())
|
|
|
+ .like(GoodsSpecAttributeRelation::getSpecAttributeIds,item.getSpecAttributeId()));
|
|
|
+ });
|
|
|
+ goodsSpecAttributeService.removeByIds(list.stream().map(GoodsSpecAttribute::getSpecAttributeId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ Integer sort = 1;
|
|
|
+ for (GoodsSpecAddBo spec : specList) {
|
|
|
+ GoodsSpec goodsSpec = new GoodsSpec();
|
|
|
+ BeanUtil.copyProperties(spec,goodsSpec);
|
|
|
+ goodsSpec.setSpecTemplateId(bo.getSpecTemplateId());
|
|
|
+ goodsSpec.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpec.setSort(sort);
|
|
|
+ goodsSpecService.updateById(goodsSpec);
|
|
|
+ spec.setSpecId(goodsSpec.getSpecId());
|
|
|
+ if (CollectionUtils.isNotEmpty(spec.getSpecAttrList())){
|
|
|
+ Integer attrSort = 1;
|
|
|
+ for (GoodsSpecAttributeAddBo item : spec.getSpecAttrList()) {
|
|
|
+ GoodsSpecAttribute goodsSpecAttribute = new GoodsSpecAttribute();
|
|
|
+ BeanUtil.copyProperties(item, goodsSpecAttribute);
|
|
|
+ if (ObjectUtils.isNull(goodsSpecAttribute.getCreateTime())){
|
|
|
+ goodsSpecAttribute.setCreateTime(DateUtils.getNowTime());
|
|
|
+ }
|
|
|
+ goodsSpecAttribute.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpecAttribute.setSpecId(goodsSpec.getSpecId());
|
|
|
+ if (ObjectUtils.isNull(item.getSort())){
|
|
|
+ goodsSpecAttribute.setSort(attrSort);
|
|
|
+ }
|
|
|
+ goodsSpecAttributeService.saveOrUpdate(goodsSpecAttribute);
|
|
|
+ item.setSpecAttributeId(goodsSpecAttribute.getSpecAttributeId());
|
|
|
+ attrSort ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteSpecAttr(GoodsSpecTemplateEditBo bo){
|
|
|
+ List<GoodsSpecAddBo> specList = bo.getSpecList();
|
|
|
+ //有新增的规格
|
|
|
+ List<GoodsSpec> list = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
+ .eq(GoodsSpec::getSpecTemplateId, bo.getSpecTemplateId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ List<Long> collect = list.stream().map(x -> x.getSpecId()).collect(Collectors.toList());
|
|
|
+ //清除规格属性
|
|
|
+ goodsSpecAttributeService.remove(new LambdaQueryWrapper<GoodsSpecAttribute>()
|
|
|
+ .in(GoodsSpecAttribute::getSpecId,collect));
|
|
|
+ //清除属性绑定的商品信息
|
|
|
+ goodsSpecAttributeRelationService.remove(new LambdaQueryWrapper<GoodsSpecAttributeRelation>()
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecTemplateId,bo.getSpecTemplateId()));
|
|
|
+ //清除规格
|
|
|
+ goodsSpecService.remove(new LambdaQueryWrapper<GoodsSpec>().eq(GoodsSpec::getSpecTemplateId,bo.getSpecTemplateId()));
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(specList)){
|
|
|
+ //重新添加规格
|
|
|
+ Integer sort = 1;
|
|
|
+ for (GoodsSpecAddBo spec : specList) {
|
|
|
+ GoodsSpec goodsSpec = new GoodsSpec();
|
|
|
+ BeanUtil.copyProperties(spec,goodsSpec);
|
|
|
+ goodsSpec.setSpecTemplateId(bo.getSpecTemplateId());
|
|
|
+ goodsSpec.setCreateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpec.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpec.setSort(sort);
|
|
|
+ goodsSpecService.save(goodsSpec);
|
|
|
+ spec.setSpecId(goodsSpec.getSpecId());
|
|
|
+ if (CollectionUtils.isNotEmpty(spec.getSpecAttrList())){
|
|
|
+ Integer attrSortId = 1;
|
|
|
+ for (GoodsSpecAttributeAddBo item : spec.getSpecAttrList()) {
|
|
|
+ GoodsSpecAttribute goodsSpecAttribute = new GoodsSpecAttribute();
|
|
|
+ BeanUtil.copyProperties(item, goodsSpecAttribute);
|
|
|
+ goodsSpecAttribute.setCreateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpecAttribute.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpecAttribute.setSpecId(goodsSpec.getSpecId());
|
|
|
+ if (ObjectUtils.isNull(item.getSort())){
|
|
|
+ goodsSpecAttribute.setSort(attrSortId);
|
|
|
+ }
|
|
|
+ goodsSpecAttributeService.save(goodsSpecAttribute);
|
|
|
+ item.setSpecAttributeId(goodsSpecAttribute.getSpecAttributeId());
|
|
|
+ attrSortId ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(GoodsSpecTemplate entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean deleteWithValidByIds(Long id, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ GoodsSpecTemplate template = getById(id);
|
|
|
+ if (Objects.isNull(template)){
|
|
|
+ throw new CustomException("模板信息获取失败");
|
|
|
+ }
|
|
|
+ //删除规格模板关联的信息
|
|
|
+ List<GoodsSpec> list = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
+ .eq(GoodsSpec::getSpecTemplateId, id));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ List<Long> specIds = list.stream().map(GoodsSpec::getSpecId).collect(Collectors.toList());
|
|
|
+ goodsSpecAttributeService.remove(new LambdaQueryWrapper<GoodsSpecAttribute>()
|
|
|
+ .in(GoodsSpecAttribute::getSpecId,specIds));
|
|
|
+ goodsSpecService.remove(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
+ .eq(GoodsSpec::getSpecTemplateId,id));
|
|
|
+ }
|
|
|
+ goodsSpecAttributeRelationService.remove(new LambdaQueryWrapper<GoodsSpecAttributeRelation>()
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecTemplateId,id));
|
|
|
+ return removeById(template);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<GoodsSpecAttributeRelationVo> specAttrRelList;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<GoodsSpecAttributeRelationVo> addSpec(GoodsSpecTemplateAddBo addBo) {
|
|
|
+ //新增模板
|
|
|
+ GoodsSpecTemplate goodsSpecTemplate = new GoodsSpecTemplate();
|
|
|
+ BeanUtil.copyProperties(addBo,goodsSpecTemplate);
|
|
|
+ goodsSpecTemplate.setCreateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpecTemplate.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ save(goodsSpecTemplate);
|
|
|
+ addBo.setSpecTemplateId(goodsSpecTemplate.getSpecTemplateId());
|
|
|
+ List<GoodsSpecAddBo> bos = addBo.getSpecList();
|
|
|
+ Integer sort = 1;//排序值
|
|
|
+ //新增规格和规格值
|
|
|
+ for (GoodsSpecAddBo bo : bos) {
|
|
|
+ GoodsSpec goodsSpec = new GoodsSpec();
|
|
|
+ BeanUtil.copyProperties(bo,goodsSpec);
|
|
|
+ goodsSpec.setSpecTemplateId(goodsSpecTemplate.getSpecTemplateId());
|
|
|
+ goodsSpec.setCreateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpec.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpec.setSort(sort);
|
|
|
+ goodsSpecService.save(goodsSpec);
|
|
|
+ bo.setSpecId(goodsSpec.getSpecId());
|
|
|
+ Integer attrSort = 1;//排序值
|
|
|
+ if (CollectionUtils.isNotEmpty(bo.getSpecAttrList())){
|
|
|
+ for (GoodsSpecAttributeAddBo item : bo.getSpecAttrList()) {
|
|
|
+ GoodsSpecAttribute goodsSpecAttribute = new GoodsSpecAttribute();
|
|
|
+ BeanUtil.copyProperties(item, goodsSpecAttribute);
|
|
|
+ goodsSpecAttribute.setCreateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpecAttribute.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ goodsSpecAttribute.setSpecId(goodsSpec.getSpecId());
|
|
|
+ if (ObjectUtils.isNull(item.getSort())){
|
|
|
+ item.setSort(attrSort);
|
|
|
+ }
|
|
|
+ goodsSpecAttributeService.save(goodsSpecAttribute);
|
|
|
+ item.setSpecAttributeId(goodsSpecAttribute.getSpecAttributeId());
|
|
|
+ attrSort ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort ++;
|
|
|
+ }
|
|
|
+ specAttrRelList = new ArrayList<>();
|
|
|
+ //组装规格属性列表
|
|
|
+ createSpec(bos,bos.get(0).getSpecAttrList(),0,new ArrayList<>(),goodsSpecTemplate.getSpecTemplateId());
|
|
|
+ return specAttrRelList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createSpec(List<GoodsSpecAddBo> bos, List<GoodsSpecAttributeAddBo> specAttrList, int index, List<GoodsSpecAttrListVo> vos,Long specTemplateId) {
|
|
|
+ for (int k = 0; k < specAttrList.size(); k++) {
|
|
|
+ List<GoodsSpecAttrListVo> attrListVos = copyList(vos);
|
|
|
+ if (index < bos.size() - 1){
|
|
|
+ GoodsSpecAttrListVo vo = new GoodsSpecAttrListVo();
|
|
|
+ vo.setKey(specAttrList.get(k).getSpecAttributeId());
|
|
|
+ vo.setValue(specAttrList.get(k).getName());
|
|
|
+ attrListVos.add(vo);
|
|
|
+ createSpec(bos,bos.get(index + 1).getSpecAttrList(),index + 1,attrListVos,specTemplateId);
|
|
|
+ }else {
|
|
|
+ GoodsSpecAttrListVo vo = new GoodsSpecAttrListVo();
|
|
|
+ vo.setKey(specAttrList.get(k).getSpecAttributeId());
|
|
|
+ vo.setValue(specAttrList.get(k).getName());
|
|
|
+ attrListVos.add(vo);
|
|
|
+ GoodsSpecAttributeRelationVo relationVo = new GoodsSpecAttributeRelationVo();
|
|
|
+ relationVo.setAttrListVos(attrListVos);
|
|
|
+ //模板信息
|
|
|
+ GoodsSpecTemplate specTemplate = getById(specTemplateId);
|
|
|
+ relationVo.setSpecTemplateId(specTemplate.getSpecTemplateId());
|
|
|
+ relationVo.setEducationTypeId(specTemplate.getEducationTypeId());
|
|
|
+ relationVo.setBusinessId(specTemplate.getBusinessId());
|
|
|
+ List<Long> attrIds = attrListVos.stream().map(GoodsSpecAttrListVo::getKey).collect(Collectors.toList());
|
|
|
+ //添加商品信息
|
|
|
+ GoodsSpecAttributeRelation attributeRelations = goodsSpecAttributeRelationService
|
|
|
+ .getOne(new LambdaQueryWrapper<GoodsSpecAttributeRelation>()
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecTemplateId, specTemplateId)
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecAttributeIds,StringUtils.join(attrIds,",")));
|
|
|
+ if (ObjectUtils.isNotNull(attributeRelations) && ObjectUtils.isNotNull(attributeRelations.getGoodsId())){
|
|
|
+ Goods goods = goodsService.getById(attributeRelations.getGoodsId());
|
|
|
+ relationVo.setGoodsName(goods.getGoodsName());
|
|
|
+ relationVo.setGoodsType(goods.getGoodsType());
|
|
|
+ relationVo.setGoodsStatus(goods.getGoodsStatus());
|
|
|
+ relationVo.setCode(goods.getCode());
|
|
|
+ relationVo.setGoodsId(goods.getGoodsId());
|
|
|
+ relationVo.setServiceTimeNum(goods.getServiceTimeNum());
|
|
|
+ relationVo.setServiceTimeType(goods.getServiceTimeType());
|
|
|
+ relationVo.setStandPrice(goods.getStandPrice());
|
|
|
+ relationVo.setValidityStartTime(goods.getValidityStartTime());
|
|
|
+ relationVo.setValidityEndTime(goods.getValidityEndTime());
|
|
|
+ if (StrUtil.isNotBlank(goods.getSubjectIds())) {
|
|
|
+ relationVo.setSubjectIds(goods.getSubjectIds());
|
|
|
+ List<String> ids = Arrays.stream(goods.getSubjectIds().split(",")).collect(Collectors.toList());
|
|
|
+ //科目名称
|
|
|
+ List<CourseSubject> subjectList = courseSubjectService.list(new LambdaQueryWrapper<CourseSubject>()
|
|
|
+ .in(CourseSubject::getId, ids));
|
|
|
+ List<String> names = subjectList.stream().map(CourseSubject::getSubjectName).collect(Collectors.toList());
|
|
|
+ relationVo.setSubjectNames(StringUtils.join(names, ","));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ specAttrRelList.add(relationVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<GoodsSpecAttrListVo> copyList(List<GoodsSpecAttrListVo> list){
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return list.stream().map(x -> BeanUtil.toBean(x,GoodsSpecAttrListVo.class)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GoodsVo getSpecTemplate(Long specTemplateId, String specAttrIds) {
|
|
|
+ GoodsSpecAttributeRelation relation = goodsSpecAttributeRelationService.getOne(new LambdaQueryWrapper<GoodsSpecAttributeRelation>()
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecTemplateId, specTemplateId)
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecAttributeIds, specAttrIds));
|
|
|
+ if (ObjectUtils.isNull(relation) || ObjectUtils.isNull(relation.getGoodsId())){
|
|
|
+ throw new CustomException("该规格属性下没有设置商品!请检查");
|
|
|
+ }
|
|
|
+ Goods goods = goodsService.getById(relation.getGoodsId());
|
|
|
+ return BeanUtil.toBean(goods,GoodsVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|