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()){ for(Map.Entry<DealInfo, Map.Entry<MetaInfo, Coordinate>> entry : results.entrySet()){
XxlJobHelper.log("文件:{} 开始解析", entry.getKey().getFileName()); XxlJobHelper.log("文件:{} 开始解析", entry.getKey().getFileName());
String result; String result;
if(paramInfo.isWind()){ // if(paramInfo.isWind()){
result = dataService.readWindElement(entry); // result = dataService.readWindElement(entry);
}else { // }else {
result = dataService.readRoutineElement(entry, paramInfo.isTemp()); // result = dataService.readRoutineElement(entry, paramInfo.isTemp());
} // }
XxlJobHelper.log("文件:{} 解析完成, 结果:{}", entry.getKey().getFileName(), result); XxlJobHelper.log("文件:{} 解析完成, 结果:{}", entry.getKey().getFileName(), result);
} }
XxlJobHelper.log("文件解析完成"); 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; //package com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain;
//
import java.util.Date; //import java.util.Date;
//
import lombok.Data; //import lombok.Data;
//
/** ///**
* @describe: 雷达 实体类 // * @describe: 雷达 实体类
* @author: xiaowuler // * @author: xiaowuler
* @createTime: 2022-02-28 09:20 // * @createTime: 2022-02-28 09:20
*/ // */
@Data //@Data
public class RadarRead { //public class RadarRead {
private short day = 0; // private short day = 0;
private short hour = 0; // private short hour = 0;
private short year = 0; // private short year = 0;
private short month = 0; // private short month = 0;
private short minute = 0; // private short minute = 0;
private int interval = 0; // private int interval = 0;
private int radarCount = 0; // private int radarCount = 0;
private short zNumGrids = 0; // private short zNumGrids = 0;
private short xNumGrids = 0; // private short xNumGrids = 0;
private short yNumGrids = 0; // private short yNumGrids = 0;
private Date time; // private Date time;
public float yReso; // public float yReso;
public float xReso; // public float xReso;
private float startLon; // private float startLon;
private float startLat; // private float startLat;
private float centerLat; // private float centerLat;
private float centerLon; // private float centerLon;
private String flag = null; // private String flag = null;
private String version = null; // private String version = null;
private char[] reserved = null; // private char[] reserved = null;
private String dataName = null; // private String dataName = null;
private String zoneName = null; // private String zoneName = null;
private byte[] mosaicFlag = null; // private byte[] mosaicFlag = null;
private float[] zHighGrids = null; // private float[] zHighGrids = null;
private float[] radarAltitude = null; // private float[] radarAltitude = null;
private float[] radarLatitude = null; // private float[] radarLatitude = null;
private float[] radarLongitude = null; // private float[] radarLongitude = null;
private String[] radarStationName = null; // private String[] radarStationName = null;
private float[] observerValue = 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; //package com.ping.chuan.ahpmsdp.xxljobexecutor.model.domain;
//
import java.io.BufferedInputStream; //import java.io.BufferedInputStream;
import java.io.FileInputStream; //import java.io.FileInputStream;
import java.io.IOException; //import java.io.IOException;
import java.io.InputStream; //import java.io.InputStream;
import java.nio.ByteBuffer; //import java.nio.ByteBuffer;
import java.nio.CharBuffer; //import java.nio.CharBuffer;
import java.nio.charset.Charset; //import java.nio.charset.Charset;
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.time.ZoneOffset; //import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.Arrays; //import java.util.Arrays;
import java.util.Date; //import java.util.Date;
import java.util.List; //import java.util.List;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
import java.util.stream.IntStream; //import java.util.stream.IntStream;
//
import com.xxl.job.core.util.DateUtil; //import com.xxl.job.core.util.DateUtil;
//
import com.ping.chuan.ahpmsdp.xxljobexecutor.util.ByteUtil; //import com.ping.chuan.ahpmsdp.xxljobexecutor.util.ByteUtil;
//
/** ///**
* @describe: 雷达读取类 // * @describe: 雷达读取类
* @author: xiaowuler // * @author: xiaowuler
* @createTime: 2022-02-28 09:18 // * @createTime: 2022-02-28 09:18
*/ // */
public class RadarReader { //public class RadarReader {
public RadarRead readBinaryFile(String filePath, String time) { // public RadarRead readBinaryFile(String filePath, String time) {
RadarRead radar = new RadarRead(); // RadarRead radar = new RadarRead();
try{ // try{
InputStream inputStream = new FileInputStream(filePath); // InputStream inputStream = new FileInputStream(filePath);
BufferedInputStream bi = new BufferedInputStream(inputStream); // BufferedInputStream bi = new BufferedInputStream(inputStream);
//
radar.setZoneName(readToString(bi, 12)); // radar.setZoneName(readToString(bi, 12));
radar.setDataName(readToString(bi, 38)); // radar.setDataName(readToString(bi, 38));
radar.setFlag(readToString(bi, 8)); // radar.setFlag(readToString(bi, 8));
radar.setVersion(readToString(bi, 8)); // radar.setVersion(readToString(bi, 8));
//
radar.setYear(readToShort(bi)); // radar.setYear(readToShort(bi));
radar.setMonth(readToShort(bi)); // radar.setMonth(readToShort(bi));
radar.setDay(readToShort(bi)); // radar.setDay(readToShort(bi));
radar.setHour(readToShort(bi)); // radar.setHour(readToShort(bi));
radar.setMinute(readToShort(bi)); // radar.setMinute(readToShort(bi));
//
radar.setInterval(readToShort(bi)); // radar.setInterval(readToShort(bi));
radar.setXNumGrids(readToShort(bi)); // radar.setXNumGrids(readToShort(bi));
radar.setYNumGrids(readToShort(bi)); // radar.setYNumGrids(readToShort(bi));
radar.setZNumGrids(readToShort(bi)); // radar.setZNumGrids(readToShort(bi));
LocalDateTime initialTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); // LocalDateTime initialTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
Date date = Date.from(initialTime.atZone(ZoneOffset.systemDefault()).toInstant()); // Date date = Date.from(initialTime.atZone(ZoneOffset.systemDefault()).toInstant());
radar.setTime(DateUtil.addHours(date, 8)); // radar.setTime(DateUtil.addHours(date, 8));
//
radar.setRadarCount(readToInt(bi)); // radar.setRadarCount(readToInt(bi));
//
radar.setStartLon(readToFloat(bi)); // radar.setStartLon(readToFloat(bi));
radar.setStartLat(readToFloat(bi)); // radar.setStartLat(readToFloat(bi));
radar.setCenterLon(readToFloat(bi)); // radar.setCenterLon(readToFloat(bi));
radar.setCenterLat(readToFloat(bi)); // radar.setCenterLat(readToFloat(bi));
radar.setXReso(readToFloat(bi)); // radar.setXReso(readToFloat(bi));
radar.setYReso(readToFloat(bi)); // radar.setYReso(readToFloat(bi));
//
radar.setZHighGrids(setMultipleValue(bi, new float[40])); // radar.setZHighGrids(setMultipleValue(bi, new float[40]));
radar.setRadarStationName(setMultipleValue(bi, new String[20], 16)); // radar.setRadarStationName(setMultipleValue(bi, new String[20], 16));
radar.setRadarLongitude(setMultipleValue(bi, new float[20])); // radar.setRadarLongitude(setMultipleValue(bi, new float[20]));
radar.setRadarLatitude(setMultipleValue(bi, new float[20])); // radar.setRadarLatitude(setMultipleValue(bi, new float[20]));
radar.setRadarAltitude(setMultipleValue(bi, new float[20])); // radar.setRadarAltitude(setMultipleValue(bi, new float[20]));
//
byte[] bytes = new byte[20]; // byte[] bytes = new byte[20];
bi.read(bytes); // bi.read(bytes);
radar.setMosaicFlag(bytes); // radar.setMosaicFlag(bytes);
radar.setReserved(setMultipleValue(bi, 172)); // radar.setReserved(setMultipleValue(bi, 172));
//
radar.setObserverValue(new float[radar.getZNumGrids() * radar.getYNumGrids() * radar.getXNumGrids()]); // radar.setObserverValue(new float[radar.getZNumGrids() * radar.getYNumGrids() * radar.getXNumGrids()]);
readValue(bi, radar, true); // readValue(bi, radar, true);
//
List<Float> targetValues = new ArrayList<>(); // List<Float> targetValues = new ArrayList<>();
List<Float> values = IntStream.range(0, radar.getObserverValue().length) // List<Float> values = IntStream.range(0, radar.getObserverValue().length)
.mapToDouble(i -> radar.getObserverValue()[i]).boxed().map(i -> i.floatValue()).collect(Collectors.toList()); // .mapToDouble(i -> radar.getObserverValue()[i]).boxed().map(i -> i.floatValue()).collect(Collectors.toList());
values = values.subList(305 * radar.getXNumGrids(), 700 * radar.getYNumGrids()); // values = values.subList(305 * radar.getXNumGrids(), 700 * radar.getYNumGrids());
for(int index = 0; index < 395; index++){ // for(int index = 0; index < 395; index++){
int tempIndex = index * radar.getXNumGrids(); // int tempIndex = index * radar.getXNumGrids();
targetValues.addAll(values.subList(tempIndex + 365, tempIndex + 700)); // targetValues.addAll(values.subList(tempIndex + 365, tempIndex + 700));
} // }
//
float[] result = new float[132325]; // float[] result = new float[132325];
for(int index = 0, len = targetValues.size(); index < len; index++){ // for(int index = 0, len = targetValues.size(); index < len; index++){
result[index] = targetValues.get(index); // result[index] = targetValues.get(index);
} // }
//
radar.setObserverValue(result); // radar.setObserverValue(result);
}catch (Exception e) { // }catch (Exception e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
return radar; // return radar;
} // }
//
private void readValue(BufferedInputStream bis, RadarRead radar, boolean flag) throws IOException { // private void readValue(BufferedInputStream bis, RadarRead radar, boolean flag) throws IOException {
if (flag){ // if (flag){
for(int i = 0, len = radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i < len; i++) { // for(int i = 0, len = radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i < len; i++) {
float value = bis.read(); // float value = bis.read();
if (value != 0){ // if (value != 0){
radar.getObserverValue()[i] = (value - 66) / 2; // radar.getObserverValue()[i] = (value - 66) / 2;
continue; // continue;
} // }
radar.getObserverValue()[i] = value; // radar.getObserverValue()[i] = value;
} // }
}else { // }else {
for(int i = 0; i < radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i++) { // for(int i = 0; i < radar.getXNumGrids() * radar.getYNumGrids() * radar.getZNumGrids(); i++) {
int value = readToInt(bis); // int value = readToInt(bis);
radar.getObserverValue()[i] = value / 1; // radar.getObserverValue()[i] = value / 1;
} // }
} // }
} // }
//
private String readToString(BufferedInputStream bi, Integer... infos) throws IOException { // private String readToString(BufferedInputStream bi, Integer... infos) throws IOException {
return convert(bi, (result, info) -> new String(result, info[1], info[2]), infos); // return convert(bi, (result, info) -> new String(result, info[1], info[2]), infos);
} // }
//
private short readToShort(BufferedInputStream bi) throws IOException{ // private short readToShort(BufferedInputStream bi) throws IOException{
return convert(bi, (result, infos) -> ByteUtil.toShort(result), 2); // return convert(bi, (result, infos) -> ByteUtil.toShort(result), 2);
} // }
//
private int readToInt(BufferedInputStream bi) throws IOException { // private int readToInt(BufferedInputStream bi) throws IOException {
return convert(bi, (result, infos) -> ByteUtil.toInt(result), 4); // return convert(bi, (result, infos) -> ByteUtil.toInt(result), 4);
} // }
//
private float readToFloat(BufferedInputStream bi) throws IOException { // private float readToFloat(BufferedInputStream bi) throws IOException {
return convert(bi, (result, infos) -> ByteUtil.toFloat(result), 4); // return convert(bi, (result, infos) -> ByteUtil.toFloat(result), 4);
} // }
//
//
private static <T> T convert(BufferedInputStream bi, Template<T> template, Integer... infos) throws IOException { // private static <T> T convert(BufferedInputStream bi, Template<T> template, Integer... infos) throws IOException {
if (infos.length == 1){ // if (infos.length == 1){
infos = Arrays.copyOf(infos,3); // infos = Arrays.copyOf(infos,3);
infos[1] = 0; // infos[1] = 0;
infos[2] = infos[0]; // infos[2] = infos[0];
} // }
//
byte[] result = new byte[infos[0]]; // byte[] result = new byte[infos[0]];
bi.read(result); // bi.read(result);
return template.readBytes(result, infos); // return template.readBytes(result, infos);
} // }
//
interface Template<T>{ // interface Template<T>{
T readBytes(byte[] result, Integer... infos) throws IOException; // T readBytes(byte[] result, Integer... infos) throws IOException;
} // }
//
private String[] setMultipleValue(BufferedInputStream bi, String[] 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++){ // for (int index = 0, len = result.length; index < len; index++){
result[index] = readToString(bi, infos); // result[index] = readToString(bi, infos);
} // }
return result; // return result;
} // }
//
private float[] setMultipleValue(BufferedInputStream bi, float[] result) throws IOException { // private float[] setMultipleValue(BufferedInputStream bi, float[] result) throws IOException {
for (int index = 0, len = result.length; index < len; index++){ // for (int index = 0, len = result.length; index < len; index++){
result[index] = readToFloat(bi); // result[index] = readToFloat(bi);
} // }
return result; // return result;
} // }
//
private char[] setMultipleValue(BufferedInputStream bis, int length) throws IOException { // private char[] setMultipleValue(BufferedInputStream bis, int length) throws IOException {
byte[] bytes = new byte[length]; // byte[] bytes = new byte[length];
bis.read(bytes); // bis.read(bytes);
//
Charset cs = Charset.forName ("UTF-8"); // Charset cs = Charset.forName ("UTF-8");
ByteBuffer bb = ByteBuffer.allocate (bytes.length); // ByteBuffer bb = ByteBuffer.allocate (bytes.length);
bb.put (bytes); // bb.put (bytes);
bb.flip (); // bb.flip ();
CharBuffer cb = cs.decode (bb); // CharBuffer cb = cs.decode (bb);
return cb.array(); // 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