mirror of
https://gitee.com/pnoker/iot-dc3.git
synced 2026-11-02 19:21:51 +08:00
refactor(common): rename NodeDto to TreeNode and clean up dto classes
This commit is contained in:
@@ -18,18 +18,18 @@ package com.dc3.common.base;
|
||||
*
|
||||
* @author pnoker
|
||||
*/
|
||||
public interface Converter<D,T> {
|
||||
public interface Converter<DO, DTO> {
|
||||
/**
|
||||
* DTO 转 DO
|
||||
*
|
||||
* @param d Do对象
|
||||
*/
|
||||
void convertToDo(D d);
|
||||
void convertDtoToDo(DO d);
|
||||
|
||||
/**
|
||||
* DO 转 DTO
|
||||
*
|
||||
* @param d Do对象
|
||||
*/
|
||||
T convert(D d);
|
||||
void convertDoToDto(DO d);
|
||||
}
|
||||
|
||||
+4
-6
@@ -11,7 +11,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.dc3.common.dto;
|
||||
package com.dc3.common.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -20,19 +20,17 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author pnoker
|
||||
*/
|
||||
@Data
|
||||
public class NodeDto implements Serializable {
|
||||
public class TreeNode implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected int id;
|
||||
protected int parentId;
|
||||
protected List<NodeDto> children = new ArrayList<>(16);
|
||||
protected List<TreeNode> children = new ArrayList<>(16);
|
||||
|
||||
public void add(NodeDto node) {
|
||||
public void add(TreeNode node) {
|
||||
children.add(node);
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,12 @@ public class BlackIpDto extends BlackIp implements Converter<BlackIp, BlackIpDto
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(BlackIp blackIp) {
|
||||
public void convertDtoToDo(BlackIp blackIp) {
|
||||
BeanUtils.copyProperties(this, blackIp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlackIpDto convert(BlackIp blackIp) {
|
||||
public void convertDoToDto(BlackIp blackIp) {
|
||||
BeanUtils.copyProperties(blackIp, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -38,13 +38,12 @@ public class DeviceDto extends Device implements Converter<Device, DeviceDto> {
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(Device device) {
|
||||
public void convertDtoToDo(Device device) {
|
||||
BeanUtils.copyProperties(this, device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceDto convert(Device device) {
|
||||
public void convertDoToDto(Device device) {
|
||||
BeanUtils.copyProperties(device, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
package com.dc3.common.dto;
|
||||
|
||||
import com.dc3.common.base.Converter;
|
||||
import com.dc3.common.bean.Pages;
|
||||
import com.dc3.common.model.DeviceEvent;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
@@ -33,7 +34,7 @@ import java.io.Serializable;
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
public class DeviceEventDto implements Serializable {
|
||||
public class DeviceEventDto implements Serializable, Converter<DeviceEvent, DeviceEventDto> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long deviceId;
|
||||
@@ -42,12 +43,11 @@ public class DeviceEventDto implements Serializable {
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Pages page;
|
||||
|
||||
public void convertToDo(DeviceEvent deviceEvent) {
|
||||
public void convertDtoToDo(DeviceEvent deviceEvent) {
|
||||
BeanUtils.copyProperties(this, deviceEvent);
|
||||
}
|
||||
|
||||
public DeviceEventDto convert(DeviceEvent deviceEvent) {
|
||||
public void convertDoToDto(DeviceEvent deviceEvent) {
|
||||
BeanUtils.copyProperties(deviceEvent, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,13 +38,12 @@ public class DriverAttributeDto extends DriverAttribute implements Converter<Dri
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(DriverAttribute info) {
|
||||
public void convertDtoToDo(DriverAttribute info) {
|
||||
BeanUtils.copyProperties(this, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverAttributeDto convert(DriverAttribute info) {
|
||||
public void convertDoToDto(DriverAttribute info) {
|
||||
BeanUtils.copyProperties(info, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,12 @@ public class DriverDto extends Driver implements Converter<Driver, DriverDto> {
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(Driver driver) {
|
||||
public void convertDtoToDo(Driver driver) {
|
||||
BeanUtils.copyProperties(this, driver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverDto convert(Driver driver) {
|
||||
public void convertDoToDto(Driver driver) {
|
||||
BeanUtils.copyProperties(driver, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,9 @@
|
||||
|
||||
package com.dc3.common.dto;
|
||||
|
||||
import com.dc3.common.base.Converter;
|
||||
import com.dc3.common.bean.Pages;
|
||||
import com.dc3.common.model.DeviceEvent;
|
||||
import com.dc3.common.model.DriverEvent;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -33,7 +34,7 @@ import java.io.Serializable;
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
public class DriverEventDto implements Serializable {
|
||||
public class DriverEventDto implements Serializable, Converter<DriverEvent, DriverEventDto> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String serviceName;
|
||||
@@ -41,12 +42,13 @@ public class DriverEventDto implements Serializable {
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Pages page;
|
||||
|
||||
public void convertToDo(DeviceEvent deviceEvent) {
|
||||
BeanUtils.copyProperties(this, deviceEvent);
|
||||
@Override
|
||||
public void convertDtoToDo(DriverEvent driverEvent) {
|
||||
BeanUtils.copyProperties(this, driverEvent);
|
||||
}
|
||||
|
||||
public DriverEventDto convert(DeviceEvent deviceEvent) {
|
||||
BeanUtils.copyProperties(deviceEvent, this);
|
||||
return this;
|
||||
@Override
|
||||
public void convertDoToDto(DriverEvent driverEvent) {
|
||||
BeanUtils.copyProperties(driverEvent, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,13 +38,12 @@ public class DriverInfoDto extends DriverInfo implements Converter<DriverInfo, D
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(DriverInfo info) {
|
||||
public void convertDtoToDo(DriverInfo info) {
|
||||
BeanUtils.copyProperties(this, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverInfoDto convert(DriverInfo info) {
|
||||
public void convertDoToDto(DriverInfo info) {
|
||||
BeanUtils.copyProperties(info, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,12 @@ public class GroupDto extends Group implements Converter<Group, GroupDto> {
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(Group group) {
|
||||
public void convertDtoToDo(Group group) {
|
||||
BeanUtils.copyProperties(this, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupDto convert(Group group) {
|
||||
public void convertDoToDto(Group group) {
|
||||
BeanUtils.copyProperties(group, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,12 @@ public class LabelBindDto extends LabelBind implements Converter<LabelBind, Labe
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(LabelBind bind) {
|
||||
public void convertDtoToDo(LabelBind bind) {
|
||||
BeanUtils.copyProperties(this, bind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelBindDto convert(LabelBind bind) {
|
||||
public void convertDoToDto(LabelBind bind) {
|
||||
BeanUtils.copyProperties(bind, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@
|
||||
|
||||
package com.dc3.common.dto;
|
||||
|
||||
import com.dc3.common.base.Converter;
|
||||
import com.dc3.common.bean.Pages;
|
||||
import com.dc3.common.model.Label;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.dc3.common.base.Converter;
|
||||
import lombok.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
@@ -36,13 +36,12 @@ public class LabelDto extends Label implements Converter<Label, LabelDto> {
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(Label label) {
|
||||
public void convertDtoToDo(Label label) {
|
||||
BeanUtils.copyProperties(this, label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelDto convert(Label label) {
|
||||
public void convertDoToDto(Label label) {
|
||||
BeanUtils.copyProperties(label, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@
|
||||
|
||||
package com.dc3.common.dto;
|
||||
|
||||
import com.dc3.common.base.Converter;
|
||||
import com.dc3.common.bean.Pages;
|
||||
import com.dc3.common.model.PointAttribute;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.dc3.common.base.Converter;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -38,13 +38,12 @@ public class PointAttributeDto extends PointAttribute implements Converter<Point
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(PointAttribute info) {
|
||||
public void convertDtoToDo(PointAttribute info) {
|
||||
BeanUtils.copyProperties(this, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointAttributeDto convert(PointAttribute info) {
|
||||
public void convertDoToDto(PointAttribute info) {
|
||||
BeanUtils.copyProperties(info, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@
|
||||
|
||||
package com.dc3.common.dto;
|
||||
|
||||
import com.dc3.common.base.Converter;
|
||||
import com.dc3.common.bean.Pages;
|
||||
import com.dc3.common.model.Point;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.dc3.common.base.Converter;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -38,13 +38,12 @@ public class PointDto extends Point implements Converter<Point, PointDto> {
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(Point point) {
|
||||
public void convertDtoToDo(Point point) {
|
||||
BeanUtils.copyProperties(this, point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointDto convert(Point point) {
|
||||
public void convertDoToDto(Point point) {
|
||||
BeanUtils.copyProperties(point, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -38,13 +38,12 @@ public class PointInfoDto extends PointInfo implements Converter<PointInfo, Poin
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(PointInfo info) {
|
||||
public void convertDtoToDo(PointInfo info) {
|
||||
BeanUtils.copyProperties(this, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointInfoDto convert(PointInfo info) {
|
||||
public void convertDoToDto(PointInfo info) {
|
||||
BeanUtils.copyProperties(info, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
package com.dc3.common.dto;
|
||||
|
||||
import com.dc3.common.base.Converter;
|
||||
import com.dc3.common.bean.Pages;
|
||||
import com.dc3.common.bean.point.PointValue;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
@@ -33,7 +34,7 @@ import java.io.Serializable;
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
public class PointValueDto implements Serializable {
|
||||
public class PointValueDto implements Serializable, Converter<PointValue, PointValueDto> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long deviceId;
|
||||
@@ -42,12 +43,13 @@ public class PointValueDto implements Serializable {
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Pages page;
|
||||
|
||||
public void convertToDo(PointValue pointValue) {
|
||||
@Override
|
||||
public void convertDtoToDo(PointValue pointValue) {
|
||||
BeanUtils.copyProperties(this, pointValue);
|
||||
}
|
||||
|
||||
public PointValueDto convert(PointValue pointValue) {
|
||||
@Override
|
||||
public void convertDoToDto(PointValue pointValue) {
|
||||
BeanUtils.copyProperties(pointValue, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,13 +36,12 @@ public class ProfileBindDto extends ProfileBind implements Converter<ProfileBind
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(ProfileBind bind) {
|
||||
public void convertDtoToDo(ProfileBind bind) {
|
||||
BeanUtils.copyProperties(this, bind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileBindDto convert(ProfileBind bind) {
|
||||
public void convertDoToDto(ProfileBind bind) {
|
||||
BeanUtils.copyProperties(bind, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -38,13 +38,12 @@ public class ProfileDto extends Profile implements Converter<Profile, ProfileDto
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(Profile profile) {
|
||||
public void convertDtoToDo(Profile profile) {
|
||||
BeanUtils.copyProperties(this, profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileDto convert(Profile profile) {
|
||||
public void convertDoToDto(Profile profile) {
|
||||
BeanUtils.copyProperties(profile, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -44,13 +44,12 @@ public class RtmpDto extends Rtmp implements Serializable, Converter<Rtmp, RtmpD
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertToDo(Rtmp rtmp) {
|
||||
public void convertDtoToDo(Rtmp rtmp) {
|
||||
BeanUtils.copyProperties(this, rtmp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RtmpDto convert(Rtmp rtmp) {
|
||||
public void convertDoToDto(Rtmp rtmp) {
|
||||
BeanUtils.copyProperties(rtmp, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,12 @@ public class TenantBindDto extends TenantBind implements Converter<TenantBind, T
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(TenantBind bind) {
|
||||
public void convertDtoToDo(TenantBind bind) {
|
||||
BeanUtils.copyProperties(this, bind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantBindDto convert(TenantBind bind) {
|
||||
public void convertDoToDto(TenantBind bind) {
|
||||
BeanUtils.copyProperties(bind, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -34,13 +34,12 @@ public class TenantDto extends Tenant implements Converter<Tenant, TenantDto> {
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(Tenant tenant) {
|
||||
public void convertDtoToDo(Tenant tenant) {
|
||||
BeanUtils.copyProperties(this, tenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantDto convert(Tenant tenant) {
|
||||
public void convertDoToDto(Tenant tenant) {
|
||||
BeanUtils.copyProperties(tenant, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -34,13 +34,12 @@ public class UserDto extends User implements Converter<User, UserDto> {
|
||||
private Pages page;
|
||||
|
||||
@Override
|
||||
public void convertToDo(User user) {
|
||||
public void convertDtoToDo(User user) {
|
||||
BeanUtils.copyProperties(this, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDto convert(User user) {
|
||||
public void convertDoToDto(User user) {
|
||||
BeanUtils.copyProperties(user, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -33,8 +33,11 @@ import javax.validation.constraints.Pattern;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BlackIp extends Description {
|
||||
|
||||
@NotBlank(message = "Ip can't be empty", groups = {Insert.class})
|
||||
@Pattern(regexp = "^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$", message = "Invalid ip , /^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$/", groups = {Insert.class})
|
||||
@NotBlank(message = "Ip can't be empty",
|
||||
groups = {Insert.class})
|
||||
@Pattern(message = "Invalid ip , /^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$/",
|
||||
regexp = "^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$",
|
||||
groups = {Insert.class})
|
||||
private String ip;
|
||||
private Boolean enable;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ package com.dc3.common.utils;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
import com.dc3.common.bean.TreeNode;
|
||||
import com.dc3.common.constant.Common;
|
||||
import com.dc3.common.dto.NodeDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
@@ -326,7 +326,7 @@ public class Dc3Util {
|
||||
* @param treeNodes 传入的树节点列表
|
||||
* @return T Array
|
||||
*/
|
||||
public <T extends NodeDto> List<T> buildByLoop(List<T> treeNodes, Object root) {
|
||||
public <T extends TreeNode> List<T> buildByLoop(List<T> treeNodes, Object root) {
|
||||
List<T> trees = new ArrayList<>(16);
|
||||
for (T treeNode : treeNodes) {
|
||||
if (root.equals(treeNode.getParentId())) {
|
||||
@@ -350,7 +350,7 @@ public class Dc3Util {
|
||||
* @param treeNodes 传入的树节点列表
|
||||
* @return T Array
|
||||
*/
|
||||
public <T extends NodeDto> List<T> buildByRecursive(List<T> treeNodes, Object root) {
|
||||
public <T extends TreeNode> List<T> buildByRecursive(List<T> treeNodes, Object root) {
|
||||
List<T> trees = new ArrayList<>(16);
|
||||
for (T treeNode : treeNodes) {
|
||||
if (root.equals(treeNode.getParentId())) {
|
||||
@@ -366,7 +366,7 @@ public class Dc3Util {
|
||||
* @param treeNodes 传入的树节点列表
|
||||
* @return T
|
||||
*/
|
||||
public <T extends NodeDto> T findChildren(T treeNode, List<T> treeNodes) {
|
||||
public <T extends TreeNode> T findChildren(T treeNode, List<T> treeNodes) {
|
||||
for (T it : treeNodes) {
|
||||
if (treeNode.getId() == it.getParentId()) {
|
||||
if (treeNode.getChildren() == null) {
|
||||
|
||||
Reference in New Issue
Block a user