1、增加广西交设10分钟推送组

This commit is contained in:
weidong 2025-10-05 08:45:25 +08:00
parent 4e50e98a3f
commit 7afdaa29dd

View File

@ -0,0 +1,161 @@
package com.imdroid.beidou_fwd.task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.imdroid.beidou_fwd.entity.XFZData;
import com.imdroid.beidou_fwd.service.TCPClient;
import com.imdroid.common.util.GsonUtil;
import com.imdroid.common.util.NumberUtils;
import com.imdroid.secapi.dto.GnssCalcData;
import com.imdroid.secapi.dto.ResendRecord;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Component
@Configuration
@EnableScheduling
public class GXJS10mForwarder extends GXXfzForwarder{
private final String FORWARDER_NAME = "广西新发展10分钟推送";
@Value("${xfz.server.host}")
private String host;
@Value("${xfz.server.port}")
private int port;
private boolean enabled=true;
@PostConstruct
void registerMe(){
init(FORWARDER_NAME, "TCP "+host+":"+port,1,FWD_DEVICE_ID,10);
xfzTcpClient = new TCPClient();
xfzTcpClient.init(host, port,listener);
if(!enabled) return;
xfzTcpClient.start();
}
/**
* 每半小时转发GNSS解算结果
*/
@Scheduled(cron = "0 0/10 * * * ?") // 每10分钟执行一次
private void forwardGnss() {
if(!enabled) return;
logger.debug("gxjs forwardGnss");
forwardCurrentGnss();
}
@Override
int send(String projectId, List<GnssCalcData> records, LocalDateTime sentTime){
int batchNum = 0;
int sendNum = 0;
if(records.size() == 0) return 0;
XFZData xfzTcpMessage = new XFZData();
xfzTcpMessage.setProjectID(projectId);
xfzTcpMessage.setWorkPointID(projectId);
List<XFZData.Data> dataList = new ArrayList<>(records.size());
xfzTcpMessage.setData(dataList);
for(GnssCalcData locationRecord: records) {
XFZData.Data data = new XFZData.Data();
dataList.add(data);
data.setDataTime(locationRecord.getCreatetime().format(formatter));
data.setDevNum(locationRecord.getDeviceid());
data.setDevtype("GNSS");
// 单位由mm转化为m
data.setX(NumberUtils.scale(locationRecord.getRpose() * 0.001, 5));
data.setY(NumberUtils.scale(locationRecord.getRposn() * 0.001, 5));
data.setZ(NumberUtils.scale(locationRecord.getRposd() * 0.001, 5));
// 经纬度
data.setDevLng(locationRecord.getR9250e());
data.setDevLat(locationRecord.getR9250n());
if(projectId!=null && projectId.equals("20257071")) {
//倾角
XFZData.Data data2 = new XFZData.Data();
dataList.add(data2);
data2.setDataTime(locationRecord.getCreatetime().format(formatter));
data2.setDevNum(locationRecord.getDeviceid() + "_qj");
data2.setDevtype("InclinoMeter");
// 角度
data2.setX(NumberUtils.scale(locationRecord.getAuxe(), 3));
data2.setY(NumberUtils.scale(locationRecord.getAuxn(), 3));
data2.setZ(NumberUtils.scale(locationRecord.getAuxd(), 3));
// 经纬度
data2.setDevLng(locationRecord.getR9250e());
data2.setDevLat(locationRecord.getR9250n());
}
// 发送
batchNum++;
if(batchNum==20){
String json = "#" + GsonUtil.toJson(xfzTcpMessage) + "!";
//logger.debug("project {}: forwad {} gnss records to {}",projectId, dataList.size(),fwdGroupId);
//logger.debug(json);
try {
listener.clear();
xfzTcpClient.writeAndFlush(json);
//等待应答
if(checkResult()) sendNum += batchNum;
} catch (Exception e1) {
logger.error(e1.toString());
}
batchNum = 0;
dataList.clear();
}
}
if(batchNum>0){
String json = "#" + GsonUtil.toJson(xfzTcpMessage) + "!";
logger.debug("project {}: forwad {} gnss records to {}",projectId, dataList.size(),fwdGroupId);
logger.debug(json);
try {
listener.clear();
xfzTcpClient.writeAndFlush(json);
//等待应答
if(checkResult()) sendNum += batchNum;
} catch (Exception e1) {
logger.error(e1.toString());
}
dataList.clear();
}
return sendNum;
}
@Override
void forwardHistoryGnss(){
// 1.从转发记录表里检索待补传记录时间表含设备Id时间段
QueryWrapper<ResendRecord> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("fwd_group_id",fwdGroupId);
queryWrapper.eq("state",ResendRecord.STATE_BREAK_POINT);
queryWrapper.ge("createtime", LocalDateTime.now().minusDays(30));
List<ResendRecord> resendRecordsList = resendRecordMapper.selectList(queryWrapper);
if(resendRecordsList!=null && resendRecordsList.size()>0){
//修改状态
UpdateWrapper<ResendRecord> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("fwd_group_id",fwdGroupId);
updateWrapper.eq("state",ResendRecord.STATE_BREAK_POINT);
updateWrapper.ge("createtime", LocalDateTime.now().minusDays(30));
updateWrapper.set("state",ResendRecord.STATE_FWDING);
int updateNum = resendRecordMapper.update(null, updateWrapper);
logger.debug("{} forward history records: {}, update {}",fwdGroupId, resendRecordsList.size(),updateNum);
// 2.检索这个这个时间段的解算结果如果有数据则单个终端转发标志记录为已补传
for(ResendRecord record:resendRecordsList){
if(record.getProjectid()!=null)
logger.debug("{} forward history {}",fwdGroupId, record.getProjectid());
forwardBatchGnssRecords(record);
}
}
}
}