fix mapstruct冲突

V0.5.x
jay 2023-06-04 20:31:53 +08:00
parent b470be12c3
commit 4aaeefcf5b
34 changed files with 124 additions and 495 deletions

View File

@ -47,20 +47,17 @@
<artifactId>hutool-core</artifactId> <artifactId>hutool-core</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.mapstruct</groupId>-->
<!-- <artifactId>mapstruct</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>io.github.linpeilie</groupId>
<artifactId>mapstruct-plus</artifactId>
</dependency>
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>io.github.linpeilie</groupId>--> <!-- <groupId>io.github.linpeilie</groupId>-->
<!-- <artifactId>mapstruct-plus-spring-boot-starter</artifactId>--> <!-- <artifactId>mapstruct-plus</artifactId>-->
<!-- </dependency>--> <!-- </dependency>-->
<dependency>
<groupId>io.github.linpeilie</groupId>
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>

View File

@ -2,6 +2,8 @@ package cc.iotkit.data.model;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -41,6 +43,8 @@ public class TbDeviceInfo {
private String uid; private String uid;
@ApiModelProperty(value = "设备状态") @ApiModelProperty(value = "设备状态")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String state; private String state;
@ApiModelProperty(value = "设备在线时间") @ApiModelProperty(value = "设备在线时间")

View File

@ -12,6 +12,8 @@ package cc.iotkit.data.model;
import cc.iotkit.model.rule.RuleInfo; import cc.iotkit.model.rule.RuleInfo;
import cc.iotkit.model.rule.RuleLog; import cc.iotkit.model.rule.RuleLog;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -40,14 +42,23 @@ public class TbRuleInfo {
@Column(columnDefinition = "text") @Column(columnDefinition = "text")
@ApiModelProperty(value = "监听器") @ApiModelProperty(value = "监听器")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String listeners; private String listeners;
@Column(columnDefinition = "text") @Column(columnDefinition = "text")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
@ApiModelProperty(value = "过滤器") @ApiModelProperty(value = "过滤器")
private String filters; private String filters;
@Column(columnDefinition = "text") @Column(columnDefinition = "text")
@ApiModelProperty(value = "动作") @ApiModelProperty(value = "动作")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String actions; private String actions;
@ApiModelProperty(value = "用户id") @ApiModelProperty(value = "用户id")

View File

@ -11,6 +11,8 @@ package cc.iotkit.data.model;
import cc.iotkit.model.rule.TaskInfo; import cc.iotkit.model.rule.TaskInfo;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -58,6 +60,9 @@ public class TbTaskInfo {
*/ */
@Column(columnDefinition = "text") @Column(columnDefinition = "text")
@ApiModelProperty(value = "任务输出") @ApiModelProperty(value = "任务输出")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String actions; private String actions;
/** /**

View File

@ -11,6 +11,8 @@ package cc.iotkit.data.model;
import cc.iotkit.model.product.ThingModel; import cc.iotkit.model.product.ThingModel;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -34,6 +36,9 @@ public class TbThingModel {
@ApiModelProperty(value = "模型内容") @ApiModelProperty(value = "模型内容")
@Column(columnDefinition = "text") @Column(columnDefinition = "text")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String model; private String model;
} }

View File

@ -2,6 +2,8 @@ package cc.iotkit.data.model;
import cc.iotkit.model.UserInfo; import cc.iotkit.model.UserInfo;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -78,12 +80,17 @@ public class TbUserInfo {
* *
*/ */
@ApiModelProperty(value="角色") @ApiModelProperty(value="角色")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String roles; private String roles;
/** /**
* *
*/ */
@ApiModelProperty(value="权限") @ApiModelProperty(value="权限")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String permissions; private String permissions;
/** /**
@ -91,6 +98,8 @@ public class TbUserInfo {
* :Constants.THIRD_PLATFORM * :Constants.THIRD_PLATFORM
*/ */
@ApiModelProperty(value="用户使用的平台") @ApiModelProperty(value="用户使用的平台")
@ReverseAutoMapping(ignore = true)
@AutoMapping(ignore = true)
private String usePlatforms; private String usePlatforms;
@ApiModelProperty(value="创建时间") @ApiModelProperty(value="创建时间")

View File

@ -8,7 +8,6 @@ import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.data.manager.IProductData; import cc.iotkit.data.manager.IProductData;
import cc.iotkit.data.dao.*; import cc.iotkit.data.dao.*;
import cc.iotkit.data.model.*; import cc.iotkit.data.model.*;
import cc.iotkit.data.service.convert.DeviceInfoMapper;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.data.util.PageBuilder; import cc.iotkit.data.util.PageBuilder;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
@ -20,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
@ -75,8 +73,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData,IJPACommData<DeviceIn
@Override @Override
public DeviceInfo findByDeviceId(String deviceId) { public DeviceInfo findByDeviceId(String deviceId) {
TbDeviceInfo tbDeviceInfo = deviceInfoRepository.findByDeviceId(deviceId); TbDeviceInfo tbDeviceInfo = deviceInfoRepository.findByDeviceId(deviceId);
DeviceInfo dto = DeviceInfoMapper.M.toDto(tbDeviceInfo);
DeviceInfo dto = MapstructUtils.convert(tbDeviceInfo, DeviceInfo.class);
fillDeviceInfo(deviceId, tbDeviceInfo, dto); fillDeviceInfo(deviceId, tbDeviceInfo, dto);
return dto; return dto;
} }
@ -141,7 +139,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData,IJPACommData<DeviceIn
if (vo == null) { if (vo == null) {
return null; return null;
} }
DeviceInfo dto = DeviceInfoMapper.M.toDto(vo); DeviceInfo dto = MapstructUtils.convert(vo, DeviceInfo.class);
fillDeviceInfo(vo.getDeviceId(), vo, dto); fillDeviceInfo(vo.getDeviceId(), vo, dto);
return dto; return dto;
} }
@ -151,7 +150,9 @@ public class DeviceInfoDataImpl implements IDeviceInfoData,IJPACommData<DeviceIn
*/ */
private List<DeviceInfo> parseVoToDto(List<TbDeviceInfo> vos) { private List<DeviceInfo> parseVoToDto(List<TbDeviceInfo> vos) {
return vos.stream().map(d -> { return vos.stream().map(d -> {
DeviceInfo dto = DeviceInfoMapper.M.toDto(d);
DeviceInfo dto = MapstructUtils.convert(d, DeviceInfo.class);
fillDeviceInfo(d.getDeviceId(), d, dto); fillDeviceInfo(d.getDeviceId(), d, dto);
return dto; return dto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
@ -441,8 +442,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData,IJPACommData<DeviceIn
@Override @Override
public DeviceInfo findById(String s) { public DeviceInfo findById(String s) {
return DeviceInfoMapper.M.toDto( return MapstructUtils.convert(
deviceInfoRepository.findById(s).orElse(null)); deviceInfoRepository.findById(s).orElse(null), DeviceInfo.class);
} }
@Override @Override

View File

@ -9,12 +9,11 @@
*/ */
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData; import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IRuleInfoData; import cc.iotkit.data.manager.IRuleInfoData;
import cc.iotkit.data.dao.RuleInfoRepository; import cc.iotkit.data.dao.RuleInfoRepository;
import cc.iotkit.data.model.TbRuleInfo; import cc.iotkit.data.model.TbRuleInfo;
import cc.iotkit.data.service.convert.RuleInfoMapper;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.model.rule.RuleInfo; import cc.iotkit.model.rule.RuleInfo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -48,7 +47,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData<RuleInfo, S
@Override @Override
public List<RuleInfo> findByUidAndType(String uid, String type) { public List<RuleInfo> findByUidAndType(String uid, String type) {
return RuleInfoMapper.toDto(ruleInfoRepository.findByUidAndType(uid, type)); return MapstructUtils.convert(ruleInfoRepository.findByUidAndType(uid, type), RuleInfo.class);
} }
@Override @Override
@ -56,7 +55,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData<RuleInfo, S
Page<TbRuleInfo> paged = ruleInfoRepository.findByUidAndType(uid, type, Page<TbRuleInfo> paged = ruleInfoRepository.findByUidAndType(uid, type,
Pageable.ofSize(size).withPage(page - 1)); Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), return new Paging<>(paged.getTotalElements(),
RuleInfoMapper.toDto(paged.getContent())); MapstructUtils.convert(paged.getContent(), RuleInfo.class));
} }
@Override @Override
@ -64,12 +63,12 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData<RuleInfo, S
Page<TbRuleInfo> paged = ruleInfoRepository.findByType(type, Page<TbRuleInfo> paged = ruleInfoRepository.findByType(type,
Pageable.ofSize(size).withPage(page - 1)); Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), return new Paging<>(paged.getTotalElements(),
RuleInfoMapper.toDto(paged.getContent())); MapstructUtils.convert(paged.getContent(), RuleInfo.class));
} }
@Override @Override
public List<RuleInfo> findByUid(String uid) { public List<RuleInfo> findByUid(String uid) {
return RuleInfoMapper.toDto(ruleInfoRepository.findByUid(uid)); return MapstructUtils.convert(ruleInfoRepository.findByUid(uid), RuleInfo.class);
} }
@Override @Override
@ -77,7 +76,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData<RuleInfo, S
Page<TbRuleInfo> paged = ruleInfoRepository.findByUid(uid, Page<TbRuleInfo> paged = ruleInfoRepository.findByUid(uid,
Pageable.ofSize(size).withPage(page - 1)); Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), return new Paging<>(paged.getTotalElements(),
RuleInfoMapper.toDto(paged.getContent())); MapstructUtils.convert(paged.getContent(), RuleInfo.class));
} }
@Override @Override
@ -88,7 +87,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData<RuleInfo, S
@Override @Override
public RuleInfo findById(String s) { public RuleInfo findById(String s) {
return RuleInfoMapper.toDtoFix(ruleInfoRepository.findById(s).orElse(null)); return MapstructUtils.convert(ruleInfoRepository.findById(s).orElse(null), RuleInfo.class);
} }
@Override @Override
@ -102,7 +101,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData<RuleInfo, S
data.setId(UUID.randomUUID().toString()); data.setId(UUID.randomUUID().toString());
data.setCreateAt(System.currentTimeMillis()); data.setCreateAt(System.currentTimeMillis());
} }
ruleInfoRepository.save(RuleInfoMapper.toVoFix(data)); ruleInfoRepository.save(MapstructUtils.convert(data, TbRuleInfo.class));
return data; return data;
} }

