| | |
| | | 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; |
| | |
| | | return CommonResult.failed(errorBuilder.toString()); |
| | | } |
| | | |
| | | // 8. 批量插入 |
| | | int affectedRows = companyIndustryTemplateMapper.insertIndustrys(companyIndustryTemplates); |
| | | List<List<CompanyIndustryTemplate>> split = ListUtil.split(companyIndustryTemplates, 50); |
| | | for (List<CompanyIndustryTemplate> industryTemplates : split) { |
| | | int affectedRows = companyIndustryTemplateMapper.insertIndustrys(industryTemplates); |
| | | } |
| | | |
| | | workbook.close(); |
| | | |
| | | if (affectedRows < 1) { |
| | | throw new ApiException("导入行业模版失败"); |
| | | } |
| | | return CommonResult.success(); |
| | | } |
| | | // 安全获取单元格值 |
| | |
| | | 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(); |
| | | |
| | | |
| | | } |