新增批量下发,告警列表搜索、告警列表导出以及下发权限控制

master
小鱼干 2 weeks ago
parent c9a72bc61b
commit 22195458c4

File diff suppressed because it is too large Load Diff

@ -79,6 +79,19 @@ public class AlertRecord extends TenantModel implements Owned<Long> {
*/ */
private Boolean readFlg; private Boolean readFlg;
private Boolean statusFlg = false; private Boolean statusFlg = false;
private Integer reasonForRemoval;
private Integer reasonForRemovalFlag;
private String site;
private String deviceName;
private String productKey;
private String levelStatus;
private String endTime;
private String beginTime;
private String productName;
/* @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") /* @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
public Date getAlertTime() { public Date getAlertTime() {
return new Date(this.alertTime); return new Date(this.alertTime);

@ -100,6 +100,7 @@ public class DeviceInfo extends TenantModel implements Owned<String> {
private String nodeStatus; private String nodeStatus;
private String node; private String node;
private String nodeDevice; private String nodeDevice;
private String nodes;
/** /**
* ID * ID
*/ */

@ -0,0 +1,69 @@
/*
*
* * | 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.model.device;
import cc.iotkit.model.Id;
import cc.iotkit.model.Owned;
import cc.iotkit.model.TenantModel;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.ParamDef;
import javax.persistence.*;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DeviceIssue extends TenantModel implements Owned<String>{
private String id;
private String productKey;
private Long tenantId;
private String fieldName;
private String fieldNameValue;
private String tenantName;
@Override
public String getUid() {
return null;
}
@Override
public void setUid(String uid) {
}
}

@ -36,6 +36,9 @@ public interface IAlertRecordData extends ICommonData<AlertRecord, Long> {
Paging<AlertRecord> selectAlertConfigPage(PageRequest<AlertRecord> request); Paging<AlertRecord> selectAlertConfigPage(PageRequest<AlertRecord> request);
Paging<AlertRecord> selectAlertRecordPageExcel(PageRequest<AlertRecord> request);
List<AlertRecord> selectAlertConfigPage(AlertRecordBo request); List<AlertRecord> selectAlertConfigPage(AlertRecordBo request);

@ -116,7 +116,7 @@ public interface IDeviceInfoData extends IOwnedData<DeviceInfo, String> {
*/ */
Paging<DeviceInfo> findByConditions(String name,String uid, String subUid, String productKey, Paging<DeviceInfo> findByConditions(String name,String uid, String subUid, String productKey,
String groupId, Boolean online, String keyword, String groupId, Boolean online, String keyword,
int page, int size,Long areaDepeId,String startTime,String endTime); int page, int size,Long areaDepeId,String startTime,String endTime,String deviceName);
Paging<DeviceInfo> findByConditionsExcel(String name,String uid, String subUid, String productKey, Paging<DeviceInfo> findByConditionsExcel(String name,String uid, String subUid, String productKey,
String groupId, Boolean online, String keyword, String groupId, Boolean online, String keyword,
int page, int size,Long areaDepeId,String startTime,String endTime); int page, int size,Long areaDepeId,String startTime,String endTime);
@ -126,7 +126,7 @@ public interface IDeviceInfoData extends IOwnedData<DeviceInfo, String> {
Paging<DeviceInfo> findByConditions1(String name,String uid, String subUid, String productKey, Paging<DeviceInfo> findByConditions1(String name,String uid, String subUid, String productKey,
String groupId, Boolean online, String keyword, String groupId, Boolean online, String keyword,
int page, int size,Long areaDepeId,String startTime,String endTime); int page, int size,Long areaDepeId,String startTime,String endTime,String deviceName);
/** /**
* *
* *
@ -197,6 +197,6 @@ public interface IDeviceInfoData extends IOwnedData<DeviceInfo, String> {
* @return * @return
*/ */
List<DeviceInfo> findNeverUsedDevices(); List<DeviceInfo> findNeverUsedDevices();
Long findNeverUsedDevices(DeviceInfo deviceInfo,Boolean flag);
List<AlertStatDTO> getDeviceRecord(); List<AlertStatDTO> getDeviceRecord();
} }

