From 7a274357052080ffd099b83628f8275402df2124 Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Tue, 19 Mar 2024 16:52:30 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=AB=AF=E8=AE=BE=E7=BD=AE=E5=B1=9E=E6=80=A7=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E5=A4=87vo=E6=B7=BB=E5=8A=A0=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SpaceDeviceController.java | 18 ++++++++++++++++++ .../dto/vo/deviceinfo/DeviceInfoVo.java | 3 +++ 2 files changed, 21 insertions(+) diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java index 6e547a51..6be0e00d 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java @@ -19,11 +19,14 @@ import cc.iotkit.common.utils.JsonUtils; import cc.iotkit.data.manager.ICategoryData; import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.manager.dto.bo.device.ServiceInvokeBo; +import cc.iotkit.manager.dto.bo.device.SetDeviceServicePorpertyBo; import cc.iotkit.manager.dto.vo.product.ProductVo; import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; import cc.iotkit.manager.model.vo.FindDeviceVo; import cc.iotkit.manager.model.vo.SpaceDeviceVo; import cc.iotkit.manager.service.*; +import cc.iotkit.model.InvokeResult; import cc.iotkit.model.UserInfo; import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.product.Category; @@ -70,6 +73,9 @@ public class SpaceDeviceController { private IUserInfoData userInfoData; @Autowired private IDeviceManagerService deviceServiceImpl; + //赋予应用端设备的服务和属性设置,关于应用的接口及相关权限设计后续完善,先打通链路 + @Autowired + private DeviceCtrlService deviceCtrlService; /** * 我最近使用的设备列表 @@ -223,6 +229,18 @@ public class SpaceDeviceController { return deviceServiceImpl.getDetail(request.getData()); } + @ApiOperation("调用设备服务") + @PostMapping("/invokeService") + public InvokeResult invokeService(@RequestBody @Validated Request request) { + return new InvokeResult(deviceCtrlService.invokeService(request.getData().getDeviceId(), request.getData().getService(), request.getData().getArgs())); + } + + @ApiOperation(value = "设备属性设置") + @PostMapping("/setProperty") + public InvokeResult setProperty(@RequestBody @Validated Request request) { + return new InvokeResult(deviceCtrlService.setProperty(request.getData().getDeviceId(), request.getData().getArgs())); + } + /** * REMOVE_DEVICE * 往指定房间中添加设备 diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoVo.java index 97684427..79c3142a 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoVo.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoVo.java @@ -79,4 +79,7 @@ public class DeviceInfoVo implements Serializable { @ApiModelProperty(value = "所属分组") private Map group; + @ApiModelProperty(value = "位置信息") + private DeviceInfo.Locate locate; + } From de49f494c0376fcf8a18b1ace2247a6b1b9b7081 Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Tue, 19 Mar 2024 18:40:57 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=A7=BB=E9=99=A4=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iotkit/manager/controller/SpaceDeviceController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java index 6be0e00d..20a1efb0 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java @@ -304,15 +304,15 @@ public class SpaceDeviceController { /** * 移除房间中的设备 */ - @DeleteMapping(Constants.API_SPACE.REMOVE_DEVICE) - public void removeDevice(String deviceId) { - SpaceDevice spaceDevice = spaceDeviceService.findByDeviceId(deviceId); + @PostMapping(Constants.API_SPACE.REMOVE_DEVICE) + public void removeDevice(@RequestBody @Validated Request request) { + SpaceDevice spaceDevice = spaceDeviceService.findByDeviceId(request.getData()); if (spaceDevice == null) { throw new BizException(ErrCode.SPACE_DEVICE_NOT_FOUND); } spaceDeviceService.deleteById(spaceDevice.getId()); - DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(request.getData()); UserInfo userInfo = userInfoData.findById(LoginHelper.getUserId()); if (userInfo == null) { throw new BizException(ErrCode.USER_NOT_FOUND); From 71afcad7ff19c029c5b431448f5895b884a4ea06 Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Wed, 27 Mar 2024 17:27:13 +0800 Subject: [PATCH 3/6] =?UTF-8?q?feat:app=E6=8E=A5=E5=8F=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=A7=84=E5=88=99=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SpaceDeviceController.java | 39 +++++++++++++++++++ .../controller/UserInfoController.java | 6 +++ .../iotkit/web/service/SysLoginService.java | 5 +-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java index 20a1efb0..99b7b36c 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java @@ -9,6 +9,8 @@ */ package cc.iotkit.manager.controller; +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Request; import cc.iotkit.common.constant.Constants; import cc.iotkit.common.enums.ErrCode; @@ -21,7 +23,9 @@ import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IUserInfoData; import cc.iotkit.manager.dto.bo.device.ServiceInvokeBo; import cc.iotkit.manager.dto.bo.device.SetDeviceServicePorpertyBo; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleInfoBo; import cc.iotkit.manager.dto.vo.product.ProductVo; +import cc.iotkit.manager.dto.vo.ruleinfo.RuleInfoVo; import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; import cc.iotkit.manager.model.vo.FindDeviceVo; import cc.iotkit.manager.model.vo.SpaceDeviceVo; @@ -70,6 +74,8 @@ public class SpaceDeviceController { @Autowired private DataOwnerService dataOwnerService; @Autowired + private IRuleEngineService ruleEngineService; + @Autowired private IUserInfoData userInfoData; @Autowired private IDeviceManagerService deviceServiceImpl; @@ -229,6 +235,39 @@ public class SpaceDeviceController { return deviceServiceImpl.getDetail(request.getData()); } + @ApiOperation("保存规则") + @PostMapping("/saveRuleEngine") + public boolean saveRuleEngine(@RequestBody @Validated Request ruleInfoBo) { + return ruleEngineService.saveRule(ruleInfoBo.getData()); + } + + @ApiOperation("删除规则") + @PostMapping("/delRuleEngine") + public boolean delRuleEngine(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.deleteRule(ruleId); + } + + @ApiOperation("停止规则") + @PostMapping("/stopRuleEngine") + public boolean stopRuleEngine(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.pauseRule(ruleId); + } + + @ApiOperation("恢复规则") + @PostMapping("/startRuleEngine") + public boolean startRuleEngine(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.resumeRule(ruleId); + } + + @ApiOperation("规则列表") + @PostMapping("/ruleEngineList") + public Paging ruleEngineList(@Validated @RequestBody PageRequest request) { + return ruleEngineService.selectPageList(request); + } + @ApiOperation("调用设备服务") @PostMapping("/invokeService") public InvokeResult invokeService(@RequestBody @Validated Request request) { diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/UserInfoController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/UserInfoController.java index 97d2d211..dd7d8e79 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/UserInfoController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/UserInfoController.java @@ -13,6 +13,7 @@ import cc.iotkit.common.constant.Constants; import cc.iotkit.common.enums.ErrCode; import cc.iotkit.common.exception.BizException; import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.utils.ReflectUtil; import cc.iotkit.data.manager.IHomeData; import cc.iotkit.data.manager.ISpaceData; @@ -128,6 +129,11 @@ public class UserInfoController { userInfoData.deleteById(id); } + @PostMapping("/getUserInfo") + public UserInfo getUserInfo() { + return userInfoData.findById(LoginHelper.getUserId()); + } + @PostMapping("/client/user/save") public void saveClientUser(@RequestBody UserInfo user) { UserInfo oldUser = userInfoData.findById(user.getId()); diff --git a/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java b/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java index 841d6a93..672daa5c 100644 --- a/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java +++ b/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java @@ -149,9 +149,7 @@ public class SysLoginService { if(sysApp==null){ throw new BizException("该应用未授权注册"); } - String url=authUrl+"?appid="+appId+"&secret="+sysApp.getAppSecret()+"&js_code="+xcxCode+"&grant_type=authorization_code"; - String ret=WeChatUtil.httpRequest(url,"GET",null); - String openid = JsonUtils.parseMap(ret).getStr("openid"); + String openid = WeChatUtil.getOpenId(appId,sysApp.getAppSecret(),xcxCode); UserInfo user = null; LoginHelper.setTenantId(sysApp.getTenantId()); try { @@ -319,6 +317,7 @@ public class SysLoginService { user.setType(UserInfo.USER_TYPE_CLIENT); user.setUid(openid); user.setRoles(Collections.singletonList(Constants.ROLE_CLIENT)); + user.setNickName("微信用户"); user.setSecret(AuthUtil.enCryptPwd(Constants.PWD_CLIENT_USER)); user.setTenantId(tenantId); user = userInfoData.save(user); From ae85ef7a06c0aa42bbbbd0402d788a0b3068c07f Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Sun, 7 Apr 2024 16:00:23 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat:=E5=BA=94=E7=94=A8=E7=AB=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iotkit/data/service/DeviceInfoDataImpl.java | 15 ++++++--------- .../manager/controller/SpaceDeviceController.java | 10 ++++++++++ .../cc/iotkit/manager/model/vo/SpaceDeviceVo.java | 6 ++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java index f39ff7fb..3f076a52 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java @@ -4,7 +4,6 @@ import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.common.utils.ReflectUtil; -import cc.iotkit.common.utils.StreamUtils; import cc.iotkit.data.dao.*; import cc.iotkit.data.manager.ICategoryData; import cc.iotkit.data.manager.IDeviceInfoData; @@ -17,10 +16,7 @@ import cc.iotkit.model.device.message.DevicePropertyCache; import cc.iotkit.model.product.Category; import cc.iotkit.model.product.Product; import cc.iotkit.model.stats.DataItem; -import cc.iotkit.model.system.SysDept; -import cc.iotkit.model.system.SysUser; import cn.hutool.core.util.ObjectUtil; -import com.querydsl.core.types.Expression; import com.querydsl.core.types.Predicate; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQuery; @@ -41,8 +37,6 @@ import static cc.iotkit.data.model.QTbDeviceGroupMapping.tbDeviceGroupMapping; import static cc.iotkit.data.model.QTbDeviceInfo.tbDeviceInfo; import static cc.iotkit.data.model.QTbDeviceSubUser.tbDeviceSubUser; import static cc.iotkit.data.model.QTbProduct.tbProduct; -import static cc.iotkit.data.model.QTbSysDept.tbSysDept; -import static cc.iotkit.data.model.QTbSysUser.tbSysUser; @Primary @Service @@ -485,8 +479,10 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData buildQuery(Predicate predicate) { - List devices = jpaQueryFactory.select(Projections.bean(TbDeviceInfo.class, - tbDeviceInfo.deviceId, tbDeviceInfo.deviceName, tbDeviceInfo.state )) + List devices = jpaQueryFactory.select(Projections.bean(TbDeviceInfo.class,tbDeviceInfo.uid, + tbDeviceInfo.deviceId, tbDeviceInfo.productKey,tbDeviceInfo.deviceName, tbDeviceInfo.state,tbDeviceInfo.createAt, + tbDeviceInfo.id,tbDeviceInfo.onlineTime,tbDeviceInfo.parentId,tbDeviceInfo.latitude,tbDeviceInfo.longitude,tbDeviceInfo.model, + tbDeviceInfo.offlineTime,tbDeviceInfo.secret)) .from(tbDeviceInfo) .where(predicate).fetch(); return MapstructUtils.convert(devices, DeviceInfo.class); @@ -495,7 +491,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData tbDeviceInfo.id.eq(device.getId())) - .and(ObjectUtil.isNotNull(device.getState().isOnline()), () -> tbDeviceInfo.state.eq(device.getState().isOnline() ? "online" : "offline")) + .and(ObjectUtil.isNotNull(device.getDeviceName()), () -> tbDeviceInfo.deviceName.eq(device.getDeviceName())) + .and(ObjectUtil.isNotNull(device.getState()), () -> tbDeviceInfo.state.eq(device.getState().isOnline() ? "online" : "offline")) .build(); } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java index 99b7b36c..6345988e 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java @@ -17,10 +17,12 @@ import cc.iotkit.common.enums.ErrCode; import cc.iotkit.common.exception.BizException; import cc.iotkit.common.satoken.utils.AuthUtil; import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.thing.ThingModelMessage; import cc.iotkit.common.utils.JsonUtils; import cc.iotkit.data.manager.ICategoryData; import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.manager.dto.bo.device.DeviceLogQueryBo; import cc.iotkit.manager.dto.bo.device.ServiceInvokeBo; import cc.iotkit.manager.dto.bo.device.SetDeviceServicePorpertyBo; import cc.iotkit.manager.dto.bo.ruleinfo.RuleInfoBo; @@ -93,6 +95,12 @@ public class SpaceDeviceController { return null; } + @ApiOperation("设备日志") + @PostMapping("/deviceLogs") + public Paging logs(@Validated @RequestBody PageRequest request) { + return deviceServiceImpl.logs(request); + } + /** * 获取用户收藏设备列表 */ @@ -152,6 +160,7 @@ public class SpaceDeviceController { .deviceId(sd.getDeviceId()) .deviceName(device.getDeviceName()) .name(sd.getName()) + .createTime(sd.getCreateTime()) .spaceId(sd.getSpaceId()) .spaceName(space.getName()) .productKey(device.getProductKey()) @@ -192,6 +201,7 @@ public class SpaceDeviceController { List findDeviceVos = new ArrayList<>(); DeviceInfo query=new DeviceInfo(); query.setDeviceName(mac); + query.setState(null); List devices = deviceInfoData.findAllByCondition(query); if(devices == null){ return findDeviceVos; diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceDeviceVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceDeviceVo.java index fd7ce45c..3e30a244 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceDeviceVo.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceDeviceVo.java @@ -14,6 +14,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -85,6 +86,11 @@ public class SpaceDeviceVo { */ private String categoryName; + /** + * 创建时间 + */ + private Date createTime; + /** * 是否收藏 */ From 28248724215767c15afcef412ab89135e4304300 Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Mon, 8 Apr 2024 18:41:40 +0800 Subject: [PATCH 5/6] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E7=89=A9=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E6=97=A5=E5=BF=97=E6=8C=89=E8=AE=BE=E5=A4=87=E9=9B=86?= =?UTF-8?q?=E5=90=88=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temporal/IThingModelMessageData.java | 12 ++++++ .../es/service/ThingModelMessageDataImpl.java | 21 ++++++++++ .../service/ThingModelMessageDataImpl.java | 5 +++ .../td/service/ThingModelMessageDataImpl.java | 40 +++++++++++++++++++ .../controller/SpaceDeviceController.java | 7 +++- .../manager/service/ISpaceDeviceService.java | 6 +++ .../service/impl/SpaceDeviceServiceImpl.java | 17 ++++++++ 7 files changed, 107 insertions(+), 1 deletion(-) diff --git a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java index 2155c135..a0f8c966 100644 --- a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java +++ b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java @@ -38,6 +38,18 @@ public interface IThingModelMessageData { */ List getDeviceMessageStatsWithUid(String uid, long start, long end); + /** + * 查询指定设备集类型并按时间倒序 + * + * @param deviceIds 设备ids + * @param type 消息类型 + * @param identifier 标识符 + * @param page 页码 + * @param size 页大小 + */ + Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, int page, int size); + void add(ThingModelMessage msg); long count(); diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java index f303588b..bfc22e55 100644 --- a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java @@ -67,6 +67,27 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData { .collect(Collectors.toList())); } + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, + int page, int size) { + BoolQueryBuilder builder = QueryBuilders.boolQuery(); + builder.must(QueryBuilders.termQuery("type", type)); + if (deviceIds.size()>0) { + builder.must(QueryBuilders.termsQuery("deviceId", deviceIds)); + } + if (StringUtils.isNotBlank(identifier)) { + builder.must(QueryBuilders.matchPhraseQuery("identifier", identifier)); + } + NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(builder) + .withPageable(PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("time")))) + .build(); + SearchHits result = template.search(query, DocThingModelMessage.class); + return new Paging<>(result.getTotalHits(), result.getSearchHits().stream() + .map(m -> MapstructUtils.convert(m.getContent(), ThingModelMessage.class)) + .collect(Collectors.toList())); + } + @Override public List getDeviceMessageStatsWithUid(String uid, long start, long end) { BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/ThingModelMessageDataImpl.java index b97fc6e3..e417a141 100644 --- a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/ThingModelMessageDataImpl.java +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/ThingModelMessageDataImpl.java @@ -33,6 +33,11 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData { return new ArrayList<>(); } + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, String identifier, int page, int size) { + return new Paging<>(); + } + @Override public void add(ThingModelMessage msg) { } diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java index 85ff48a3..88258a00 100644 --- a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java @@ -72,6 +72,46 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData { .collect(Collectors.toList())); } + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, + int page, int size) { + String sql = "select time,mid,product_key,device_name,type,identifier,code,data,report_time " + + "from thing_model_message where type=? %s order by time desc limit %d offset %d"; + + //构建动态条件 + List args = new ArrayList<>(); + args.add(type); + StringBuilder sbCond = new StringBuilder(); + if (deviceIds.size()>0) { + sbCond.append(" and deviceIds in (?) "); + args.add(String.join(",",deviceIds)); + } + if (StringUtils.isNotBlank(identifier)) { + sbCond.append("and identifier=? "); + args.add(identifier); + } + + sql = String.format(sql, sbCond.toString(), size, (page - 1) * size); + List ruleLogs = tdTemplate.query(sql, + new BeanPropertyRowMapper<>(TbThingModelMessage.class), + args.toArray() + ); + + sql = String.format("select count(*) from thing_model_message where type=? %s", + sbCond.toString()); + List counts = tdTemplate.queryForList(sql, Long.class, args.toArray()); + long count = !counts.isEmpty() ? counts.get(0) : 0; + + return new Paging<>(count, ruleLogs.stream().map(r -> + new ThingModelMessage(r.getTime().toString(), r.getMid(), + r.getDeviceId(), r.getProductKey(), r.getDeviceName(), + r.getUid(), r.getType(), r.getIdentifier(), r.getCode(), + JsonUtils.parseObject(r.getData(), Map.class), + r.getTime(), r.getReportTime())) + .collect(Collectors.toList())); + } + @Override public List getDeviceMessageStatsWithUid(String uid, long start, long end) { String sql = "select time,count(*) as data from(" + diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java index 6345988e..8c0cc499 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java @@ -98,7 +98,10 @@ public class SpaceDeviceController { @ApiOperation("设备日志") @PostMapping("/deviceLogs") public Paging logs(@Validated @RequestBody PageRequest request) { - return deviceServiceImpl.logs(request); + Home home = homeService.findByUserIdAndCurrent(LoginHelper.getUserId(), true); + List spaceDevices = spaceDeviceService.findByHomeId(home.getId()); + List devIds=spaceDevices.stream().map((spaceDevice->spaceDevice.getDeviceId())).collect(Collectors.toList()); + return spaceDeviceService.findByTypeAndDeviceIds(devIds,request.getData().getType(),"",request.getPageNum(),request.getPageSize()); } /** @@ -111,6 +114,8 @@ public class SpaceDeviceController { return spaceDevices.stream().map((this::parseSpaceDevice)).collect(Collectors.toList()); } + + /** * 收藏/取消收藏设备 */ diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceDeviceService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceDeviceService.java index 1cd50136..64ac89f6 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceDeviceService.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceDeviceService.java @@ -1,5 +1,7 @@ package cc.iotkit.manager.service; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.thing.ThingModelMessage; import cc.iotkit.model.space.SpaceDevice; import java.util.List; @@ -23,4 +25,8 @@ public interface ISpaceDeviceService { void deleteById (Long id); SpaceDevice findById (Long id); + + Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, + int page, int size); } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceDeviceServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceDeviceServiceImpl.java index 86732691..760cd50d 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceDeviceServiceImpl.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceDeviceServiceImpl.java @@ -1,8 +1,14 @@ package cc.iotkit.manager.service.impl; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.StringUtils; import cc.iotkit.data.manager.ISpaceDeviceData; import cc.iotkit.manager.service.ISpaceDeviceService; import cc.iotkit.model.space.SpaceDevice; +import cc.iotkit.temporal.IThingModelMessageData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,6 +24,9 @@ public class SpaceDeviceServiceImpl implements ISpaceDeviceService { @Autowired private ISpaceDeviceData spaceDeviceData; + @Autowired + private IThingModelMessageData thingModelMessageData; + @Override public List findByHomeIdAndCollect(Long homeId, boolean collect) { return spaceDeviceData.findByHomeIdAndCollect(homeId,collect); @@ -52,4 +61,12 @@ public class SpaceDeviceServiceImpl implements ISpaceDeviceService { public SpaceDevice findById(Long id) { return spaceDeviceData.findById(id); } + + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, String identifier, int page, int size) { + if(StringUtils.isEmpty(type)){ + throw new BizException(ErrCode.PARAMS_EXCEPTION); + } + return thingModelMessageData.findByTypeAndDeviceIds(deviceIds,type,identifier,page,size); + } } From 6fb56c3f2878ee598cc648d4f9df8dfd114bc9a5 Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Wed, 10 Apr 2024 11:36:09 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=E7=89=A9=E6=A8=A1=E5=9E=8B=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/init/thingModel.json | 126 ++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/data/init/thingModel.json b/data/init/thingModel.json index ab51831c..7ae5810c 100755 --- a/data/init/thingModel.json +++ b/data/init/thingModel.json @@ -988,70 +988,76 @@ "productKey": "bGdZt8ffBETtsirm", "model": { "properties": [ - { - "identifier": "temp", - "dataType": { - "type": "int32", - "specs": { - "min": "17", - "max": "32" - } + { + "identifier": "temp", + "dataType": { + "type": "int32", + "specs": { + "min": "17", + "max": "32" + } + }, + "name": "温度", + "accessMode": "rw", + "description": "温度", + "unit": "℃" }, - "name": "温度", - "accessMode": "rw" - }, - { - "identifier": "swing_modes", - "dataType": { - "type": "bool", - "specs": { - "0": "关", - "1": "开" - } + { + "identifier": "swing_modes", + "dataType": { + "type": "enum", + "specs": { + "off": "关", + "on": "开" + } + }, + "name": "扫风开关", + "accessMode": "rw", + "description": "扫风开关" }, - "name": "扫风开关", - "accessMode": "rw" - }, - { - "identifier": "modes", - "dataType": { - "type": "enum", - "specs": { - "0": "制热", - "1": "关闭", - "2": "制冷", - "3": "送风" - } + { + "identifier": "modes", + "dataType": { + "type": "enum", + "specs": { + "heat": "制热", + "off": "关闭", + "cool": "制冷", + "fan_only": "送风" + } + }, + "name": "模式", + "accessMode": "rw", + "description": "模式" }, - "name": "模式", - "accessMode": "rw" - }, - { - "identifier": "fan_modes", - "dataType": { - "type": "enum", - "specs": { - "0": "高", - "1": "中", - "2": "低" - } + { + "identifier": "fan_modes", + "dataType": { + "type": "enum", + "specs": { + "high": "高", + "medium": "中", + "low": "低" + } + }, + "name": "风模式", + "accessMode": "rw", + "description": "风模式" }, - "name": "风模式", - "accessMode": "rw" - }, - { - "identifier": "presets_modes", - "dataType": { - "type": "enum", - "specs": { - "0": "节能", - "1": "睡眠", - "2": "活动" - } - }, - "name": "预设模式", - "accessMode": "rw" - } + { + "identifier": "preset_modes", + "dataType": { + "type": "enum", + "specs": { + "eco": "节能", + "sleep": "睡眠", + "activity": "活动" + } + }, + "name": "预设模式", + "accessMode": "rw", + "description": "预设模式" + } ], "services": [ ],