Forráskód Böngészése

submit:清理商品数据接口

yangdamao 2 éve
szülő
commit
9d9d0187d1

+ 10 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/goods/GoodsController.java

@@ -356,4 +356,14 @@ public class GoodsController extends BaseController {
     public AjaxResult<Void> updateCourse() {
         return toAjax(iGoodsService.goodsBatchCopyDisposeTenant() ? 1 : 0);
     }
+
+
+    /**
+     * 修复二建/二造商品(注意不接页面,自己使用)
+     */
+    @ApiOperation("修复二建/二造商品")
+    @PostMapping("/update/goods/repair")
+    public AjaxResult<Void> updateGoodsRepair(@RequestBody UpdateGoodsRepairBo bo) {
+        return toAjax(iGoodsService.updateGoodsRepair(bo) ? 1 : 0);
+    }
 }

+ 17 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/bo/UpdateGoodsRepairBo.java

@@ -0,0 +1,17 @@
+package com.zhongzheng.modules.goods.bo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author yangdamao
+ * @date 2023年02月23日 14:38
+ */
+@Data
+public class UpdateGoodsRepairBo implements Serializable {
+
+    private List<Long> goodsIds;
+
+}

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/service/IGoodsService.java

@@ -117,4 +117,7 @@ public interface IGoodsService extends IService<Goods> {
 	List<GoodsListAllVo> getUserGoodsListAll(UserGoodsListAllBo bo);
 
     Goods getGoodsByIdTenant(Long goodsId, Long tenantId);
+
+    boolean updateGoodsRepair(UpdateGoodsRepairBo bo);
+
 }

+ 140 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/service/impl/GoodsServiceImpl.java

