增加补传推送第三方功能

This commit is contained in:
weidong 2023-12-11 11:17:12 +08:00
parent b5946d0f03
commit 02f2196ebe
9 changed files with 154 additions and 6 deletions

View File

@ -0,0 +1,30 @@
package com.imdroid.secapi.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
/**
* GNSS收发统计消息每个工作周期结束的时候统计一次
*
* @author LiGang
*/
@Data
@TableName(value = "fwdrecords")
public class FwdRecord {
public static final short STATE_READY = 1;
public static final short STATE_UPLOADING = 2;
public static final short STATE_UPLOAD_DONE = 3;
public static final short STATE_FWD_DONE = 0;
@TableId(value = "id", type = IdType.AUTO)
Long id;
Integer tenantid;
String deviceid;
String project_id;
LocalDateTime starttime;
LocalDateTime endtime;
Short state;
}

View File

@ -0,0 +1,8 @@
package com.imdroid.secapi.dto;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface FwdRecordMapper extends BaseMapper<FwdRecord> {
}

View File

@ -1,5 +1,7 @@
package com.imdroid.sideslope.calc;
import com.imdroid.secapi.dto.FwdRecord;
import com.imdroid.secapi.dto.FwdRecordMapper;
import com.imdroid.sideslope.message.BaseMessage;
import com.imdroid.sideslope.message.D341LocationMessage;
import com.imdroid.sideslope.message.D342LocationMessage;
@ -17,11 +19,16 @@ import java.util.concurrent.ConcurrentHashMap;
public class MultiLineGNSSCalcService {
private static final Logger logger = LoggerFactory.getLogger(SingleLineGNSSCalcService.class);
private static final Map<String, LocalDateTime> deviceMap = new ConcurrentHashMap<>();
private static final Map<String, FwdRecord> fwdRecordMap = new ConcurrentHashMap<>();
@Autowired
SingleLineGNSSCalcService calcService;
@Autowired
private GNSSDeviceLocationRecordService dataPersistService;
@Autowired
private FwdRecordMapper fwdRecordMapper;
public void calc(D342LocationMessage d342Message){
// 如果时间跨度大于1分钟或者不含d341则计算平滑值
String deviceId = d342Message.getId();
@ -30,12 +37,25 @@ public class MultiLineGNSSCalcService {
int d341Count = d342Message.getMessageList().size();
if(msgTime!=null) logger.info("proc D342: "+msgTime+" D341 num: "+d341Count);
// 如果序号为0则创建一条转发记录表
if(d342Message.getSeq() == 0){
createFwdReord(d342Message);
}
if(lastDate != null){
if(d341Count == 0){
// 计算上轮结果
calcService.calSingleDone(deviceId, d342Message.getTenantId(),lastDate);
// 重算最近的
dataPersistService.updateRb562(deviceId,lastDate);
// 记录转发表更新为upload done
FwdRecord fwdRecord = fwdRecordMap.get(deviceId);
if(fwdRecord != null){
fwdRecord.setEndtime(lastDate);
fwdRecord.setState(FwdRecord.STATE_UPLOAD_DONE);
fwdRecordMapper.insert(fwdRecord);
fwdRecordMap.remove(deviceId);
}
}
else if(msgTime!=null && msgTime.isAfter(lastDate.plusMinutes(1))){
// 计算上轮结果
@ -51,4 +71,16 @@ public class MultiLineGNSSCalcService {
}
}
void createFwdReord(D342LocationMessage d342Message){
String deviceId = d342Message.getId();
// 查找这个设备是否有项目号
FwdRecord fwdRecord = new FwdRecord();
fwdRecord.setDeviceid(deviceId);
fwdRecord.setTenantid(d342Message.getTenantId());
fwdRecord.setProject_id(d342Message.getProjectId());
fwdRecord.setState(FwdRecord.STATE_UPLOADING);
fwdRecord.setStarttime(d342Message.getOriginalTime());
fwdRecordMap.put(deviceId, fwdRecord);
}
}

View File

@ -29,6 +29,7 @@ public class D342LocationMessageExecutor implements Executor<D342LocationMessage
Device device = deviceService.findByDeviceId(message.getId());
if(device == null) return null;
message.setTenantId(device.getTenantId());
message.setProjectId(device.getProjectId());
ThreadManager.getFixedThreadPool().submit(() -> {
gnssCalcService.calc(message);

View File

@ -1,10 +1,7 @@
package com.imdroid.sideslope.fwd;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imdroid.secapi.dto.GnssCalcData;
import com.imdroid.secapi.dto.GnssCalcDataMapper;
import com.imdroid.secapi.dto.GnssDevice;
import com.imdroid.secapi.dto.GnssDeviceMapper;
import com.imdroid.secapi.dto.*;
import com.imdroid.sideslope.util.GsonUtil;
import com.imdroid.sideslope.util.NumberUtils;
import org.slf4j.Logger;
@ -40,6 +37,11 @@ public class ForwardGnssTask {
private GnssCalcDataMapper gnssDataMapper;
@Autowired
private XFZTcpClient xfzTcpClient;
@Autowired
private FwdRecordMapper fwdRecordsMapper;
final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/**
* 每半小时转发GNSS解算结果
*/
@ -50,11 +52,28 @@ public class ForwardGnssTask {
forwardGnssToXFZ(1);
}
@Scheduled(cron = "0 10 * * * ?") // 每小时的10分钟执行一次
//@Scheduled(cron = "0 40 * * * ?") // 每小时的40分钟执行一次
@Scheduled(cron = "0 0/20 * * * ?") // 每20分钟执行一次
private void forwardHistoryGnss() {
// 1.从转发记录表里检索待补传记录时间表含设备Id时间段
QueryWrapper<FwdRecord> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenantid",1);
queryWrapper.eq("state",FwdRecord.STATE_UPLOAD_DONE);
List<FwdRecord> fwdRecordsList = fwdRecordsMapper.selectList(queryWrapper);
// 2.检索这个这个时间段的解算结果如果有数据则单个终端转发标志记录为已补传
//forwardGnssToXFZ(1);
for(FwdRecord fwdRecord:fwdRecordsList){
QueryWrapper<GnssCalcData> calcDataQueryWrapper = new QueryWrapper<>();
calcDataQueryWrapper.eq("deviceid", fwdRecord.getDeviceid());
calcDataQueryWrapper.ge("createtime", fwdRecord.getStarttime());
calcDataQueryWrapper.le("createtime", fwdRecord.getEndtime());
calcDataQueryWrapper.orderByAsc("createtime");
List<GnssCalcData> calcDataList = gnssDataMapper.selectList(calcDataQueryWrapper);
// 推送记录
BatchToXFZ(fwdRecord.getProject_id(),calcDataList);
// 记录推送结果
fwdRecord.setState(FwdRecord.STATE_FWD_DONE);
fwdRecordsMapper.updateById(fwdRecord);
}
}
private void forwardGnssToXFZ(int tenantId) {
@ -126,4 +145,43 @@ public class ForwardGnssTask {
logger.info(json);
}
void BatchToXFZ(String projectId, List<GnssCalcData> records){
if(records.size() == 0) return;
LocalDateTime lastTime = records.get(0).getCreatetime();
for(GnssCalcData calcData:records){
if(calcData.getEnabled() &&
calcData.getCreatetime().isAfter(lastTime.plusMinutes(30))){
// 推送
SendOneToXFZ(projectId, calcData,lastTime.format(dateFormatter));
lastTime = calcData.getCreatetime();
}
}
}
void SendOneToXFZ(String projectId, GnssCalcData calcData, String sendTime){
XFZTcpMessage xfzTcpMessage = new XFZTcpMessage();
xfzTcpMessage.setProjectID(projectId);
xfzTcpMessage.setWorkPointID(projectId);
List<XFZTcpMessage.Data> dataList = new ArrayList<>();
xfzTcpMessage.setData(dataList);
XFZTcpMessage.Data data = new XFZTcpMessage.Data();
dataList.add(data);
data.setDataTime(sendTime);
data.setDevNum("1");
data.setDevtype("GNSS");
// 单位由mm转化为m
data.setX(NumberUtils.scale(calcData.getRb562e() * 0.001, 5));
data.setY(NumberUtils.scale(calcData.getRb562n() * 0.001, 5));
data.setZ(NumberUtils.scale(calcData.getRb562d() * 0.001, 5));
String json = GsonUtil.toJson(xfzTcpMessage);
xfzTcpClient.writeAndFlush(json);
logger.info("project " + projectId + ": push one calculation result to XFZ");
logger.info(json);
}
}

View File

@ -17,6 +17,7 @@ import java.util.List;
public class D342LocationMessage extends BaseMessage {
LocalDateTime originalTime; //补传前记录的时间
List<BaseMessage> messageList = new ArrayList<>();
String projectId;
@Override
public void decodeBody(ByteBuf src) {
// d3 51 length(2048+6) device_id(4bytes) seq(2bytes) data

View File

@ -43,6 +43,7 @@ public class DbDeviceServiceImpl implements DeviceService {
device.setDeviceType(gnssDevice.getDevicetype());
device.setParentId(gnssDevice.getParentid());
device.setName(gnssDevice.getName());
device.setProjectId(gnssDevice.getProject_id());
return device;
}
@ -58,6 +59,7 @@ public class DbDeviceServiceImpl implements DeviceService {
device.setDeviceType(gnssDevice.getDevicetype());
device.setParentId(gnssDevice.getParentid());
device.setName(gnssDevice.getName());
device.setProjectId(gnssDevice.getProject_id());
deviceList.add(device);
}
return deviceList;

View File

@ -27,6 +27,7 @@ public class Device {
private String deviceId;
private String parentId;
private String projectId;
private Integer deviceType;

View File

@ -234,3 +234,18 @@ CREATE TABLE IF NOT EXISTS `warningcfg` (
`value` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/***
id
state状态值1230
*/
CREATE TABLE IF NOT EXISTS `fwdrecords` (
`id` bigint AUTO_INCREMENT,
`tenantid` int NOT NULL,
`deviceid` varchar(20) NOT NULL,
`project_id` varchar(64) DEFAULT NULL COMMENT '项目id',
`starttime` datetime DEFAULT NULL,
`endtime` datetime DEFAULT NULL,
`state` smallint DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;