|
|
@@ -52,6 +52,7 @@ import tk.mybatis.mapper.entity.Example;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@@ -118,13 +119,11 @@ public class WindFieldServiceImpl extends BaseServiceImpl<WindFieldPO> implement
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean createWindRelation(WindFieldPO po) {
|
|
|
-
|
|
|
WindRelationDto windRelationDto = new WindRelationDto();
|
|
|
windRelationDto.setCodeNumber(po.getFieldCode());
|
|
|
windRelationDto.setCodeName(po.getFieldName());
|
|
|
windRelationDto.setParentCode(po.getCompanyCode());
|
|
|
windRelationDto.setType(TypeRelationEnum.WIND_FIELD_NUMBER.getCode());
|
|
|
-
|
|
|
return windRelationServic.createWindRelation(windRelationDto);
|
|
|
}
|
|
|
|
|
|
@@ -132,26 +131,40 @@ public class WindFieldServiceImpl extends BaseServiceImpl<WindFieldPO> implement
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ResultResp windFieldImportData(MultipartFile file, WindFieldImportDataDto windFieldImportDataDto) {
|
|
|
- ;
|
|
|
List<WindFieldExceVo> windFieldExceVos = EasyExcel.read(file.getInputStream()).head(WindFieldExceVo.class).sheet().doReadSync();
|
|
|
if (CollectionUtils.isEmpty(windFieldExceVos)) {
|
|
|
return ResultResp.FAIL("未读取到文件数据,请核对数据准确性!");
|
|
|
}
|
|
|
+ // 过滤空数据
|
|
|
+ List<WindFieldExceVo> windFieldExceVoList = windFieldExceVos.stream().filter(item -> !StringUtils.isEmpty(item.getFieldName())).collect(Collectors.toList());
|
|
|
|
|
|
- // Todo 获取区域信息
|
|
|
- List<String> provinceNames = windFieldExceVos.stream().map(WindFieldExceVo::getProvinceName).distinct().collect(Collectors.toList());
|
|
|
- List<AreaPO> areaProvinces = areaApiService.getAllProvinceByName(1,provinceNames);
|
|
|
-
|
|
|
-
|
|
|
- List<String> cityNames = windFieldExceVos.stream().map(WindFieldExceVo::getCityName).distinct().collect(Collectors.toList());
|
|
|
- List<AreaPO> areacitys = areaApiService.getAllProvinceByName(2,cityNames);
|
|
|
-
|
|
|
+ // 校验数据非空
|
|
|
+ for (WindFieldExceVo exceVo : windFieldExceVoList) {
|
|
|
+ if (StringUtils.isEmpty(exceVo.getCityName()) || StringUtils.isEmpty(exceVo.getProvinceName())) {
|
|
|
+ return ResultResp.FAIL("当前导入风场数据未填写区域,请核查导入数据!");
|
|
|
+ }
|
|
|
+ if (exceVo.getLongitude() == null || exceVo.getLatitude() == null) {
|
|
|
+ return ResultResp.FAIL("当前导入风场数据未填写经纬度,请核查导入数据!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 数据校验是否有重名风场
|
|
|
+ List<String> fieldNames = windFieldExceVoList.stream().map(item -> item.getFieldName()).collect(Collectors.toList());
|
|
|
+ Example queryExample = new Example(WindFieldPO.class);
|
|
|
+ Example.Criteria criteria = queryExample.createCriteria();
|
|
|
+ criteria.andIn("fieldName", fieldNames);
|
|
|
+ criteria.andEqualTo("companyCode", windFieldImportDataDto.getCompanyCode());
|
|
|
+ criteria.andEqualTo("delState", DeleteStatusEnum.NODELETE.getCode());
|
|
|
+ int count = windFieldMapper.selectCountByExample(queryExample);
|
|
|
+ if (count > 0) {
|
|
|
+ return ResultResp.FAIL("当前项目公司中有已经存在的风场,请核查导入数据!");
|
|
|
+ }
|
|
|
|
|
|
+ // 查询区域id并赋值
|
|
|
+ this.setWindFieldExceAreaId(windFieldExceVoList);
|
|
|
|
|
|
WindFieldPO windFieldPO = null;
|
|
|
List<WindFieldPO> list = Lists.newArrayList();
|
|
|
-
|
|
|
- for (WindFieldExceVo windFieldExceVo : windFieldExceVos) {
|
|
|
+ for (WindFieldExceVo windFieldExceVo : windFieldExceVoList) {
|
|
|
windFieldPO = new WindFieldPO();
|
|
|
BeanUtil.copyProperties(windFieldExceVo, windFieldPO);
|
|
|
String number = IdPrefixEnum.WIND_FIELD_NUMBER.getCode().concat(windFieldExceVo.getAreaCode() + IdGeneratorUtil.zeroFillUtil(cacheService.incr(ManagerRedisKeyConstant.build(ManagerRedisKeyConstant.IDGENERATOR_CONSTANTS_KEY, IdPrefixEnum.WIND_FIELD_NUMBER.getCode()))));
|
|
|
@@ -172,6 +185,34 @@ public class WindFieldServiceImpl extends BaseServiceImpl<WindFieldPO> implement
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 查询区域id并赋值
|
|
|
+ *
|
|
|
+ * @param windFieldExceVos
|
|
|
+ */
|
|
|
+ private void setWindFieldExceAreaId(List<WindFieldExceVo> windFieldExceVos) {
|
|
|
+ // 区域id 赋值
|
|
|
+ List<String> provinceNames = windFieldExceVos.stream().map(WindFieldExceVo::getProvinceName).distinct().collect(Collectors.toList());
|
|
|
+ List<AreaPO> areaProvinces = areaApiService.getAllProvinceByName(1, provinceNames);
|
|
|
+ for (WindFieldExceVo windFieldExceVo : windFieldExceVos) {
|
|
|
+ for (AreaPO areaPO : areaProvinces) {
|
|
|
+ if (windFieldExceVo.getProvinceName().equals(areaPO.getProvince())) {
|
|
|
+ windFieldExceVo.setProvinceId(areaPO.getAreaId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> cityNames = windFieldExceVos.stream().map(WindFieldExceVo::getCityName).distinct().collect(Collectors.toList());
|
|
|
+ List<AreaPO> areaCitys = areaApiService.getAllProvinceByName(2, cityNames);
|
|
|
+ for (WindFieldExceVo windFieldExceVo : windFieldExceVos) {
|
|
|
+ for (AreaPO areaPO : areaCitys) {
|
|
|
+ if (windFieldExceVo.getCityName().equals(areaPO.getCity())) {
|
|
|
+ windFieldExceVo.setCityId(areaPO.getAreaId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 批量创建关系数据
|
|
|
*
|
|
|
* @param list
|