首次提交

This commit is contained in:
guotao 2026-01-09 12:20:24 +08:00
commit 1101681331
131 changed files with 7017 additions and 0 deletions

View file

@ -0,0 +1,168 @@
package com.xjhs.findmemerchant.entity;
import com.xjhs.findmemerchant.common.jpa.AbstractBaseEntity;
import com.xjhs.findmemerchant.types.ReviewStatus;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
/**
* 用户评价C端共享
* 对应表reviews
*/
@Getter
@Setter
@Entity
@Table(
name = "reviews",
indexes = {
@Index(name = "idx_reviews_order_id", columnList = "order_id"),
@Index(name = "idx_reviews_merchant_id", columnList = "merchant_id"),
@Index(name = "idx_reviews_store_id", columnList = "store_id"),
@Index(name = "idx_reviews_user_id", columnList = "user_id"),
@Index(name = "idx_reviews_created_at", columnList = "created_at")
}
)
public class Review extends AbstractBaseEntity {
/**
* 订单ID
*/
@Column(name = "order_id", nullable = false)
@Comment("订单ID")
private Long orderId;
/**
* C端用户ID
*/
@Column(name = "user_id", nullable = false)
@Comment("C端用户ID")
private Long userId;
/**
* 用户昵称
*/
@Column(name = "user_name", length = 50)
@Comment("用户昵称")
private String userName;
/**
* 用户头像
*/
@Column(name = "user_avatar", length = 255)
@Comment("用户头像URL")
private String userAvatar;
/**
* 评分 1-5
*/
@Column(name = "rating", nullable = false)
@Comment("评分 1-5")
private Integer rating;
/**
* 评价内容
*/
@Column(name = "content", columnDefinition = "text")
@Comment("评价内容")
private String content;
/**
* 图片URL逗号分隔
*/
@Column(name = "images", length = 1000)
@Comment("评价图片URL逗号分隔")
private String images;
/**
* 是否匿名
*/
@Column(name = "is_anonymous", nullable = false)
@Comment("是否匿名")
private Boolean isAnonymous = Boolean.FALSE;
/**
* 状态1-正常 0-隐藏
*/
@Column(name = "status",columnDefinition = "VARCHAR(20)",length = 20, nullable = false)
@Comment("状态1正常 0隐藏")
private ReviewStatus status = ReviewStatus.NORMAL;
// ========== 关联关系 ==========
/**
* 回复
*/
@OneToOne(mappedBy = "review", fetch = FetchType.LAZY)
private ReviewReply reply;
/**
* 门店
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id", insertable = false, updatable = false)
private Store store;
/**
* 订单
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id", insertable = false, updatable = false)
private Order order;
// ========== 业务方法 ==========
/**
* 评分文案
*/
public String getRatingText() {
if (rating == null) {
return "未知";
}
return switch (rating) {
case 5 -> "非常满意";
case 4 -> "满意";
case 3 -> "一般";
case 2 -> "不满意";
case 1 -> "非常不满意";
default -> "未知";
};
}
/**
* 是否好评4-5星
*/
public boolean isPositive() {
return rating != null && rating >= 4;
}
/**
* 是否差评1-2星
*/
public boolean isNegative() {
return rating != null && rating <= 2;
}
/**
* 展示用昵称匿名/真实
*/
public String getDisplayName() {
if (Boolean.TRUE.equals(isAnonymous)) {
return "匿名用户";
}
return userName;
}
public ReviewStatus getStatusEnum() {
return this.status;
}
public String getStatusText() {
ReviewStatus e = getStatusEnum();
return e != null ? e.getDesc() : "未知";
}
}