View File

@ -9,12 +9,11 @@
*/ */
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData; import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.ITaskInfoData; import cc.iotkit.data.manager.ITaskInfoData;
import cc.iotkit.data.dao.TaskInfoRepository; import cc.iotkit.data.dao.TaskInfoRepository;
import cc.iotkit.data.model.TbTaskInfo; import cc.iotkit.data.model.TbTaskInfo;
import cc.iotkit.data.service.convert.TaskInfoMapper;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.model.rule.TaskInfo; import cc.iotkit.model.rule.TaskInfo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -26,7 +25,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -40,7 +38,7 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData<TaskInfo, S
@Override @Override
public List<TaskInfo> findByUid(String uid) { public List<TaskInfo> findByUid(String uid) {
return TaskInfoMapper.toDto(taskInfoRepository.findByUid(uid)); return MapstructUtils.convert(taskInfoRepository.findByUid(uid), TaskInfo.class);
} }
@Override @Override
@ -48,7 +46,7 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData<TaskInfo, S
Page<TbTaskInfo> paged = taskInfoRepository.findByUid(uid, Page<TbTaskInfo> paged = taskInfoRepository.findByUid(uid,
Pageable.ofSize(size).withPage(page - 1)); Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), return new Paging<>(paged.getTotalElements(),
TaskInfoMapper.toDto(paged.getContent())); MapstructUtils.convert(paged.getContent(), TaskInfo.class));
} }
@Override @Override
@ -68,7 +66,7 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData<TaskInfo, S
@Override @Override
public TaskInfo findById(String s) { public TaskInfo findById(String s) {
return TaskInfoMapper.toDtoFix(taskInfoRepository.findById(s).orElse(null)); return MapstructUtils.convert(taskInfoRepository.findById(s).orElse(null), TaskInfo.class);
} }
@ -79,7 +77,7 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData<TaskInfo, S
data.setId(UUID.randomUUID().toString()); data.setId(UUID.randomUUID().toString());
data.setCreateAt(System.currentTimeMillis()); data.setCreateAt(System.currentTimeMillis());
} }
taskInfoRepository.save(TaskInfoMapper.toVoFix(data)); taskInfoRepository.save(MapstructUtils.convert(data, TbTaskInfo.class));
return data; return data;
} }

