gps新增数据来源

This commit is contained in:
2025-09-11 20:17:47 +08:00
parent 8e84195e98
commit c68d6cb53c
7 changed files with 66 additions and 9 deletions

View File

@ -58,11 +58,11 @@ public class GpsEquipmentController extends BaseController {
/** /**
* 接收设备数据 * 获取用户打卡数据
* @param jsonData * @param jsonData
* @return * @return
*/ */
@PostMapping("/setData") @PostMapping("/setAppData")
public R<Void> setData(@RequestBody String jsonData) { public R<Void> setData(@RequestBody String jsonData) {
log.info("接收设备数据:{}", jsonData); log.info("接收设备数据:{}", jsonData);
gpsEquipmentService.setData(jsonData); gpsEquipmentService.setData(jsonData);

View File

@ -83,5 +83,10 @@ public class GpsEquipment extends BaseEntity {
*/ */
private String alive; private String alive;
/**
* 类型0、设备1、用户
*/
private Integer gpsType;
} }

View File

@ -82,4 +82,9 @@ public class GpsEquipmentBo extends BaseEntity {
private List<String> idList; private List<String> idList;
/**
* 类型0、设备1、用户
*/
private Integer gpsType;
} }

View File

@ -116,4 +116,9 @@ public class GpsEquipmentSonBo extends BaseEntity {
private Long projectId; private Long projectId;
/**
* 类型0、设备1、用户
*/
private Integer gpsType;
} }

View File

@ -101,6 +101,10 @@ public class GpsEquipmentVo implements Serializable {
private Integer type; private Integer type;
/**
* 类型0、设备1、用户
*/
private Integer gpsType;
} }

View File

@ -144,6 +144,7 @@ public class GpsEquipmentServiceImpl extends ServiceImpl<GpsEquipmentMapper, Gps
Map<String, Object> params = bo.getParams(); Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<GpsEquipment> lqw = Wrappers.lambdaQuery(); LambdaQueryWrapper<GpsEquipment> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(GpsEquipment::getId); lqw.orderByDesc(GpsEquipment::getId);
lqw.eq(bo.getGpsType() != null, GpsEquipment::getGpsType, bo.getGpsType());
lqw.eq(bo.getProjectId() != null, GpsEquipment::getProjectId, bo.getProjectId()); lqw.eq(bo.getProjectId() != null, GpsEquipment::getProjectId, bo.getProjectId());
lqw.eq(bo.getUserId() != null, GpsEquipment::getUserId, bo.getUserId()); lqw.eq(bo.getUserId() != null, GpsEquipment::getUserId, bo.getUserId());
lqw.eq(StringUtils.isNotBlank(bo.getClientId()), GpsEquipment::getClientId, bo.getClientId()); lqw.eq(StringUtils.isNotBlank(bo.getClientId()), GpsEquipment::getClientId, bo.getClientId());
@ -209,6 +210,7 @@ public class GpsEquipmentServiceImpl extends ServiceImpl<GpsEquipmentMapper, Gps
GpsEquipment equipment = baseMapper.selectOne(new LambdaQueryWrapper<GpsEquipment>() GpsEquipment equipment = baseMapper.selectOne(new LambdaQueryWrapper<GpsEquipment>()
.eq(GpsEquipment::getClientId, gpsEquipment.getClientId())); .eq(GpsEquipment::getClientId, gpsEquipment.getClientId()));
if(equipment == null){ if(equipment == null){
gpsEquipment.setGpsType(0);
baseMapper.insert(gpsEquipment); baseMapper.insert(gpsEquipment);
} }
JSONObject attributes = jsonObject.getJSONObject("attributes"); JSONObject attributes = jsonObject.getJSONObject("attributes");
@ -437,14 +439,42 @@ public class GpsEquipmentServiceImpl extends ServiceImpl<GpsEquipmentMapper, Gps
@Override @Override
public void setData(String jsonData) { public void setData(String jsonData) {
JSONObject jsonObject = JSONUtil.parseObj(jsonData);
GpsEquipment gpsEquipment = JSONUtil.toBean(jsonObject, GpsEquipment.class);
GpsEquipment equipment = baseMapper.selectOne(new LambdaQueryWrapper<GpsEquipment>()
.eq(GpsEquipment::getProjectId, gpsEquipment.getProjectId())
.eq(GpsEquipment::getUserId, gpsEquipment.getUserId()));
if(equipment == null){
gpsEquipment.setGpsType(1);
// gpsEquipment.setClientId(jsonObject.getStr("deviceId"));
baseMapper.insert(gpsEquipment);
}
GpsEquipmentSonBo gpsEquipmentSonBo = new GpsEquipmentSonBo();
gpsEquipmentSonBo.setLocLatitude(jsonObject.getBigDecimal("latitude"));
gpsEquipmentSonBo.setLocLongitude(jsonObject.getBigDecimal("longitude"));
gpsEquipmentSonBo.setUserId(gpsEquipment.getUserId());
gpsEquipmentSonBo.setProjectId(gpsEquipment.getProjectId());
gpsEquipmentSonBo.setLocAltitude(0L);
gpsEquipmentSonService.insertByBo(gpsEquipmentSonBo);
String pushContent = buildPushMessage(gpsEquipmentSonBo);
// WebSocketUtils.publishAll(pushContent);
// 2. 发布消息根据是否有用户ID决定发送给指定用户或广播
if (equipment != null && equipment.getProjectId() != null) {
// 发送给指定用户equipment.getUserId() // 发送给指定用户equipment.getUserId()
WebSocketMessageDto messageDto = new WebSocketMessageDto(); WebSocketMessageDto messageDto = new WebSocketMessageDto();
messageDto.setMessage(jsonData); messageDto.setMessage(pushContent);
messageDto.setSessionKeys(Collections.singletonList(1897160897167638522L)); messageDto.setSessionKeys(Collections.singletonList(equipment.getProjectId()));
WebSocketUtils.publishMessage(messageDto); WebSocketUtils.publishMessage(messageDto);
} else {
// WebSocketUtils.publishAll(jsonData); // 无用户ID则广播给所有在线客户端
WebSocketUtils.publishAll(pushContent);
}
// 保存到Redis并设置过期监听
updateDeviceAliveStatus(gpsEquipment.getClientId());
} }

View File

@ -65,8 +65,16 @@ public class GpsEquipmentSonServiceImpl extends ServiceImpl<GpsEquipmentSonMappe
*/ */
@Override @Override
public List<GpsEquipmentSonVo> queryList(GpsEquipmentSonBo bo) { public List<GpsEquipmentSonVo> queryList(GpsEquipmentSonBo bo) {
LambdaQueryWrapper<GpsEquipmentSon> lqw = buildQueryWrapper(bo); if (bo.getGpsType() == 0){
return baseMapper.selectVoList(lqw); LambdaQueryWrapper<GpsEquipmentSon> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}else {
return baseMapper.selectVoList(new LambdaQueryWrapper<GpsEquipmentSon>()
.isNull(GpsEquipmentSon::getClientId)
.eq(GpsEquipmentSon::getUserId, bo.getUserId())
.eq(GpsEquipmentSon::getProjectId, bo.getProjectId())
.orderByDesc(GpsEquipmentSon::getCreateTime));
}
} }
private LambdaQueryWrapper<GpsEquipmentSon> buildQueryWrapper(GpsEquipmentSonBo bo) { private LambdaQueryWrapper<GpsEquipmentSon> buildQueryWrapper(GpsEquipmentSonBo bo) {