瀏覽代碼

created_at, upated_at version

tanlie 1 月之前
父節點
當前提交
47824e4835

+ 27 - 0
wishing-platform/platform-entity/platform-entity-wishing/src/main/java/cn/qinys/platform/entity/wishing/BaseEntity.java

@@ -0,0 +1,27 @@
+package cn.qinys.platform.entity.wishing;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.Version;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-05-23 13:22
+ **/
+public class BaseEntity implements Serializable {
+
+    @Version
+    private Integer version;
+
+    private Integer isDeleted;
+
+    @TableField(fill = FieldFill.INSERT)
+    private LocalDateTime createdAt;
+
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private LocalDateTime updatedAt;
+}

+ 28 - 2
wishing-platform/platform-entity/platform-entity-wishing/src/main/java/cn/qinys/platform/entity/wishing/WishingTree.java

@@ -1,16 +1,42 @@
 package cn.qinys.platform.entity.wishing;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
-import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * @author lie tan
  * @description
  * @date 2026-05-17 21:33
  **/
+@EqualsAndHashCode(callSuper = true)
 @Data
 @TableName("wishing_tree")
-public class WishingTree implements Serializable {
+public class WishingTree extends BaseEntity  {
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    private String name; // 许愿树名称
+
+    private String description;
+
+    private BigDecimal longitude;
+
+    private BigDecimal latitude;
+
+    private String address;
+
+    private Integer radius = 100; // 有效范围(米),设置默认值以与 DB 的默认保持一致
+
+    private String coverImage;
+
+    private Integer totalWishes = 0; // 总许愿数(Redis定时同步)
+
+    private Integer isActive; // TINYINT -> Boolean 映射(Hibernate 会映射为 0/1)
+
 }

+ 2 - 5
wishing-platform/platform-service/platform-service-admin/pom.xml

@@ -28,8 +28,9 @@
         </dependency>
         <dependency>
             <groupId>cn.qinys</groupId>
-            <artifactId>platform-entity-upms</artifactId>
+            <artifactId>platform-entity-wishing</artifactId>
             <version>1.0.0-SNAPSHOT</version>
+            <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>com.alibaba.cloud</groupId>
@@ -48,10 +49,6 @@
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-jsqlparser</artifactId>
         </dependency>
-        <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>transmittable-thread-local</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.hibernate.validator</groupId>
             <artifactId>hibernate-validator</artifactId>

+ 6 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/controller/WishTreeController.java

@@ -1,6 +1,8 @@
 package cn.qinys.platform.admin.controller;
 
+import cn.qinys.platform.admin.service.WishTreeService;
 import cn.qinys.platform.base.response.UnifyResponse;
+import jakarta.annotation.Resource;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -13,6 +15,10 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("/admin/tree")
 public class WishTreeController {
+
+    @Resource
+    private WishTreeService wishTreeService;
+
     @RequestMapping("/page")
     public UnifyResponse<String> getWishTreePage() {
         return new UnifyResponse<>("wishingtree page");

+ 14 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/mapper/WishingTreeMapper.java

@@ -0,0 +1,14 @@
+package cn.qinys.platform.admin.mapper;
+
+import cn.qinys.platform.entity.wishing.WishingTree;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2026-05-23 12:41
+ **/
+@Mapper
+public interface WishingTreeMapper extends BaseMapper<WishingTree> {
+}

+ 85 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/config/MyMetaObjectHandler.java

@@ -0,0 +1,85 @@
+package cn.qinys.platform.config;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+import java.util.Objects;
+
+/**
+ * MyBatis-Plus 自动填充处理器:
+ * - 支持 Java 字段类型 LocalDateTime / java.util.Date / Long (时间戳毫秒)
+ * - 填充字段名为 createdAt / updatedAt(与实体属性匹配,不依赖数据库列名)
+ */
+@Component
+public class MyMetaObjectHandler implements MetaObjectHandler {
+
+    private static final String CREATED_FIELD = "createdAt";
+    private static final String UPDATED_FIELD = "updatedAt";
+
+    @Override
+    public void insertFill(MetaObject metaObject) {
+        // createdAt
+        Object createdVal = getFieldValByName(CREATED_FIELD, metaObject);
+        if (Objects.isNull(createdVal) && hasGetter(metaObject, CREATED_FIELD)) {
+            Class<?> type = getFieldType(metaObject, CREATED_FIELD);
+            if (type != null && LocalDateTime.class.isAssignableFrom(type)) {
+                this.setFieldValByName(CREATED_FIELD, LocalDateTime.now(), metaObject);
+            } else if (type != null && Date.class.isAssignableFrom(type)) {
+                this.setFieldValByName(CREATED_FIELD, new Date(), metaObject);
+            } else if (type != null && (Long.class.isAssignableFrom(type) || long.class.isAssignableFrom(type))) {
+                this.setFieldValByName(CREATED_FIELD, System.currentTimeMillis(), metaObject);
+            }
+        }
+
+        // updatedAt -> for insert also set updatedAt
+        Object updatedVal = getFieldValByName(UPDATED_FIELD, metaObject);
+        if (Objects.isNull(updatedVal) && hasGetter(metaObject, UPDATED_FIELD)) {
+            Class<?> type = getFieldType(metaObject, UPDATED_FIELD);
+            if (type != null && LocalDateTime.class.isAssignableFrom(type)) {
+                this.setFieldValByName(UPDATED_FIELD, LocalDateTime.now(), metaObject);
+            } else if (type != null && Date.class.isAssignableFrom(type)) {
+                this.setFieldValByName(UPDATED_FIELD, new Date(), metaObject);
+            } else if (type != null && (Long.class.isAssignableFrom(type) || long.class.isAssignableFrom(type))) {
+                this.setFieldValByName(UPDATED_FIELD, System.currentTimeMillis(), metaObject);
+            }
+        }
+    }
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        if (hasGetter(metaObject, UPDATED_FIELD)) {
+            Class<?> type = getFieldType(metaObject, UPDATED_FIELD);
+            if (type != null && LocalDateTime.class.isAssignableFrom(type)) {
+                this.setFieldValByName(UPDATED_FIELD, LocalDateTime.now(), metaObject);
+            } else if (type != null && Date.class.isAssignableFrom(type)) {
+                this.setFieldValByName(UPDATED_FIELD, new Date(), metaObject);
+            } else if (type != null && (Long.class.isAssignableFrom(type) || long.class.isAssignableFrom(type))) {
+                this.setFieldValByName(UPDATED_FIELD, System.currentTimeMillis(), metaObject);
+            }
+        }
+    }
+
+    private boolean hasGetter(MetaObject metaObject, String name) {
+        try {
+            return metaObject.hasGetter(name);
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    private Class<?> getFieldType(MetaObject metaObject, String name) {
+        try {
+            Class<?> t = metaObject.getSetterType(name);
+            if (t == null) {
+                t = metaObject.getGetterType(name);
+            }
+            return t;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+}
+