findme-backend-merchant-java/src/main/java/com/xjhs/findmemerchant/entity/Employee.java
2026-01-09 12:20:24 +08:00

103 lines
2.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.xjhs.findmemerchant.entity;
import com.xjhs.findmemerchant.common.jpa.AbstractBaseEntity;
import com.xjhs.findmemerchant.types.CommonStatus;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
/**
* 员工实体
* 对应表employees
*/
@Getter
@Setter
@Entity
@Table(
name = "employees",
indexes = {
@Index(name = "idx_employees_merchant_id", columnList = "merchant_id"),
@Index(name = "idx_employees_store_id", columnList = "store_id"),
@Index(name = "idx_employees_role_id", columnList = "role_id"),
@Index(name = "idx_employees_phone", columnList = "phone")
}
)
public class Employee extends AbstractBaseEntity {
/**
* 手机号
*/
@Column(name = "phone", nullable = false, length = 11)
@Comment("手机号")
private String phone;
/**
* 员工姓名
*/
@Column(name = "name", nullable = false, length = 50)
@Comment("员工姓名")
private String name;
/**
* 状态0-禁用 1-启用
*/
@Column(name = "status",columnDefinition = "VARCHAR(15)",length = 15, nullable = false)
@Comment("状态0禁用 1启用")
private CommonStatus status = CommonStatus.ENABLED;
// ===== 关联关系 =====
/**
* 商户
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "merchant_id", insertable = false, updatable = false)
private Merchant merchant;
/**
* 门店
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id", insertable = false, updatable = false)
private Store store;
/**
* 角色
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id", insertable = false, updatable = false)
private Role role;
// ===== 业务方法 =====
/**
* 是否为启用状态
*/
public boolean isActive() {
return this.status == CommonStatus.ENABLED;
}
/**
* 状态文案
*/
public String getStatusText() {
CommonStatus e = this.status;
return e != null ? e.getDesc() : "未知";
}
/**
* 返回脱敏手机号例如138****1234
*/
public String maskPhone() {
if (phone == null || phone.length() != 11) {
return phone;
}
return phone.substring(0, 3) + "****" + phone.substring(7);
}
}