From 211be5b22e7e1cfd0814a97dd58727e23794b9eb Mon Sep 17 00:00:00 2001 From: jay <75509151@qq.com> Date: Mon, 7 Aug 2023 19:09:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2,postgrep=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/service/DeviceInfoDataImpl.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java index 38110b8a..0e441578 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java @@ -56,7 +56,6 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData findSubDeviceIds(String parentId) { - return jdbcTemplate.queryForList( - "select device_id from device_info " + - "where parent_id=?", String.class, parentId); + return jpaQueryFactory.select(tbDeviceInfo.deviceId).from(tbDeviceInfo) + .where(tbDeviceInfo.parentId.eq(parentId)).fetch(); } @Override @@ -283,20 +281,19 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData getDeviceStatsByCategory(String uid) { //先按产品统计设备数量 - String sql = "SELECT COUNT(*) as value,product_key as name from " + - "device_info %s GROUP BY product_key"; - List args = new ArrayList<>(); + JPAQuery query = jpaQueryFactory.select(Projections.bean(DataItem.class, + tbDeviceInfo.productKey, + tbDeviceInfo.count())) + .from(tbDeviceInfo) + .groupBy(tbDeviceInfo.productKey); + if (StringUtils.isNotBlank(uid)) { - sql = String.format(sql, "where uid=:uid"); - args.add(uid); - } else { - sql = String.format(sql, ""); + query.where(tbDeviceInfo.uid.eq(uid)); } + List stats = new ArrayList<>(); - List rst = jdbcTemplate.query(sql, - new BeanPropertyRowMapper<>(DataItem.class), - args.toArray()); + List rst = query.fetch(); for (DataItem item : rst) { //找到产品对应的品类取出品类名 Product product = productData.findByProductKey(item.getName()); @@ -349,8 +346,10 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData