fix:产线列表返回采集设备名称

ck
HuangHuiKang 1 month ago
parent a6031a0c30
commit b31e3ede4f

@ -14,6 +14,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -130,7 +131,10 @@ public interface DeviceMapper extends BaseMapperX<DeviceDO> {
List<DeviceSelectRespVO> selectDeviceSelectList();
// DeviceMapper.java
DeviceDO selectByIdWithDeleted(@Param("id") Long id);
List<DeviceDO> selectListIncludeDeletedByIds(@Param("ids") Collection<Long> ids);
}

@ -150,4 +150,8 @@ public interface DeviceService {
void updateDeviceEnabled(@Valid DeviceUpdateEnabledReqVO updateEnabledReqVO) throws MqttException;
DeviceDO getDeviceByMqttTopic(String topic);
Map<Long, DeviceDO> getMapIncludeDeleted(Collection<Long> ids);
}

@ -1712,4 +1712,19 @@ public class DeviceServiceImpl implements DeviceService {
return deviceMapper.selectDeviceSelectList();
}
@Override
public Map<Long, DeviceDO> getMapIncludeDeleted(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyMap();
}
List<DeviceDO> list = deviceMapper.selectListIncludeDeletedByIds(ids);
return list.stream().collect(Collectors.toMap(
DeviceDO::getId,
Function.identity(),
(a, b) -> a
));
}
}

@ -233,4 +233,18 @@
LIMIT 1
</select>
<select id="selectListIncludeDeletedByIds"
resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO">
SELECT
id,
device_name,
deleted
FROM iot_device
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

@ -125,10 +125,12 @@ public class OrganizationServiceImpl implements OrganizationService {
// 设备台账关联产线
if (updateObj.getMachineId() != null) {
DeviceLedgerDO deviceLedgerDO = deviceLedgerService.getDeviceLedger(updateObj.getMachineId());
if (deviceLedgerDO != null){
deviceLedgerDO.setWorkshop(String.valueOf(updateObj.getParentId()));
deviceLedgerService.updateDeviceLedger(BeanUtils.toBean(deviceLedgerDO, DeviceLedgerSaveReqVO.class));
}
}
}
@Override
public void deleteOrganization(Long id) {
@ -228,39 +230,23 @@ public class OrganizationServiceImpl implements OrganizationService {
return Collections.emptyList();
}
//关联机台
// Map<Long, MachineComponentDO> map = machineComponentService.getMap(
// convertSet(list, OrganizationDO::getMachineId));
//
// return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
// MapUtils.findAndThen(map, item.getMachineId(),
// machine -> item.setMachineName(machine.getName()));
//
// });
//关联设备
Map<Long, DeviceDO> map = deviceService.getMap(
convertSet(list, OrganizationDO::getDvId));
// List<DeviceLedgerDO> deviceLedgerDOList = deviceLedgerService.getDeviceLedgerList();
// Map<Long, DeviceLedgerDO> resultMap = deviceLedgerDOList.stream()
// .filter(Objects::nonNull)
// .collect(Collectors.toMap(
// DeviceLedgerDO::getId,
// Function.identity(),
// (existing, replacement) -> existing // 处理重复key
// ));
// return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
// MapUtils.findAndThen(resultMap, item.getDvId(),
// device -> item.setMachineName(device.getDeviceName()));
// });
Set<Long> dvIds = convertSet(list, OrganizationDO::getDvId);
return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
MapUtils.findAndThen(map, item.getDvId(),
device -> item.setMachineName(device.getDeviceName()));
Map<Long, DeviceDO> deviceMap = deviceService.getMapIncludeDeleted(dvIds);
return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
MapUtils.findAndThen(deviceMap, item.getDvId(), device -> {
String deviceName = device.getDeviceName();
// 按你项目删除标记字段调整,比如 getDeleted()/getIsDeleted()/getStatus()
if (Boolean.TRUE.equals(device.getDeleted())) {
deviceName = deviceName + "(已被删除)";
}
item.setMachineName(deviceName);
});
});
}
@Override
public List<OrganizationRespVO> buildWorkerVOList(List<OrganizationDO> list) {
if (CollUtil.isEmpty(list)) {

Loading…
Cancel
Save