View File

@ -10,11 +10,11 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData; import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IThingModelData; import cc.iotkit.data.manager.IThingModelData;
import cc.iotkit.data.dao.ThingModelRepository; import cc.iotkit.data.dao.ThingModelRepository;
import cc.iotkit.data.model.TbThingModel; import cc.iotkit.data.model.TbThingModel;
import cc.iotkit.data.service.convert.ThingModelMapper;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.model.product.ThingModel; import cc.iotkit.model.product.ThingModel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -48,7 +48,7 @@ public class ThingModelDataImpl implements IThingModelData, IJPACommData<ThingMo
@Override @Override
public ThingModel findById(String s) { public ThingModel findById(String s) {
return ThingModelMapper.toDtoFix(thingModelRepository.findById(s).orElse(null)); return MapstructUtils.convert(thingModelRepository.findById(s).orElse(null),ThingModel.class);
} }
@ -57,7 +57,7 @@ public class ThingModelDataImpl implements IThingModelData, IJPACommData<ThingMo
if (StringUtils.isBlank(data.getId())) { if (StringUtils.isBlank(data.getId())) {
data.setId(UUID.randomUUID().toString()); data.setId(UUID.randomUUID().toString());
} }
thingModelRepository.save(ThingModelMapper.toVoFix(data)); thingModelRepository.save(MapstructUtils.convert(data, TbThingModel.class));
return data; return data;
} }

View File

@ -9,25 +9,22 @@
*/ */
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData; import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IUserInfoData; import cc.iotkit.data.manager.IUserInfoData;
import cc.iotkit.data.dao.UserInfoRepository; import cc.iotkit.data.dao.UserInfoRepository;
import cc.iotkit.data.model.TbUserInfo; import cc.iotkit.data.model.TbUserInfo;
import cc.iotkit.data.service.convert.UserInfoMapper;
import cc.iotkit.common.api.Paging;
import cc.iotkit.model.UserInfo; import cc.iotkit.model.UserInfo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
@Primary @Primary
@ -40,17 +37,17 @@ public class UserInfoDataImpl implements IUserInfoData, IJPACommData<UserInfo, S
@Override @Override
public UserInfo findByUid(String uid) { public UserInfo findByUid(String uid) {
return UserInfoMapper.toDtoFix(userInfoRepository.findByUid(uid)); return MapstructUtils.convert(userInfoRepository.findByUid(uid), UserInfo.class);
} }
@Override @Override
public List<UserInfo> findByType(int type) { public List<UserInfo> findByType(int type) {
return UserInfoMapper.toDto(userInfoRepository.findByType(type)); return MapstructUtils.convert(userInfoRepository.findByType(type), UserInfo.class);
} }
@Override @Override
public List<UserInfo> findByTypeAndOwnerId(int type, String ownerId) { public List<UserInfo> findByTypeAndOwnerId(int type, String ownerId) {
return UserInfoMapper.toDto(userInfoRepository.findByTypeAndOwnerId(type, ownerId)); return MapstructUtils.convert(userInfoRepository.findByTypeAndOwnerId(type, ownerId), UserInfo.class);
} }
@Override @Override
@ -65,7 +62,7 @@ public class UserInfoDataImpl implements IUserInfoData, IJPACommData<UserInfo, S
@Override @Override
public UserInfo findById(String s) { public UserInfo findById(String s) {
return UserInfoMapper.toDtoFix(userInfoRepository.findById(s).orElse(null)); return MapstructUtils.convert(userInfoRepository.findById(s).orElse(null), UserInfo.class);
} }
@Override @Override
@ -79,7 +76,7 @@ public class UserInfoDataImpl implements IUserInfoData, IJPACommData<UserInfo, S
data.setId(UUID.randomUUID().toString()); data.setId(UUID.randomUUID().toString());
data.setCreateAt(System.currentTimeMillis()); data.setCreateAt(System.currentTimeMillis());
} }
userInfoRepository.save(UserInfoMapper.toVoFix(data)); userInfoRepository.save(MapstructUtils.convert(data, TbUserInfo.class));
return data; return data;
} }
@ -93,7 +90,7 @@ public class UserInfoDataImpl implements IUserInfoData, IJPACommData<UserInfo, S
@Override @Override
public List<UserInfo> findAll() { public List<UserInfo> findAll() {
return UserInfoMapper.toDto(userInfoRepository.findAll()); return MapstructUtils.convert(userInfoRepository.findAll(), UserInfo.class);
} }

View File

@ -16,7 +16,7 @@ import cc.iotkit.data.dao.VirtualDeviceMappingRepository;
import cc.iotkit.data.dao.VirtualDeviceRepository; import cc.iotkit.data.dao.VirtualDeviceRepository;
import cc.iotkit.data.model.TbVirtualDevice; import cc.iotkit.data.model.TbVirtualDevice;
import cc.iotkit.data.model.TbVirtualDeviceMapping; import cc.iotkit.data.model.TbVirtualDeviceMapping;
import cc.iotkit.data.service.convert.VirtualDeviceMapper; import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.model.device.VirtualDevice; import cc.iotkit.model.device.VirtualDevice;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
@ -58,7 +58,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData<V
@Override @Override
public List<VirtualDevice> findByUid(String uid) { public List<VirtualDevice> findByUid(String uid) {
return VirtualDeviceMapper.toDto(virtualDeviceRepository.findByUid(uid)); return MapstructUtils.convert(virtualDeviceRepository.findByUid(uid), VirtualDevice.class);
} }
@Override @Override
@ -66,7 +66,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData<V
Page<TbVirtualDevice> paged = virtualDeviceRepository.findByUid(uid, Page<TbVirtualDevice> paged = virtualDeviceRepository.findByUid(uid,
Pageable.ofSize(size).withPage(page - 1)); Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), return new Paging<>(paged.getTotalElements(),
VirtualDeviceMapper.toDto(paged.getContent())); MapstructUtils.convert(paged.getContent(), VirtualDevice.class));
} }
@Override @Override
@ -81,8 +81,8 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData<V
@Override @Override
public List<VirtualDevice> findByTriggerAndState(String trigger, String state) { public List<VirtualDevice> findByTriggerAndState(String trigger, String state) {
List<VirtualDevice> list = VirtualDeviceMapper.toDto(virtualDeviceRepository List<VirtualDevice> list = MapstructUtils.convert(virtualDeviceRepository
.findByTriggerAndState(trigger, state)); .findByTriggerAndState(trigger, state), VirtualDevice.class);
for (VirtualDevice virtualDevice : list) { for (VirtualDevice virtualDevice : list) {
virtualDevice.setDevices(getVirtualDeviceIds(virtualDevice.getId())); virtualDevice.setDevices(getVirtualDeviceIds(virtualDevice.getId()));
} }
@ -91,7 +91,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData<V
@Override @Override
public VirtualDevice findById(String s) { public VirtualDevice findById(String s) {
VirtualDevice dto = VirtualDeviceMapper.M.toDto(virtualDeviceRepository.findById(s).orElse(null)); VirtualDevice dto = MapstructUtils.convert(virtualDeviceRepository.findById(s).orElse(null),VirtualDevice.class);
dto.setDevices(getVirtualDeviceIds(s)); dto.setDevices(getVirtualDeviceIds(s));
return dto; return dto;
} }
@ -109,7 +109,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData<V
data.setId(IdUtil.simpleUUID()); data.setId(IdUtil.simpleUUID());
data.setCreateAt(System.currentTimeMillis()); data.setCreateAt(System.currentTimeMillis());
} }
virtualDeviceRepository.save(VirtualDeviceMapper.M.toVo(data)); virtualDeviceRepository.save(MapstructUtils.convert(data, TbVirtualDevice.class));
//删除旧的添加新的关联设备记录 //删除旧的添加新的关联设备记录
virtualDeviceMappingRepository.deleteByVirtualId(data.getId()); virtualDeviceMappingRepository.deleteByVirtualId(data.getId());
@ -134,7 +134,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData<V
@Override @Override
public List<VirtualDevice> findAll() { public List<VirtualDevice> findAll() {
return VirtualDeviceMapper.toDto(virtualDeviceRepository.findAll()); return MapstructUtils.convert(virtualDeviceRepository.findAll(), VirtualDevice.class);
} }

View File

@ -1,28 +0,0 @@
package cc.iotkit.data.service.convert;
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
import cc.iotkit.data.model.TbDeviceInfo;
import cc.iotkit.model.device.DeviceInfo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface DeviceInfoMapper {
DeviceInfoMapper M = Mappers.getMapper(DeviceInfoMapper.class);
@Mapping(target = "state", ignore = true)
DeviceInfo toDto(TbDeviceInfo vo);
@Mapping(target = "state", ignore = true)
TbDeviceInfo toVo(DeviceInfo dto);
}

View File

@ -1,66 +0,0 @@
package cc.iotkit.data.service.convert;
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
import cc.iotkit.common.utils.JsonUtils;
import cc.iotkit.data.model.TbRuleInfo;
import cc.iotkit.model.rule.RuleInfo;
import com.fasterxml.jackson.core.type.TypeReference;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public interface RuleInfoMapper {
RuleInfoMapper M = Mappers.getMapper(RuleInfoMapper.class);
@Mappings({
@Mapping(target = "listeners", ignore = true),
@Mapping(target = "filters", ignore = true),
@Mapping(target = "actions", ignore = true)
}
)
RuleInfo toDto(TbRuleInfo vo);
@Mappings({
@Mapping(target = "listeners", ignore = true),
@Mapping(target = "filters", ignore = true),
@Mapping(target = "actions", ignore = true)
}
)
TbRuleInfo toVo(RuleInfo dto);
static RuleInfo toDtoFix(TbRuleInfo vo) {
RuleInfo dto = M.toDto(vo);
dto.setListeners(JsonUtils.parseObject(vo.getListeners(), new TypeReference<>() {
}));
dto.setFilters(JsonUtils.parseObject(vo.getFilters(), new TypeReference<>() {
}));
dto.setActions(JsonUtils.parseObject(vo.getActions(), new TypeReference<>() {
}));
return dto;
}
static TbRuleInfo toVoFix(RuleInfo dto) {
TbRuleInfo vo = M.toVo(dto);
vo.setListeners(JsonUtils.toJsonString(dto.getListeners()));
vo.setFilters(JsonUtils.toJsonString(dto.getFilters()));
vo.setActions(JsonUtils.toJsonString(dto.getActions()));
return vo;
}
static List<RuleInfo> toDto(List<TbRuleInfo> list) {
return list.stream().map(RuleInfoMapper::toDtoFix).collect(Collectors.toList());
}
}

View File

@ -1,51 +0,0 @@
package cc.iotkit.data.service.convert;
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
import cc.iotkit.common.utils.JsonUtils;
import cc.iotkit.data.model.TbTaskInfo;
import cc.iotkit.model.rule.TaskInfo;
import com.fasterxml.jackson.core.type.TypeReference;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public interface TaskInfoMapper {
TaskInfoMapper M = Mappers.getMapper(TaskInfoMapper.class);
@Mapping(target = "actions", ignore = true)
TaskInfo toDto(TbTaskInfo vo);
static TaskInfo toDtoFix(TbTaskInfo vo) {
TaskInfo dto = M.toDto(vo);
dto.setActions(JsonUtils.parseObject(vo.getActions(), new TypeReference<>() {
}));
return dto;
}
@Mapping(target = "actions", ignore = true)
TbTaskInfo toVo(TaskInfo dto);
static TbTaskInfo toVoFix(TaskInfo dto) {
TbTaskInfo vo = M.toVo(dto);
vo.setActions(JsonUtils.toJsonString(dto.getActions()));
return vo;
}
static List<TaskInfo> toDto(List<TbTaskInfo> list) {
return list.stream().map(TaskInfoMapper::toDtoFix).collect(Collectors.toList());
}
}

View File

@ -1,54 +0,0 @@
package cc.iotkit.data.service.convert;
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
import cc.iotkit.common.utils.JsonUtils;
import cc.iotkit.data.model.TbThingModel;
import cc.iotkit.model.product.ThingModel;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public interface ThingModelMapper {
ThingModelMapper M = Mappers.getMapper(ThingModelMapper.class);
@Mapping(target = "model", ignore = true)
ThingModel toDto(TbThingModel vo);
static ThingModel toDtoFix(TbThingModel vo) {
if (vo == null) {
return null;
}
ThingModel dto = M.toDto(vo);
if (StringUtils.isNotBlank(vo.getModel())) {
dto.setModel(JsonUtils.parseObject(vo.getModel(), ThingModel.Model.class));
}
return dto;
}
@Mapping(target = "model", ignore = true)
TbThingModel toVo(ThingModel dto);
static TbThingModel toVoFix(ThingModel dto) {
TbThingModel vo = M.toVo(dto);
vo.setModel(JsonUtils.toJsonString(dto.getModel()));
return vo;
}
static List<ThingModel> toDto(List<TbThingModel> list) {
return list.stream().map(ThingModelMapper::toDtoFix).collect(Collectors.toList());
}
}

View File

@ -1,80 +0,0 @@
package cc.iotkit.data.service.convert;
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
import cc.iotkit.data.model.TbUserInfo;
import cc.iotkit.model.UserInfo;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public interface UserInfoMapper {
UserInfoMapper M = Mappers.getMapper(UserInfoMapper.class);
@Mappings({
@Mapping(target = "roles", ignore = true),
@Mapping(target = "permissions", ignore = true),
@Mapping(target = "usePlatforms", ignore = true)
}
)
UserInfo toDto(TbUserInfo vo);
static UserInfo toDtoFix(TbUserInfo vo) {
UserInfo dto = M.toDto(vo);
dto.setRoles(splitToList(vo.getRoles()));
dto.setPermissions(splitToList(vo.getPermissions()));
dto.setUsePlatforms(splitToList(vo.getUsePlatforms()));
return dto;
}
@Mappings({
@Mapping(target = "roles", ignore = true),
@Mapping(target = "permissions", ignore = true),
@Mapping(target = "usePlatforms", ignore = true)
}
)
TbUserInfo toVo(UserInfo dto);
static TbUserInfo toVoFix(UserInfo dto) {
TbUserInfo vo = M.toVo(dto);
vo.setRoles(listToStr(dto.getRoles()));
vo.setPermissions(listToStr(dto.getPermissions()));
vo.setUsePlatforms(listToStr(dto.getUsePlatforms()));
return vo;
}
static List<UserInfo> toDto(List<TbUserInfo> list) {
return list.stream().map(UserInfoMapper::toDtoFix).collect(Collectors.toList());
}
static List<String> splitToList(String str) {
if (StringUtils.isBlank(str)) {
return new ArrayList<>();
}
return Arrays.asList(str.split(","));
}
static String listToStr(List<String> list) {
if (list == null || list.size() == 0) {
return "";
}
return String.join(",", list);
}
}

View File

@ -1,34 +0,0 @@
package cc.iotkit.data.service.convert;
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
import cc.iotkit.data.model.TbVirtualDevice;
import cc.iotkit.model.device.VirtualDevice;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public interface VirtualDeviceMapper {
VirtualDeviceMapper M = Mappers.getMapper(VirtualDeviceMapper.class);
@Mapping(target = "devices", ignore = true)
VirtualDevice toDto(TbVirtualDevice vo);
TbVirtualDevice toVo(VirtualDevice dto);
static List<VirtualDevice> toDto(List<TbVirtualDevice> list) {
return list.stream().map(VirtualDeviceMapper.M::toDto).collect(Collectors.toList());
}
}

View File

@ -29,9 +29,13 @@
<artifactId>jackson-annotations</artifactId> <artifactId>jackson-annotations</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>io.github.linpeilie</groupId>-->
<!-- <artifactId>mapstruct-plus</artifactId>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>io.github.linpeilie</groupId> <groupId>io.github.linpeilie</groupId>
<artifactId>mapstruct-plus</artifactId> <artifactId>mapstruct-plus-spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>

View File

@ -1,21 +0,0 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.es.document;
import cc.iotkit.model.device.message.DeviceProperty;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface DevicePropertyMapper {
DevicePropertyMapper M = Mappers.getMapper(DevicePropertyMapper.class);
DeviceProperty toDto(DocDeviceProperty vo);
}

View File