@ -0,0 +1,36 @@
/*
*
* * | 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.data.manager;
import cc.iotkit.data.ICommonData;
import cc.iotkit.data.IOwnedData;
import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.device.DeviceInstallInfo;
import cc.iotkit.model.device.DeviceIssue;
public interface IDeviceIssueData extends ICommonData<DeviceIssue, String> {
DeviceIssue findByTenantId(Long tenantId);
}

@ -223,6 +223,10 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
public List<DeviceInfo> findNeverUsedDevices() { public List<DeviceInfo> findNeverUsedDevices() {
return deviceInfoData.findNeverUsedDevices(); return deviceInfoData.findNeverUsedDevices();
} }
@Override
public Long findNeverUsedDevices(DeviceInfo deviceInfo,Boolean flag) {
return deviceInfoData.findNeverUsedDevices(deviceInfo,flag);
}
@Override @Override
public List<String> findSubDeviceIds(String parentId) { public List<String> findSubDeviceIds(String parentId) {
@ -231,8 +235,8 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
@Override @Override
public Paging<DeviceInfo> findByConditions(String name,String uid, String subUid, String productKey, public Paging<DeviceInfo> findByConditions(String name,String uid, String subUid, String productKey,
String groupId, Boolean state, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime) { String groupId, Boolean state, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime,String deviceName) {
return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, state, keyword, page, size,deptAreaId,startTime,endTime); return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, state, keyword, page, size,deptAreaId,startTime,endTime,deviceName);
} }
@Override @Override
public Paging<DeviceInfo> findByConditionsExcel(String name,String uid, String subUid, String productKey, public Paging<DeviceInfo> findByConditionsExcel(String name,String uid, String subUid, String productKey,
@ -242,8 +246,8 @@ public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSi
public Paging<DeviceInfo> findByConditions1(String name,String uid, String subUid, String productKey, public Paging<DeviceInfo> findByConditions1(String name,String uid, String subUid, String productKey,
String groupId, Boolean state, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime) { String groupId, Boolean state, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime,String deviceName) {
return deviceInfoData.findByConditions1(name,uid, subUid, productKey, groupId, state, keyword, page, size,deptAreaId,startTime,endTime); return deviceInfoData.findByConditions1(name,uid, subUid, productKey, groupId, state, keyword, page, size,deptAreaId,startTime,endTime,deviceName);
} }
@Override @Override
public void updateTag(String deviceId, DeviceInfo.Tag tag) { public void updateTag(String deviceId, DeviceInfo.Tag tag) {

@ -187,8 +187,8 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
} }
@Override @Override
public Paging<DeviceInfo> findByConditions(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime) { public Paging<DeviceInfo> findByConditions(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime,String deviceName) {
return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, online, keyword, page, size,deptAreaId,startTime,endTime); return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, online, keyword, page, size,deptAreaId,startTime,endTime,deviceName);
} }
@Override @Override
public Paging<DeviceInfo> findByConditionsExcel(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime) { public Paging<DeviceInfo> findByConditionsExcel(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime) {
@ -196,8 +196,8 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
} }
@Override @Override
public Paging<DeviceInfo> findByConditions1(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime) { public Paging<DeviceInfo> findByConditions1(String name,String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId,String startTime,String endTime,String deviceName) {
return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, online, keyword, page, size,deptAreaId,startTime, endTime); return deviceInfoData.findByConditions(name,uid, subUid, productKey, groupId, online, keyword, page, size,deptAreaId,startTime, endTime,deviceName);
} }
@Override @Override
public void updateTag(String deviceId, DeviceInfo.Tag tag) { public void updateTag(String deviceId, DeviceInfo.Tag tag) {
@ -253,7 +253,10 @@ public class DeviceInfoPropertyDataCache implements IDeviceInfoData {
public List<DeviceInfo> findNeverUsedDevices() { public List<DeviceInfo> findNeverUsedDevices() {
return deviceInfoData.findNeverUsedDevices(); return deviceInfoData.findNeverUsedDevices();
} }
@Override
public Long findNeverUsedDevices(DeviceInfo deviceInfo,Boolean flag) {
return deviceInfoData.findNeverUsedDevices(deviceInfo,flag);
}
@Override @Override
public List<DeviceInfo> findByUid(String uid) { public List<DeviceInfo> findByUid(String uid) {
return deviceInfoData.findByUid(uid); return deviceInfoData.findByUid(uid);

@ -0,0 +1,33 @@
/*
*
* * | 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.data.dao;
import cc.iotkit.data.model.TbDeviceInstallInfo;
import cc.iotkit.data.model.TbDeviceIssue;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
public interface DeviceIssueRepository extends JpaRepository<TbDeviceIssue, String>, QuerydslPredicateExecutor<TbDeviceIssue> {
TbDeviceIssue findByTenantId(Long tenantId);
}

@ -89,6 +89,15 @@ public class TbAlertRecord extends BaseEntity implements TenantAware {
private Boolean readFlg; private Boolean readFlg;
private Long tenantId; private Long tenantId;
private Long deptAreaId; private Long deptAreaId;
@ApiModelProperty(value = "清除原因(0测试”、“1点检”、“2已确认)")
private Integer reasonForRemoval;
@ApiModelProperty(value = "1已清除0未清除")
private Integer reasonForRemovalFlag;
@ApiModelProperty(value = "设备安装地址")
private String site;
private String deviceName;
private String productKey;
private String levelStatus;
} }

@ -0,0 +1,65 @@
/*
*
* * | 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.data.model;
import cc.iotkit.common.tenant.dao.TenantAware;
import cc.iotkit.common.tenant.listener.TenantListener;
import cc.iotkit.model.device.DeviceInstallInfo;
import cc.iotkit.model.device.DeviceIssue;
import io.github.linpeilie.annotations.AutoMapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.ParamDef;
import javax.persistence.*;
import java.util.Date;
@Data
@Entity
@Table(name = "device_issue")
@ApiModel(value = "设备下发权限")
@AutoMapper(target = DeviceIssue.class)
@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")})
@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")
@EntityListeners(TenantListener.class)
public class TbDeviceIssue extends BaseEntity implements TenantAware {
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
private String id;
@ApiModelProperty(value = "产品key")
private String productKey;
@ApiModelProperty(value = "字段标识")
private String fieldName;
@ApiModelProperty(value = "租户编号")
private Long tenantId;
private String fieldNameValue;
}

@ -25,6 +25,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.enums.UserType;
import cc.iotkit.common.satoken.utils.AuthUtil; import cc.iotkit.common.satoken.utils.AuthUtil;
import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.tenant.helper.TenantHelper; import cc.iotkit.common.tenant.helper.TenantHelper;
@ -33,15 +34,19 @@ import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.data.dao.AlertRecordRepository; import cc.iotkit.data.dao.AlertRecordRepository;
import cc.iotkit.data.dao.IJPACommData; import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IAlertRecordData; import cc.iotkit.data.manager.IAlertRecordData;
import cc.iotkit.data.manager.IProductData;
import cc.iotkit.data.model.QTbAlertRecord; import cc.iotkit.data.model.QTbAlertRecord;
import cc.iotkit.data.model.TbAlertRecord; import cc.iotkit.data.model.TbAlertRecord;
import cc.iotkit.data.system.ISysUserData;
import cc.iotkit.data.util.PageBuilder; import cc.iotkit.data.util.PageBuilder;
import cc.iotkit.data.util.PredicateBuilder; import cc.iotkit.data.util.PredicateBuilder;
import cc.iotkit.model.alert.AlertConfig; import cc.iotkit.model.alert.AlertConfig;
import cc.iotkit.model.alert.AlertRecord; import cc.iotkit.model.alert.AlertRecord;
import cc.iotkit.model.alert.AlertRecordBo; import cc.iotkit.model.alert.AlertRecordBo;
import cc.iotkit.model.product.Product;
import cc.iotkit.model.stats.AlertStatDTO; import cc.iotkit.model.stats.AlertStatDTO;
import cc.iotkit.model.system.SysLoginInfo; import cc.iotkit.model.system.SysLoginInfo;
import cc.iotkit.model.system.SysUser;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.querydsl.core.QueryResults; import com.querydsl.core.QueryResults;
@ -53,6 +58,7 @@ import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -64,6 +70,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -71,6 +78,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cc.iotkit.data.model.QTbAlertRecord.tbAlertRecord; import static cc.iotkit.data.model.QTbAlertRecord.tbAlertRecord;
import static cc.iotkit.data.model.QTbDeviceInfo.tbDeviceInfo;
@Primary @Primary
@Service @Service
@ -81,12 +89,15 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData<Alert
@Autowired @Autowired
private JPAQueryFactory jpaQueryFactory; private JPAQueryFactory jpaQueryFactory;
@Autowired
private ISysUserData isSysUserData;
@Override @Override
public JpaRepository getBaseRepository() { public JpaRepository getBaseRepository() {
return alertRecordRepository; return alertRecordRepository;
} }
@Autowired
@Qualifier("productDataCache")
private IProductData productData;
@Override @Override
public Class getJpaRepositoryClass() { public Class getJpaRepositoryClass() {
return TbAlertRecord.class; return TbAlertRecord.class;
@ -99,19 +110,34 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData<Alert
private static Predicate genPredicate(AlertRecord data) { private static Predicate genPredicate(AlertRecord data) {
boolean flag = false; boolean flag = false;
if(ObjectUtils.isNotEmpty(data.getParams()) && !"".equals(data.getParams().get("endTime"))){ if(ObjectUtils.isNotEmpty(data.getParams()) && !"".equals(data.getParams().get("endTime"))){
flag = true; flag = true;
} }
if(ObjectUtils.isNotEmpty(data.getEndTime()) && !"".equals(data.getEndTime())){
Map map = new HashMap();
map.put("endTime",data.getEndTime());
map.put("beginTime",data.getBeginTime());
data.setParams(map);
flag = true;
}
if(!data.getStatusFlg()) { if(!data.getStatusFlg()) {
if (!LoginHelper.isSuperAdmin() && ObjectUtil.isNotNull(LoginHelper.getUserId())) { if (!LoginHelper.isSuperAdmin() && ObjectUtil.isNotNull(LoginHelper.getUserId())) {
String uid = AuthUtil.getUserId(); String uid = AuthUtil.getUserId();
data.setUid(uid); data.setUid(uid);
} }
} }
if(ObjectUtils.isNotEmpty(data)) { if(ObjectUtils.isNotEmpty(data)) {
if(!LoginHelper.isSuperAdmin()) { if(!LoginHelper.isSuperAdmin()) {
return PredicateBuilder.instance() return PredicateBuilder.instance()
.and(StringUtils.isNotBlank(data.getName()), () -> tbAlertRecord.name.like("%" + data.getName() + "%")) .and(StringUtils.isNotBlank(data.getName()), () -> tbAlertRecord.name.like("%" + data.getName() + "%"))
.and(StringUtils.isNotBlank(data.getDeviceName()), () -> tbAlertRecord.deviceName.like("%" + data.getDeviceName() + "%"))
.and(ObjectUtils.isNotEmpty(data.getReasonForRemoval()), () -> tbAlertRecord.reasonForRemoval.eq(data.getReasonForRemoval()))
.and(ObjectUtils.isNotEmpty(data.getDeptAreaId()), () -> tbAlertRecord.deptAreaId.eq(data.getDeptAreaId()))
.and(ObjectUtils.isNotEmpty(data.getLevelStatus()), () -> tbAlertRecord.levelStatus.like("%" + data.getLevelStatus() + "%"))
.and(ObjectUtils.isNotEmpty(data.getProductKey()), () -> tbAlertRecord.productKey.eq(data.getProductKey()))
.and(ObjectUtils.isNotEmpty(data.getReasonForRemovalFlag()), () -> tbAlertRecord.reasonForRemovalFlag.eq(data.getReasonForRemovalFlag()))
.and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) .and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel()))
.and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid())) .and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid()))
.and(ObjectUtil.isNotEmpty(TenantHelper.getTenantId()), () -> tbAlertRecord.tenantId.eq(TenantHelper.getTenantId())) .and(ObjectUtil.isNotEmpty(TenantHelper.getTenantId()), () -> tbAlertRecord.tenantId.eq(TenantHelper.getTenantId()))
@ -121,6 +147,12 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData<Alert
if(TenantHelper.getTenantId() != 0) { if(TenantHelper.getTenantId() != 0) {
return PredicateBuilder.instance() return PredicateBuilder.instance()
.and(StringUtils.isNotBlank(data.getName()), () -> tbAlertRecord.name.like("%" + data.getName() + "%")) .and(StringUtils.isNotBlank(data.getName()), () -> tbAlertRecord.name.like("%" + data.getName() + "%"))
.and(StringUtils.isNotBlank(data.getDeviceName()), () -> tbAlertRecord.deviceName.like("%" + data.getDeviceName() + "%"))
.and(ObjectUtils.isNotEmpty(data.getReasonForRemoval()), () -> tbAlertRecord.reasonForRemoval.eq(data.getReasonForRemoval()))
.and(ObjectUtils.isNotEmpty(data.getLevelStatus()), () -> tbAlertRecord.levelStatus.like("%" + data.getLevelStatus() + "%"))
.and(ObjectUtils.isNotEmpty(data.getProductKey()), () -> tbAlertRecord.productKey.eq(data.getProductKey()))
.and(ObjectUtils.isNotEmpty(data.getDeptAreaId()), () -> tbAlertRecord.deptAreaId.eq(data.getDeptAreaId()))
.and(ObjectUtils.isNotEmpty(data.getReasonForRemovalFlag()), () -> tbAlertRecord.reasonForRemovalFlag.eq(data.getReasonForRemovalFlag()))
.and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) .and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel()))
.and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid())) .and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid()))
.and(ObjectUtil.isNotEmpty(TenantHelper.getTenantId()), () -> tbAlertRecord.tenantId.eq(TenantHelper.getTenantId())) .and(ObjectUtil.isNotEmpty(TenantHelper.getTenantId()), () -> tbAlertRecord.tenantId.eq(TenantHelper.getTenantId()))
@ -129,6 +161,12 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData<Alert
}else{ }else{
return PredicateBuilder.instance() return PredicateBuilder.instance()
.and(StringUtils.isNotBlank(data.getName()), () -> tbAlertRecord.name.like("%" + data.getName() + "%")) .and(StringUtils.isNotBlank(data.getName()), () -> tbAlertRecord.name.like("%" + data.getName() + "%"))
.and(StringUtils.isNotBlank(data.getDeviceName()), () -> tbAlertRecord.deviceName.like("%" + data.getDeviceName() + "%"))
.and(ObjectUtils.isNotEmpty(data.getReasonForRemoval()), () -> tbAlertRecord.reasonForRemoval.eq(data.getReasonForRemoval()))
.and(ObjectUtils.isNotEmpty(data.getLevelStatus()), () -> tbAlertRecord.levelStatus.like("%" + data.getLevelStatus() + "%"))
.and(ObjectUtils.isNotEmpty(data.getProductKey()), () -> tbAlertRecord.productKey.eq(data.getProductKey()))
.and(ObjectUtils.isNotEmpty(data.getDeptAreaId()), () -> tbAlertRecord.deptAreaId.eq(data.getDeptAreaId()))
.and(ObjectUtils.isNotEmpty(data.getReasonForRemovalFlag()), () -> tbAlertRecord.reasonForRemovalFlag.eq(data.getReasonForRemovalFlag()))
.and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) .and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel()))
.and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid())) .and(StringUtils.isNotBlank(data.getUid()), () -> tbAlertRecord.uid.eq(data.getUid()))
// .and(ObjectUtil.isNotEmpty(TenantHelper.getTenantId()), () -> tbAlertRecord.tenantId.eq(TenantHelper.getTenantId())) // .and(ObjectUtil.isNotEmpty(TenantHelper.getTenantId()), () -> tbAlertRecord.tenantId.eq(TenantHelper.getTenantId()))
@ -168,15 +206,40 @@ public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData<Alert
.orderBy(tbAlertRecord.id.desc()) .orderBy(tbAlertRecord.id.desc())
.limit(request.getPageSize()) .limit(request.getPageSize())
.offset(request.getOffset()).fetchResults(); .offset(request.getOffset()).fetchResults();
Paging<AlertRecord> result = new Paging<>(results.getTotal(), results.getResults()).to(AlertRecord.class);
for (AlertRecord row : result.getRows()) {
if(ObjectUtil.isNotEmpty(row.getProductKey())) {
Product product = productData.findByProductKey(row.getProductKey());
if(ObjectUtil.isNotEmpty(product)) {
row.setProductName(product.getName());
}
}
}
/* // 将alertTime乘以1000 /* // 将alertTime乘以1000
List<TbAlertRecord> convertedResults = results.getResults().stream() List<TbAlertRecord> convertedResults = results.getResults().stream()
.peek(record -> record.setAlertTime(record.getAlertTime() * 1000)) .peek(record -> record.setAlertTime(record.getAlertTime() * 1000))
.collect(Collectors.toList());*/ .collect(Collectors.toList());*/
return new Paging<>(results.getTotal(), results.getResults()).to(AlertRecord.class); return result;
} }
@Override
public Paging<AlertRecord> selectAlertRecordPageExcel(PageRequest<AlertRecord> request) {
QueryResults<TbAlertRecord> results = jpaQueryFactory.selectFrom(tbAlertRecord)
.where(genPredicate(request.getData()))
.orderBy(tbAlertRecord.id.desc()).fetchResults();
// .limit(request.getPageSize())
// .offset(request.getOffset())
/* // 将alertTime乘以1000
List<TbAlertRecord> convertedResults = results.getResults().stream()
.peek(record -> record.setAlertTime(record.getAlertTime() * 1000))
.collect(Collectors.toList());*/
return new Paging<>(results.getTotal(), results.getResults()).to(AlertRecord.class);
}
private String extractByPattern(String text, String regex) { private String extractByPattern(String text, String regex) {
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);

@ -139,15 +139,15 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
public SysDeptDto getStatsCount(Long deptAreaId){ public SysDeptDto getStatsCount(Long deptAreaId){
SysDeptDto statistics = new SysDeptDto(); SysDeptDto statistics = new SysDeptDto();
List<Long> areaIds = null; List<Long> areaIds = new ArrayList<>();
List<Tuple> results = null; List<Tuple> results = null;
if (ObjectUtil.isNotNull(deptAreaId)) { if (ObjectUtil.isNotNull(deptAreaId)) {
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
Long areaId = deptAreaId; /* Long areaId = deptAreaId;
List<SysDept> depts = sysDeptData.findByDeptId(areaId); List<SysDept> depts = sysDeptData.findByDeptId(areaId);
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);*/
areaIds.add(areaId); areaIds.add(deptAreaId);
/* if (ObjectUtil.isNotEmpty(areaIds)) { /* if (ObjectUtil.isNotEmpty(areaIds)) {
query.where(tbDeviceInfo.deptAreaId.in(areaIds)); query.where(tbDeviceInfo.deptAreaId.in(areaIds));
}*/ }*/
@ -159,8 +159,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
Long areaId = user.getDeptAreaId(); Long areaId = user.getDeptAreaId();
List<SysDept> depts = sysDeptData.findByDeptId(areaId); /* List<SysDept> depts = sysDeptData.findByDeptId(areaId);
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);*/
areaIds.add(areaId); areaIds.add(areaId);
} }
/* if (ObjectUtil.isNotEmpty(areaIds)) { /* if (ObjectUtil.isNotEmpty(areaIds)) {
@ -438,6 +438,26 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
return MapstructUtils.convert(devices, DeviceInfo.class); return MapstructUtils.convert(devices, DeviceInfo.class);
} }
@Override @Override
public Long findNeverUsedDevices(DeviceInfo deviceInfo,Boolean flag) {
JPAQuery<TbDeviceInfo> query = jpaQueryFactory.selectFrom(tbDeviceInfo);
if( flag){
query.where(tbDeviceInfo.state.eq(deviceInfo.getState().isOnline() ? "online" : "offline"));
}else {
query.where(tbDeviceInfo.onlineTime.isNull());
}
if(ObjectUtil.isNotNull(TenantHelper.getTenantId())) {
if (!LoginHelper.isSuperAdmin()) {
query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId()));
} else if (LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() != 0) {
query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId()));
}
}
Long count = query.fetchCount();
return count;
}
@Override
public List<AlertStatDTO> getDeviceRecord() { public List<AlertStatDTO> getDeviceRecord() {
QTbDeviceInfo device = tbDeviceInfo; QTbDeviceInfo device = tbDeviceInfo;
QTbProduct product = tbProduct; QTbProduct product = tbProduct;
@ -502,8 +522,15 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
// 根据groupId, 如果groupId存在则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices // 根据groupId, 如果groupId存在则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices
if (StringUtils.isNotBlank(groupId)) { if (StringUtils.isNotBlank(groupId)) {
if(!groupId.equals("0")) {
query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId)); query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId));
query.where(tbDeviceGroupMapping.groupId.eq(groupId));
query.where(tbDeviceGroupMapping.groupId.eq(groupId));
}
}else{
query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId));
query.where(tbDeviceGroupMapping.groupId.isNull());
} }
@ -518,15 +545,17 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId())); query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId()));
} }
if (ObjectUtil.isNotNull(deptAreaId)) { if (ObjectUtil.isNotNull(deptAreaId)) {
List<Long> areaIds; // List<Long> areaIds;
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
Long areaId = deptAreaId; /* Long areaId = deptAreaId;
List<SysDept> depts = sysDeptData.findByDeptId(areaId); List<SysDept> depts = sysDeptData.findByDeptId(areaId);
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);
areaIds.add(areaId); areaIds.add(areaId);
if (ObjectUtil.isNotEmpty(areaIds)) { if (ObjectUtil.isNotEmpty(areaIds)) {*/
query.where(tbDeviceInfo.deptAreaId.in(areaIds)); if(deptAreaId != 0) {
query.where(tbDeviceInfo.deptAreaId.in(deptAreaId));
} }
// }
}else{ }else{
if(!LoginHelper.isSuperAdmin()) { if(!LoginHelper.isSuperAdmin()) {
if(ObjectUtil.isNotEmpty(LoginHelper.getUserId())) { if(ObjectUtil.isNotEmpty(LoginHelper.getUserId())) {
@ -536,13 +565,13 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
if (ObjectUtil.isNotNull(user.getDeptAreaId())) { if (ObjectUtil.isNotNull(user.getDeptAreaId())) {
List<Long> areaIds; List<Long> areaIds;
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
Long areaId = user.getDeptAreaId(); /* Long areaId = user.getDeptAreaId();
List<SysDept> depts = sysDeptData.findByDeptId(areaId); List<SysDept> depts = sysDeptData.findByDeptId(areaId);
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);
areaIds.add(areaId); areaIds.add(areaId);
if (ObjectUtil.isNotEmpty(areaIds)) { if (ObjectUtil.isNotEmpty(areaIds)) {*/
query.where(tbDeviceInfo.deptAreaId.in(areaIds)); query.where(tbDeviceInfo.deptAreaId.in(user.getDeptAreaId()));
} // }
} else { } else {
if(ObjectUtil.isNotEmpty(LoginHelper.getUserType()) && !LoginHelper.getUserType().equals(UserType.APP_USER)) { if(ObjectUtil.isNotEmpty(LoginHelper.getUserType()) && !LoginHelper.getUserType().equals(UserType.APP_USER)) {
//没有绑定区域查不到设备 //没有绑定区域查不到设备
@ -552,6 +581,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
} }
} }
}else{
query.where(tbDeviceInfo.deptAreaId.isNull());
} }
} }
if (StringUtils.isNotBlank(subUid)) { if (StringUtils.isNotBlank(subUid)) {
@ -601,13 +632,20 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
public Paging<DeviceInfo> findByConditions(String name, String uid, String subUid, public Paging<DeviceInfo> findByConditions(String name, String uid, String subUid,
String productKey, String groupId, String productKey, String groupId,
Boolean online, String keyword, Boolean online, String keyword,
int page, int size, Long deptAreaId,String startTime,String endTime) { int page, int size, Long deptAreaId,String startTime,String endTime,String deviceName) {
JPAQuery<TbDeviceInfo> query = jpaQueryFactory.selectFrom(tbDeviceInfo); JPAQuery<TbDeviceInfo> query = jpaQueryFactory.selectFrom(tbDeviceInfo);
// 根据groupId, 如果groupId存在则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices // 根据groupId, 如果groupId存在则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices
if (StringUtils.isNotBlank(groupId)) { if (StringUtils.isNotBlank(groupId)) {
if(!groupId.equals("0")){
query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId)); query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId));
query.where(tbDeviceGroupMapping.groupId.eq(groupId)); // query.where(tbDeviceGroupMapping.groupId.eq(groupId));
query.where(tbDeviceGroupMapping.groupId.eq(groupId));
}
}else{
query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId));
query.where(tbDeviceGroupMapping.groupId.isNull());
} }
@ -617,20 +655,26 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
if (StringUtils.isNotBlank(name)) { if (StringUtils.isNotBlank(name)) {
query.where(tbDeviceInfo.name.like("%" + name + "%")); query.where(tbDeviceInfo.name.like("%" + name + "%"));
} }
if (StringUtils.isNotBlank(deviceName)) {
query.where(tbDeviceInfo.deviceName.like("%" + deviceName + "%"));
}
System.out.println(TenantHelper.getTenantId()); System.out.println(TenantHelper.getTenantId());
if (ObjectUtil.isNotNull(TenantHelper.getTenantId()) && (!LoginHelper.isSuperAdmin() || TenantHelper.getTenantId()!=0)) { if (ObjectUtil.isNotNull(TenantHelper.getTenantId()) && (!LoginHelper.isSuperAdmin() || TenantHelper.getTenantId()!=0)) {
query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId())); query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId()));
} }
if (ObjectUtil.isNotNull(deptAreaId)) { if (ObjectUtil.isNotNull(deptAreaId)) {
List<Long> areaIds; /* List<Long> areaIds;
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
Long areaId = deptAreaId; Long areaId = deptAreaId;
List<SysDept> depts = sysDeptData.findByDeptId(areaId); List<SysDept> depts = sysDeptData.findByDeptId(areaId);
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);
areaIds.add(areaId); areaIds.add(areaId);
if (ObjectUtil.isNotEmpty(areaIds)) { if (ObjectUtil.isNotEmpty(areaIds)) {*/
query.where(tbDeviceInfo.deptAreaId.in(areaIds)); if(deptAreaId != 0) {
query.where(tbDeviceInfo.deptAreaId.in(deptAreaId));
} }
// query.where(tbDeviceInfo.deptAreaId.in(deptAreaId));
// }
}else{ }else{
if(!LoginHelper.isSuperAdmin()) { if(!LoginHelper.isSuperAdmin()) {
if(ObjectUtil.isNotEmpty(LoginHelper.getUserId())) { if(ObjectUtil.isNotEmpty(LoginHelper.getUserId())) {
@ -638,15 +682,15 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
SysUser user = isSysUserData.findById(LoginHelper.getUserId()); SysUser user = isSysUserData.findById(LoginHelper.getUserId());
if (ObjectUtil.isNotNull(user)) { if (ObjectUtil.isNotNull(user)) {
if (ObjectUtil.isNotNull(user.getDeptAreaId())) { if (ObjectUtil.isNotNull(user.getDeptAreaId())) {
List<Long> areaIds; /* List<Long> areaIds;
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
Long areaId = user.getDeptAreaId(); Long areaId = user.getDeptAreaId();
List<SysDept> depts = sysDeptData.findByDeptId(areaId); List<SysDept> depts = sysDeptData.findByDeptId(areaId);
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);
areaIds.add(areaId); areaIds.add(areaId);
if (ObjectUtil.isNotEmpty(areaIds)) { if (ObjectUtil.isNotEmpty(areaIds)) {*/
query.where(tbDeviceInfo.deptAreaId.in(areaIds)); query.where(tbDeviceInfo.deptAreaId.in(user.getDeptAreaId()));
} // }
} else { } else {
if(ObjectUtil.isNotEmpty(LoginHelper.getUserType()) && !LoginHelper.getUserType().equals(UserType.APP_USER)) { if(ObjectUtil.isNotEmpty(LoginHelper.getUserType()) && !LoginHelper.getUserType().equals(UserType.APP_USER)) {
//没有绑定区域查不到设备 //没有绑定区域查不到设备
@ -707,13 +751,20 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
public Paging<DeviceInfo> findByConditions1(String name, String uid, String subUid, public Paging<DeviceInfo> findByConditions1(String name, String uid, String subUid,
String productKey, String groupId, String productKey, String groupId,
Boolean online, String keyword, Boolean online, String keyword,
int page, int size, Long deptAreaId,String startTime,String endTime) { int page, int size, Long deptAreaId,String startTime,String endTime,String deviceName) {
JPAQuery<TbDeviceInfo> query = jpaQueryFactory.selectFrom(tbDeviceInfo); JPAQuery<TbDeviceInfo> query = jpaQueryFactory.selectFrom(tbDeviceInfo);
// 根据groupId, 如果groupId存在则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices // 根据groupId, 如果groupId存在则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices
if (StringUtils.isNotBlank(groupId)) { if (StringUtils.isNotBlank(groupId)) {
if(!groupId.equals("0")) {
query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId)); query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId));
query.where(tbDeviceGroupMapping.groupId.eq(groupId));
query.where(tbDeviceGroupMapping.groupId.eq(groupId));
}
}else{
query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId));
query.where(tbDeviceGroupMapping.groupId.isNull());
} }
@ -723,12 +774,18 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
if (StringUtils.isNotBlank(name)) { if (StringUtils.isNotBlank(name)) {
query.where(tbDeviceInfo.name.like("%" + name + "%")); query.where(tbDeviceInfo.name.like("%" + name + "%"));
} }
if (StringUtils.isNotBlank(deviceName)) {
query.where(tbDeviceInfo.deviceName.like("%" + deviceName + "%"));
}
System.out.println(TenantHelper.getTenantId()); System.out.println(TenantHelper.getTenantId());
if (ObjectUtil.isNotNull(TenantHelper.getTenantId()) && (!LoginHelper.isSuperAdmin() || TenantHelper.getTenantId()!=0)) { if (ObjectUtil.isNotNull(TenantHelper.getTenantId()) && (!LoginHelper.isSuperAdmin() || TenantHelper.getTenantId()!=0)) {
query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId())); query.where(tbDeviceInfo.tenantId.eq(TenantHelper.getTenantId()));
} }
if (ObjectUtil.isNotNull(deptAreaId)) { if (ObjectUtil.isNotNull(deptAreaId)) {
query.where(tbDeviceInfo.deptAreaId.eq(deptAreaId)); if(deptAreaId != 0) {
query.where(tbDeviceInfo.deptAreaId.in(deptAreaId));
}
// query.where(tbDeviceInfo.deptAreaId.eq(deptAreaId));
}else{ }else{
if(!LoginHelper.isSuperAdmin()) { if(!LoginHelper.isSuperAdmin()) {
if(ObjectUtil.isNotEmpty(LoginHelper.getUserId())) { if(ObjectUtil.isNotEmpty(LoginHelper.getUserId())) {
@ -744,7 +801,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
} }
} }
} }
}else{
query.where(tbDeviceInfo.deptAreaId.isNull());
} }
} }
if (StringUtils.isNotBlank(subUid)) { if (StringUtils.isNotBlank(subUid)) {
@ -974,8 +1032,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
if (ObjectUtil.isNotNull(deptAreaId)) { if (ObjectUtil.isNotNull(deptAreaId)) {
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
Long areaId = deptAreaId; Long areaId = deptAreaId;
List<SysDept> depts = sysDeptData.findByDeptId(areaId); /* List<SysDept> depts = sysDeptData.findByDeptId(areaId);
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);*/
areaIds.add(areaId); areaIds.add(areaId);
/* if (ObjectUtil.isNotEmpty(areaIds)) { /* if (ObjectUtil.isNotEmpty(areaIds)) {
query.where(tbDeviceInfo.deptAreaId.in(areaIds)); query.where(tbDeviceInfo.deptAreaId.in(areaIds));
@ -985,8 +1043,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
if(ObjectUtil.isNotNull(LoginHelper.getUserId())){ if(ObjectUtil.isNotNull(LoginHelper.getUserId())){
SysUser sysUser = isSysUserData.findById(LoginHelper.getUserId()); SysUser sysUser = isSysUserData.findById(LoginHelper.getUserId());
if (ObjectUtil.isNotNull(sysUser) && ObjectUtil.isNotNull(sysUser.getDeptAreaId())) { if (ObjectUtil.isNotNull(sysUser) && ObjectUtil.isNotNull(sysUser.getDeptAreaId())) {
List<SysDept> depts = sysDeptData.findByDeptId(sysUser.getDeptAreaId()); /* List<SysDept> depts = sysDeptData.findByDeptId(sysUser.getDeptAreaId());
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);*/
areaIds.add(sysUser.getDeptAreaId()); areaIds.add(sysUser.getDeptAreaId());
} }
} }
@ -995,6 +1053,7 @@ public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData<DeviceI
if(ObjectUtil.isNull(deptAreaId) && LoginHelper.isSuperAdmin() && ObjectUtil.isNotNull(TenantHelper.getTenantId()) && TenantHelper.getTenantId() != 0) { if(ObjectUtil.isNull(deptAreaId) && LoginHelper.isSuperAdmin() && ObjectUtil.isNotNull(TenantHelper.getTenantId()) && TenantHelper.getTenantId() != 0) {
List<SysDept> depts = sysDeptData.findByTenantId(TenantHelper.getTenantId()); List<SysDept> depts = sysDeptData.findByTenantId(TenantHelper.getTenantId());
areaIds = StreamUtils.toList(depts, SysDept::getId); areaIds = StreamUtils.toList(depts, SysDept::getId);
//areaIds.add(sysUser.getDeptAreaId()); //areaIds.add(sysUser.getDeptAreaId());
} }

@ -0,0 +1,74 @@
/*
*
* * | 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.data.service;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.DeviceInstallInfoRepository;
import cc.iotkit.data.dao.DeviceIssueRepository;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IDeviceInstallInfoData;
import cc.iotkit.data.manager.IDeviceIssueData;
import cc.iotkit.data.model.TbDeviceInstallInfo;
import cc.iotkit.data.model.TbDeviceIssue;
import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.device.DeviceInstallInfo;
import cc.iotkit.model.device.DeviceIssue;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Primary
@Service
@RequiredArgsConstructor
public class DeviceIssueDataImpl implements IDeviceIssueData, IJPACommData<DeviceIssue,String> {
@Autowired
private DeviceIssueRepository homeRepository;
private final JPAQueryFactory jpaQueryFactory;
@Override
public JpaRepository getBaseRepository() {
return homeRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbDeviceIssue.class;
}
@Override
public Class getTClass() {
return DeviceIssue.class;
}
@Override
public DeviceIssue findByTenantId(Long tenantId) {
return MapstructUtils.convert(homeRepository.findByTenantId(tenantId), DeviceIssue.class);
}
}

@ -113,24 +113,26 @@ public class SysDeptDataImpl implements ISysDeptData, IJPACommData<SysDept, Long
}*/ }*/
if (!LoginHelper.isSuperAdmin()) { if (!LoginHelper.isSuperAdmin()) {
predicateBuilder.and(ObjectUtil.isNotNull(dept.getTenantId()), () -> tbSysDept.tenantId.eq(dept.getTenantId())); predicateBuilder.and(ObjectUtil.isNotNull(dept.getTenantId()), () -> tbSysDept.tenantId.eq(dept.getTenantId()));
Optional<TbSysUser> tbSysUser = sysUserData.findById(LoginHelper.getUserId()); if (ObjectUtil.isNotEmpty(LoginHelper.getUserId())) {
List<Long> areaIds; Optional<TbSysUser> tbSysUser = sysUserData.findById(LoginHelper.getUserId());
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { List<Long> areaIds;
// if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) {
if (ObjectUtil.isNotEmpty(tbSysUser) && ObjectUtil.isNotEmpty(LoginHelper.getUserType()) && !LoginHelper.getUserType().equals(UserType.APP_USER)) {
if (ObjectUtil.isNotNull(dept.getAreaType()) && dept.getAreaType() == 1) { if (ObjectUtil.isNotEmpty(tbSysUser) && ObjectUtil.isNotEmpty(LoginHelper.getUserType()) && !LoginHelper.getUserType().equals(UserType.APP_USER)) {
//查询区域 if (ObjectUtil.isNotNull(dept.getAreaType()) && dept.getAreaType() == 1) {
Long areaId = tbSysUser.get().getDeptAreaId(); //查询区域
List<SysDept> depts = this.findByDeptId(areaId); Long areaId = tbSysUser.get().getDeptAreaId();
List<Long> filteredIds = depts.stream() List<SysDept> depts = this.findByDeptId(areaId);
.filter(dept1 -> dept1.getAreaType() == 1) List<Long> filteredIds = depts.stream()
.map(SysDept::getId) .filter(dept1 -> dept1.getAreaType() == 1)
.collect(Collectors.toList()); .map(SysDept::getId)
filteredIds.add(areaId); .collect(Collectors.toList());
filteredIds.add(areaId);
//areaIds = StreamUtils.toList(depts, SysDept::getId);
// areaIds.add(areaId); //areaIds = StreamUtils.toList(depts, SysDept::getId);
predicateBuilder.and(ObjectUtil.isNotNull(tbSysUser.get().getDeptAreaId()), () -> tbSysDept.id.in(filteredIds)); // areaIds.add(areaId);
predicateBuilder.and(ObjectUtil.isNotNull(tbSysUser.get().getDeptAreaId()), () -> tbSysDept.id.in(filteredIds));
}
} else { } else {
/* Long areaId = tbSysUser.get().getDeptId(); /* Long areaId = tbSysUser.get().getDeptId();
List<SysDept> depts = iSysDeptData.findByDeptId(areaId); List<SysDept> depts = iSysDeptData.findByDeptId(areaId);

@ -35,9 +35,9 @@ public class PDFGenerator {
public static void generateInstallationPDF(DeviceInstallInfo entity, OutputStream outputStream) throws IOException { public static void generateInstallationPDF(DeviceInstallInfo entity, OutputStream outputStream) throws IOException {
try (PDDocument document = new PDDocument()) { try (PDDocument document = new PDDocument()) {
// 加载字体(需替换实际路径) // 加载字体(需替换实际路径)
// PDType0Font font = PDType0Font.load(document, new File("D:\\NotoSansCJK-Regular.ttf")); //PDType0Font font = PDType0Font.load(document, new File("D:\\NotoSansCJK-Regular.ttf"));
//PDType0Font font = PDType0Font.load(document, new File("/ttf/simsun.ttf")); //PDType0Font font = PDType0Font.load(document, new File("/ttf/simsun.ttf"));
PDType0Font font = PDType0Font.load(document, new File("/ttf/NotoSansCJK-Regular.ttf")); PDType0Font font = PDType0Font.load(document, new File("/ttf/NotoSansCJK-Regular.ttf"));
// 初始化第一页 // 初始化第一页
PDPage currentPage = new PDPage(PDRectangle.A4); PDPage currentPage = new PDPage(PDRectangle.A4);
document.addPage(currentPage); document.addPage(currentPage);
@ -59,6 +59,7 @@ public class PDFGenerator {
{"申请人班组", entity.getProposerTeam()}, {"申请人班组", entity.getProposerTeam()},
{"小区名字", entity.getCommunityName()}, {"小区名字", entity.getCommunityName()},
{"用户姓名", entity.getUserName()}, {"用户姓名", entity.getUserName()},
// {"用户姓名", entity.getUserName()+"-" + entity.getCommunityName()+entity.getBuildingUnit()+entity.getRoomNo()},
{"电话", entity.getUserIpone()}, {"电话", entity.getUserIpone()},
{"楼栋单元号", entity.getBuildingUnit()}, {"楼栋单元号", entity.getBuildingUnit()},
{"房间号", entity.getRoomNo()}, {"房间号", entity.getRoomNo()},

@ -25,14 +25,24 @@ package cc.iotkit.manager.controller;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request; import cc.iotkit.common.api.Request;
import cc.iotkit.common.excel.utils.ExcelUtil;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.log.annotation.Log;
import cc.iotkit.common.log.enums.BusinessType;
import cc.iotkit.common.satoken.utils.AuthUtil; import cc.iotkit.common.satoken.utils.AuthUtil;
import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.tenant.helper.TenantHelper;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.manager.dto.bo.device.DeviceInfoBo; import cc.iotkit.manager.dto.bo.device.DeviceInfoBo;
import cc.iotkit.manager.dto.bo.device.DeviceQueryBo;
import cc.iotkit.manager.dto.vo.deviceinfo.AlertRecordExpordVo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoExpordVo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo;
import cc.iotkit.manager.service.AlertService; import cc.iotkit.manager.service.AlertService;
import cc.iotkit.model.alert.AlertConfig; import cc.iotkit.model.alert.AlertConfig;
import cc.iotkit.model.alert.AlertRecord; import cc.iotkit.model.alert.AlertRecord;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -44,6 +54,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
@ -112,7 +123,27 @@ public class AlertController {
request.getData().setStatusFlg(true); request.getData().setStatusFlg(true);
return alertService.selectAlertRecordPage(request); return alertService.selectAlertRecordPage(request);
} }
@ApiOperation("查询告警消息已读未读") @ApiOperation("导出告警消息列表")
@Log(title = "告警消息", businessType = BusinessType.EXPORT)
// @SaCheckPermission("system:user:export")@RequestBody Request<ProductBo>
@PostMapping("/export")
public void export(@Validated @RequestBody PageRequest<AlertRecord> deviceQueryBo,
HttpServletResponse response) {
if(ObjectUtil.isEmpty(deviceQueryBo)){
if(LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() == 0){
deviceQueryBo.getData().setTenantId(null);
}else{
deviceQueryBo.getData().setTenantId(TenantHelper.getTenantId());
}
}
deviceQueryBo.getData().setStatusFlg(true);
Paging<AlertRecord> list = alertService.selectAlertRecordPageExcel(deviceQueryBo);
// List<DeviceInfoVo> list = deviceServiceImpl.getDevicessExcel(deviceQueryBo);
List<AlertRecordExpordVo> listVo = MapstructUtils.convert(list.getRows(), AlertRecordExpordVo.class);
ExcelUtil.exportExcel(listVo, "告警信息数据", AlertRecordExpordVo.class, response);
}
@ApiOperation("添加修改报警消息")
// @SaCheckPermission("iot:alert:query") // @SaCheckPermission("iot:alert:query")
@PostMapping("/saveAlertRecord") @PostMapping("/saveAlertRecord")
public void saveAlertRecord(@RequestBody @Validated Request<AlertRecord> bo) { public void saveAlertRecord(@RequestBody @Validated Request<AlertRecord> bo) {

@ -31,6 +31,7 @@ import cc.iotkit.common.excel.core.CellMergeStrategy;
import cc.iotkit.common.excel.utils.ExcelUtil; import cc.iotkit.common.excel.utils.ExcelUtil;
import cc.iotkit.common.log.annotation.Log; import cc.iotkit.common.log.annotation.Log;
import cc.iotkit.common.log.enums.BusinessType; import cc.iotkit.common.log.enums.BusinessType;
import cc.iotkit.common.redis.utils.RedisUtils;
import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.tenant.helper.TenantHelper; import cc.iotkit.common.tenant.helper.TenantHelper;
import cc.iotkit.common.thing.ThingModelMessage; import cc.iotkit.common.thing.ThingModelMessage;
@ -57,7 +58,11 @@ import cc.iotkit.model.device.DeviceConfig;
import cc.iotkit.model.device.DeviceGroup; import cc.iotkit.model.device.DeviceGroup;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.model.device.message.DeviceProperty;
import cc.iotkit.model.stats.SysDeptDto;
import cc.iotkit.plugin.main.ThingServiceImpl;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.ExcelWriter;
@ -65,6 +70,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.sl.usermodel.Sheet;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RMap;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -72,9 +79,12 @@ import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.util.*;
import java.util.List; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static cc.iotkit.common.redis.utils.RedisUtils.setCacheMapValue;
import static cc.iotkit.common.web.core.BaseController.fail; import static cc.iotkit.common.web.core.BaseController.fail;
@Api(tags = {"设备"}) @Api(tags = {"设备"})
@ -91,6 +101,8 @@ public class DeviceController {
private DeviceCtrlService deviceCtrlService; private DeviceCtrlService deviceCtrlService;
@Autowired @Autowired
private IDeviceManagerService deviceServiceImpl; private IDeviceManagerService deviceServiceImpl;
@Autowired
private ThingServiceImpl thingService;
@ApiOperation(value = "服务调用", notes = "服务调用", httpMethod = "POST") @ApiOperation(value = "服务调用", notes = "服务调用", httpMethod = "POST")
@ -115,7 +127,7 @@ public class DeviceController {
} }
@ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "POST") @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "POST")
@SaCheckPermission("iot:device:query") //@SaCheckPermission("iot:device:query")
@PostMapping("/list") @PostMapping("/list")
public Paging<DeviceInfoVo> getDevices(@Validated @RequestBody PageRequest<DeviceQueryBo> pageRequest) { public Paging<DeviceInfoVo> getDevices(@Validated @RequestBody PageRequest<DeviceQueryBo> pageRequest) {
return deviceServiceImpl.getDevices(pageRequest); return deviceServiceImpl.getDevices(pageRequest);
@ -132,7 +144,19 @@ public class DeviceController {
public boolean createDevice(@RequestBody @Validated Request<DeviceInfoAddBo> bo) { public boolean createDevice(@RequestBody @Validated Request<DeviceInfoAddBo> bo) {
return deviceServiceImpl.addDevice(bo.getData()); return deviceServiceImpl.addDevice(bo.getData());
} }
@ApiOperation(value = "联动控制箱下发指令")
// @SaCheckPermission("iot:device:add")
@PostMapping("/deviceLinkageControlSend")
public boolean deviceLinkageControlSend(@RequestBody @Validated Request<DeviceInfo> bo) {
boolean result = false;
if(bo.getData()!=null && ObjectUtil.isNotNull(bo.getData().getNodes())){
for (String node:bo.getData().getNodes().split(",")) {
result = thingService.deviceLinkageControlSend(bo.getData(), node);
}
}
return result;
// return deviceServiceImpl.addDevice(bo.getData());
}
@ApiOperation(value = "保存设备") @ApiOperation(value = "保存设备")
@SaCheckPermission("iot:device:edit") @SaCheckPermission("iot:device:edit")
@PostMapping("/save") @PostMapping("/save")
@ -148,6 +172,8 @@ public class DeviceController {
return deviceServiceImpl.selectChildrenPageList(deviceId); return deviceServiceImpl.selectChildrenPageList(deviceId);
} }
@ApiOperation("获取网关设备") @ApiOperation("获取网关设备")
@SaCheckPermission("iot:device:query") @SaCheckPermission("iot:device:query")
@PostMapping("/getParentDevices") @PostMapping("/getParentDevices")
@ -421,6 +447,55 @@ public class DeviceController {
String deviceId = bo.getData(); String deviceId = bo.getData();
return new InvokeResult(deviceCtrlService.sendConfig(deviceId)); return new InvokeResult(deviceCtrlService.sendConfig(deviceId));
} }
/**
*
*/
@ApiOperation(value = "设备配置批量下发")
@SaCheckPermission("iot:device:ctrl")
@PostMapping("/config/sends")
public Integer sendConfig(@Validated @RequestBody PageRequest<DeviceQueryBo> deviceQueryBo) {
ExecutorService executor = Executors.newFixedThreadPool(50);
if(ObjectUtil.isNull(deviceQueryBo.getData().getConfig())){
fail("参数错误");
}
List<DeviceInfoVo> list = deviceServiceImpl.getDevicessExcel(deviceQueryBo);
// String ALERT_MAP_KEY = "device:config:sends:" + TenantHelper.getTenantId();
String ALERT_MAP_KEY = "device:config:sends";
RMap<String, Integer> alertMap = RedisUtils.getClient().getMap(ALERT_MAP_KEY);
alertMap.expire(5, TimeUnit.MINUTES);
list.forEach(device -> {
executor.submit(() -> {
DeviceConfigAddBo deviceConfigAddBo = new DeviceConfigAddBo();
deviceConfigAddBo.setConfig(deviceQueryBo.getData().getConfig());
deviceConfigAddBo.setDeviceId(device.getDeviceId());
DeviceConfig data = deviceConfigAddBo.to(DeviceConfig.class);
deviceServiceImpl.saveConfig(data);
// 记录状态2已下发0成功1失败
setCacheMapValue(ALERT_MAP_KEY, device.getDeviceName(), 2);
// alertMap.put(device.getDeviceName(), 0);
// expire(ALERT_MAP_KEY, 172800);
// RMap<String, Long> alertMap = RedisUtils.getClient().getMap(ALERT_MAP_KEY);
deviceCtrlService.sendConfig(device,data);
});
});
return list.size();
}
@ApiOperation(value = "设备配置批量下发数据获取")
@PostMapping("/config/sendsReult")
public RMap<String, Integer> getConfigSendsReult() {
String ALERT_MAP_KEY = "device:config:sends";
RMap<String, Integer> alertMap = RedisUtils.getClient().getMap(ALERT_MAP_KEY);
String counterKey = "device:alert:modify_count";
RAtomicLong counter = RedisUtils.getClient().getAtomicLong(counterKey);
long currentCount = counter.get();
if (currentCount >= alertMap.size()) {
alertMap.clear();
counter.delete();
}
return alertMap;
}
@ApiOperation(value = "配置获取", notes = "属性获取", httpMethod = "POST") @ApiOperation(value = "配置获取", notes = "属性获取", httpMethod = "POST")
//@SaCheckPermission("iot:device:ctrl") //@SaCheckPermission("iot:device:ctrl")
@PostMapping("/service/config/get") @PostMapping("/service/config/get")
@ -431,4 +506,6 @@ public class DeviceController {
} }
return new InvokeResult(deviceCtrlService.getConfig(deviceId)); return new InvokeResult(deviceCtrlService.getConfig(deviceId));
} }
} }

@ -0,0 +1,185 @@
/*
*
* * | 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.enums.ErrCode;
import cc.iotkit.common.excel.utils.ExcelUtil;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.log.annotation.Log;
import cc.iotkit.common.log.enums.BusinessType;
import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.tenant.helper.TenantHelper;
import cc.iotkit.common.utils.DeviceUtil;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.manager.IDeviceInstallInfoData;
import cc.iotkit.data.manager.IDeviceIssueData;
import cc.iotkit.manager.config.PDFGenerator;
import cc.iotkit.manager.dto.bo.device.DeviceInstallInfoQueryBo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInstallInfoExpordVo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInstallInfoVo;
import cc.iotkit.manager.service.IDeviceInstallInfoService;
import cc.iotkit.manager.service.IDeviceIssueService;
import cc.iotkit.model.device.DeviceInstallInfo;
import cc.iotkit.model.device.DeviceIssue;
import cc.iotkit.model.device.InstallationRecord;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.AreaBreak;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.properties.AreaBreakType;
import com.itextpdf.layout.properties.TextAlignment;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.util.List;
@Api(tags = {"设备下发权限信息"})
@Slf4j
@RestController
@RequestMapping("/deviceIssue")
public class DeviceIssueController {
@Autowired
private IDeviceIssueService deviceServiceImpl;
@Autowired
private IDeviceIssueData iDeviceInstallInfoData;
@ApiOperation(value = "下发权限列表", notes = "设备列表", httpMethod = "POST")
//@SaCheckPermission("iot:device:query")
@PostMapping("/page")
public Paging<DeviceIssue> getDevices(@Validated @RequestBody PageRequest<DeviceIssue> pageRequest) {
return deviceServiceImpl.getPage(pageRequest);
}
@PostMapping("/add")
@SaCheckPermission("device:issue:add")
public void addClientUser(@RequestBody Request<DeviceIssue> deviceInstallInfo) throws Exception {
/* user.getData().setType(UserInfo.USER_TYPE_CLIENT);
user.getData().setRoles(Collections.singletonList(Constants.ROLE_CLIENT));
user.getData().setSecret(null);*/
TenantHelper.enableIgnore();
if (ObjectUtil.isNull(deviceInstallInfo.getData()) || ObjectUtil.isNull(deviceInstallInfo.getData().getFieldName())) {
throw new BizException(ErrCode.PARAMS_EXCEPTION);
}
/* DeviceInstallInfo deviceRepetition = iDeviceInstallInfoData.findByDeviceNameAndUid(deviceInstallInfo.getData().getDeviceName(), deviceInstallInfo.getData().getUid());
if (deviceRepetition != null) {
throw new BizException(ErrCode.MODEL_DEVICE_ALREADY);
}*/
if (LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() != 0) {
deviceInstallInfo.getData().setTenantId(TenantHelper.getTenantId());
// query.where(tbDeviceInstallInfo.tenantId.eq(TenantHelper.getTenantId()));
}
deviceInstallInfo.getData().setId(DeviceUtil.newDeviceId("0"));
/* if(!LoginHelper.isSuperAdmin() && ObjectUtil.isNotNull(pageReqVO.getData().getTenantId())){
query.where(tbDeviceInstallInfo.tenantId.eq(pageReqVO.getData().getTenantId()));
}*/
DeviceIssue deviceIssue = iDeviceInstallInfoData.findByTenantId(deviceInstallInfo.getData().getTenantId());
if(ObjectUtil.isNotEmpty(deviceIssue)){
throw new BizException("租户权限已存在");
}
iDeviceInstallInfoData.save(deviceInstallInfo.getData());
/* if(LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() != 0) {
userInfoData.save(user.getData());
}else{
user.getData().setTenantId(null);
userInfoData.save(user.getData());
}*/
}
@PostMapping("/edit")
@SaCheckPermission("device:issue:edit")
public void editClientUser(@RequestBody Request<DeviceIssue> deviceInstallInfo) throws Exception {
TenantHelper.enableIgnore();
if (ObjectUtil.isNull(deviceInstallInfo.getData()) || ObjectUtil.isNull(deviceInstallInfo.getData().getFieldName()) || ObjectUtil.isNull(deviceInstallInfo.getData().getId())) {
throw new BizException(ErrCode.PARAMS_EXCEPTION);
}
if (LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() != 0) {
deviceInstallInfo.getData().setTenantId(TenantHelper.getTenantId());
// query.where(tbDeviceInstallInfo.tenantId.eq(TenantHelper.getTenantId()));
}
DeviceIssue deviceIssue = iDeviceInstallInfoData.findById(deviceInstallInfo.getData().getId());
// DeviceIssue deviceIssue = iDeviceInstallInfoData.findByTenantId(deviceInstallInfo.getData().getTenantId());
if(ObjectUtil.isNotEmpty(deviceIssue) && !deviceIssue.getTenantId().equals(deviceInstallInfo.getData().getTenantId())){
DeviceIssue deviceIssue1 = iDeviceInstallInfoData.findByTenantId(deviceInstallInfo.getData().getTenantId());
if(ObjectUtil.isNotEmpty(deviceIssue1)) {
throw new BizException("租户权限已存在");
}
}
iDeviceInstallInfoData.save(deviceInstallInfo.getData());
}
@PostMapping("/device/{id}/delete")
@SaCheckPermission("device:issue:delete")
public void deleteClientUser(@PathVariable("id") String id) {
DeviceIssue user = iDeviceInstallInfoData.findById(id);
if (user == null) {
throw new BizException(ErrCode.RECORD_NOT_FOUND);
}
iDeviceInstallInfoData.deleteById(id);
}
/* @PostMapping("/getDeviceInstallInfo")
public DeviceInstallInfo getUserInfo() {
return iDeviceInstallInfoData.findById(LoginHelper.getUserId());
}*/
@PostMapping("/getDetail")
@SaCheckPermission("device:issue:query")
public DeviceIssue getDetail(@Validated @RequestBody Request<String> request) {
return iDeviceInstallInfoData.findById(request.getData());
}
@PostMapping("/getDetailTenandId")
// @SaCheckPermission("device:issue:query")
public DeviceIssue getDetailTenandId() {
return iDeviceInstallInfoData.findByTenantId(TenantHelper.getTenantId());
}
}

@ -76,7 +76,7 @@ public class ProductController {
private IProductService productService; private IProductService productService;
@ApiOperation("列表") @ApiOperation("列表")
@SaCheckPermission("iot:product:query") // @SaCheckPermission("iot:product:query")
@PostMapping("/list") @PostMapping("/list")
public Paging<ProductVo> getProducts(@Validated(QueryGroup.class) @RequestBody public Paging<ProductVo> getProducts(@Validated(QueryGroup.class) @RequestBody
PageRequest<ProductBo> request) { PageRequest<ProductBo> request) {

@ -28,6 +28,7 @@ import cc.iotkit.common.api.Request;
import cc.iotkit.common.satoken.utils.AuthUtil; import cc.iotkit.common.satoken.utils.AuthUtil;
import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.utils.StreamUtils; import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.common.validate.QueryGroup;
import cc.iotkit.data.config.TenantContext; import cc.iotkit.data.config.TenantContext;
import cc.iotkit.data.manager.IAlertRecordData; import cc.iotkit.data.manager.IAlertRecordData;
import cc.iotkit.data.manager.ICategoryData; import cc.iotkit.data.manager.ICategoryData;
@ -37,10 +38,13 @@ import cc.iotkit.data.system.ISysDeptData;
import cc.iotkit.data.system.ISysUserData; import cc.iotkit.data.system.ISysUserData;
import cc.iotkit.manager.dto.bo.device.DeviceQueryBo; import cc.iotkit.manager.dto.bo.device.DeviceQueryBo;
import cc.iotkit.manager.dto.bo.product.ProductBo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo;
import cc.iotkit.manager.dto.vo.product.ProductVo;
import cc.iotkit.manager.model.stats.MainStats; import cc.iotkit.manager.model.stats.MainStats;
import cc.iotkit.manager.service.AlertService; import cc.iotkit.manager.service.AlertService;
import cc.iotkit.manager.service.IDeviceManagerService; import cc.iotkit.manager.service.IDeviceManagerService;
import cc.iotkit.manager.service.IProductService;
import cc.iotkit.model.alert.AlertRecord; import cc.iotkit.model.alert.AlertRecord;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.stats.AlertStatDTO; import cc.iotkit.model.stats.AlertStatDTO;
@ -95,6 +99,8 @@ public class StatsController {
private AlertService alertService; private AlertService alertService;
@Autowired @Autowired
private IDeviceManagerService deviceServiceImpl; private IDeviceManagerService deviceServiceImpl;
@Autowired
private IProductService productService;
@Autowired @Autowired
private ISysDeptData isysDeptData; private ISysDeptData isysDeptData;
@ -121,14 +127,14 @@ public class StatsController {
DeviceInfo.State state = new DeviceInfo.State(); DeviceInfo.State state = new DeviceInfo.State();
state.setOnline(true); state.setOnline(true);
condition.setState(state); condition.setState(state);
mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size()); mainStats.setOnlineTotal(deviceInfoData.findNeverUsedDevices(condition,true));
state.setOnline(false); state.setOnline(false);
condition.setState(state); condition.setState(state);
mainStats.setOfflineTotal(deviceInfoData.findAllByCondition(condition).size()); mainStats.setOfflineTotal(deviceInfoData.findNeverUsedDevices(condition,true));
// 待激活设备 // 待激活设备
mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices().size()); mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices(condition,false));
mainStats.setReportTotal(thingModelMessageData.count()); mainStats.setReportTotal(thingModelMessageData.count());
//上行数据统计 //上行数据统计
@ -147,6 +153,18 @@ public class StatsController {
DeviceInfo condition = new DeviceInfo(); DeviceInfo condition = new DeviceInfo();
DeviceInfo.State state = new DeviceInfo.State(); DeviceInfo.State state = new DeviceInfo.State();
state.setOnline(true);
condition.setState(state);
mainStats.setOnlineTotal(deviceInfoData.findNeverUsedDevices(condition,true));
state.setOnline(false);
condition.setState(state);
mainStats.setOfflineTotal(deviceInfoData.findNeverUsedDevices(condition,true));
// 待激活设备
mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices(condition,false));
/* DeviceInfo.State state = new DeviceInfo.State();
state.setOnline(true); state.setOnline(true);
condition.setState(state); condition.setState(state);
mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size()); mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size());
@ -156,7 +174,7 @@ public class StatsController {
mainStats.setOfflineTotal(deviceInfoData.findAllByCondition(condition).size()); mainStats.setOfflineTotal(deviceInfoData.findAllByCondition(condition).size());
// 待激活设备 // 待激活设备
mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices().size()); mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices().size());*/
// mainStats.setReportTotal(deviceReportRepository.countByUid(uid)); // mainStats.setReportTotal(deviceReportRepository.countByUid(uid));
//上报数据统计 //上报数据统计
@ -206,14 +224,15 @@ public class StatsController {
DeviceInfo.State state = new DeviceInfo.State(); DeviceInfo.State state = new DeviceInfo.State();
state.setOnline(true); state.setOnline(true);
condition.setState(state); condition.setState(state);
mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size()); mainStats.setOnlineTotal(deviceInfoData.findNeverUsedDevices(condition,true));
state.setOnline(false); state.setOnline(false);
condition.setState(state); condition.setState(state);
mainStats.setOfflineTotal(deviceInfoData.findAllByCondition(condition).size()); mainStats.setOfflineTotal(deviceInfoData.findNeverUsedDevices(condition,true));
// 待激活设备 // 待激活设备
mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices().size()); mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices(condition,false));
mainStats.setReportTotal(thingModelMessageData.count()); mainStats.setReportTotal(thingModelMessageData.count());
//上行数据统计 //上行数据统计
@ -365,4 +384,22 @@ public class StatsController {
//long countByUid(String uid); //long countByUid(String uid);
} }
//-----------------------大屏開放接口
@ApiOperation("查询告警消息分页")
@PostMapping("/selectAlertRecordPage")
public Paging<AlertRecord> selectAlertRecordPage(@RequestBody @Validated PageRequest<AlertRecord> request) {
request.getData().setStatusFlg(true);
return alertService.selectAlertRecordPage(request);
}
@ApiOperation("产品列表")
@PostMapping("/selectListProduct")
public Paging<ProductVo> getProducts(@Validated(QueryGroup.class) @RequestBody
PageRequest<ProductBo> request) {
TenantContext.disableTenantFilter();
request.getData().setTenantId(null);
return productService.selectPageList(request);
}
} }

@ -23,6 +23,7 @@
package cc.iotkit.manager.dto.bo.device; package cc.iotkit.manager.dto.bo.device;
import cc.iotkit.common.api.BaseDto; import cc.iotkit.common.api.BaseDto;
import cc.iotkit.manager.dto.bo.deviceconfig.DeviceConfigAddBo;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.system.SysApp; import cc.iotkit.model.system.SysApp;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
@ -87,4 +88,7 @@ public class DeviceQueryBo extends BaseDto {
private String startTime; private String startTime;
@ApiModelProperty(value = "设备名称") @ApiModelProperty(value = "设备名称")
private String endTime; private String endTime;
private String config;
} }

@ -0,0 +1,109 @@
/*
*
* * | 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.dto.vo.deviceinfo;
import cc.iotkit.model.Owned;
import cc.iotkit.model.TenantModel;
import cc.iotkit.model.alert.AlertRecord;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Map;
/**
*
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = AlertRecord.class,convertGenerate = false)
public class AlertRecordExpordVo implements Serializable {
private static final long serialVersionUID = -1L;
// private Long id;
// private Map params;
/**
*
*/
// private String uid;
/**
*
*/
@ExcelProperty(value = "告警名称")
private String name;
/**
* 1-5
*/
@ExcelProperty(value = "告警严重度")
private String level;
/**
*
*/
/* @JsonFormat(timezone = "Asia/Shanghai",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")*/
@ExcelProperty(value = "告警时间")
private Long alertTime;
// private String alertTimeStats;
/**
*
*/
@ExcelProperty(value = "告警详情")
private String details;
@ExcelProperty(value = "创建租户")
private Long tenantId;
@ExcelProperty(value = "创建区域")
private Long deptAreaId;
/**
*
*/
@ExcelProperty(value = "是否已读")
private Boolean readFlg;
// private Boolean statusFlg = false;
@ExcelProperty(value = "清除原因0测试、1点检、2已确认")
private Integer reasonForRemoval;
@ExcelProperty(value = "清除1已清除0未清除")
private Integer reasonForRemovalFlag;
@ExcelProperty(value = "安装地址")
private String site;
@ExcelProperty(value = "设备编号")
private String deviceName;
@ExcelProperty(value = "所属产品")
private String productKey;
@ExcelProperty(value = "事件类型")
private String levelStatus;
/* @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
public Date getAlertTime() {
return new Date(this.alertTime);
}*/
}

@ -134,4 +134,6 @@ public class DeviceInfoVo implements Serializable {
private String nodeFiveDevice; private String nodeFiveDevice;
private String longitude; private String longitude;
private String latitude; private String latitude;
private String category;
} }

@ -67,6 +67,9 @@ public class AlertService {
public Paging<AlertRecord> selectAlertRecordPage(PageRequest<AlertRecord> request) { public Paging<AlertRecord> selectAlertRecordPage(PageRequest<AlertRecord> request) {
return alertRecordData.selectAlertConfigPage(request); return alertRecordData.selectAlertConfigPage(request);
} }
public Paging<AlertRecord> selectAlertRecordPageExcel(PageRequest<AlertRecord> request) {
return alertRecordData.selectAlertRecordPageExcel(request);
}
public void save(AlertRecord request) { public void save(AlertRecord request) {
alertRecordData.save(request); alertRecordData.save(request);
} }

@ -30,6 +30,7 @@ import cc.iotkit.common.utils.JsonUtils;
import cc.iotkit.common.utils.UniqueIdUtil; import cc.iotkit.common.utils.UniqueIdUtil;
import cc.iotkit.data.manager.IDeviceConfigData; import cc.iotkit.data.manager.IDeviceConfigData;
import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo;
import cc.iotkit.model.device.DeviceConfig; import cc.iotkit.model.device.DeviceConfig;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.temporal.IThingModelMessageData; import cc.iotkit.temporal.IThingModelMessageData;
@ -142,6 +143,16 @@ public class DeviceCtrlService {
return send(deviceId, device.getProductKey(), device.getDeviceName(), data, return send(deviceId, device.getProductKey(), device.getDeviceName(), data,
ThingModelMessage.TYPE_CONFIG, ThingModelMessage.ID_CONFIG_SET); ThingModelMessage.TYPE_CONFIG, ThingModelMessage.ID_CONFIG_SET);
} }
public String sendConfig1(DeviceInfoVo device, DeviceConfig config) {
//DeviceInfo device = getAndCheckDevice(deviceId, checkOwner);
/* DeviceConfig config = deviceConfigData.findByDeviceId(deviceId);
if (config == null || ObjectUtil.isEmpty(config)) {
fail("设备未配置");
}*/
Map data = JsonUtils.parseObject(config.getConfig(), Map.class);
return send(device.getDeviceId(), device.getProductKey(), device.getDeviceName(), data,
ThingModelMessage.TYPE_CONFIG, ThingModelMessage.ID_CONFIG_SET);
}
/** /**
* - * -
*/ */
@ -163,7 +174,9 @@ public class DeviceCtrlService {
public String sendConfig(String deviceId) { public String sendConfig(String deviceId) {
return sendConfig(deviceId, true); return sendConfig(deviceId, true);
} }
public String sendConfig(DeviceInfoVo deviceInfoVo,DeviceConfig deviceConfig) {
return sendConfig1(deviceInfoVo, deviceConfig);
}
/** /**
* *
*/ */

@ -65,7 +65,7 @@ public class DeviceStateCheckTask {
Paging<DeviceInfo> all; Paging<DeviceInfo> all;
while (true) { while (true) {
//取出数据库中所有在线设备 //取出数据库中所有在线设备
all = deviceInfoData.findByConditions("","","","","",true,"",pn,1000,null,null,null); all = deviceInfoData.findByConditions("","","","","",true,"",pn,1000,null,null,null,null);
//判断属性更新时间是否大于产品定义保活时长 //判断属性更新时间是否大于产品定义保活时长
for (DeviceInfo device : all.getRows()) { for (DeviceInfo device : all.getRows()) {
if(ObjectUtil.isNull(device)){ if(ObjectUtil.isNull(device)){

@ -0,0 +1,44 @@
/*
*
* * | 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.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.manager.dto.bo.device.DeviceInstallInfoQueryBo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInstallInfoVo;
import cc.iotkit.model.device.DeviceInstallInfo;
import cc.iotkit.model.device.DeviceIssue;
import java.util.List;
/**
* @Author: jay
* @Date: 2023/5/31 11:05
* @Version: V1.0
* @Description:
*/
public interface IDeviceIssueService {
Paging<DeviceIssue> getPage(PageRequest<DeviceIssue> pageRequest);
//List<DeviceInstallInfoVo> getList(PageRequest<DeviceInstallInfoQueryBo> pageRequest);
}

@ -0,0 +1,102 @@
package cc.iotkit.manager.service.impl;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.tenant.helper.TenantHelper;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.DeviceInstallInfoRepository;
import cc.iotkit.data.dao.DeviceIssueRepository;
import cc.iotkit.data.manager.IDeviceInstallInfoData;
import cc.iotkit.data.manager.IDeviceIssueData;
import cc.iotkit.data.manager.IUserInfoData;
import cc.iotkit.data.model.TbDeviceInstallInfo;
import cc.iotkit.data.model.TbDeviceIssue;
import cc.iotkit.data.system.ISysTenantData;
import cc.iotkit.manager.dto.bo.device.DeviceInstallInfoQueryBo;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInstallInfoVo;
import cc.iotkit.manager.service.IDeviceInstallInfoService;
import cc.iotkit.manager.service.IDeviceIssueService;
import cc.iotkit.model.UserInfo;
import cc.iotkit.model.device.DeviceInstallInfo;
import cc.iotkit.model.device.DeviceIssue;
import cc.iotkit.model.system.SysTenant;
import cn.hutool.core.util.ObjectUtil;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static cc.iotkit.data.model.QTbDeviceIssue.tbDeviceIssue;
/**
* Service
*
* @author
*/
@Slf4j
@Service
@Primary
@RequiredArgsConstructor
public class DeviceIssueServiceImpl implements IDeviceIssueService {
@Autowired
private final ISysTenantData isSysTenantData;
@Autowired
private IDeviceIssueData iDeviceInstallInfoData;
//@Autowired
// private IUserInfoData iUserInfoData;
@Autowired
private DeviceIssueRepository deviceInstallInfoRepository;
private final JPAQueryFactory jpaQueryFactory;
@Override
public Paging<DeviceIssue> getPage(PageRequest<DeviceIssue> pageReqVO) {
JPAQuery<TbDeviceIssue> query = jpaQueryFactory.selectFrom(tbDeviceIssue);
if(LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() != 0){
query.where(tbDeviceIssue.tenantId.eq(TenantHelper.getTenantId()));
}
if(!LoginHelper.isSuperAdmin() && ObjectUtil.isNotNull(pageReqVO.getData().getTenantId())){
query.where(tbDeviceIssue.tenantId.eq(pageReqVO.getData().getTenantId()));
}
query.orderBy(tbDeviceIssue.createTime.desc());
Integer page = ObjectUtil.isNotNull(pageReqVO.getPageNum()) ?pageReqVO.getPageNum():1;
Integer size = ObjectUtil.isNotNull(pageReqVO.getPageSize()) ?pageReqVO.getPageSize():10;
query.offset((page - 1) * size).limit(size);
List<TbDeviceIssue> tbDeviceInfos = query.fetch();
List<DeviceIssue> deviceInfos = new ArrayList<>(tbDeviceInfos.size());
long total = query.fetchCount();
for (TbDeviceIssue tbDeviceInfo : tbDeviceInfos) {
DeviceIssue deviceInfo = MapstructUtils.convert(tbDeviceInfo, DeviceIssue.class);
if (ObjectUtil.isNotNull(tbDeviceInfo.getTenantId())) {
SysTenant sysTenant = new SysTenant();
sysTenant.setTenantId(tbDeviceInfo.getTenantId());
SysTenant sysTenant1 = isSysTenantData.findOneByCondition(sysTenant);
if (sysTenant1 != null) {
deviceInfo.setTenantName(sysTenant1.getCompanyName());
}
}
deviceInfos.add(deviceInfo);
}
return new Paging<>(total, deviceInfos);
}
// 构建动态查询条件(含排序)
}

@ -43,6 +43,7 @@ import cc.iotkit.data.system.ISysDeptData;
import cc.iotkit.manager.dto.bo.device.*; import cc.iotkit.manager.dto.bo.device.*;
import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo; import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo;
import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo; import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo;
import cc.iotkit.manager.dto.vo.category.CategoryVo;
import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo;
import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupImportVo; import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupImportVo;
import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo;
@ -61,6 +62,7 @@ import cc.iotkit.model.device.DeviceGroup;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.device.DeviceInstallInfo; import cc.iotkit.model.device.DeviceInstallInfo;
import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.model.device.message.DeviceProperty;
import cc.iotkit.model.product.Category;
import cc.iotkit.model.product.Product; import cc.iotkit.model.product.Product;
import cc.iotkit.model.system.SysApp; import cc.iotkit.model.system.SysApp;
import cc.iotkit.model.system.SysDept; import cc.iotkit.model.system.SysDept;
@ -71,6 +73,7 @@ import cc.iotkit.temporal.IThingModelMessageData;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQuery;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import me.chanjar.weixin.common.bean.subscribemsg.CategoryData;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -132,6 +135,9 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
private IUserInfoData iUserInfoData; private IUserInfoData iUserInfoData;
@Autowired @Autowired
private IDeviceInfoData iDeviceInfoData; private IDeviceInfoData iDeviceInfoData;
@Autowired
@Qualifier("categoryDataCache")
private ICategoryData categoryData;
@Override @Override
public Paging<DeviceInfoVo> getDevices(PageRequest<DeviceQueryBo> pageRequest) { public Paging<DeviceInfoVo> getDevices(PageRequest<DeviceQueryBo> pageRequest) {
@ -140,6 +146,7 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
String uid = query.getUid(); String uid = query.getUid();
String subUid = ""; String subUid = "";
String name = query.getName(); String name = query.getName();
String deviceName = query.getDeviceName();
String pk = query.getProductKey(); String pk = query.getProductKey();
//关键字查询 //关键字查询
String keyword = query.getKeyword(); String keyword = query.getKeyword();
@ -147,12 +154,28 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
Boolean online = query.getOnline(); Boolean online = query.getOnline();
Long areaDepeId = query.getDeptAreaId(); Long areaDepeId = query.getDeptAreaId();
Paging<DeviceInfoVo> result = MapstructUtils.convert(deviceInfoData.findByConditions(name, uid, subUid, pk, group, Paging<DeviceInfoVo> result = MapstructUtils.convert(deviceInfoData.findByConditions(name, uid, subUid, pk, group,
online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId,query.getStartTime(), query.getEndTime()), DeviceInfoVo.class); online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId, query.getStartTime(), query.getEndTime(), deviceName), DeviceInfoVo.class);
List<Category> categorys = categoryData.findAll();
for (DeviceInfoVo row : result.getRows()) { for (DeviceInfoVo row : result.getRows()) {
row.setProduct(productData.findByProductKey(row.getProductKey())); if (ObjectUtil.isNotEmpty(row.getProductKey())) {
Product product = productData.findByProductKey(row.getProductKey());
if (ObjectUtil.isNotEmpty(product)) {
row.setProduct(product);
for (Category category : categorys) {
if (ObjectUtil.isNotEmpty(product.getCategory()) && ObjectUtil.isNotEmpty(category.getId())) {
if (category.getId().equals(product.getCategory())) {
row.setCategory(category.getName());
break;
}
}
}
}
}
} }
return result; return result;
} }
@Override @Override
public Paging<DeviceInfoVo> getDevices1(PageRequest<DeviceQueryBo> pageRequest) { public Paging<DeviceInfoVo> getDevices1(PageRequest<DeviceQueryBo> pageRequest) {
DeviceQueryBo query = pageRequest.getData(); DeviceQueryBo query = pageRequest.getData();
@ -160,6 +183,7 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
String uid = query.getUid(); String uid = query.getUid();
String subUid = ""; String subUid = "";
String name = query.getName(); String name = query.getName();
String deviceName = query.getDeviceName();
String pk = query.getProductKey(); String pk = query.getProductKey();
//关键字查询 //关键字查询
String keyword = query.getKeyword(); String keyword = query.getKeyword();
@ -167,7 +191,7 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
Boolean online = query.getOnline(); Boolean online = query.getOnline();
Long areaDepeId = query.getDeptAreaId(); Long areaDepeId = query.getDeptAreaId();
Paging<DeviceInfoVo> result = MapstructUtils.convert(deviceInfoData.findByConditions1(name, uid, subUid, pk, group, Paging<DeviceInfoVo> result = MapstructUtils.convert(deviceInfoData.findByConditions1(name, uid, subUid, pk, group,
online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId,query.getStartTime(), query.getEndTime()), DeviceInfoVo.class); online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId, query.getStartTime(), query.getEndTime(), deviceName), DeviceInfoVo.class);
for (DeviceInfoVo row : result.getRows()) { for (DeviceInfoVo row : result.getRows()) {
row.setProduct(productData.findByProductKey(row.getProductKey())); row.setProduct(productData.findByProductKey(row.getProductKey()));
} }
@ -203,12 +227,13 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
Long areaDepeId = query.getDeptAreaId(); Long areaDepeId = query.getDeptAreaId();
//pageRequest.setPageSize(99999); //pageRequest.setPageSize(99999);
Paging<DeviceInfoVo> result = MapstructUtils.convert(deviceInfoData.findByConditionsExcel(name, uid, subUid, pk, group, Paging<DeviceInfoVo> result = MapstructUtils.convert(deviceInfoData.findByConditionsExcel(name, uid, subUid, pk, group,
online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId,query.getStartTime(), query.getEndTime()), DeviceInfoVo.class); online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId, query.getStartTime(), query.getEndTime()), DeviceInfoVo.class);
/* for (DeviceInfoVo row : result.getRows()) { /* for (DeviceInfoVo row : result.getRows()) {
row.setProduct(productData.findByProductKey(row.getProductKey())); row.setProduct(productData.findByProductKey(row.getProductKey()));
}*/ }*/
return result.getRows(); return result.getRows();
} }
@Override @Override
public List<DeviceInfoVo> findByConditionsList(String productKey, boolean flag) { public List<DeviceInfoVo> findByConditionsList(String productKey, boolean flag) {
return MapstructUtils.convert(iDeviceInfoData.findByConditionsList(productKey, flag), DeviceInfoVo.class); return MapstructUtils.convert(iDeviceInfoData.findByConditionsList(productKey, flag), DeviceInfoVo.class);
@ -247,7 +272,7 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
/* if(ObjectUtil.isNotNull(sysDept) && ObjectUtil.isNull(deviceInfo.getTenantId())) { /* if(ObjectUtil.isNotNull(sysDept) && ObjectUtil.isNull(deviceInfo.getTenantId())) {
device.setTenantId(sysDept.getTenantId()); device.setTenantId(sysDept.getTenantId());
}*/ }*/
if (ObjectUtil.isNotNull(sysDept) && ObjectUtil.isNull(deviceInfo.getTenantId()) ) { if (ObjectUtil.isNotNull(sysDept) && ObjectUtil.isNull(deviceInfo.getTenantId())) {
device.setTenantId(sysDept.getTenantId()); device.setTenantId(sysDept.getTenantId());
} }
if (LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() == 0) { if (LoginHelper.isSuperAdmin() && TenantHelper.getTenantId() == 0) {
@ -365,12 +390,12 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
public boolean unbindDeviceXcx(String deviceId) { public boolean unbindDeviceXcx(String deviceId) {
TenantContext.disableTenantFilter(); TenantContext.disableTenantFilter();
DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId);
DeviceInstallInfo deviceInstallInfo = iDeviceInstallInfoData.findByDeviceNameAndUidAndState(deviceInfo.getDeviceName(), deviceInfo.getUid(),0); DeviceInstallInfo deviceInstallInfo = iDeviceInstallInfoData.findByDeviceNameAndUidAndState(deviceInfo.getDeviceName(), deviceInfo.getUid(), 0);
if(ObjectUtil.isNotEmpty(deviceInstallInfo)){ if (ObjectUtil.isNotEmpty(deviceInstallInfo)) {
//解绑 //解绑
deviceInstallInfo.setState(1); deviceInstallInfo.setState(1);
iDeviceInstallInfoData.save(deviceInstallInfo); iDeviceInstallInfoData.save(deviceInstallInfo);
} }
deviceInfo.setUid(""); deviceInfo.setUid("");
deviceInfo.setName(""); deviceInfo.setName("");
deviceInfoData.save(deviceInfo); deviceInfoData.save(deviceInfo);
@ -603,7 +628,7 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
if (deviceRepetition != null && !deviceRepetition.getDeviceId().equals(di.getDeviceId())) { if (deviceRepetition != null && !deviceRepetition.getDeviceId().equals(di.getDeviceId())) {
throw new BizException(ErrCode.MODEL_DEVICE_ALREADY); throw new BizException(ErrCode.MODEL_DEVICE_ALREADY);
} }
if(ObjectUtil.isNotEmpty(deviceRepetition) && ObjectUtil.isNotNull(deviceRepetition.getState())) { if (ObjectUtil.isNotEmpty(deviceRepetition) && ObjectUtil.isNotNull(deviceRepetition.getState())) {
di.setState(deviceRepetition.getState()); di.setState(deviceRepetition.getState());
} }
/* if(ObjectUtil.isNotNull(data.getGroup())){ /* if(ObjectUtil.isNotNull(data.getGroup())){
@ -613,25 +638,26 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
TenantHelper.enableIgnore(); TenantHelper.enableIgnore();
return deviceInfoData.save(di) != null; return deviceInfoData.save(di) != null;
} }
public static Map<String, DeviceInfo.Group> convert(Object obj) { public static Map<String, DeviceInfo.Group> convert(Object obj) {
return obj instanceof Map ? ((Map<?,?>) obj).entrySet().stream() return obj instanceof Map ? ((Map<?, ?>) obj).entrySet().stream()
.filter(e -> e.getKey() instanceof String) .filter(e -> e.getKey() instanceof String)
.filter(e -> e.getValue() instanceof DeviceInfo.Group) .filter(e -> e.getValue() instanceof DeviceInfo.Group)
.collect(Collectors.toMap( .collect(Collectors.toMap(
e -> (String)e.getKey(), e -> (String) e.getKey(),
e -> (DeviceInfo.Group)e.getValue() e -> (DeviceInfo.Group) e.getValue()
)) : Collections.emptyMap(); )) : Collections.emptyMap();
} }
public boolean process(DeviceInfoBo dto) { public boolean process(DeviceInfoBo dto) {
Object input = dto.getGroup(); Object input = dto.getGroup();
if(input == null){ if (input == null) {
return false; return false;
} }
if (input instanceof Map) { if (input instanceof Map) {
// 处理Map逻辑 // 处理Map逻辑
return true; return true;
}else if(isMapFormat(input.toString())){ } else if (isMapFormat(input.toString())) {
// 处理Map逻辑 // 处理Map逻辑
return true; return true;
} else { } else {
@ -639,6 +665,7 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
return false; return false;
} }
} }
public boolean isMapFormat(String input) { public boolean isMapFormat(String input) {
return input.matches("^\\{(\\w+:\\w+,?)*\\}$"); return input.matches("^\\{(\\w+:\\w+,?)*\\}$");
} }
@ -647,25 +674,26 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
public boolean saveDevice1(DeviceInfoBo data) { public boolean saveDevice1(DeviceInfoBo data) {
DeviceInfo di = new DeviceInfo(); DeviceInfo di = new DeviceInfo();
if(ObjectUtil.isNull(data) || ObjectUtil.isNull(data.getId())){ if (ObjectUtil.isNull(data) || ObjectUtil.isNull(data.getId())) {
fail("修改失败"); fail("修改失败");
} }
DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(data.getId()); DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(data.getId());
if(ObjectUtil.isEmpty(deviceInfo)){ if (ObjectUtil.isEmpty(deviceInfo)) {
fail("设备不存在"); fail("设备不存在");
} }
deviceInfo.setSite(data.getSite()); deviceInfo.setSite(data.getSite());
// DeviceInfo.Locate locate = deviceInfo.getLocate(); // DeviceInfo.Locate locate = deviceInfo.getLocate();
/* deviceInfo.getLocate().setLatitude(deviceInfo.getLatitude()); /* deviceInfo.getLocate().setLatitude(deviceInfo.getLatitude());
deviceInfo.getLocate().setLongitude(deviceInfo.getLongitude());*/ deviceInfo.getLocate().setLongitude(deviceInfo.getLongitude());*/
deviceInfo.setDeptAreaId(data.getDeptAreaId()); deviceInfo.setDeptAreaId(data.getDeptAreaId());
// di.setId(data.getId()); // di.setId(data.getId());
TenantHelper.enableIgnore(); TenantHelper.enableIgnore();
return deviceInfoData.save(deviceInfo) != null; return deviceInfoData.save(deviceInfo) != null;
} }
@Override @Override
public boolean editDeviceInfo(DeviceInfoBo data) { public boolean editDeviceInfo(DeviceInfoBo data) {
String uid = AuthUtil.getUserId(); String uid = AuthUtil.getUserId();
@ -704,7 +732,7 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
fail(ErrCode.DEVICE_NOT_FOUND); fail(ErrCode.DEVICE_NOT_FOUND);
} }
deviceRepetition = deviceInfoData.findByDeviceId(deviceRepetition.getId()); deviceRepetition = deviceInfoData.findByDeviceId(deviceRepetition.getId());
if (ObjectUtil.isNull(deviceRepetition.getTenantId())) { if (ObjectUtil.isNull(deviceRepetition.getTenantId())) {
fail("租户未指定"); fail("租户未指定");
@ -746,9 +774,9 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
deviceRepetition.setSite(data.getDeviceInstallInfo().getCommunityName() deviceRepetition.setSite(data.getDeviceInstallInfo().getCommunityName()
+ data.getDeviceInstallInfo().getBuildingUnit() + data.getDeviceInstallInfo().getBuildingUnit()
+ data.getDeviceInstallInfo().getRoomNo()); + data.getDeviceInstallInfo().getRoomNo());
// deviceRepetition.getLocate().setLatitude(deviceRepetition.getLatitude()); // deviceRepetition.getLocate().setLatitude(deviceRepetition.getLatitude());
// deviceRepetition.getLocate().setLongitude(deviceRepetition.getLongitude()); // deviceRepetition.getLocate().setLongitude(deviceRepetition.getLongitude());
DeviceInstallInfo deviceRepetition1 = iDeviceInstallInfoData.findByDeviceNameAndUidAndState(deviceRepetition.getDeviceName(), uid,0); DeviceInstallInfo deviceRepetition1 = iDeviceInstallInfoData.findByDeviceNameAndUidAndState(deviceRepetition.getDeviceName(), uid, 0);
if (deviceRepetition1 != null) { if (deviceRepetition1 != null) {
throw new BizException("安装信息已存在"); throw new BizException("安装信息已存在");
} }

@ -56,6 +56,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RMap; import org.redisson.api.RMap;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -73,6 +74,7 @@ import java.util.stream.Collectors;
import static cc.iotkit.common.redis.utils.RedisUtils.*; import static cc.iotkit.common.redis.utils.RedisUtils.*;
import static com.ibm.icu.impl.Assert.fail; import static com.ibm.icu.impl.Assert.fail;
import static io.vertx.ext.web.client.spi.CookieStore.build;
/** /**
* @author sjg * @author sjg
@ -109,8 +111,12 @@ public class ThingServiceImpl implements IThingService {
private RuleExecutor ruleExecutor; private RuleExecutor ruleExecutor;
@Autowired @Autowired
private RuleMessageHandler ruleMessageHandler; private RuleMessageHandler ruleMessageHandler;
/* @Override
public ActionResult post(String pluginId, IDeviceAction action) {
@Override return ActionResult.builder().code(1).reason("").build();
}*/
@Override
public ActionResult post(String pluginId, IDeviceAction action) { public ActionResult post(String pluginId, IDeviceAction action) {
try { try {
@ -124,26 +130,26 @@ public class ThingServiceImpl implements IThingService {
} }
long lastTime = System.currentTimeMillis(); long lastTime = System.currentTimeMillis();
DeviceInfo device = getDeviceInfo(deviceName); DeviceInfo device = getDeviceInfo(deviceName);
if (ObjectUtil.isNotEmpty(action)) { /* if (ObjectUtil.isNotEmpty(action)) {
try { try {
DeviceStateChange deviceInfo = ((DeviceStateChange) action); DeviceStateChange deviceInfo = ((DeviceStateChange) action);
if (ObjectUtil.isNotEmpty(deviceInfo) && ObjectUtil.isNotNull(deviceInfo.getState())) { if (ObjectUtil.isNotEmpty(deviceInfo) && ObjectUtil.isNotNull(deviceInfo.getState())) {
// if (deviceInfo.getState().equals(DeviceState.ONLINE)) { // if (deviceInfo.getState().equals(DeviceState.ONLINE)) {
device.getState().setOnline(true); device.getState().setOnline(true);
device.getState().setOnlineTime(System.currentTimeMillis()); device.getState().setOnlineTime(System.currentTimeMillis());
/* } else { } else {
device.getState().setOnline(false); device.getState().setOnline(false);
device.getState().setOfflineTime(System.currentTimeMillis()); device.getState().setOfflineTime(System.currentTimeMillis());
}*/ }
} }
} catch (Exception e) { } catch (Exception e) {
} }
}*/
}
if (Objects.isNull(device)) { if (Objects.isNull(device)) {
log.warn("device:{} is not found.", deviceName); log.warn("device:{} is not found.", deviceName);
} else { } else {
device.getState().setOnline(true);
device.getState().setOnlineTime(System.currentTimeMillis());
deviceUpdateLastTime(device, lastTime); deviceUpdateLastTime(device, lastTime);
} }
@ -279,9 +285,32 @@ public class ThingServiceImpl implements IThingService {
if (!status.equals(1) && !status.equals(2)) { if (!status.equals(1) && !status.equals(2)) {
device.setDeviceStatus(0); device.setDeviceStatus(0);
} }
String eventTypeValue = "";
List<DeviceInfo> deviceInfoArrayList = new ArrayList<>(); List<DeviceInfo> deviceInfoArrayList = new ArrayList<>();
boolean success = false; boolean success = false;
//设备在线发生了故障或者报警 //设备在线发生了故障或者报警
try {
if (isMapValid(map, "resultCode")) {
String ALERT_MAP_KEY = "device:config:sends";
RMap<String, Integer> alertMap = RedisUtils.getClient().getMap(ALERT_MAP_KEY);
String counterKey = "device:alert:modify_count";
RAtomicLong counter = RedisUtils.getClient().getAtomicLong(counterKey);
if(!alertMap.isEmpty()) {
if (map.get("resultCode").equals("0")) {
alertMap.put(device.getDeviceName(), 0);
} else {
alertMap.put(device.getDeviceName(), 1);
}
counter.incrementAndGet();
/* if (currentCount >= alertMap.size()) {
alertMap.clear();
counter.delete();
}*/
}
}
}catch (Exception e){
}
if (isMapValid(map, "eventTypeValue")) { if (isMapValid(map, "eventTypeValue")) {
if (map.get("eventTypeValue").toString().contains("寿命到期")) { if (map.get("eventTypeValue").toString().contains("寿命到期")) {
@ -303,7 +332,7 @@ public class ThingServiceImpl implements IThingService {
} }
success = true; success = true;
device.setDeviceStatus(2); device.setDeviceStatus(2);
}
} else if (map.get("eventTypeValue").toString().contains("报警恢复")) { } else if (map.get("eventTypeValue").toString().contains("报警恢复")) {
device.setDeviceStatus(0); device.setDeviceStatus(0);
deviceLinkageControl1(device); deviceLinkageControl1(device);
@ -315,7 +344,8 @@ public class ThingServiceImpl implements IThingService {
device.setDeviceStatus(0); device.setDeviceStatus(0);
deviceLinkageControl1(device); deviceLinkageControl1(device);
} }
// } eventTypeValue = map.get("eventTypeValue").toString();
}
if (!state.isOnline()) { if (!state.isOnline()) {
if (!status.equals(1) && !status.equals(2)) { if (!status.equals(1) && !status.equals(2)) {
device.setDeviceStatus(3); device.setDeviceStatus(3);
@ -338,18 +368,14 @@ public class ThingServiceImpl implements IThingService {
.occurred(System.currentTimeMillis()) .occurred(System.currentTimeMillis())
.build(); .build();
List<AlertConfig> config = iAlertConfigData.findByDeviceName(device.getDeviceName()); List<AlertConfig> config = iAlertConfigData.findByDeviceName(device.getDeviceName());
/* if(config.isEmpty()){
List<Rule> rules = ruleMessageHandler.processMessage1(thingModelMessage);
for (Rule rule : rules) {
config = iAlertConfigData.findByRuleInfoId(rule.getId());
}
}*/
// List<AlertRecord> alerts = idAlertRecordData.selectAlertConfigPage(AlertRecordBo.builder().details(device.getDeviceName()).build()); // List<AlertRecord> alerts = idAlertRecordData.selectAlertConfigPage(AlertRecordBo.builder().details(device.getDeviceName()).build());
System.out.println("设备告警 您的设备【" + device.getDeviceName() + "】触发事件 事件类型为:【" + map.get("eventTypeValue").toString() + "】。"); System.out.println("设备告警 您的设备【" + device.getDeviceName() + "】触发事件 事件类型为:【" + map.get("eventTypeValue").toString() + "】。");
if (ObjectUtil.isEmpty(config)) { if (ObjectUtil.isEmpty(config)) {
try { try {
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
List<DeviceInfo> deviceInfoArrayList1 = deviceInfoArrayList; List<DeviceInfo> deviceInfoArrayList1 = deviceInfoArrayList;
String eventTypeValue1 =eventTypeValue;
executor.execute(() -> { executor.execute(() -> {
List<Rule> rules = ruleMessageHandler.processMessage1(thingModelMessage); List<Rule> rules = ruleMessageHandler.processMessage1(thingModelMessage);
for (Rule rule : rules) { for (Rule rule : rules) {
@ -359,6 +385,11 @@ public class ThingServiceImpl implements IThingService {
.level(config1.get(i).getLevel()) .level(config1.get(i).getLevel())
.name(config1.get(i).getName()) .name(config1.get(i).getName())
.tenantId(device.getTenantId()) .tenantId(device.getTenantId())
.productKey(device.getProductKey())
.levelStatus(eventTypeValue1)
.site(device.getSite())
.deviceName(device.getDeviceName())
.reasonForRemovalFlag(0)
.uid(device.getUid()) .uid(device.getUid())
.deptAreaId(device.getDeptAreaId()) .deptAreaId(device.getDeptAreaId())
.readFlg(false) .readFlg(false)
@ -371,6 +402,11 @@ public class ThingServiceImpl implements IThingService {
idAlertRecordData.save(AlertRecord.builder() idAlertRecordData.save(AlertRecord.builder()
.level(config1.get(i).getLevel()) .level(config1.get(i).getLevel())
.name(config1.get(i).getName()) .name(config1.get(i).getName())
.reasonForRemovalFlag(0)
.productKey(device.getProductKey())
.levelStatus(eventTypeValue1)
.deviceName(deviceInfoArrayList1.get(j).getDeviceName())
.site(deviceInfoArrayList1.get(j).getSite())
.tenantId(deviceInfoArrayList1.get(j).getTenantId()) .tenantId(deviceInfoArrayList1.get(j).getTenantId())
.uid(deviceInfoArrayList1.get(j).getUid()) .uid(deviceInfoArrayList1.get(j).getUid())
.deptAreaId(deviceInfoArrayList1.get(j).getDeptAreaId()) .deptAreaId(deviceInfoArrayList1.get(j).getDeptAreaId())
@ -391,11 +427,17 @@ public class ThingServiceImpl implements IThingService {
} else { } else {
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
List<DeviceInfo> deviceInfoArrayList1 = deviceInfoArrayList; List<DeviceInfo> deviceInfoArrayList1 = deviceInfoArrayList;
String eventTypeValue1 =eventTypeValue;
executor.execute(() -> { executor.execute(() -> {
for (int i = 0; i < config.size(); i++) { for (int i = 0; i < config.size(); i++) {
idAlertRecordData.save(AlertRecord.builder() idAlertRecordData.save(AlertRecord.builder()
.level(config.get(i).getLevel()) .level(config.get(i).getLevel())
.name(config.get(i).getName()) .name(config.get(i).getName())
.site(device.getSite())
.reasonForRemovalFlag(0)
.productKey(device.getProductKey())
.levelStatus(eventTypeValue1)
.deviceName(device.getDeviceName())
.tenantId(device.getTenantId()) .tenantId(device.getTenantId())
.uid(device.getUid()) .uid(device.getUid())
.deptAreaId(device.getDeptAreaId()) .deptAreaId(device.getDeptAreaId())
@ -409,6 +451,11 @@ public class ThingServiceImpl implements IThingService {
idAlertRecordData.save(AlertRecord.builder() idAlertRecordData.save(AlertRecord.builder()
.level(config.get(i).getLevel()) .level(config.get(i).getLevel())
.name(config.get(i).getName()) .name(config.get(i).getName())
.site(deviceInfoArrayList1.get(j).getSite())
.reasonForRemovalFlag(0)
.productKey(device.getProductKey())
.levelStatus(eventTypeValue1)
.deviceName(deviceInfoArrayList1.get(j).getDeviceName())
.tenantId(deviceInfoArrayList1.get(j).getTenantId()) .tenantId(deviceInfoArrayList1.get(j).getTenantId())
.uid(deviceInfoArrayList1.get(j).getUid()) .uid(deviceInfoArrayList1.get(j).getUid())
.deptAreaId(deviceInfoArrayList1.get(j).getDeptAreaId()) .deptAreaId(deviceInfoArrayList1.get(j).getDeptAreaId())
@ -609,7 +656,7 @@ public class ThingServiceImpl implements IThingService {
} }
private boolean deviceLinkageControlSend(DeviceInfo device, String node) { public boolean deviceLinkageControlSend(DeviceInfo device, String node) {
ThingService<Object> thingService = ThingService.builder() ThingService<Object> thingService = ThingService.builder()
.mid(UniqueIdUtil.newRequestId()) .mid(UniqueIdUtil.newRequestId())
.productKey(device.getProductKey()) .productKey(device.getProductKey())

@ -59,7 +59,7 @@ public class SysNoticeController extends BaseController {
/** /**
* *
*/ */
@SaCheckPermission("system:notice:list") // @SaCheckPermission("system:notice:list")
@ApiOperation(value = "获取通知公告列表", notes = "获取通知公告列表") @ApiOperation(value = "获取通知公告列表", notes = "获取通知公告列表")
@PostMapping("/list") @PostMapping("/list")
public Paging<SysNoticeVo> list(@Validated @RequestBody PageRequest<SysNoticeBo> query) { public Paging<SysNoticeVo> list(@Validated @RequestBody PageRequest<SysNoticeBo> query) {

@ -89,7 +89,7 @@ public class SysUserController extends BaseController {
@Qualifier("deviceInfoDataCache") @Qualifier("deviceInfoDataCache")
private IDeviceInfoData deviceInfoData; private IDeviceInfoData deviceInfoData;
@ApiOperation("获取用户列表") @ApiOperation("获取用户列表")
@SaCheckPermission("system:user:list") // @SaCheckPermission("system:user:list")
@PostMapping("/list") @PostMapping("/list")
public Paging<SysUserVo> list(@RequestBody @Validated(QueryGroup.class) PageRequest<SysUserBo> query) { public Paging<SysUserVo> list(@RequestBody @Validated(QueryGroup.class) PageRequest<SysUserBo> query) {
/* if(LoginHelper.isSuperAdmin()){ /* if(LoginHelper.isSuperAdmin()){

@ -94,10 +94,12 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
condition.getData().setParams(query.getData().getParams()); condition.getData().setParams(query.getData().getParams());
}// 手动补全Map字段 }// 手动补全Map字段
if(!LoginHelper.isSuperAdmin()) { if(!LoginHelper.isSuperAdmin()) {
SysUser sysUser = sysUserData.findById(LoginHelper.getUserId()); if(ObjectUtil.isNotEmpty(LoginHelper.getUserId())) {
condition.getData().setDeptId(sysUser.getDeptId()); SysUser sysUser = sysUserData.findById(LoginHelper.getUserId());
condition.getData().setDept(sysUser.getDept()); condition.getData().setDeptId(sysUser.getDeptId());
condition.getData().setAreaDept(sysUser.getAreaDept()); condition.getData().setDept(sysUser.getDept());
condition.getData().setAreaDept(sysUser.getAreaDept());
}
} }
return sysUserData.findAll(condition).to(SysUserVo.class); return sysUserData.findAll(condition).to(SysUserVo.class);

Loading…
Cancel
Save