Commit 7c65aeea by 杨伟程
parents dd754f0e d5be3981
......@@ -38,5 +38,7 @@ public class PlatDeviceQueryDTO extends BaseTenantDTO {
@ApiModelProperty(value = "组织id")
private String orgId;
private String spaceId;
}
package com.makeit.mapper.platform.device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.makeit.dto.platform.device.PlatDeviceQueryDTO;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.vo.platform.device.PlatDeviceListVO;
import org.apache.ibatis.annotations.Param;
/**
* <p>
......@@ -13,4 +17,7 @@ import com.makeit.entity.platform.device.PlatDevice;
*/
public interface PlatDeviceMapper extends BaseMapper<PlatDevice> {
Page<PlatDeviceListVO> getDeviceIdsBySpaceId(@Param("param")PlatDeviceQueryDTO param, Page page);
}
......@@ -21,4 +21,8 @@ public interface PlatRoomMapper extends BaseMapper<PlatRoom> {
List<WorkStationInstitutionRoomVO> workStationList(@Param("dto") WorkStationQueryDTO dto);
Page<WorkStationInstitutionRoomVO> workStationPage(Page<WorkStationQueryDTO> page, @Param("dto") WorkStationQueryDTO dto);
List<PlatSpaceAndRoomVO> spaceList(@Param("orgIds")List<String> orgIds);
List<PlatSpaceAndRoomVO> roomList(@Param("orgIds")List<String> orgIds);
}
......@@ -22,6 +22,7 @@ import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.device.PlatDeviceOther;
import com.makeit.entity.platform.space.PlatRegionSetting;
import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.enums.CodeMessageEnum;
import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.device.PlatDeviceMapper;
......@@ -32,6 +33,7 @@ import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.device.PlatDeviceOtherService;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.space.PlatRegionSettingService;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.DeviceCacheUtil;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
......@@ -42,12 +44,17 @@ import com.makeit.utils.old.StringUtils;
import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.vo.platform.device.PlatDeviceListVO;
import com.makeit.vo.platform.device.PlatDeviceViewVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* <p>
......@@ -75,34 +82,68 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
private PlatRegionSettingService platRegionSettingService;
@Autowired
private IotProductDeviceService iotProductDeviceService;
@Autowired
private PlatSpaceService platSpaceService;
@Override
public PageVO<PlatDeviceListVO> page(PageReqDTO<PlatDeviceQueryDTO> pageReqDTO) {
PlatDeviceQueryDTO dto = pageReqDTO.getData();
Page<PlatDevice> p = PageUtil.toMpPage(pageReqDTO);
Page<PlatDevice> page = page(p, new QueryWrapper<PlatDevice>().lambda()
.like(StringUtils.isNotBlank(dto.getOriDeviceId()), PlatDevice::getOriDeviceId, dto.getOriDeviceId())
.like(StringUtils.isNotBlank(dto.getName()), PlatDevice::getName, dto.getName())
.eq(StringUtils.isNotBlank(dto.getStatus()), PlatDevice::getStatus, dto.getStatus())
.like(StringUtils.isNotBlank(dto.getProductName()), PlatDevice::getProductName, dto.getProductName())
.eq(StringUtils.isNotBlank(dto.getProductId()), PlatDevice::getProductId, dto.getProductId())
.eq(StringUtils.isNotBlank(dto.getOrgId()),PlatDevice::getOrgId,dto.getOrgId())
// .apply(StringUtils.isNotBlank(dto.getOrgId()), "find_in_set('" + dto.getOrgId() + "',org_path)")
.orderByDesc(BaseEntity::getUpdateDate)
);
Page<PlatDeviceListVO> page = baseMapper.getDeviceIdsBySpaceId(dto, p);
// Page<PlatDevice> page = page(p, new QueryWrapper<PlatDevice>().lambda()
// .like(StringUtils.isNotBlank(dto.getOriDeviceId()), PlatDevice::getOriDeviceId, dto.getOriDeviceId())
// .like(StringUtils.isNotBlank(dto.getName()), PlatDevice::getName, dto.getName())
// .eq(StringUtils.isNotBlank(dto.getStatus()), PlatDevice::getStatus, dto.getStatus())
// .like(StringUtils.isNotBlank(dto.getProductName()), PlatDevice::getProductName, dto.getProductName())
// .eq(StringUtils.isNotBlank(dto.getProductId()), PlatDevice::getProductId, dto.getProductId())
// .eq(StringUtils.isNotBlank(dto.getOrgId()),PlatDevice::getOrgId,dto.getOrgId())
// .orderByDesc(BaseEntity::getUpdateDate)
// );
List<PlatDeviceListVO> records = page.getRecords();
//List<PlatDeviceListVO> voList = BeanDtoVoUtils.listVo(records, PlatDeviceListVO.class);
if(CollectionUtils.isEmpty(records)){
return new PageVO<>();
}
List<String> spaceIdList = records.stream().flatMap(vo -> {
String spaceParentPath = vo.getSpaceParentPath();
String spp = Optional.ofNullable(spaceParentPath).orElse("");
return Stream.of(spp.split(","));
}).collect(Collectors.toList());
List<PlatDeviceListVO> voList = BeanDtoVoUtils.listVo(page.getRecords(), PlatDeviceListVO.class);
spaceIdList.add("-1");
List<PlatSpace> platSpaces = platSpaceService.listByIds(spaceIdList);
Map<String, String> spaceIdNameMap = platSpaces.stream().collect(Collectors.toMap(BaseEntity::getId, vo -> vo.getName(), (v1, v2) -> v1));
for (PlatDeviceListVO record : records) {
String spaceParentPath = record.getSpaceParentPath();
if(StringUtils.isNotBlank(spaceParentPath)){
String spaceNameJoin = Stream.of(spaceParentPath.split(",")).map(vo -> spaceIdNameMap.get(vo)).collect(Collectors.joining("-"));
String spaceName = spaceNameJoin + "-" + record.getSpaceName() + "-" + record.getRoomName();
if(StringUtils.isNotBlank(record.getBedName())){
spaceName = spaceName +"-"+record.getBedName();
}
record.setSpaceName(spaceName);
}
}
JoinUtil.join(voList, platOrgService, PlatDeviceListVO::getOrgId, PlatOrg::getId, (d, o) -> {
JoinUtil.join(records, platOrgService, PlatDeviceListVO::getOrgId, PlatOrg::getId, (d, o) -> {
d.setOrgName(o.getName());
});
JoinUtil.joinSplit(voList, platOrgService, PlatDeviceListVO::getOrgPath, PlatOrg::getId, (d, o) -> {
JoinUtil.joinSplit(records, platOrgService, PlatDeviceListVO::getOrgPath, PlatOrg::getId, (d, o) -> {
d.setOrgPathName(StreamUtil.join(o, PlatOrg::getName));
});
return PageUtil.toPageVO(voList, page);
return PageUtil.toPageVO(records, page);
}
......
......@@ -906,6 +906,10 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder
public List<PlatDevice> getFallDevice(String id) {
PlatElder platElder = getById(id);
if (platElder == null) {
return null;
}
if (StringUtils.isBlank(platElder.getBedId())) {
return null;
}
......
......@@ -66,4 +66,8 @@ public interface PlatRoomService extends IService<PlatRoom> {
List<WorkStationInstitutionRoomVO> workStationList(WorkStationQueryDTO dto);
Page<WorkStationInstitutionRoomVO> workStationPage(Page<WorkStationQueryDTO> objectPage, WorkStationQueryDTO data);
List<PlatSpaceAndRoomVO> spaceList(List<String> orgIds);
List<PlatSpaceAndRoomVO> roomList(List<String> orgIds);
}
......@@ -165,8 +165,13 @@ public class PlatRoomDynamicServiceImpl implements PlatRoomDynamicService {
return new ArrayList<>();
}
List<String> orgIds = orgs.stream().map(PlatOrg::getId).collect(Collectors.toList());
//获取空间及房间
List<PlatSpaceAndRoomVO> list = platRoomService.spaceAndRoomList(orgIds);
//获取空间
List<PlatSpaceAndRoomVO> spaceList = platRoomService.spaceList(orgIds);
List<PlatSpaceAndRoomVO> roomList = platRoomService.roomList(orgIds);
List<PlatSpaceAndRoomVO> list = new ArrayList<>();
list.addAll(spaceList);
list.addAll(roomList);
//父级
List<PlatSpaceAndRoomVO> listParent = list.stream().filter(item-> StringUtil.isEmpty(item.getParentId())).collect(Collectors.toList());
......
......@@ -179,5 +179,14 @@ public class PlatRoomServiceImpl extends ServiceImpl<PlatRoomMapper, PlatRoom> i
return baseMapper.workStationPage(page,params);
}
@Override
public List<PlatSpaceAndRoomVO> spaceList(List<String> orgIds) {
return baseMapper.spaceList(orgIds);
}
@Override
public List<PlatSpaceAndRoomVO> roomList(List<String> orgIds) {
return baseMapper.roomList(orgIds); }
}
......@@ -83,5 +83,15 @@ public class PlatDeviceListVO extends BaseTenantDTO {
private String tenantName;
private String spaceParentPath;
private String spaceParentPathName;
private String spaceName;
private String roomName;
private String bedName;
}
......@@ -13,7 +13,9 @@ import lombok.Data;
*/
@Data
@ApiModel("PlatBedPanoramaVO参数")
public class PlatBedPanoramaVO extends BaseIdDTO {
public class PlatBedPanoramaVO{
private String id;
@ApiModelProperty("空间全路径id")
private String spacePath;
......
......@@ -3,8 +3,23 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.makeit.mapper.platform.space.PlatBedMapper">
<resultMap id="BaseResultMap" type="com.makeit.entity.platform.space.PlatBed">
<id property="id" column="id" jdbcType="VARCHAR"/>
<result property="tenantId" column="tenant_id" jdbcType="VARCHAR"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="roomId" column="room_id" jdbcType="VARCHAR"/>
<result property="spaceId" column="space_id" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="VARCHAR"/>
<result property="sort" column="sort" jdbcType="VARCHAR"/>
<result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
<result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
<result property="update_by" column="update_by" jdbcType="VARCHAR"/>
<result property="sort" column="sort" jdbcType="VARCHAR"/>
<result property="delFlag" column="del_flag" jdbcType="CHAR"/>
</resultMap>
<select id="selectBySpaceIdAndStatus" resultType="com.makeit.vo.platform.space.PlatBedPanoramaVO">
SELECT pb.id,pb.`status`,pb.name bedName ,pm.`name` roomName,pm.space_path,pe.name as elderName,pe.id as elderId,pm.id as roomId
SELECT pb.id,pb.`status`,pb.name as bedName ,pm.`name` as roomName,pm.space_path as spacePath,pe.name as elderName,pe.id as elderId,pm.id as roomId
FROM `plat_bed` pb
LEFT JOIN plat_room pm on pb.room_id = pm.id
LEFT JOIN plat_elder pe on pe.bed_id = pb.id
......@@ -20,7 +35,7 @@
</select>
<select id="selectByRoomIdAndStatus" resultType="com.makeit.vo.platform.space.PlatBedPanoramaVO">
SELECT pb.id,pb.`status`,pb.name bedName ,pm.`name` roomName,pm.space_path,pe.name as elderName,pe.id as elderId,pm.id as roomId
SELECT pb.id,pb.`status`,pb.name as bedName ,pm.`name` as roomName,pm.space_path as spacePath,pe.name as elderName,pe.id as elderId,pm.id as roomId
FROM `plat_bed` pb
LEFT JOIN plat_room pm on pb.room_id = pm.id
LEFT JOIN plat_elder pe on pe.bed_id = pb.id and pe.del_flag = 0
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.makeit.mapper.platform.device.PlatDeviceMapper">
<select id="getDeviceIdsBySpaceId" resultType="com.makeit.vo.platform.device.PlatDeviceListVO">
select
distinct
pd.*,
ps.parent_path as spaceParentPath,
ps.name as spaceName,
pr.name as roomName,
pb.name as bedName
from plat_device pd
left join plat_room_bed_device prbd on (pd.id = prbd.device_id and prbd.del_flag = 0)
left join plat_room pr on (pr.id = prbd.room_id and pr.del_flag = 0 )
left join plat_bed pb on ( pb.id = prbd.bed_id and pb.del_flag = 0)
left join plat_space ps on (ps.id = pr.space_id and ps.del_flag = 0)
<where>
pd.del_flag = 0
<if test="param.spaceId != null and param.spaceId != ''">
and ( FIND_IN_SET(#{param.spaceId},ps.parent_path) or ps.id = #{param.spaceId})
</if>
<if test="param.oriDeviceId != null and param.oriDeviceId != ''">
and pd.ori_device_id like concat('%',#{param.oriDeviceId},'%')
</if>
<if test="param.name != null and param.name != ''">
and pd.name like concat('%',#{param.name},'%')
</if>
<if test="param.status != null and param.status != '' ">
and pd.status = #{param.status}
</if>
<if test="param.productName != null and param.productName != '' ">
and pd.product_name like concat('%',#{param.productName},'%')
</if>
<if test="param.productId != null and param.productId != '' ">
and pd.product_id = #{param.productId}
</if>
<if test="param.orgId != null and param.orgId != '' ">
and pd.org_id = #{param.orgId}
</if>
</where>
order by pd.update_date desc,prbd.update_date desc
</select>
</mapper>
......@@ -4,6 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.makeit.mapper.platform.space.PlatRoomMapper">
<select id="spaceAndRoomList" resultType="com.makeit.vo.platform.space.PlatSpaceAndRoomVO">
SELECT ps.id,ps.`name`,ps.parent_id as parentId,'1' as type FROM plat_space ps
<where>
ps.del_flag = 0
......@@ -27,6 +28,7 @@
</if>
</where>
</select>
<select id="workStationList" resultType="com.makeit.vo.platform.workstation.WorkStationInstitutionRoomVO">
......@@ -81,5 +83,35 @@
</where>
</select>
<select id="spaceList" resultType="com.makeit.vo.platform.space.PlatSpaceAndRoomVO">
SELECT ps.id,ps.`name`,ps.parent_id as parentId,'1' as type FROM plat_space ps
<where>
ps.del_flag = 0
<if test="orgIds != null and orgIds.size()>0 ">
AND ps.org_id IN
<foreach collection="orgIds" item="item" separator="," open="(" close=")" index="">
#{item}
</foreach>
</if>
</where>
</select>
<select id="roomList" resultType="com.makeit.vo.platform.space.PlatSpaceAndRoomVO">
SELECT pr.id,pr.`name`,pr.space_id as parentId,'2' as type FROM plat_room pr
LEFT JOIN plat_space p ON p.id = pr.space_id
<where>
pr.del_flag = 0
<if test="orgIds != null and orgIds.size()>0 ">
AND p.org_id IN
<foreach collection="orgIds" item="item" separator="," open="(" close=")" index="">
#{item}
</foreach>
</if>
</where>
</select>
</mapper>
......@@ -2,16 +2,24 @@ package com.makeit.mqtt;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
import com.makeit.entity.platform.alarm.PlatAlarmConfig;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.saas.PlatTenant;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.enums.DeviceState;
import com.makeit.module.iot.vo.DeviceInfo;
import com.makeit.module.iot.vo.HeaderInfo;
import com.makeit.service.platform.alarm.alarmStrategy.IAlarm;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.AlarmConfigCacheUtil;
import com.makeit.utils.DeviceCacheUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
......@@ -21,10 +29,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StopWatch;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Component
......@@ -43,6 +53,11 @@ public class PushCallback implements MqttCallback {
@Autowired
private List<IAlarm> alarmList;
@Autowired
private PlatDeviceService platDeviceService;
@Autowired
private PlatTenantService platTenantService;
@Override
public void connectionLost(Throwable cause) {
......@@ -82,12 +97,16 @@ public class PushCallback implements MqttCallback {
public void checkAlarm(DeviceInfo device) {
HeaderInfo headers = device.getHeaders();
List<HeaderInfo.Bind> bindings = headers.getBindings();
for (HeaderInfo.Bind binding : bindings) {
try {
String iot_tenantId = binding.getId();
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
String messageType = device.getMessageType();
//更新设备状态
updateDeviceStatus(messageType,deviceId,iot_tenantId);
JSONObject properties = device.getProperties();
......@@ -120,6 +139,8 @@ public class PushCallback implements MqttCallback {
}
}
}
stopWatch.stop();
logger.info(stopWatch.prettyPrint());
}catch (Exception e){
......@@ -130,6 +151,35 @@ public class PushCallback implements MqttCallback {
}
@Transactional
public void updateDeviceStatus(String messageType, String deviceId, String iot_tenantId) {
if(StringUtils.equalsAnyIgnoreCase(messageType, DeviceState.offline.getValue(),DeviceState.online.getValue())){
LambdaQueryWrapper<PlatTenant> platTenantLambdaQueryWrapper = new LambdaQueryWrapper<>();
platTenantLambdaQueryWrapper.eq(PlatTenant::getIotOrgId,iot_tenantId);
List<PlatTenant> platTenants = platTenantService.list(platTenantLambdaQueryWrapper);
if(CollectionUtils.isEmpty(platTenants)){
return;
}
List<String> tenantIdList = platTenants.stream().map(BaseEntity::getId).collect(Collectors.toList());
LambdaQueryWrapper<PlatDevice> deviceLambdaQueryWrapper = new LambdaQueryWrapper<>();
deviceLambdaQueryWrapper.eq(PlatDevice::getOriDeviceId,deviceId)
.in(BaseBusEntity::getTenantId,tenantIdList);
List<PlatDevice> deviceList = platDeviceService.list(deviceLambdaQueryWrapper);
if(CollectionUtils.isEmpty(deviceList)){
return;
}
for (PlatDevice platDevice : deviceList) {
platDevice.setStatus(messageType.toLowerCase());
}
platDeviceService.updateBatchById(deviceList);
deviceCacheUtil.putAll(deviceList);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment