diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/FeedBackEvaluation/FeedBackEvaluationDO.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/FeedBackEvaluation/FeedBackEvaluationDO.java index e4ba057..dbca3b7 100644 --- a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/FeedBackEvaluation/FeedBackEvaluationDO.java +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/FeedBackEvaluation/FeedBackEvaluationDO.java @@ -70,4 +70,5 @@ public class FeedBackEvaluationDO extends TenantModel implements Id { */ private Long tenantId; + private Long customerId; } \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java index 8e1ef86..7c9b77e 100644 --- a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java @@ -59,6 +59,7 @@ public class UserInfo extends TenantModel implements Id, Serializable { */ private String nickName; + /** * 性别 0-未知 1-male,2-female */ @@ -73,7 +74,10 @@ public class UserInfo extends TenantModel implements Id, Serializable { private String address; private String site; - + /** + * 客户账号 + */ + private String userName; /** * 当前家庭Id */ @@ -101,7 +105,7 @@ public class UserInfo extends TenantModel implements Id, Serializable { /** * 用户使用的平台 - * 见:Constants.THIRD_PLATFORM + * 见:Constants.THIRD_PLAT */ private List usePlatforms = new ArrayList<>(); diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java index b8b0ad7..5e018a1 100644 --- a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java @@ -79,5 +79,9 @@ public class AlertConfig extends TenantModel implements Owned { * 创建时间 */ private Long createAt; + /** + * 0短信1微信小程序推送2语音,数据用,隔开 + */ + private String messagePush; } diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java index 81f7d33..00341f4 100644 --- a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java @@ -44,12 +44,15 @@ public class DeviceInfo extends TenantModel implements Owned { private String deviceId; + private String site; + private String name; private Long deptAreaId; /** * 产品key */ private String productKey; + private String productName; private String deviceName; diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java index 571e2d0..075ec60 100644 --- a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java @@ -27,9 +27,11 @@ import cc.iotkit.common.api.Paging; import cc.iotkit.data.ICommonData; import cc.iotkit.model.alert.AlertConfig; +import java.util.List; -public interface IAlertConfigData extends ICommonData { +public interface IAlertConfigData extends ICommonData { + List findByUidAndRuleInfoId(String uid, String ruleInfoId); Paging selectAlertConfigPage(PageRequest request); } diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java index 343569c..0a1918b 100644 --- a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java @@ -38,4 +38,6 @@ public interface IAlertRecordData extends ICommonData { List getAlertRecord(); + + long countByUid(String uid); } diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java index 9eb781a..ff3e68a 100644 --- a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java @@ -112,7 +112,7 @@ public interface IDeviceInfoData extends IOwnedData { * @param page 页码 * @param size 分页大小 */ - Paging findByConditions(String uid, String subUid, String productKey, + Paging findByConditions(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long areaDepeId); diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java index 251c3c8..7518da3 100644 --- a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java @@ -213,9 +213,9 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi } @Override - public Paging findByConditions(String uid, String subUid, String productKey, + public Paging findByConditions(String name,String uid, String subUid, String productKey, String groupId, Boolean state, String keyword, int page, int size,Long deptAreaId) { - return deviceInfoData.findByConditions(uid, subUid, productKey, groupId, state, keyword, page, size,deptAreaId); + return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, state, keyword, page, size,deptAreaId); } @Override diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java index 89c5515..3b835ba 100644 --- a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java @@ -164,8 +164,8 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData { } @Override - public Paging findByConditions(String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId) { - return deviceInfoData.findByConditions(uid, subUid, productKey, groupId, online, keyword, page, size,deptAreaId); + public Paging findByConditions(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId) { + return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, online, keyword, page, size,deptAreaId); } @Override diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java index afa6030..c3785ad 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java @@ -23,8 +23,17 @@ package cc.iotkit.data.dao; import cc.iotkit.data.model.TbAlertConfig; +import cc.iotkit.data.model.TbSysDictData; +import cc.iotkit.model.alert.AlertConfig; +import com.querydsl.core.types.Predicate; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; -public interface AlertConfigRepository extends JpaRepository { +import java.util.List; +public interface AlertConfigRepository extends JpaRepository, QuerydslPredicateExecutor { + + List findByUidAndRuleInfoId(String uid, String ruleInfoId); } diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java index 31bf1a6..0422474 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java @@ -27,5 +27,5 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.querydsl.QuerydslPredicateExecutor; public interface AlertRecordRepository extends JpaRepository, QuerydslPredicateExecutor { - + long countByUid(String uid); } diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/FeedBackEvaluationRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/FeedBackEvaluationRepository.java index 563961c..009eed6 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/FeedBackEvaluationRepository.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/FeedBackEvaluationRepository.java @@ -23,11 +23,13 @@ package cc.iotkit.data.dao; import cc.iotkit.data.model.TbFeedBackEvaluation; +import cc.iotkit.data.model.TbWorderDO; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; import java.util.List; -public interface FeedBackEvaluationRepository extends JpaRepository { +public interface FeedBackEvaluationRepository extends JpaRepository, QuerydslPredicateExecutor { diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/WorderRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/WorderRepository.java index c4230da..431a0d2 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/WorderRepository.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/WorderRepository.java @@ -22,12 +22,14 @@ */ package cc.iotkit.data.dao; +import cc.iotkit.data.model.TbAlertConfig; import cc.iotkit.data.model.TbWorderDO; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; import java.util.List; -public interface WorderRepository extends JpaRepository { +public interface WorderRepository extends JpaRepository, QuerydslPredicateExecutor { diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java index 4279b75..3021fcf 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java @@ -101,5 +101,8 @@ public class TbAlertConfig extends BaseEntity implements TenantAware { private Long createAt; private Long tenantId; - + /** + * 0短信1微信小程序推送2语音,数据用,隔开 + */ + private String messagePush; } diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java index b81dd09..2174839 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java @@ -53,7 +53,8 @@ public class TbDeviceInfo extends BaseEntity implements TenantAware { @GeneratedValue(generator = "SnowflakeIdGenerator") @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") private String id; - + @ApiModelProperty(value = "详细地址") + private String site; @ApiModelProperty(value = "设备id") private String deviceId; @@ -102,4 +103,5 @@ public class TbDeviceInfo extends BaseEntity implements TenantAware { private Long tenantId; @ApiModelProperty(value = "区域id") private Long deptAreaId; + private String name; } diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbFeedBackEvaluation.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbFeedBackEvaluation.java index 2475282..50747f1 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbFeedBackEvaluation.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbFeedBackEvaluation.java @@ -85,4 +85,5 @@ public class TbFeedBackEvaluation extends BaseEntity implements TenantAware { */ private Long tenantId; + private Long customerId; } \ No newline at end of file diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java index 99f382b..809912c 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java @@ -59,7 +59,7 @@ public class TbUserInfo extends BaseEntity implements TenantAware { private Long id; /** - * 用户账号 + * 用户账号-OPENID */ @ApiModelProperty(value = "用户账号") private String uid; @@ -144,5 +144,8 @@ public class TbUserInfo extends BaseEntity implements TenantAware { @ReverseAutoMapping(ignore = true) @AutoMapping(ignore = true) private String usePlatforms; - + /** + * 客户账号 + */ + private String userName; } diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java index 28fdf3b..4f4b7df 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java @@ -25,12 +25,19 @@ package cc.iotkit.data.service; import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.satoken.utils.AuthUtil; import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; import cc.iotkit.data.dao.AlertConfigRepository; import cc.iotkit.data.dao.IJPACommData; import cc.iotkit.data.manager.IAlertConfigData; import cc.iotkit.data.model.TbAlertConfig; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.system.SysDictData; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.types.Predicate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; import org.springframework.data.domain.Page; @@ -38,6 +45,11 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Service; +import java.util.List; + +import static cc.iotkit.data.model.QTbAlertConfig.tbAlertConfig; +import static cc.iotkit.data.model.QTbSysDictData.tbSysDictData; + @Primary @Service public class AlertConfigDataImpl implements IAlertConfigData, IJPACommData { @@ -64,7 +76,17 @@ public class AlertConfigDataImpl implements IAlertConfigData, IJPACommData selectAlertConfigPage(PageRequest request) { - Page alertConfigPage = alertConfigRepository.findAll(Pageable.ofSize(request.getPageSize()).withPage(request.getPageNum() - 1)); + Page alertConfigPage = alertConfigRepository + .findAll(buildQueryCondition(request.getData()), PageBuilder.toPageable(request)); return new Paging<>(alertConfigPage.getTotalElements(), MapstructUtils.convert(alertConfigPage.getContent(), AlertConfig.class)); } + @Override + public List findByUidAndRuleInfoId(String uid, String ruleInfoId) { + return alertConfigRepository.findByUidAndRuleInfoId(uid, ruleInfoId); + // return new Paging<>(alertConfigPage.getTotalElements(), MapstructUtils.convert(alertConfigPage.getContent(), AlertConfig.class)); + } + private Predicate buildQueryCondition(AlertConfig dictData) { + return PredicateBuilder.instance() + .and(dictData.getUid() != null, () -> tbAlertConfig.uid.eq(AuthUtil.getUserId())).build(); + } } diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java index 3fbf351..e8573fa 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java @@ -25,6 +25,8 @@ package cc.iotkit.data.service; import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.common.utils.StringUtils; import cc.iotkit.data.dao.AlertRecordRepository; @@ -93,13 +95,25 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData tbAlertRecord.name.like(data.getName())) .and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) + .and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid())) .and(flag, () -> (BooleanExpression) genTimePredicate(data.getParams())) + .build(); }else{ + if(!LoginHelper.isSuperAdmin()){ + return PredicateBuilder.instance() + .and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid())) + //.and(data != null && StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) + .build(); + } return PredicateBuilder.instance() //.and(data != null && StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) .build(); @@ -115,12 +129,12 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData convertedResults = results.getResults().stream() .peek(record -> record.setAlertTime(record.getAlertTime() * 1000)) - .collect(Collectors.toList()); + .collect(Collectors.toList());*/ - return new Paging<>(results.getTotal(), convertedResults).to(AlertRecord.class); + return new Paging<>(results.getTotal(), results.getResults()).to(AlertRecord.class); } private static Predicate genTimePredicate(Map params) { @@ -129,10 +143,10 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData findByConditions(String uid, String subUid, + public Paging findByConditions(String name, String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size, Long deptAreaId) { @@ -343,6 +343,10 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData findAllByCondition(DeviceInfo data) { + return buildQuery(buildQueryCondition(data)); } diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java index 146a7c8..d9b2a8d 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java @@ -53,6 +53,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Service; +import java.sql.Date; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -364,11 +365,21 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData tbSysUser.id.eq(user.getId())) .and(StringUtils.isNotEmpty(user.getUserName()), () -> tbSysUser.userName.like("%" + user.getUserName() + "%")) .and(StringUtils.isNotEmpty(user.getStatus()), () -> tbSysUser.status.eq(user.getStatus())) - .and(ObjectUtil.isNotEmpty(user.getParams()), () -> tbSysUser.createTime.between(java.sql.Date.valueOf(user.getParams().get("beginTime").toString()), java.sql.Date.valueOf(user.getParams().get("endTime").toString()))) + .and(ObjectUtil.isNotNull(beginTime1), () -> tbSysUser.createTime.between(beginTime1,endTime1)) .and(StringUtils.isNotEmpty(user.getPhonenumber()), () -> tbSysUser.phonenumber.like("%" + user.getPhonenumber() + "%")) .and(ObjectUtil.isNotEmpty(ids), () -> tbSysUser.deptId.in(ids)) .and(ObjectUtil.isNotEmpty(areaIds), () -> tbSysUser.deptAreaId.in(areaIds)).build(); diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/AlertController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/AlertController.java index a6cf26d..1a2fcc0 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/AlertController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/AlertController.java @@ -25,6 +25,9 @@ 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.exception.BizException; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.manager.service.AlertService; import cc.iotkit.model.alert.AlertConfig; import cc.iotkit.model.alert.AlertRecord; @@ -32,6 +35,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; @@ -39,6 +43,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @Api(tags = {"告警中心"}) @Slf4j @@ -54,6 +60,13 @@ public class AlertController { @SaCheckPermission("iot:alertConfig:add") @PostMapping("/createAlertConfig") public AlertConfig createAlertConfig(@RequestBody @Validated Request request) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + request.getData().setUid(uid); + } + if(ObjectUtils.isNotEmpty( alertService.getAlertConfig(request.getData()))){ + throw new BizException("该规则模版已存在"); + } return alertService.createAlertConfig(request.getData()); } @@ -61,6 +74,18 @@ public class AlertController { @SaCheckPermission("iot:alertConfig:edit") @PostMapping("/updateAlertConfig") public AlertConfig updateAlertConfig(@RequestBody @Validated Request request) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + request.getData().setUid(uid); + } + List list= alertService.getAlertConfig(request.getData()); + if(ObjectUtils.isNotEmpty(list)){ + for (int i = 0; i < list.size(); i++) { + if(!list.get(i).getRuleInfoId().equals(request.getData().getRuleInfoId())){ + throw new BizException("该规则模版已存在"); + } + } + } return alertService.updateAlertConfig(request.getData()); } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/FeedBackEvaluationController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/FeedBackEvaluationController.java index 8aebd9b..1a7ad38 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/FeedBackEvaluationController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/FeedBackEvaluationController.java @@ -79,8 +79,8 @@ public class FeedBackEvaluationController { @PostMapping("/list") //@Operation(summary = "获得意见反馈评价分页") //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") - public Paging getFeedBackEvaluationPage(@RequestBody @Validated PageRequest pageReqVO) { - Paging pageResult = feedBackEvaluationService.getFeedBackEvaluationPage(pageReqVO); + public Paging getFeedBackEvaluationPage(@RequestBody @Validated PageRequest pageReqVO) { + Paging pageResult = feedBackEvaluationService.getFeedBackEvaluationPage(pageReqVO); return pageResult; } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java index 39ecac0..b50402f 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java @@ -78,7 +78,6 @@ public class RuleEngineController { String ruleId = request.getData(); return ruleEngineService.pauseRule(ruleId); } - @ApiOperation("恢复规则") @SaCheckPermission("iot:rule:edit") @PostMapping("/resume") 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 2498e4c..4598d59 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 @@ -161,7 +161,29 @@ public class UserInfoController { .build()); } } + @PostMapping("/client/user/edit") + public void editClientUser(@RequestBody Request user) throws Exception { +/* user.getData().setType(UserInfo.USER_TYPE_CLIENT); + user.getData().setRoles(Collections.singletonList(Constants.ROLE_CLIENT)); + user.getData().setSecret(AuthUtil.enCryptPwd(Constants.PWD_CLIENT_USER));*/ + userInfoData.save(user.getData()); + /* //添加默认家庭 + Home home = homeData.save(Home.builder() + .name("我的家庭") + .address("") + .deviceNum(0) + .spaceNum(0) + .current(true) + .build()); + //添加默认房间 + for (String name : new String[]{"客厅", "卧室", "厨房"}) { + spaceData.save(Space.builder() + .homeId(home.getId()) + .name(name) + .build()); + }*/ + } @PostMapping("/client/user/{id}/delete") public void deleteClientUser(@PathVariable("id") Long id) { UserInfo user = userInfoData.findById(id); diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/WorderController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/WorderController.java index 925896e..e9d06a9 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/WorderController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/WorderController.java @@ -73,8 +73,8 @@ public class WorderController { @PostMapping("/list") //@Operation(summary = "获得工单分页") //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") - public Paging getFeedBackEvaluationPage(@Validated @RequestBody PageRequest pageReqVO) { - Paging pageResult = worderService.getWorderPage(pageReqVO); + public Paging getFeedBackEvaluationPage(@Validated @RequestBody PageRequest pageReqVO) { + Paging pageResult = worderService.getWorderPage(pageReqVO); return pageResult; } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxAlertController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxAlertController.java new file mode 100644 index 0000000..06e3819 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxAlertController.java @@ -0,0 +1,106 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +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.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.data.config.TenantContext; +import cc.iotkit.data.manager.IAlertRecordData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.manager.dto.bo.device.DevicePropertyLogQueryBo; +import cc.iotkit.manager.dto.bo.device.DeviceQueryBo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; +import cc.iotkit.manager.model.stats.MainStats; +import cc.iotkit.manager.service.AlertService; +import cc.iotkit.manager.service.DeviceCtrlService; +import cc.iotkit.manager.service.IDeviceManagerService; +import cc.iotkit.manager.service.IProductService; +import cc.iotkit.model.alert.AlertRecord; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.temporal.IThingModelMessageData; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@Api(tags = {"小程序-告警"}) +@Slf4j +@RestController +@RequestMapping("/xcxAlert") +public class XcxAlertController { + + @Autowired + private AlertService alertService; + @Autowired + private IDeviceManagerService deviceServiceImpl; + @ApiOperation("查询告警消息分页") + @PostMapping("/selectAlertRecordPage") + public Paging selectAlertRecordPage(@RequestBody @Validated PageRequest request) { + return alertService.selectAlertRecordPage(request); + } + @ApiOperation("事件列表分页-最新的数据") + @PostMapping("/detail") + public List getDetail(@RequestBody @Validated PageRequest pageRequest) { + /* PageRequest pageRequest = new PageRequest<>(); + pageRequest.setPageNum(1); + pageRequest.setPageSize(-1);*/ + DeviceQueryBo deviceQueryBo =new DeviceQueryBo(); + deviceQueryBo.setUid(AuthUtil.getUserId()); + pageRequest.setData(deviceQueryBo); + Paging paging = deviceServiceImpl.getDevices(pageRequest); + List list = new ArrayList<>(); + for (int i = 0; i < paging.getRows().size(); i++) { + DeviceInfo devInfo = deviceServiceImpl.getDetail(paging.getRows().get(i).getDeviceId()); + list.add(devInfo); + } + + return list; + } + + @ApiOperation("单个设备事件历史数据分页") + @PostMapping("/deviceProperty/log/list") + public List getPropertyHistory(@Validated @RequestBody + Request query) { + DevicePropertyLogQueryBo data = query.getData(); + String deviceId = data.getDeviceId(); + String name = data.getName(); + long start = data.getStart(); + long end = data.getEnd(); + return deviceServiceImpl.getPropertyHistory(deviceId, name, start, end, 10000); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxDeviceController.java new file mode 100644 index 0000000..147fdee --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxDeviceController.java @@ -0,0 +1,332 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +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.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.validate.QueryGroup; +import cc.iotkit.data.config.TenantContext; +import cc.iotkit.data.manager.IAlertRecordData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.manager.dto.bo.channel.ChannelTemplateBo; +import cc.iotkit.manager.dto.bo.device.*; +import cc.iotkit.manager.dto.bo.deviceconfig.DeviceConfigAddBo; +import cc.iotkit.manager.dto.bo.product.ProductBo; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleInfoBo; +import cc.iotkit.manager.dto.vo.channel.ChannelTemplateVo; +import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; +import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo; +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.stats.MainStats; +import cc.iotkit.manager.service.*; +import cc.iotkit.model.InvokeResult; +import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.product.Product; +import cc.iotkit.temporal.IThingModelMessageData; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.lang.tree.Tree; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +@Api(tags = {"小程序-我的设备"}) +@Slf4j +@RestController +@RequestMapping("/xcxDevice") +public class XcxDeviceController { + + + @Autowired + IProductService productService; + @Autowired + IRuleEngineService ruleEngineService; + @Autowired + private DeviceCtrlService deviceCtrlService; + @Autowired + private IDeviceManagerService deviceServiceImpl; + + @Autowired + private IProductData productData; + + @Resource + private NotifyService notifyService; + @Autowired + private AlertService alertService; + /** + * 获取部门树列表 + */ + /* @ApiOperation("获取部门树列表") + + @PostMapping("/deptTree") + public List> deptTree(@RequestBody @Validated(QueryGroup.class) Request reqDept) { + + return deptService.selectDeptTreeList(reqDept.getData()); + }*/ + + + @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "POST") + @PostMapping("/list") + public Paging getDevices(@Validated @RequestBody PageRequest pageRequest) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + pageRequest.getData().setUid(uid); + } + Paging d= deviceServiceImpl.getDevices(pageRequest); + return deviceServiceImpl.getDevices(pageRequest); + } + + /* @ApiOperation(value = "创建设备") + @SaCheckPermission("iot:device:add") + @PostMapping("/add") + public boolean createDevice(@RequestBody @Validated Request bo) { + return deviceServiceImpl.addDevice(bo.getData()); + }*/ + + @ApiOperation(value = "保存与绑定设备") + @PostMapping("/save") + public boolean saveDevice(@RequestBody @Validated Request bo) { + + return deviceServiceImpl.editBandDeviceInfo(bo.getData()); + } + @ApiOperation("设备解绑") + // @SaCheckPermission("iot:device:edit") + @PostMapping("/unbind") + public boolean unbindDevice(@Validated @RequestBody Request request) { + return deviceServiceImpl.unbindDevice(request.getData()); + } + @ApiOperation(value = "获取子设备", notes = "获取子设备") + // @SaCheckPermission("iot:device:query") + @PostMapping("/children/list") + public List getChildren(@Validated @RequestBody PageRequest request) { + String deviceId = request.getData(); + return deviceServiceImpl.selectChildrenPageList(deviceId); + } + + @ApiOperation("获取网关设备") + // @SaCheckPermission("iot:device:query") + @PostMapping("/getParentDevices") + public List getParentDevices() { + return deviceServiceImpl.getParentDevices(); + } + + @ApiOperation("获取设备详情") + // @SaCheckPermission("iot:device:query") + @PostMapping("/detail") + public DeviceInfo getDetail(@RequestBody @Validated Request request) { + DeviceInfo deviceInfo = deviceServiceImpl.getDetail(request.getData()); + Product product= productData.findByProductKey(deviceInfo.getProductKey()); + deviceInfo.setProductName(product.getName()); + return deviceInfo; + } + + /* @ApiOperation("删除设备") + @SaCheckPermission("iot:device:remove") + @PostMapping("/delete") + public boolean deleteDevice(@Validated @RequestBody Request request) { + return deviceServiceImpl.deleteDevice(request.getData()); + }*/ + + @ApiOperation("设备物模型日志") + // @SaCheckPermission("iot:deviceLog:query") + @PostMapping("/deviceLogs/list") + public Paging logs(@Validated(QueryGroup.class) @RequestBody PageRequest request) { + return deviceServiceImpl.logs(request); + } + + @ApiOperation("获取设备属性历史数据") + // @SaCheckPermission("iot:deviceLog:query") + @PostMapping("/deviceProperty/log/list") + public List getPropertyHistory(@Validated @RequestBody + Request query) { + DevicePropertyLogQueryBo data = query.getData(); + String deviceId = data.getDeviceId(); + String name = data.getName(); + long start = data.getStart(); + long end = data.getEnd(); + return deviceServiceImpl.getPropertyHistory(deviceId, name, start, end, 10000); + } + + + + + + @ApiOperation("添加标签") + // @SaCheckPermission("iot:device:edit") + @PostMapping("/tag/add") + public boolean addTag(@Validated @RequestBody Request bo) { + return deviceServiceImpl.addTag(bo.getData()); + } + + + /** + * 保存设备配置 + */ + @ApiOperation(value = "保存设备配置") + //@SaCheckPermission("iot:device:edit") + @PostMapping("/config/save") + public boolean saveConfig(@Validated @RequestBody Request request) { + DeviceConfig data = request.getData().to(DeviceConfig.class); + return deviceServiceImpl.saveConfig(data); + } + + /** + * 获取设备配置 + */ + @ApiOperation(value = "获取设备配置") + // @SaCheckPermission("iot:device:query") + @PostMapping("/config/get") + public DeviceConfigVo getConfig(@Validated @RequestBody Request request) { + String deviceId = request.getData(); + return deviceServiceImpl.getConfig(deviceId); + } + + /** + * 设备配置下发 + */ + @ApiOperation(value = "设备配置下发") + //@SaCheckPermission("iot:device:ctrl") + @PostMapping("/config/send") + public InvokeResult sendConfig(@Validated @RequestBody Request bo) { + String deviceId = bo.getData(); + return new InvokeResult(deviceCtrlService.sendConfig(deviceId)); + } + /* + * 规则-告警配置 + * **********************************************************************/ + @ApiOperation("规则列表") + @PostMapping("/rulelist") + public Paging rules( + @Validated @RequestBody + PageRequest request + ) { + return ruleEngineService.selectPageList(request); + } + @ApiOperation("产品列表") + //@SaCheckPermission("iot:product:query") + @PostMapping("/productlist") + public Paging getProducts(@Validated(QueryGroup.class) @RequestBody + PageRequest request) { + return productService.selectPageList(request); + } + @ApiOperation("查看产品属性") + //@SaCheckPermission("iot:thingModel:query") + @PostMapping("/getThingModelByProductKey") + public ThingModelVo getThingModelByProductKey(@RequestBody @Validated Request request) { + return productService.getThingModelByProductKey(request.getData()); + } + @ApiOperation("暂停规则") + @PostMapping("/pause") + public boolean pauseRule(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.pauseRule(ruleId); + } + @ApiOperation("恢复规则") + @PostMapping("/resume") + public boolean resumeRule(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.resumeRule(ruleId); + } + @ApiOperation("保存规则") + @PostMapping("/ruleEdit") + public boolean saveRule(@RequestBody @Validated Request ruleInfoBo) { + return ruleEngineService.saveRule(ruleInfoBo.getData()); + } + @ApiOperation("删除规则") + //@SaCheckPermission("iot:rule:remove") + @PostMapping("/ruledelete") + public boolean deleteRule(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.deleteRule(ruleId); + } + @ApiOperation("获取通道模板列表") + //@SaCheckPermission("iot:channel:query") + @PostMapping("/channel/template/getList") + public Paging getChannelTemplateList(@RequestBody @Validated(QueryGroup.class) PageRequest request) { + //方案1 admin设置好之后,过滤租户id,所有租户都可以用该模版. + return notifyService.getChannelTemplateList(request); + } + + @ApiOperation("新增告警中心配置") + // @SaCheckPermission("iot:alertConfig:add") + @PostMapping("/createAlertConfig") + public AlertConfig createAlertConfig(@RequestBody @Validated Request request) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + request.getData().setUid(uid); + } + List list= alertService.getAlertConfig(request.getData()); + if(ObjectUtils.isNotEmpty(list)){ + for (int i = 0; i < list.size(); i++) { + if(!list.get(i).getRuleInfoId().equals(request.getData().getRuleInfoId())){ + throw new BizException("该规则模版已存在"); + } + } + } + return alertService.createAlertConfig(request.getData()); + } + + @ApiOperation("查询告警中心配置分页") + @PostMapping("/selectAlertConfigPage") + public Paging selectAlertConfigPage(@RequestBody @Validated PageRequest request) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + request.getData().setUid(uid); + } + return alertService.selectAlertConfigPage(request); + } + @ApiOperation("删除告警中心配置") + // @SaCheckPermission("iot:alertConfig:remove") + @PostMapping("/deleteAlertConfigById") + public void deleteAlertConfigById(@RequestBody @Validated Request request) { + alertService.deleteAlertConfigById(request.getData()); + } + /* @ApiOperation("编辑告警中心配置") + // @SaCheckPermission("iot:alertConfig:edit") + @PostMapping("/updateAlertConfig") + public AlertConfig updateAlertConfig(@RequestBody @Validated Request request) { + return alertService.updateAlertConfig(request.getData()); + }*/ +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxIndexController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxIndexController.java new file mode 100644 index 0000000..5601c82 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxIndexController.java @@ -0,0 +1,155 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +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.api.Response; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.data.config.TenantContext; +import cc.iotkit.data.manager.IAlertRecordData; +import cc.iotkit.data.manager.ICategoryData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.manager.dto.bo.device.*; +import cc.iotkit.manager.dto.bo.deviceconfig.DeviceConfigAddBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo; +import cc.iotkit.manager.dto.bo.thingmodel.ThingModelMessageBo; +import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupImportVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoImportVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; +import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo; +import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; +import cc.iotkit.manager.model.stats.MainStats; +import cc.iotkit.manager.service.AlertService; +import cc.iotkit.manager.service.DeviceCtrlService; +import cc.iotkit.manager.service.IDeviceManagerService; +import cc.iotkit.manager.service.IProductService; +import cc.iotkit.model.InvokeResult; +import cc.iotkit.model.alert.AlertRecord; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.model.device.DeviceGroup; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.temporal.IThingModelMessageData; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.async.DeferredResult; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; + +@Api(tags = {"小程序-首页"}) +@Slf4j +@RestController +@RequestMapping("/xcxIndex") +public class XcxIndexController { + + + @Autowired + IProductService productService; + + @Autowired + private DeviceCtrlService deviceCtrlService; + @Autowired + private IDeviceManagerService deviceServiceImpl; + @Autowired + private cc.iotkit.data.manager.ICategoryData ICategoryData; + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + private IThingModelMessageData thingModelMessageData; + @Autowired + private IAlertRecordData iAlertRecordData; + + @PostMapping("/main") + public MainStats getMainStats() { + MainStats mainStats = new MainStats(); + String uid = AuthUtil.getUserId(); + log.info("Thread {} - TenantFilter disabled: {}", + Thread.currentThread().getId(), + TenantContext.isFilterDisabled()); + long now = System.currentTimeMillis(); + mainStats.setDeviceTotal(deviceInfoData.countByUid(uid)); + // mainStats.setOnlineTotal(deviceInfoData.countOnlineByUid(uid)); + /* mainStats.setCategoryTotal(ICategoryData.count()); + mainStats.setProductTotal(productData.count()); + mainStats.setDeviceTotal(deviceInfoData.count());*/ + + DeviceInfo condition = new DeviceInfo(); + DeviceInfo.State state = new DeviceInfo.State(); + state.setOnline(true); + + condition.setState(state); + condition.setUid(uid); + mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size()); + mainStats.setAlertCount(iAlertRecordData.countByUid(uid)); + //上报数据统计 + /* mainStats.setReportDataStats(thingModelMessageData.getDeviceMessageStatsWithUid(uid, now - 48 * 3600 * 1000, now)); + //产品数量统计 + mainStats.setDeviceStatsOfCategory(deviceInfoData.getDeviceStatsByCategory(uid)); + */ + + return mainStats; + } + @PostMapping("/getAlertRecord") + public Paging selectAlertConfigPage(@Validated @RequestBody PageRequest request) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + request.getData().setUid(uid); + } + Paging alertRecordPage = iAlertRecordData.selectAlertConfigPage(request); + return alertRecordPage; + } + @ApiOperation("获取设备属性历史数据") + @PostMapping("/deviceProperty/log/list") + public List getPropertyHistory(@Validated @RequestBody + Request query) { + DevicePropertyLogQueryBo data = query.getData(); + String deviceId = data.getDeviceId(); + String name = data.getName(); + long start = data.getStart(); + long end = data.getEnd(); + return deviceServiceImpl.getPropertyHistory(deviceId, name, start, end, 10000); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxMyCenterController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxMyCenterController.java new file mode 100644 index 0000000..1a14912 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/XcxMyCenterController.java @@ -0,0 +1,162 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +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.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.data.config.TenantContext; +import cc.iotkit.data.manager.IAlertRecordData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.manager.dto.bo.device.DevicePropertyLogQueryBo; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO; +import cc.iotkit.manager.dto.vo.worder.WorderPageReqVO; +import cc.iotkit.manager.dto.vo.worder.WorderSaveReqVO; +import cc.iotkit.manager.model.stats.MainStats; +import cc.iotkit.manager.service.*; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.alert.AlertRecord; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.worder.WorderDO; +import cc.iotkit.temporal.IThingModelMessageData; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +@Api(tags = {"小程序-我的"}) +@Slf4j +@RestController +@RequestMapping("/xcxMyCenter") +public class XcxMyCenterController { + @Autowired + private FeedBackEvaluationService feedBackEvaluationService; + @Resource + private IWorderService worderService; + @PostMapping("/feedadd") + //@Operation(summary = "创建意见反馈评价") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:create')") + public Long createFeedBackEvaluation(@Valid @RequestBody Request createReqVO) { + return feedBackEvaluationService.createFeedBackEvaluation(createReqVO.getData()); + } + + @PostMapping("/feededit") + //@Operation(summary = "更新意见反馈评价") + // @PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:update')") + public Boolean updateFeedBackEvaluation(@Valid @RequestBody Request updateReqVO) { + feedBackEvaluationService.updateFeedBackEvaluation(updateReqVO.getData()); + return true; + } + + @PostMapping("/feeddelete") + //@Operation(summary = "删除意见反馈评价") + //@Parameter(name = "id", description = "编号", required = true) + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:delete')") + public boolean deleteFeedBackEvaluation(@Validated @RequestBody Request request) { + feedBackEvaluationService.deleteFeedBackEvaluation(request.getData()); + return true; + } + + @PostMapping("/feedgetDetail") + //@Operation(summary = "获得意见反馈评价") + //@Parameter(name = "id", description = "编号", required = true, example = "1024") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public FeedBackEvaluationDO getFeedBackEvaluation(@Validated @RequestBody Request request) { + FeedBackEvaluationDO feedBackEvaluation = feedBackEvaluationService.getFeedBackEvaluation(request.getData()); + return feedBackEvaluation; + } + + @PostMapping("/feedlist") + //@Operation(summary = "获得意见反馈评价分页") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public Paging getFeedBackEvaluationPage(@RequestBody @Validated PageRequest pageReqVO) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + pageReqVO.getData().setCustomerId(Long.valueOf(uid)); + } + Paging pageResult = feedBackEvaluationService.getFeedBackEvaluationPage(pageReqVO); + return pageResult; + } + + @PostMapping("/worderadd") + //@Operation(summary = "创建工单") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:create')") + public Long createWorder(@Valid @RequestBody Request createReqVO) { + return worderService.createWorder(createReqVO.getData()); + } + + @PostMapping("/worderedit") + //@Operation(summary = "更新工单") + // @PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:update')") + public Boolean updateWorder(@Valid @RequestBody Request updateReqVO) { + worderService.updateWorder(updateReqVO.getData()); + return true; + } + + @PostMapping("/worderdelete") + //@Operation(summary = "删除工单") + //@Parameter(name = "id", description = "编号", required = true) + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:delete')") + public Boolean deleteWorder(@Validated @RequestBody Request request) { + worderService.deleteWorder(request.getData()); + return true; + } + + @PostMapping("/wordergetDetail") + //@Operation(summary = "获得工单") + //@Parameter(name = "id", description = "编号", required = true, example = "1024") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public WorderDO getWorder(@Validated @RequestBody Request request) { + WorderDO worderDO = worderService.getWorder(request.getData()); + return worderDO; + } + + @PostMapping("/worderlist") + //@Operation(summary = "获得工单分页") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public Paging getWorderPage(@Validated @RequestBody PageRequest pageReqVO) { + if(!LoginHelper.isSuperAdmin()){ + String uid = AuthUtil.getUserId(); + pageReqVO.getData().setCustomerId(Long.valueOf(uid)); + } + Paging pageResult = worderService.getWorderPage(pageReqVO); + return pageResult; + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceInfoBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceInfoBo.java index 672ae28..930ffb4 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceInfoBo.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceInfoBo.java @@ -73,7 +73,7 @@ public class DeviceInfoBo extends BaseDto { @ApiModelProperty(value = "产品key") @Size(max = 255, message = "产品key长度不正确") - @NotBlank(message = "产品Key不能为空") + // @NotBlank(message = "产品Key不能为空") private String productKey; @ApiModelProperty(value = "设备描述") @@ -85,6 +85,9 @@ public class DeviceInfoBo extends BaseDto { @ApiModelProperty(value = "纬度") private String latitude; + @ApiModelProperty(value = "详细地址") + private String site; + private String name; @ApiModelProperty(value="部门表-区域id") private Long deptAreaId; @ApiModelProperty(value = "用户id") diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryBo.java index 20dab1d..bc83976 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryBo.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryBo.java @@ -51,7 +51,7 @@ public class DeviceQueryBo extends BaseDto { @Size(max = 255, message = "设备id长度不正确") private String deviceId; - @ApiModelProperty(value="设备名称") + @ApiModelProperty(value="设备名称特殊编码") @Size(max = 255, message = "设备名称长度不正确") private String deviceName; @@ -77,4 +77,7 @@ public class DeviceQueryBo extends BaseDto { @Size(max = 255, message = "用户id长度不正确") private String uid; private Long deptAreaId; + + @ApiModelProperty(value="设备名称") + private String name; } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationPageReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationPageReqVO.java index f351d50..31c70a3 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationPageReqVO.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationPageReqVO.java @@ -77,4 +77,5 @@ public class FeedBackEvaluationPageReqVO extends BaseDto{ *租户id */ private Long tenantId; + private Long customerId; } \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationSaveReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationSaveReqVO.java index dd69e08..554cc4d 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationSaveReqVO.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationSaveReqVO.java @@ -43,5 +43,5 @@ public class FeedBackEvaluationSaveReqVO { // @Schema(description = "客户电话") private String customerPhone; - + private Long customerId; } \ No newline at end of file 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 a2bc5d4..92c30f1 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 @@ -109,4 +109,6 @@ public class DeviceInfoVo implements Serializable { @ApiModelProperty(value="部门表-区域id") private Long deptAreaId; private String productName; + private String site; + private String name; } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertService.java index 1a34bb1..6add862 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertService.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertService.java @@ -33,6 +33,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Slf4j @Service public class AlertService { @@ -45,7 +47,10 @@ public class AlertService { public AlertConfig createAlertConfig(AlertConfig alertConfig) { return alertConfigData.save(alertConfig); } - + public List getAlertConfig(AlertConfig alertConfig) { + //List findByUidAndRuleInfoId(String uid, String ruleInfoId); + return alertConfigData.findByUidAndRuleInfoId(alertConfig.getUid(), alertConfig.getRuleInfoId()); + } public AlertConfig updateAlertConfig(AlertConfig alertConfig) { return alertConfigData.save(alertConfig); } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceStateCheckTask.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceStateCheckTask.java index 6253eb1..f891bc5 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceStateCheckTask.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceStateCheckTask.java @@ -64,7 +64,7 @@ public class DeviceStateCheckTask { Paging all; while (true) { //取出数据库中所有在线设备 - all = deviceInfoData.findByConditions("","","","",true,"",pn,1000,null); + all = deviceInfoData.findByConditions("","","","","",true,"",pn,1000,null); //判断属性更新时间是否大于产品定义保活时长 for (DeviceInfo device : all.getRows()) { Product product = productData.findByProductKey(device.getProductKey()); diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/FeedBackEvaluationService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/FeedBackEvaluationService.java index 4dd0573..5a020d2 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/FeedBackEvaluationService.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/FeedBackEvaluationService.java @@ -54,6 +54,6 @@ public interface FeedBackEvaluationService { * @param pageReqVO 分页查询 * @return 意见反馈评价分页 */ - Paging getFeedBackEvaluationPage(PageRequest pageReqVO); + Paging getFeedBackEvaluationPage(PageRequest pageReqVO); } \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java index 429d653..f785f72 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java @@ -99,6 +99,8 @@ public interface IDeviceManagerService { DeviceConfigVo getConfig(String deviceId); boolean saveDevice(DeviceInfoBo data); + boolean editDeviceInfo(DeviceInfoBo data); + boolean editBandDeviceInfo(DeviceInfoBo data); String importGroup(MultipartFile file); diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IWorderService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IWorderService.java index b65ecdd..36f0550 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IWorderService.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IWorderService.java @@ -61,5 +61,5 @@ public interface IWorderService { * @param pageReqVO 分页查询 * @return 工单分页 */ - Paging getWorderPage(PageRequest pageReqVO); + Paging getWorderPage(PageRequest pageReqVO); } \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java index 353f5fd..e4c704d 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java @@ -63,6 +63,7 @@ import cc.iotkit.model.product.Product; import cc.iotkit.mq.MqProducer; import cc.iotkit.temporal.IDevicePropertyData; import cc.iotkit.temporal.IThingModelMessageData; +import cn.hutool.core.util.ObjectUtil; import lombok.SneakyThrows; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -117,16 +118,16 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService { public Paging getDevices(PageRequest pageRequest) { DeviceQueryBo query = pageRequest.getData(); - String uid = ""; + String uid = query.getUid(); String subUid = ""; - + String name = query.getName(); String pk = query.getProductKey(); //关键字查询 String keyword = query.getKeyword(); String group = query.getGroup(); Boolean online = query.getOnline(); Long areaDepeId = query.getDeptAreaId(); - Paging result = MapstructUtils.convert(deviceInfoData.findByConditions(uid, subUid, pk, group, + Paging result = MapstructUtils.convert(deviceInfoData.findByConditions(name,uid, subUid, pk, group, online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId), DeviceInfoVo.class); for (DeviceInfoVo row : result.getRows()) { row.setProduct(productData.findByProductKey(row.getProductKey())); @@ -455,8 +456,47 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService { } return deviceInfoData.save(di) != null; } + @Override + public boolean editDeviceInfo(DeviceInfoBo data) { + String uid = AuthUtil.getUserId(); + data.setUid(uid); + DeviceInfo di = data.to(DeviceInfo.class); + di.setLocate(new DeviceInfo.Locate(data.getLongitude(), data.getLatitude())); + if (StringUtils.isBlank(data.getSecret())) { + data.setSecret(RandomStringUtils.random(16)); + } + //deviceName不可重复 + DeviceInfo deviceRepetition = deviceInfoData.findByDeviceName(data.getDeviceName()); + if (deviceRepetition != null && !deviceRepetition.getDeviceId().equals(di.getDeviceId())) { + throw new BizException(ErrCode.MODEL_DEVICE_ALREADY); + } + if(ObjectUtil.isNotNull(deviceRepetition.getUid()) && !deviceRepetition.getUid().equals(di.getUid())){ + throw new BizException("设备已绑定"); + } + return deviceInfoData.save(di) != null; + } + @Override + public boolean editBandDeviceInfo(DeviceInfoBo data) { + String uid = AuthUtil.getUserId(); + data.setUid(uid); + DeviceInfo di = data.to(DeviceInfo.class); + di.setLocate(new DeviceInfo.Locate(data.getLongitude(), data.getLatitude())); + if (StringUtils.isBlank(data.getSecret())) { + data.setSecret(RandomStringUtils.random(16)); + } + //deviceName不可重复 + DeviceInfo deviceRepetition = deviceInfoData.findByDeviceName(data.getDeviceName()); + if (deviceRepetition == null || ObjectUtil.isEmpty(deviceRepetition)) { + throw new BizException(ErrCode.DEVICE_NOT_FOUND); + } + if(ObjectUtil.isNotNull(deviceRepetition.getUid()) && !deviceRepetition.getUid().equals(di.getUid())){ + throw new BizException(ErrCode.DEVICE_HAS_ASSOCIATED); + } + di.setId(deviceRepetition.getId()); + return deviceInfoData.save(di) != null; + } @SneakyThrows @Override public String importGroup(MultipartFile file) { diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/FeedBackEvaluationServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/FeedBackEvaluationServiceImpl.java index b6d99ff..b634d13 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/FeedBackEvaluationServiceImpl.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/FeedBackEvaluationServiceImpl.java @@ -2,20 +2,28 @@ package cc.iotkit.manager.service.impl; import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; +import cc.iotkit.data.dao.FeedBackEvaluationRepository; +import cc.iotkit.data.dao.WorderRepository; import cc.iotkit.data.manager.IDIccidRecordData; import cc.iotkit.data.manager.IFeedBackEvaluationData; +import cc.iotkit.data.model.QTbFeedBackEvaluation; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; import cc.iotkit.manager.config.BeanUtils; import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO; import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO; import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationVO; import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordPageReqVO; import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordRespVO; +import cc.iotkit.manager.dto.vo.worder.WorderPageReqVO; import cc.iotkit.manager.service.FeedBackEvaluationService; import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.worder.WorderDO; import cn.hutool.core.util.ObjectUtil; import cn.hutool.db.PageResult; +import com.querydsl.core.types.Predicate; import lombok.extern.slf4j.Slf4j; import org.hibernate.service.spi.ServiceException; import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +33,8 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import static cc.iotkit.data.model.QTbFeedBackEvaluation.tbFeedBackEvaluation; +import static cc.iotkit.data.model.QTbWorderDO.tbWorderDO; import static io.micrometer.core.instrument.binder.http.HttpRequestTags.exception; @@ -39,7 +49,8 @@ public class FeedBackEvaluationServiceImpl implements FeedBackEvaluationService @Autowired private IFeedBackEvaluationData iFeedBackEvaluationData; - + @Autowired + private FeedBackEvaluationRepository feedBackEvaluationRepository; @Override @Transactional(rollbackFor = {Exception.class, RuntimeException.class}) public Long createFeedBackEvaluation(FeedBackEvaluationSaveReqVO createReqVO) { @@ -95,20 +106,22 @@ public class FeedBackEvaluationServiceImpl implements FeedBackEvaluationService } @Override - public Paging getFeedBackEvaluationPage(PageRequest pageReqVO) { + public Paging getFeedBackEvaluationPage(PageRequest pageReqVO) { + return PageBuilder.toPaging(feedBackEvaluationRepository.findAll( + buildQueryCondition(pageReqVO.getData()), + PageBuilder.toPageable(pageReqVO) + )).to(FeedBackEvaluationDO.class); - // 参数校验 - if(pageReqVO == null) { - pageReqVO = new PageRequest<>(); - } - PageRequest feedBackEvaluationDO = pageReqVO.to(FeedBackEvaluationDO.class); - if (feedBackEvaluationDO == null) { - throw new IllegalArgumentException("Conversion to TbFeedBackEvaluation resulted in null"); - } - // Paging a= iFeedBackEvaluationData.findAll(feedBackEvaluationDO); + } - return iFeedBackEvaluationData.findAll(feedBackEvaluationDO).to(FeedBackEvaluationVO.class); + private Predicate buildQueryCondition(FeedBackEvaluationPageReqVO dictData) { + return PredicateBuilder.instance() + .and(dictData.getMessage() != null, () -> tbFeedBackEvaluation.message.like("%" + dictData.getMessage() +"%")) + .and(dictData.getCustomerName() != null, () -> tbFeedBackEvaluation.customerName.like("%" + dictData.getCustomerName()+"%")) + .and(dictData.getCustomerPhone() != null, () -> tbFeedBackEvaluation.customerPhone.like("%" + dictData.getCustomerPhone()+"%")) + .and(dictData.getIsSolve() != null, () -> tbFeedBackEvaluation.isSolve.eq( dictData.getIsSolve())) + .and(dictData.getCustomerId() != null, () -> tbFeedBackEvaluation.customerId.eq(dictData.getCustomerId())).build(); } } \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/WorderServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/WorderServiceImpl.java index c01b44f..06125cd 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/WorderServiceImpl.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/WorderServiceImpl.java @@ -2,18 +2,29 @@ package cc.iotkit.manager.service.impl; import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.WorderRepository; import cc.iotkit.data.manager.IWorderData; +import cc.iotkit.data.model.TbAlertConfig; +import cc.iotkit.data.model.TbWorderDO; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; import cc.iotkit.manager.config.BeanUtils; import cc.iotkit.manager.config.TimestampIdentifierGenerator; import cc.iotkit.manager.dto.vo.worder.WorderPageReqVO; import cc.iotkit.manager.dto.vo.worder.WorderRespVO; import cc.iotkit.manager.dto.vo.worder.WorderSaveReqVO; import cc.iotkit.manager.service.IWorderService; +import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.plugin.PluginInfo; import cc.iotkit.model.worder.WorderDO; import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.types.Predicate; import lombok.extern.slf4j.Slf4j; import org.hibernate.service.spi.ServiceException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; @@ -21,6 +32,8 @@ import org.springframework.util.ObjectUtils; import java.util.Date; import static cc.iotkit.common.satoken.utils.LoginHelper.getLoginUser; +import static cc.iotkit.data.model.QTbAlertConfig.tbAlertConfig; +import static cc.iotkit.data.model.QTbWorderDO.tbWorderDO; /** @@ -34,6 +47,8 @@ public class WorderServiceImpl implements IWorderService { @Autowired private IWorderData iWorderData; + @Autowired + private WorderRepository worderRepository; @Override @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) public Long createWorder(WorderSaveReqVO createReqVO) { @@ -109,11 +124,21 @@ public class WorderServiceImpl implements IWorderService { return worderDO; } @Override - public Paging getWorderPage(PageRequest pageReqVO) { - // Paging -//PageRequest pageReqVO - Paging ddd= iWorderData.findAll(pageReqVO.to(WorderDO.class)).to(WorderRespVO.class); - return iWorderData.findAll(pageReqVO.to(WorderDO.class)).to(WorderRespVO.class); + public Paging getWorderPage(PageRequest pageReqVO) { + + return PageBuilder.toPaging(worderRepository.findAll( + buildQueryCondition(pageReqVO.getData()), + PageBuilder.toPageable(pageReqVO) + )).to(WorderDO.class); + } + private Predicate buildQueryCondition(WorderPageReqVO dictData) { + return PredicateBuilder.instance() + .and(dictData.getWorderNum() != null, () -> tbWorderDO.worderNum.like("%" + dictData.getWorderNum() +"%")) + .and(dictData.getCustomerName() != null, () -> tbWorderDO.customerName.like("%" + dictData.getCustomerName()+"%")) + .and(dictData.getCustomerPhone() != null, () -> tbWorderDO.customerPhone.like("%" + dictData.getCustomerPhone()+"%")) + .and(dictData.getReservationTime() != null, () -> tbWorderDO.reservationTime.like( dictData.getReservationTime()+"%")) + .and(dictData.getCustomerId() != null, () -> tbWorderDO.customerId.eq(dictData.getCustomerId())).build(); + } } \ No newline at end of file diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java index 8b42dc4..55cdcb4 100644 --- a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java @@ -28,6 +28,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; import java.util.Map; /** @@ -39,7 +40,8 @@ import java.util.Map; @NoArgsConstructor @AllArgsConstructor @Builder -public class Message { +public class Message implements Serializable { + private static final long serialVersionUID = 1L; private String content; private Map param; private Long channelId; diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java index f56bc52..9e5438d 100644 --- a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java @@ -29,6 +29,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.io.Serializable; /** * author: 石恒 @@ -37,6 +38,7 @@ import javax.annotation.Resource; **/ @Service public class MessageService { + @Resource private ApplicationEventPublisher applicationEventPublisher; diff --git a/iot-module/iot-plugin/iot-plugin-main/pom.xml b/iot-module/iot-plugin/iot-plugin-main/pom.xml index 01cdec8..6f0e4df 100644 --- a/iot-module/iot-plugin/iot-plugin-main/pom.xml +++ b/iot-module/iot-plugin/iot-plugin-main/pom.xml @@ -32,7 +32,21 @@ cc.iotkit iot-temporal-service - + diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java index bcef38a..2ac77ed 100644 --- a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java @@ -41,6 +41,7 @@ import cc.iotkit.plugin.core.thing.actions.*; import cc.iotkit.plugin.core.thing.actions.up.*; import cc.iotkit.plugin.core.thing.model.ThingDevice; import cc.iotkit.plugin.core.thing.model.ThingProduct; +import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -82,6 +83,16 @@ public class ThingServiceImpl implements IThingService { } long lastTime = System.currentTimeMillis(); DeviceInfo device = getDeviceInfo(deviceName); + DeviceStateChange deviceInfo = ((DeviceStateChange) action); + if(ObjectUtil.isNotNull(deviceInfo.getState())){ + if (deviceInfo.getState().equals(DeviceState.ONLINE)) { + device.getState().setOnline(true); + device.getState().setOnlineTime(System.currentTimeMillis()); + } else { + device.getState().setOnline(false); + device.getState().setOfflineTime(System.currentTimeMillis()); + } + } if (Objects.isNull(device)) { log.warn("device:{} is not found.", deviceName); }else { @@ -114,7 +125,7 @@ public class ThingServiceImpl implements IThingService { Product product = productData.findByProductKey(subDevice.getProductKey()); Boolean transparent = product.getTransparent(); //透传设备父设备上线,子设备也上线。非透传设备父设备离线,子设备才离线 - if (transparent != null && transparent || ((DeviceStateChange) action).getState() != DeviceState.ONLINE) { + if (transparent != null && transparent || !((DeviceStateChange) action).getState().equals(DeviceState.ONLINE)) { deviceStateChange(subDevice, (DeviceStateChange)action); } } @@ -238,12 +249,12 @@ public class ThingServiceImpl implements IThingService { private void deviceStateChange(DeviceInfo device, DeviceStateChange action) { DeviceState state = action.getState(); - if ( (device.getState().isOnline() && state == DeviceState.ONLINE) || - (!device.getState().isOnline() && state == DeviceState.OFFLINE) ) { + if ( (device.getState().isOnline() && state.equals(DeviceState.ONLINE) || + (!device.getState().isOnline() && state.equals(DeviceState.OFFLINE)))) { return; } - if (state == DeviceState.ONLINE) { + if (state.equals(DeviceState.ONLINE)) { device.getState().setOnline(true); device.getState().setOnlineTime(System.currentTimeMillis()); } else { diff --git a/iot-module/iot-rule-engine/pom.xml b/iot-module/iot-rule-engine/pom.xml index 28406fc..6c8f0e9 100644 --- a/iot-module/iot-rule-engine/pom.xml +++ b/iot-module/iot-rule-engine/pom.xml @@ -86,7 +86,26 @@ org.springframework.integration spring-integration-mqtt - + + com.github.binarywang + weixin-java-pay + 4.6.0 + + + com.github.binarywang + wx-java-mp-spring-boot-starter + 4.6.0 + + + com.github.binarywang + wx-java-miniapp-spring-boot-starter + 4.6.0 + + + org.springframework.data + spring-data-redis + 2.7.18 + com.squareup.okhttp3 okhttp diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertAction.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertAction.java index d4520d7..e3bb569 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertAction.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertAction.java @@ -28,6 +28,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -37,7 +38,8 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor @Data -public class AlertAction implements Action { +public class AlertAction implements Action, Serializable { + private static final long serialVersionUID = 1L; public static final String TYPE = "alert"; diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertService.java index a530c0f..922a4cb 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertService.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertService.java @@ -32,6 +32,7 @@ import lombok.EqualsAndHashCode; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +import java.io.Serializable; import java.util.Map; /** @@ -40,7 +41,8 @@ import java.util.Map; @EqualsAndHashCode(callSuper = true) @Slf4j @Data -public class AlertService extends ScriptService { +public class AlertService extends ScriptService implements Serializable { + private static final long serialVersionUID = 1L; private Message message; diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/expression/Expression.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/expression/Expression.java index 2264d59..269303d 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/expression/Expression.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/expression/Expression.java @@ -65,9 +65,31 @@ public class Expression { if (name == null) { throw new BizException(ErrCode.DATA_BLANK); } + for (int i = 0; i < args.length; i++) { + args[i] = convertIfNumeric(args[i]); + } return engine.invokeMethod(new TypeReference<>() { }, name, args); } + public static Object convertIfNumeric(Object arg) { + if (arg instanceof String) { + String str = (String) arg; + try { + // 尝试解析为整数 + return Integer.parseInt(str); + } catch (NumberFormatException e1) { + try { + // 尝试解析为浮点数 + return Double.parseDouble(str); + } catch (NumberFormatException e2) { + // 非数字字符串保持原样 + return arg; + } + } + } + return arg; // 非字符串直接返回 + } + } diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java index c85361c..2829915 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Data public class DeviceCondition { @@ -51,14 +52,24 @@ public class DeviceCondition { if (!this.identifier.equals(identifier)) { return false; } + boolean found = false; + this.parameters = filterParameters(parameter,this.parameters); for (Parameter p : this.parameters) { - if (!p.matches(parameter)) { - return false; + if (p.matches(parameter)) { + found = true; + // return false; } } - return true; + return found; } + public List filterParameters( + Map parameter, + List parameters) { + return parameters.stream() + .filter(p -> parameter.containsKey(p.getIdentifier())) + .collect(Collectors.toList()); + } @Data public static class Parameter { private String identifier; diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/Rule.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/Rule.java index 1044320..a1c9135 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/Rule.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/Rule.java @@ -23,18 +23,22 @@ package cc.iotkit.ruleengine.rule; import cc.iotkit.ruleengine.action.Action; +import cc.iotkit.ruleengine.action.alert.AlertService; import cc.iotkit.ruleengine.filter.Filter; import cc.iotkit.ruleengine.listener.Listener; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; +import java.util.ArrayList; import java.util.List; @Data @NoArgsConstructor @AllArgsConstructor -public class Rule { +public class Rule implements Serializable { + private static final long serialVersionUID = 1L; private String id; @@ -46,4 +50,6 @@ public class Rule { private List> actions; + + } diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleExecutor.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleExecutor.java index a89fb5e..bd23d32 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleExecutor.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleExecutor.java @@ -24,19 +24,38 @@ package cc.iotkit.ruleengine.rule; import cc.iotkit.common.thing.ThingModelMessage; import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.data.manager.IAlertConfigData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.model.UserInfo; +import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.rule.RuleLog; +import cc.iotkit.model.worder.WorderDO; import cc.iotkit.ruleengine.action.Action; import cc.iotkit.ruleengine.filter.Filter; import cc.iotkit.ruleengine.listener.Listener; import cc.iotkit.temporal.IRuleLogData; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; +import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; +import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; +import cn.hutool.core.util.ObjectUtil; +import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import javax.annotation.Resource; +import javax.security.auth.message.config.AuthConfig; +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.util.*; /** * 规则执行器 @@ -48,7 +67,22 @@ public class RuleExecutor { @Lazy @Autowired private IRuleLogData ruleLogData; - + @Lazy + @Autowired + private IAlertConfigData iAlertConfigData; + @Lazy + @Autowired + private IDeviceInfoData iDeviceInfoData; + @Lazy + @Autowired + private IUserInfoData iUserInfoData; + @Lazy + @Resource + private WxMaProperties wxMaProperties; + @Resource + private StringRedisTemplate stringRedisTemplate; // WxMpService 需要使用到,所以在 Servi + @Resource + private WxMaService wxMaService; public void execute(ThingModelMessage message, Rule rule) { if (!doListeners(message, rule)) { log.info("The listener did not match the appropriate content,rule:{},{}", rule.getId(), rule.getName()); @@ -81,11 +115,150 @@ public class RuleExecutor { ruleLog.setSuccess(false); ruleLog.setContent(e.toString()); } finally { + // 注入 WxMaService 后直接调用 + String appId = wxMaService.getWxMaConfig().getAppid(); + System.out.println("当前小程序AppID: " + appId); + + String alertData = processData(message); + String deviceName=message.getDeviceName(); + try { + DeviceInfo deviceInfo = iDeviceInfoData.findByDeviceId(message.getDeviceId()); + if(ObjectUtil.isNotNull(deviceInfo) && ObjectUtil.isNotNull(deviceInfo.getUid())){ + UserInfo userInfo= iUserInfoData.findById(Long.valueOf(deviceInfo.getUid())); + List listAlertConfigs = iAlertConfigData.findByUidAndRuleInfoId(deviceInfo.getUid(), ruleLog.getRuleId()); + for (AlertConfig alertConfig : listAlertConfigs){ + String [] messagePush = alertConfig.getMessagePush().split(","); + for (int i = 0; i < messagePush.length; i++) { + switch (messagePush[i]){ + case "0": + //发送短信 + break; + case "1": + //发送微信小程序 + String openid = userInfo.getUid(); + Date date = new Date(message.getTime()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Map map = new HashMap(); + map.put("openid",openid); + map.put("alertData", alertData); + map.put("deviceName", deviceName); + map.put("level",getSeverityLight(alertConfig.getLevel())); + map.put("time", sdf.format(date)); + messageReminder(map); + break; + case "2": + //语音 + break; + } + } + + } + + } + }catch (Exception e){} + //进行报警 + //告警配置中心的rule_info_id 根据这个与uid查询出对应的报警等级 + ruleLog.getRuleId(); ruleLog.setLogAt(System.currentTimeMillis()); ruleLogData.add(ruleLog); } } + + public static String getSeverityLight(String level) { + switch (level) { + case "1": return "严重"; // 严重 + case "2": return "紧急"; // 紧急 + case "3": return "较重"; // 较重 + case "4": return "一般"; // 一般 + case "5": return "提示"; // 提示 + default: return null; + } + //return null; + } + public void messageReminder(Map map){ + try { + + //MemberUserDO memberUserDO = memberUserMapper.selectById(orDefault1.getMasteruser()); + if (ObjectUtil.isNotNull(map)) { + //封装推送信息 + // wxMaSubMsgList组装示例,在业务里组装好,再调用系统消息发送工具,系统消息判断是否需要发送小程序订阅消息进行分发,此处不做展示 + ArrayList wxMaSubscribeData = new ArrayList<>(); + WxMaSubscribeMessage.MsgData thing13 = new WxMaSubscribeMessage.MsgData(); + thing13.setName("thing13"); + thing13.setValue(map.get("deviceName")); + wxMaSubscribeData.add(thing13); + WxMaSubscribeMessage.MsgData short_thing18 = new WxMaSubscribeMessage.MsgData(); + short_thing18.setName("short_thing18"); + short_thing18.setValue(map.get("level")); + wxMaSubscribeData.add(short_thing18); + WxMaSubscribeMessage.MsgData time7 = new WxMaSubscribeMessage.MsgData(); + time7.setName("time7"); + time7.setValue(map.get("time")); + wxMaSubscribeData.add(time7); + WxMaSubscribeMessage.MsgData thing11 = new WxMaSubscribeMessage.MsgData(); + thing11.setName("thing11"); + thing11.setValue(map.get("alertData")); + wxMaSubscribeData.add(thing11); + + sendWechatAppSubMessage(map.get("openid"), + "formal", + "H89Wdr3oPVbEbe4kamZUKeCt7i5pqmDe2sfaOlvPqR0", + "\"pages/index/index\"", + wxMaSubscribeData); + + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + /* private WxMaService buildWxMaService(String clientId, String clientSecret) { + // 第一步,创建 WxMaRedisBetterConfigImpl 对象 + WxMaRedisBetterConfigImpl configStorage = new WxMaRedisBetterConfigImpl( + new RedisTemplateWxRedisOps(stringRedisTemplate), + wxMaProperties.getConfigStorage().getKeyPrefix()); + configStorage.setAppid(clientId); + configStorage.setSecret(clientSecret); + + // 第二步,创建 WxMpService 对象 + WxMaService service = new WxMaServiceImpl(); + service.setWxMaConfig(configStorage); + return service; + }*/ + + + public void sendWechatAppSubMessage(String openId, String appletsSubType, String appSubTempId, String appSubPagePath, ArrayList wxMaSubMsgList) throws Exception { + //AuthConfig + + // WxMaService wxMaService = buildWxMaService("wx756050a3772987c8","4dc7df1922d7cf210ccbc086bc473de8"); + // TODO:根据用户id获取OpenId,测试时写死 + WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); + // 要推送的用户openid + subscribeMessage.setToUser(openId); + // 小程序类型(developer为开发版、trial为体验版、formal为正式版),默认为formal(正式版) + subscribeMessage.setMiniprogramState(appletsSubType); + // 订阅消息模板id + subscribeMessage.setTemplateId(appSubTempId); + // 跳转小程序地址 + subscribeMessage.setPage(appSubPagePath); + // 消息列表(组装示例请看方法开始注释部分) + subscribeMessage.setData(wxMaSubMsgList); + try { + // 发送订阅消息 + wxMaService.getMsgService().sendSubscribeMsg(subscribeMessage); + } catch (Exception e) { + } + } + + public static String processData(ThingModelMessage message) { + Map data = message.dataToMap(); + StringJoiner result = new StringJoiner("、"); + for (Map.Entry entry : data.entrySet()) { + result.add(entry.getKey() + "=" + entry.getValue()); + } + + return result.toString(); + } private boolean doListeners(ThingModelMessage message, Rule rule) { List> listeners = rule.getListeners(); for (Listener listener : listeners) { diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleMessageHandler.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleMessageHandler.java index 027c081..fc06eba 100644 --- a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleMessageHandler.java +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleMessageHandler.java @@ -23,19 +23,31 @@ package cc.iotkit.ruleengine.rule; import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.action.Action; +import cc.iotkit.ruleengine.action.alert.AlertAction; +import cc.iotkit.ruleengine.action.alert.AlertService; import cc.iotkit.ruleengine.handler.DeviceMessageHandler; import cc.iotkit.ruleengine.listener.DeviceCondition; import cc.iotkit.ruleengine.listener.Listener; +import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + @Component public class RuleMessageHandler implements DeviceMessageHandler { private final Map> deviceRuleMap = new HashMap<>(); + @Autowired private RuleExecutor ruleExecutor; @@ -80,17 +92,83 @@ public class RuleMessageHandler implements DeviceMessageHandler { //仅用PK匹配 List foundRules = deviceRuleMap.get(pk + "/#"); if (foundRules != null) { - rules.addAll(foundRules); + if(foundRules.get(0).getListeners().size() == 1){ + rules.add(foundRules.get(0)); + }else{ + rules.addAll(foundRules); + } } //用PK和DN匹配 foundRules = deviceRuleMap.get(pk + "/" + dn); if (foundRules != null) { - rules.addAll(foundRules); + if(foundRules.get(0).getListeners().size() == 1){ + rules.add(foundRules.get(0)); + }else{ + rules.addAll(foundRules); + } + // rules.addAll(foundRules); + } + // 创建一个集合用于存储待删除的服务 + List servicesToRemove = new ArrayList<>(); + for (Rule rule : rules) { + clearUnmatchedScripts(rule, message,servicesToRemove); + ruleExecutor.execute(message, rule); } - //执行规则 + // 处理完所有规则后,恢复被删除的服务 for (Rule rule : rules) { - ruleExecutor.execute(message, rule); + restoreDeletedServices(rule, servicesToRemove); + } + } + + + + public void clearUnmatchedScripts(Rule rule, ThingModelMessage message, List servicesToRemove) { + + // 获取message中的data key集合 + Set messageKeys = message.dataToMap().keySet(); + + // 遍历所有actions + for (Action action : rule.getActions()) { + // 使用迭代器安全删除 + Iterator iterator = action.getServices().iterator(); + while (iterator.hasNext()) { + AlertService service = iterator.next(); + String script = service.getScript(); + if (script != null) { + // 提取script中引用的data key + Pattern pattern = Pattern.compile("msg\\.data\\['(\\w+)'\\]"); + Matcher matcher = pattern.matcher(script); + + // 检查每个引用的key是否存在于message中 + while (matcher.find()) { + String referencedKey = matcher.group(1); + servicesToRemove.add(service); + if (!messageKeys.contains(referencedKey)) { + // 如果引用的key不存在于message中,则移除整个service// 添加到待删除集合 + iterator.remove(); + break; + } + } + } + } } } + public void restoreDeletedServices(Rule rule, List servicesToAdd) { + // 创建服务副本避免修改原集合 + // 将待添加的服务转换为列表保持顺序 + List newServices = new ArrayList<>(servicesToAdd); + // 遍历所有actions + for (int i = 0; i < rule.getActions().size(); i++) { + Action action = rule.getActions().get(i); + // 清空原有服务 + action.getServices().clear(); + // 添加对应位置的新服务 + if (i < newServices.size()) { + action.getServices().add(newServices.get(i)); + } + } + servicesToAdd.clear(); + } + } diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java index ee2e438..55ed837 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java @@ -295,11 +295,18 @@ public class SysUserController extends BaseController { * 获取部门树列表 */ @ApiOperation("获取部门树列表") - @SaCheckPermission("system:user:list") + //@SaCheckPermission("system:user:list") @PostMapping("/deptTree") public List> deptTree(@RequestBody @Validated(QueryGroup.class) Request reqDept) { return deptService.selectDeptTreeList(reqDept.getData()); } + @ApiOperation("根据部门编号获取详细信息") + @PostMapping(value = "/getDeptInfo") + public SysDeptVo getDeptInfo(@Validated @RequestBody Request bo) { + Long deptId = bo.getData(); + deptService.checkDeptDataScope(deptId); + return deptService.selectDeptById(deptId); + } } diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginBo.java index b9d7f4b..57b58a5 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginBo.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginBo.java @@ -27,6 +27,8 @@ import io.swagger.annotations.ApiModelProperty; import org.hibernate.validator.constraints.NotBlank; import lombok.Data; +import javax.validation.constraints.NotNull; + /** * 小程序登录对象 * @@ -50,4 +52,22 @@ public class XcxLoginBo { @NotBlank(message = "code不能为空") private String code; + /** + * 租户ID + */ + //@NotNull(message = "{tenant.number.not.blank}") + private Long tenantId; + + /** + * 用户名 + */ + // @NotBlank(message = "{user.username.not.blank}") + private String username; + + /** + * 用户密码 + */ + // @NotBlank(message = "{user.password.not.blank}") + private String password; + private String smsCode; } diff --git a/iot-starter/pom.xml b/iot-starter/pom.xml index 4eca99a..8616bf2 100644 --- a/iot-starter/pom.xml +++ b/iot-starter/pom.xml @@ -132,7 +132,11 @@ - + + org.dromara.sms4j + sms4j-spring-boot-starter + 2.2.0 + com.gitee.starblues spring-brick diff --git a/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java b/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java index 6a9de56..ac7d63e 100644 --- a/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java +++ b/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java @@ -24,9 +24,13 @@ package cc.iotkit.web.controller; import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.constant.GlobalConstants; import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.redis.utils.RedisUtils; import cc.iotkit.common.utils.StreamUtils; import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.system.dto.LoginBody; import cc.iotkit.system.dto.RegisterBody; import cc.iotkit.system.dto.bo.SysTenantBo; @@ -41,18 +45,23 @@ import cc.iotkit.web.service.SysLoginService; import cc.iotkit.web.service.SysRegisterService; import cn.dev33.satoken.annotation.SaIgnore; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.RandomUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import org.dromara.sms4j.api.SmsBlend; +import org.dromara.sms4j.api.entity.SmsResponse; +import org.dromara.sms4j.core.factory.SmsFactory; +import org.dromara.sms4j.provider.enumerate.SupplierType; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.net.URL; +import java.time.Duration; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -92,7 +101,52 @@ public class AuthController { loginVo.setToken(token); return loginVo; } + /** + * 邮箱验证码 + * + * @param email 邮箱 + */ + // @RateLimiter(key = "#email", time = 60, count = 1) + /* @GetMapping("/resource/email/code") + public R emailCode(@NotBlank(message = "{user.email.not.blank}") String email) { + if (!mailProperties.getEnabled()) { + return R.fail("当前系统没有开启邮箱功能!"); + } + String key = GlobalConstants.CAPTCHA_CODE_KEY + email; + String code = RandomUtil.randomNumbers(4); + RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); + try { + MailUtils.sendText(email, "登录验证码", "您本次验证码为:" + code + ",有效性为" + Constants.CAPTCHA_EXPIRATION + "分钟,请尽快填写。"); + } catch (Exception e) { + log.error("验证码短信发送异常 => {}", e.getMessage()); + return R.fail(e.getMessage()); + } + return R.ok(); + }*/ + /** + * 短信验证码 + * + * @param body 用户手机号 + */ + // @RateLimiter(key = "#phonenumber", time = 60, count = 1) + @PostMapping("/smscode") + public boolean smsCode(@Validated @RequestBody Request body) { + String key = GlobalConstants.CAPTCHA_CODE_KEY + body.getData(); + String code = RandomUtil.randomNumbers(4); + RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); + // 验证码模板id 自行处理 (查数据库或写死均可) + String templateId = "SMS_235815708"; + LinkedHashMap map = new LinkedHashMap<>(1); + map.put("code", code); + SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA); + SmsResponse smsResponse = smsBlend.sendMessage(body.getData(), templateId, map); + System.out.println(smsResponse); + if (!"OK".equals(smsResponse.getCode())) { + return false; + } + return true; + } /** * 小程序登录(示例) * @@ -105,12 +159,20 @@ public class AuthController { LoginVo loginVo = new LoginVo(); XcxLoginBo data = body.getData(); // 生成令牌 - String token = loginService.xcxLogin(data.getAppId(), data.getCode()); + loginVo = loginService.xcxLogin(data.getAppId(), data.getCode(),data.getUsername(),data.getPassword()); + return loginVo; + } + @ApiOperation("小程序注册") + @PostMapping("/xcxRegister") + public LoginVo xcxRegister(@Validated @RequestBody Request body) { + LoginVo loginVo = new LoginVo(); + XcxLoginBo data = body.getData(); + // 生成令牌 + String token = loginService.xcxRegister(data.getAppId(), data.getCode(),data.getUsername(),data.getPassword(),data.getSmsCode()); loginVo.setToken(token); return loginVo; } - /** * 退出登录 */ diff --git a/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginVo.java b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginVo.java index a0bd645..df74b13 100644 --- a/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginVo.java +++ b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginVo.java @@ -34,5 +34,5 @@ import lombok.Data; public class LoginVo { private String token; - + private String openid; } 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 9e6d8de..21ecedd 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 @@ -55,6 +55,7 @@ import cc.iotkit.system.dto.vo.SysUserVo; import cc.iotkit.system.service.ISysAppService; import cc.iotkit.system.service.ISysPermissionService; import cc.iotkit.system.service.ISysTenantService; +import cc.iotkit.web.domain.vo.LoginVo; import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.secure.BCrypt; import cn.dev33.satoken.stp.StpUtil; @@ -66,9 +67,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.time.Duration; -import java.util.Collections; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.function.Supplier; /** @@ -166,20 +165,36 @@ public class SysLoginService { } - public String xcxLogin(String appId,String xcxCode) { + public LoginVo xcxLogin(String appId, String xcxCode, String username, String password) { // xcxCode 为 小程序调用 wx.login 授权后获取 SysAppVo sysApp=appService.queryByAppId(appId); if(sysApp==null){ throw new BizException("该应用未授权注册"); } + LoginVo loginVo = new LoginVo(); + String openid = WeChatUtil.getOpenId(appId,sysApp.getAppSecret(),xcxCode); - UserInfo user = null; - LoginHelper.setTenantId(sysApp.getTenantId()); + loginVo.setOpenid(openid); + UserInfo user = new UserInfo(); try { - user = loadUserByOpenid(openid,sysApp.getTenantId()); + LoginHelper.setTenantId(sysApp.getTenantId()); + user = loadUserByOpenid(openid,sysApp.getTenantId()); } catch (Exception e) { e.printStackTrace(); } + if(ObjectUtil.isEmpty(user) || ObjectUtil.isNull(user)){ + throw new BizException("用户不存在,请先注册"); + } + UserInfo user1 = user; + checkLogin(LoginType.PASSWORD, sysApp.getTenantId(), username, () -> { + try { + return !AuthUtil.checkPwd(password, user1.getSecret()); + } catch (Exception e) { + throw new BizException("密码错误"); + } + }); + + // checkLogin(LoginType.PASSWORD, sysApp.getTenantId(), username, () -> !BCrypt.checkpw(password, user1.getSecret())); // 校验租户 // checkTenant(user.getTenantId()); @@ -195,9 +210,46 @@ public class SysLoginService { recordLoginInfo(loginUser.getTenantId(), user.getNickName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); // recordLoginInfo(user.getId()); - return StpUtil.getTokenValue(); + + loginVo.setToken(StpUtil.getTokenValue()); + return loginVo; } + public String xcxRegister(String appId,String xcxCode,String username,String password,String smsCode) { + // xcxCode 为 小程序调用 wx.login 授权后获取 + SysAppVo sysApp=appService.queryByAppId(appId); + //校验验证码 + validateSmsCode(sysApp.getTenantId(), username, smsCode); + if(sysApp==null){ + throw new BizException("该应用未授权注册"); + } + String openid = WeChatUtil.getOpenId(appId,sysApp.getAppSecret(),xcxCode); + UserInfo user=userInfoData.findByUid(openid); + if(ObjectUtil.isNotEmpty(user)){ + throw new BizException("该用户已存在"); + } + // UserInfo user = new UserInfo(); + try { + LoginHelper.setTenantId(sysApp.getTenantId()); + user = loadUserByOpenidRegister(openid,sysApp.getTenantId(),username,password); + } catch (Exception e) { + e.printStackTrace(); + } + // 校验租户 +// checkTenant(user.getTenantId()); + // 此处可根据登录用户的数据不同 自行创建 loginUser + XcxLoginUserBo loginUser = new XcxLoginUserBo(); + loginUser.setUserId(user.getId()); + loginUser.setUsername(user.getNickName()); + loginUser.setUserType(UserType.APP_USER.getUserType()); + loginUser.setOpenid(openid); + loginUser.setTenantId(sysApp.getTenantId()); + // 生成token + LoginHelper.loginByDevice(loginUser, DeviceType.XCX); + recordLoginInfo(loginUser.getTenantId(), user.getNickName(),Constants.REGISTER, MessageUtils.message("user.register.success")); +// recordLoginInfo(user.getId()); + return StpUtil.getTokenValue(); + } /** * 退出登录 */ @@ -334,7 +386,7 @@ public class SysLoginService { private UserInfo loadUserByOpenid(String openid,Long tenantId) throws Exception { // 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户 UserInfo user=userInfoData.findByUid(openid); - if (ObjectUtil.isNull(user)) { + /* if (ObjectUtil.isNull(user)) { log.info("小程序用户:{} 不存在,开始初始化", openid); user=new UserInfo(); user.setType(UserInfo.USER_TYPE_CLIENT); @@ -362,10 +414,45 @@ public class SysLoginService { .deviceNum(0) .build()); } - } + }*/ return user; } + //小程序注册 + private UserInfo loadUserByOpenidRegister(String openid,Long tenantId,String username,String password) throws Exception { + // 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户 + + log.info("小程序用户:{} 不存在,开始初始化", openid); + UserInfo user=new UserInfo(); + user.setType(UserInfo.USER_TYPE_CLIENT); + user.setUid(openid); + // user.setSecret(BCrypt.hashpw(password)); + user.setUserName(username); + user.setRoles(Collections.singletonList(Constants.ROLE_CLIENT)); + user.setNickName("微信用户"); + user.setSecret(AuthUtil.enCryptPwd(password)); + user.setTenantId(tenantId); + user = userInfoData.save(user); + //添加默认家庭 + Home home = homeService.save(HomeBo.builder() + .name("我的家庭") + .userId(user.getId()) + .address("") + .deviceNum(0) + .spaceNum(3) + .current(true) + .build()); + + //添加默认房间 + for (String name : new String[]{"客厅", "卧室", "厨房"}) { + spaceService.save(Space.builder() + .homeId(home.getId()) + .name(name) + .deviceNum(0) + .build()); + } + return user; + } /** * 构建登录用户 */ diff --git a/iot-starter/src/main/resources/application-dev.yml b/iot-starter/src/main/resources/application-dev.yml index 1b0e8aa..ef1d61d 100644 --- a/iot-starter/src/main/resources/application-dev.yml +++ b/iot-starter/src/main/resources/application-dev.yml @@ -190,6 +190,80 @@ websocket: enabled: true path: /websocket allowedOrigins: '*' +--- # mail 邮件发送 +mail: + enabled: false + host: smtp.163.com + port: 465 + # 是否需要用户名密码验证 + auth: true + # 发送方,遵循RFC-822标准 + from: xxx@163.com + # 用户名(注意:如果使用foxmail邮箱,此处user为qq号) + user: xxx@163.com + # 密码(注意,某些邮箱需要为SMTP服务单独设置密码,详情查看相关帮助) + pass: xxxxxxxxxx + # 使用 STARTTLS安全连接,STARTTLS是对纯文本通信协议的扩展。 + starttlsEnable: true + # 使用SSL安全连接 + sslEnable: true + # SMTP超时时长,单位毫秒,缺省值不超时 + timeout: 0 + # Socket连接超时值,单位毫秒,缺省值不超时 + connectionTimeout: 0 + +--- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商 +# https://wind.kim/doc/start 文档地址 各个厂商可同时使用 +sms: + # 阿里云 dysmsapi.aliyuncs.com + alibaba: + #请求地址 默认为 dysmsapi.aliyuncs.com 如无特殊改变可以不用设置 + requestUrl: dysmsapi.aliyuncs.com + #阿里云的accessKey + accessKeyId: LTAI5tC3orqkvCeHhihvfAet + #阿里云的accessKeySecret + accessKeySecret: mTRyGL2J4IywsRWFu0ugMjncjQzAML + #短信签名 + signature: 河南华码信息科技 + tencent: + #请求地址默认为 sms.tencentcloudapi.com 如无特殊改变可不用设置 + requestUrl: sms.tencentcloudapi.com + #腾讯云的accessKey + accessKeyId: xxxxxxx + #腾讯云的accessKeySecret + accessKeySecret: xxxxxxx + #短信签名 + signature: 测试 + #短信sdkAppId + sdkAppId: appid + #地域信息默认为 ap-guangzhou 如无特殊改变可不用设置 + territory: ap-guangzhou +wx: + mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 + # app-id: wx041349c6f39b268b # 测试号(牛希尧提供的) + # secret: 5abee519483bc9f8cb37ce280e814bd0 + app-id: wx5b23ba7a5589ecbb # 测试号(自己的) + secret: 2a7b3b20c537e52e74afd395eb85f61f + # app-id: wxa69ab825b163be19 # 测试号(Kongdy 提供的) + # secret: bd4f9fab889591b62aeac0d7b8d8b4a0 + # 存储配置,解决 AccessToken 的跨节点的共享 + config-storage: + type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 + key-prefix: wx # Redis Key 的前缀 + http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 + miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档 + # appid: wx62056c0d5e8db250 # 测试号(牛希尧提供的) + # secret: 333ae72f41552af1e998fe1f54e1584a + #appid: wx53b5ac263b9cdb5b # wenhualian的接口测试号 + #secret: baa127ca662344cf9b0b8e52b26bac9d + appid: wx756050a3772987c8 # 安强净水的接口测试号 + secret: 4dc7df1922d7cf210ccbc086bc473de8 + # appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的) + # secret: 4a1a04e07f6a4a0751b39c3064a92c8b + config-storage: + type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 + key-prefix: wa # Redis Key 的前缀 + http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 # 插件配置 plugin: diff --git a/pom.xml b/pom.xml index a97a27c..10ccb76 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,8 @@ 4.2.2 1.34.0 1.9.3 + 2.2.0 + 3.1.8 3.7 5.8.18 1.3.1 @@ -153,6 +155,23 @@ vertx-web-proxy ${vertx.version} + + + org.dromara.sms4j + sms4j-spring-boot-starter + 2.2.0 + + + + de.codecentric + spring-boot-admin-starter-server + ${spring-boot-admin.version} + + + de.codecentric + spring-boot-admin-starter-client + ${spring-boot-admin.version} + io.vertx