Commit cbdb8a97 authored by 周健威's avatar 周健威

修改代码

parent 07802411
package com.upyuns.platform.rs.datacenter.job;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.upyuns.platform.rs.datacenter.biz.RscpImageDataTotalBiz;
import com.upyuns.platform.rs.datacenter.biz.RscpImagePriceBiz;
import com.upyuns.platform.rs.datacenter.biz.RscpImageStatisticsBiz;
import com.upyuns.platform.rs.datacenter.entity.RscpImageDataTotal;
import com.upyuns.platform.rs.datacenter.entity.RscpImagePrice;
import com.upyuns.platform.rs.datacenter.entity.RscpImageStatistics;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.List;
import java.util.stream.Collectors;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Slf4j
public class CoverScheduleTask {
@Autowired
RscpImagePriceBiz rscpImagePriceBiz;
@Autowired
RscpImageDataTotalBiz rscpImageDataTotalBiz;
@Autowired
RscpImageStatisticsBiz rscpImageStatisticsBiz;
//定时按月份统计覆盖率
@Scheduled(cron = "0 0 2 * * ?")
//或直接指定时间间隔,例如:5秒
//@Scheduled(fixedRate=5000)
public void configureTasks() {
}
private void insertPart(int sort, String satelliteType, Integer countAll, int type) {
insertPart(sort, satelliteType, countAll, type, null);
}
private void insertPart(int sort, String satelliteType, Integer countAll, int type, String year) {
RscpImageStatistics rscpImageStatisticsAll = new RscpImageStatistics();
rscpImageStatisticsAll.setName(satelliteType);
rscpImageStatisticsAll.setNum(countAll);
rscpImageStatisticsAll.setSort(sort);
rscpImageStatisticsAll.setType(type);
rscpImageStatisticsAll.setDateyear(Integer.valueOf(year));
rscpImageStatisticsBiz.insertSelective(rscpImageStatisticsAll);
}
private void yearInsert(String year, String satelliteType, Integer sort) {
Integer countYear = rscpImageDataTotalBiz.selectCountByWeekend(w-> {
w.andEqualTo(RscpImageDataTotal::getImageSatelliteType, satelliteType);
w.andEqualTo(RscpImageDataTotal::getImageYear, year);
return w;
});
//添加
insertPart(sort, satelliteType, countYear, RscpImageStatistics.TYPE_YEAR, year);
}
}
\ No newline at end of file
...@@ -98,11 +98,16 @@ public class SaticScheduleTask { ...@@ -98,11 +98,16 @@ public class SaticScheduleTask {
} }
private void insertPart(int sort, String satelliteType, Integer countAll, int type) { private void insertPart(int sort, String satelliteType, Integer countAll, int type) {
insertPart(sort, satelliteType, countAll, type, null);
}
private void insertPart(int sort, String satelliteType, Integer countAll, int type, String year) {
RscpImageStatistics rscpImageStatisticsAll = new RscpImageStatistics(); RscpImageStatistics rscpImageStatisticsAll = new RscpImageStatistics();
rscpImageStatisticsAll.setName(satelliteType); rscpImageStatisticsAll.setName(satelliteType);
rscpImageStatisticsAll.setNum(countAll); rscpImageStatisticsAll.setNum(countAll);
rscpImageStatisticsAll.setSort(sort); rscpImageStatisticsAll.setSort(sort);
rscpImageStatisticsAll.setType(type); rscpImageStatisticsAll.setType(type);
rscpImageStatisticsAll.setDateyear(Integer.valueOf(year));
rscpImageStatisticsBiz.insertSelective(rscpImageStatisticsAll); rscpImageStatisticsBiz.insertSelective(rscpImageStatisticsAll);
} }
...@@ -114,6 +119,6 @@ public class SaticScheduleTask { ...@@ -114,6 +119,6 @@ public class SaticScheduleTask {
}); });
//添加 //添加
insertPart(sort, satelliteType, countYear, RscpImageStatistics.TYPE_YEAR); insertPart(sort, satelliteType, countYear, RscpImageStatistics.TYPE_YEAR, year);
} }
} }
\ No newline at end of file
...@@ -67,7 +67,8 @@ public class UploadService { ...@@ -67,7 +67,8 @@ public class UploadService {
//将文件写入指定位置 //将文件写入指定位置
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath)); FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
String key = "shp:"+ UUIDUtils.generateShortUuid(); String key = "shp:"+ UUIDUtils.generateShortUuid();
String geomJson = ShpToGeojson.shp2geojson(filePath); // String geomJson = ShpToGeojson.shp2geojson(filePath);
String geomJson = ShpToGeojson.shp2OneGeojson(filePath);
redisTemplate.opsForValue().setIfAbsent(key, geomJson); redisTemplate.opsForValue().setIfAbsent(key, geomJson);
// realFileRelPath=xx_url+SystemConfig.XXMP_URL+realFileRelPath; // realFileRelPath=xx_url+SystemConfig.XXMP_URL+realFileRelPath;
......
...@@ -147,6 +147,54 @@ public class ShpToGeojson { ...@@ -147,6 +147,54 @@ public class ShpToGeojson {
// return map; // return map;
// } // }
/**
* shp文件转换geojson数据
* @param shpPath
* @return
*/
public static String shp2OneGeojson(String shpPath){
Map map = new HashMap();
//新建json对象
FeatureJSON fjson = new FeatureJSON();
JSONObject geojsonObject=new JSONObject();
geojsonObject.put("type","FeatureCollection");
Object geometry = new JSONObject();
try{
//获取featurecollection
File file = new File(shpPath);
ShapefileDataStore shpDataStore = null;
shpDataStore = new ShapefileDataStore(file.toURL());
//设置编码
/* Charset charset = Charset.forName("GBK");
shpDataStore.setCharset(charset);*/
String typeName = shpDataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = null;
featureSource = shpDataStore.getFeatureSource (typeName);
SimpleFeatureCollection result = featureSource.getFeatures();
SimpleFeatureIterator itertor = result.features();
//遍历feature转为json对象
while (itertor.hasNext())
{
SimpleFeature feature = itertor.next();
StringWriter writer = new StringWriter();
fjson.writeFeature(feature, writer);
String temp=writer.toString();
geometry = JSONObject.parseObject(temp).getString("geometry");
byte[] b=temp.getBytes("iso8859-1");
temp=new String(b,"gbk");
JSONObject json = JSON.parseObject(temp);
break;
}
itertor.close();
}
catch(Exception e){
map.put("status", "failure");
map.put("message", e.getMessage());
e.printStackTrace();
}
return geometry.toString();
}
/** /**
* shp文件转换geojson数据 * shp文件转换geojson数据
* @param shpPath * @param shpPath
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment