package com.lf.server.service.show;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.lf.server.entity.sys.UserEntity;
|
import com.lf.server.helper.*;
|
import com.lf.server.mapper.all.GeomBaseMapper;
|
import com.lf.server.service.all.BaseQueryService;
|
import com.lf.server.service.data.DownloadService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.io.File;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 资料馆
|
* @author WWW
|
*/
|
@Service
|
public class DataLibService {
|
@Autowired
|
PathHelper pathHelper;
|
|
@Autowired
|
BaseQueryService baseQueryService;
|
|
@Autowired
|
DownloadService downloadService;
|
|
/**
|
* 创建Zip包
|
*/
|
public String createZipFile(UserEntity ue, List<String> entities, String wkt, String pwd) {
|
Map<String, List<?>> map = queryData(entities, wkt);
|
if (map.size() == 0) {
|
return null;
|
}
|
|
//String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
|
//String tempPath = pathHelper.getTempPath(tempName);
|
//String filePath = tempPath + File.separator + tempName + ".gdb";
|
|
String filePath = "D:\\LF\\temp\\20221219202706\\20221219202705.gdb";
|
File file = new File(filePath);
|
if (!file.exists() || !file.isDirectory()) {
|
file.mkdirs();
|
}
|
|
filePath = "D:\\LF\\temp\\20221219202706\\2022.gdb";
|
if (file.exists() && file.isDirectory()) {
|
FileHelper.deleteDir(filePath);
|
}
|
GdbHelper.createGdb(filePath, map);
|
|
return null;
|
}
|
|
/**
|
* 查询数据
|
*/
|
private Map<String, List<?>> queryData(List<String> entities, String wkt) {
|
Map<String, List<?>> map = new HashMap<>(5);
|
for (String enity : entities) {
|
try {
|
GeomBaseMapper baseMapper = ClassHelper.getGeoBaseMapper(enity);
|
if (null == baseMapper) {
|
continue;
|
}
|
|
QueryWrapper wrapper = createWrapper(baseMapper, wkt);
|
List<?> list = baseMapper.selectList(wrapper);
|
if (null == list || list.size() == 0) {
|
continue;
|
}
|
|
if (!map.containsKey(enity)) {
|
map.put(enity, list);
|
}
|
} catch (Exception ex) {
|
//
|
}
|
}
|
|
return map;
|
}
|
|
/**
|
* 创建QueryWrapper
|
*/
|
private QueryWrapper createWrapper(GeomBaseMapper baseMapper, String wkt) {
|
QueryWrapper wrapper = new QueryWrapper();
|
wrapper.select("ST_AsText(geom) as geom, *");
|
Integer srid = baseQueryService.getSrid(baseMapper);
|
wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", wkt, srid));
|
|
return wrapper;
|
}
|
}
|