|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.fuyuanshen.app.service;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
@ -11,6 +12,7 @@ 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.equipment.APPDeviceMapper;
|
|
|
|
|
import com.fuyuanshen.common.core.exception.ServiceException;
|
|
|
|
|
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
|
|
|
|
import com.fuyuanshen.common.core.utils.ObjectUtils;
|
|
|
|
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
|
|
|
@ -19,20 +21,24 @@ import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.Device;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.DeviceType;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
|
|
|
|
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 com.fuyuanshen.equipment.utils.c.ReliableTextToBitmap;
|
|
|
|
|
import com.fuyuanshen.system.mqtt.config.MqttGateway;
|
|
|
|
|
import com.fuyuanshen.system.mqtt.constants.MqttConstants;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static org.apache.poi.hslf.usermodel.HSLFFontInfo.FontRenderType.device;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@ -44,6 +50,7 @@ public class AppDeviceBizService {
|
|
|
|
|
private final DeviceMapper deviceMapper;
|
|
|
|
|
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
|
|
|
|
private final DeviceTypeMapper deviceTypeMapper;
|
|
|
|
|
private final MqttGateway mqttGateway;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<APPDeviceTypeVo> getTypeList() {
|
|
|
|
@ -60,12 +67,31 @@ public class AppDeviceBizService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int sendMessage(AppDeviceBo bo) {
|
|
|
|
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq("id", bo.getDeviceId())
|
|
|
|
|
.eq("binding_user_id", AppLoginHelper.getUserId())
|
|
|
|
|
.set("send_msg", bo.getSendMsg());
|
|
|
|
|
return deviceMapper.update(updateWrapper);
|
|
|
|
|
public int sendMessage(AppDeviceSendMsgBo bo) {
|
|
|
|
|
List<Long> deviceIds = bo.getDeviceIds();
|
|
|
|
|
if(deviceIds == null || deviceIds.isEmpty()){
|
|
|
|
|
throw new ServiceException("请选择设备");
|
|
|
|
|
}
|
|
|
|
|
for (Long deviceId : deviceIds){
|
|
|
|
|
Device deviceObj = deviceMapper.selectById(deviceId);
|
|
|
|
|
if(deviceObj==null) {
|
|
|
|
|
throw new ServiceException("设备不存在"+deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] msg = ReliableTextToBitmap.textToBitmapBytes(bo.getSendMsg());
|
|
|
|
|
Map<String,Object> linkHashMap = new HashMap<>();
|
|
|
|
|
linkHashMap.put("message",msg);
|
|
|
|
|
String sendMsg = JSON.toJSONString(linkHashMap);
|
|
|
|
|
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 ,sendMsg);
|
|
|
|
|
log.info("发送设备消息:{}", bo.getSendMsg());
|
|
|
|
|
|
|
|
|
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq("id", deviceId)
|
|
|
|
|
.eq("binding_user_id", AppLoginHelper.getUserId())
|
|
|
|
|
.set("send_msg", bo.getSendMsg());
|
|
|
|
|
deviceMapper.update(updateWrapper);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -172,9 +198,27 @@ public class AppDeviceBizService {
|
|
|
|
|
|
|
|
|
|
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
|
|
|
|
Long deviceId = bo.getDeviceId();
|
|
|
|
|
Device deviceObj = deviceMapper.selectById(deviceId);
|
|
|
|
|
if(deviceObj == null){
|
|
|
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
|
|
|
|
.eq("device_id", deviceId);
|
|
|
|
|
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
|
|
|
|
// unitName,position,name,id
|
|
|
|
|
byte[] unitName = ReliableTextToBitmap.textToBitmapBytes(bo.getUnitName());
|
|
|
|
|
byte[] position = ReliableTextToBitmap.textToBitmapBytes(bo.getPosition());
|
|
|
|
|
byte[] name = ReliableTextToBitmap.textToBitmapBytes(bo.getName());
|
|
|
|
|
byte[] id = ReliableTextToBitmap.textToBitmapBytes(bo.getCode());
|
|
|
|
|
Map<String,Object> linkHashMap = new HashMap<>();
|
|
|
|
|
linkHashMap.put("unitName",unitName);
|
|
|
|
|
linkHashMap.put("position",position);
|
|
|
|
|
linkHashMap.put("name",name);
|
|
|
|
|
linkHashMap.put("id",id);
|
|
|
|
|
String personnelInfo = JSON.toJSONString(linkHashMap);
|
|
|
|
|
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 ,personnelInfo);
|
|
|
|
|
log.info("发送点阵数据到设备消息:{}", bo);
|
|
|
|
|
|
|
|
|
|
if(ObjectUtils.length(appPersonnelInfoVos) == 0){
|
|
|
|
|
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
|
|
|
|
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
|
|
|
|