upd: 仍有报错 没改完 先提交

This commit is contained in:
zwh
2025-09-30 17:58:34 +08:00
parent 3b7ebf9688
commit ea755d240d
708 changed files with 64652 additions and 2362 deletions
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+55
View File
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="iboot-shiro" />
<module name="iboot-iotview" />
<module name="iboot-oauth2" />
<module name="modbus-tcp" />
<module name="iboot-file" />
<module name="bootstrap" />
<module name="iboot-quartz" />
<module name="iboot-SaToken" />
<module name="framework" />
<module name="modbus-common" />
<module name="protocol-mqtt" />
<module name="iboot-knife4j" />
<module name="iboot-message" />
<module name="protocol-dtu" />
<module name="modbus-rtu" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="iboot-code" target="17" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="bootstrap" options="-parameters" />
<module name="framework" options="-parameters" />
<module name="iboot" options="" />
<module name="iboot-SaToken" options="-parameters" />
<module name="iboot-code" options="-parameters" />
<module name="iboot-file" options="-parameters" />
<module name="iboot-iotview" options="-parameters" />
<module name="iboot-knife4j" options="-parameters" />
<module name="iboot-message" options="-parameters" />
<module name="iboot-oauth2" options="-parameters" />
<module name="iboot-plugin" options="-parameters" />
<module name="iboot-protocol" options="-parameters" />
<module name="iboot-quartz" options="-parameters" />
<module name="iboot-shiro" options="-parameters" />
<module name="iboot-tos" options="" />
<module name="modbus-common" options="-parameters" />
<module name="modbus-rtu" options="-parameters" />
<module name="modbus-tcp" options="-parameters" />
<module name="protocol-dtu" options="-parameters" />
<module name="protocol-modbus" options="-parameters" />
<module name="protocol-mqtt" options="-parameters" />
</option>
</component>
</project>
+31
View File
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/bootstrap/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/framework/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-SaToken/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-code/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-file/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-iotview/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-knife4j/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-message/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-oauth2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/protocol-dtu/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/protocol-modbus/modbus-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/protocol-modbus/modbus-rtu/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/protocol-modbus/modbus-tcp/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/protocol-modbus/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/protocol-modbus/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/protocol-mqtt/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-protocol/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-quartz/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/iboot-shiro/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-plugin/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-tos/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/iboot-tos/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
+35
View File
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="aliMaven" />
<option name="name" value="AliYun Maven" />
<option name="url" value="https://maven.aliyun.com/repository/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="aliMaven" />
<option name="name" value="aliYun maven" />
<option name="url" value="https://maven.aliyun.com/repository/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK" />
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+29 -10
View File
@@ -28,6 +28,17 @@
<groupId>com.iteaj</groupId>
<artifactId>iot-mqtt</artifactId>
</dependency>
<!-- Jakarta Bean Validation API -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<!-- Hibernate Validator(实现) -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.iteaj</groupId>
<artifactId>iot-serial</artifactId>
@@ -45,11 +56,6 @@
<version>${hutool.version}</version>
<artifactId>hutool-cron</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<version>4.3.0</version>
<groupId>cn.afterturn</groupId>
@@ -111,11 +117,11 @@
<!-- iboot 可选插件 -->
<!--低代码平台插件-->
<dependency>
<groupId>com.iteaj</groupId>
<artifactId>iboot-code</artifactId>
<version>${project.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.iteaj</groupId>-->
<!-- <artifactId>iboot-code</artifactId>-->
<!-- <version>${project.version}</version>-->
<!-- </dependency>-->
<!-- Shiro权限认证插件(和SaToken二选其一)-->
<!-- <dependency>-->
@@ -216,5 +222,18 @@
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<encoding>UTF-8</encoding>
<release>${java.version}</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -87,7 +87,7 @@ public class CoreAutoConfiguration implements WebMvcConfigurer, AsyncConfigurer
public OrderFilterChainDefinition coreFilterChainDefinition() {
return new OrderFilterChainDefinition()
.addAnon("/core/login", "/js/**", "/css/**", "/img/**"
, "/libs/**", "/doc/**", "/favicon.ico", "/", "/static/**");
, "/libs/**", "/doc/**", "/favicon.ico", "/", "/static/**");
}
@Bean
@@ -8,8 +8,8 @@ import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* 演示拦截器
@@ -53,9 +53,9 @@ public class OnlineUserListener implements FrameworkListener<PayloadEvent<Online
.setExpireTime(payload.getExpireTime());
service.getOne(Wrappers.<OnlineUser>lambdaQuery().eq(OnlineUser::getSessionId, onlineUser.getSessionId()))
.ifPresent(user -> {
user.setLoginTime(onlineUser.getLoginTime()).setStatus(OnlineStatus.Online);
service.updateById(user);
}).ifNotPresent(user -> {
user.setLoginTime(onlineUser.getLoginTime()).setStatus(OnlineStatus.Online);
service.updateById(user);
}).ifNotPresent(user -> {
service.save(onlineUser);
});
@@ -48,7 +48,7 @@ public class AdminCenterController extends BaseController {
@PostMapping("pwd")
public Result<Boolean> updatePwd(@RequestBody PasswordDto passwordDto) {
this.adminService.updatePwdById(passwordDto.getId()
, passwordDto.getPassword(), passwordDto.getOldPwd());
, passwordDto.getPassword(), passwordDto.getOldPwd());
return success("修改成功");
}
}
@@ -18,8 +18,8 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
@@ -188,7 +188,7 @@ public class AdminController extends BaseController {
@PostMapping("updateCurrentPwd")
public Result updateCurrentPwd(@RequestBody PasswordDto passwordDto) {
this.adminService.updatePwdById(passwordDto.getId()
, passwordDto.getPassword(), passwordDto.getOldPwd());
, passwordDto.getPassword(), passwordDto.getOldPwd());
return success("设置成功");
}
}
@@ -12,8 +12,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* 用户管理中心接口
@@ -16,7 +16,7 @@ import com.iteaj.iboot.module.core.service.IOnlineUserService;
import com.iteaj.framework.security.CheckPermission;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@@ -87,7 +87,7 @@ public class UploadController extends BaseController {
try {
Admin admin = SecurityUtil.getLoginUser().map(item -> (Admin) item).get();
UploadResult result = this.uploadService.upload(file.getInputStream()
, file.getOriginalFilename(), "avatar-" + admin.getAccount(), "/avatar");
, file.getOriginalFilename(), "avatar-" + admin.getAccount(), "/avatar");
return success(result.getUrl(), "上传成功");
} catch (IOException e) {
logger.error(e.getMessage(), e);
@@ -95,7 +95,7 @@ public class Admin extends BaseEntity implements AuthenticationUser {
*/
@Excel(name = "创建时间", orderNum = "90", exportFormat = "yyyy-MM-dd", width = 15)
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd", timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date createTime;
/**
@@ -105,7 +105,7 @@ public class Admin extends BaseEntity implements AuthenticationUser {
/**更新时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
/**
@@ -32,15 +32,16 @@ public class Config extends BaseEntity {
/**创建时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**更新时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
public Config() { }
public Config() {
}
public Config(ConfigType type) {
this.type = type;
@@ -51,12 +51,12 @@ public class DictData extends BaseEntity {
/**创建时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**更新时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}
@@ -48,11 +48,11 @@ public class DictType extends BaseEntity implements DictResource {
/**创建时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**更新时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}
@@ -50,15 +50,16 @@ public class Menu extends TreeEntity implements MenuResource, Comparable<Menu> {
private String target;
/**创建时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd", timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date createTime;
/**更新时间*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date updateTime;
public Menu() { }
public Menu() {
}
public String getUrl() {
return url;
@@ -2,6 +2,8 @@ package com.iteaj.iboot.module.core.entity;
import com.iteaj.framework.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -21,6 +23,7 @@ import lombok.experimental.Accessors;
@TableName("sys_notify")
public class Notify extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
@@ -2,6 +2,8 @@ package com.iteaj.iboot.module.core.entity;
import com.iteaj.framework.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -21,6 +23,7 @@ import lombok.experimental.Accessors;
@TableName("sys_notify_user")
public class NotifyUser extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -80,14 +80,15 @@ public class OnlineUser extends BaseEntity implements OnlineSession {
private String userNick;
/**创建时间*/
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**更新时间*/
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
public OnlineUser() { }
public OnlineUser() {
}
public OnlineUser(String sessionId) {
this.sessionId = sessionId;
@@ -55,11 +55,11 @@ public class Org extends TreeEntity {
private Integer level;
/**创建时间*/
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**更新时间*/
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}
@@ -3,6 +3,8 @@ package com.iteaj.iboot.module.core.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.iteaj.framework.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -22,6 +24,7 @@ import lombok.experimental.Accessors;
@TableName("sys_post")
public class Post extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -41,10 +41,10 @@ public class Role extends BaseEntity {
private String remark;
/**创建时间*/
@JsonFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date createTime;
/**更新时间*/
@JsonFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date updateTime;
}
@@ -21,7 +21,7 @@ public class LoggerListener implements FrameworkListener<PayloadEvent<AccessLogg
@Override
public void onApplicationEvent(PayloadEvent<AccessLogger> event) {
AccessLogger payload = event.getPayload();
Optional<Entity> source = (Optional<Entity>)event.getSource();
Optional<Entity> source = (Optional<Entity>) event.getSource();
AccessLog accessLog = new AccessLog();
BeanUtils.copyProperties(payload, accessLog);
@@ -22,7 +22,7 @@ public interface IMenuService extends IBaseService<Menu> {
* @param isSuper 是否是超级管理员
* @return
*/
ListResult<Menu> selectMenuBarTrees(Long aid, boolean isSuper);
ListResult<Menu> selectMenuBarTrees(Long aid, boolean isSuper);
/**
* 不包含菜单类型是权限的菜单
@@ -21,14 +21,14 @@ public class AccessLogServiceImpl extends BaseServiceImpl<IAccessLogDao, AccessL
@Override
public PageResult<IPage<AccessLog>> page(IPage<AccessLog> page, AccessLog condition) {
Object[] section = condition.getSection();
Object start = section != null && section.length>0 ? section[0] : null;
Object end = section != null && section.length>1 ? section[1] : null;
Object start = section != null && section.length > 0 ? section[0] : null;
Object end = section != null && section.length > 1 ? section[1] : null;
return new PageResult<>(getBaseMapper().selectPage(page,
new QueryWrapper<>(condition)
.gt(start!=null, "create_time", start)
.lt(end!=null, "create_time", end)
.gt(start != null, "create_time", start)
.lt(end != null, "create_time", end)
.orderByDesc("create_time")
.orderByDesc(condition.getMillis()!=null, "millis")));
.orderByDesc(condition.getMillis() != null, "millis")));
}
}
@@ -42,7 +42,7 @@ public class AdminServiceImpl extends BaseServiceImpl<IAdminDao, Admin> implemen
public void createAdmin(AdminDto adminDto) {
if(null == adminDto) throw new ServiceException("创建失败");
Admin byAccount = this.getByAccount(adminDto.getAccount());
if(null != byAccount) throw new ServiceException("此账号已经存在:"+adminDto.getAccount());
if(null != byAccount) throw new ServiceException("此账号已经存在:" + adminDto.getAccount());
if(StrUtil.isNotBlank(adminDto.getPassword())) {
adminDto.setPassword(SecureUtil.md5(adminDto.getPassword()));
@@ -21,10 +21,14 @@ public class ConfigServiceImpl extends BaseServiceImpl<IConfigDao, Config> imple
@Override
public BooleanResult save(Config entity) {
getOne(Wrappers.<Config>lambdaQuery().eq(Config::getLabel, entity.getLabel())).ofNullable()
.ifPresent(item -> {throw new ServiceException("配置标识重复["+entity.getLabel()+"]");});
.ifPresent(item -> {
throw new ServiceException("配置标识重复[" + entity.getLabel() + "]");
});
getOne(Wrappers.<Config>lambdaQuery().eq(Config::getName, entity.getName())).ofNullable()
.ifPresent(item -> {throw new ServiceException("配置名称重复["+entity.getName()+"]");});
.ifPresent(item -> {
throw new ServiceException("配置名称重复[" + entity.getName() + "]");
});
return super.save(entity);
}
@@ -35,7 +39,7 @@ public class ConfigServiceImpl extends BaseServiceImpl<IConfigDao, Config> imple
.ifPresent(item -> {
// 名称重复
if(entity.getId().compareTo(item.getId()) != 0) {
throw new ServiceException("配置名称重复["+entity.getName()+"]");
throw new ServiceException("配置名称重复[" + entity.getName() + "]");
}
});
return super.updateById(entity);
@@ -33,10 +33,14 @@ public class DictTypeServiceImpl extends BaseServiceImpl<IDictTypeDao, DictType>
@Override
public BooleanResult save(DictType entity) {
getOne(Wrappers.<DictType>lambdaQuery().eq(DictType::getType, entity.getType())).ofNullable()
.ifPresent(item -> {throw new ServiceException("字典类型重复["+entity.getType()+"]");});
.ifPresent(item -> {
throw new ServiceException("字典类型重复[" + entity.getType() + "]");
});
getOne(Wrappers.<DictType>lambdaQuery().eq(DictType::getName, entity.getName())).ofNullable()
.ifPresent(item -> {throw new ServiceException("字典名称重复["+entity.getName()+"]");});
.ifPresent(item -> {
throw new ServiceException("字典名称重复[" + entity.getName() + "]");
});
return super.save(entity);
}
@@ -46,7 +50,7 @@ public class DictTypeServiceImpl extends BaseServiceImpl<IDictTypeDao, DictType>
getOne(Wrappers.<DictType>lambdaQuery().eq(DictType::getName, entity.getName())).ofNullable()
.ifPresent(item -> {
if(item.getId().compareTo(entity.getId()) != 0) {
throw new ServiceException("字典名称重复["+entity.getName()+"]");
throw new ServiceException("字典名称重复[" + entity.getName() + "]");
}
});
@@ -26,6 +26,7 @@ import java.util.stream.Collectors;
public class MenuServiceImpl extends BaseServiceImpl<IMenuDao, Menu> implements IMenuService {
private final List<Module> modules;
public MenuServiceImpl(List<Module> modules) {
this.modules = modules;
}
@@ -36,7 +37,9 @@ public class MenuServiceImpl extends BaseServiceImpl<IMenuDao, Menu> implements
.eq(Menu::getName, entity.getName())
.eq(Menu::getPid, entity.getPid()))
.ofNullable()
.ifPresent(menu -> {throw new ServiceException("同级已经存在菜单名称["+entity.getName()+"]");});
.ifPresent(menu -> {
throw new ServiceException("同级已经存在菜单名称[" + entity.getName() + "]");
});
return super.save(entity);
}
@@ -48,8 +51,8 @@ public class MenuServiceImpl extends BaseServiceImpl<IMenuDao, Menu> implements
.eq(Menu::getPid, entity.getPid())
.eq(Menu::getName, entity.getName()))
.ofNullable().ifPresent(menu -> {
throw new ServiceException("同级已经存在菜单名称["+entity.getName()+"]");
});
throw new ServiceException("同级已经存在菜单名称[" + entity.getName() + "]");
});
entity.setUpdateTime(new Date());
return super.updateById(entity);
@@ -127,10 +130,10 @@ public class MenuServiceImpl extends BaseServiceImpl<IMenuDao, Menu> implements
idList.stream().forEach(item -> {
this.count(Wrappers.<Menu>query().eq("pid", item))
.ofNullable().filter(count -> count > 0)
.ifPresent((menu) -> {
throw new ServiceException("请先删除子菜单");
});
.ofNullable().filter(count -> count > 0)
.ifPresent((menu) -> {
throw new ServiceException("请先删除子菜单");
});
});
return super.removeByIds(idList);
@@ -40,7 +40,7 @@ public class OrgServiceImpl extends BaseServiceImpl<IOrgDao, Org> implements IOr
@CacheEvict(allEntries = true)
public BooleanResult save(Org entity) {
this.getOne(Wrappers.<Org>lambdaQuery().eq(Org::getName, entity.getName()))
.ifPresentThrow("部门["+entity.getName()+"]已存在");
.ifPresentThrow("部门[" + entity.getName() + "]已存在");
super.save(entity);
if(entity.getPid() == 0l) {
@@ -51,7 +51,7 @@ public class OrgServiceImpl extends BaseServiceImpl<IOrgDao, Org> implements IOr
parent.ofNullable().orElseThrow(() -> new ServiceException("父部门不存在"));
entity.setLevel(parent.getData().getLevel() + 1);
entity.setPath(parent.getData().getPath()+","+entity.getId());
entity.setPath(parent.getData().getPath() + "," + entity.getId());
}
return updateById(entity); // 更新最新路径path;
@@ -65,7 +65,7 @@ public class OrgServiceImpl extends BaseServiceImpl<IOrgDao, Org> implements IOr
parent.ofNullable().orElseThrow(() -> new ServiceException("父部门不存在"));
entity.setLevel(parent.getData().getLevel() + 1);
entity.setPath(parent.getData().getPath()+","+entity.getId());
entity.setPath(parent.getData().getPath() + "," + entity.getId());
if(parent.getData().getId().equals(entity.getId())) {
throw new ServiceException("父部门不能是自己");
@@ -92,10 +92,10 @@ public class OrgServiceImpl extends BaseServiceImpl<IOrgDao, Org> implements IOr
// 如果存在子部门, 则要先删除子部门
list(Wrappers.<Org>query().eq("pid", id))
.ofNullable().ifPresent(item -> {
if(!item.isEmpty()) {
throw new ServiceException("请先删除子部门");
}
});
if(!item.isEmpty()) {
throw new ServiceException("请先删除子部门");
}
});
// 此部门已经在使用
adminService.getOne(Wrappers.<Admin>query().eq("org_id", id))
@@ -27,10 +27,10 @@ public class PostServiceImpl extends BaseServiceImpl<PostMapper, Post> implement
public BooleanResult save(Post entity) {
// 同一个机构下面不能存在同一个岗位
this.getOne(Wrappers.<Post>lambdaQuery()
.eq(Post::getOrgId, entity.getOrgId())
.eq(Post::getName, entity.getName())).ifPresent(item -> {
throw new ServiceException("岗位名称["+entity.getName()+"]已存在");
});
.eq(Post::getOrgId, entity.getOrgId())
.eq(Post::getName, entity.getName())).ifPresent(item -> {
throw new ServiceException("岗位名称[" + entity.getName() + "]已存在");
});
return super.save(entity);
}
@@ -40,7 +40,7 @@ public class PostServiceImpl extends BaseServiceImpl<PostMapper, Post> implement
.ne(Post::getId, entity.getId())
.eq(Post::getOrgId, entity.getOrgId())
.eq(Post::getName, entity.getName())).ifPresent(item -> {
throw new ServiceException("岗位名称["+entity.getName()+"]已存在");
throw new ServiceException("岗位名称[" + entity.getName() + "]已存在");
});
return super.updateById(entity);
@@ -48,10 +48,10 @@ public class RoleServiceImpl extends BaseServiceImpl<IRoleDao, Role> implements
public BooleanResult updateById(Role entity) {
this.getOne(Wrappers.<Role>lambdaQuery().eq(Role::getName, entity.getName()))
.ofNullable().ifPresent(item -> {
if(item.getId().compareTo(entity.getId()) != 0) {
throw new ServiceException("角色名称重复["+entity.getName()+"]");
}
});
if(item.getId().compareTo(entity.getId()) != 0) {
throw new ServiceException("角色名称重复[" + entity.getName() + "]");
}
});
return super.updateById(entity);
}
@@ -86,7 +86,9 @@ public class RoleServiceImpl extends BaseServiceImpl<IRoleDao, Role> implements
@Override
public void createRoleAndPerms(RoleDto role) {
this.getOne(Wrappers.<Role>lambdaQuery().eq(Role::getName, role.getName())).ofNullable()
.ifPresent(item -> {throw new ServiceException("角色名称重复["+role.getName()+"]");});
.ifPresent(item -> {
throw new ServiceException("角色名称重复[" + role.getName() + "]");
});
getBaseMapper().createRoleAndPerms(role);
}
@@ -98,11 +100,11 @@ public class RoleServiceImpl extends BaseServiceImpl<IRoleDao, Role> implements
}
this.getOne(Wrappers.<Role>lambdaQuery().eq(Role::getName, role.getName()))
.ofNullable().ifPresent(item -> {
// 设备名称已存在
if(role.getId().compareTo(item.getId()) != 0) {
throw new ServiceException("角色名称重复["+role.getName()+"]");
}
});
// 设备名称已存在
if(role.getId().compareTo(item.getId()) != 0) {
throw new ServiceException("角色名称重复[" + role.getName() + "]");
}
});
getBaseMapper().updateRolePermsById(role);
Objects.requireNonNull(cacheManager.getCache(IBOOT_CACHE_KEY_PERMS)).clear();
@@ -20,7 +20,7 @@ import java.util.stream.Collectors;
* @author iteaj
* @since 1.0
*/
public class SysResourceManager implements ResourceManager{
public class SysResourceManager implements ResourceManager {
@Autowired
private IMenuService menuService;
@@ -53,7 +53,7 @@ public class SysResourceManager implements ResourceManager{
Collection<Menu> menus = TreeUtils.toTrees(listResult.getData(), 0l);
return menus.stream().map(item -> (MenuResource)item)
return menus.stream().map(item -> (MenuResource) item)
.collect(Collectors.toCollection(ArrayList::new));
}
}
@@ -139,7 +139,7 @@ public class IotAutoConfiguration {
public IBootThreadManger iBootThreadManger(IotMsnProperties properties) {
Integer poolSize = properties.getTask().getPoolSize();
TaskSchedulerBuilder builder = new TaskSchedulerBuilder(poolSize, false
, null, properties.getTask().getThreadNamePrefix(), null);
, null, properties.getTask().getThreadNamePrefix(), null);
return new IBootThreadManger(builder.build());
}
}
@@ -11,7 +11,7 @@ import com.iteaj.iboot.module.iot.cache.entity.RealtimeStatus;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class HashMapRealtimeDataService implements RealtimeDataService{
public class HashMapRealtimeDataService implements RealtimeDataService {
private final IotCacheManager cacheManager;
private final Map<String, Map<String, Map<String, RealtimeData>>> realtimeMap = new ConcurrentHashMap<>(500);
@@ -26,7 +26,7 @@ public class RealtimeData implements ModelAttrRealtimeData {
*/
private String signalOrField;
public RealtimeData( SignalOrFieldValue realtime) {
public RealtimeData(SignalOrFieldValue realtime) {
this.realtime = realtime;
this.signalOrField = realtime.getSignalOrField();
}
@@ -27,7 +27,7 @@ public class RealtimeDataCacheListener implements EventGroupCollectListener, Sig
if(supplier != null) {
realtimeDataService.put(supplier);
IotLogger.debug(IotLogger.REPORT_NAME, supplier.getProtocolCode(), device.getUid()
, "<<< 接收到设备上报数据 设备编号: {}", supplier.getKey().getKey());
, "<<< 接收到设备上报数据 设备编号: {}", supplier.getKey().getKey());
}
}
@@ -39,7 +39,7 @@ public class RealtimeDataCacheListener implements EventGroupCollectListener, Sig
@Override
public void supplier(CollectDevice device, CollectData data) {
realtimeDataService.put(device.getProtocolCode(), device.buildKey()
, SignalOrFieldValue.build(data.getSignalId(), data.getAddress(), data.getCollectTime()
, data.getValue(), data.getAddress()).builder(data.getCollectStatus()));
, SignalOrFieldValue.build(data.getSignalId(), data.getAddress(), data.getCollectTime()
, data.getValue(), data.getAddress()).builder(data.getCollectStatus()));
}
}
@@ -11,7 +11,7 @@ import com.iteaj.framework.utils.RedisUtils;
import java.util.*;
import java.util.stream.Collectors;
public class RedisRealtimeDataService implements RealtimeDataService{
public class RedisRealtimeDataService implements RealtimeDataService {
private static final String KEY_PREFIX = "Realtime:Data:";
@@ -60,12 +60,12 @@ public class RedisRealtimeDataService implements RealtimeDataService{
String signalOrField = value.getSignalOrField();
String valueKey = KEY_PREFIX + protocolCode + ":" + key.getKey();
Object o = RedisUtils.getOpsForHash().get(valueKey, signalOrField);
if(o instanceof RealtimeData) {
((RealtimeData) o).setRealtime(value);
if(o instanceof RealtimeData data) {
data.setRealtime(value);
RedisUtils.getOpsForHash().put(valueKey, signalOrField, o);
} else {
RedisUtils.getOpsForHash().put(valueKey
, signalOrField, new RealtimeData(value));
, signalOrField, new RealtimeData(value));
}
}
@@ -82,8 +82,8 @@ public class RedisRealtimeDataService implements RealtimeDataService{
String key = keys.get(i);
Object value = list.get(i);
SignalOrFieldValue fieldValue = collect.get(key);
if(value instanceof RealtimeData) {
((RealtimeData) value).setRealtime(fieldValue);
if(value instanceof RealtimeData data) {
data.setRealtime(fieldValue);
} else {
value = new RealtimeData(fieldValue);
}
@@ -53,83 +53,83 @@ public class CollectActionTask implements Runnable {
RealtimeStatus realtimeStatus = cacheManager.get(collectDevice.getProtocolCode(), collectDevice.buildKey());
if(realtimeStatus != null) {
// if(realtimeStatus.getStatus() == DeviceStatus.online) {
List<CollectData> values = new ArrayList<>();
DeviceProtocolSupplier supplier = ProtocolSupplierManager.get(collectDevice.getProtocolCode());
if(supplier != null) {
ProtocolModel protocol = supplier.getProtocol();
collectDevice.getSignals().forEach(signal -> {
CollectData data = new CollectData(CollectMode.signal)
.setCid(cid + "").setReason("")
.setFieldName(signal.getFieldName())
.setAddress(signal.getAddress())
.setCollectStatus(CollectStatus.Success)
.setCreateTime(date)
.setUid(String.valueOf(collectDevice.getUid()))
.setSignalId(signal.getId())
.setCollectTaskId(taskDto.getId());
List<CollectData> values = new ArrayList<>();
DeviceProtocolSupplier supplier = ProtocolSupplierManager.get(collectDevice.getProtocolCode());
if(supplier != null) {
ProtocolModel protocol = supplier.getProtocol();
collectDevice.getSignals().forEach(signal -> {
CollectData data = new CollectData(CollectMode.signal)
.setCid(cid + "").setReason("")
.setFieldName(signal.getFieldName())
.setAddress(signal.getAddress())
.setCollectStatus(CollectStatus.Success)
.setCreateTime(date)
.setUid(String.valueOf(collectDevice.getUid()))
.setSignalId(signal.getId())
.setCollectTaskId(taskDto.getId());
try {
AbstractProtocolModelApi modelApi = protocol.getApi(signal.getDirect());
JSONObject param = new JSONObject();
param.put(PointProtocolConfig.POINT_NUMBER, signal.getNum());
param.put(PointProtocolConfig.POINT_ADDRESS, signal.getAddress());
param.put(PointProtocolConfig.POINT_CHILD_SN, collectDevice.getDeviceSn());
ProtocolModelApiInvokeParam invokeParam = new ProtocolModelApiInvokeParam(collectDevice.getUid().toString(), param)
.setDeviceSn(collectDevice.getDeviceSn()).setParentDeviceSn(collectDevice.getParentDeviceSn());
try {
AbstractProtocolModelApi modelApi = protocol.getApi(signal.getDirect());
JSONObject param = new JSONObject();
param.put(PointProtocolConfig.POINT_NUMBER, signal.getNum());
param.put(PointProtocolConfig.POINT_ADDRESS, signal.getAddress());
param.put(PointProtocolConfig.POINT_CHILD_SN, collectDevice.getDeviceSn());
ProtocolModelApiInvokeParam invokeParam = new ProtocolModelApiInvokeParam(collectDevice.getUid().toString(), param)
.setDeviceSn(collectDevice.getDeviceSn()).setParentDeviceSn(collectDevice.getParentDeviceSn());
modelApi.invoke(invokeParam, invokeResult -> {
data.setCollectTime(new Date());
if(invokeResult.getStatus() == ExecStatus.success) {
data.setValue(invokeResult.getValue().toString());
} else {
data.setCollectStatus(CollectStatus.from(invokeResult.getStatus()));
}
});
} catch (CollectException e) {
String message = e.getMessage() == null ? e.getCause().getMessage() : e.getMessage();
data.setCollectStatus(CollectStatus.Fail).setCollectTime(new Date()).setReason(message);
logger.error("采集任务失败 {} - 任务: {} - 周期: {} - 设备: {} - 点位: {}({})"
, message, taskDto.getName(), taskDto.getCron()
, collectDevice.getDeviceSn(), signal.getName(), signal.getAddress(), e);
} catch (NotIotClientException e) {
data.setCollectStatus(CollectStatus.Fail).setCollectTime(new Date()).setReason("获取不到客户端");
logger.error("采集任务失败 {} - 任务: {} - 周期: {} - 设备: {} - 点位: {}({})"
, e.getMessage(), taskDto.getName(), taskDto.getCron()
, collectDevice.getDeviceSn(), signal.getName(), signal.getAddress(), e);
} catch (Exception e) {
data.setCollectStatus(CollectStatus.Fail).setCollectTime(new Date()).setReason("未知错误");
logger.error("采集任务失败 {} - 任务: {} - 周期: {} - 设备: {} - 点位: {}({})"
, e.getMessage(), taskDto.getName(), taskDto.getCron()
, collectDevice.getDeviceSn(), signal.getName(), signal.getAddress(), e);
}
values.add(data);
CollectListenerManager.getInstance().signalPublish(listener -> {
try {
listener.supplier(collectDevice, data);
} catch (Exception e) {
logger.error("采集点位事件实时发布异常 - 任务: {} - 设备: {}", taskDto.getName(), collectDevice.buildKey(), e);
modelApi.invoke(invokeParam, invokeResult -> {
data.setCollectTime(new Date());
if(invokeResult.getStatus() == ExecStatus.success) {
data.setValue(invokeResult.getValue().toString());
} else {
data.setCollectStatus(CollectStatus.from(invokeResult.getStatus()));
}
});
});
}
// 存储
if(!CollectionUtils.isEmpty(values)) {
StoreAction storeAction = StoreActionFactory.getInstance().get(item.getStoreAction());
if(storeAction != null) {
storeAction.store(item, values);
} catch (CollectException e) {
String message = e.getMessage() == null ? e.getCause().getMessage() : e.getMessage();
data.setCollectStatus(CollectStatus.Fail).setCollectTime(new Date()).setReason(message);
logger.error("采集任务失败 {} - 任务: {} - 周期: {} - 设备: {} - 点位: {}({})"
, message, taskDto.getName(), taskDto.getCron()
, collectDevice.getDeviceSn(), signal.getName(), signal.getAddress(), e);
} catch (NotIotClientException e) {
data.setCollectStatus(CollectStatus.Fail).setCollectTime(new Date()).setReason("获取不到客户端");
logger.error("采集任务失败 {} - 任务: {} - 周期: {} - 设备: {} - 点位: {}({})"
, e.getMessage(), taskDto.getName(), taskDto.getCron()
, collectDevice.getDeviceSn(), signal.getName(), signal.getAddress(), e);
} catch (Exception e) {
data.setCollectStatus(CollectStatus.Fail).setCollectTime(new Date()).setReason("未知错误");
logger.error("采集任务失败 {} - 任务: {} - 周期: {} - 设备: {} - 点位: {}({})"
, e.getMessage(), taskDto.getName(), taskDto.getCron()
, collectDevice.getDeviceSn(), signal.getName(), signal.getAddress(), e);
}
// 存储实时数据
values.add(data);
CollectListenerManager.getInstance().signalPublish(listener -> {
try {
listener.finished(collectDevice, values);
listener.supplier(collectDevice, data);
} catch (Exception e) {
logger.error("采集点位事件完成发布异常 - 任务: {} - 设备: {}", taskDto.getName(), collectDevice.buildKey(), e);
logger.error("采集点位事件实时发布异常 - 任务: {} - 设备: {}", taskDto.getName(), collectDevice.buildKey(), e);
}
});
});
}
// 存储
if(!CollectionUtils.isEmpty(values)) {
StoreAction storeAction = StoreActionFactory.getInstance().get(item.getStoreAction());
if(storeAction != null) {
storeAction.store(item, values);
}
// 存储实时数据
CollectListenerManager.getInstance().signalPublish(listener -> {
try {
listener.finished(collectDevice, values);
} catch (Exception e) {
logger.error("采集点位事件完成发布异常 - 任务: {} - 设备: {}", taskDto.getName(), collectDevice.buildKey(), e);
}
});
}
// } else {
// logger.warn("采集点位取消 设备不在线 - 任务: {} - 设备: {}", taskDto.getName(), collectDevice.buildKey());
// }
@@ -1,5 +1,5 @@
package com.iteaj.iboot.module.iot.collect;
public interface CollectDataListener {
}
@@ -16,7 +16,8 @@ public class CollectListenerManager {
private static CollectListenerManager instance = new CollectListenerManager();
protected CollectListenerManager() { }
protected CollectListenerManager() {
}
public static CollectListenerManager build(List<CollectDataListener> listeners) {
if(CollectionUtil.isNotEmpty(listeners)) {
@@ -29,12 +30,12 @@ public class CollectListenerManager {
}
public void register(CollectDataListener listener) {
if(listener instanceof EventGroupCollectListener) {
instance.register((EventGroupCollectListener) listener);
if(listener instanceof EventGroupCollectListener collectListener) {
instance.register(collectListener);
}
if(listener instanceof SignalCollectListener) {
instance.register((SignalCollectListener) listener);
if(listener instanceof SignalCollectListener collectListener) {
instance.register(collectListener);
}
listeners.add(listener);
@@ -67,8 +68,8 @@ public class CollectListenerManager {
public void modelAttrPublish(Consumer<ModelAttrListener> consumer) {
try {
this.listeners.forEach(item -> {
if(item instanceof ModelAttrListener) {
consumer.accept((ModelAttrListener) item);
if(item instanceof ModelAttrListener listener) {
consumer.accept(listener);
}
});
} catch (Exception e) {
@@ -83,8 +84,8 @@ public class CollectListenerManager {
public void deviceStatusPublish(Consumer<DeviceStatusListener> consumer) {
try {
this.listeners.forEach(item -> {
if(item instanceof DeviceStatusListener) {
consumer.accept((DeviceStatusListener) item);
if(item instanceof DeviceStatusListener listener) {
consumer.accept(listener);
}
});
} catch (Exception e) {
@@ -38,14 +38,14 @@ public class CollectTaskListenerService implements ApplicationReadyListener {
private Map<Long, ScheduledFuture> scheduledFutureMap = new ConcurrentHashMap<>();
public CollectTaskListenerService(IBootThreadManger threadManger, IotCacheManager cacheManager
, StoreActionFactory storeActionFactory, ICollectTaskService collectTaskService) {
, StoreActionFactory storeActionFactory, ICollectTaskService collectTaskService) {
this.threadManger = threadManger;
this.cacheManager = cacheManager;
this.storeActionFactory = storeActionFactory;
this.collectTaskService = collectTaskService;
}
public void statusSwitch(Long id, String status) throws CollectException{
public void statusSwitch(Long id, String status) throws CollectException {
if(status.equals("run")) {
CollectTaskDto taskDto = collectTaskService.collectDetailById(id);
@@ -60,8 +60,8 @@ public class CollectTaskListenerService implements ApplicationReadyListener {
ScheduledFuture future = scheduledFutureMap.get(id);
Object result = validateTask(taskDto);// 校验采集任务
if(result instanceof String) { // 任务校验失败
throw new CollectException((String) result);
if(result instanceof String string) { // 任务校验失败
throw new CollectException(string);
}
if(future == null) {
@@ -70,13 +70,13 @@ public class CollectTaskListenerService implements ApplicationReadyListener {
scheduledFutureMap.remove(id);
createScheduledTask(taskDto);
}
} else if(status.equals("stop")){
} else if(status.equals("stop")) {
ScheduledFuture future = scheduledFutureMap.remove(id);
if(future != null && !future.isCancelled()) {
future.cancel(true);
}
} else {
throw new IllegalArgumentException("不支持的状态["+status+"]");
throw new IllegalArgumentException("不支持的状态[" + status + "]");
}
collectTaskService.update(Wrappers.<CollectTask>lambdaUpdate()
@@ -105,7 +105,7 @@ public class CollectTaskListenerService implements ApplicationReadyListener {
String reason = null;
if(CollectionUtils.isEmpty(item.getDevices())) {
reason = "任务详情["+item.getPointGroupName()+"]没有绑定任何设备";
reason = "任务详情[" + item.getPointGroupName() + "]没有绑定任何设备";
}
if(reason != null) {
@@ -119,7 +119,7 @@ public class CollectTaskListenerService implements ApplicationReadyListener {
}
});
} catch (CollectException e) {
logger.error("校验任务失败 {} - 任务:{}", e.getMessage(), taskDto.getName());
logger.error("校验任务失败 {} - 任务:{}", e.getMessage(), taskDto.getName(), e);
return e.getMessage();
} catch (Exception e) {
logger.error("校验任务失败 {} - 任务:{}", e.getMessage(), taskDto.getName(), e);
@@ -5,7 +5,7 @@ import com.iteaj.iboot.module.iot.cache.entity.RealtimeStatus;
import java.util.Arrays;
import java.util.Collection;
public interface DeviceStatusListener extends CollectDataListener{
public interface DeviceStatusListener extends CollectDataListener {
default void supplier(RealtimeStatus device) {
this.supplier(Arrays.asList(device));
@@ -8,5 +8,6 @@ public interface SignalCollectListener extends CollectDataListener {
void supplier(CollectDevice device, CollectData data);
default void finished(CollectDevice device, List<CollectData> data) {}
default void finished(CollectDevice device, List<CollectData> data) {
}
}
@@ -22,7 +22,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
public class CollectGroupTask implements Runnable{
public class CollectGroupTask implements Runnable {
private DeviceGroup group;
private List<ModelApi> apis;
@@ -40,7 +40,7 @@ public class CollectGroupTask implements Runnable{
public void run() {
// 没有任何采集接口, 放弃采集任务
if(this.apis == null || this.apis.isEmpty()) {
IotLogger.warn(source,"-","放弃采集任务 没有任何采集接口 - 设备组: {}", group.getName());
IotLogger.warn(source, "-", "放弃采集任务 没有任何采集接口 - 设备组: {}", group.getName());
return;
}
@@ -58,19 +58,19 @@ public class CollectGroupTask implements Runnable{
if(device.getStatus() == DeviceStatus.offline) {
if(device.getType() == DeviceType.Gateway) {
IotLogger.warn(source, device.getUid(), "放弃设备采集 设备不在线 - 设备组: {} - 设备编号: {}"
, group.getName(), device.buildDeviceKey());
, group.getName(), device.buildDeviceKey());
continue;
} else if(device.getType() == DeviceType.Child) {
RealtimeStatus parent = cacheManager.get(device.getProtocolCode(), device.getParentDeviceSn());
if(parent != null) {
if(parent.getStatus() == DeviceStatus.offline) {
IotLogger.warn(source, device.getUid(), "放弃设备采集 网关设备不在线 - 设备组: {} - 设备编号: {}"
, group.getName(), device.buildDeviceKey());
, group.getName(), device.buildDeviceKey());
continue;
}
} else {
IotLogger.warn(source, device.getUid(), "放弃设备采集 父设备不存在 - 设备组: {} - 设备编号: {}"
, group.getName(), device.buildDeviceKey());
, group.getName(), device.buildDeviceKey());
continue;
}
}
@@ -94,14 +94,14 @@ public class CollectGroupTask implements Runnable{
prevParentDeviceSn = device.getParentDeviceSn();
}
} catch (ProtocolInvokeException e) {
IotLogger.error(source, device.getUid(),"接口采集执行异常 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", e.getMessage()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
IotLogger.error(source, device.getUid(), "接口采集执行异常 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", e.getMessage()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
} catch (ServiceException e) {
IotLogger.error(source, device.getUid(),"接口采集执行错误 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", e.getMessage()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
IotLogger.error(source, device.getUid(), "接口采集执行错误 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", e.getMessage()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
} catch (Exception e) {
IotLogger.error(source, device.getUid(),"接口采集未知异常 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", e.getMessage()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
IotLogger.error(source, device.getUid(), "接口采集未知异常 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", e.getMessage()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
}
}
}
@@ -110,7 +110,7 @@ public class CollectGroupTask implements Runnable{
try {
listener.finished(info);
} catch (Exception e) {
IotLogger.error(source,"-","采集事件完成发布异常 {} - 设备组: {}", e.getMessage(), source.getName(), group.getName(), e);
IotLogger.error(source, "-", "采集事件完成发布异常 {} - 设备组: {}", e.getMessage(), source.getName(), group.getName(), e);
}
});
}
@@ -128,10 +128,10 @@ public class CollectGroupTask implements Runnable{
} else {
if(retry) {
IotLogger.warn(source, device.getUid(), "采集重试失败 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", result.getReason()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect());
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect());
} else {
IotLogger.warn(source, device.getUid(), "采集失败 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", result.getReason()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect());
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect());
}
// 发布采集的数据
@@ -150,7 +150,7 @@ public class CollectGroupTask implements Runnable{
item.supplier(source, group, deviceInfo);
} catch (Exception e) {
IotLogger.error(source, device.getUid(), "采集事件实时发布异常 {} - 设备组: {} - 设备编号: {} - 接口: {}/{}", e.getMessage()
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
, group.getName(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
}
});
});
@@ -38,7 +38,8 @@ public class CollectInfo {
public DeviceInfo addDeviceInfo(RealtimeStatus device, ModelApi api, DataSupplier supplier) {
DeviceInfo deviceInfo = new DeviceInfo(api, device, supplier);
this.infos.add(deviceInfo); return deviceInfo;
this.infos.add(deviceInfo);
return deviceInfo;
}
@Getter
@@ -160,7 +160,7 @@ public class DeviceStatusModelApiManager implements Runnable, ApplicationReadyLi
// 父设备不存在或者不在线则不采集子设备状态
if(realtimeStatus == null || realtimeStatus.getStatus() == DeviceStatus.offline) {
IotLogger.debug(IotLogger.NAME, "采集状态", device.getUid(), "放弃状态接口调用 网关设备不在线 - 网关编号: {} - 设备编号: {} - 接口: {}/{}"
, device.getParentDeviceSn(), device.getDeviceSn(), api.getCode(), api.getDirect());
, device.getParentDeviceSn(), device.getDeviceSn(), api.getCode(), api.getDirect());
return;
}
}
@@ -180,7 +180,7 @@ public class DeviceStatusModelApiManager implements Runnable, ApplicationReadyLi
}
IotLogger.error(IotLogger.NAME, "采集状态", device.getUid(), "采集状态异常 {} - 设备编号: {} - 接口: {}/{}"
, e.getMessage(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
, e.getMessage(), device.buildDeviceKey(), api.getCode(), api.getDirect(), e);
}
private void doInvoke(ModelApi api, RealtimeStatus device, long timeout, boolean retry) {
@@ -217,10 +217,10 @@ public class DeviceStatusModelApiManager implements Runnable, ApplicationReadyLi
if(logger.isWarnEnabled()) {
if(retry) {
IotLogger.warn(IotLogger.NAME, "采集状态", device.getUid(), "采集状态重试失败 {} - 设备编号: {} - 接口: {}/{}"
, result.getStatus(), device.buildDeviceKey(), api.getCode(), api.getDirect());
, result.getStatus(), device.buildDeviceKey(), api.getCode(), api.getDirect());
} else {
IotLogger.warn(IotLogger.NAME, "采集状态", device.getUid(), "采集状态失败 {} - 设备编号: {} - 接口: {}/{}"
, result.getStatus(), device.buildDeviceKey(), api.getCode(), api.getDirect());
, result.getStatus(), device.buildDeviceKey(), api.getCode(), api.getDirect());
}
}
}
@@ -10,7 +10,8 @@ public interface EventGroupCollectListener extends CollectDataListener {
* 组任务采集完成
* @param info
*/
default void finished(CollectInfo info) {}
default void finished(CollectInfo info) {
}
/**
* 设备采集完成
@@ -34,8 +34,8 @@ public class EventSourceCollectService implements ApplicationReadyListener {
private final Map<Long, ScheduledFuture> futures = new ConcurrentHashMap<>(128);
public EventSourceCollectService(IotCacheManager cacheManager
, IBootThreadManger threadManger, IDeviceGroupService deviceGroupService
, IEventSourceService eventSourceService) {
, IBootThreadManger threadManger, IDeviceGroupService deviceGroupService
, IEventSourceService eventSourceService) {
this.cacheManager = cacheManager;
this.threadManger = threadManger;
this.deviceGroupService = deviceGroupService;
@@ -53,16 +53,16 @@ public class EventSourceCollectService implements ApplicationReadyListener {
eventSourceService.listProductById(source.getId(), null).forEach(product -> {
if(product.getStatus() == FuncStatus.disabled) {
throw new ServiceException("产品["+product.getName()+"]未启用");
throw new ServiceException("产品[" + product.getName() + "]未启用");
}
});
ThreadPoolTaskScheduler scheduler = threadManger.getScheduler();
ScheduledFuture<?> schedule = scheduler.schedule(new EventSourceTask(scheduler
, source, cacheManager), new CronTrigger(source.getCron()));
, source, cacheManager), new CronTrigger(source.getCron()));
futures.put(source.getId(), schedule);
} catch (ServiceException e) {
logger.error("启动事件源失败({}) {}", item.getName(), e.getMessage());
logger.error("启动事件源失败({}) {}", item.getName(), e.getMessage(), e);
eventSourceService.update(Wrappers.<EventSource>lambdaUpdate()
.set(EventSource::getReason, e.getMessage())
.eq(EventSource::getId, item.getId()));
@@ -94,7 +94,7 @@ public class EventSourceCollectService implements ApplicationReadyListener {
if(status == FuncStatus.enabled) { // 启用
this.eventSourceService.listProductById(source.getId(), null).forEach(product -> {
if(product.getStatus() == FuncStatus.disabled) {
throw new ServiceException("产品["+product.getName()+"]未启用");
throw new ServiceException("产品[" + product.getName() + "]未启用");
}
});
@@ -104,7 +104,7 @@ public class EventSourceCollectService implements ApplicationReadyListener {
ThreadPoolTaskScheduler scheduler = threadManger.getScheduler();
ScheduledFuture<?> schedule = scheduler.schedule(new EventSourceTask(scheduler
, source, cacheManager), new CronTrigger(source.getCron()));
, source, cacheManager), new CronTrigger(source.getCron()));
futures.put(id, schedule);
} else { // 禁用
// 取消定时任务
@@ -54,7 +54,7 @@ public class MqttStoreAction extends StoreAction {
// 创建连接配置信息
MqttGatewayConnectProperties connectProperties = new MqttGatewayConnectProperties((String) config.get("host")
, (Integer) config.get("port"), (String) config.get("clientId"), (String) config.get("topic"));
, (Integer) config.get("port"), (String) config.get("clientId"), (String) config.get("topic"));
if(StringUtils.hasText((String) config.get("username")) &&
StringUtils.hasText((String) config.get("password"))) {
connectProperties.setPassword((String) config.get("password"));
@@ -63,7 +63,7 @@ public class MqttStoreAction extends StoreAction {
// 创建请求报文
MqttGatewayHead head = new MqttGatewayHead((String) config.get("clientId")
, null, MqttGatewayProtocolType.Mqtt_Gateway);
, null, MqttGatewayProtocolType.Mqtt_Gateway);
DefaultMessageBody body = new DefaultMessageBody(JSONObject.toJSONBytes(item));
MqttGatewayMessage gatewayMessage = new MqttGatewayMessage(head, body, MqttQoS.AT_LEAST_ONCE, topic);
@@ -19,7 +19,8 @@ public class StoreActionFactory implements InitializingBean {
@Autowired(required = false)
private List<StoreAction> actions;
protected StoreActionFactory() { }
protected StoreActionFactory() {
}
private Map<String, StoreAction> actionMap = new ConcurrentHashMap<>(8);
private static StoreActionFactory actionFactory = new StoreActionFactory();
@@ -107,7 +108,7 @@ public class StoreActionFactory implements InitializingBean {
if(!this.isExists(item.getName())) {
this.register(item);
} else {
throw new BeanInitializationException("存在相同的采集动作["+item.getName()+"]");
throw new BeanInitializationException("存在相同的采集动作[" + item.getName() + "]");
}
});
}
@@ -25,6 +25,7 @@ public class RealtimeLoggerPush implements WebSocketServerListener, LoggerPushSe
private static final String URI = "/ws/logger/realtime";
private final DefaultWebSocketServerComponent server;
private ChannelGroup channelGroup;
public RealtimeLoggerPush(DefaultWebSocketServerComponent server) {
this.server = server;
}
@@ -41,7 +42,7 @@ public class RealtimeLoggerPush implements WebSocketServerListener, LoggerPushSe
JSONObject params = JSONObject.parseObject(protocol.readText());
if(!params.containsKey("level") || !params.containsKey("filter")) {
DefaultWebSocketServerProtocol.close(protocol.getEquipCode()
, WebSocketCloseStatus.INVALID_PAYLOAD_DATA, "未指定参数");
, WebSocketCloseStatus.INVALID_PAYLOAD_DATA, "未指定参数");
return;
}
@@ -56,28 +57,28 @@ public class RealtimeLoggerPush implements WebSocketServerListener, LoggerPushSe
public void push(Level level, PushParams params) {
if(channelGroup != null && !channelGroup.isEmpty()) {
DefaultWebSocketServerProtocol.writeGroup(URI, JSON.toJSONString(params)
, new WebSocketChannelMatcher((channel, session) -> {
JSONObject reqParams = channel.attr(PARAM_KEY).get();
Integer reqLevel = reqParams.getInteger("level");
, new WebSocketChannelMatcher((channel, session) -> {
JSONObject reqParams = channel.attr(PARAM_KEY).get();
Integer reqLevel = reqParams.getInteger("level");
if(reqLevel != null) {
if(level.toInt() < reqLevel) {
return false;
}
}
if(reqLevel != null) {
if(level.toInt() < reqLevel) {
return false;
}
}
JSONArray filter = reqParams.getJSONArray("filter");
if(filter == null || filter.isEmpty()) {
return true;
}
JSONArray filter = reqParams.getJSONArray("filter");
if(filter == null || filter.isEmpty()) {
return true;
}
long count = filter.stream()
.map(type -> LoggerManager.getFilter((String) type))
.filter(item -> item.filter(params))
.count();
long count = filter.stream()
.map(type -> LoggerManager.getFilter((String) type))
.filter(item -> item.filter(params))
.count();
return count > 0;
})
return count > 0;
})
);
}
}
@@ -81,7 +81,7 @@ public class RealtimePushListener implements WebSocketServerListener, EventGroup
devices.forEach(device -> {
try {
IotLogger.info(device.getStatus(), device.getUid(), "设备{} - 设备编号: {}"
, device.getStatus() == DeviceStatus.online ? "上线" : "离线", device.getDeviceSn());
, device.getStatus() == DeviceStatus.online ? "上线" : "离线", device.getDeviceSn());
String jsonString = JSONObject.toJSONString(PushData.buildStatus(device));
doPush(device.getUid(), jsonString, TYPE_STATUS);
} catch (Exception e) {
@@ -130,7 +130,7 @@ public class RealtimePushListener implements WebSocketServerListener, EventGroup
try {
Map<String, SignalOrFieldValue> valueMap = new HashMap<>();
valueMap.put(data.getAddress(), SignalOrFieldValue.build(data.getSignalId()
, data.getAddress(), data.getCollectTime(), data.getValue()).builder(data.getCollectStatus()));
, data.getAddress(), data.getCollectTime(), data.getValue()).builder(data.getCollectStatus()));
String deviceUid = device.getUid().toString();
String jsonString = JSONObject.toJSONString(PushData.buildSignal(deviceUid, valueMap));
@@ -131,7 +131,8 @@ public class ViewRealtimePushListener implements WebSocketServerListener, EventG
.append(DataItemOption.SPLIT).append(item.getAttr());
final String keyValue = key.toString();
if(binds.contains(keyValue)) {
item.setKey(keyValue); return true;
item.setKey(keyValue);
return true;
}
return false;
@@ -142,11 +143,13 @@ public class ViewRealtimePushListener implements WebSocketServerListener, EventG
.append(DataItemOption.SPLIT).append(item.getProductCode());
String keyValue = key.toString();
if(binds.contains(keyValue)) {
item.setKey(keyValue); return true;
item.setKey(keyValue);
return true;
} else {
keyValue = key.append(DataItemOption.SPLIT).append(item.getUid()).toString();
if(binds.contains(keyValue)) {
item.setKey(keyValue); return true;
item.setKey(keyValue);
return true;
}
}
@@ -9,7 +9,6 @@ import com.iteaj.iboot.module.iot.dto.CollectDataDto;
import com.iteaj.iboot.module.iot.entity.CollectData;
import com.iteaj.iboot.module.iot.service.ICollectDataService;
import com.iteaj.iboot.module.iot.service.IDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -33,8 +33,9 @@ public class CollectTaskController extends BaseController {
private final CollectTaskListenerService collectTaskListenerService;
private final ICollectTaskService collectTaskService;
private final StoreActionFactory storeActionFactory;
public CollectTaskController(@Autowired(required = false) CollectTaskListenerService collectTaskListenerService
, ICollectTaskService collectTaskService, StoreActionFactory storeActionFactory) {
, ICollectTaskService collectTaskService, StoreActionFactory storeActionFactory) {
this.collectTaskListenerService = collectTaskListenerService;
this.collectTaskService = collectTaskService;
this.storeActionFactory = storeActionFactory;
@@ -144,21 +144,21 @@ public class DeviceController extends BaseController {
}
DeviceDto entity = deviceService.detailById(device.getId())
.ifNotPresentThrow("设备不存在["+device.getDeviceSn()+"]")
.ifNotPresentThrow("设备不存在[" + device.getDeviceSn() + "]")
.getData();
this.productService.getById(entity.getProductId()).ifNotPresentThrow("产品不存在")
.ifPresent(product -> {
if(product.getStatus() == FuncStatus.disabled) {
throw new ServiceException("请先启用产品["+product.getName()+"]");
}
if(product.getStatus() == FuncStatus.disabled) {
throw new ServiceException("请先启用产品[" + product.getName() + "]");
}
});
try {
FuncStatus funcStatus = status == DeviceStatus.online ? FuncStatus.enabled : FuncStatus.disabled;
Object networkCtrl = IotNetworkUtil.networkCtrl(entity.getProtocolCode(), entity, funcStatus);
if(networkCtrl instanceof ChannelFuture) {
((ChannelFuture) networkCtrl).get(10, TimeUnit.SECONDS);
if(networkCtrl instanceof ChannelFuture future) {
future.get(10, TimeUnit.SECONDS);
}
} catch (Throwable e) {
e.printStackTrace();
@@ -44,9 +44,10 @@ public class DeviceCtrlController extends BaseController {
private final IProductService productService;
private final IModelApiService modelApiService;
private final RealtimePushListener realtimeListener;
public DeviceCtrlController(IDeviceService deviceService
, IProductService productService, IModelApiService modelApiService
, IotCacheManager cacheManager, RealtimePushListener realtimeListener) {
, IProductService productService, IModelApiService modelApiService
, IotCacheManager cacheManager, RealtimePushListener realtimeListener) {
this.deviceService = deviceService;
this.productService = productService;
this.modelApiService = modelApiService;
@@ -71,11 +72,13 @@ public class DeviceCtrlController extends BaseController {
RealtimeStatus realtimeStatus = cacheManager.get(supplier.getProtocol().getCode(), param.buildKey());
if(realtimeStatus.getStatus() == DeviceStatus.offline) {
if(realtimeStatus.getType() == DeviceType.Direct) {
item.success(InvokeResult.fail("设备不在线["+realtimeStatus.getDeviceName()+"]", null)); return;
item.success(InvokeResult.fail("设备不在线[" + realtimeStatus.getDeviceName() + "]", null));
return;
} else if(realtimeStatus.getType() == DeviceType.Child) {
RealtimeStatus parent = cacheManager.get(supplier.getProtocol().getCode(), param.getParentDeviceSn());
if(parent != null && parent.getStatus() == DeviceStatus.offline) {
item.success(InvokeResult.fail("网关设备不在线["+parent.getDeviceName()+"]", null)); return;
item.success(InvokeResult.fail("网关设备不在线[" + parent.getDeviceName() + "]", null));
return;
}
}
}
@@ -148,7 +151,7 @@ public class DeviceCtrlController extends BaseController {
.ifNotPresentThrow("未找到所属产品").getData();
if(product.getStatus() == FuncStatus.disabled) {
throw new ServiceException("请先启用产品["+product.getName()+"]");
throw new ServiceException("请先启用产品[" + product.getName() + "]");
}
Device device = deviceService.getByUid(param.getUid())
@@ -175,7 +178,7 @@ public class DeviceCtrlController extends BaseController {
// 查找对应的协议接口
AbstractProtocolModelApi protocolModelApi = protocolSupplier.getProtocol().getApi(modelApi.getDirect());
if(protocolModelApi == null) {
throw new ServiceException("没有找到接口[apiCode="+modelApi.getDirect()+"]");
throw new ServiceException("没有找到接口[apiCode=" + modelApi.getDirect() + "]");
}
// 设置父网关设备配置
@@ -35,8 +35,8 @@ public class DeviceDebugController extends BaseController {
private final IProductTypeService productTypeService;
public DeviceDebugController(IDeviceService deviceService
, IProductService productService, IModelApiService modelApiService
, IProductTypeService productTypeService) {
, IProductService productService, IModelApiService modelApiService
, IProductTypeService productTypeService) {
this.deviceService = deviceService;
this.productService = productService;
this.modelApiService = modelApiService;
@@ -110,17 +110,17 @@ public class DeviceDebugController extends BaseController {
public Result<DebugDto> detail(Long deviceId) {
DebugDto debugDto = new DebugDto();
deviceService.detailById(deviceId)
.ifNotPresentThrow("设备不存在").of().ifPresent(item -> {
debugDto.setDevice(item);
.ifNotPresentThrow("设备不存在").of().ifPresent(item -> {
debugDto.setDevice(item);
productService.debugById(item.getProductId())
.ifNotPresentThrow("此设备数据不完整["+item.getName()+"]")
.ifPresent(productDto -> {
debugDto.setProduct(productDto);
if(!CollectionUtils.isEmpty(productDto.getFuncApis())) {
productDto.getFuncApis().forEach(api -> debugDto.addApiDebugParam(api.getCode(), api.resolveDownApiConfig(productDto.getAttrs())));
}
productDto.setAttrs(null);
});
.ifNotPresentThrow("此设备数据不完整[" + item.getName() + "]")
.ifPresent(productDto -> {
debugDto.setProduct(productDto);
if(!CollectionUtils.isEmpty(productDto.getFuncApis())) {
productDto.getFuncApis().forEach(api -> debugDto.addApiDebugParam(api.getCode(), api.resolveDownApiConfig(productDto.getAttrs())));
}
productDto.setAttrs(null);
});
});
return success(debugDto);
@@ -35,7 +35,7 @@ public class DeviceGroupController extends BaseController {
private final IDeviceGroupService deviceGroupService;
public DeviceGroupController(IModelApiService modelApiService
, IDeviceGroupService deviceGroupService) {
, IDeviceGroupService deviceGroupService) {
this.modelApiService = modelApiService;
this.deviceGroupService = deviceGroupService;
}
@@ -40,7 +40,7 @@ public class EMapController extends BaseController {
private final RealtimeDataService realtimeDataService;
public EMapController(IDeviceService deviceService, IProductService productService
, RealtimeDataService realtimeDataService) {
, RealtimeDataService realtimeDataService) {
this.deviceService = deviceService;
this.productService = productService;
this.realtimeDataService = realtimeDataService;
@@ -68,71 +68,71 @@ public class EMapController extends BaseController {
EMapDetailDto detailDto = new EMapDetailDto();
deviceService.getByUid(uid).ifNotPresentThrow("设备不存在").ifPresent(item -> {
productService.joinDetailById(item.getProductId())
.ifNotPresentThrow("此设备数据不完整["+item.getName()+"]")
.ifPresent(productDto -> {
.ifNotPresentThrow("此设备数据不完整[" + item.getName() + "]")
.ifPresent(productDto -> {
if(!CollectionUtils.isEmpty(productDto.getFuncApis())) {
// 过滤出被动的功能接口
List<ModelApi> modelApis = productDto.getFuncApis().stream()
.filter(api -> api.getTriggerMode() == TriggerMode.passive && api.getFuncType() != FuncType.R)
.collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(modelApis)) {
detailDto.setFuncApis(modelApis);
modelApis.forEach(api -> detailDto.addApiDebugParam(api.getCode(), api.resolveDownApiConfig(productDto.getAttrs())));
modelApis.removeIf(api -> {
if(Boolean.TRUE.equals(api.getAsStatus())) {
detailDto.setCtrlApi(api);
return true;
}
if(!CollectionUtils.isEmpty(productDto.getFuncApis())) {
// 过滤出被动的功能接口
List<ModelApi> modelApis = productDto.getFuncApis().stream()
.filter(api -> api.getTriggerMode() == TriggerMode.passive && api.getFuncType() != FuncType.R)
.collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(modelApis)) {
detailDto.setFuncApis(modelApis);
modelApis.forEach(api -> detailDto.addApiDebugParam(api.getCode(), api.resolveDownApiConfig(productDto.getAttrs())));
modelApis.removeIf(api -> {
if(Boolean.TRUE.equals(api.getAsStatus())) {
detailDto.setCtrlApi(api);
return true;
}
return false;
});
return false;
});
}
}
}
Map<String, RealtimeData> realtimeDataMap = realtimeDataService.listOfDevice(productDto.getProtocolCode()
, DeviceKey.build(item.getDeviceSn(), item.getParentDeviceSn()));
if(CollectionUtil.isNotEmpty(productDto.getAttrs())) {
productDto.getAttrs().stream().filter(attr -> (attr.getAttrType() != AttrType.W
&& !DataType.t_json.getValue().equals(attr.getDataType())))
.forEach(attr -> {
boolean isCtrlAttr = false;
if(attr.getAttrType() != AttrType.R) { // 写或者读写
if(Boolean.TRUE.equals(attr.getCtrlStatus())) {
isCtrlAttr = true;
ModelApi ctrlApi = detailDto.getCtrlApi();
if(ctrlApi != null) {
List<ModelApiConfig> downConfig = ctrlApi.getDownConfig();
if(CollectionUtil.isNotEmpty(downConfig)) {
downConfig.forEach(config -> {
if(config.getModelAttrId() != null && config.getModelAttrId() == attr.getId()
&& CollectionUtil.isNotEmpty(config.getDicts())) {
config.getDicts().forEach(dict -> detailDto.addCtrlAttr(dict.getDictName(), dict.getDictValue()));
Map<String, RealtimeData> realtimeDataMap = realtimeDataService.listOfDevice(productDto.getProtocolCode()
, DeviceKey.build(item.getDeviceSn(), item.getParentDeviceSn()));
if(CollectionUtil.isNotEmpty(productDto.getAttrs())) {
productDto.getAttrs().stream().filter(attr -> (attr.getAttrType() != AttrType.W
&& !DataType.t_json.getValue().equals(attr.getDataType())))
.forEach(attr -> {
boolean isCtrlAttr = false;
if(attr.getAttrType() != AttrType.R) { // 写或者读写
if(Boolean.TRUE.equals(attr.getCtrlStatus())) {
isCtrlAttr = true;
ModelApi ctrlApi = detailDto.getCtrlApi();
if(ctrlApi != null) {
List<ModelApiConfig> downConfig = ctrlApi.getDownConfig();
if(CollectionUtil.isNotEmpty(downConfig)) {
downConfig.forEach(config -> {
if(config.getModelAttrId() != null && config.getModelAttrId() == attr.getId()
&& CollectionUtil.isNotEmpty(config.getDicts())) {
config.getDicts().forEach(dict -> detailDto.addCtrlAttr(dict.getDictName(), dict.getDictValue()));
}
});
}
});
}
}
}
}
}
if(realtimeDataMap != null) {
RealtimeData realtimeData = realtimeDataMap.get(attr.getField());
if(realtimeData != null && realtimeData.getRealtime() != null) {
SignalOrFieldValue realtime = realtimeData.getRealtime();
detailDto.addAttr(attr.getField(), attr.getName(), attr.getUnit()
if(realtimeDataMap != null) {
RealtimeData realtimeData = realtimeDataMap.get(attr.getField());
if(realtimeData != null && realtimeData.getRealtime() != null) {
SignalOrFieldValue realtime = realtimeData.getRealtime();
detailDto.addAttr(attr.getField(), attr.getName(), attr.getUnit()
, realtime.getValue(), realtime.getCollectTime(), realtime.getStatus());
if(isCtrlAttr && realtime.getValue() != null) {
detailDto.setCtrlAttrValue(realtime.getValue().toString());
if(isCtrlAttr && realtime.getValue() != null) {
detailDto.setCtrlAttrValue(realtime.getValue().toString());
}
return;
}
}
return;
}
}
detailDto.addAttr(attr.getField(), attr.getName(), attr.getUnit());
});
}
});
detailDto.addAttr(attr.getField(), attr.getName(), attr.getUnit());
});
}
});
});
return success(detailDto);
@@ -32,8 +32,9 @@ public class EventSourceController extends BaseController {
private final IDeviceGroupService deviceGroupService;
private final IEventSourceService eventSourceService;
private final EventSourceCollectService eventSourceCollectService;
public EventSourceController(IDeviceGroupService deviceGroupService
, IEventSourceService eventSourceService, EventSourceCollectService eventSourceCollectService) {
, IEventSourceService eventSourceService, EventSourceCollectService eventSourceCollectService) {
this.deviceGroupService = deviceGroupService;
this.eventSourceService = eventSourceService;
this.eventSourceCollectService = eventSourceCollectService;
@@ -126,7 +126,7 @@ public class GatewayController extends BaseController {
@Logger("切换网关状态")
@PostMapping("switch/{id}/{status}")
@CheckPermission({"iot:gateway:switch"})
public Result<Boolean> switchStatus(@PathVariable Long id, @PathVariable GatewayStatus status) {
public Result<Boolean> switchStatus(@PathVariable Long id, @PathVariable GatewayStatus status) {
this.gatewayService.switchStatus(id, status);
return success(true);
}
@@ -27,8 +27,8 @@ public class IotIndexController extends BaseController {
private final RealtimeCollectDataService collectDataService;
public IotIndexController(IDeviceService deviceService, IProductService productService
, IProtocolService protocolService, RealtimeCollectDataService collectDataService
, IEventSourceService eventSourceService) {
, IProtocolService protocolService, RealtimeCollectDataService collectDataService
, IEventSourceService eventSourceService) {
this.deviceService = deviceService;
this.productService = productService;
this.protocolService = protocolService;
@@ -52,8 +52,8 @@ public class PanelsController extends BaseController {
private final RealtimeDataService realtimeDataService;
public PanelsController(ISignalService signalService, IDeviceService deviceService
, IProductService productService, IotCacheManager cacheManager
, RealtimeDataService realtimeDataService) {
, IProductService productService, IotCacheManager cacheManager
, RealtimeDataService realtimeDataService) {
this.signalService = signalService;
this.deviceService = deviceService;
this.productService = productService;
@@ -105,7 +105,7 @@ public class PanelsController extends BaseController {
}
if(CollectionUtil.isNotEmpty(attr.getDicts()) && !DataType.t_json.getValue().equals(attr.getDataType())) {
attr.getDicts().forEach(dict -> attrDictMap.put(attr.getField()+"_"+dict.getDictValue(), dict.getDictName()));
attr.getDicts().forEach(dict -> attrDictMap.put(attr.getField() + "_" + dict.getDictValue(), dict.getDictName()));
}
});
@@ -132,7 +132,7 @@ public class PanelsController extends BaseController {
copyAttrValues.forEach(attrValue -> {
String protocolCode = productProtocolMap.get(deviceDto.getProductId());
Map<String, RealtimeData> realtimeDataMap = realtimeDataService.listOfDevice(protocolCode
, DeviceKey.build(deviceDto.getDeviceSn(), deviceDto.getParentDeviceSn()));
, DeviceKey.build(deviceDto.getDeviceSn(), deviceDto.getParentDeviceSn()));
if(CollectionUtil.isNotEmpty(realtimeDataMap)) {
// 设置各属性的实时值
@@ -178,7 +178,7 @@ public class PanelsController extends BaseController {
.ifNotPresentThrow("设备不存在").of().ifPresent(item -> {
debugDto.setDevice(item);
productService.joinDetailById(item.getProductId())
.ifNotPresentThrow("此设备数据不完整["+item.getName()+"]")
.ifNotPresentThrow("此设备数据不完整[" + item.getName() + "]")
.ifPresent(productDto -> {
debugDto.setProduct(productDto);
if(!CollectionUtils.isEmpty(productDto.getFuncApis())) {
@@ -201,23 +201,23 @@ public class PanelsController extends BaseController {
productDto.setEventApis(modelApis);
}
Map<String, RealtimeData> realtimeDataMap = realtimeDataService.listOfDevice(productDto.getProtocolCode()
, DeviceKey.build(item.getDeviceSn(), item.getParentDeviceSn()));
, DeviceKey.build(item.getDeviceSn(), item.getParentDeviceSn()));
if(CollectionUtil.isNotEmpty(productDto.getAttrs())) {
productDto.getAttrs().stream().filter(attr -> (attr.getAttrType() != AttrType.W
&& !DataType.t_json.getValue().equals(attr.getDataType())))
.forEach(attr -> {
if(realtimeDataMap != null) {
RealtimeData realtimeData = realtimeDataMap.get(attr.getField());
if(realtimeData != null && realtimeData.getRealtime() != null) {
SignalOrFieldValue realtime = realtimeData.getRealtime();
debugDto.addAttr(attr.getField(), attr.getName(), attr.getUnit(), attr.getAttrType()
, realtime.getValue(), realtime.getCollectTime(), realtime.getStatus());
return;
.forEach(attr -> {
if(realtimeDataMap != null) {
RealtimeData realtimeData = realtimeDataMap.get(attr.getField());
if(realtimeData != null && realtimeData.getRealtime() != null) {
SignalOrFieldValue realtime = realtimeData.getRealtime();
debugDto.addAttr(attr.getField(), attr.getName(), attr.getUnit(), attr.getAttrType()
, realtime.getValue(), realtime.getCollectTime(), realtime.getStatus());
return;
}
}
}
debugDto.addAttr(attr.getField(), attr.getName(), attr.getUnit(), attr.getAttrType());
});
debugDto.addAttr(attr.getField(), attr.getName(), attr.getUnit(), attr.getAttrType());
});
}
productDto.setAttrs(null);
@@ -230,7 +230,7 @@ public class PanelsController extends BaseController {
if(realtimeData != null && realtimeData.getRealtime() != null) {
SignalOrFieldValue realtime = realtimeData.getRealtime();
debugDto.addSignal(signal.getName(), signal.getAddress(), realtime.getValue()
, realtime.getCollectTime(), realtime.getStatus());
, realtime.getCollectTime(), realtime.getStatus());
return;
}
}
@@ -253,62 +253,62 @@ public class PanelsController extends BaseController {
this.deviceService.getByUid(dto.getId().toString())
.ifNotPresentThrow("设备不存在")
.ifPresent(item -> {
this.productService.getCtrlStatusModelApi(item.getProductId())
.ifNotPresentThrow("此设备绑定的产品有误").ifPresent(productDto -> {
if(CollectionUtil.isEmpty(productDto.getFuncApis())) {
throw new ServiceException("此产品["+productDto.getName()+"]没有指定状态接口");
}
if(productDto.getStatus() == FuncStatus.disabled) {
throw new ServiceException("请先启用产品["+productDto.getName()+"]");
}
ModelApi modelApi = productDto.getFuncApis().get(0);
DeviceKey deviceKey = DeviceKey.build(item.getDeviceSn(), item.getParentDeviceSn());
RealtimeStatus realtimeStatus = cacheManager.get(productDto.getProtocolCode(), deviceKey);
if(CollectionUtil.isEmpty(productDto.getAttrs())) {
throw new ServiceException("此产品["+productDto.getName()+"]没有模型属性");
}
ModelAttr ctrlStatusAttr = productDto.getAttrs().stream()
.filter(attr -> Boolean.TRUE.equals(attr.getCtrlStatus()))
.findFirst().orElse(null);
if(ctrlStatusAttr == null) {
throw new ServiceException("此产品["+productDto.getName()+"]没有设置控制属性");
}
JSONObject jsonObject = new JSONObject();
ProtocolModelApiInvokeParam invokeParam = new ProtocolModelApiInvokeParam(realtimeStatus.getUid(), jsonObject);
if(CollectionUtil.isNotEmpty(modelApi.getDownConfig())) {
modelApi.getDownConfig().forEach(config -> {
if(config.getModelAttrId() != null) {
// 控制属性
if(ctrlStatusAttr.getField().equals(config.getAttrField())) {
jsonObject.put(config.getProtocolAttrField(), dto.getStatus());
} else {
jsonObject.put(config.getProtocolAttrField(), config.getAttrDefaultValue());
}
} else {
jsonObject.put(config.getProtocolAttrField(), config.getValue());
this.productService.getCtrlStatusModelApi(item.getProductId())
.ifNotPresentThrow("此设备绑定的产品有误").ifPresent(productDto -> {
if(CollectionUtil.isEmpty(productDto.getFuncApis())) {
throw new ServiceException("此产品[" + productDto.getName() + "]没有指定状态接口");
}
});
}
ProtocolInvokeUtil.invoke(modelApi, invokeParam, realtimeStatus, (result) -> {
if(result.getStatus() != ExecStatus.success) {
throw new ServiceException("调用设备失败["+result.getReason()+"]");
} else {
// 将实时值更新为下发的值
realtimeDataService.put(realtimeStatus.getProtocolCode(), deviceKey
if(productDto.getStatus() == FuncStatus.disabled) {
throw new ServiceException("请先启用产品[" + productDto.getName() + "]");
}
ModelApi modelApi = productDto.getFuncApis().get(0);
DeviceKey deviceKey = DeviceKey.build(item.getDeviceSn(), item.getParentDeviceSn());
RealtimeStatus realtimeStatus = cacheManager.get(productDto.getProtocolCode(), deviceKey);
if(CollectionUtil.isEmpty(productDto.getAttrs())) {
throw new ServiceException("此产品[" + productDto.getName() + "]没有模型属性");
}
ModelAttr ctrlStatusAttr = productDto.getAttrs().stream()
.filter(attr -> Boolean.TRUE.equals(attr.getCtrlStatus()))
.findFirst().orElse(null);
if(ctrlStatusAttr == null) {
throw new ServiceException("此产品[" + productDto.getName() + "]没有设置控制属性");
}
JSONObject jsonObject = new JSONObject();
ProtocolModelApiInvokeParam invokeParam = new ProtocolModelApiInvokeParam(realtimeStatus.getUid(), jsonObject);
if(CollectionUtil.isNotEmpty(modelApi.getDownConfig())) {
modelApi.getDownConfig().forEach(config -> {
if(config.getModelAttrId() != null) {
// 控制属性
if(ctrlStatusAttr.getField().equals(config.getAttrField())) {
jsonObject.put(config.getProtocolAttrField(), dto.getStatus());
} else {
jsonObject.put(config.getProtocolAttrField(), config.getAttrDefaultValue());
}
} else {
jsonObject.put(config.getProtocolAttrField(), config.getValue());
}
});
}
ProtocolInvokeUtil.invoke(modelApi, invokeParam, realtimeStatus, (result) -> {
if(result.getStatus() != ExecStatus.success) {
throw new ServiceException("调用设备失败[" + result.getReason() + "]");
} else {
// 将实时值更新为下发的值
realtimeDataService.put(realtimeStatus.getProtocolCode(), deviceKey
, SignalOrFieldValue.build(ctrlStatusAttr.getId(), ctrlStatusAttr.getField(), dto.getStatus()));
// 触发状态更新
DeviceStatusModelApiManager.getInstance().trigger(realtimeStatus.getProductCode(), realtimeStatus.getUid());
}
// 触发状态更新
DeviceStatusModelApiManager.getInstance().trigger(realtimeStatus.getProductCode(), realtimeStatus.getUid());
}
});
});
});
});
});
return success();
}
@@ -151,7 +151,7 @@ public class ProductController extends BaseController {
@Logger("切换产品状态")
@PostMapping("switch/{id}/{status}")
@CheckPermission({"iot:gateway:switch"})
public Result<Boolean> switchStatus(@PathVariable Long id, @PathVariable FuncStatus status) {
public Result<Boolean> switchStatus(@PathVariable Long id, @PathVariable FuncStatus status) {
this.productService.switchStatus(id, status);
return success(true);
}
@@ -122,7 +122,7 @@ public class ProtocolController extends BaseController {
public Result<Protocol> loadProtocol(MultipartFile file) throws IOException {
// 先上传到临时文件
UploadResult protocol = uploadService.upload(file.getInputStream()
, file.getOriginalFilename(), file.getOriginalFilename(), ProtocolSupplierManager.PROTOCOL_JAR_TEMP_DIR);
, file.getOriginalFilename(), file.getOriginalFilename(), ProtocolSupplierManager.PROTOCOL_JAR_TEMP_DIR);
List<DeviceProtocolSupplier> load = ProtocolSupplierManager.loadFromTempProtocol(protocol.getFileName());
if(load.size() > 1) {
@@ -186,9 +186,9 @@ public class ProtocolController extends BaseController {
@GetMapping("apis")
public Result<List<ProtocolApi>> apis(Long id, ProtocolApiType type) {
List<ProtocolApi> protocolApis = this.protocolService.getByDetail(id).ofNullable().map(item -> {
if (type == ProtocolApiType.func) {
if(type == ProtocolApiType.func) {
return item.getFuncApis();
} else if (type == ProtocolApiType.event) {
} else if(type == ProtocolApiType.event) {
return item.getEventApis();
} else {
ArrayList<ProtocolApi> list = new ArrayList<>();
@@ -222,7 +222,7 @@ public class ProtocolController extends BaseController {
internals.forEach(item -> {
Protocol protocol = protocolMap.get(item.getProtocol().getCode());
if (protocol == null) {
if(protocol == null) {
ProtocolDto protocolDto = protocolService.loadProtocol(item);
protocol = new Protocol();
BeanUtils.copyProperties(protocolDto, protocol);
@@ -267,7 +267,7 @@ public class ProtocolController extends BaseController {
DeviceProtocolSupplier supplier = ProtocolSupplierManager.get(protocolCode);
if(supplier == null) {
return fail("找不到协议[protocolCode="+protocolCode+"]");
return fail("找不到协议[protocolCode=" + protocolCode + "]");
}
if(type.equals("network")) {
@@ -277,7 +277,7 @@ public class ProtocolController extends BaseController {
} else if(type.equals("child")) {
return success(supplier.getDeviceConfig());
} else {
return fail("不支持的类型[type="+type+"]");
return fail("不支持的类型[type=" + type + "]");
}
}
@@ -95,7 +95,7 @@ public class RealtimeDataController extends BaseController {
public Result<RealtimeData> getByEventOrSignalField(Long deviceId, String signalOrField) {
DeviceDto device = deviceService.detailById(deviceId).ifNotPresentThrow("设备不存在").getData();
RealtimeData realtimeData = realtimeDataService.getOfDeviceAndKey(device.getProductCode()
, DeviceKey.build(device.getDeviceSn(), device.getDeviceSn()), signalOrField);
, DeviceKey.build(device.getDeviceSn(), device.getDeviceSn()), signalOrField);
return success(realtimeData);
}
}
@@ -23,7 +23,6 @@ import com.iteaj.iot.client.ClientConnectProperties;
import com.iteaj.iot.client.SocketClient;
import com.iteaj.iot.modbus.client.tcp.ModbusTcpClientComponent;
import com.iteaj.framework.security.CheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -45,7 +44,7 @@ public class DeviceModbusController extends BaseController {
private final static String[] modbusCodes = {ProtocolCodes.MODBUS_RTU.getValue(), ProtocolCodes.MODBUS_TCP.getValue()};
public DeviceModbusController(ISerialService serialService, IDeviceService deviceService
, IProductService productService) {
, IProductService productService) {
this.serialService = serialService;
this.deviceService = deviceService;
this.productService = productService;
@@ -90,12 +89,12 @@ public class DeviceModbusController extends BaseController {
Device device = this.deviceService.getOne(Wrappers.<Device>lambdaQuery()
.eq(Device::getProductId, entity.getProductId())
.orderByDesc(Device::getDeviceSn).last("limit 1")).getData();
if (device != null) {
if(device != null) {
String[] number = device.getDeviceSn().split("_");
Integer idValue = Integer.valueOf(number[number.length - 1]);
deviceSn = String.format("gwd_%s_%d_%04d", deviceSn.toLowerCase(), entity.getProductId(), (idValue + 1));
deviceSn = "gwd_%s_%d_%04d".formatted(deviceSn.toLowerCase(), entity.getProductId(), (idValue + 1));
} else {
deviceSn = "gwd_"+deviceSn.toLowerCase()+"_" + entity.getProductId() + "_0001";
deviceSn = "gwd_" + deviceSn.toLowerCase() + "_" + entity.getProductId() + "_0001";
}
entity.setDeviceSn(deviceSn);
@@ -34,7 +34,7 @@ public class DeviceMqttController extends BaseController {
private final IProductService productService;
public DeviceMqttController(IDeviceService deviceService
, IProductService productService) {
, IProductService productService) {
this.deviceService = deviceService;
this.productService = productService;
}
@@ -76,10 +76,10 @@ public class DeviceMqttController extends BaseController {
Device device = this.deviceService.getOne(Wrappers.<Device>lambdaQuery()
.eq(Device::getProductId, entity.getProductId())
.orderByDesc(Device::getDeviceSn).last("limit 1")).getData();
if (device != null) {
if(device != null) {
String[] number = device.getDeviceSn().split("_");
Integer idValue = Integer.valueOf(number[number.length - 1]);
deviceSn = String.format("gwd_mqtt_%d_%04d", entity.getProductId(), (idValue + 1));
deviceSn = "gwd_mqtt_%d_%04d".formatted(entity.getProductId(), (idValue + 1));
} else {
deviceSn = "gwd_mqtt_" + entity.getProductId() + "_0001";
}
@@ -74,12 +74,12 @@ public class DevicePlcController extends BaseController {
Device device = this.deviceService.getOne(Wrappers.<Device>lambdaQuery()
.eq(Device::getProductId, entity.getProductId())
.orderByDesc(Device::getDeviceSn).last("limit 1")).getData();
if (device != null) {
if(device != null) {
String[] number = device.getDeviceSn().split("_");
Integer idValue = Integer.valueOf(number[number.length - 1]);
deviceSn = String.format("gwd_%s_%d_%04d", deviceSn.toLowerCase(), entity.getProductId(), (idValue + 1));
deviceSn = "gwd_%s_%d_%04d".formatted(deviceSn.toLowerCase(), entity.getProductId(), (idValue + 1));
} else {
deviceSn = "gwd_"+deviceSn.toLowerCase()+"_" + entity.getProductId() + "_0001";
deviceSn = "gwd_" + deviceSn.toLowerCase() + "_" + entity.getProductId() + "_0001";
}
entity.setDeviceSn(deviceSn);
@@ -20,7 +20,8 @@ public interface DebugHandle<P extends DebugModel> {
default DebugRequestModel<P> parse(String model) {
Class<P> typeArgument = (Class<P>) GenericTypeResolver
.resolveTypeArguments(getClass(), DebugHandle.class)[0];
return JSON.parseObject(model, new TypeReference<DebugRequestModel<P>>(typeArgument){});
return JSON.parseObject(model, new TypeReference<DebugRequestModel<P>>(typeArgument){
});
}
/**
@@ -37,7 +37,8 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
public void handle(DtuDebugModel model, DebugWebsocketWrite write) {
String deviceSn = model.getDeviceSn();
if(!StringUtils.hasText(deviceSn)) {
write.write(HttpResult.Fail("未指定设备编号[deviceSn]")); return;
write.write(HttpResult.Fail("未指定设备编号[deviceSn]"));
return;
}
try {
@@ -52,7 +53,7 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
modbusRtuHandle(model, write); break;
case "cus": // 自定义协议
otherHandle(model, write); break;
default: write.write(HttpResult.Fail("不支持的协议类型["+protocolType+"]"));
default: write.write(HttpResult.Fail("不支持的协议类型[" + protocolType + "]"));
}
}
} catch (Exception e) {
@@ -63,12 +64,14 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
private void otherHandle(DtuDebugModel model, DebugWebsocketWrite write) {
String message = model.getMessage();
if(!StringUtils.hasText(message)) {
write.write(HttpResult.Fail("未指定要发送的报文")); return;
write.write(HttpResult.Fail("未指定要发送的报文"));
return;
}
String cmd = model.getCmd();
if(!StringUtils.hasText(cmd)) {
write.write(HttpResult.Fail("未指定操作指令")); return;
write.write(HttpResult.Fail("未指定操作指令"));
return;
}
try {
@@ -76,7 +79,8 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
try {
bytes = ByteUtil.hexToByte(message);
} catch (Exception e) {
write.write(HttpResult.Fail("只支持16进制报文格式")); return;
write.write(HttpResult.Fail("只支持16进制报文格式"));
return;
}
DebugResult result = new DebugResult(model)
@@ -92,7 +96,8 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
} else if("writeOfAsync".equals(cmd)) {
protocol.writeOfAsync(bytes);
} else {
write.write(HttpResult.Fail("只支持指令[read、write、writeOfAsync]")); return;
write.write(HttpResult.Fail("只支持指令[read、write、writeOfAsync]"));
return;
}
result.setRespTime(System.currentTimeMillis())
@@ -116,7 +121,8 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
byte[] bytes = ByteUtil.hexToByte(model.getMessage());
protocol = ModbusTcpForDtuCommonProtocol.build(model.getDeviceSn(), bytes, null);
} catch (Exception e) {
write.write(HttpResult.Fail("报文只支持十六进制格式")); return;
write.write(HttpResult.Fail("报文只支持十六进制格式"));
return;
}
} else {
if(!modbusValidate(model, write)) {
@@ -128,34 +134,35 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
switch (cmd) {
case "01":
protocol = ModbusTcpForDtuCommonProtocol.buildRead01(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "02":
protocol = ModbusTcpForDtuCommonProtocol.buildRead02(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "03":
protocol = ModbusTcpForDtuCommonProtocol.buildRead03(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "04":
protocol = ModbusTcpForDtuCommonProtocol.buildRead04(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "05":
Object writeValue = parseWriteValue(model);
if(writeValue == null) {
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]")); return;
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]"));
return;
}
protocol = ModbusTcpForDtuCommonProtocol.buildWrite05(model.getDeviceSn()
, address, model.getStart(), (ModbusCoilStatus) writeValue); break;
, address, model.getStart(), (ModbusCoilStatus) writeValue); break;
case "06":
protocol = ModbusTcpForDtuCommonProtocol.buildWrite06(model.getDeviceSn()
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
case "10":
byte[] writeBytes = (byte[]) parseWriteValue(model);
protocol = ModbusTcpForDtuCommonProtocol.buildWrite10(model.getDeviceSn()
, address, model.getStart(), writeBytes.length / 2, writeBytes); break;
, address, model.getStart(), writeBytes.length / 2, writeBytes); break;
case "0F":
protocol = ModbusTcpForDtuCommonProtocol.buildWrite0F(model.getDeviceSn()
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
default: write.write(HttpResult.Fail("不支持的指令["+cmd+"]"));
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
default: write.write(HttpResult.Fail("不支持的指令[" + cmd + "]"));
return;
}
}
@@ -165,15 +172,18 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
private boolean modbusValidate(DtuDebugModel model, DebugWebsocketWrite write) {
if(model.getStart() == null) {
write.write(HttpResult.Fail("未指定寄存器起始地址")); return false;
write.write(HttpResult.Fail("未指定寄存器起始地址"));
return false;
}
if(!StringUtils.hasText(model.getCmd())) {
write.write(HttpResult.Fail("未指定功能码指令")); return false;
write.write(HttpResult.Fail("未指定功能码指令"));
return false;
}
if(!StringUtils.hasText(model.getType())) {
write.write(HttpResult.Fail("未指定值类型")); return false;
write.write(HttpResult.Fail("未指定值类型"));
return false;
}
return true;
@@ -187,7 +197,8 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
byte[] bytes = ByteUtil.hexToByte(hexMsg);
protocol = ModbusRtuForDtuCommonProtocol.build(model.getDeviceSn(), bytes, null);
} catch (Exception e) {
write.write(HttpResult.Fail("报文只支持十六进制格式")); return;
write.write(HttpResult.Fail("报文只支持十六进制格式"));
return;
}
} else {
if(!modbusValidate(model, write)) {
@@ -199,34 +210,35 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
switch (cmd) {
case "01":
protocol = ModbusRtuForDtuCommonProtocol.buildRead01(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "02":
protocol = ModbusRtuForDtuCommonProtocol.buildRead02(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "03":
protocol = ModbusRtuForDtuCommonProtocol.buildRead03(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "04":
protocol = ModbusRtuForDtuCommonProtocol.buildRead04(model.getDeviceSn()
, address, model.getStart(), this.getTypeCoilNum(model)); break;
, address, model.getStart(), this.getTypeCoilNum(model)); break;
case "05":
Object writeValue = parseWriteValue(model);
if(writeValue == null) {
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]")); return;
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]"));
return;
}
protocol = ModbusRtuForDtuCommonProtocol.buildWrite05(model.getDeviceSn()
, address, model.getStart(), (ModbusCoilStatus) writeValue); break;
, address, model.getStart(), (ModbusCoilStatus) writeValue); break;
case "06":
protocol = ModbusRtuForDtuCommonProtocol.buildWrite06(model.getDeviceSn()
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
case "10":
byte[] writeBytes = (byte[]) parseWriteValue(model);
protocol = ModbusRtuForDtuCommonProtocol.buildWrite10(model.getDeviceSn()
, address, model.getStart(), writeBytes.length / 2, writeBytes); break;
, address, model.getStart(), writeBytes.length / 2, writeBytes); break;
case "0F":
protocol = ModbusRtuForDtuCommonProtocol.buildWrite0F(model.getDeviceSn()
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
default: write.write(HttpResult.Fail("不支持的指令["+cmd+"]"));
, address, model.getStart(), (byte[]) parseWriteValue(model)); break;
default: write.write(HttpResult.Fail("不支持的指令[" + cmd + "]"));
return;
}
}
@@ -254,9 +266,9 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
try {
return Integer.valueOf(writeValue);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("字符串的长度值["+writeValue+"]不支持");
throw new IllegalArgumentException("字符串的长度值[" + writeValue + "]不支持");
}
default: throw new IllegalArgumentException("不支持的值类型["+type+"]");
default: throw new IllegalArgumentException("不支持的值类型[" + type + "]");
}
}
@@ -284,15 +296,15 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
if(protocol.getExecStatus() == ExecStatus.success) {
Message.MessageBody body = serverMessage.getBody();
if(body instanceof ModbusRtuBody) {
if(!((ModbusRtuBody) body).isSuccess()) {
String reason = ((ModbusRtuBody) body).getErrCode().getDesc();
if(body instanceof ModbusRtuBody rtuBody) {
if(!rtuBody.isSuccess()) {
String reason = rtuBody.getErrCode().getDesc();
write.write(HttpResult.StatusCode(result, reason, 208));
return null;
}
} else if(body instanceof ModbusTcpBody) {
if(!((ModbusTcpBody) body).isSuccess()) {
String reason = ((ModbusTcpBody) body).getErrCode().getDesc();
} else if(body instanceof ModbusTcpBody tcpBody) {
if(!tcpBody.isSuccess()) {
String reason = tcpBody.getErrCode().getDesc();
write.write(HttpResult.StatusCode(result, reason, 208));
return null;
}
@@ -335,7 +347,7 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
case "string":
int length = Integer.valueOf(model.getWriteValue());
return payload.readString(model.getStart(), length);
default: throw new IllegalArgumentException("不支持的值类型["+type+"]");
default: throw new IllegalArgumentException("不支持的值类型[" + type + "]");
}
}
@@ -357,10 +369,10 @@ public class DtuDebugHandle implements DebugHandle<DtuDebugModel> {
model.getWriteValue().equals("1") ? ModbusCoilStatus.ON : null;
case "string":
return model.getWriteValue().getBytes(StandardCharsets.UTF_8);
default: throw new IllegalArgumentException("不支持的值类型["+type+"]");
default: throw new IllegalArgumentException("不支持的值类型[" + type + "]");
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException("值类型["+type+"]和值["+model.getWriteValue()+"]不匹配");
throw new IllegalArgumentException("值类型[" + type + "]和值[" + model.getWriteValue() + "]不匹配");
}
}
@@ -39,7 +39,8 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
public void handle(ModbusDebugModel model, DebugWebsocketWrite write) {
String deviceSn = model.getDeviceSn();
if(!StringUtils.hasText(deviceSn)) {
write.write(HttpResult.Fail("未指定设备编号[deviceSn]")); return;
write.write(HttpResult.Fail("未指定设备编号[deviceSn]"));
return;
}
try {
@@ -52,7 +53,7 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
modbusTcpHandle(model, write); break;
case "rtu": // modbus rtu
modbusRtuHandle(model, write); break;
default: write.write(HttpResult.Fail("不支持的协议类型["+protocolType+"]"));
default: write.write(HttpResult.Fail("不支持的协议类型[" + protocolType + "]"));
}
}
} catch (Exception e) {
@@ -72,7 +73,8 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
header.setMessage(bytes);
protocol = ModbusTcpClientCommonProtocol.build(header, empty);
} catch (Exception e) {
write.write(HttpResult.Fail("报文只支持十六进制格式")); return;
write.write(HttpResult.Fail("报文只支持十六进制格式"));
return;
}
} else {
if(!modbusValidate(model, write)) {
@@ -97,7 +99,8 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
case "05":
Object writeValue = parseWriteValue(model);
if(writeValue == null) {
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]")); return;
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]"));
return;
}
protocol = ModbusTcpClientCommonProtocol.buildWrite05(
address, model.getStart(), (ModbusCoilStatus) writeValue); break;
@@ -111,7 +114,7 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
case "0F":
protocol = ModbusTcpClientCommonProtocol.buildWrite0F(
address, model.getStart(), (byte[]) parseWriteValue(model)); break;
default: write.write(HttpResult.Fail("不支持的指令["+cmd+"]"));
default: write.write(HttpResult.Fail("不支持的指令[" + cmd + "]"));
return;
}
}
@@ -123,15 +126,18 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
private boolean modbusValidate(ModbusDebugModel model, DebugWebsocketWrite write) {
if(model.getStart() == null) {
write.write(HttpResult.Fail("未指定寄存器起始地址")); return false;
write.write(HttpResult.Fail("未指定寄存器起始地址"));
return false;
}
if(!StringUtils.hasText(model.getCmd())) {
write.write(HttpResult.Fail("未指定功能码指令")); return false;
write.write(HttpResult.Fail("未指定功能码指令"));
return false;
}
if(!StringUtils.hasText(model.getType())) {
write.write(HttpResult.Fail("未指定值类型")); return false;
write.write(HttpResult.Fail("未指定值类型"));
return false;
}
return true;
@@ -146,10 +152,12 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
byte[] bytes = ByteUtil.hexToByte(hexMsg);
protocol = ModbusRtuClientProtocol.build(bytes);
} catch (Exception e) {
write.write(HttpResult.Fail("报文只支持十六进制格式")); return;
write.write(HttpResult.Fail("报文只支持十六进制格式"));
return;
}
} catch (Exception e) {
write.write(HttpResult.Fail("报文只支持十六进制格式")); return;
write.write(HttpResult.Fail("报文只支持十六进制格式"));
return;
}
} else {
if(!modbusValidate(model, write)) {
@@ -157,7 +165,8 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
}
if(true) {
write.write(HttpResult.Fail("暂不支持modbus rtu调试")); return;
write.write(HttpResult.Fail("暂不支持modbus rtu调试"));
return;
}
String cmd = model.getCmd();
@@ -165,34 +174,35 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
switch (cmd) {
case "01":
protocol = ModbusRtuClientProtocol.buildRead01(address
, model.getStart(), this.getTypeCoilNum(model)); break;
, model.getStart(), this.getTypeCoilNum(model)); break;
case "02":
protocol = ModbusRtuClientProtocol.buildRead02(address
, model.getStart(), this.getTypeCoilNum(model)); break;
, model.getStart(), this.getTypeCoilNum(model)); break;
case "03":
protocol = ModbusRtuClientProtocol.buildRead03(address
, model.getStart(), this.getTypeCoilNum(model)); break;
, model.getStart(), this.getTypeCoilNum(model)); break;
case "04":
protocol = ModbusRtuClientProtocol.buildRead04(address
, model.getStart(), this.getTypeCoilNum(model)); break;
, model.getStart(), this.getTypeCoilNum(model)); break;
case "05":
Object writeValue = parseWriteValue(model);
if(writeValue == null) {
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]")); return;
write.write(HttpResult.Fail("写05功能码的值只能是[0 或 1]"));
return;
}
protocol = ModbusRtuClientProtocol.buildWrite05(address
, model.getStart(), (ModbusCoilStatus) writeValue); break;
, model.getStart(), (ModbusCoilStatus) writeValue); break;
case "06":
protocol = ModbusRtuClientProtocol.buildWrite06(address
, model.getStart(), (byte[]) parseWriteValue(model)); break;
, model.getStart(), (byte[]) parseWriteValue(model)); break;
case "10":
byte[] writeBytes = (byte[]) parseWriteValue(model);
protocol = ModbusRtuClientProtocol.buildWrite10(address
, model.getStart(), writeBytes.length / 2, writeBytes); break;
, model.getStart(), writeBytes.length / 2, writeBytes); break;
case "0F":
protocol = ModbusRtuClientProtocol.buildWrite0F(
address, model.getStart(), (byte[]) parseWriteValue(model)); break;
default: write.write(HttpResult.Fail("不支持的指令["+cmd+"]"));
default: write.write(HttpResult.Fail("不支持的指令[" + cmd + "]"));
return;
}
}
@@ -223,9 +233,9 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
try {
return Integer.valueOf(writeValue);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("字符串的长度值["+writeValue+"]不支持");
throw new IllegalArgumentException("字符串的长度值[" + writeValue + "]不支持");
}
default: throw new IllegalArgumentException("不支持的值类型["+type+"]");
default: throw new IllegalArgumentException("不支持的值类型[" + type + "]");
}
}
@@ -254,15 +264,15 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
if(protocol.getExecStatus() == ExecStatus.success) {
Message.MessageBody body = clientMessage.getBody();
if(body instanceof ModbusRtuBody) {
if(!((ModbusRtuBody) body).isSuccess()) {
String reason = ((ModbusRtuBody) body).getErrCode().getDesc();
if(body instanceof ModbusRtuBody rtuBody) {
if(!rtuBody.isSuccess()) {
String reason = rtuBody.getErrCode().getDesc();
write.write(HttpResult.StatusCode(result, reason, 208));
return null;
}
} else if(body instanceof ModbusTcpBody) {
if(!((ModbusTcpBody) body).isSuccess()) {
String reason = ((ModbusTcpBody) body).getErrCode().getDesc();
} else if(body instanceof ModbusTcpBody tcpBody) {
if(!tcpBody.isSuccess()) {
String reason = tcpBody.getErrCode().getDesc();
write.write(HttpResult.StatusCode(result, reason, 208));
return null;
}
@@ -302,7 +312,7 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
case "string":
int length = Integer.valueOf(model.getWriteValue());
return payload.readString(model.getStart(), length);
default: throw new IllegalArgumentException("不支持的值类型["+type+"]");
default: throw new IllegalArgumentException("不支持的值类型[" + type + "]");
}
}
@@ -324,10 +334,10 @@ public class ModbusDebugHandle implements DebugHandle<ModbusDebugModel> {
model.getWriteValue().equals("1") ? ModbusCoilStatus.ON : null;
case "string":
return model.getWriteValue().getBytes(StandardCharsets.UTF_8);
default: throw new IllegalArgumentException("不支持的值类型["+type+"]");
default: throw new IllegalArgumentException("不支持的值类型[" + type + "]");
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException("值类型["+type+"]和值["+model.getWriteValue()+"]不匹配");
throw new IllegalArgumentException("值类型[" + type + "]和值[" + model.getWriteValue() + "]不匹配");
}
}
@@ -30,16 +30,18 @@ public class MqttDebugHandle implements DebugHandle<MqttDebugModel> {
@Override
public void handle(MqttDebugModel model, DebugWebsocketWrite write) {
if(!StringUtils.hasText(model.getIp()) || model.getPort() == null) {
write.write(HttpResult.Fail("未指定mqtt设备的ip地址和端口")); return;
write.write(HttpResult.Fail("未指定mqtt设备的ip地址和端口"));
return;
}
DebugResult result = new DebugResult(model);
try{
try {
DefaultMqttConnectProperties properties = new DefaultMqttConnectProperties(model.getIp()
, model.getPort(), model.getDeviceSn(), null, null);
, model.getPort(), model.getDeviceSn(), null, null);
MqttClient client = defaultMqttComponent.getClient(properties);
if(client == null) {
write.write(HttpResult.Fail("客户端未连接")); return;
write.write(HttpResult.Fail("客户端未连接"));
return;
}
// 订阅
@@ -23,7 +23,8 @@ public class DebugProtocol extends ClientInitiativeProtocol<DebugServerMessage>
}
@Override
protected void doBuildRequestMessage(DebugServerMessage requestMessage) { }
protected void doBuildRequestMessage(DebugServerMessage requestMessage) {
}
@Override
public ProtocolType protocolType() {
@@ -46,7 +46,7 @@ public class WebsocketDebugListener implements WebSocketServerListener, WebSocke
DebugRequestModel parse = debugHandle.parse(protocol.readText());
iotTaskScheduler.execute(() -> debugHandle.handle(parse.getModel(), new DebugWebsocketWrite(parse.getClientSn())));
} else {
protocol.response(JSON.toJSONString(HttpResult.Fail("未找到对应的处理器["+type.get()+"]")));
protocol.response(JSON.toJSONString(HttpResult.Fail("未找到对应的处理器[" + type.get() + "]")));
}
} else {
protocol.response(JSON.toJSONString(HttpResult.Fail("未指定调试类型[type]")));
@@ -20,7 +20,8 @@ public class CountLastTimeDto {
*/
private Object value;
public CountLastTimeDto() { }
public CountLastTimeDto() {
}
public CountLastTimeDto(String time, Object value) {
this.time = time;
@@ -49,7 +49,8 @@ public class DebugRespDto {
*/
private ExecStatus status;
public DebugRespDto() { }
public DebugRespDto() {
}
public DebugRespDto(String deviceSn) {
this(deviceSn, System.currentTimeMillis());
@@ -67,7 +67,8 @@ public class DebugTree {
@JsonIgnore
private DebugTree parent;
public DebugTree() { }
public DebugTree() {
}
protected DebugTree(Long id, Long pid, String type, String name) {
this(id, pid, type, name, null);
@@ -84,7 +85,7 @@ public class DebugTree {
}
public static DebugTree buildProduct(Long id, Long pid, String name) {
return new DebugTree(id, pid, "product", name).setPkey("productType:"+pid).setIsLeaf(false);
return new DebugTree(id, pid, "product", name).setPkey("productType:" + pid).setIsLeaf(false);
}
public static DebugTree buildProductType(Long id, Long pid, String name) {
@@ -92,7 +93,7 @@ public class DebugTree {
}
public static DebugTree buildDevice(Long id, Long pid, String name, DeviceStatus status) {
return new DebugTree(id, pid, "device", name, status).setPkey("product:"+pid).setIsLeaf(true);
return new DebugTree(id, pid, "device", name, status).setPkey("product:" + pid).setIsLeaf(true);
}
public DebugTree addChildren(DebugTree tree) {
@@ -100,7 +100,7 @@ public class EMapDetailDto {
private CollectStatus status;
public ModelAttr(String field, String name, String unit, Object value
, Date collectTime, CollectStatus status) {
, Date collectTime, CollectStatus status) {
this.field = field;
this.name = name;
this.unit = unit;
@@ -48,11 +48,13 @@ public class PanelsDetailDto {
}
public PanelsDetailDto addSignal(String name, String address) {
this.signals.add(new Signal(name, "-", address, null, CollectStatus.Success)); return this;
this.signals.add(new Signal(name, "-", address, null, CollectStatus.Success));
return this;
}
public PanelsDetailDto addSignal(String name, String address, Object value, Date collectTime, CollectStatus status) {
this.signals.add(new Signal(name, value, address, collectTime, status)); return this;
this.signals.add(new Signal(name, value, address, collectTime, status));
return this;
}
@Getter
@@ -125,7 +127,7 @@ public class PanelsDetailDto {
private CollectStatus status;
public ModelAttr(String field, String name, String unit, Object value
, AttrType attrType, Date collectTime, CollectStatus status) {
, AttrType attrType, Date collectTime, CollectStatus status) {
this.field = field;
this.name = name;
this.unit = unit;
@@ -56,7 +56,8 @@ public class ProductTree {
*/
private List<ProductTree> children;
public ProductTree() { }
public ProductTree() {
}
protected ProductTree(Long id, Long pid, String type, String name) {
this(id, pid, type, name, null);
@@ -73,7 +74,7 @@ public class ProductTree {
}
public static ProductTree buildProduct(Long id, Long pid, String name) {
return new ProductTree(id, pid, "product", name).setPkey("productType:"+pid).setIsLeaf(true);
return new ProductTree(id, pid, "product", name).setPkey("productType:" + pid).setIsLeaf(true);
}
public static ProductTree buildProductType(Long id, Long pid, String name) {
@@ -117,7 +117,8 @@ public class CollectData extends BaseEntity implements RealtimeCollectData {
*/
private CollectStatus collectStatus;
public CollectData() { }
public CollectData() {
}
public CollectData(CollectMode collectMode) {
this.collectMode = collectMode.name();
@@ -6,7 +6,9 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;
import java.io.Serial;
import java.util.Date;
/**
@@ -22,6 +24,7 @@ import java.util.Date;
@TableName("iot_collect_task")
public class CollectTask extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -12,8 +12,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.util.Date;
/**
@@ -28,6 +30,7 @@ import java.util.Date;
@TableName("iot_device")
public class Device extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.iteaj.framework.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -23,6 +25,7 @@ import lombok.experimental.Accessors;
@TableName("iot_device_child")
public class DeviceChild extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -3,6 +3,8 @@ package com.iteaj.iboot.module.iot.entity;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.Date;
import java.util.List;
@@ -24,6 +26,7 @@ import lombok.experimental.Accessors;
@TableName("iot_device_group")
public class DeviceGroup extends TreeEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.TableField;
import com.iteaj.framework.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.Date;
import java.util.List;
@@ -28,6 +30,7 @@ import lombok.experimental.Accessors;
@TableName("iot_event_source")
public class EventSource extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -2,6 +2,8 @@ package com.iteaj.iboot.module.iot.entity;
import com.iteaj.framework.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -21,6 +23,7 @@ import lombok.experimental.Accessors;
@TableName("iot_event_source_detail")
public class EventSourceDetail extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -14,8 +14,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.util.Date;
/**
@@ -32,6 +34,7 @@ import java.util.Date;
@TableName("iot_gateway")
public class Gateway extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -18,7 +18,8 @@ public class GroupPoint extends BaseEntity {
*/
private Long groupId;
public GroupPoint() { }
public GroupPoint() {
}
public GroupPoint(Long signalId, Long groupId) {
this.signalId = signalId;
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iteaj.framework.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.util.*;
import java.util.stream.Collectors;
@@ -20,8 +21,8 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.util.CollectionUtils;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
/**
* <p>
@@ -37,6 +38,7 @@ import javax.validation.constraints.NotNull;
@TableName("iot_model_api")
public class ModelApi extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -182,7 +184,7 @@ public class ModelApi extends BaseEntity {
}
private void cartesianProductHelper(List<List<ModelAttrDict>> lists, int index, List<ModelAttrDict> current, List<List<ModelAttrDict>> result, Map<Long, ModelAttr> attrMap) {
if (index == lists.size()) {
if(index == lists.size()) {
result.add(new ArrayList<>(current));
return;
}
@@ -11,8 +11,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.util.Date;
import java.util.List;
@@ -30,6 +32,7 @@ import java.util.List;
@TableName("iot_model_api_config")
public class ModelApiConfig extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -12,8 +12,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.util.Date;
import java.util.List;
@@ -31,6 +33,7 @@ import java.util.List;
@TableName("iot_model_attr")
public class ModelAttr extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -8,8 +8,8 @@ import com.iteaj.framework.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
/**
* 物模型属性字典

Some files were not shown because too many files have changed in this diff Show More