From 07beae1b6535dc088785381df497c1e688780531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=89=E6=9D=A5=E6=8A=80=E6=9C=AF?= <1490493387@qq.com> Date: Tue, 21 Sep 2021 09:51:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(MyMetaObjectHandler.java):=20=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=97=B6=E9=97=B4=E5=92=8C=E4=BF=AE=E6=94=B9=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=87=AA=E5=8A=A8=E5=A1=AB=E5=85=85=E5=92=8CDate?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9=E4=B8=BALocalDateTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../youlai/mall/oms/service/impl/OrderServiceImpl.java | 3 +-- .../oms/tcc/service/impl/SeataTccOrderServiceImpl.java | 3 +-- .../main/java/com/youlai/common/base/BaseEntity.java | 10 +++++----- .../common/mybatis/handler/MyMetaObjectHandler.java | 1 + 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java index 059b3fb1e..e130ca0de 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java @@ -201,8 +201,7 @@ public class OrderServiceImpl extends ServiceImpl impleme .setRemark(submitDTO.getRemark()) .setPayAmount(submitDTO.getPayAmount()) .setTotalQuantity(orderItems.stream().map(OrderItemDTO::getCount).reduce(0, Integer::sum)) - .setTotalAmount(orderItems.stream().map(item -> item.getPrice() * item.getCount()).reduce(0L, Long::sum)) - .setGmtCreate(new Date()); + .setTotalAmount(orderItems.stream().map(item -> item.getPrice() * item.getCount()).reduce(0L, Long::sum)); this.save(order); // 创建订单商品 diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/tcc/service/impl/SeataTccOrderServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/tcc/service/impl/SeataTccOrderServiceImpl.java index 64856a957..1f86b4565 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/tcc/service/impl/SeataTccOrderServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/tcc/service/impl/SeataTccOrderServiceImpl.java @@ -49,8 +49,7 @@ public class SeataTccOrderServiceImpl implements SeataTccOrderService { .setRemark(orderSubmitDTO.getRemark()) .setPayAmount(orderSubmitDTO.getPayAmount()) .setTotalQuantity(orderItems.stream().map(item -> item.getCount()).reduce(0, (x, y) -> x + y)) - .setTotalAmount(orderItems.stream().map(item -> item.getPrice() * item.getCount()).reduce(0l, (x, y) -> x + y)) - .setGmtCreate(new Date()); + .setTotalAmount(orderItems.stream().map(item -> item.getPrice() * item.getCount()).reduce(0l, (x, y) -> x + y)); orderMapper.insert(order); int i = 1 / 0; // 创建订单商品 diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/base/BaseEntity.java b/youlai-common/common-core/src/main/java/com/youlai/common/base/BaseEntity.java index b495f02a2..c5f57a9c2 100644 --- a/youlai-common/common-core/src/main/java/com/youlai/common/base/BaseEntity.java +++ b/youlai-common/common-core/src/main/java/com/youlai/common/base/BaseEntity.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDateTime; @Data public class BaseEntity implements Serializable { @@ -13,11 +13,11 @@ public class BaseEntity implements Serializable { @TableField(fill = FieldFill.INSERT) @JsonInclude(value = JsonInclude.Include.NON_NULL) - @JsonFormat(shape= JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") - private Date gmtCreate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime gmtCreate; @TableField(fill = FieldFill.INSERT_UPDATE) @JsonInclude(value = JsonInclude.Include.NON_NULL) - @JsonFormat(shape= JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") - private Date gmtModified; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime gmtModified; } diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyMetaObjectHandler.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyMetaObjectHandler.java index 714be5376..a34bad70b 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyMetaObjectHandler.java +++ b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyMetaObjectHandler.java @@ -22,6 +22,7 @@ public class MyMetaObjectHandler implements MetaObjectHandler { @Override public void insertFill(MetaObject metaObject) { this.strictInsertFill(metaObject, "gmtCreate", () -> LocalDateTime.now(), LocalDateTime.class); + this.strictUpdateFill(metaObject, "gmtModified", () -> LocalDateTime.now(), LocalDateTime.class); } /**