forked from dyf/fys-Multi-tenant
web端控制中心2
This commit is contained in:
@ -1,16 +1,19 @@
|
||||
package com.fuyuanshen.web.service.device;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
||||
import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
||||
import com.fuyuanshen.app.mapper.AppPersonnelInfoRecordsMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.*;
|
||||
@ -50,6 +53,7 @@ public class DeviceBJQBizService {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
||||
private final AppPersonnelInfoRecordsMapper appPersonnelInfoRecordsMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
private final MqttGateway mqttGateway;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
@ -242,11 +246,18 @@ public class DeviceBJQBizService {
|
||||
map.put("instruct", intData);
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
|
||||
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", JSON.toJSONString(bo), AppLoginHelper.getUserId());
|
||||
String logContent = "单位:"+bo.getUnitName()+",职位:"+bo.getPosition()+",姓名:"+bo.getName()+",ID:"+bo.getCode();
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", logContent, AppLoginHelper.getUserId());
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
||||
appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
||||
|
||||
AppPersonnelInfoRecords appPersonnelInfoRecords = new AppPersonnelInfoRecords();
|
||||
BeanUtil.copyProperties(appPersonnelInfo, appPersonnelInfoRecords);
|
||||
appPersonnelInfoRecords.setId(null);
|
||||
appPersonnelInfoRecords.setPersonnelId(appPersonnelInfo.getId());
|
||||
|
||||
appPersonnelInfoRecordsMapper.insert(appPersonnelInfoRecords);
|
||||
} else {
|
||||
UpdateWrapper<AppPersonnelInfo> uw = new UpdateWrapper<>();
|
||||
uw.eq("device_id", deviceId)
|
||||
@ -254,10 +265,52 @@ public class DeviceBJQBizService {
|
||||
.set("position", bo.getPosition())
|
||||
.set("unit_name", bo.getUnitName())
|
||||
.set("code", bo.getCode());
|
||||
return appPersonnelInfoMapper.update(null, uw) > 0;
|
||||
appPersonnelInfoMapper.update(null, uw);
|
||||
|
||||
AppPersonnelInfoVo personnelInfoVo = appPersonnelInfoVos.get(0);
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
AppPersonnelInfoRecords appPersonnelInfoRecords = new AppPersonnelInfoRecords();
|
||||
BeanUtil.copyProperties(appPersonnelInfo, appPersonnelInfoRecords);
|
||||
appPersonnelInfoRecords.setId(null);
|
||||
appPersonnelInfoRecords.setPersonnelId(personnelInfoVo.getId());
|
||||
appPersonnelInfoRecordsMapper.insert(appPersonnelInfoRecords);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
|
||||
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
|
||||
|
||||
log.info("长度:" + largeData.length);
|
||||
// 在获取 largeData 后,将其与前缀合并
|
||||
byte[] prefix = new byte[]{0x50, 0x49, 0x43, 0x54, 0x55, 0x52, 0x45}; // "PICTURE"
|
||||
byte[] combinedData = new byte[prefix.length + largeData.length];
|
||||
System.arraycopy(prefix, 0, combinedData, 0, prefix.length);
|
||||
System.arraycopy(largeData, 0, combinedData, prefix.length, largeData.length);
|
||||
|
||||
// 将 combinedData 转换为十六进制表示
|
||||
String[] hexArray = new String[combinedData.length];
|
||||
for (int i = 0; i < combinedData.length; i++) {
|
||||
hexArray[i] = String.format("0x%02X", combinedData[i]);
|
||||
}
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", combinedData);
|
||||
String[] specificChunk = ImageToCArrayConverter.getChunk2(hexArray, 0, bo.getChunkSize());
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),Arrays.toString(specificChunk));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
|
@ -28,6 +28,7 @@ import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceLogMapper;
|
||||
@ -123,6 +124,47 @@ public class DeviceBizService {
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
public TableDataInfo<WebDeviceVo> queryWebDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
Page<WebDeviceVo> result = deviceMapper.queryWebDeviceList(pageQuery.build(), bo);
|
||||
List<WebDeviceVo> records = result.getRecords();
|
||||
if(records != null && !records.isEmpty()){
|
||||
records.forEach(item -> {
|
||||
if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){
|
||||
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
|
||||
item.setOnlineStatus(1);
|
||||
}else{
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(location)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
item.setLatitude(jsonObject.getString("latitude"));
|
||||
item.setLongitude(jsonObject.getString("longitude"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
public int bindDevice(AppDeviceBo bo) {
|
||||
Integer mode = bo.getCommunicationMode();
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
|
Reference in New Issue
Block a user