Browse Source

modify some codes

master
xiaowuler 3 years ago
parent
commit
10857bdae2
  1. 10
      04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/jobhandler/TianQingRadarDataHandler.java
  2. 86
      04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/model/domain/RadarRead.java
  3. 350
      04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/model/domain/RadarReader.java
  4. 11
      04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/IRadarService.java
  5. 17
      04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/RadarService.java

10
04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/jobhandler/TianQingRadarDataHandler.java

@ -81,11 +81,11 @@ public class TianQingRadarDataHandler {
for(Map.Entry<DealInfo, Map.Entry<MetaInfo, Coordinate>> entry : results.entrySet()){
XxlJobHelper.log("文件:{} 开始解析", entry.getKey().getFileName());
String result;
if(paramInfo.isWind()){
result = dataService.readWindElement(entry);
}else {
result = dataService.readRoutineElement(entry, paramInfo.isTemp());
}
// if(paramInfo.isWind()){
// result = dataService.readWindElement(entry);
// }else {
// result = dataService.readRoutineElement(entry, paramInfo.isTemp());
// }
XxlJobHelper.log("文件:{} 解析完成, 结果:{}", entry.getKey().getFileName(), result);
}
XxlJobHelper.log("文件解析完成");

86
04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/model/domain/RadarRead.java

@ -1,43 +1,43 @@
package com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain;
import java.util.Date;
import lombok.Data;
/**
* @describe: 雷达 实体类
* @author: xiaowuler
* @createTime: 2022-02-28 09:20
*/
@Data
public class RadarRead {
private short day = 0;
private short hour = 0;
private short year = 0;
private short month = 0;
private short minute = 0;
private int interval = 0;
private int radarCount = 0;
private short zNumGrids = 0;
private short xNumGrids = 0;
private short yNumGrids = 0;
private Date time;
public float yReso;
public float xReso;
private float startLon;
private float startLat;
private float centerLat;
private float centerLon;
private String flag = null;
private String version = null;
private char[] reserved = null;
private String dataName = null;
private String zoneName = null;
private byte[] mosaicFlag = null;
private float[] zHighGrids = null;
private float[] radarAltitude = null;
private float[] radarLatitude = null;
private float[] radarLongitude = null;
private String[] radarStationName = null;
private float[] observerValue = null;
}
//package com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain;
//
//import java.util.Date;
//
//import lombok.Data;
//
///**
// * @describe: 雷达 实体类
// * @author: xiaowuler
// * @createTime: 2022-02-28 09:20
// */
//@Data
//public class RadarRead {
// private short day = 0;
// private short hour = 0;
// private short year = 0;
// private short month = 0;
// private short minute = 0;
// private int interval = 0;
// private int radarCount = 0;
// private short zNumGrids = 0;
// private short xNumGrids = 0;
// private short yNumGrids = 0;
// private Date time;
// public float yReso;
// public float xReso;
// private float startLon;
// private float startLat;
// private float centerLat;
// private float centerLon;
// private String flag = null;
// private String version = null;
// private char[] reserved = null;
// private String dataName = null;
// private String zoneName = null;
// private byte[] mosaicFlag = null;
// private float[] zHighGrids = null;
// private float[] radarAltitude = null;
// private float[] radarLatitude = null;
// private float[] radarLongitude = null;
// private String[] radarStationName = null;
// private float[] observerValue = null;
//}

350
04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/model/domain/RadarReader.java

@ -1,175 +1,175 @@
package com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.xxl.job.core.util.DateUtil;
import com.ping.chuan.ahpmsdp.xxljobexecutor.util.ByteUtil;
/**
* @describe: 雷达读取类
* @author: xiaowuler
* @createTime: 2022-02-28 09:18
*/
public class RadarReader {
public RadarRead readBinaryFile(String filePath, String time) {
RadarRead radar = new RadarRead();
try{
InputStream inputStream = new FileInputStream(filePath);
BufferedInputStream bi = new BufferedInputStream(inputStream);
radar.setZoneName(readToString(bi, 12));
radar.setDataName(readToString(bi, 38));
radar.setFlag(readToString(bi, 8));
radar.setVersion(readToString(bi, 8));
radar.setYear(readToShort(bi));
radar.setMonth(readToShort(bi));
radar.setDay(readToShort(bi));
radar.setHour(readToShort(bi));
radar.setMinute(readToShort(bi));
radar.setInterval(readToShort(bi));
radar.setXNumGrids(readToShort(bi));
radar.setYNumGrids(readToShort(bi));
radar.setZNumGrids(readToShort(bi));
LocalDateTime initialTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
Date date = Date.from(initialTime.atZone(ZoneOffset.systemDefault()).toInstant());
radar.setTime(DateUtil.addHours(date, 8));
radar.setRadarCount(readToInt(bi));
radar.setStartLon(readToFloat(bi));
radar.setStartLat(readToFloat(bi));
radar.setCenterLon(readToFloat(bi));
radar.setCenterLat(readToFloat(bi));
radar.setXReso(readToFloat(bi));
radar.setYReso(readToFloat(bi));
radar.setZHighGrids(setMultipleValue(bi, new float[40]));
radar.setRadarStationName(setMultipleValue(bi, new String[20], 16));
radar.setRadarLongitude(setMultipleValue(bi, new float[20]));
radar.setRadarLatitude(setMultipleValue(bi, new float[20]));
radar.setRadarAltitude(setMultipleValue(bi, new float[20]));
byte[] bytes = new byte[20];
bi.read(bytes);
radar.setMosaicFlag(bytes);
radar.setReserved(setMultipleValue(bi, 172));
radar.setObserverValue(new float[radar.getZNumGrids() * radar.getYNumGrids() * radar.getXNumGrids()]);
readValue(bi, radar, true);
List<Float> targetValues = new ArrayList<>();
List<Float> values = IntStream.range(0, radar.getObserverValue().length)
.mapToDouble(i -> radar.getObserverValue()[i]).boxed().map(i -> i.floatValue()).collect(Collectors.toList());
values = values.subList(305 * radar.getXNumGrids(), 700 * radar.getYNumGrids());
for(int index = 0; index < 395; index++){
int tempIndex = index * radar.getXNumGrids();
targetValues.addAll(values.subList(tempIndex + 365, tempIndex + 700));
}
float[] result = new float[132325];
for(int index = 0, len = targetValues.size(); index < len; index++){
result[index] = targetValues.get(index);
}
radar.setObserverValue(result);
}catch (Exception e) {
throw new RuntimeException(e);
}
return radar;
}
private void readValue(BufferedInputStream bis, RadarRead radar, boolean flag) throws IOException {
if (flag){
for(int i = 0, len = radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i < len; i++) {
float value = bis.read();
if (value != 0){
radar.getObserverValue()[i] = (value - 66) / 2;
continue;
}
radar.getObserverValue()[i] = value;
}
}else {
for(int i = 0; i < radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i++) {
int value = readToInt(bis);
radar.getObserverValue()[i] = value / 1;
}
}
}
private String readToString(BufferedInputStream bi, Integer... infos) throws IOException {
return convert(bi, (result, info) -> new String(result, info[1], info[2]), infos);
}
private short readToShort(BufferedInputStream bi) throws IOException{
return convert(bi, (result, infos) -> ByteUtil.toShort(result), 2);
}
private int readToInt(BufferedInputStream bi) throws IOException {
return convert(bi, (result, infos) -> ByteUtil.toInt(result), 4);
}
private float readToFloat(BufferedInputStream bi) throws IOException {
return convert(bi, (result, infos) -> ByteUtil.toFloat(result), 4);
}
private static <T> T convert(BufferedInputStream bi, Template<T> template, Integer... infos) throws IOException {
if (infos.length == 1){
infos = Arrays.copyOf(infos,3);
infos[1] = 0;
infos[2] = infos[0];
}
byte[] result = new byte[infos[0]];
bi.read(result);
return template.readBytes(result, infos);
}
interface Template<T>{
T readBytes(byte[] result, Integer... infos) throws IOException;
}
private String[] setMultipleValue(BufferedInputStream bi, String[] result, Integer... infos) throws IOException {
for (int index = 0, len = result.length; index < len; index++){
result[index] = readToString(bi, infos);
}
return result;
}
private float[] setMultipleValue(BufferedInputStream bi, float[] result) throws IOException {
for (int index = 0, len = result.length; index < len; index++){
result[index] = readToFloat(bi);
}
return result;
}
private char[] setMultipleValue(BufferedInputStream bis, int length) throws IOException {
byte[] bytes = new byte[length];
bis.read(bytes);
Charset cs = Charset.forName ("UTF-8");
ByteBuffer bb = ByteBuffer.allocate (bytes.length);
bb.put (bytes);
bb.flip ();
CharBuffer cb = cs.decode (bb);
return cb.array();
}
}
//package com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain;
//
//import java.io.BufferedInputStream;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.nio.ByteBuffer;
//import java.nio.CharBuffer;
//import java.nio.charset.Charset;
//import java.time.LocalDateTime;
//import java.time.ZoneOffset;
//import java.time.format.DateTimeFormatter;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Date;
//import java.util.List;
//import java.util.stream.Collectors;
//import java.util.stream.IntStream;
//
//import com.xxl.job.core.util.DateUtil;
//
//import com.ping.chuan.ahpmsdp.xxljobexecutor.util.ByteUtil;
//
///**
// * @describe: 雷达读取类
// * @author: xiaowuler
// * @createTime: 2022-02-28 09:18
// */
//public class RadarReader {
// public RadarRead readBinaryFile(String filePath, String time) {
// RadarRead radar = new RadarRead();
// try{
// InputStream inputStream = new FileInputStream(filePath);
// BufferedInputStream bi = new BufferedInputStream(inputStream);
//
// radar.setZoneName(readToString(bi, 12));
// radar.setDataName(readToString(bi, 38));
// radar.setFlag(readToString(bi, 8));
// radar.setVersion(readToString(bi, 8));
//
// radar.setYear(readToShort(bi));
// radar.setMonth(readToShort(bi));
// radar.setDay(readToShort(bi));
// radar.setHour(readToShort(bi));
// radar.setMinute(readToShort(bi));
//
// radar.setInterval(readToShort(bi));
// radar.setXNumGrids(readToShort(bi));
// radar.setYNumGrids(readToShort(bi));
// radar.setZNumGrids(readToShort(bi));
// LocalDateTime initialTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
// Date date = Date.from(initialTime.atZone(ZoneOffset.systemDefault()).toInstant());
// radar.setTime(DateUtil.addHours(date, 8));
//
// radar.setRadarCount(readToInt(bi));
//
// radar.setStartLon(readToFloat(bi));
// radar.setStartLat(readToFloat(bi));
// radar.setCenterLon(readToFloat(bi));
// radar.setCenterLat(readToFloat(bi));
// radar.setXReso(readToFloat(bi));
// radar.setYReso(readToFloat(bi));
//
// radar.setZHighGrids(setMultipleValue(bi, new float[40]));
// radar.setRadarStationName(setMultipleValue(bi, new String[20], 16));
// radar.setRadarLongitude(setMultipleValue(bi, new float[20]));
// radar.setRadarLatitude(setMultipleValue(bi, new float[20]));
// radar.setRadarAltitude(setMultipleValue(bi, new float[20]));
//
// byte[] bytes = new byte[20];
// bi.read(bytes);
// radar.setMosaicFlag(bytes);
// radar.setReserved(setMultipleValue(bi, 172));
//
// radar.setObserverValue(new float[radar.getZNumGrids() * radar.getYNumGrids() * radar.getXNumGrids()]);
// readValue(bi, radar, true);
//
// List<Float> targetValues = new ArrayList<>();
// List<Float> values = IntStream.range(0, radar.getObserverValue().length)
// .mapToDouble(i -> radar.getObserverValue()[i]).boxed().map(i -> i.floatValue()).collect(Collectors.toList());
// values = values.subList(305 * radar.getXNumGrids(), 700 * radar.getYNumGrids());
// for(int index = 0; index < 395; index++){
// int tempIndex = index * radar.getXNumGrids();
// targetValues.addAll(values.subList(tempIndex + 365, tempIndex + 700));
// }
//
// float[] result = new float[132325];
// for(int index = 0, len = targetValues.size(); index < len; index++){
// result[index] = targetValues.get(index);
// }
//
// radar.setObserverValue(result);
// }catch (Exception e) {
// throw new RuntimeException(e);
// }
// return radar;
// }
//
// private void readValue(BufferedInputStream bis, RadarRead radar, boolean flag) throws IOException {
// if (flag){
// for(int i = 0, len = radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i < len; i++) {
// float value = bis.read();
// if (value != 0){
// radar.getObserverValue()[i] = (value - 66) / 2;
// continue;
// }
// radar.getObserverValue()[i] = value;
// }
// }else {
// for(int i = 0; i < radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i++) {
// int value = readToInt(bis);
// radar.getObserverValue()[i] = value / 1;
// }
// }
// }
//
// private String readToString(BufferedInputStream bi, Integer... infos) throws IOException {
// return convert(bi, (result, info) -> new String(result, info[1], info[2]), infos);
// }
//
// private short readToShort(BufferedInputStream bi) throws IOException{
// return convert(bi, (result, infos) -> ByteUtil.toShort(result), 2);
// }
//
// private int readToInt(BufferedInputStream bi) throws IOException {
// return convert(bi, (result, infos) -> ByteUtil.toInt(result), 4);
// }
//
// private float readToFloat(BufferedInputStream bi) throws IOException {
// return convert(bi, (result, infos) -> ByteUtil.toFloat(result), 4);
// }
//
//
// private static <T> T convert(BufferedInputStream bi, Template<T> template, Integer... infos) throws IOException {
// if (infos.length == 1){
// infos = Arrays.copyOf(infos,3);
// infos[1] = 0;
// infos[2] = infos[0];
// }
//
// byte[] result = new byte[infos[0]];
// bi.read(result);
// return template.readBytes(result, infos);
// }
//
// interface Template<T>{
// T readBytes(byte[] result, Integer... infos) throws IOException;
// }
//
// private String[] setMultipleValue(BufferedInputStream bi, String[] result, Integer... infos) throws IOException {
// for (int index = 0, len = result.length; index < len; index++){
// result[index] = readToString(bi, infos);
// }
// return result;
// }
//
// private float[] setMultipleValue(BufferedInputStream bi, float[] result) throws IOException {
// for (int index = 0, len = result.length; index < len; index++){
// result[index] = readToFloat(bi);
// }
// return result;
// }
//
// private char[] setMultipleValue(BufferedInputStream bis, int length) throws IOException {
// byte[] bytes = new byte[length];
// bis.read(bytes);
//
// Charset cs = Charset.forName ("UTF-8");
// ByteBuffer bb = ByteBuffer.allocate (bytes.length);
// bb.put (bytes);
// bb.flip ();
// CharBuffer cb = cs.decode (bb);
// return cb.array();
// }
//}

11
04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/IRadarService.java

@ -0,0 +1,11 @@
package com.ping.chuan.ahpmsdp.xxljobexecutor.service;
import com.ping.chuan.ahpmsdp.xxljobexecutor.model.dao.DealInfo;
import com.ping.chuan.ahpmsdp.xxljobexecutor.model.dao.MetaInfo;
import com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain.Coordinate;
import java.util.Map;
public interface IRadarService {
void read(Map.Entry<DealInfo, Map.Entry<MetaInfo, Coordinate>> entry);
}

17
04.系统编码/01.xxl-job/xxl-job-executor/src/main/java/com/ping/chuan/ahpmsdp/xxljobexecutor/service/impl/RadarService.java

@ -0,0 +1,17 @@
package com.ping.chuan.ahpmsdp.xxljobexecutor.service.impl;
import com.ping.chuan.ahpmsdp.xxljobexecutor.model.dao.DealInfo;
import com.ping.chuan.ahpmsdp.xxljobexecutor.model.dao.MetaInfo;
import com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain.Coordinate;
import com.ping.chuan.ahpmsdp.xxljobexecutor.service.IRadarService;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class RadarService implements IRadarService {
@Override
public void read(Map.Entry<DealInfo, Map.Entry<MetaInfo, Coordinate>> entry) {
RadarReader radarReader = new RadarReader();
}
}
Loading…
Cancel
Save