170 lines
3.7 KiB
Java
170 lines
3.7 KiB
Java
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 {
|
||
|
||
|
||
|
||
|
||
/**
|
||
* C端用户ID
|
||
*/
|
||
@Column(name = "user_id")
|
||
@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")
|
||
@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")
|
||
@Comment("是否匿名")
|
||
private Boolean isAnonymous = Boolean.FALSE;
|
||
|
||
/**
|
||
* 状态:1-正常 0-隐藏
|
||
*/
|
||
@Column(name = "status",columnDefinition = "VARCHAR(20)",length = 20)
|
||
@Comment("状态:1正常 0隐藏")
|
||
private ReviewStatus status = ReviewStatus.NORMAL;
|
||
|
||
// ========== 关联关系 ==========
|
||
|
||
/**
|
||
* 回复
|
||
*/
|
||
@OneToOne(mappedBy = "review", fetch = FetchType.LAZY)
|
||
private ReviewReply reply;
|
||
|
||
/**
|
||
* 门店
|
||
*/
|
||
@ManyToOne(fetch = FetchType.LAZY)
|
||
@JoinColumn(name = "merchant_id")
|
||
private Merchant merchant;
|
||
/**
|
||
* 门店
|
||
*/
|
||
@ManyToOne(fetch = FetchType.LAZY)
|
||
@JoinColumn(name = "store_id")
|
||
private Store store;
|
||
|
||
/**
|
||
* 订单
|
||
*/
|
||
@ManyToOne(fetch = FetchType.LAZY)
|
||
@JoinColumn(name = "order_id")
|
||
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() : "未知";
|
||
}
|
||
}
|