Commit 19d93d08 by 罗志长

fix: 平台端设备管理列表关联长者

parent 7aeedc74
......@@ -81,6 +81,7 @@ import com.makeit.vo.platform.device.PlatDeviceListVO;
import com.makeit.vo.platform.device.PlatDeviceViewVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -176,6 +177,15 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
List<PlatSpace> platSpaces = platSpaceService.listByIds(spaceIdList);
Map<String, String> spaceIdNameMap = platSpaces.stream().collect(Collectors.toMap(BaseEntity::getId, vo -> vo.getName(), (v1, v2) -> v1));
List<String> deviceIds = StreamUtil.map(records, PlatDeviceListVO::getId);
List<PlatRoomBedDevice> platRoomBedDevices = platRoomBedDeviceService.list(new QueryWrapper<PlatRoomBedDevice>().lambda()
.in(PlatRoomBedDevice::getDeviceId, deviceIds));
List<String> roomIds = StreamUtil.map(platRoomBedDevices, PlatRoomBedDevice::getRoomId).stream().distinct().collect(Collectors.toList());
List<String> bedIds = StreamUtil.filterMap(platRoomBedDevices, b -> b.getBedId() != null, PlatRoomBedDevice::getBedId);
List<PlatElder> roomElders = platElderService.list(new QueryWrapper<PlatElder>().lambda().in(PlatElder::getRoomId, roomIds));
List<PlatElder> bedElders = platElderService.list(new QueryWrapper<PlatElder>().lambda().in(PlatElder::getBedId, bedIds));
Map<String, List<PlatElder>> roomEldersMap = roomElders.stream().collect(Collectors.groupingBy(PlatElder::getRoomId, Collectors.toList()));
Map<String, List<PlatElder>> bedEldersMap = bedElders.stream().collect(Collectors.groupingBy(PlatElder::getBedId, Collectors.toList()));
for (PlatDeviceListVO record : records) {
String spaceParentPath = record.getSpaceParentPath();
......@@ -196,6 +206,14 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
spaceName = spaceName + "-" + record.getBedName();
}
record.setSpaceName(spaceName);
String elderNames = "";
if (PlatDeviceEnum.CategoryEnum.HEART.getValue().equals(record.getCategory())) {
elderNames = bedEldersMap.getOrDefault(record.getBedId(), Lists.newArrayList()).stream().map(PlatElder::getName).collect(Collectors.joining(","));
} else {
elderNames = roomEldersMap.getOrDefault(record.getRoomId(), Lists.newArrayList()).stream().map(PlatElder::getName).collect(Collectors.joining(","));
}
record.setElderName(elderNames);
}
JoinUtil.join(records, platOrgService, PlatDeviceListVO::getOrgId, PlatOrg::getId, (d, o) -> {
......
......@@ -90,8 +90,12 @@ public class PlatDeviceListVO extends BaseTenantDTO {
private String spaceName;
private String roomId;
private String roomName;
private String bedId;
private String bedName;
private String elderName;
......
......@@ -62,20 +62,22 @@
<select id="getDeviceIdsBySpaceIdAndElder" 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,
GROUP_CONCAT(pe.`name`) as elderName
pr.id as roomId,
pb.id as bedId
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')
left join plat_elder pe on (pe.room_id = prbd.room_id and pe.del_flag = '0')
left join plat_elder pe on (pe.space_id = ps.id and pe.del_flag = '0')
<where>
pd.del_flag = 0
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>
......@@ -117,7 +119,6 @@
</if>
</where>
GROUP BY pd.ori_device_id
order by pd.update_date desc,pd.id desc
</select>
......
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