| | |
| | | package org.springblade.modules.yw.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.utils.FileUtil; |
| | | import org.springblade.common.utils.ShapeFileUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.modules.yw.entity.FirmInfo; |
| | | import org.springblade.modules.yw.entity.GeomInfoEntity; |
| | | import org.springblade.modules.yw.mapper.GeomInfoMapper; |
| | | import org.springblade.modules.yw.service.IFirmInfoService; |
| | | import org.springblade.modules.yw.service.IGeomInfoService; |
| | | import org.springblade.modules.yw.vo.GeomInfoVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import java.io.File; |
| | |
| | | */ |
| | | @Service |
| | | public class GeomInfoServiceImpl extends ServiceImpl<GeomInfoMapper, GeomInfoEntity> implements IGeomInfoService { |
| | | |
| | | @Autowired |
| | | private IFirmInfoService firmInfoService; |
| | | |
| | | /** |
| | | * 自定义分页 |
| | |
| | | // 查询空间数据 |
| | | return baseMapper.getGeomInfoList(ids); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导入 shp zip 包文件解析空间信息 |
| | | * @param multipartFile |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R importSpaceShpZip(MultipartFile multipartFile) { |
| | | // 判断文件是否为 zip 文件 |
| | | if (!FileUtil.getFileExtension(multipartFile).equals("zip")){ |
| | | return R.data(400,"文件格式不对,必须是 zip 文件","文件格式不对,必须是 zip 文件"); |
| | | } |
| | | // 转 file |
| | | File file = FileUtil.toFile(multipartFile); |
| | | // 获取文件信息 |
| | | try { |
| | | List<Map<String, Object>> list = ShapeFileUtil.shpToGeoJson(file); |
| | | // 写入数据库,暂时考虑只有一组数据的情况 |
| | | if (list.size()>0){ |
| | | for (Map<String, Object> map : list) { |
| | | GeomInfoEntity geomInfoEntity = Objects.requireNonNull(BeanUtil.copy(map, GeomInfoEntity.class)); |
| | | String geometry = map.get("geometry").toString(); |
| | | geomInfoEntity.setGeom("'" + geometry +"'"); |
| | | String firmName = null; |
| | | if (null!=map.get("firmName")){ |
| | | firmName = map.get("firmName").toString(); |
| | | } |
| | | // 设置所属单位 |
| | | setFirmId(geomInfoEntity,firmName); |
| | | // 判断是否已经存在 |
| | | Long id = isSave(geomInfoEntity); |
| | | if (id!=null){ |
| | | // 覆盖更新 |
| | | // updateById(); |
| | | continue; |
| | | } |
| | | // 保存 |
| | | baseMapper.saveGeoInfo(geomInfoEntity); |
| | | } |
| | | // 返回 |
| | | return R.data(200,list,"操作成功!"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // 返回 |
| | | return R.data(200,"操作失败","操作失败!读取数据错误!"); |
| | | } |
| | | |
| | | /** |
| | | * 设置所属企业id |
| | | * @param geomInfoEntity |
| | | * @param firmName |
| | | */ |
| | | private void setFirmId(GeomInfoEntity geomInfoEntity,String firmName) { |
| | | if (!Strings.isBlank(firmName)) { |
| | | QueryWrapper<FirmInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("name", firmName); |
| | | FirmInfo one = firmInfoService.getOne(wrapper); |
| | | if (null!=one) |
| | | geomInfoEntity.setFirmId(one.getId()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断是否已经保存 |
| | | * @param geomInfoEntity |
| | | * @return |
| | | */ |
| | | private Long isSave(GeomInfoEntity geomInfoEntity) { |
| | | QueryWrapper<GeomInfoEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("name",geomInfoEntity); |
| | | GeomInfoEntity one = getOne(wrapper); |
| | | if (null!=one){ |
| | | return one.getId(); |
| | | } |
| | | return null; |
| | | } |
| | | } |