@ -9,6 +9,8 @@
*/ */
package cc.iotkit.temporal.es.document; package cc.iotkit.temporal.es.document;
import cc.iotkit.model.device.message.DeviceProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -23,6 +25,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "device_property") @Document(indexName = "device_property")
@AutoMapper(target = DeviceProperty.class)
public class DocDeviceProperty { public class DocDeviceProperty {
@Id @Id

View File

@ -9,6 +9,8 @@
*/ */
package cc.iotkit.temporal.es.document; package cc.iotkit.temporal.es.document;
import cc.iotkit.model.rule.RuleLog;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -23,6 +25,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "rule_log") @Document(indexName = "rule_log")
@AutoMapper(target = RuleLog.class)
public class DocRuleLog { public class DocRuleLog {
@Id @Id
private String id; private String id;

View File

@ -9,6 +9,9 @@
*/ */
package cc.iotkit.temporal.es.document; package cc.iotkit.temporal.es.document;
import cc.iotkit.model.rule.TaskLog;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -23,6 +26,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "task_log") @Document(indexName = "task_log")
@AutoMapper(target = TaskLog.class)
public class DocTaskLog { public class DocTaskLog {
@Id @Id

View File

@ -9,6 +9,8 @@
*/ */
package cc.iotkit.temporal.es.document; package cc.iotkit.temporal.es.document;
import cc.iotkit.model.device.message.ThingModelMessage;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -23,6 +25,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Document(indexName = "thing_model_message") @Document(indexName = "thing_model_message")
@AutoMapper(target = ThingModelMessage.class)
public class DocThingModelMessage { public class DocThingModelMessage {
@Id @Id

View File

@ -1,23 +0,0 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.es.document;
import cc.iotkit.model.rule.RuleLog;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface RuleLogMapper {
RuleLogMapper M = Mappers.getMapper(RuleLogMapper.class);
RuleLog toDto(DocRuleLog vo);
DocRuleLog toVo(RuleLog dto);
}

View File

@ -1,23 +0,0 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.es.document;
import cc.iotkit.model.rule.TaskLog;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface TaskLogMapper {
TaskLogMapper M = Mappers.getMapper(TaskLogMapper.class);
TaskLog toDto(DocTaskLog vo);
DocTaskLog toVo(TaskLog dto);
}

View File

@ -1,23 +0,0 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.es.document;
import cc.iotkit.model.device.message.ThingModelMessage;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ThingModelMessageMapper {
ThingModelMessageMapper M = Mappers.getMapper(ThingModelMessageMapper.class);
ThingModelMessage toDto(DocThingModelMessage vo);
DocThingModelMessage toVo(ThingModelMessage dto);
}

View File

@ -1,23 +0,0 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.es.document;
import cc.iotkit.model.device.VirtualDeviceLog;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface VirtualDeviceLogMapper {
VirtualDeviceLogMapper M = Mappers.getMapper(VirtualDeviceLogMapper.class);
VirtualDeviceLog toDto(DocVirtualDeviceLog vo);
DocVirtualDeviceLog toVo(VirtualDeviceLog dto);
}

View File

@ -9,11 +9,11 @@
*/ */
package cc.iotkit.temporal.es.service; package cc.iotkit.temporal.es.service;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.model.device.message.DeviceProperty;
import cc.iotkit.temporal.IDevicePropertyData; import cc.iotkit.temporal.IDevicePropertyData;
import cc.iotkit.temporal.es.document.DevicePropertyMapper;
import cc.iotkit.temporal.es.document.DocDeviceProperty; import cc.iotkit.temporal.es.document.DocDeviceProperty;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.FieldSortBuilder;
@ -56,7 +56,7 @@ public class DevicePropertyDataImpl implements IDevicePropertyData {
.build(); .build();
SearchHits<DocDeviceProperty> result = template.search(query, DocDeviceProperty.class, IndexCoordinates.of(index)); SearchHits<DocDeviceProperty> result = template.search(query, DocDeviceProperty.class, IndexCoordinates.of(index));
return result.getSearchHits().stream() return result.getSearchHits().stream()
.map(h -> DevicePropertyMapper.M.toDto(h.getContent())) .map(h -> MapstructUtils.convert(h.getContent(), DeviceProperty.class))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -10,11 +10,11 @@
package cc.iotkit.temporal.es.service; package cc.iotkit.temporal.es.service;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.model.rule.RuleLog; import cc.iotkit.model.rule.RuleLog;
import cc.iotkit.temporal.IRuleLogData; import cc.iotkit.temporal.IRuleLogData;
import cc.iotkit.temporal.es.dao.RuleLogRepository; import cc.iotkit.temporal.es.dao.RuleLogRepository;
import cc.iotkit.temporal.es.document.DocRuleLog; import cc.iotkit.temporal.es.document.DocRuleLog;
import cc.iotkit.temporal.es.document.RuleLogMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -37,12 +37,14 @@ public class RuleLogDataImpl implements IRuleLogData {
public Paging<RuleLog> findByRuleId(String ruleId, int page, int size) { public Paging<RuleLog> findByRuleId(String ruleId, int page, int size) {
Page<DocRuleLog> paged = ruleLogRepository.findByRuleId(ruleId, Pageable.ofSize(size).withPage(page - 1)); Page<DocRuleLog> paged = ruleLogRepository.findByRuleId(ruleId, Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), return new Paging<>(paged.getTotalElements(),
paged.getContent().stream().map(RuleLogMapper.M::toDto) paged.getContent().stream().map(o->{
return MapstructUtils.convert(o, RuleLog.class);
})
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
@Override @Override
public void add(RuleLog log) { public void add(RuleLog log) {
ruleLogRepository.save(RuleLogMapper.M.toVo(log)); ruleLogRepository.save(MapstructUtils.convert(log, DocRuleLog.class));
} }
} }

View File

@ -10,11 +10,11 @@
package cc.iotkit.temporal.es.service; package cc.iotkit.temporal.es.service;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.model.rule.TaskLog; import cc.iotkit.model.rule.TaskLog;
import cc.iotkit.temporal.ITaskLogData; import cc.iotkit.temporal.ITaskLogData;
import cc.iotkit.temporal.es.dao.TaskLogRepository; import cc.iotkit.temporal.es.dao.TaskLogRepository;
import cc.iotkit.temporal.es.document.DocTaskLog; import cc.iotkit.temporal.es.document.DocTaskLog;
import cc.iotkit.temporal.es.document.TaskLogMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -37,12 +37,12 @@ public class TaskLogDataImpl implements ITaskLogData {
public Paging<TaskLog> findByTaskId(String taskId, int page, int size) { public Paging<TaskLog> findByTaskId(String taskId, int page, int size) {
Page<DocTaskLog> paged = taskLogRepository.findByTaskId(taskId, Pageable.ofSize(size).withPage(page - 1)); Page<DocTaskLog> paged = taskLogRepository.findByTaskId(taskId, Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), return new Paging<>(paged.getTotalElements(),
paged.getContent().stream().map(TaskLogMapper.M::toDto) paged.getContent().stream().map(o->{return MapstructUtils.convert(o, TaskLog.class);})
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
@Override @Override
public void add(TaskLog log) { public void add(TaskLog log) {
taskLogRepository.save(TaskLogMapper.M.toVo(log)); taskLogRepository.save(MapstructUtils.convert(log, DocTaskLog.class));
} }
} }

View File

@ -10,12 +10,12 @@
package cc.iotkit.temporal.es.service; package cc.iotkit.temporal.es.service;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.model.device.message.ThingModelMessage;
import cc.iotkit.model.stats.TimeData; import cc.iotkit.model.stats.TimeData;
import cc.iotkit.temporal.IThingModelMessageData; import cc.iotkit.temporal.IThingModelMessageData;
import cc.iotkit.temporal.es.dao.ThingModelMessageRepository; import cc.iotkit.temporal.es.dao.ThingModelMessageRepository;
import cc.iotkit.temporal.es.document.DocThingModelMessage; import cc.iotkit.temporal.es.document.DocThingModelMessage;
import cc.iotkit.temporal.es.document.ThingModelMessageMapper;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
@ -63,7 +63,7 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData {
.build(); .build();
SearchHits<DocThingModelMessage> result = template.search(query, DocThingModelMessage.class); SearchHits<DocThingModelMessage> result = template.search(query, DocThingModelMessage.class);
return new Paging<>(result.getTotalHits(), result.getSearchHits().stream() return new Paging<>(result.getTotalHits(), result.getSearchHits().stream()
.map(m -> ThingModelMessageMapper.M.toDto(m.getContent())) .map(m -> MapstructUtils.convert(m.getContent(), ThingModelMessage.class))
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
@ -102,7 +102,7 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData {
@Override @Override
public void add(ThingModelMessage msg) { public void add(ThingModelMessage msg) {
thingModelMessageRepository.save(ThingModelMessageMapper.M.toVo(msg)); thingModelMessageRepository.save(MapstructUtils.convert(msg, DocThingModelMessage.class));
} }
@Override @Override

View File

@ -10,16 +10,17 @@
package cc.iotkit.temporal.es.service; package cc.iotkit.temporal.es.service;
import cc.iotkit.common.api.Paging; import cc.iotkit.common.api.Paging;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.model.device.VirtualDeviceLog; import cc.iotkit.model.device.VirtualDeviceLog;
import cc.iotkit.temporal.IVirtualDeviceLogData; import cc.iotkit.temporal.IVirtualDeviceLogData;
import cc.iotkit.temporal.es.dao.VirtualDeviceLogRepository; import cc.iotkit.temporal.es.dao.VirtualDeviceLogRepository;
import cc.iotkit.temporal.es.document.DocVirtualDeviceLog; import cc.iotkit.temporal.es.document.DocVirtualDeviceLog;
import cc.iotkit.temporal.es.document.VirtualDeviceLogMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -34,12 +35,14 @@ public class VirtualDeviceLogDataImpl implements IVirtualDeviceLogData {
.findByVirtualDeviceId(virtualDeviceId, .findByVirtualDeviceId(virtualDeviceId,
Pageable.ofSize(size).withPage(page - 1)); Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(), paged.getContent().stream() return new Paging<>(paged.getTotalElements(), paged.getContent().stream()
.map(VirtualDeviceLogMapper.M::toDto) .map(o -> {
return MapstructUtils.convert(o, VirtualDeviceLog.class);
})
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
@Override @Override
public void add(VirtualDeviceLog log) { public void add(VirtualDeviceLog log) {
virtualDeviceLogRepository.save(VirtualDeviceLogMapper.M.toVo(log)); virtualDeviceLogRepository.save(MapstructUtils.convert(log, DocVirtualDeviceLog.class));
} }
} }

View File

@ -28,6 +28,13 @@
<dependency> <dependency>
<groupId>com.github.xiaoymin</groupId> <groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId> <artifactId>knife4j-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>