|
@@ -0,0 +1,234 @@
|
|
|
|
+package com.onemap.file.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
+import com.onemap.common.core.utils.StringUtils;
|
|
|
|
+import com.onemap.common.core.web.domain.AjaxResult;
|
|
|
|
+import com.onemap.common.core.web.domain.RequestResult;
|
|
|
|
+import com.onemap.file.domain.SpaceFileRecordDTO;
|
|
|
|
+import com.onemap.file.mapper.SpaceFileRecordMapper;
|
|
|
|
+import com.onemap.file.service.ISpaceFileRecordService;
|
|
|
|
+import com.onemap.file.service.SaveFileService;
|
|
|
|
+import com.onemap.file.utils.FileUtils;
|
|
|
|
+import com.onemap.file.utils.UnPackageUtils;
|
|
|
|
+import com.onemap.system.api.AnalyseService;
|
|
|
|
+import com.onemap.system.api.SpatialService;
|
|
|
|
+import com.onemap.system.api.TableFiledRelationService;
|
|
|
|
+import com.onemap.system.api.domain.GeomGroupSummaryVo;
|
|
|
|
+import com.onemap.system.api.domain.RawTableVo;
|
|
|
|
+import com.onemap.file.domain.res.ApiTTable;
|
|
|
|
+import com.onemap.file.domain.res.ApiTTableFiled;
|
|
|
|
+import com.onemap.file.domain.res.TableDataVo;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.annotation.processing.FilerException;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class SpaceFileRecordServiceImpl implements ISpaceFileRecordService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SaveFileService saveFileService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SpatialService spatialService;
|
|
|
|
+ @Value("${businessType.shp}")
|
|
|
|
+ private String shpLocalFilePath;
|
|
|
|
+ @Resource
|
|
|
|
+ private SpaceFileRecordMapper spaceFileRecordMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private TableFiledRelationService tableFiledRelationService;
|
|
|
|
+ @Resource
|
|
|
|
+ private AnalyseService analyseService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String saveSpaceFileRecord(SpaceFileRecordDTO spaceFileRecordDTO) throws Exception {
|
|
|
|
+ if (StringUtils.isEmpty(spaceFileRecordDTO.getId())) {
|
|
|
|
+ spaceFileRecordDTO.setId(StringUtils.getUUID());
|
|
|
|
+ }
|
|
|
|
+ spaceFileRecordMapper.saveSpaceFileRecord(spaceFileRecordDTO);
|
|
|
|
+ return spaceFileRecordDTO.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public SpaceFileRecordDTO querySpaceFileRecord(String id, int isDetail) {
|
|
|
|
+ SpaceFileRecordDTO dto = spaceFileRecordMapper.querySpaceFileRecordById(id);
|
|
|
|
+ if (dto == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询tableid
|
|
|
|
+ String tableId = dto.getFilepath();
|
|
|
|
+ AjaxResult ajaxResult = tableFiledRelationService.QueryTableFiledRelation(tableId);
|
|
|
|
+ if (!ajaxResult.isSuccess()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ Object tableStr = ajaxResult.get(AjaxResult.DATA_TAG);
|
|
|
|
+ ApiTTable tTable = JSON.parseObject(JSON.toJSONString(tableStr), ApiTTable.class);
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(dto.getGeom())) {
|
|
|
|
+ //分组查询
|
|
|
|
+ GeomGroupSummaryVo geomGroupSummaryVo = new GeomGroupSummaryVo();
|
|
|
|
+ geomGroupSummaryVo.setSiweiArea(true);
|
|
|
|
+ geomGroupSummaryVo.setSrid(4525);
|
|
|
|
+ geomGroupSummaryVo.setIsGeography(false);
|
|
|
|
+ geomGroupSummaryVo.setTableName(tTable.getTableName());
|
|
|
|
+ RequestResult rawTableSumData = analyseService.getGeomGroupSummary(geomGroupSummaryVo);
|
|
|
|
+ if (!rawTableSumData.isSuccess()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> d_list_0 = (List<Map<String, Object>>) rawTableSumData.get(RequestResult.DATA_TAG);
|
|
|
|
+ Map<String, Object> d_map_0 = d_list_0.get(0);
|
|
|
|
+ int siweicount = (int) d_map_0.get("siweicount");
|
|
|
|
+ Double siweiarea = (Double) d_map_0.get("siweiarea");
|
|
|
|
+ String sumgeom = (String) d_map_0.get("geom");
|
|
|
|
+
|
|
|
|
+ dto.setArea(siweiarea);
|
|
|
|
+ dto.setNumber(siweicount);
|
|
|
|
+ dto.setGeom(sumgeom);
|
|
|
|
+ spaceFileRecordMapper.updateSpaceFileRecord(dto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isDetail == 1) {
|
|
|
|
+ List<String> columns = new ArrayList<>();
|
|
|
|
+ for (ApiTTableFiled filed : tTable.getTableFiledlist()) {
|
|
|
|
+ columns.add(filed.getFiledName());
|
|
|
|
+ }
|
|
|
|
+ RawTableVo rawTableVo = new RawTableVo();
|
|
|
|
+ rawTableVo.setRawTableName(tTable.getTableName());
|
|
|
|
+ rawTableVo.setColumns(columns);
|
|
|
|
+ rawTableVo.setSrid(4525);
|
|
|
|
+ rawTableVo.setIsGeography(false);
|
|
|
|
+ rawTableVo.setSiweiArea(true);
|
|
|
|
+ RequestResult rawTableData = analyseService.rawTable(rawTableVo);
|
|
|
|
+ if (!rawTableData.isSuccess()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ List<Map<String, Object>> retData = (List<Map<String, Object>>) rawTableData.get(RequestResult.DATA_TAG);
|
|
|
|
+ List<List<TableDataVo>> dataList_0 = dataMapTransFormZh(retData, tTable.getTableFiledlist());
|
|
|
|
+ dto.setDataList(dataList_0);
|
|
|
|
+ }
|
|
|
|
+ return dto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public RequestResult uploadAddShpFile(MultipartFile file, String fromRoute) throws Exception {
|
|
|
|
+ // 获取当前时间的时间戳
|
|
|
|
+ long timeMillis = System.currentTimeMillis();
|
|
|
|
+ //生成SHP解压文件路径
|
|
|
|
+ String shpPath = shpLocalFilePath + "/temp" + "/" + timeMillis;
|
|
|
|
+ //解压文件
|
|
|
|
+ uploadDestMultipartFile(file, shpPath);
|
|
|
|
+
|
|
|
|
+ String newShpPath = null;
|
|
|
|
+ File[] files = new File(shpPath).listFiles();
|
|
|
|
+ for (File file1 : files) {
|
|
|
|
+ List<File> shpFiles = new ArrayList<>();
|
|
|
|
+ FileUtils.findShpFiles(file1, shpFiles);
|
|
|
|
+ if (shpFiles.size() != 0) {
|
|
|
|
+ newShpPath = shpFiles.get(0).getPath();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(newShpPath)) {
|
|
|
|
+ return RequestResult.error("未读取到SHP文件");
|
|
|
|
+ }
|
|
|
|
+ RequestResult res = spatialService.shpReadFile(newShpPath);
|
|
|
|
+ if (!res.isSuccess()) {
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+ String tableID = (String) res.get(RequestResult.MSG_TAG);
|
|
|
|
+ SpaceFileRecordDTO spaceFileRecordDTO = new SpaceFileRecordDTO();
|
|
|
|
+ spaceFileRecordDTO.setFromType(2);
|
|
|
|
+ spaceFileRecordDTO.setFilepath(tableID);
|
|
|
|
+ spaceFileRecordDTO.setFilepath(tableID);
|
|
|
|
+ spaceFileRecordDTO.setFromRoute(fromRoute);
|
|
|
|
+ String id = saveSpaceFileRecord(spaceFileRecordDTO);
|
|
|
|
+ return RequestResult.success("上传成功", querySpaceFileRecord(id, 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public RequestResult uploadAddShpDraw(String geom, String fromRoute) throws Exception {
|
|
|
|
+ RequestResult res = spatialService.shpReadEwkt(geom);
|
|
|
|
+ if (!res.isSuccess()) {
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+ String tableID = (String) res.get(RequestResult.MSG_TAG);
|
|
|
|
+ SpaceFileRecordDTO spaceFileRecordDTO = new SpaceFileRecordDTO();
|
|
|
|
+ spaceFileRecordDTO.setFromType(2);
|
|
|
|
+ spaceFileRecordDTO.setFilepath(tableID);
|
|
|
|
+ spaceFileRecordDTO.setFilepath(tableID);
|
|
|
|
+ spaceFileRecordDTO.setFromRoute(fromRoute);
|
|
|
|
+ String id = saveSpaceFileRecord(spaceFileRecordDTO);
|
|
|
|
+ return RequestResult.success("上传成功", querySpaceFileRecord(id, 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void uploadDestMultipartFile(MultipartFile file, String destPath) throws IOException {
|
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
|
+ // 获得文件后缀名
|
|
|
|
+ String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
|
+ // 判断上传的是否是压缩包
|
|
|
|
+ if (!type.equals("zip")) {
|
|
|
|
+ throw new FilerException("请上传压缩包,暂支持ZIP");
|
|
|
|
+ }
|
|
|
|
+ //新文件
|
|
|
|
+ File newFile = new File(destPath + "/" + fileName);
|
|
|
|
+ //新文件的上级目录
|
|
|
|
+ File dir = newFile.getParentFile();
|
|
|
|
+ // 判断是否,并创建文件夹
|
|
|
|
+ if (!dir.exists()) {
|
|
|
|
+ dir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ //将文件复制到新文件
|
|
|
|
+ Files.copy(file.getInputStream(), newFile.toPath());
|
|
|
|
+ // 解压zip格式
|
|
|
|
+ new UnPackageUtils().unPackZip(newFile, destPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<List<TableDataVo>> dataMapTransFormZh(List<Map<String, Object>> from_jg, List<ApiTTableFiled> filedList) {
|
|
|
|
+ List<List<TableDataVo>> retList = new ArrayList<>();
|
|
|
|
+ if (from_jg == null || from_jg.size() == 0) {
|
|
|
|
+ return retList;
|
|
|
|
+ }
|
|
|
|
+ if (filedList == null || filedList.size() == 0) {
|
|
|
|
+ return retList;
|
|
|
|
+ }
|
|
|
|
+ //循环结果
|
|
|
|
+ for (Map v_data : from_jg) {
|
|
|
|
+ //循环字段
|
|
|
|
+ List<TableDataVo> v_dataList = new ArrayList<>();
|
|
|
|
+ for (ApiTTableFiled v_filed_data : filedList) {
|
|
|
|
+ String v_filedName = v_filed_data.getFiledName();
|
|
|
|
+ String v_filedZh = v_filed_data.getFiledZh();
|
|
|
|
+ Object v_filedData = v_data.get(v_filedName);
|
|
|
|
+ TableDataVo tableDataVo = new TableDataVo();
|
|
|
|
+ tableDataVo.setData(v_filedData);
|
|
|
|
+ tableDataVo.setFiledZH(v_filedZh);
|
|
|
|
+ tableDataVo.setFiled(v_filedName);
|
|
|
|
+ v_dataList.add(tableDataVo);
|
|
|
|
+ }
|
|
|
|
+ Object siweiarea = v_data.get("siweiarea");
|
|
|
|
+ if (StringUtils.isNotNull(siweiarea)) {
|
|
|
|
+ // 面积
|
|
|
|
+ TableDataVo tableDataVo = new TableDataVo();
|
|
|
|
+ tableDataVo.setData(new BigDecimal(String.valueOf(siweiarea)).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
|
+ tableDataVo.setFiledZH("面积(平方米)");
|
|
|
|
+ tableDataVo.setFiled("siweiarea");
|
|
|
|
+ v_dataList.add(tableDataVo);
|
|
|
|
+ }
|
|
|
|
+ retList.add(v_dataList);
|
|
|
|
+ }
|
|
|
|
+ return retList;
|
|
|
|
+ }
|
|
|
|
+}
|