fix: 设备信息查询,postgrep报错
parent
bfdf904e1c
commit
211be5b22e
|
@ -56,7 +56,6 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
|
|
||||||
private final DeviceTagRepository deviceTagRepository;
|
private final DeviceTagRepository deviceTagRepository;
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
|
||||||
|
|
||||||
@Qualifier("productDataCache")
|
@Qualifier("productDataCache")
|
||||||
private final IProductData productData;
|
private final IProductData productData;
|
||||||
|
@ -194,9 +193,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> findSubDeviceIds(String parentId) {
|
public List<String> findSubDeviceIds(String parentId) {
|
||||||
return jdbcTemplate.queryForList(
|
return jpaQueryFactory.select(tbDeviceInfo.deviceId).from(tbDeviceInfo)
|
||||||
"select device_id from device_info " +
|
.where(tbDeviceInfo.parentId.eq(parentId)).fetch();
|
||||||
"where parent_id=?", String.class, parentId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -283,20 +281,19 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
@Override
|
@Override
|
||||||
public List<DataItem> getDeviceStatsByCategory(String uid) {
|
public List<DataItem> getDeviceStatsByCategory(String uid) {
|
||||||
//先按产品统计设备数量
|
//先按产品统计设备数量
|
||||||
String sql = "SELECT COUNT(*) as value,product_key as name from " +
|
JPAQuery<DataItem> query = jpaQueryFactory.select(Projections.bean(DataItem.class,
|
||||||
"device_info %s GROUP BY product_key";
|
tbDeviceInfo.productKey,
|
||||||
List<Object> args = new ArrayList<>();
|
tbDeviceInfo.count()))
|
||||||
|
.from(tbDeviceInfo)
|
||||||
|
.groupBy(tbDeviceInfo.productKey);
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(uid)) {
|
if (StringUtils.isNotBlank(uid)) {
|
||||||
sql = String.format(sql, "where uid=:uid");
|
query.where(tbDeviceInfo.uid.eq(uid));
|
||||||
args.add(uid);
|
|
||||||
} else {
|
|
||||||
sql = String.format(sql, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DataItem> stats = new ArrayList<>();
|
List<DataItem> stats = new ArrayList<>();
|
||||||
|
|
||||||
List<DataItem> rst = jdbcTemplate.query(sql,
|
List<DataItem> rst = query.fetch();
|
||||||
new BeanPropertyRowMapper<>(DataItem.class),
|
|
||||||
args.toArray());
|
|
||||||
for (DataItem item : rst) {
|
for (DataItem item : rst) {
|
||||||
//找到产品对应的品类取出品类名
|
//找到产品对应的品类取出品类名
|
||||||
Product product = productData.findByProductKey(item.getName());
|
Product product = productData.findByProductKey(item.getName());
|
||||||
|
@ -349,8 +346,10 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeGroup(String deviceId, String groupId) {
|
public void removeGroup(String deviceId, String groupId) {
|
||||||
jdbcTemplate.update("delete from device_group_mapping " +
|
jpaQueryFactory.delete(tbDeviceGroupMapping)
|
||||||
"where device_id=? and group_id=?", deviceId, groupId);
|
.where(tbDeviceGroupMapping.deviceId.eq(deviceId)
|
||||||
|
.and(tbDeviceGroupMapping.groupId.eq(groupId)))
|
||||||
|
.execute();
|
||||||
//更新设备数量
|
//更新设备数量
|
||||||
updateGroupDeviceCount(groupId);
|
updateGroupDeviceCount(groupId);
|
||||||
}
|
}
|
||||||
|
@ -358,8 +357,9 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeGroup(String groupId) {
|
public void removeGroup(String groupId) {
|
||||||
jdbcTemplate.update("delete from device_group_mapping " +
|
jpaQueryFactory.delete(tbDeviceGroupMapping)
|
||||||
"where group_id=?", groupId);
|
.where(tbDeviceGroupMapping.groupId.eq(groupId))
|
||||||
|
.execute();
|
||||||
//更新设备数量
|
//更新设备数量
|
||||||
updateGroupDeviceCount(groupId);
|
updateGroupDeviceCount(groupId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue