forked from dyf/fys-Multi-tenant
代码优化
This commit is contained in:
@ -13,7 +13,6 @@ import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
|
||||
@ -38,12 +37,9 @@ import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.*;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
|
||||
import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap;
|
||||
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
||||
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
||||
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -53,6 +49,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
|
||||
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
||||
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -117,6 +118,31 @@ public class AppDeviceBizService {
|
||||
bo.setBindingUserId(userId);
|
||||
}
|
||||
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
||||
List<AppDeviceVo> 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+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + item.getDeviceImei());
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
|
||||
item.setOnlineStatus(1);
|
||||
}else{
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + item.getDeviceImei());
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@ -275,44 +301,28 @@ public class AppDeviceBizService {
|
||||
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
||||
vo.setPersonnelInfo(personnelInfoVo);
|
||||
}
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX + device.getDeviceImei());
|
||||
if(StringUtils.isNotBlank(onlineStatus)){
|
||||
vo.setOnlineStatus(1);
|
||||
}else{
|
||||
vo.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX + device.getDeviceImei());
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
vo.setMainLightMode(jsonObject.getString("mainLightMode"));
|
||||
vo.setLaserLightMode(jsonObject.getString("laserLightMode"));
|
||||
vo.setBatteryPercentage(jsonObject.getString("batteryPercentage"));
|
||||
vo.setChargeState(jsonObject.getString("chargeState"));
|
||||
vo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime"));
|
||||
}else{
|
||||
vo.setBatteryPercentage("0");
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
byte[] unitName = generateFixedBitmapData("富源晟科技", 120);
|
||||
byte[] position = generateFixedBitmapData("研发", 120);
|
||||
byte[] name = generateFixedBitmapData("张三", 120);
|
||||
byte[] id = generateFixedBitmapData("123456", 120);
|
||||
// int[] intUnitNames = Bitmap80x12Generator.convertHexToDecimal(unitName);
|
||||
// int[] intPosition = Bitmap80x12Generator.convertHexToDecimal(position);
|
||||
// int[] intNames = Bitmap80x12Generator.convertHexToDecimal(position);
|
||||
// int[] intIds = Bitmap80x12Generator.convertHexToDecimal(position);
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", 2);
|
||||
// System.out.println(JSON.toJSONString( map));
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.append("[")
|
||||
// buildStr(unitName, sb);
|
||||
// System.out.println(sb.toString());
|
||||
// Object[] arr = new Object[]{2, Bitmap80x12Generator , Arrays.toString(name), Arrays.toString(id)};
|
||||
|
||||
// System.out.println(Arrays.deepToString(arr));
|
||||
// int[] a = new int[]{6,6,6,6,6,6};
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(2);
|
||||
buildArr(convertHexToDecimal(unitName), intData);
|
||||
buildArr(convertHexToDecimal(position), intData);
|
||||
buildArr(convertHexToDecimal(name), intData);
|
||||
buildArr(convertHexToDecimal(id), intData);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
intData.add(0);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("instruct", intData);
|
||||
System.out.println(JSON.toJSONString(map));
|
||||
}
|
||||
|
||||
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
@ -373,9 +383,9 @@ public class AppDeviceBizService {
|
||||
System.out.println("原始数据大小: " + largeData.length + " 字节");
|
||||
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject("app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject("app_logo_data:" + device.getDeviceImei());
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+"app_logo_data:" + device.getDeviceImei());
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
@ -410,7 +420,7 @@ public class AppDeviceBizService {
|
||||
if(device == null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
Integer instructValue = (Integer) params.getInstructValue();
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(1);
|
||||
intData.add(instructValue);
|
||||
@ -434,7 +444,7 @@ public class AppDeviceBizService {
|
||||
if(device == null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
String instructValue = (String)params.getInstructValue();
|
||||
String instructValue = params.getInstructValue();
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(5);
|
||||
String[] values = instructValue.split("\\.");
|
||||
@ -466,7 +476,7 @@ public class AppDeviceBizService {
|
||||
if(device == null){
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
Integer instructValue = (Integer) params.getInstructValue();
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(4);
|
||||
intData.add(instructValue);
|
||||
|
Reference in New Issue
Block a user