|
|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
package cn.iocoder.yudao.module.iot.service.devicemodelattribute;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService;
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattributetype.DeviceAttributeTypeDO;
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.mysql.deviceattributetype.DeviceAttributeTypeMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.iot.service.device.TDengineService;
|
|
|
|
|
@ -26,6 +29,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.mysql.devicemodelattribute.DeviceModelAttributeMapper;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
|
|
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -47,6 +51,9 @@ public class DeviceModelAttributeServiceImpl implements DeviceModelAttributeServ
|
|
|
|
|
@Resource
|
|
|
|
|
private DeviceAttributeTypeMapper deviceAttributeTypeMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpProductUnitService productUnitService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Long createDeviceModelAttribute(DeviceModelAttributeSaveReqVO createReqVO) {
|
|
|
|
|
@ -109,9 +116,33 @@ public class DeviceModelAttributeServiceImpl implements DeviceModelAttributeServ
|
|
|
|
|
// List<DeviceAttributeTypeDO> attributeTypes = deviceAttributeTypeMapper.selectList();
|
|
|
|
|
// Map<Long, String> typeNameMap = attributeTypes.stream()
|
|
|
|
|
// .collect(Collectors.toMap(DeviceAttributeTypeDO::getId, DeviceAttributeTypeDO::getName));
|
|
|
|
|
|
|
|
|
|
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
|
|
|
|
|
pageResult.getList().stream()
|
|
|
|
|
.map(DeviceModelAttributeDO::getDataUnit)
|
|
|
|
|
.filter(StringUtils::isNotEmpty)
|
|
|
|
|
.map(str -> {
|
|
|
|
|
try {
|
|
|
|
|
return Long.valueOf(str.trim());
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.collect(Collectors.toSet())
|
|
|
|
|
);
|
|
|
|
|
// 转换并设置类型名称
|
|
|
|
|
PageResult<DeviceModelAttributeRespVO> respPageResult = BeanUtils.toBean(pageResult, DeviceModelAttributeRespVO.class);
|
|
|
|
|
PageResult<DeviceModelAttributeRespVO> respPageResult = BeanUtils.toBean(pageResult, DeviceModelAttributeRespVO.class, deviceModelAttribute -> {
|
|
|
|
|
String dataUnitStr = deviceModelAttribute.getDataUnit();
|
|
|
|
|
if (StringUtils.isNotBlank(dataUnitStr)) {
|
|
|
|
|
try {
|
|
|
|
|
Long dataUnitId = Long.valueOf(dataUnitStr.trim());
|
|
|
|
|
MapUtils.findAndThen(unitMap, dataUnitId,
|
|
|
|
|
unit -> deviceModelAttribute.setDataUnitName(unit.getName()));
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// respPageResult.getList().forEach(item -> {
|
|
|
|
|
// String typeName = typeNameMap.get(item.getAttributeType());
|
|
|
|
|
|