forked from dyf/fys-Multi-tenant
设备分享功能开发
This commit is contained in:
@ -94,10 +94,10 @@
|
||||
</dependency>
|
||||
|
||||
<!-- demo模块 -->
|
||||
<dependency>
|
||||
<!--<dependency>
|
||||
<groupId>com.fuyuanshen</groupId>
|
||||
<artifactId>fys-demo</artifactId>
|
||||
</dependency>
|
||||
</dependency>-->
|
||||
|
||||
<!-- 工作流模块 -->
|
||||
<dependency>
|
||||
|
@ -11,6 +11,7 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
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 jakarta.validation.constraints.NotNull;
|
||||
@ -101,7 +102,7 @@ public class AppDeviceController extends BaseController {
|
||||
* 发送信息
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceBo bo) {
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendMessage(bo));
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,14 @@ public class AppDeviceShareController extends BaseController {
|
||||
return deviceShareService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 他人分享管理列表
|
||||
*/
|
||||
@GetMapping("/otherDeviceShareList")
|
||||
public TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||
return deviceShareService.otherDeviceShareList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备分享详细信息
|
||||
*
|
||||
|
@ -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);
|
||||
|
@ -303,6 +303,6 @@ mqtt:
|
||||
password: #YtvpSfCNG
|
||||
url: tcp://47.120.79.150:2883
|
||||
subClientId: fys_subClient
|
||||
subTopic: worker/alert/#,worker/location/#
|
||||
pubTopic: worker/location
|
||||
subTopic: A/#,worker/location/#
|
||||
pubTopic: B/#
|
||||
pubClientId: fys_pubClient
|
@ -51,5 +51,6 @@ public class AppPersonnelInfo extends TenantEntity {
|
||||
*/
|
||||
private String sendMsg;
|
||||
|
||||
private String code;
|
||||
|
||||
}
|
||||
|
@ -41,6 +41,10 @@ public class AppDeviceShareVo implements Serializable {
|
||||
@ExcelProperty(value = "设备ID")
|
||||
private Long deviceId;
|
||||
|
||||
/**
|
||||
* 设备IMEI
|
||||
*/
|
||||
private String deviceImei;
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
|
@ -47,10 +47,10 @@ public class AppPersonnelInfoVo implements Serializable {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
* 岗位
|
||||
*/
|
||||
@ExcelProperty(value = "部门名称")
|
||||
private String deptName;
|
||||
@ExcelProperty(value = "岗位")
|
||||
private String position;
|
||||
|
||||
/**
|
||||
* 单位名称
|
||||
@ -59,10 +59,10 @@ public class AppPersonnelInfoVo implements Serializable {
|
||||
private String unitName;
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
* ID号
|
||||
*/
|
||||
@ExcelProperty(value = "发送信息")
|
||||
private String sendMsg;
|
||||
@ExcelProperty(value = "ID号")
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package com.fuyuanshen.app.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppDeviceShare;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 设备分享Mapper接口
|
||||
@ -11,5 +15,5 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
* @date 2025-07-16
|
||||
*/
|
||||
public interface AppDeviceShareMapper extends BaseMapperPlus<AppDeviceShare, AppDeviceShareVo> {
|
||||
|
||||
IPage<AppDeviceShareVo> otherDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page<AppDeviceShareVo> page);
|
||||
}
|
||||
|
@ -65,4 +65,6 @@ public interface IAppDeviceShareService {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.fuyuanshen.app.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
@ -68,6 +69,7 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService {
|
||||
if(device != null){
|
||||
r.setDevicePic(device.getDevicePic());
|
||||
r.setDeviceName(device.getDeviceName());
|
||||
r.setDeviceImei(device.getDeviceImei());
|
||||
}
|
||||
});
|
||||
return TableDataInfo.build(result);
|
||||
@ -146,4 +148,22 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService {
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery) {
|
||||
String username = AppLoginHelper.getUsername();
|
||||
bo.setPhonenumber(username);
|
||||
Page<AppDeviceShareVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
||||
IPage<AppDeviceShareVo> result = baseMapper.otherDeviceShareList(bo, page);
|
||||
List<AppDeviceShareVo> records = result.getRecords();
|
||||
records.forEach(r -> {
|
||||
Device device = deviceMapper.selectById(r.getDeviceId());
|
||||
if(device != null){
|
||||
r.setDevicePic(device.getDevicePic());
|
||||
r.setDeviceName(device.getDeviceName());
|
||||
r.setDeviceImei(device.getDeviceImei());
|
||||
}
|
||||
});
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceShareMapper">
|
||||
|
||||
<select id="otherDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
|
||||
SELECT * FROM app_device_share a where a.phonenumber = #{bo.phonenumber}
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.fuyuanshen.equipment.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 绑定设备参数
|
||||
*/
|
||||
@Data
|
||||
public class AppDeviceSendMsgBo {
|
||||
|
||||
private String sendMsg;
|
||||
|
||||
private List<Long> deviceIds;
|
||||
}
|
@ -44,7 +44,7 @@ public class MqttOutboundConfiguration {
|
||||
mqttPahoClientFactory
|
||||
);
|
||||
mqttPahoMessageHandler.setDefaultQos(1);
|
||||
mqttPahoMessageHandler.setDefaultTopic("worker/location");
|
||||
mqttPahoMessageHandler.setDefaultTopic("B/#");
|
||||
mqttPahoMessageHandler.setAsync(true);
|
||||
return mqttPahoMessageHandler;
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.fuyuanshen.system.mqtt.constants;
|
||||
|
||||
|
||||
public interface MqttConstants {
|
||||
|
||||
|
||||
/**
|
||||
* 全局发布消息的key
|
||||
*/
|
||||
String GLOBAL_PUB_KEY = "B/";
|
||||
|
||||
/**
|
||||
* 全局订阅消息的key
|
||||
*/
|
||||
String GLOBAL_SUB_KEY = "A/";
|
||||
}
|
@ -27,5 +27,6 @@ public class ReceiverMessageHandler implements MessageHandler {
|
||||
String timestamp = Objects.requireNonNull(headers.get("timestamp")).toString();
|
||||
log.info("MQTT payload= {} \n receivedTopic = {} \n receivedQos = {} \n timestamp = {}"
|
||||
,payload,receivedTopic,receivedQos,timestamp);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user