|
@@ -3,20 +3,31 @@ package com.dragoninfo.dcuc.app.sub.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.dragoninfo.dcuc.app.sub.dto.DataLevelDTO;
|
|
import com.dragoninfo.dcuc.app.sub.dto.DataLevelDTO;
|
|
|
|
+import com.dragoninfo.dcuc.app.sub.dto.ExcelDataLevel;
|
|
import com.dragoninfo.dcuc.app.sub.entity.DataLevel;
|
|
import com.dragoninfo.dcuc.app.sub.entity.DataLevel;
|
|
import com.dragoninfo.dcuc.app.sub.mapper.DataLevelMapper;
|
|
import com.dragoninfo.dcuc.app.sub.mapper.DataLevelMapper;
|
|
import com.dragoninfo.dcuc.app.sub.service.IDataLevelService;
|
|
import com.dragoninfo.dcuc.app.sub.service.IDataLevelService;
|
|
|
|
+import com.dragoninfo.dcuc.app.util.ImportUtil;
|
|
import com.dragoninfo.dcuc.app.vo.DataLevelVo;
|
|
import com.dragoninfo.dcuc.app.vo.DataLevelVo;
|
|
|
|
+import com.dragoninfo.dcuc.auth.sub.dto.ExcelImpOrgInfo;
|
|
|
|
+import com.dragoninfo.dcuc.duceap.facade.IDuceapUploadFacade;
|
|
|
|
+import com.dragoninfo.dcuc.duceap.upload.dto.DocContentDTO;
|
|
|
|
+import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
|
+import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
import com.dragonsoft.duceap.core.search.Searchable;
|
|
import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -30,9 +41,14 @@ import static com.dragoninfo.dcuc.app.enumresources.DataResourceEnum.getByCode;
|
|
@Service
|
|
@Service
|
|
public class DataLevelServiceImpl implements IDataLevelService {
|
|
public class DataLevelServiceImpl implements IDataLevelService {
|
|
|
|
|
|
|
|
+ private List<String> excelTitle = Arrays.asList("代码","数据分级","说明");
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private DataLevelMapper dataLevelMapper;
|
|
private DataLevelMapper dataLevelMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IDuceapUploadFacade uploadFacade;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public DataLevel saveOrUpdate(DataLevelDTO dto) {
|
|
public DataLevel saveOrUpdate(DataLevelDTO dto) {
|
|
String id = dto.getId();
|
|
String id = dto.getId();
|
|
@@ -126,6 +142,124 @@ public class DataLevelServiceImpl implements IDataLevelService {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseStatus impExcel(String fileId) {
|
|
|
|
+ DocContentDTO fileContent = uploadFacade.getFileContent(fileId);
|
|
|
|
+ InputStream inputStream = fileContent.getInputStream();
|
|
|
|
+ try {
|
|
|
|
+ List<ExcelDataLevel> list = loadDataLevelFromExcel(inputStream);
|
|
|
|
+ verifyImport(list);
|
|
|
|
+ saveImport(list);
|
|
|
|
+ } catch (IOException e){
|
|
|
|
+ return ResponseStatus.fail("文件格式不正确");
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ return ResponseStatus.fail(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return ResponseStatus.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void saveImport(List<ExcelDataLevel> list) {
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ list.forEach(item->{
|
|
|
|
+ DataLevel dataLevel = new DataLevel();
|
|
|
|
+ BeanUtils.copyProperties(item, dataLevel);
|
|
|
|
+ dataLevel.setDeleted(BooleanEnum.FALSE.value);
|
|
|
|
+ dataLevel.setCreateTime(date);
|
|
|
|
+ dataLevelMapper.insert(dataLevel);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void verifyImport(List<ExcelDataLevel> list) {
|
|
|
|
+ if(list.size() > 1000) {
|
|
|
|
+ throw new NumberFormatException("导入条数超过1000条!!!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String codeEmpRows = list.stream().filter(item -> StringUtils.isBlank(item.getLevelCode()))
|
|
|
|
+ .map(item -> item.getRowNum().toString())
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
+ if(StringUtils.isNotBlank(codeEmpRows)) {
|
|
|
|
+ throw new NumberFormatException("第【"+ codeEmpRows +"】行【代码】列为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String nameEmpRows = list.stream().filter(item -> StringUtils.isBlank(item.getLevelName()))
|
|
|
|
+ .map(item -> item.getRowNum().toString())
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
+ if(StringUtils.isNotBlank(nameEmpRows)) {
|
|
|
|
+ throw new NumberFormatException("第【"+ nameEmpRows +"】行【数据分级】列为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String remarkLengthRows = list.stream().filter(item -> {
|
|
|
|
+ String remark = item.getRemark();
|
|
|
|
+ return StringUtils.isNotBlank(remark) && remark.length() > 500;
|
|
|
|
+ }).map(item -> item.getRowNum().toString()).collect(Collectors.joining(","));
|
|
|
|
+ if(StringUtils.isNotBlank(remarkLengthRows)) {
|
|
|
|
+ throw new NumberFormatException("第【"+ remarkLengthRows +"】行【说明】列超过500个字符!!!");
|
|
|
|
+ }
|
|
|
|
+ //校验导入的数据中是否存在重复
|
|
|
|
+ Map<String, List<ExcelDataLevel>> map = list.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(ExcelDataLevel::getLevelCode));
|
|
|
|
+ String dupCodes = map.values().stream()
|
|
|
|
+ .filter(item -> item.size() >= 2)
|
|
|
|
+ .map(item -> item.get(0).getLevelCode())
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
+ if(StringUtils.isNotBlank(dupCodes)) {
|
|
|
|
+ throw new NumberFormatException("导入的数据中存在重复代码:【"+ dupCodes +"】");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //校验编码是否存在
|
|
|
|
+ List<String> codes = list.stream().map(ExcelDataLevel::getLevelCode).distinct().collect(Collectors.toList());
|
|
|
|
+ List<DataLevel> existList = getByCodes(codes);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(existList)) {
|
|
|
|
+ String existCodes = existList.stream().map(DataLevel::getLevelCode).collect(Collectors.joining(","));
|
|
|
|
+ throw new NumberFormatException("【"+ existCodes +"】代码已被使用");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<DataLevel> getByCodes(List<String> codes) {
|
|
|
|
+ LambdaQueryWrapper<DataLevel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.select().in(DataLevel::getLevelCode, codes);
|
|
|
|
+ return dataLevelMapper.selectList(queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<ExcelDataLevel> loadDataLevelFromExcel(InputStream inputStream) throws IOException {
|
|
|
|
+ List<ExcelDataLevel> list = new ArrayList<>();
|
|
|
|
+ Workbook wb0 = new HSSFWorkbook(inputStream);
|
|
|
|
+ //获取Excel文档中的第一个表单
|
|
|
|
+ Sheet sht0 = wb0.getSheetAt(0);
|
|
|
|
+ for (Row r : sht0) {
|
|
|
|
+ if (r.getRowNum() == 0) {
|
|
|
|
+ ImportUtil.checkTitle(r, excelTitle);
|
|
|
|
+ }else {
|
|
|
|
+ if(ImportUtil.checkIsEmpty(r, 2)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ ExcelDataLevel dataLevel = getDataLevelFromRow(r);
|
|
|
|
+ list.add(dataLevel);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ExcelDataLevel getDataLevelFromRow(Row r) {
|
|
|
|
+ ExcelDataLevel dataLevel = new ExcelDataLevel();
|
|
|
|
+ dataLevel.setRowNum(r.getRowNum());
|
|
|
|
+ Cell cell;
|
|
|
|
+ //码值
|
|
|
|
+ cell = r.getCell(0);
|
|
|
|
+ String code = ImportUtil.getCellStringValue(cell);
|
|
|
|
+ dataLevel.setLevelCode(code);
|
|
|
|
+ //数据分级
|
|
|
|
+ cell = r.getCell(1);
|
|
|
|
+ String name = ImportUtil.getCellStringValue(cell);
|
|
|
|
+ dataLevel.setLevelName(name);
|
|
|
|
+ //说明
|
|
|
|
+ cell = r.getCell(2);
|
|
|
|
+ String remark = ImportUtil.getCellStringValue(cell);
|
|
|
|
+ dataLevel.setRemark(remark);
|
|
|
|
+ return dataLevel;
|
|
|
|
+ }
|
|
|
|
+
|
|
private void saveByCode(DataLevel dataLevel) {
|
|
private void saveByCode(DataLevel dataLevel) {
|
|
DataLevel exist = this.getByCode(dataLevel.getLevelCode());
|
|
DataLevel exist = this.getByCode(dataLevel.getLevelCode());
|
|
if(null == exist) {
|
|
if(null == exist) {
|