|
@@ -1224,325 +1224,340 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean goodsBatchCopyIncrementTenant(GoodsBatchCopyTenantBo bo) {
|
|
|
- //获取商品信息
|
|
|
- List<Goods> goodsList = list(new LambdaQueryWrapper<Goods>()
|
|
|
- .in(CollectionUtils.isNotEmpty(bo.getGoodsIds()), Goods::getGoodsId, bo.getGoodsIds()));
|
|
|
- if (CollectionUtils.isEmpty(goodsList)){
|
|
|
- return true;
|
|
|
+ if (CollectionUtils.isNotEmpty(bo.getGoodsIds()) && bo.getGoodsIds().size() > 10){
|
|
|
+ throw new CustomException("商品复制一次最多10条!");
|
|
|
}
|
|
|
- Long tenantId = 867735392558919680L;
|
|
|
- Long newTenantId = bo.getTenantId();
|
|
|
- List<GoodsSpecAttributeRelation> newRelationList = new ArrayList<>();
|
|
|
- List<SysGoodsCopyRecord> recordList = new ArrayList<>();
|
|
|
- for (Goods goods : goodsList) {
|
|
|
- Long oldGoodsId = goods.getGoodsId();
|
|
|
- //判断商品是否存在
|
|
|
- Long newGoodsId = getNewIdByTenant(goods.getGoodsId(), GoodsCopyEnum.GOODS.getType(),newTenantId);
|
|
|
+ String key = "GOODS_COPY";
|
|
|
+ Object object = redisCache.getCacheObject(key);
|
|
|
+ if (ObjectUtils.isNotNull(object)){
|
|
|
+ throw new CustomException("存在商品正在复制中,请稍后重试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ redisCache.setCacheObject(key,DateUtils.getNowTime(),30,TimeUnit.MINUTES);
|
|
|
+ //获取商品信息
|
|
|
+ List<Goods> goodsList = list(new LambdaQueryWrapper<Goods>()
|
|
|
+ .in(CollectionUtils.isNotEmpty(bo.getGoodsIds()), Goods::getGoodsId, bo.getGoodsIds()));
|
|
|
+ if (CollectionUtils.isEmpty(goodsList)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ Long tenantId = 867735392558919680L;
|
|
|
+ Long newTenantId = bo.getTenantId();
|
|
|
+ List<GoodsSpecAttributeRelation> newRelationList = new ArrayList<>();
|
|
|
+ List<SysGoodsCopyRecord> recordList = new ArrayList<>();
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ Long oldGoodsId = goods.getGoodsId();
|
|
|
+ //判断商品是否存在
|
|
|
+ Long newGoodsId = getNewIdByTenant(goods.getGoodsId(), GoodsCopyEnum.GOODS.getType(),newTenantId);
|
|
|
// Goods newGoods = this.baseMapper.queryGoodsByTenant(goods.getCode(),newTenantId);
|
|
|
- if (ObjectUtils.isNull(newGoodsId)){
|
|
|
- //不存在(新增)
|
|
|
- goods.setGoodsId(null);
|
|
|
- goods.setTenantId(newTenantId);
|
|
|
- }else {
|
|
|
- //修改
|
|
|
- goods.setGoodsId(newGoodsId);
|
|
|
- goods.setTenantId(newTenantId);
|
|
|
- }
|
|
|
+ if (ObjectUtils.isNull(newGoodsId)){
|
|
|
+ //不存在(新增)
|
|
|
+ goods.setGoodsId(null);
|
|
|
+ goods.setTenantId(newTenantId);
|
|
|
+ }else {
|
|
|
+ //修改
|
|
|
+ goods.setGoodsId(newGoodsId);
|
|
|
+ goods.setTenantId(newTenantId);
|
|
|
+ }
|
|
|
|
|
|
- //供应方ID
|
|
|
- if (ObjectUtil.isNotNull(goods.getSupplyId())){
|
|
|
- PaySupply supply = iPaySupplyService.getById(goods.getSupplyId());
|
|
|
- if (ObjectUtils.isNotNull(supply)){
|
|
|
- Long oldSupplyId = supply.getSupplyId();
|
|
|
- //新机构是否存在
|
|
|
- Long newSupplyId = getNewIdByTenant(supply.getSupplyId(), GoodsCopyEnum.PAY_SUPPLY.getType(),newTenantId);
|
|
|
- if (ObjectUtil.isNotNull(newSupplyId)){
|
|
|
- goods.setSupplyId(newSupplyId);
|
|
|
- }else {
|
|
|
- supply.setSupplyId(null);
|
|
|
- supply.setTenantId(newTenantId);
|
|
|
- //服务类型ID
|
|
|
- if (ObjectUtil.isNotNull(supply.getServerId())){
|
|
|
- PayServe payServe = iPayServeService.getById(supply.getServerId());
|
|
|
- Long oldServeId = payServe.getServeId();
|
|
|
- if (ObjectUtils.isNotNull(payServe)){
|
|
|
- Long newPayServerId = getNewIdByTenant(payServe.getServeId(), GoodsCopyEnum.PAY_SERVE.getType(),newTenantId);
|
|
|
- if (ObjectUtils.isNotNull(newPayServerId)){
|
|
|
- supply.setServerId(newPayServerId);
|
|
|
- }else {
|
|
|
- //新增服务
|
|
|
- payServe.setServeId(null);
|
|
|
- payServe.setTenantId(newTenantId);
|
|
|
- iPayServeService.save(payServe);
|
|
|
- supply.setServerId(payServe.getServeId());
|
|
|
- addSysGoodsRecord(oldServeId,payServe.getServeId(),GoodsCopyEnum.PAY_SERVE.getType(),newTenantId,recordList);
|
|
|
+ //供应方ID
|
|
|
+ if (ObjectUtil.isNotNull(goods.getSupplyId())){
|
|
|
+ PaySupply supply = iPaySupplyService.getById(goods.getSupplyId());
|
|
|
+ if (ObjectUtils.isNotNull(supply)){
|
|
|
+ Long oldSupplyId = supply.getSupplyId();
|
|
|
+ //新机构是否存在
|
|
|
+ Long newSupplyId = getNewIdByTenant(supply.getSupplyId(), GoodsCopyEnum.PAY_SUPPLY.getType(),newTenantId);
|
|
|
+ if (ObjectUtil.isNotNull(newSupplyId)){
|
|
|
+ goods.setSupplyId(newSupplyId);
|
|
|
+ }else {
|
|
|
+ supply.setSupplyId(null);
|
|
|
+ supply.setTenantId(newTenantId);
|
|
|
+ //服务类型ID
|
|
|
+ if (ObjectUtil.isNotNull(supply.getServerId())){
|
|
|
+ PayServe payServe = iPayServeService.getById(supply.getServerId());
|
|
|
+ Long oldServeId = payServe.getServeId();
|
|
|
+ if (ObjectUtils.isNotNull(payServe)){
|
|
|
+ Long newPayServerId = getNewIdByTenant(payServe.getServeId(), GoodsCopyEnum.PAY_SERVE.getType(),newTenantId);
|
|
|
+ if (ObjectUtils.isNotNull(newPayServerId)){
|
|
|
+ supply.setServerId(newPayServerId);
|
|
|
+ }else {
|
|
|
+ //新增服务
|
|
|
+ payServe.setServeId(null);
|
|
|
+ payServe.setTenantId(newTenantId);
|
|
|
+ iPayServeService.save(payServe);
|
|
|
+ supply.setServerId(payServe.getServeId());
|
|
|
+ addSysGoodsRecord(oldServeId,payServe.getServeId(),GoodsCopyEnum.PAY_SERVE.getType(),newTenantId,recordList);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ iPaySupplyService.save(supply);
|
|
|
+ goods.setSupplyId(supply.getSupplyId());
|
|
|
+ addSysGoodsRecord(oldSupplyId,supply.getSupplyId(),GoodsCopyEnum.PAY_SUPPLY.getType(),newTenantId,recordList);
|
|
|
}
|
|
|
- iPaySupplyService.save(supply);
|
|
|
- goods.setSupplyId(supply.getSupplyId());
|
|
|
- addSysGoodsRecord(oldSupplyId,supply.getSupplyId(),GoodsCopyEnum.PAY_SUPPLY.getType(),newTenantId,recordList);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //教育类型
|
|
|
- if (ObjectUtil.isNotNull(goods.getEducationTypeId())){
|
|
|
- goods.setEducationTypeId(getNewEducationTypeId(goods.getEducationTypeId(),newTenantId,recordList));
|
|
|
- }
|
|
|
+ //教育类型
|
|
|
+ if (ObjectUtil.isNotNull(goods.getEducationTypeId())){
|
|
|
+ goods.setEducationTypeId(getNewEducationTypeId(goods.getEducationTypeId(),newTenantId,recordList));
|
|
|
+ }
|
|
|
|
|
|
- //业务层次
|
|
|
- if (ObjectUtil.isNotNull(goods.getBusinessId())){
|
|
|
- goods.setBusinessId(getNewBusinessId(goods.getBusinessId(),newTenantId,recordList));
|
|
|
- }
|
|
|
-
|
|
|
- //所属院校
|
|
|
- if (ObjectUtil.isNotNull(goods.getSchoolId())){
|
|
|
- School school = iSchoolService.getById(goods.getSchoolId());
|
|
|
- if (ObjectUtil.isNotNull(school)){
|
|
|
- Long oid = school.getId();
|
|
|
- School newSchool = iSchoolService.getSchoolByTenant(school.getEncoder(),newTenantId);
|
|
|
- if (ObjectUtil.isNotNull(newSchool)){
|
|
|
- goods.setSchoolId(newSchool.getId());
|
|
|
- }else {
|
|
|
- school.setId(null);
|
|
|
- school.setTenantId(newTenantId);
|
|
|
- iSchoolService.save(school);
|
|
|
- goods.setSchoolId(school.getId());
|
|
|
- addSysGoodsRecord(oid,school.getId(),GoodsCopyEnum.SCHOOL.getType(),newTenantId,recordList);
|
|
|
+ //业务层次
|
|
|
+ if (ObjectUtil.isNotNull(goods.getBusinessId())){
|
|
|
+ goods.setBusinessId(getNewBusinessId(goods.getBusinessId(),newTenantId,recordList));
|
|
|
+ }
|
|
|
+
|
|
|
+ //所属院校
|
|
|
+ if (ObjectUtil.isNotNull(goods.getSchoolId())){
|
|
|
+ School school = iSchoolService.getById(goods.getSchoolId());
|
|
|
+ if (ObjectUtil.isNotNull(school)){
|
|
|
+ Long oid = school.getId();
|
|
|
+ School newSchool = iSchoolService.getSchoolByTenant(school.getEncoder(),newTenantId);
|
|
|
+ if (ObjectUtil.isNotNull(newSchool)){
|
|
|
+ goods.setSchoolId(newSchool.getId());
|
|
|
+ }else {
|
|
|
+ school.setId(null);
|
|
|
+ school.setTenantId(newTenantId);
|
|
|
+ iSchoolService.save(school);
|
|
|
+ goods.setSchoolId(school.getId());
|
|
|
+ addSysGoodsRecord(oid,school.getId(),GoodsCopyEnum.SCHOOL.getType(),newTenantId,recordList);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //所属专业
|
|
|
- if (ObjectUtil.isNotNull(goods.getMajorId())){
|
|
|
- goods.setMajorId(getNewMajorId(goods.getMajorId(),newTenantId,recordList));
|
|
|
- }
|
|
|
+ //所属专业
|
|
|
+ if (ObjectUtil.isNotNull(goods.getMajorId())){
|
|
|
+ goods.setMajorId(getNewMajorId(goods.getMajorId(),newTenantId,recordList));
|
|
|
+ }
|
|
|
|
|
|
- //项目
|
|
|
- if (ObjectUtil.isNotNull(goods.getProjectId())){
|
|
|
- goods.setProjectId(getNewProjectTypeId(goods.getProjectId().longValue(),newTenantId,recordList).intValue());
|
|
|
- }
|
|
|
+ //项目
|
|
|
+ if (ObjectUtil.isNotNull(goods.getProjectId())){
|
|
|
+ goods.setProjectId(getNewProjectTypeId(goods.getProjectId().longValue(),newTenantId,recordList).intValue());
|
|
|
+ }
|
|
|
|
|
|
- //讲义
|
|
|
- if (ObjectUtil.isNotNull(goods.getHandoutsId())){
|
|
|
- CourseHandouts courseHandouts = iCourseHandoutsService.getById(goods.getHandoutsId());
|
|
|
- if (ObjectUtil.isNotNull(courseHandouts)){
|
|
|
- Long oid = courseHandouts.getHandoutsId();
|
|
|
- Long newId = getNewIdByTenant(oid, GoodsCopyEnum.COURSE_HANDOUTS.getType(),newTenantId);
|
|
|
+ //讲义
|
|
|
+ if (ObjectUtil.isNotNull(goods.getHandoutsId())){
|
|
|
+ CourseHandouts courseHandouts = iCourseHandoutsService.getById(goods.getHandoutsId());
|
|
|
+ if (ObjectUtil.isNotNull(courseHandouts)){
|
|
|
+ Long oid = courseHandouts.getHandoutsId();
|
|
|
+ Long newId = getNewIdByTenant(oid, GoodsCopyEnum.COURSE_HANDOUTS.getType(),newTenantId);
|
|
|
// CourseHandouts newCourseHandouts = iCourseHandoutsService.getHandoutsByTenant(courseHandouts.getEncoder(),newTenantId);
|
|
|
- if (ObjectUtil.isNotNull(newId)){
|
|
|
- goods.setHandoutsId(newId);
|
|
|
- }else {
|
|
|
- //讲义业务层次
|
|
|
- List<CourseHandoutsBusiness> handoutsBusinessList = iCourseHandoutsBusinessService
|
|
|
- .list(new LambdaQueryWrapper<CourseHandoutsBusiness>()
|
|
|
- .eq(CourseHandoutsBusiness::getHandoutsId, courseHandouts.getHandoutsId()));
|
|
|
- courseHandouts.setHandoutsId(null);
|
|
|
- courseHandouts.setTenantId(newTenantId);
|
|
|
- iCourseHandoutsService.save(courseHandouts);
|
|
|
- addSysGoodsRecord(oid,courseHandouts.getHandoutsId(),GoodsCopyEnum.COURSE_HANDOUTS.getType(),newTenantId,recordList);
|
|
|
- goods.setHandoutsId(courseHandouts.getHandoutsId());
|
|
|
- if (CollectionUtils.isNotEmpty(handoutsBusinessList)){
|
|
|
- List<CourseHandoutsBusiness> collect = handoutsBusinessList.stream().map(business -> {
|
|
|
- business.setId(null);
|
|
|
- business.setTenantId(newTenantId);
|
|
|
- //项目
|
|
|
- business.setEducationId(getNewEducationTypeId(business.getEducationId(), newTenantId,recordList));
|
|
|
- //业务
|
|
|
- business.setBusinessId(getNewBusinessId(business.getBusinessId(), newTenantId,recordList));
|
|
|
- //科目
|
|
|
- business.setSubjectId(getNewSubjectId(business.getSubjectId(), newTenantId,recordList));
|
|
|
- //讲义
|
|
|
- business.setHandoutsId(courseHandouts.getHandoutsId());
|
|
|
- return business;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- iCourseHandoutsBusinessService.saveBatch(collect);
|
|
|
+ if (ObjectUtil.isNotNull(newId)){
|
|
|
+ goods.setHandoutsId(newId);
|
|
|
+ }else {
|
|
|
+ //讲义业务层次
|
|
|
+ List<CourseHandoutsBusiness> handoutsBusinessList = iCourseHandoutsBusinessService
|
|
|
+ .list(new LambdaQueryWrapper<CourseHandoutsBusiness>()
|
|
|
+ .eq(CourseHandoutsBusiness::getHandoutsId, courseHandouts.getHandoutsId()));
|
|
|
+ courseHandouts.setHandoutsId(null);
|
|
|
+ courseHandouts.setTenantId(newTenantId);
|
|
|
+ iCourseHandoutsService.save(courseHandouts);
|
|
|
+ addSysGoodsRecord(oid,courseHandouts.getHandoutsId(),GoodsCopyEnum.COURSE_HANDOUTS.getType(),newTenantId,recordList);
|
|
|
+ goods.setHandoutsId(courseHandouts.getHandoutsId());
|
|
|
+ if (CollectionUtils.isNotEmpty(handoutsBusinessList)){
|
|
|
+ List<CourseHandoutsBusiness> collect = handoutsBusinessList.stream().map(business -> {
|
|
|
+ business.setId(null);
|
|
|
+ business.setTenantId(newTenantId);
|
|
|
+ //项目
|
|
|
+ business.setEducationId(getNewEducationTypeId(business.getEducationId(), newTenantId,recordList));
|
|
|
+ //业务
|
|
|
+ business.setBusinessId(getNewBusinessId(business.getBusinessId(), newTenantId,recordList));
|
|
|
+ //科目
|
|
|
+ business.setSubjectId(getNewSubjectId(business.getSubjectId(), newTenantId,recordList));
|
|
|
+ //讲义
|
|
|
+ business.setHandoutsId(courseHandouts.getHandoutsId());
|
|
|
+ return business;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ iCourseHandoutsBusinessService.saveBatch(collect);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //科目ID,拼接
|
|
|
- if (StringUtils.isNotBlank(goods.getSubjectIds())){
|
|
|
- List<Long> subIds = new ArrayList<>();
|
|
|
- List<Long> ids = Arrays.asList(goods.getSubjectIds().split(",")).stream().map(x -> Long.valueOf(x)).collect(Collectors.toList());
|
|
|
- ids.forEach(item -> {
|
|
|
- Long newSubjectId = getNewSubjectId(item, newTenantId,recordList);
|
|
|
- if (ObjectUtils.isNotNull(newSubjectId)){
|
|
|
- subIds.add(newSubjectId);
|
|
|
+ //科目ID,拼接
|
|
|
+ if (StringUtils.isNotBlank(goods.getSubjectIds())){
|
|
|
+ List<Long> subIds = new ArrayList<>();
|
|
|
+ List<Long> ids = Arrays.asList(goods.getSubjectIds().split(",")).stream().map(x -> Long.valueOf(x)).collect(Collectors.toList());
|
|
|
+ ids.forEach(item -> {
|
|
|
+ Long newSubjectId = getNewSubjectId(item, newTenantId,recordList);
|
|
|
+ if (ObjectUtils.isNotNull(newSubjectId)){
|
|
|
+ subIds.add(newSubjectId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (CollectionUtils.isNotEmpty(subIds)){
|
|
|
+ goods.setSubjectIds(subIds.stream().map(x -> x.toString()).collect(Collectors.joining(",")));
|
|
|
}
|
|
|
- });
|
|
|
- if (CollectionUtils.isNotEmpty(subIds)){
|
|
|
- goods.setSubjectIds(subIds.stream().map(x -> x.toString()).collect(Collectors.joining(",")));
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //证书类型
|
|
|
- if (ObjectUtils.isNotNull(goods.getCertificateTypeId())){
|
|
|
- goods.setCertificateTypeId(getNewCertificateTypeId(goods.getCertificateTypeId(),newTenantId,recordList));
|
|
|
- }
|
|
|
+ //证书类型
|
|
|
+ if (ObjectUtils.isNotNull(goods.getCertificateTypeId())){
|
|
|
+ goods.setCertificateTypeId(getNewCertificateTypeId(goods.getCertificateTypeId(),newTenantId,recordList));
|
|
|
+ }
|
|
|
|
|
|
- //证书
|
|
|
- if (ObjectUtils.isNotNull(goods.getCertificateId())){
|
|
|
- goods.setCertificateId(getNewCertificateId(goods.getCertificateId(),newTenantId,recordList));
|
|
|
- }
|
|
|
+ //证书
|
|
|
+ if (ObjectUtils.isNotNull(goods.getCertificateId())){
|
|
|
+ goods.setCertificateId(getNewCertificateId(goods.getCertificateId(),newTenantId,recordList));
|
|
|
+ }
|
|
|
|
|
|
- //证书模板
|
|
|
- if (ObjectUtils.isNotNull(goods.getCertificateTpId())){
|
|
|
- goods.setCertificateTpId(getNewCertificateTpId(goods.getCertificateTpId(),newTenantId,recordList));
|
|
|
- }
|
|
|
+ //证书模板
|
|
|
+ if (ObjectUtils.isNotNull(goods.getCertificateTpId())){
|
|
|
+ goods.setCertificateTpId(getNewCertificateTpId(goods.getCertificateTpId(),newTenantId,recordList));
|
|
|
+ }
|
|
|
|
|
|
- //规格模板
|
|
|
- if (ObjectUtils.isNotNull(goods.getSpecTemplateId())){
|
|
|
- Long oldSpecTemplateId = goods.getSpecTemplateId();
|
|
|
- Long newSpecTemplateId = getNewIdByTenant(oldSpecTemplateId,GoodsCopyEnum.GOODS_SPEC_TEMPLATE.getType(),newTenantId);
|
|
|
- GoodsSpecTemplate specTemplate = goodsSpecTemplateService.getById(oldSpecTemplateId);
|
|
|
+ //规格模板
|
|
|
+ if (ObjectUtils.isNotNull(goods.getSpecTemplateId())){
|
|
|
+ Long oldSpecTemplateId = goods.getSpecTemplateId();
|
|
|
+ Long newSpecTemplateId = getNewIdByTenant(oldSpecTemplateId,GoodsCopyEnum.GOODS_SPEC_TEMPLATE.getType(),newTenantId);
|
|
|
+ GoodsSpecTemplate specTemplate = goodsSpecTemplateService.getById(oldSpecTemplateId);
|
|
|
// GoodsSpecTemplate newSpecTemplate = goodsSpecTemplateService.getSpecTpByTenant(specTemplate.getName(),specTemplate.getCreateTime(),newTenantId);
|
|
|
- if (ObjectUtils.isNotNull(newSpecTemplateId)){
|
|
|
- //更新
|
|
|
- List<Long> specIds = goodsSpecService.getIdsByTenant(newSpecTemplateId,newTenantId);
|
|
|
- if (CollectionUtils.isNotEmpty(specIds)){
|
|
|
- //删除关联信息
|
|
|
- List<Long> specAttrIds = goodsSpecAttributeService.getIdsByTenant(specIds);
|
|
|
- if (CollectionUtils.isNotEmpty(specAttrIds)){
|
|
|
- goodsSpecAttributeService.deleteByIdsTenant(specAttrIds);
|
|
|
- goodsSpecAttributeRelationService.deleteByTemplateIdTenant(newSpecTemplateId,newTenantId);
|
|
|
+ if (ObjectUtils.isNotNull(newSpecTemplateId)){
|
|
|
+ //更新
|
|
|
+ List<Long> specIds = goodsSpecService.getIdsByTenant(newSpecTemplateId,newTenantId);
|
|
|
+ if (CollectionUtils.isNotEmpty(specIds)){
|
|
|
+ //删除关联信息
|
|
|
+ List<Long> specAttrIds = goodsSpecAttributeService.getIdsByTenant(specIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(specAttrIds)){
|
|
|
+ goodsSpecAttributeService.deleteByIdsTenant(specAttrIds);
|
|
|
+ goodsSpecAttributeRelationService.deleteByTemplateIdTenant(newSpecTemplateId,newTenantId);
|
|
|
+ }
|
|
|
+ goodsSpecService.deleteByIdsTenant(specIds);
|
|
|
}
|
|
|
- goodsSpecService.deleteByIdsTenant(specIds);
|
|
|
+ }else {
|
|
|
+ //新增
|
|
|
+ specTemplate.setEducationTypeId(getNewEducationTypeId(specTemplate.getEducationTypeId(),newTenantId,recordList));
|
|
|
+ specTemplate.setBusinessId(getNewBusinessId(specTemplate.getBusinessId(), newTenantId,recordList));
|
|
|
+ specTemplate.setSpecTemplateId(null);
|
|
|
+ specTemplate.setTenantId(newTenantId);
|
|
|
+ goodsSpecTemplateService.save(specTemplate);
|
|
|
+ newSpecTemplateId = specTemplate.getSpecTemplateId();
|
|
|
+ addSysGoodsRecord(oldSpecTemplateId,newSpecTemplateId,GoodsCopyEnum.GOODS_SPEC_TEMPLATE.getType(),newTenantId,recordList);
|
|
|
}
|
|
|
- }else {
|
|
|
- //新增
|
|
|
- specTemplate.setEducationTypeId(getNewEducationTypeId(specTemplate.getEducationTypeId(),newTenantId,recordList));
|
|
|
- specTemplate.setBusinessId(getNewBusinessId(specTemplate.getBusinessId(), newTenantId,recordList));
|
|
|
- specTemplate.setSpecTemplateId(null);
|
|
|
- specTemplate.setTenantId(newTenantId);
|
|
|
- goodsSpecTemplateService.save(specTemplate);
|
|
|
- newSpecTemplateId = specTemplate.getSpecTemplateId();
|
|
|
- addSysGoodsRecord(oldSpecTemplateId,newSpecTemplateId,GoodsCopyEnum.GOODS_SPEC_TEMPLATE.getType(),newTenantId,recordList);
|
|
|
- }
|
|
|
|
|
|
- //新增关联
|
|
|
- List<GoodsSpec> specList = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
- .eq(GoodsSpec::getSpecTemplateId, oldSpecTemplateId));
|
|
|
- if (CollectionUtils.isNotEmpty(specList)){
|
|
|
- for (GoodsSpec item : specList) {
|
|
|
- Long oldSpecId = item.getSpecId();
|
|
|
- item.setSpecId(null);
|
|
|
- item.setSpecTemplateId(newSpecTemplateId);
|
|
|
- item.setTenantId(newTenantId);
|
|
|
- goodsSpecService.save(item);
|
|
|
- addSysGoodsRecord(oldSpecId,item.getSpecId(),GoodsCopyEnum.GOODS_SPEC.getType(),newTenantId,recordList);
|
|
|
- List<GoodsSpecAttribute> specAttributeList = goodsSpecAttributeService
|
|
|
- .list(new LambdaQueryWrapper<GoodsSpecAttribute>()
|
|
|
- .eq(GoodsSpecAttribute::getSpecId, oldSpecId));
|
|
|
- if (CollectionUtils.isNotEmpty(specAttributeList)){
|
|
|
- List<GoodsSpecAttribute> collect = specAttributeList.stream().map(attrItem -> {
|
|
|
- attrItem.setSpecAttributeId(null);
|
|
|
- attrItem.setSpecId(item.getSpecId());
|
|
|
- attrItem.setTenantId(newTenantId);
|
|
|
- attrItem.setOId(attrItem.getSpecAttributeId());
|
|
|
- return attrItem;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- goodsSpecAttributeService.saveBatch(collect);
|
|
|
- for (GoodsSpecAttribute attr : collect) {
|
|
|
- addSysGoodsRecord(attr.getOId(),attr.getSpecAttributeId(),GoodsCopyEnum.GOODS_SPEC_ATTRIBUTE.getType(),newTenantId,recordList);
|
|
|
+ //新增关联
|
|
|
+ List<GoodsSpec> specList = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>()
|
|
|
+ .eq(GoodsSpec::getSpecTemplateId, oldSpecTemplateId));
|
|
|
+ if (CollectionUtils.isNotEmpty(specList)){
|
|
|
+ for (GoodsSpec item : specList) {
|
|
|
+ Long oldSpecId = item.getSpecId();
|
|
|
+ item.setSpecId(null);
|
|
|
+ item.setSpecTemplateId(newSpecTemplateId);
|
|
|
+ item.setTenantId(newTenantId);
|
|
|
+ goodsSpecService.save(item);
|
|
|
+ addSysGoodsRecord(oldSpecId,item.getSpecId(),GoodsCopyEnum.GOODS_SPEC.getType(),newTenantId,recordList);
|
|
|
+ List<GoodsSpecAttribute> specAttributeList = goodsSpecAttributeService
|
|
|
+ .list(new LambdaQueryWrapper<GoodsSpecAttribute>()
|
|
|
+ .eq(GoodsSpecAttribute::getSpecId, oldSpecId));
|
|
|
+ if (CollectionUtils.isNotEmpty(specAttributeList)){
|
|
|
+ List<GoodsSpecAttribute> collect = specAttributeList.stream().map(attrItem -> {
|
|
|
+ attrItem.setSpecAttributeId(null);
|
|
|
+ attrItem.setSpecId(item.getSpecId());
|
|
|
+ attrItem.setTenantId(newTenantId);
|
|
|
+ attrItem.setOId(attrItem.getSpecAttributeId());
|
|
|
+ return attrItem;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ goodsSpecAttributeService.saveBatch(collect);
|
|
|
+ for (GoodsSpecAttribute attr : collect) {
|
|
|
+ addSysGoodsRecord(attr.getOId(),attr.getSpecAttributeId(),GoodsCopyEnum.GOODS_SPEC_ATTRIBUTE.getType(),newTenantId,recordList);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //模板属性值关联
|
|
|
+ List<GoodsSpecAttributeRelation> relationList = goodsSpecAttributeRelationService
|
|
|
+ .list(new LambdaQueryWrapper<GoodsSpecAttributeRelation>()
|
|
|
+ .eq(GoodsSpecAttributeRelation::getSpecTemplateId,oldSpecTemplateId));
|
|
|
+ if (CollectionUtils.isNotEmpty(relationList)){
|
|
|
+ newRelationList.addAll(relationList);
|
|
|
+ }
|
|
|
+ goods.setSpecTemplateId(newSpecTemplateId);
|
|
|
}
|
|
|
- //模板属性值关联
|
|
|
- List<GoodsSpecAttributeRelation> relationList = goodsSpecAttributeRelationService
|
|
|
- .list(new LambdaQueryWrapper<GoodsSpecAttributeRelation>()
|
|
|
- .eq(GoodsSpecAttributeRelation::getSpecTemplateId,oldSpecTemplateId));
|
|
|
- if (CollectionUtils.isNotEmpty(relationList)){
|
|
|
- newRelationList.addAll(relationList);
|
|
|
- }
|
|
|
- goods.setSpecTemplateId(newSpecTemplateId);
|
|
|
- }
|
|
|
|
|
|
- if (ObjectUtils.isNull(goods.getGoodsId())){
|
|
|
- //新增
|
|
|
- save(goods);
|
|
|
- addSysGoodsRecord(oldGoodsId,goods.getGoodsId(),GoodsCopyEnum.GOODS.getType(),newTenantId,recordList);
|
|
|
- }else {
|
|
|
- //修改
|
|
|
- baseMapper.updateByTenant(goods);
|
|
|
- }
|
|
|
- newGoodsId = goods.getGoodsId();
|
|
|
-
|
|
|
- //商品课程
|
|
|
- List<CourseMenuExam> newCourseMenuExamList = new ArrayList<>();
|
|
|
- disposeGoodsCourse(oldGoodsId,newGoodsId,newTenantId,newCourseMenuExamList,recordList);
|
|
|
- //商品试卷
|
|
|
- disposeGoodsAttached(oldGoodsId,newGoodsId,newTenantId,recordList);
|
|
|
-
|
|
|
- //处理商品试卷
|
|
|
- if (CollectionUtils.isNotEmpty(newCourseMenuExamList)){
|
|
|
- for (CourseMenuExam menuExam : newCourseMenuExamList) {
|
|
|
- menuExam.setExamId(getNewExamId(menuExam.getExamId(),newTenantId,recordList));
|
|
|
+ if (ObjectUtils.isNull(goods.getGoodsId())){
|
|
|
+ //新增
|
|
|
+ save(goods);
|
|
|
+ addSysGoodsRecord(oldGoodsId,goods.getGoodsId(),GoodsCopyEnum.GOODS.getType(),newTenantId,recordList);
|
|
|
+ }else {
|
|
|
+ //修改
|
|
|
+ baseMapper.updateByTenant(goods);
|
|
|
+ }
|
|
|
+ newGoodsId = goods.getGoodsId();
|
|
|
+
|
|
|
+ //商品课程
|
|
|
+ List<CourseMenuExam> newCourseMenuExamList = new ArrayList<>();
|
|
|
+ disposeGoodsCourse(oldGoodsId,newGoodsId,newTenantId,newCourseMenuExamList,recordList);
|
|
|
+ //商品试卷
|
|
|
+ disposeGoodsAttached(oldGoodsId,newGoodsId,newTenantId,recordList);
|
|
|
+
|
|
|
+ //处理商品试卷
|
|
|
+ if (CollectionUtils.isNotEmpty(newCourseMenuExamList)){
|
|
|
+ for (CourseMenuExam menuExam : newCourseMenuExamList) {
|
|
|
+ menuExam.setExamId(getNewExamId(menuExam.getExamId(),newTenantId,recordList));
|
|
|
+ }
|
|
|
+ iCourseMenuExamService.saveBatch(newCourseMenuExamList);
|
|
|
}
|
|
|
- iCourseMenuExamService.saveBatch(newCourseMenuExamList);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //规格模板商品重新绑定
|
|
|
- if (CollectionUtils.isNotEmpty(newRelationList)){
|
|
|
- for (GoodsSpecAttributeRelation relation : newRelationList) {
|
|
|
- relation.setId(null);
|
|
|
- relation.setTenantId(newTenantId);
|
|
|
- //模板ID
|
|
|
- if (ObjectUtils.isNotNull(relation.getSpecTemplateId())){
|
|
|
- GoodsSpecTemplate specTemplate = goodsSpecTemplateService.getById(relation.getSpecTemplateId());
|
|
|
- Long newId = getNewIdByTenant(specTemplate.getSpecTemplateId(), GoodsCopyEnum.GOODS_SPEC_TEMPLATE.getType(),newTenantId);
|
|
|
+ //规格模板商品重新绑定
|
|
|
+ if (CollectionUtils.isNotEmpty(newRelationList)){
|
|
|
+ for (GoodsSpecAttributeRelation relation : newRelationList) {
|
|
|
+ relation.setId(null);
|
|
|
+ relation.setTenantId(newTenantId);
|
|
|
+ //模板ID
|
|
|
+ if (ObjectUtils.isNotNull(relation.getSpecTemplateId())){
|
|
|
+ GoodsSpecTemplate specTemplate = goodsSpecTemplateService.getById(relation.getSpecTemplateId());
|
|
|
+ Long newId = getNewIdByTenant(specTemplate.getSpecTemplateId(), GoodsCopyEnum.GOODS_SPEC_TEMPLATE.getType(),newTenantId);
|
|
|
// GoodsSpecTemplate newSpecTemplate = goodsSpecTemplateService.getSpecTpByTenant(specTemplate.getName(),specTemplate.getCreateTime(),newTenantId);
|
|
|
- if (ObjectUtils.isNotNull(newId)){
|
|
|
- relation.setSpecTemplateId(newId);
|
|
|
- }else {
|
|
|
- relation.setSpecTemplateId(null);
|
|
|
+ if (ObjectUtils.isNotNull(newId)){
|
|
|
+ relation.setSpecTemplateId(newId);
|
|
|
+ }else {
|
|
|
+ relation.setSpecTemplateId(null);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //商品ID
|
|
|
- if (ObjectUtils.isNotNull(relation.getGoodsId())){
|
|
|
- Goods goods = getById(relation.getGoodsId());
|
|
|
- Long newId = getNewIdByTenant(goods.getGoodsId(), GoodsCopyEnum.GOODS.getType(),newTenantId);
|
|
|
+ //商品ID
|
|
|
+ if (ObjectUtils.isNotNull(relation.getGoodsId())){
|
|
|
+ Goods goods = getById(relation.getGoodsId());
|
|
|
+ Long newId = getNewIdByTenant(goods.getGoodsId(), GoodsCopyEnum.GOODS.getType(),newTenantId);
|
|
|
// Goods newGoods = baseMapper.queryGoodsByTenant(goods.getCode(),newTenantId);
|
|
|
- if (ObjectUtils.isNotNull(newId)){
|
|
|
- relation.setGoodsId(newId);
|
|
|
- }else {
|
|
|
- relation.setGoodsId(null);
|
|
|
+ if (ObjectUtils.isNotNull(newId)){
|
|
|
+ relation.setGoodsId(newId);
|
|
|
+ }else {
|
|
|
+ relation.setGoodsId(null);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //规格属性IDS
|
|
|
- if (StringUtils.isNotBlank(relation.getSpecAttributeIds())){
|
|
|
- List<Long> ids = Arrays.asList(relation.getSpecAttributeIds().split(",")).stream().map(x -> Long.valueOf(x)).collect(Collectors.toList());
|
|
|
- List<GoodsSpecAttribute> specAttributeList = goodsSpecAttributeService.listByIds(ids);
|
|
|
- if (CollectionUtils.isNotEmpty(specAttributeList)){
|
|
|
- List<Long> newIds = new ArrayList<>();
|
|
|
- specAttributeList.forEach(item -> {
|
|
|
- Long newId = getNewIdByTenant(item.getSpecAttributeId(), GoodsCopyEnum.GOODS_SPEC_ATTRIBUTE.getType(),newTenantId);
|
|
|
+ //规格属性IDS
|
|
|
+ if (StringUtils.isNotBlank(relation.getSpecAttributeIds())){
|
|
|
+ List<Long> ids = Arrays.asList(relation.getSpecAttributeIds().split(",")).stream().map(x -> Long.valueOf(x)).collect(Collectors.toList());
|
|
|
+ List<GoodsSpecAttribute> specAttributeList = goodsSpecAttributeService.listByIds(ids);
|
|
|
+ if (CollectionUtils.isNotEmpty(specAttributeList)){
|
|
|
+ List<Long> newIds = new ArrayList<>();
|
|
|
+ specAttributeList.forEach(item -> {
|
|
|
+ Long newId = getNewIdByTenant(item.getSpecAttributeId(), GoodsCopyEnum.GOODS_SPEC_ATTRIBUTE.getType(),newTenantId);
|
|
|
// GoodsSpecAttribute newSpecAttribute = goodsSpecAttributeService.getSpecAttrByTenant(item.getName(),item.getCreateTime(),newTenantId);
|
|
|
- if (ObjectUtils.isNotNull(newId)){
|
|
|
- newIds.add(newId);
|
|
|
+ if (ObjectUtils.isNotNull(newId)){
|
|
|
+ newIds.add(newId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (CollectionUtils.isNotEmpty(newIds)){
|
|
|
+ relation.setSpecAttributeIds(newIds.stream().map(x -> x.toString()).collect(Collectors.joining(",")));
|
|
|
}
|
|
|
- });
|
|
|
- if (CollectionUtils.isNotEmpty(newIds)){
|
|
|
- relation.setSpecAttributeIds(newIds.stream().map(x -> x.toString()).collect(Collectors.joining(",")));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- goodsSpecAttributeRelationService.saveBatch(newRelationList);
|
|
|
- }
|
|
|
+ goodsSpecAttributeRelationService.saveBatch(newRelationList);
|
|
|
+ }
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(recordList)){
|
|
|
- //保存记录
|
|
|
- iSysGoodsCopyRecordService.saveBatch(recordList);
|
|
|
+ if (CollectionUtils.isNotEmpty(recordList)){
|
|
|
+ //保存记录
|
|
|
+ iSysGoodsCopyRecordService.saveBatch(recordList);
|
|
|
+ }
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ }catch (Exception e){
|
|
|
+ //释放
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ log.error("商品增量报错:"+e.getMessage());
|
|
|
}
|
|
|
-
|
|
|
return true;
|
|
|
}
|
|
|
|