heheng
2026-02-02 8bda5d156d97a6f86da6ee068447643a2fff8c4f
multi-system/src/main/java/com/gkhy/exam/system/service/impl/CompanyIndustryTemplateServiceImpl.java
@@ -1,7 +1,6 @@
package com.gkhy.exam.system.service.impl;
import cn.hutool.core.collection.ListUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
@@ -9,14 +8,13 @@
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.common.utils.StringUtils;
import com.gkhy.exam.system.domain.*;
import com.gkhy.exam.system.domain.CompanyIndustryTemplate;
import com.gkhy.exam.system.domain.CompanyIndustryType;
import com.gkhy.exam.system.domain.SysCompany;
import com.gkhy.exam.system.mapper.CompanyIndustryTemplateMapper;
import com.gkhy.exam.system.mapper.CompanyRosterMapper;
import com.gkhy.exam.system.mapper.SysIndustryTypeMapper;
import com.gkhy.exam.system.service.CompanyIndustryTemplateService;
import com.gkhy.exam.system.service.SysCompanyService;
import com.gkhy.exam.system.service.SysIndustryTypeService;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -28,8 +26,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.hutool.poi.excel.cell.CellUtil.getCellValue;
@Service
public class CompanyIndustryTemplateServiceImpl extends ServiceImpl<CompanyIndustryTemplateMapper, CompanyIndustryTemplate> implements CompanyIndustryTemplateService {
@@ -196,13 +192,9 @@
        for (List<CompanyIndustryTemplate> industryTemplates : split) {
            int affectedRows = companyIndustryTemplateMapper.insertIndustrys(industryTemplates);
        }
        // 8. 批量插入
//        int affectedRows = companyIndustryTemplateMapper.insertIndustrys(companyIndustryTemplates);
        workbook.close();
//        if (affectedRows < 1) {
//            throw new ApiException("导入行业模版失败");
//        }
        return CommonResult.success();
    }
        // 安全获取单元格值
@@ -212,52 +204,6 @@
            return formatter.formatCellValue(cell).trim();
        }
//    List<CompanyIndustryType> companyIndustryTypes = sysIndustryTypeMapper.selectIndustryTypeList();
//    List<SysCompany> list = sysCompanyService.selectCompanyLists();
//    Workbook workbook = WorkbookFactory.create(file.getInputStream());
//    Sheet sheetAt = workbook.getSheetAt(0);
//    List<CompanyIndustryTemplate> companyIndustryTemplates = new ArrayList<>();
//    LoginUserDetails loginUser = SecurityUtils.getLoginUser();
//    DataFormatter dataFormatter = new DataFormatter();
//    StringBuilder stringBuilder = new StringBuilder();
//        for (int i = 0; i <sheetAt.getLastRowNum(); i++) {
//        Row row = sheetAt.getRow(i + 1);
//        CompanyIndustryTemplate companyIndustryTemplate = new CompanyIndustryTemplate();
//        if (row!=null){
//            companyIndustryTemplate.setChapter(dataFormatter.formatCellValue(row.getCell(0)));
//            companyIndustryTemplate.setTemplateName(dataFormatter.formatCellValue(row.getCell(1)));
//            companyIndustryTemplate.setType(dataFormatter.formatCellValue(row.getCell(2)));
//            for (CompanyIndustryType companyIndustryType : companyIndustryTypes) {
//                if (dataFormatter.formatCellValue(row.getCell(3)).equals(companyIndustryType.getName())){
//                    companyIndustryTemplate.setIndustryType(companyIndustryType.getId());
//                }
//            }
//            if (companyIndustryTemplate.getIndustryType()==null){
//                stringBuilder.append("未找到对应行业类型:["+dataFormatter.formatCellValue(row.getCell(3))+"]   ,");
//            }
//            companyIndustryTemplate.setCreateBy(loginUser.getUsername());
//            companyIndustryTemplate.setCreateTime(LocalDateTime.now());
//            for (SysCompany sysCompany : list) {
//                if (dataFormatter.formatCellValue(row.getCell(4)).equals(sysCompany.getName())){
//                    companyIndustryTemplate.setCompanyId(sysCompany.getId());
//                }
//            }
//            if (companyIndustryTemplate.getCompanyId()==null){
//                stringBuilder.append("未找到对应企业:["+dataFormatter.formatCellValue(row.getCell(4))+"]");
//            }
//            companyIndustryTemplates.add(companyIndustryTemplate);
//        }
//    }
//        if (StringUtils.isNotBlank(stringBuilder)){
//        workbook.close();
//        return CommonResult.failed(stringBuilder.toString());
//    }
//    int i = companyIndustryTemplateMapper.insertIndustrys(companyIndustryTemplates);
//        if (i<1){
//        throw new ApiException("导入行业模版失败");
//    }
//        workbook.close();
//        return CommonResult.success();
}