|
|
@@ -1,8 +1,12 @@
|
|
|
package com.zhongzheng.modules.company.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelReader;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -15,9 +19,16 @@ import com.zhongzheng.modules.company.domain.Company;
|
|
|
import com.zhongzheng.modules.company.mapper.CompanyMapper;
|
|
|
import com.zhongzheng.modules.company.vo.CompanyVo;
|
|
|
import com.zhongzheng.modules.company.service.ICompanyService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -42,7 +53,7 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
lqw.like(StrUtil.isNotBlank(bo.getCompanyName()), Company::getCompanyName, bo.getCompanyName());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getCompanyType()), Company::getCompanyType, bo.getCompanyType());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getCompanySize()), Company::getCompanySize, bo.getCompanySize());
|
|
|
- lqw.eq(StrUtil.isNotBlank(bo.getIndustryType()), Company::getIndustryType, bo.getIndustryType());
|
|
|
+ lqw.eq(bo.getIndustryType()!=null, Company::getIndustryType, bo.getIndustryType());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getCompanyIntroduce()), Company::getCompanyIntroduce, bo.getCompanyIntroduce());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getLogoUrl()), Company::getLogoUrl, bo.getLogoUrl());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getLicenseUrl()), Company::getLicenseUrl, bo.getLicenseUrl());
|
|
|
@@ -113,7 +124,41 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean batchImport(MultipartFile file) {
|
|
|
- return true;
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean batchImport(MultipartFile file) throws IOException {
|
|
|
+ byte [] byteArr=file.getBytes();
|
|
|
+ InputStream inputStream = new ByteArrayInputStream(byteArr);
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(inputStream);
|
|
|
+ List<List<Object>> readAll = reader.read();
|
|
|
+ readAll.remove(0);
|
|
|
+ List<Company> companyList = new ArrayList<>();
|
|
|
+ String TenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ Long nowTime = DateUtils.getNowTime();
|
|
|
+ for (int i = 0; i < readAll.size(); i++) {
|
|
|
+ Company company = new Company();
|
|
|
+ company.setCompanyName(readAll.get(i).get(0).toString());
|
|
|
+ company.setCompanyType(readAll.get(i).get(1).toString());
|
|
|
+ Integer industryId = baseMapper.selectIndustry(readAll.get(i).get(2).toString());
|
|
|
+ if (industryId == null){
|
|
|
+ throw new RuntimeException("第"+i+1+"行存在错误,请仔细检查再上传。");
|
|
|
+ }
|
|
|
+ company.setIndustryType(industryId);
|
|
|
+ company.setIndustryTypeName(readAll.get(i).get(2).toString());
|
|
|
+ company.setCompanySize(readAll.get(i).get(3).toString());
|
|
|
+ company.setCompanyIntroduce(readAll.get(i).get(4).toString());
|
|
|
+ company.setSocietyCode(readAll.get(i).get(5).toString());
|
|
|
+ company.setProvince(readAll.get(i).get(6).toString());
|
|
|
+ company.setCity(readAll.get(i).get(7).toString());
|
|
|
+ company.setAddress(readAll.get(i).get(8).toString());
|
|
|
+ company.setCompanyPh(readAll.get(i).get(9).toString());
|
|
|
+ company.setLinkMan(readAll.get(i).get(10).toString());
|
|
|
+ company.setPostBox(readAll.get(i).get(11).toString());
|
|
|
+ company.setTenantId(Convert.toLong(TenantId));
|
|
|
+ company.setCreateTime(nowTime);
|
|
|
+ company.setUpdateTime(nowTime);
|
|
|
+ company.setStatus(1);
|
|
|
+ companyList.add(company);
|
|
|
+ }
|
|
|
+ return this.saveBatch(companyList);
|
|
|
}
|
|
|
}
|