fix: 设备信息查询,postgrep报错

V0.5.x
jay 2023-08-07 19:09:22 +08:00
parent bfdf904e1c
commit 211be5b22e
1 changed files with 18 additions and 18 deletions

View File

@ -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);
} }