@ -9,6 +9,8 @@ import com.fuyuanshen.app.domain.AppDeviceBindRecord;
import com.fuyuanshen.app.domain.AppPersonnelInfo ;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo ;
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.AppDeviceDetailVo ;
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo ;
@ -16,10 +18,13 @@ import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper ;
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper ;
import com.fuyuanshen.common.core.exception.ServiceException ;
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter ;
import com.fuyuanshen.common.core.utils.MapstructUtils ;
import com.fuyuanshen.common.core.utils.ObjectUtils ;
import com.fuyuanshen.common.core.utils.StringUtils ;
import com.fuyuanshen.common.mybatis.core.page.PageQuery ;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo ;
import com.fuyuanshen.common.redis.utils.RedisUtils ;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper ;
import com.fuyuanshen.equipment.domain.Device ;
import com.fuyuanshen.equipment.domain.DeviceType ;
@ -32,16 +37,18 @@ import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
import com.fuyuanshen.equipment.mapper.DeviceMapper ;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper ;
import com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap ;
import com.fuyuanshen.system .mqtt.config.MqttGateway ;
import com.fuyuanshen.system .mqtt.constants.MqttConstants ;
import com.fuyuanshen.global .mqtt.config.MqttGateway ;
import com.fuyuanshen.global .mqtt.constants.MqttConstants ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.stereotype.Service ;
import org.springframework.web.multipart.MultipartFile ;
import java.u til.Date ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
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.ImageToCArrayConverter.convertHexToDecimal ;
@Slf4j
@ -283,5 +290,139 @@ public class AppDeviceBizService {
}
public void uploadDeviceLogo ( 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 ) ;
System . out . println ( " 长度: " + largeData . length ) ;
System . out . println ( " 原始数据大小: " + largeData . length + " 字节 " ) ;
int [ ] ints = convertHexToDecimal ( largeData ) ;
RedisUtils . setCacheObject ( GLOBAL_REDIS_KEY + " app_logo_data: " + device . getDeviceImei ( ) , Arrays . toString ( ints ) , Duration . ofSeconds ( 30 * 60L ) ) ;
String data = RedisUtils . getCacheObject ( GLOBAL_REDIS_KEY + " app_logo_data: " + device . getDeviceImei ( ) ) ;
byte [ ] arr = ImageToCArrayConverter . convertStringToByteArray ( data ) ;
byte [ ] specificChunk = ImageToCArrayConverter . getChunk ( arr , 0 , 512 ) ;
System . out . println ( " 第0块数据大小: " + specificChunk . length + " 字节 " ) ;
System . out . println ( " 第0块数据: " + Arrays . toString ( specificChunk ) ) ;
ArrayList < Integer > intData = new ArrayList < > ( ) ;
intData . add ( 3 ) ;
intData . add ( 1 ) ;
ImageToCArrayConverter . buildArr ( convertHexToDecimal ( specificChunk ) , intData ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
Map < String , Object > map = new HashMap < > ( ) ;
map . put ( " instruct " , intData ) ;
mqttGateway . sendMsgToMqtt ( MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , 1 , JSON . toJSONString ( map ) ) ;
log . info ( " 发送点阵数据到设备消息=>topic:{},payload:{} " , MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , JSON . toJSONString ( map ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
/**
* 灯光模式
* 0( 关灯) , 1( 强光模式) , 2( 弱光模式) , 3( 爆闪模式) , 4( 泛光模式)
*/
public void lightModeSettings ( DeviceInstructDto params ) {
try {
Long deviceId = params . getDeviceId ( ) ;
Device device = deviceMapper . selectById ( deviceId ) ;
if ( device = = null ) {
throw new ServiceException ( " 设备不存在 " ) ;
}
Integer instructValue = Integer . parseInt ( params . getInstructValue ( ) ) ;
ArrayList < Integer > intData = new ArrayList < > ( ) ;
intData . add ( 1 ) ;
intData . add ( instructValue ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
Map < String , Object > map = new HashMap < > ( ) ;
map . put ( " instruct " , intData ) ;
mqttGateway . sendMsgToMqtt ( MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , 1 , JSON . toJSONString ( map ) ) ;
log . info ( " 发送点阵数据到设备消息=>topic:{},payload:{} " , MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , JSON . toJSONString ( map ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
//灯光亮度设置
public void lightBrightnessSettings ( DeviceInstructDto params ) {
try {
Long deviceId = params . getDeviceId ( ) ;
Device device = deviceMapper . selectById ( deviceId ) ;
if ( device = = null ) {
throw new ServiceException ( " 设备不存在 " ) ;
}
String instructValue = params . getInstructValue ( ) ;
ArrayList < Integer > intData = new ArrayList < > ( ) ;
intData . add ( 5 ) ;
String [ ] values = instructValue . split ( " \\ . " ) ;
String value1 = values [ 0 ] ;
String value2 = values [ 1 ] ;
if ( StringUtils . isNoneBlank ( value1 ) ) {
intData . add ( Integer . parseInt ( value1 ) ) ;
}
if ( StringUtils . isNoneBlank ( value2 ) ) {
intData . add ( Integer . parseInt ( value2 ) ) ;
}
intData . add ( 0 ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
Map < String , Object > map = new HashMap < > ( ) ;
map . put ( " instruct " , intData ) ;
mqttGateway . sendMsgToMqtt ( MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , 1 , JSON . toJSONString ( map ) ) ;
log . info ( " 发送点阵数据到设备消息=>topic:{},payload:{} " , MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , JSON . toJSONString ( map ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
//激光模式设置
public void laserModeSettings ( DeviceInstructDto params ) {
try {
Long deviceId = params . getDeviceId ( ) ;
Device device = deviceMapper . selectById ( deviceId ) ;
if ( device = = null ) {
throw new ServiceException ( " 设备不存在 " ) ;
}
Integer instructValue = Integer . parseInt ( params . getInstructValue ( ) ) ;
ArrayList < Integer > intData = new ArrayList < > ( ) ;
intData . add ( 4 ) ;
intData . add ( instructValue ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
intData . add ( 0 ) ;
Map < String , Object > map = new HashMap < > ( ) ;
map . put ( " instruct " , intData ) ;
mqttGateway . sendMsgToMqtt ( MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , 1 , JSON . toJSONString ( map ) ) ;
log . info ( " 发送点阵数据到设备消息=>topic:{},payload:{} " , MqttConstants . GLOBAL_PUB_KEY + device . getDeviceImei ( ) , JSON . toJSONString ( map ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
public String mapReverseGeocoding ( DeviceInstructDto params ) {
// Long deviceId = params.getDeviceId();
// Device device = deviceMapper.selectById(deviceId);
QueryWrapper < Device > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . eq ( " device_imei " , params . getDeviceImei ( ) ) ;
List < Device > devices = deviceMapper . selectList ( queryWrapper ) ;
if ( ObjectUtils . length ( devices ) = = 0 ) {
throw new ServiceException ( " 设备不存在 " ) ;
}
return RedisUtils . getCacheObject ( " device:location: " + devices . get ( 0 ) . getDeviceImei ( ) ) ;
}
}