1
0

Merge remote-tracking branch 'upstream/main' into fys-prod

# Conflicts:
#	fys-admin/pom.xml
This commit is contained in:
2025-07-23 10:57:03 +08:00
23 changed files with 260 additions and 44 deletions

View File

@ -11,6 +11,7 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.web.core.BaseController; import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; 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.query.DeviceQueryCriteria;
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@ -101,7 +102,7 @@ public class AppDeviceController extends BaseController {
* 发送信息 * 发送信息
*/ */
@PostMapping(value = "/sendMessage") @PostMapping(value = "/sendMessage")
public R<Void> sendMessage(@RequestBody AppDeviceBo bo) { public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
return toAjax(appDeviceService.sendMessage(bo)); return toAjax(appDeviceService.sendMessage(bo));
} }
} }

View File

@ -55,6 +55,14 @@ public class AppDeviceShareController extends BaseController {
return deviceShareService.queryPageList(bo, pageQuery); return deviceShareService.queryPageList(bo, pageQuery);
} }
/**
* 他人分享管理列表
*/
@GetMapping("/otherDeviceShareList")
public TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery) {
return deviceShareService.otherDeviceShareList(bo, pageQuery);
}
/** /**
* 获取设备分享详细信息 * 获取设备分享详细信息
* *

View File

@ -1,5 +1,6 @@
package com.fuyuanshen.app.service; package com.fuyuanshen.app.service;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -11,25 +12,33 @@ import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo; import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper; import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper; 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.MapstructUtils;
import com.fuyuanshen.common.core.utils.ObjectUtils;
import com.fuyuanshen.common.mybatis.core.page.PageQuery; import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.satoken.utils.AppLoginHelper; import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
import com.fuyuanshen.equipment.domain.Device; import com.fuyuanshen.equipment.domain.Device;
import com.fuyuanshen.equipment.domain.DeviceType; import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; 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.query.DeviceQueryCriteria;
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
import com.fuyuanshen.equipment.enums.BindingStatusEnum; import com.fuyuanshen.equipment.enums.BindingStatusEnum;
import com.fuyuanshen.equipment.enums.CommunicationModeEnum; import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
import com.fuyuanshen.equipment.mapper.DeviceMapper; import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper; 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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Slf4j @Slf4j
@ -41,6 +50,7 @@ public class AppDeviceBizService {
private final DeviceMapper deviceMapper; private final DeviceMapper deviceMapper;
private final AppPersonnelInfoMapper appPersonnelInfoMapper; private final AppPersonnelInfoMapper appPersonnelInfoMapper;
private final DeviceTypeMapper deviceTypeMapper; private final DeviceTypeMapper deviceTypeMapper;
private final MqttGateway mqttGateway;
public List<APPDeviceTypeVo> getTypeList() { public List<APPDeviceTypeVo> getTypeList() {
@ -57,12 +67,31 @@ public class AppDeviceBizService {
} }
public int sendMessage(AppDeviceBo bo) { public int sendMessage(AppDeviceSendMsgBo bo) {
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>(); List<Long> deviceIds = bo.getDeviceIds();
updateWrapper.eq("id", bo.getDeviceId()) if(deviceIds == null || deviceIds.isEmpty()){
.eq("binding_user_id", AppLoginHelper.getUserId()) throw new ServiceException("请选择设备");
.set("send_msg", bo.getSendMsg()); }
return deviceMapper.update(updateWrapper); 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;
} }
@ -138,6 +167,9 @@ public class AppDeviceBizService {
public AppDeviceDetailVo getInfo(Long id) { public AppDeviceDetailVo getInfo(Long id) {
Device device = deviceMapper.selectById(id); Device device = deviceMapper.selectById(id);
if (device == null) {
throw new RuntimeException("请先将设备入库!!!");
}
AppDeviceDetailVo vo = new AppDeviceDetailVo(); AppDeviceDetailVo vo = new AppDeviceDetailVo();
vo.setDeviceId(device.getId()); vo.setDeviceId(device.getId());
vo.setDeviceName(device.getDeviceName()); vo.setDeviceName(device.getDeviceName());
@ -152,7 +184,11 @@ public class AppDeviceBizService {
} }
vo.setBluetoothName(device.getBluetoothName()); vo.setBluetoothName(device.getBluetoothName());
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectById(device.getId()); vo.setSendMsg(device.getSendMsg());
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
.eq("device_id", device.getId());
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectOne(qw);
if(appPersonnelInfo != null){ if(appPersonnelInfo != null){
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class); AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
vo.setPersonnelInfo(personnelInfoVo); vo.setPersonnelInfo(personnelInfoVo);
@ -161,7 +197,41 @@ public class AppDeviceBizService {
} }
public boolean registerPersonInfo(AppPersonnelInfoBo bo) { public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class); Long deviceId = bo.getDeviceId();
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo); 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);
}else {
UpdateWrapper<AppPersonnelInfo> uw = new UpdateWrapper<>();
uw.eq("device_id", deviceId)
.set("name", bo.getName())
.set("position", bo.getPosition())
.set("unit_name", bo.getUnitName())
.set("code",bo.getCode());
return appPersonnelInfoMapper.update(null, uw)>0;
}
} }
} }

View File

@ -303,6 +303,6 @@ mqtt:
password: fys123456 password: fys123456
url: tcp://47.107.152.87:1883 url: tcp://47.107.152.87:1883
subClientId: fys_subClient subClientId: fys_subClient
subTopic: worker/alert/#,worker/location/# subTopic: A/#,worker/location/#
pubTopic: worker/location pubTopic: B/#
pubClientId: fys_pubClient pubClientId: fys_pubClient

View File

@ -36,6 +36,11 @@ public class AppPersonnelInfo extends TenantEntity {
*/ */
private String name; private String name;
/**
* 职位
*/
private String position;
/** /**
* 单位名称 * 单位名称
*/ */
@ -46,5 +51,6 @@ public class AppPersonnelInfo extends TenantEntity {
*/ */
private String sendMsg; private String sendMsg;
private String code;
} }

