gps新增数据来源
This commit is contained in:
@ -58,11 +58,11 @@ public class GpsEquipmentController extends BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* 接收设备数据
|
||||
* 获取用户打卡数据
|
||||
* @param jsonData
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/setData")
|
||||
@PostMapping("/setAppData")
|
||||
public R<Void> setData(@RequestBody String jsonData) {
|
||||
log.info("接收设备数据:{}", jsonData);
|
||||
gpsEquipmentService.setData(jsonData);
|
||||
|
@ -83,5 +83,10 @@ public class GpsEquipment extends BaseEntity {
|
||||
*/
|
||||
private String alive;
|
||||
|
||||
/**
|
||||
* 类型(0、设备,1、用户)
|
||||
*/
|
||||
private Integer gpsType;
|
||||
|
||||
|
||||
}
|
||||
|
@ -82,4 +82,9 @@ public class GpsEquipmentBo extends BaseEntity {
|
||||
|
||||
private List<String> idList;
|
||||
|
||||
/**
|
||||
* 类型(0、设备,1、用户)
|
||||
*/
|
||||
private Integer gpsType;
|
||||
|
||||
}
|
||||
|
@ -116,4 +116,9 @@ public class GpsEquipmentSonBo extends BaseEntity {
|
||||
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 类型(0、设备,1、用户)
|
||||
*/
|
||||
private Integer gpsType;
|
||||
|
||||
}
|
||||
|
@ -101,6 +101,10 @@ public class GpsEquipmentVo implements Serializable {
|
||||
|
||||
|
||||
private Integer type;
|
||||
/**
|
||||
* 类型(0、设备,1、用户)
|
||||
*/
|
||||
private Integer gpsType;
|
||||
|
||||
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ public class GpsEquipmentServiceImpl extends ServiceImpl<GpsEquipmentMapper, Gps
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<GpsEquipment> lqw = Wrappers.lambdaQuery();
|
||||
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.getUserId() != null, GpsEquipment::getUserId, bo.getUserId());
|
||||
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>()
|
||||
.eq(GpsEquipment::getClientId, gpsEquipment.getClientId()));
|
||||
if(equipment == null){
|
||||
gpsEquipment.setGpsType(0);
|
||||
baseMapper.insert(gpsEquipment);
|
||||
}
|
||||
JSONObject attributes = jsonObject.getJSONObject("attributes");
|
||||
@ -437,14 +439,42 @@ public class GpsEquipmentServiceImpl extends ServiceImpl<GpsEquipmentMapper, Gps
|
||||
@Override
|
||||
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())
|
||||
WebSocketMessageDto messageDto = new WebSocketMessageDto();
|
||||
messageDto.setMessage(jsonData);
|
||||
messageDto.setSessionKeys(Collections.singletonList(1897160897167638522L));
|
||||
messageDto.setMessage(pushContent);
|
||||
messageDto.setSessionKeys(Collections.singletonList(equipment.getProjectId()));
|
||||
WebSocketUtils.publishMessage(messageDto);
|
||||
|
||||
// WebSocketUtils.publishAll(jsonData);
|
||||
|
||||
} else {
|
||||
// 无用户ID则广播给所有在线客户端
|
||||
WebSocketUtils.publishAll(pushContent);
|
||||
}
|
||||
// 保存到Redis并设置过期监听
|
||||
updateDeviceAliveStatus(gpsEquipment.getClientId());
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,8 +65,16 @@ public class GpsEquipmentSonServiceImpl extends ServiceImpl<GpsEquipmentSonMappe
|
||||
*/
|
||||
@Override
|
||||
public List<GpsEquipmentSonVo> queryList(GpsEquipmentSonBo bo) {
|
||||
LambdaQueryWrapper<GpsEquipmentSon> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
if (bo.getGpsType() == 0){
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user