From 4aaeefcf5b77c6693e837009e8954d27bce6b55b Mon Sep 17 00:00:00 2001 From: jay <75509151@qq.com> Date: Sun, 4 Jun 2023 20:31:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20mapstruct=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot-data-serviceImpl-rdb/pom.xml | 15 ++-- .../cc/iotkit/data/model/TbDeviceInfo.java | 4 + .../java/cc/iotkit/data/model/TbRuleInfo.java | 11 +++ .../java/cc/iotkit/data/model/TbTaskInfo.java | 5 ++ .../cc/iotkit/data/model/TbThingModel.java | 5 ++ .../java/cc/iotkit/data/model/TbUserInfo.java | 9 +++ .../data/service/DeviceInfoDataImpl.java | 15 ++-- .../iotkit/data/service/RuleInfoDataImpl.java | 17 ++-- .../iotkit/data/service/TaskInfoDataImpl.java | 12 ++- .../data/service/ThingModelDataImpl.java | 6 +- .../iotkit/data/service/UserInfoDataImpl.java | 19 ++--- .../data/service/VirtualDeviceDataImpl.java | 16 ++-- .../service/convert/DeviceInfoMapper.java | 28 ------- .../data/service/convert/RuleInfoMapper.java | 66 --------------- .../data/service/convert/TaskInfoMapper.java | 51 ------------ .../service/convert/ThingModelMapper.java | 54 ------------- .../data/service/convert/UserInfoMapper.java | 80 ------------------- .../service/convert/VirtualDeviceMapper.java | 34 -------- .../iot-temporal-serviceImpl-es/pom.xml | 6 +- .../es/document/DevicePropertyMapper.java | 21 ----- .../es/document/DocDeviceProperty.java | 3 + .../temporal/es/document/DocRuleLog.java | 3 + .../temporal/es/document/DocTaskLog.java | 4 + .../es/document/DocThingModelMessage.java | 3 + .../temporal/es/document/RuleLogMapper.java | 23 ------ .../temporal/es/document/TaskLogMapper.java | 23 ------ .../es/document/ThingModelMessageMapper.java | 23 ------ .../es/document/VirtualDeviceLogMapper.java | 23 ------ .../es/service/DevicePropertyDataImpl.java | 4 +- .../temporal/es/service/RuleLogDataImpl.java | 8 +- .../temporal/es/service/TaskLogDataImpl.java | 6 +- .../es/service/ThingModelMessageDataImpl.java | 6 +- .../es/service/VirtualDeviceLogDataImpl.java | 9 ++- iot-common/iot-common-doc/pom.xml | 7 ++ 34 files changed, 124 insertions(+), 495 deletions(-) delete mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/DeviceInfoMapper.java delete mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/RuleInfoMapper.java delete mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/TaskInfoMapper.java delete mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/ThingModelMapper.java delete mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/UserInfoMapper.java delete mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/VirtualDeviceMapper.java delete mode 100644 iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DevicePropertyMapper.java delete mode 100644 iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/RuleLogMapper.java delete mode 100644 iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/TaskLogMapper.java delete mode 100644 iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/ThingModelMessageMapper.java delete mode 100644 iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/VirtualDeviceLogMapper.java diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml index 897d0096..c3362134 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml @@ -47,20 +47,17 @@ hutool-core - - - - - - io.github.linpeilie - mapstruct-plus - - + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + org.projectlombok lombok diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java index d18b6005..18cce677 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java @@ -2,6 +2,8 @@ package cc.iotkit.data.model; import cc.iotkit.model.device.DeviceInfo; 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.ApiModelProperty; import lombok.Data; @@ -41,6 +43,8 @@ public class TbDeviceInfo { private String uid; @ApiModelProperty(value = "设备状态") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) private String state; @ApiModelProperty(value = "设备在线时间") diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java index e8636d3b..64af6f3b 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java @@ -12,6 +12,8 @@ package cc.iotkit.data.model; import cc.iotkit.model.rule.RuleInfo; import cc.iotkit.model.rule.RuleLog; 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.ApiModelProperty; import lombok.Data; @@ -40,14 +42,23 @@ public class TbRuleInfo { @Column(columnDefinition = "text") @ApiModelProperty(value = "监听器") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String listeners; @Column(columnDefinition = "text") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + @ApiModelProperty(value = "过滤器") private String filters; @Column(columnDefinition = "text") @ApiModelProperty(value = "动作") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String actions; @ApiModelProperty(value = "用户id") diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java index 2c178856..fec630ba 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java @@ -11,6 +11,8 @@ package cc.iotkit.data.model; import cc.iotkit.model.rule.TaskInfo; import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -58,6 +60,9 @@ public class TbTaskInfo { */ @Column(columnDefinition = "text") @ApiModelProperty(value = "任务输出") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String actions; /** diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java index 43f394f2..f25b91f3 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java @@ -11,6 +11,8 @@ package cc.iotkit.data.model; import cc.iotkit.model.product.ThingModel; import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -34,6 +36,9 @@ public class TbThingModel { @ApiModelProperty(value = "模型内容") @Column(columnDefinition = "text") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String model; } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java index 1217077a..31894d91 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java @@ -2,6 +2,8 @@ package cc.iotkit.data.model; import cc.iotkit.model.UserInfo; import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -78,12 +80,17 @@ public class TbUserInfo { * 角色 */ @ApiModelProperty(value="角色") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) private String roles; /** * 权限 */ @ApiModelProperty(value="权限") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String permissions; /** @@ -91,6 +98,8 @@ public class TbUserInfo { * 见:Constants.THIRD_PLATFORM */ @ApiModelProperty(value="用户使用的平台") + @ReverseAutoMapping(ignore = true) + @AutoMapping(ignore = true) private String usePlatforms; @ApiModelProperty(value="创建时间") diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java index 9a84e61a..4b69978e 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java @@ -8,7 +8,6 @@ import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IProductData; import cc.iotkit.data.dao.*; import cc.iotkit.data.model.*; -import cc.iotkit.data.service.convert.DeviceInfoMapper; import cc.iotkit.common.api.Paging; import cc.iotkit.data.util.PageBuilder; 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.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.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; @@ -75,8 +73,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData,IJPACommData parseVoToDto(List vos) { return vos.stream().map(d -> { - DeviceInfo dto = DeviceInfoMapper.M.toDto(d); + + DeviceInfo dto = MapstructUtils.convert(d, DeviceInfo.class); + fillDeviceInfo(d.getDeviceId(), d, dto); return dto; }).collect(Collectors.toList()); @@ -441,8 +442,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData,IJPACommData findByUidAndType(String uid, String type) { - return RuleInfoMapper.toDto(ruleInfoRepository.findByUidAndType(uid, type)); + return MapstructUtils.convert(ruleInfoRepository.findByUidAndType(uid, type), RuleInfo.class); } @Override @@ -56,7 +55,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData paged = ruleInfoRepository.findByUidAndType(uid, type, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), - RuleInfoMapper.toDto(paged.getContent())); + MapstructUtils.convert(paged.getContent(), RuleInfo.class)); } @Override @@ -64,12 +63,12 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData paged = ruleInfoRepository.findByType(type, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), - RuleInfoMapper.toDto(paged.getContent())); + MapstructUtils.convert(paged.getContent(), RuleInfo.class)); } @Override public List findByUid(String uid) { - return RuleInfoMapper.toDto(ruleInfoRepository.findByUid(uid)); + return MapstructUtils.convert(ruleInfoRepository.findByUid(uid), RuleInfo.class); } @Override @@ -77,7 +76,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData paged = ruleInfoRepository.findByUid(uid, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), - RuleInfoMapper.toDto(paged.getContent())); + MapstructUtils.convert(paged.getContent(), RuleInfo.class)); } @Override @@ -88,7 +87,7 @@ public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData findByUid(String uid) { - return TaskInfoMapper.toDto(taskInfoRepository.findByUid(uid)); + return MapstructUtils.convert(taskInfoRepository.findByUid(uid), TaskInfo.class); } @Override @@ -48,7 +46,7 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData paged = taskInfoRepository.findByUid(uid, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), - TaskInfoMapper.toDto(paged.getContent())); + MapstructUtils.convert(paged.getContent(), TaskInfo.class)); } @Override @@ -68,7 +66,7 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData findByType(int type) { - return UserInfoMapper.toDto(userInfoRepository.findByType(type)); + return MapstructUtils.convert(userInfoRepository.findByType(type), UserInfo.class); } @Override public List findByTypeAndOwnerId(int type, String ownerId) { - return UserInfoMapper.toDto(userInfoRepository.findByTypeAndOwnerId(type, ownerId)); + return MapstructUtils.convert(userInfoRepository.findByTypeAndOwnerId(type, ownerId), UserInfo.class); } @Override @@ -65,7 +62,7 @@ public class UserInfoDataImpl implements IUserInfoData, IJPACommData findAll() { - return UserInfoMapper.toDto(userInfoRepository.findAll()); + return MapstructUtils.convert(userInfoRepository.findAll(), UserInfo.class); } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java index 4c476916..a46a8aa7 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java @@ -16,7 +16,7 @@ import cc.iotkit.data.dao.VirtualDeviceMappingRepository; import cc.iotkit.data.dao.VirtualDeviceRepository; import cc.iotkit.data.model.TbVirtualDevice; 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.model.device.VirtualDevice; import cn.hutool.core.util.IdUtil; @@ -58,7 +58,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData findByUid(String uid) { - return VirtualDeviceMapper.toDto(virtualDeviceRepository.findByUid(uid)); + return MapstructUtils.convert(virtualDeviceRepository.findByUid(uid), VirtualDevice.class); } @Override @@ -66,7 +66,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData paged = virtualDeviceRepository.findByUid(uid, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), - VirtualDeviceMapper.toDto(paged.getContent())); + MapstructUtils.convert(paged.getContent(), VirtualDevice.class)); } @Override @@ -81,8 +81,8 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData findByTriggerAndState(String trigger, String state) { - List list = VirtualDeviceMapper.toDto(virtualDeviceRepository - .findByTriggerAndState(trigger, state)); + List list = MapstructUtils.convert(virtualDeviceRepository + .findByTriggerAndState(trigger, state), VirtualDevice.class); for (VirtualDevice virtualDevice : list) { virtualDevice.setDevices(getVirtualDeviceIds(virtualDevice.getId())); } @@ -91,7 +91,7 @@ public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData findAll() { - return VirtualDeviceMapper.toDto(virtualDeviceRepository.findAll()); + return MapstructUtils.convert(virtualDeviceRepository.findAll(), VirtualDevice.class); } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/DeviceInfoMapper.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/DeviceInfoMapper.java deleted file mode 100644 index 98afd480..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/DeviceInfoMapper.java +++ /dev/null @@ -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); -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/RuleInfoMapper.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/RuleInfoMapper.java deleted file mode 100644 index e6c6bde3..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/RuleInfoMapper.java +++ /dev/null @@ -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 toDto(List list) { - return list.stream().map(RuleInfoMapper::toDtoFix).collect(Collectors.toList()); - } -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/TaskInfoMapper.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/TaskInfoMapper.java deleted file mode 100644 index 210affbd..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/TaskInfoMapper.java +++ /dev/null @@ -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 toDto(List list) { - return list.stream().map(TaskInfoMapper::toDtoFix).collect(Collectors.toList()); - } - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/ThingModelMapper.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/ThingModelMapper.java deleted file mode 100644 index 178da9d7..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/ThingModelMapper.java +++ /dev/null @@ -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 toDto(List list) { - return list.stream().map(ThingModelMapper::toDtoFix).collect(Collectors.toList()); - } - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/UserInfoMapper.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/UserInfoMapper.java deleted file mode 100644 index 4ada1d98..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/UserInfoMapper.java +++ /dev/null @@ -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 toDto(List list) { - return list.stream().map(UserInfoMapper::toDtoFix).collect(Collectors.toList()); - } - - static List splitToList(String str) { - if (StringUtils.isBlank(str)) { - return new ArrayList<>(); - } - return Arrays.asList(str.split(",")); - } - - static String listToStr(List list) { - if (list == null || list.size() == 0) { - return ""; - } - return String.join(",", list); - } - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/VirtualDeviceMapper.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/VirtualDeviceMapper.java deleted file mode 100644 index 0b8f64d8..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/convert/VirtualDeviceMapper.java +++ /dev/null @@ -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 toDto(List list) { - return list.stream().map(VirtualDeviceMapper.M::toDto).collect(Collectors.toList()); - } - -} diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/pom.xml b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/pom.xml index 81b33f8a..54d2ad40 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/pom.xml +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/pom.xml @@ -29,9 +29,13 @@ jackson-annotations + + + + io.github.linpeilie - mapstruct-plus + mapstruct-plus-spring-boot-starter cc.iotkit diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DevicePropertyMapper.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DevicePropertyMapper.java deleted file mode 100644 index f99ad055..00000000 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DevicePropertyMapper.java +++ /dev/null @@ -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); -} diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java index 83fadfb8..06148970 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java @@ -9,6 +9,8 @@ */ package cc.iotkit.temporal.es.document; +import cc.iotkit.model.device.message.DeviceProperty; +import io.github.linpeilie.annotations.AutoMapper; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -23,6 +25,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType; @AllArgsConstructor @Builder @Document(indexName = "device_property") +@AutoMapper(target = DeviceProperty.class) public class DocDeviceProperty { @Id diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java index 1b6995d9..fa93b478 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java @@ -9,6 +9,8 @@ */ package cc.iotkit.temporal.es.document; +import cc.iotkit.model.rule.RuleLog; +import io.github.linpeilie.annotations.AutoMapper; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -23,6 +25,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType; @AllArgsConstructor @Builder @Document(indexName = "rule_log") +@AutoMapper(target = RuleLog.class) public class DocRuleLog { @Id private String id; diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java index f3214dd5..cce7a0b2 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java @@ -9,6 +9,9 @@ */ 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.Builder; import lombok.Data; @@ -23,6 +26,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType; @AllArgsConstructor @Builder @Document(indexName = "task_log") +@AutoMapper(target = TaskLog.class) public class DocTaskLog { @Id diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java index c7c8d177..20ddac73 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java @@ -9,6 +9,8 @@ */ package cc.iotkit.temporal.es.document; +import cc.iotkit.model.device.message.ThingModelMessage; +import io.github.linpeilie.annotations.AutoMapper; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -23,6 +25,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType; @AllArgsConstructor @Builder @Document(indexName = "thing_model_message") +@AutoMapper(target = ThingModelMessage.class) public class DocThingModelMessage { @Id diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/RuleLogMapper.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/RuleLogMapper.java deleted file mode 100644 index ea2fcc3f..00000000 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/RuleLogMapper.java +++ /dev/null @@ -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); -} diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/TaskLogMapper.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/TaskLogMapper.java deleted file mode 100644 index 0a373de7..00000000 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/TaskLogMapper.java +++ /dev/null @@ -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); -} diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/ThingModelMessageMapper.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/ThingModelMessageMapper.java deleted file mode 100644 index 488eac1e..00000000 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/ThingModelMessageMapper.java +++ /dev/null @@ -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); -} diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/VirtualDeviceLogMapper.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/VirtualDeviceLogMapper.java deleted file mode 100644 index b10c67af..00000000 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/VirtualDeviceLogMapper.java +++ /dev/null @@ -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); -} diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java index 9c89e6bf..b9087401 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java @@ -9,11 +9,11 @@ */ package cc.iotkit.temporal.es.service; +import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.temporal.IDevicePropertyData; -import cc.iotkit.temporal.es.document.DevicePropertyMapper; import cc.iotkit.temporal.es.document.DocDeviceProperty; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.sort.FieldSortBuilder; @@ -56,7 +56,7 @@ public class DevicePropertyDataImpl implements IDevicePropertyData { .build(); SearchHits result = template.search(query, DocDeviceProperty.class, IndexCoordinates.of(index)); return result.getSearchHits().stream() - .map(h -> DevicePropertyMapper.M.toDto(h.getContent())) + .map(h -> MapstructUtils.convert(h.getContent(), DeviceProperty.class)) .collect(Collectors.toList()); } diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java index 5342f340..58e03a67 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java @@ -10,11 +10,11 @@ package cc.iotkit.temporal.es.service; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.model.rule.RuleLog; import cc.iotkit.temporal.IRuleLogData; import cc.iotkit.temporal.es.dao.RuleLogRepository; import cc.iotkit.temporal.es.document.DocRuleLog; -import cc.iotkit.temporal.es.document.RuleLogMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -37,12 +37,14 @@ public class RuleLogDataImpl implements IRuleLogData { public Paging findByRuleId(String ruleId, int page, int size) { Page paged = ruleLogRepository.findByRuleId(ruleId, Pageable.ofSize(size).withPage(page - 1)); 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())); } @Override public void add(RuleLog log) { - ruleLogRepository.save(RuleLogMapper.M.toVo(log)); + ruleLogRepository.save(MapstructUtils.convert(log, DocRuleLog.class)); } } diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java index bcda796e..c753ac7e 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java @@ -10,11 +10,11 @@ package cc.iotkit.temporal.es.service; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.model.rule.TaskLog; import cc.iotkit.temporal.ITaskLogData; import cc.iotkit.temporal.es.dao.TaskLogRepository; import cc.iotkit.temporal.es.document.DocTaskLog; -import cc.iotkit.temporal.es.document.TaskLogMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -37,12 +37,12 @@ public class TaskLogDataImpl implements ITaskLogData { public Paging findByTaskId(String taskId, int page, int size) { Page paged = taskLogRepository.findByTaskId(taskId, Pageable.ofSize(size).withPage(page - 1)); 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())); } @Override public void add(TaskLog log) { - taskLogRepository.save(TaskLogMapper.M.toVo(log)); + taskLogRepository.save(MapstructUtils.convert(log, DocTaskLog.class)); } } diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java index 015b4d07..74dbe185 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java @@ -10,12 +10,12 @@ package cc.iotkit.temporal.es.service; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.model.stats.TimeData; import cc.iotkit.temporal.IThingModelMessageData; import cc.iotkit.temporal.es.dao.ThingModelMessageRepository; import cc.iotkit.temporal.es.document.DocThingModelMessage; -import cc.iotkit.temporal.es.document.ThingModelMessageMapper; import org.apache.commons.lang3.StringUtils; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -63,7 +63,7 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData { .build(); SearchHits result = template.search(query, DocThingModelMessage.class); 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())); } @@ -102,7 +102,7 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData { @Override public void add(ThingModelMessage msg) { - thingModelMessageRepository.save(ThingModelMessageMapper.M.toVo(msg)); + thingModelMessageRepository.save(MapstructUtils.convert(msg, DocThingModelMessage.class)); } @Override diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java index 0892da9a..10bc4bd2 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java +++ b/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java @@ -10,16 +10,17 @@ package cc.iotkit.temporal.es.service; import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; import cc.iotkit.model.device.VirtualDeviceLog; import cc.iotkit.temporal.IVirtualDeviceLogData; import cc.iotkit.temporal.es.dao.VirtualDeviceLogRepository; import cc.iotkit.temporal.es.document.DocVirtualDeviceLog; -import cc.iotkit.temporal.es.document.VirtualDeviceLogMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.util.Map; import java.util.stream.Collectors; @Service @@ -34,12 +35,14 @@ public class VirtualDeviceLogDataImpl implements IVirtualDeviceLogData { .findByVirtualDeviceId(virtualDeviceId, Pageable.ofSize(size).withPage(page - 1)); return new Paging<>(paged.getTotalElements(), paged.getContent().stream() - .map(VirtualDeviceLogMapper.M::toDto) + .map(o -> { + return MapstructUtils.convert(o, VirtualDeviceLog.class); + }) .collect(Collectors.toList())); } @Override public void add(VirtualDeviceLog log) { - virtualDeviceLogRepository.save(VirtualDeviceLogMapper.M.toVo(log)); + virtualDeviceLogRepository.save(MapstructUtils.convert(log, DocVirtualDeviceLog.class)); } } diff --git a/iot-common/iot-common-doc/pom.xml b/iot-common/iot-common-doc/pom.xml index 51f3816b..64aadcda 100644 --- a/iot-common/iot-common-doc/pom.xml +++ b/iot-common/iot-common-doc/pom.xml @@ -28,6 +28,13 @@ com.github.xiaoymin knife4j-spring-boot-starter + + + org.mapstruct + mapstruct + + +