View File

@ -23,13 +23,11 @@ public class AppPersonnelInfoBo extends BaseEntity {
/** /**
* 主键 * 主键
*/ */
@NotNull(message = "主键不能为空", groups = { AddGroup.class, EditGroup.class })
private Long id; private Long id;
/** /**
* 设备id * 设备id
*/ */
@NotNull(message = "设备id不能为空", groups = { AddGroup.class, EditGroup.class })
private Long deviceId; private Long deviceId;
/** /**
@ -37,6 +35,11 @@ public class AppPersonnelInfoBo extends BaseEntity {
*/ */
private String name; private String name;
/**
* 职位
*/
private String position;
/** /**
* 部门名称 * 部门名称
*/ */
@ -52,5 +55,8 @@ public class AppPersonnelInfoBo extends BaseEntity {
*/ */
private String sendMsg; private String sendMsg;
/**
* ID号
*/
private String code;
} }

View File

@ -69,4 +69,9 @@ public class AppDeviceDetailVo {
* 人员信息 * 人员信息
*/ */
private AppPersonnelInfoVo personnelInfo; private AppPersonnelInfoVo personnelInfo;
/**
* 发送信息
*/
private String sendMsg;
} }

View File

@ -41,6 +41,10 @@ public class AppDeviceShareVo implements Serializable {
@ExcelProperty(value = "设备ID") @ExcelProperty(value = "设备ID")
private Long deviceId; private Long deviceId;
/**
* 设备IMEI
*/
private String deviceImei;
/** /**
* 设备名称 * 设备名称
*/ */

View File

@ -47,10 +47,10 @@ public class AppPersonnelInfoVo implements Serializable {
private String name; private String name;
/** /**
* 部门名称 * 岗位
*/ */
@ExcelProperty(value = "部门名称") @ExcelProperty(value = "岗位")
private String deptName; private String position;
/** /**
* 单位名称 * 单位名称
@ -59,10 +59,10 @@ public class AppPersonnelInfoVo implements Serializable {
private String unitName; private String unitName;
/** /**
* 发送信息 * ID号
*/ */
@ExcelProperty(value = "发送信息") @ExcelProperty(value = "ID号")
private String sendMsg; private String code;
} }

View File

@ -1,8 +1,12 @@
package com.fuyuanshen.app.mapper; 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.AppDeviceShare;
import com.fuyuanshen.app.domain.bo.AppDeviceShareBo;
import com.fuyuanshen.app.domain.vo.AppDeviceShareVo; import com.fuyuanshen.app.domain.vo.AppDeviceShareVo;
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;
/** /**
* 设备分享Mapper接口 * 设备分享Mapper接口
@ -11,5 +15,5 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
* @date 2025-07-16 * @date 2025-07-16
*/ */
public interface AppDeviceShareMapper extends BaseMapperPlus<AppDeviceShare, AppDeviceShareVo> { public interface AppDeviceShareMapper extends BaseMapperPlus<AppDeviceShare, AppDeviceShareVo> {
IPage<AppDeviceShareVo> otherDeviceShareList(@Param("bo") AppDeviceShareBo bo, Page<AppDeviceShareVo> page);
} }

View File

@ -65,4 +65,6 @@ public interface IAppDeviceShareService {
* @return 是否删除成功 * @return 是否删除成功
*/ */
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
TableDataInfo<AppDeviceShareVo> otherDeviceShareList(AppDeviceShareBo bo, PageQuery pageQuery);
} }

View File

