|
|
@@ -10,12 +10,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.SneakyThrows;
|
|
|
-import org.sky.core.excel.util.ExcelUtil;
|
|
|
import org.sky.core.log.exception.ServiceException;
|
|
|
import org.sky.core.mp.base.BaseServiceImpl;
|
|
|
import org.sky.core.secure.utils.SecureUtil;
|
|
|
import org.sky.core.tool.utils.*;
|
|
|
import org.sky.scientific.excel.CgRjzzqExcel;
|
|
|
+import org.sky.scientific.excel.listener.CgRjzzqImportListener;
|
|
|
import org.sky.scientific.mapper.CgRjzzqMapper;
|
|
|
import org.sky.scientific.mapper.XmMapper;
|
|
|
import org.sky.scientific.pojo.dto.CgRjzzqDTO;
|
|
|
@@ -26,6 +26,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -45,14 +46,21 @@ public class CgRjzzqServiceImpl extends BaseServiceImpl<CgRjzzqMapper, CgRjzzqEn
|
|
|
@Resource
|
|
|
private XmMapper xmMapper;
|
|
|
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public void importRjzzq(MultipartFile file) {
|
|
|
- List<CgRjzzqExcel> data = ExcelUtil.read(file, 0, 2, CgRjzzqExcel.class);
|
|
|
- if(CollectionUtil.isEmpty(data)){
|
|
|
+ @SneakyThrows
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void importRjzzq(MultipartFile file) {
|
|
|
+ CgRjzzqImportListener listener = new CgRjzzqImportListener();
|
|
|
+ EasyExcel.read(new BufferedInputStream(file.getInputStream()))
|
|
|
+ .registerReadListener(listener)
|
|
|
+ .sheet(0)
|
|
|
+ .headRowNumber(2) // 重要:设置表头行数(0-based)
|
|
|
+ .doRead();
|
|
|
+ List<CgRjzzqExcel> dataList = listener.getDataList();
|
|
|
+ if (CollectionUtil.isEmpty(dataList)) {
|
|
|
throw new ServiceException("未能从模板中读取数据,请检查模板格式是否正确");
|
|
|
}
|
|
|
- for (CgRjzzqExcel excel : data) {
|
|
|
+ for (CgRjzzqExcel excel : dataList) {
|
|
|
CgRjzzqEntity zlDTO = Objects.requireNonNull(BeanUtil.copyProperties(excel, CgRjzzqDTO.class));
|
|
|
if (!StringUtil.isAllBlank(excel.getXmbh(), excel.getXmmc())) {
|
|
|
Long xmId = xmMapper.getXmIdByXmmcOrXmbh(null, excel.getXmmc(), excel.getXmbh());
|
|
|
@@ -63,11 +71,10 @@ public class CgRjzzqServiceImpl extends BaseServiceImpl<CgRjzzqMapper, CgRjzzqEn
|
|
|
}
|
|
|
this.save(zlDTO);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public boolean save(CgRjzzqEntity cgRjzzq) {
|
|
|
-
|
|
|
return super.save(cgRjzzq);
|
|
|
}
|
|
|
|
|
|
@@ -97,15 +104,15 @@ public class CgRjzzqServiceImpl extends BaseServiceImpl<CgRjzzqMapper, CgRjzzqEn
|
|
|
@SneakyThrows
|
|
|
@Override
|
|
|
public void export(OutputStream os, List<CgRjzzqEntity> list) {
|
|
|
- AtomicInteger index = new AtomicInteger(1);
|
|
|
+ AtomicInteger index = new AtomicInteger(1);
|
|
|
List<CgRjzzqExcel> results = new ArrayList<>();
|
|
|
list.forEach(temp -> {
|
|
|
CgRjzzqExcel excel = BeanUtil.copyProperties(temp, CgRjzzqExcel.class);
|
|
|
assert excel != null;
|
|
|
excel.setXh(index.getAndIncrement() + "");
|
|
|
- excel.setKfwcrqStr(Func.notNull(temp.getKfwcrq())?DateUtil.format(temp.getKfwcrq(), DateUtil.PATTERN_DATE):null);
|
|
|
- excel.setScfbrqStr(Func.notNull(temp.getScfbrq())?DateUtil.format(temp.getScfbrq(), DateUtil.PATTERN_DATE):null);
|
|
|
- excel.setDjpzrqStr(Func.notNull(temp.getDjpzrq())?DateUtil.format(temp.getDjpzrq(), DateUtil.PATTERN_DATE):null);
|
|
|
+ excel.setKfwcrqStr(Func.notNull(temp.getKfwcrq()) ? DateUtil.format(temp.getKfwcrq(), DateUtil.PATTERN_DATE) : null);
|
|
|
+ excel.setScfbrqStr(Func.notNull(temp.getScfbrq()) ? DateUtil.format(temp.getScfbrq(), DateUtil.PATTERN_DATE) : null);
|
|
|
+ excel.setDjpzrqStr(Func.notNull(temp.getDjpzrq()) ? DateUtil.format(temp.getDjpzrq(), DateUtil.PATTERN_DATE) : null);
|
|
|
results.add(excel);
|
|
|
});
|
|
|
InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/科研成果-软件著作.xls");
|