Commit eb4434ecbc7b56ff7f2c3a1bcc33662cc42fa187
1 parent
287a17a9
解决MapStruct的时区问题
Showing
7 changed files
with
22 additions
and
11 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java
| ... | ... | @@ -36,6 +36,9 @@ public class DateUtils { |
| 36 | 36 | * @return LocalDateTime |
| 37 | 37 | */ |
| 38 | 38 | public static Date of(LocalDateTime date) { |
| 39 | + if (date == null) { | |
| 40 | + return null; | |
| 41 | + } | |
| 39 | 42 | // 将此日期时间与时区相结合以创建 ZonedDateTime |
| 40 | 43 | ZonedDateTime zonedDateTime = date.atZone(ZoneId.systemDefault()); |
| 41 | 44 | // 本地时间线 LocalDateTime 到即时时间线 Instant 时间戳 |
| ... | ... | @@ -51,6 +54,9 @@ public class DateUtils { |
| 51 | 54 | * @return LocalDateTime |
| 52 | 55 | */ |
| 53 | 56 | public static LocalDateTime of(Date date) { |
| 57 | + if (date == null) { | |
| 58 | + return null; | |
| 59 | + } | |
| 54 | 60 | // 转为时间戳 |
| 55 | 61 | Instant instant = date.toInstant(); |
| 56 | 62 | // UTC时间(世界协调时间,UTC + 00:00)转北京(北京,UTC + 8:00)时间 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmActivityConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.convert.task; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 3 | 4 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.activity.BpmActivityRespVO; |
| 4 | 5 | import org.flowable.engine.history.HistoricActivityInstance; |
| 5 | 6 | import org.mapstruct.Mapper; |
| ... | ... | @@ -14,7 +15,7 @@ import java.util.List; |
| 14 | 15 | * |
| 15 | 16 | * @author 芋道源码 |
| 16 | 17 | */ |
| 17 | -@Mapper | |
| 18 | +@Mapper(uses = DateUtils.class) | |
| 18 | 19 | public interface BpmActivityConvert { |
| 19 | 20 | |
| 20 | 21 | BpmActivityConvert INSTANCE = Mappers.getMapper(BpmActivityConvert.class); | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmProcessInstanceConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.convert.task; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |
| 5 | 6 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstancePageItemRespVO; |
| 6 | 7 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO; |
| ... | ... | @@ -28,7 +29,7 @@ import java.util.Map; |
| 28 | 29 | * |
| 29 | 30 | * @author 芋道源码 |
| 30 | 31 | */ |
| 31 | -@Mapper | |
| 32 | +@Mapper(uses = DateUtils.class) | |
| 32 | 33 | public interface BpmProcessInstanceConvert { |
| 33 | 34 | |
| 34 | 35 | BpmProcessInstanceConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceConvert.class); | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.convert.task; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 5 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.number.NumberUtils; |
| 6 | 7 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskDonePageItemRespVO; |
| 7 | 8 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO; |
| ... | ... | @@ -26,7 +27,7 @@ import java.util.Map; |
| 26 | 27 | * |
| 27 | 28 | * @author 芋道源码 |
| 28 | 29 | */ |
| 29 | -@Mapper | |
| 30 | +@Mapper(uses = DateUtils.class) | |
| 30 | 31 | public interface BpmTaskConvert { |
| 31 | 32 | |
| 32 | 33 | BpmTaskConvert INSTANCE = Mappers.getMapper(BpmTaskConvert.class); |
| ... | ... | @@ -46,8 +47,8 @@ public interface BpmTaskConvert { |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | 49 | @Mapping(source = "suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState") |
| 49 | - @Mapping(target = "claimTime", expression = "java(bean.getClaimTime()==null?null: LocalDateTime.ofInstant(bean.getClaimTime().toInstant(),ZoneId.systemDefault()))") | |
| 50 | - @Mapping(target = "createTime", expression = "java(bean.getCreateTime()==null?null:LocalDateTime.ofInstant(bean.getCreateTime().toInstant(),ZoneId.systemDefault()))") | |
| 50 | + // @Mapping(target = "claimTime", expression = "java(bean.getClaimTime()==null?null: LocalDateTime.ofInstant(bean.getClaimTime().toInstant(),ZoneId.systemDefault()))") | |
| 51 | + // @Mapping(target = "createTime", expression = "java(bean.getCreateTime()==null?null:LocalDateTime.ofInstant(bean.getCreateTime().toInstant(),ZoneId.systemDefault()))") | |
| 51 | 52 | BpmTaskTodoPageItemRespVO convert1(Task bean); |
| 52 | 53 | |
| 53 | 54 | @Named("convertSuspendedToSuspensionState") |
| ... | ... | @@ -106,8 +107,8 @@ public interface BpmTaskConvert { |
| 106 | 107 | } |
| 107 | 108 | |
| 108 | 109 | @Mapping(source = "taskDefinitionKey", target = "definitionKey") |
| 109 | - @Mapping(target = "createTime", expression = "java(bean.getCreateTime() == null ? null : LocalDateTime.ofInstant(bean.getCreateTime().toInstant(), ZoneId.systemDefault()))") | |
| 110 | - @Mapping(target = "endTime", expression = "java(bean.getEndTime() == null ? null : LocalDateTime.ofInstant(bean.getEndTime().toInstant(), ZoneId.systemDefault()))") | |
| 110 | + // @Mapping(target = "createTime", expression = "java(bean.getCreateTime() == null ? null : LocalDateTime.ofInstant(bean.getCreateTime().toInstant(), ZoneId.systemDefault()))") | |
| 111 | + // @Mapping(target = "endTime", expression = "java(bean.getEndTime() == null ? null : LocalDateTime.ofInstant(bean.getEndTime().toInstant(), ZoneId.systemDefault()))") | |
| 111 | 112 | BpmTaskRespVO convert3(HistoricTaskInstance bean); |
| 112 | 113 | |
| 113 | 114 | BpmTaskRespVO.User convert3(AdminUserRespDTO bean); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 7 | 8 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 8 | 9 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; |
| 9 | 10 | import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; |
| ... | ... | @@ -44,7 +45,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 44 | 45 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; |
| 45 | 46 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime; |
| 46 | 47 | |
| 47 | -@Mapper | |
| 48 | +@Mapper(uses = DateUtils.class) | |
| 48 | 49 | public interface TradeOrderConvert { |
| 49 | 50 | |
| 50 | 51 | TradeOrderConvert INSTANCE = Mappers.getMapper(TradeOrderConvert.class); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.system.convert.notify; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 4 | 5 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; |
| 5 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; |
| 6 | 7 | import org.mapstruct.Mapper; |
| ... | ... | @@ -13,7 +14,7 @@ import java.util.List; |
| 13 | 14 | * |
| 14 | 15 | * @author xrcoder |
| 15 | 16 | */ |
| 16 | -@Mapper | |
| 17 | +@Mapper(uses = DateUtils.class) | |
| 17 | 18 | public interface NotifyMessageConvert { |
| 18 | 19 | |
| 19 | 20 | NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class); |
| ... | ... | @@ -24,5 +25,4 @@ public interface NotifyMessageConvert { |
| 24 | 25 | |
| 25 | 26 | PageResult<NotifyMessageRespVO> convertPage(PageResult<NotifyMessageDO> page); |
| 26 | 27 | |
| 27 | - | |
| 28 | 28 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyTemplateConvert.java
| ... | ... | @@ -4,6 +4,7 @@ import java.util.*; |
| 4 | 4 | |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | |
| 7 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 7 | 8 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateCreateReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateRespVO; |
| 9 | 10 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateUpdateReqVO; |
| ... | ... | @@ -16,7 +17,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; |
| 16 | 17 | * |
| 17 | 18 | * @author xrcoder |
| 18 | 19 | */ |
| 19 | -@Mapper | |
| 20 | +@Mapper(uses = DateUtils.class) | |
| 20 | 21 | public interface NotifyTemplateConvert { |
| 21 | 22 | |
| 22 | 23 | NotifyTemplateConvert INSTANCE = Mappers.getMapper(NotifyTemplateConvert.class); | ... | ... |