@ -1,5 +1,6 @@
package com.fuyuanshen.app.service.impl; 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.MapstructUtils;
import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
@ -68,6 +69,7 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService {
if(device != null){ if(device != null){
r.setDevicePic(device.getDevicePic()); r.setDevicePic(device.getDevicePic());
r.setDeviceName(device.getDeviceName()); r.setDeviceName(device.getDeviceName());
r.setDeviceImei(device.getDeviceImei());
} }
}); });
return TableDataInfo.build(result); return TableDataInfo.build(result);
@ -146,4 +148,22 @@ public class AppDeviceShareServiceImpl implements IAppDeviceShareService {
} }
return baseMapper.deleteByIds(ids) > 0; 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);
}
} }

View File

@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.app.mapper.AppDeviceShareMapper"> <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> </mapper>

View File

@ -92,7 +92,7 @@ public class Customer extends TenantEntity {
/** /**
* 帐号状态0正常 1停用 * 帐号状态0正常 1停用
*/ */
private String status; private String status = "0";
/** /**
* 删除标志0代表存在 1代表删除 * 删除标志0代表存在 1代表删除

View File

@ -1,9 +1,11 @@
package com.fuyuanshen.customer.service.impl; package com.fuyuanshen.customer.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyuanshen.common.core.domain.model.LoginUser; import com.fuyuanshen.common.core.domain.model.LoginUser;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.satoken.utils.LoginHelper; import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.customer.constant.ArrayConstants; import com.fuyuanshen.customer.constant.ArrayConstants;
@ -92,6 +94,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
} }
customer.setUserLevel((byte) (loginUser.getUserLevel() + 1)); customer.setUserLevel((byte) (loginUser.getUserLevel() + 1));
customer.setPid(loginUser.getUserId()); customer.setPid(loginUser.getUserId());
customer.setStatus("0");
save(customer); save(customer);
@ -106,18 +109,40 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
/** /**
* 修改客户 * 修改客户
* 不是因为寂寞才想你,只是因为想你才寂寞。
* *
* @param resources / * @param customer /
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateCustomer(Customer resources) throws Exception { public void updateCustomer(Customer customer) throws Exception {
if (resources.getEnabled()) {
resources.setStatus("0"); UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
} else { if (StringUtils.isNotEmpty(customer.getUserName())) {
resources.setStatus("1"); userQueryCriteria.setCustomerName(customer.getUserName());
List<Customer> customers = customerMapper.queryCustomers(userQueryCriteria);
if (!customers.isEmpty()) {
throw new BadRequestException("用户名已存在!!!");
}
} }
saveOrUpdate(resources);
if (customer.getEnabled()) {
customer.setStatus("0");
} else {
// 强制下线
// StpUtil.logout(customer.getCustomerId());
// StpUtil.kickout(customer.getCustomerId());
customer.setStatus("1");
// 检查目标用户是否有有效的登录状态
if (StpUtil.isLogin(customer.getCustomerId())) {
// 用户已登录,可以执行踢出操作
StpUtil.kickout(customer.getCustomerId());
} else {
// 用户未登录,无法踢出
System.out.println("目标用户未登录,无法执行踢出操作");
}
}
saveOrUpdate(customer);
} }

View File

@ -105,7 +105,6 @@ public class Device extends TenantEntity {
@Schema(name = "设备状态") @Schema(name = "设备状态")
private Integer deviceStatus; private Integer deviceStatus;
/** /**
* 绑定状态 * 绑定状态
* 0 未绑定 * 0 未绑定
@ -127,4 +126,17 @@ public class Device extends TenantEntity {
private Date bindingTime; private Date bindingTime;
private String sendMsg; private String sendMsg;
/**
* 发布主题格式A/{device_id}
* pub_topic
*/
private String pubTopic;
/**
* 订阅主题格式B/{device_id}
* sub_topic
*/
private String subTopic;
} }

View File

@ -30,5 +30,5 @@ public class AppDeviceBo {
private String sendMsg; private String sendMsg;
private String deviceId; private Long deviceId;
} }

View File

@ -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;
}

View File

