|
@@ -28,6 +28,7 @@ import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.dao.DataIntegrityViolationException;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -540,33 +541,58 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void executeImportSysOrgLogic(MultipartFile file) throws Exception {
|
|
|
- InputStream inputStream = file.getInputStream();
|
|
|
- List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(SysOrgImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> finalExcelList);
|
|
|
- List<String> orgInfoList = new ArrayList<>();
|
|
|
- for (int i = 0; i < finalList.size(); i++) {
|
|
|
- LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
|
- List<Object> sysOrgImportDtoList = excelMap.get(i);
|
|
|
- assert sysOrgImportDtoList != null;
|
|
|
- if (sysOrgImportDtoList.get(0) instanceof DescribeImportDto) {
|
|
|
- continue;
|
|
|
+ public void executeImportSysOrgLogic(MultipartFile file) {
|
|
|
+ try {
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
+ List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(SysOrgImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> finalExcelList);
|
|
|
+ List<String> orgInfoList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < finalList.size(); i++) {
|
|
|
+ LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
|
+ List<Object> sysOrgImportDtoList = excelMap.get(i);
|
|
|
+ assert sysOrgImportDtoList != null;
|
|
|
+ if (sysOrgImportDtoList.get(0) instanceof DescribeImportDto) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 处理机构
|
|
|
+ if (sysOrgImportDtoList.get(0) instanceof SysOrgImportDto) {
|
|
|
+ List<SysOrgImportDto> datasource = sysOrgImportDtoList.stream().map(e -> {
|
|
|
+ SysOrgImportDto sysOrgImportDto = new SysOrgImportDto();
|
|
|
+ BeanUtils.copyProperties(e, sysOrgImportDto);
|
|
|
+ return sysOrgImportDto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (datasource.size() > 0) {
|
|
|
+ datasource.forEach(e -> orgInfoList.add(e.getName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (orgInfoList.size() > 0) {
|
|
|
+ SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ this.createOrGetOrgByOrgInfo(orgInfoList, requestUser);
|
|
|
}
|
|
|
- // 处理机构
|
|
|
- if (sysOrgImportDtoList.get(0) instanceof SysOrgImportDto) {
|
|
|
- List<SysOrgImportDto> datasource = sysOrgImportDtoList.stream().map(e -> {
|
|
|
- SysOrgImportDto sysOrgImportDto = new SysOrgImportDto();
|
|
|
- BeanUtils.copyProperties(e, sysOrgImportDto);
|
|
|
- return sysOrgImportDto;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- if (datasource.size() > 0) {
|
|
|
- datasource.forEach(e -> orgInfoList.add(e.getName()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof DataIntegrityViolationException) {
|
|
|
+ String error = e.getCause().toString();
|
|
|
+ String tooLongColumn = error.substring(error.lastIndexOf("column") + 7);
|
|
|
+ tooLongColumn = tooLongColumn.substring(0, tooLongColumn.lastIndexOf("at") - 1);
|
|
|
+ tooLongColumn = tooLongColumn.replaceAll("'", "");
|
|
|
+ String columnName = "";
|
|
|
+ switch (tooLongColumn) {
|
|
|
+ case "name":
|
|
|
+ columnName = "机构名称";
|
|
|
+ break;
|
|
|
+ case "code":
|
|
|
+ columnName = "机构编号";
|
|
|
+ break;
|
|
|
}
|
|
|
+ String content = SystemConstant.strNotNull(columnName) ? columnName : tooLongColumn;
|
|
|
+ throw ExceptionResultEnum.SQL_ERROR.exception("[" + content + "]超过长度限制");
|
|
|
+ } else if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- if (orgInfoList.size() > 0) {
|
|
|
- SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- this.createOrGetOrgByOrgInfo(orgInfoList, requestUser);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@Override
|