|
@@ -420,87 +420,91 @@ public class BaseGgpFacilityServiceImpl extends AbstractCrudService<BaseGgpFacil
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public void facilityImport(MultipartFile multipartFile) {
|
|
|
-// ImportParams params = new ImportParams();
|
|
|
-// params.setHeadRows(1);
|
|
|
-// params.setTitleRows(1);
|
|
|
-// String err="文件导入失败";
|
|
|
-// try {
|
|
|
-// List<FacilityImportVo> facilityImportVos = ExcelImportUtil.importExcel(multipartFile.getInputStream(),
|
|
|
-// FacilityImportVo.class, params);
|
|
|
-// if (CollectionUtils.isNotEmpty(facilityImportVos)){
|
|
|
-// int rot=0;
|
|
|
-// for (FacilityImportVo facilityImportVo:facilityImportVos) {
|
|
|
-// BaseGgpFacility baseGgpFacility = BeanMapperUtils.map(facilityImportVo, BaseGgpFacility.class);
|
|
|
-// if (StringUtils.isBlank(baseGgpFacility.getFacilityType())||StringUtils.isBlank(baseGgpFacility.getFacilityName())||StringUtils.isBlank(baseGgpFacility.getAddress())||StringUtils.isBlank(baseGgpFacility.getLatitude())||StringUtils.isBlank(baseGgpFacility.getLongitude())){
|
|
|
-// int h=rot+3;
|
|
|
-// err="文件导入失败,第"+h+"行数据导入失败,必填字段不能为空";
|
|
|
-// throw new BusinessException(err);
|
|
|
-// }
|
|
|
-// try{
|
|
|
-// this.add(baseGgpFacility);
|
|
|
-// }catch (Exception e){
|
|
|
-// int h=rot+3;
|
|
|
-// err="文件导入失败,第"+h+"行数据导入失败";
|
|
|
-// throw new BusinessException(err);
|
|
|
-// }
|
|
|
-// rot++;
|
|
|
-// }
|
|
|
-// }else {
|
|
|
-// err="文件不能为空";
|
|
|
-// throw new BusinessException(err);
|
|
|
-// }
|
|
|
-// }catch (Exception e){
|
|
|
-// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
-// throw new BusinessException(err);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
@Override
|
|
|
public void facilityImport(MultipartFile multipartFile) {
|
|
|
- String FILE_IMPORT_FAILED = "文件导入失败";
|
|
|
- String FILE_EMPTY = "文件不能为空";
|
|
|
- String ROW_IMPORT_FAILED = "第%d行数据导入失败";
|
|
|
-
|
|
|
ImportParams params = new ImportParams();
|
|
|
params.setHeadRows(1);
|
|
|
params.setTitleRows(1);
|
|
|
-
|
|
|
- try (InputStream inputStream = multipartFile.getInputStream()) {
|
|
|
- List<BaseGgpFacility> facilityList = new ArrayList<>();
|
|
|
- List<FacilityImportVo> facilityImportVos = ExcelImportUtil.importExcel(inputStream, FacilityImportVo.class, params);
|
|
|
- if (CollectionUtils.isEmpty(facilityImportVos)) {
|
|
|
- throw new BusinessException(FILE_EMPTY);
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < facilityImportVos.size(); i++) {
|
|
|
- FacilityImportVo facilityImportVo = facilityImportVos.get(i);
|
|
|
- BaseGgpFacility baseGgpFacility = BeanMapperUtils.map(facilityImportVo, BaseGgpFacility.class);
|
|
|
- if (isBlank(baseGgpFacility.getFacilityType()) || isBlank(baseGgpFacility.getFacilityName()) || isBlank(baseGgpFacility.getAddress()) || isBlank(baseGgpFacility.getLatitude()) || isBlank(baseGgpFacility.getLongitude())) {
|
|
|
- throw new BusinessException(String.format(ROW_IMPORT_FAILED, i + 1));
|
|
|
+ String err="文件导入失败";
|
|
|
+ try {
|
|
|
+ List<FacilityImportVo> facilityImportVos = ExcelImportUtil.importExcel(multipartFile.getInputStream(),
|
|
|
+ FacilityImportVo.class, params);
|
|
|
+ if (CollectionUtils.isNotEmpty(facilityImportVos)){
|
|
|
+ int rot=0;
|
|
|
+ for (FacilityImportVo facilityImportVo:facilityImportVos) {
|
|
|
+ BaseGgpFacility baseGgpFacility = BeanMapperUtils.map(facilityImportVo, BaseGgpFacility.class);
|
|
|
+ if (StringUtils.isBlank(baseGgpFacility.getFacilityType())||StringUtils.isBlank(baseGgpFacility.getFacilityName())||StringUtils.isBlank(baseGgpFacility.getAddress())||StringUtils.isBlank(baseGgpFacility.getLatitude())||StringUtils.isBlank(baseGgpFacility.getLongitude())){
|
|
|
+ int h=rot+3;
|
|
|
+ err="文件导入失败,第"+h+"行数据导入失败,必填字段不能为空";
|
|
|
+ throw new BusinessException(err);
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ this.add(baseGgpFacility);
|
|
|
+ }catch (Exception e){
|
|
|
+ int h=rot+3;
|
|
|
+ err="文件导入失败,第"+h+"行数据导入失败";
|
|
|
+ throw new BusinessException(err);
|
|
|
+ }
|
|
|
+ rot++;
|
|
|
}
|
|
|
- Calendar cal1 = Calendar.getInstance();
|
|
|
- Date date = cal1.getTime();
|
|
|
- List<BaseFacilityType> typeList = baseFacilityTypeMapper.typeList(baseGgpFacility.getFacilityType());
|
|
|
- baseGgpFacility.setFacilityNum(typeList.get(0).getTypeAbbrevia()+'-'+new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date));
|
|
|
- baseGgpFacility.setCreator(SecurityUtils.getUsername());
|
|
|
- baseGgpFacility.setCreateTime(LocalDateTime.now());
|
|
|
- baseGgpFacility.setTenantId(SecurityUtils.getTenantId());
|
|
|
- facilityList.add(baseGgpFacility);
|
|
|
- }
|
|
|
- try {
|
|
|
- this.saveBatch(facilityList);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new BusinessException(FILE_IMPORT_FAILED);
|
|
|
+ }else {
|
|
|
+ err="文件不能为空";
|
|
|
+ throw new BusinessException(err);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("文件导入失败", e);
|
|
|
+ }catch (Exception e){
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- throw new BusinessException(FILE_IMPORT_FAILED);
|
|
|
+ throw new BusinessException(err);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// @Override
|
|
|
+// public void facilityImport(MultipartFile multipartFile) {
|
|
|
+// String FILE_IMPORT_FAILED = "文件导入失败";
|
|
|
+// String FILE_EMPTY = "文件不能为空";
|
|
|
+// String ROW_IMPORT_FAILED = "第%d行数据导入失败";
|
|
|
+//
|
|
|
+// ImportParams params = new ImportParams();
|
|
|
+// params.setHeadRows(1);
|
|
|
+// params.setTitleRows(1);
|
|
|
+//
|
|
|
+// try (InputStream inputStream = multipartFile.getInputStream()) {
|
|
|
+// List<BaseGgpFacility> facilityList = new ArrayList<>();
|
|
|
+// List<FacilityImportVo> facilityImportVos = ExcelImportUtil.importExcel(inputStream, FacilityImportVo.class, params);
|
|
|
+// if (CollectionUtils.isEmpty(facilityImportVos)) {
|
|
|
+// throw new BusinessException(FILE_EMPTY);
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (int i = 0; i < facilityImportVos.size(); i++) {
|
|
|
+// FacilityImportVo facilityImportVo = facilityImportVos.get(i);
|
|
|
+// BaseGgpFacility baseGgpFacility = BeanMapperUtils.map(facilityImportVo, BaseGgpFacility.class);
|
|
|
+// if (isBlank(baseGgpFacility.getFacilityType()) || isBlank(baseGgpFacility.getFacilityName()) || isBlank(baseGgpFacility.getAddress()) || isBlank(baseGgpFacility.getLatitude()) || isBlank(baseGgpFacility.getLongitude())) {
|
|
|
+// throw new BusinessException(String.format(ROW_IMPORT_FAILED, i + 1));
|
|
|
+// }
|
|
|
+// Calendar cal1 = Calendar.getInstance();
|
|
|
+// Date date = cal1.getTime();
|
|
|
+// List<BaseFacilityType> typeList = baseFacilityTypeMapper.typeList(baseGgpFacility.getFacilityType());
|
|
|
+// if (CollectionUtils.isEmpty(typeList)) {
|
|
|
+// String FILE_TYPE_ERROR = "设施类型有误";
|
|
|
+// throw new BusinessException(FILE_TYPE_ERROR);
|
|
|
+// }
|
|
|
+// baseGgpFacility.setFacilityNum(typeList.get(0).getTypeAbbrevia()+'-'+new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date));
|
|
|
+// baseGgpFacility.setCreator(SecurityUtils.getUsername());
|
|
|
+// baseGgpFacility.setCreateTime(LocalDateTime.now());
|
|
|
+// baseGgpFacility.setTenantId(SecurityUtils.getTenantId());
|
|
|
+// facilityList.add(baseGgpFacility);
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// this.saveBatch(facilityList);
|
|
|
+// } catch (Exception e) {
|
|
|
+// throw new BusinessException(FILE_IMPORT_FAILED);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("文件导入失败", e);
|
|
|
+// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+// throw new BusinessException(FILE_IMPORT_FAILED);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
private boolean isBlank(String str) {
|
|
|
return StringUtils.isBlank(str) || StringUtils.isBlank(str.trim());
|
|
|
}
|