@ -186,6 +186,10 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
device.setCreateByName(loginUser.getNickname()); device.setCreateByName(loginUser.getNickname());
device.setTypeName(deviceTypes.getTypeName()); device.setTypeName(deviceTypes.getTypeName());
device.setDeviceType(deviceTypes.getId()); device.setDeviceType(deviceTypes.getId());
if (device.getDeviceImei() != null) {
device.setPubTopic("A/" + device.getDeviceImei());
device.setSubTopic("B/" + device.getDeviceImei());
}
deviceMapper.insert(device); deviceMapper.insert(device);
@ -293,14 +297,18 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
for (Long id : ids) { for (Long id : ids) {
DeviceAssignments deviceAssignment = deviceAssignmentsMapper.selectById(id); DeviceAssignments deviceAssignment = deviceAssignmentsMapper.selectById(id);
Device deviceType = deviceMapper.selectById(deviceAssignment.getDeviceId()); Device device = deviceMapper.selectById(deviceAssignment.getDeviceId());
if (StringUtils.isNotEmpty(deviceAssignment.getAssigneeName())) { if (StringUtils.isNotEmpty(deviceAssignment.getAssigneeName())) {
throw new BadRequestException(deviceType.getDeviceName() + ":设备已分配,请先解绑设备!!!"); throw new BadRequestException(device.getDeviceName() + ":设备已分配,请先解绑设备!!!");
}
if (device.getBindingStatus().equals(1)){
throw new BadRequestException(device.getDeviceName() + ":设备已绑定,请先解绑设备!!!");
} }
// 接收者 // 接收者
if (Objects.equals(deviceAssignment.getAssigneeId(), deviceType.getOriginalOwnerId())) { if (Objects.equals(deviceAssignment.getAssigneeId(), device.getOriginalOwnerId())) {
invalidIds.add(deviceAssignment.getDeviceId()); invalidIds.add(deviceAssignment.getDeviceId());
} }

View File

@ -38,13 +38,19 @@
<!-- 分页查询设备 --> <!-- 分页查询设备 -->
<select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device"> <select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device">
select SELECT *
da.id AS id,d.device_name,d.bluetooth_name, FROM (
d.device_pic, d.device_mac, d.device_sn, d.update_by,d.device_imei, SELECT
d.update_time, dg.id AS device_type, d.remark, d.binding_status,t.type_name AS typeName, da.id AS id, d.device_name, d.bluetooth_name,
da.assignee_id AS customerId, da.assignee_name AS customerName, da.active AS deviceStatus, d.pub_topic, d.sub_topic, d.device_pic,
da.create_time AS create_time , da.assigner_name AS createByName , da.id AS assignId d.device_mac, d.device_sn, d.update_by,
from device d d.device_imei, d.update_time, dg.id AS device_type,
d.remark, d.binding_status, t.type_name AS typeName,
da.assignee_id AS customerId, da.assignee_name AS customerName,
da.active AS deviceStatus, da.create_time AS create_time,
da.assigner_name AS createByName, da.id AS assignId,
ROW_NUMBER() OVER (PARTITION BY d.id ORDER BY da.create_time DESC) AS rn
FROM device d
LEFT JOIN device_type t ON d.device_type = t.id LEFT JOIN device_type t ON d.device_type = t.id
LEFT JOIN device_type_grants dg ON dg.device_type_id = t.id LEFT JOIN device_type_grants dg ON dg.device_type_id = t.id
LEFT JOIN device_assignments da ON da.device_id = d.id LEFT JOIN device_assignments da ON da.device_id = d.id
@ -71,9 +77,12 @@
AND da.assignee_id = #{criteria.currentOwnerId} AND da.assignee_id = #{criteria.currentOwnerId}
AND dg.customer_id = #{criteria.currentOwnerId} AND dg.customer_id = #{criteria.currentOwnerId}
</where> </where>
ORDER BY da.create_time DESC ) AS ranked
WHERE rn = 1
ORDER BY create_time DESC
</select> </select>
<select id="findAllDevices" resultType="com.fuyuanshen.equipment.domain.Device"> <select id="findAllDevices" resultType="com.fuyuanshen.equipment.domain.Device">
select select
d.id, d.customer_id, d.device_name,d.bluetooth_name, d.id, d.customer_id, d.device_name,d.bluetooth_name,

View File

@ -44,7 +44,7 @@ public class MqttOutboundConfiguration {
mqttPahoClientFactory mqttPahoClientFactory
); );
mqttPahoMessageHandler.setDefaultQos(1); mqttPahoMessageHandler.setDefaultQos(1);
mqttPahoMessageHandler.setDefaultTopic("worker/location"); mqttPahoMessageHandler.setDefaultTopic("B/#");
mqttPahoMessageHandler.setAsync(true); mqttPahoMessageHandler.setAsync(true);
return mqttPahoMessageHandler; return mqttPahoMessageHandler;
} }

View File

@ -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/";
}

View File

@ -27,5 +27,6 @@ public class ReceiverMessageHandler implements MessageHandler {
String timestamp = Objects.requireNonNull(headers.get("timestamp")).toString(); String timestamp = Objects.requireNonNull(headers.get("timestamp")).toString();
log.info("MQTT payload= {} \n receivedTopic = {} \n receivedQos = {} \n timestamp = {}" log.info("MQTT payload= {} \n receivedTopic = {} \n receivedQos = {} \n timestamp = {}"
,payload,receivedTopic,receivedQos,timestamp); ,payload,receivedTopic,receivedQos,timestamp);
} }
} }