@@ -3994,6 +3994,146 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
         return baseMapper.queryGoodsByIdTenant(goodsId,tenantId);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean updateGoodsRepair(UpdateGoodsRepairBo bo) {
+//        List<Goods> goodsList = list(new LambdaQueryWrapper<Goods>()
+//                .eq(Goods::getEducationTypeId, bo.getEducationTypeId())
+//                .eq(Goods::getBusinessId, bo.getBusinessId()));
+//        if (CollectionUtils.isEmpty(goodsList)){
+//            return true;
+//        }
+        Map<Integer,List<Long>> mapIds = new HashMap<>();
+        List<Long> goodsIds = new ArrayList<>();
+        List<Long> courseIds = new ArrayList<>();
+        List<Long> moduleIds = new ArrayList<>();
+        List<Long> chapterIds = new ArrayList<>();
+        List<Long> sectionIds = new ArrayList<>();
+        for (Long goodsId : bo.getGoodsIds()) {
+            Goods goods = getById(goodsId);
+            if (ObjectUtils.isNull(goods)){
+                continue;
+            }
+            goodsIds.add(goodsId);
+            //商品课程
+            List<GoodsCourse> courseList = iGoodsCourseService
+                    .list(new LambdaQueryWrapper<GoodsCourse>()
+                    .eq(GoodsCourse::getGoodsId, goodsId));
+            if (CollectionUtils.isEmpty(courseList)){
+                continue;
+            }
+            List<Long> idsCourse = courseList.stream().map(GoodsCourse::getCourseId).collect(Collectors.toList());
+            courseIds.addAll(idsCourse);
+            //课程目录
+            List<CourseMenu> courseMenuList = iCourseMenuService.list(new LambdaQueryWrapper<CourseMenu>()
+                    .in(CourseMenu::getCourseId, courseIds));
+            if (CollectionUtils.isEmpty(courseMenuList)){
+                continue;
+            }
+            Map<Integer, List<CourseMenu>> collect = courseMenuList.stream().collect(Collectors.groupingBy(CourseMenu::getType));
+            collect.forEach((k,v) -> {
+                List<Long> menuIds = v.stream().map(CourseMenu::getMenuId).collect(Collectors.toList());
+                switch (k){
+                    case 1://模块
+                        List<CourseModule> moduleList = iCourseModuleService.listByIds(menuIds);
+                        List<CourseModule> list = iCourseModuleService.list(new LambdaQueryWrapper<CourseModule>()
+                                .in(CourseModule::getModuleName, moduleList.stream().map(CourseModule::getModuleName).collect(Collectors.toList())));
+                        List<Long> idsModule = list.stream().map(CourseModule::getModuleId).collect(Collectors.toList());
+                        List<CourseModuleChapter> list1 = iCourseModuleChapterService
+                                .list(new LambdaQueryWrapper<CourseModuleChapter>()
+                                .in(CourseModuleChapter::getModuleId, idsModule));
+                        if (CollectionUtils.isNotEmpty(list1)){
+                            List<Long> collect1 = list1.stream().map(CourseModuleChapter::getChapterId).collect(Collectors.toList());
+                            List<CourseChapter> courseChapterList = iCourseChapterService.listByIds(collect1);
+                            List<CourseChapter> list2 = iCourseChapterService.list(new LambdaQueryWrapper<CourseChapter>()
+                                    .in(CourseChapter::getName, courseChapterList.stream().map(CourseChapter::getName).collect(Collectors.toList())));
+                            List<Long> idsChapter = list2.stream().map(CourseChapter::getChapterId).collect(Collectors.toList());
+                            chapterIds.addAll(idsChapter);
+                            List<CourseChapterSection> list3 = iCourseChapterSectionService
+                                    .list(new LambdaQueryWrapper<CourseChapterSection>()
+                                    .in(CourseChapterSection::getChapterId, idsChapter));
+                            if (CollectionUtils.isNotEmpty(list3)){
+                                List<CourseSection> sectionList = iCourseSectionService.listByIds(list3.stream().map(CourseChapterSection::getSectionId).collect(Collectors.toList()));
+                                List<CourseSection> list4 = iCourseSectionService.list(new LambdaQueryWrapper<CourseSection>()
+                                        .in(CourseSection::getName, sectionList.stream().map(CourseSection::getName).collect(Collectors.toList())));
+                                List<Long> idsSection = list4.stream().map(CourseSection::getSectionId).collect(Collectors.toList());
+                                sectionIds.addAll(idsSection);
+                            }
+                        }
+                        moduleIds.addAll(idsModule);
+                        break;
+                    case 2://章
+                        List<CourseChapter> courseChapterList = iCourseChapterService.listByIds(menuIds);
+                        List<CourseChapter> list2 = iCourseChapterService.list(new LambdaQueryWrapper<CourseChapter>()
+                                .in(CourseChapter::getName, courseChapterList.stream().map(CourseChapter::getName).collect(Collectors.toList())));
+                        List<Long> idsChapter = list2.stream().map(CourseChapter::getChapterId).collect(Collectors.toList());
+                        chapterIds.addAll(idsChapter);
+                        List<CourseChapterSection> list3 = iCourseChapterSectionService
+                                .list(new LambdaQueryWrapper<CourseChapterSection>()
+                                        .in(CourseChapterSection::getChapterId, idsChapter));
+                        if (CollectionUtils.isNotEmpty(list3)){
+                            List<CourseSection> sectionList = iCourseSectionService.listByIds(list3.stream().map(CourseChapterSection::getSectionId).collect(Collectors.toList()));
+                            List<CourseSection> list4 = iCourseSectionService.list(new LambdaQueryWrapper<CourseSection>()
+                                    .in(CourseSection::getName, sectionList.stream().map(CourseSection::getName).collect(Collectors.toList())));
+                            List<Long> idsSection = list4.stream().map(CourseSection::getSectionId).collect(Collectors.toList());
+                            sectionIds.addAll(idsSection);
+                        }
+                        break;
+                    case 3://节
+                        List<CourseSection> sectionList = iCourseSectionService.listByIds(menuIds);
+                        List<CourseSection> list4 = iCourseSectionService.list(new LambdaQueryWrapper<CourseSection>()
+                                .in(CourseSection::getName, sectionList.stream().map(CourseSection::getName).collect(Collectors.toList())));
+                        List<Long> idsSection = list4.stream().map(CourseSection::getSectionId).collect(Collectors.toList());
+                        sectionIds.addAll(idsSection);
+                        break;
+                }
+            });
+//            List<Long> goodsIds = new ArrayList<>();
+//            List<Long> courseIds = new ArrayList<>();
+//            List<Long> moduleIds = new ArrayList<>();
+//            List<Long> chapterIds = new ArrayList<>();
+//            List<Long> sectionIds = new ArrayList<>();
+            //执行删除
+            iCourseSectionBusinessService.remove(new LambdaQueryWrapper<CourseSectionBusiness>()
+            .in(CourseSectionBusiness::getSectionId,sectionIds));
+            iCourseSectionService.removeByIds(sectionIds);
+
+            iCourseChapterSectionService.remove(new LambdaQueryWrapper<CourseChapterSection>()
+            .in(CourseChapterSection::getChapterId,chapterIds));
+            iCourseChapterBusinessService.remove(new LambdaQueryWrapper<CourseChapterBusiness>()
+            .in(CourseChapterBusiness::getChapterId,chapterIds));
+            iCourseChapterService.removeByIds(chapterIds);
+
+            iCourseModuleChapterService.remove(new LambdaQueryWrapper<CourseModuleChapter>()
+            .in(CourseModuleChapter::getModuleId,moduleIds));
+            iCourseModuleBusinessService.remove(new LambdaQueryWrapper<CourseModuleBusiness>()
+            .in(CourseModuleBusiness::getModuleId,moduleIds));
+            iCourseModuleService.removeByIds(moduleIds);
+
+            iCourseMenuService.remove(new LambdaQueryWrapper<CourseMenu>()
+            .in(CourseMenu::getCourseId,courseIds));
+            iCourseService.removeByIds(courseIds);
+
+            iGoodsCourseService.remove(new LambdaQueryWrapper<GoodsCourse>()
+            .in(GoodsCourse::getGoodsId,goodsIds));
+            removeByIds(goodsIds);
+
+            mapIds.put(GoodsCopyEnum.GOODS.getType(),goodsIds);
+            mapIds.put(GoodsCopyEnum.COURSE.getType(),courseIds);
+            mapIds.put(GoodsCopyEnum.COURSE_MODULE.getType(),moduleIds);
+            mapIds.put(GoodsCopyEnum.COURSE_CHAPTER.getType(),chapterIds);
+            mapIds.put(GoodsCopyEnum.COURSE_SECTION.getType(),sectionIds);
+
+            mapIds.forEach((k,v) -> {
+                iSysGoodsCopyRecordService.remove(new LambdaQueryWrapper<SysGoodsCopyRecord>()
+                .eq(SysGoodsCopyRecord::getType,k)
+                .in(SysGoodsCopyRecord::getNewId,v));
+            });
+
+        }
+        return true;
+    }
+
     private Long getNewId(Long oldId, Integer type){
         if (ObjectUtils.isNull(oldId) || oldId <= 0L){
             return null;