From 994de8bc7067afc1e32043eeeaabdda60d400ef1 Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: 星期二, 15 七月 2025 13:01:36 +0800
Subject: [PATCH] 修改

---
 multi-system/src/main/java/com/gkhy/exam/system/service/impl/CatalogueServiceImpl.java |   74 ++++++++++++++++++++++++++++++++++---
 1 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/CatalogueServiceImpl.java b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/CatalogueServiceImpl.java
index 9b0b0e2..f2886fd 100644
--- a/multi-system/src/main/java/com/gkhy/exam/system/service/impl/CatalogueServiceImpl.java
+++ b/multi-system/src/main/java/com/gkhy/exam/system/service/impl/CatalogueServiceImpl.java
@@ -1,18 +1,19 @@
 package com.gkhy.exam.system.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.gkhy.exam.common.api.CommonPage;
 import com.gkhy.exam.common.api.CommonResult;
+import com.gkhy.exam.common.exception.ApiException;
 import com.gkhy.exam.common.utils.SecurityUtils;
-import com.gkhy.exam.system.domain.Catalogue;
-import com.gkhy.exam.system.domain.CatalogueData;
-import com.gkhy.exam.system.domain.CatalogueDataFile;
-import com.gkhy.exam.system.domain.SysCompany;
+import com.gkhy.exam.system.domain.*;
 import com.gkhy.exam.system.domain.req.CatalogueDataReq;
 import com.gkhy.exam.system.domain.req.CatalogueReq;
 import com.gkhy.exam.system.domain.vo.CatalogueDataVo;
 import com.gkhy.exam.system.domain.vo.CatalogueVo;
 import com.gkhy.exam.system.mapper.CatalogueMapper;
+import com.gkhy.exam.system.mapper.CompanyIndustryTemplateMapper;
+import com.gkhy.exam.system.mapper.ProductItemMapper;
 import com.gkhy.exam.system.mapper.SysCompanyMapper;
 import com.gkhy.exam.system.service.CatalogueService;
 import com.gkhy.exam.system.service.SysCompanyService;
@@ -32,6 +33,10 @@
     private CatalogueMapper catalogueMapper;
     @Autowired
     private SysCompanyMapper sysCompanyMapper;
+    @Autowired
+    private CompanyIndustryTemplateMapper companyIndustryTemplateMapper;
+    @Autowired
+    private ProductItemMapper productItemMapper;
 
     /**
      * 目录管理
@@ -52,7 +57,7 @@
     private List<CatalogueVo> getchildren(CatalogueVo catalogueVo, List<CatalogueVo> catalogueVos) {
         List<CatalogueVo> catalogueCharlden = new ArrayList<>();
         for (CatalogueVo catalogue : catalogueVos) {
-            if (catalogueVo.getId() == catalogue.getParentId()){
+            if (catalogueVo.getId().equals(catalogue.getParentId())){
                 catalogueCharlden.add(catalogue);
             }
         }
@@ -65,6 +70,11 @@
 
     @Override
     public CommonResult insertCatalogue(Catalogue catalogue) {
+        if (catalogue.getType()==2||catalogue.getType()==3){
+            if (catalogue.getCompanyId()==null){
+                throw new ApiException("企业id不能为空");
+            }
+        }
         catalogue.setCreateBy(SecurityUtils.getUsername());
         catalogue.setCreateTime(LocalDate.now());
         int insert = catalogueMapper.insert(catalogue);
@@ -187,6 +197,11 @@
 
     @Override
     public CommonResult insertCatalogueDataFile(CatalogueDataFile catalogueDataFile) {
+        CompanyIndustryTemplate companyIndustryTemplate = companyIndustryTemplateMapper.selectCompanyIndustryTemplate(catalogueDataFile.getName());
+        if (companyIndustryTemplate!=null){
+            catalogueDataFile.setFilePath(companyIndustryTemplate.getFilePath());
+            catalogueDataFile.setFileName(companyIndustryTemplate.getFileName());
+        }
         catalogueDataFile.setCreateTime(LocalDate.now());
         catalogueDataFile.setCreateBy(SecurityUtils.getUsername());
         catalogueMapper.insertCatalogueDataFile(catalogueDataFile);
@@ -195,9 +210,20 @@
 
     @Override
     public CommonResult updateCatalogueDataFile(CatalogueDataFile catalogueDataFile) {
+        CompanyIndustryTemplate companyIndustryTemplate = companyIndustryTemplateMapper.selectCompanyIndustryTemplate(catalogueDataFile.getName());
+        if (companyIndustryTemplate!=null){
+            catalogueDataFile.setFilePath(companyIndustryTemplate.getFilePath());
+            catalogueDataFile.setFileName(companyIndustryTemplate.getFileName());
+        }else {
+            catalogueDataFile.setFileName(null);
+            catalogueDataFile.setFilePath(null);
+        }
+        catalogueDataFile.setCreateBy(SecurityUtils.getUsername());
+        catalogueDataFile.setCreateTime(LocalDate.now());
         catalogueDataFile.setUpdateBy(SecurityUtils.getUsername());
         catalogueDataFile.setUpdateTime(LocalDate.now());
-        catalogueMapper.updateCatalogueDataFile(catalogueDataFile);
+        catalogueMapper.deleteByCatalogueDataFileId(catalogueDataFile.getId());
+        catalogueMapper.insertCatalogueDataFile(catalogueDataFile);
         return CommonResult.success();
     }
 
@@ -216,4 +242,40 @@
     public CommonResult selectCatalogueDataFileList(CatalogueReq catalogueReq) {
         return CommonResult.success(catalogueMapper.selectCatalogueDataFile(catalogueReq.getCompanyId(),catalogueReq.getCatalogueId()));
     }
+
+    @Override
+    public CommonResult copyCatalogue(List<CatalogueVo> catalogue) {
+        Integer companyId = catalogue.get(0).getCompanyId();
+        Integer type = catalogue.get(0).getType();
+        catalogueMapper.delete(Wrappers.<Catalogue>lambdaQuery().eq(Catalogue::getCompanyId,companyId).eq(Catalogue::getType,catalogue.get(0).getType()));
+        for (CatalogueVo catalogueVo : catalogue) {
+            Catalogue catalogue1 = new Catalogue();
+            BeanUtils.copyProperties(catalogueVo,catalogue1);
+            catalogueMapper.insertCatalogue(catalogue1);
+            List<CatalogueVo> children = catalogueVo.getChildren();
+            if (children.size()>0){
+                saveCatalogue(children,catalogue1);
+            }
+        }
+        productItemMapper.deletedByCompanyId(companyId,type.equals(2)?1:2);
+        return CommonResult.success();
+    }
+
+    private void saveCatalogue(List<CatalogueVo> children,Catalogue catalogue) {
+        for (CatalogueVo child : children) {
+            Catalogue catalogue1 = new Catalogue();
+            BeanUtils.copyProperties(child,catalogue1);
+            catalogue1.setParentId(catalogue.getId());
+            catalogue1.setCompanyId(catalogue.getCompanyId());
+            catalogueMapper.insertCatalogue(catalogue1);
+            List<CatalogueVo> children1 = child.getChildren();
+            if (children1.size()>0){
+                saveCatalogue(children1,catalogue1);
+            }else {
+                continue;
+            }
+        }
+    }
+
+
 }

--
Gitblit v1.9.2