import { Column, Model, Table, DataType, CreatedAt, UpdatedAt, HasMany } from "sequelize-typescript"; import CustomerDepartment from "./customer_department.entity"; import CustomerAccount from "./customer_account.entity"; @Table({ tableName: "customer", comment: "客户信息表", timestamps: true, createdAt: "created_at", updatedAt: "updated_at", indexes: [ { name: "idx_customer_name", fields: ["customer_name"] }, { name: "idx_customer_salesman", fields: ["salesman_id"] }, { name: "idx_customer_status", fields: ["status"] }, { unique: true, name: "uk_customer_no", fields: ["customer_no"] } ] }) export default class Customer extends Model { @Column({ type: DataType.BIGINT, autoIncrement: true, primaryKey: true }) id!: number; @Column({ type: DataType.STRING(64), allowNull: false, unique: true, field: "customer_no", comment: "客户业务编号(KH+YYYYMMDD+序号)" }) customerNo!: string; @Column({ type: DataType.STRING(64), field: "icc_code", comment: "ICC客户编码(ICC平台 orgCode,同步来源)" }) iccCode!: string; @Column({ type: DataType.STRING(128), allowNull: false, comment: "客户名称" }) customerName!: string; @Column({ type: DataType.STRING(32), comment: "省" }) province!: string; @Column({ type: DataType.STRING(32), comment: "市" }) city!: string; @Column({ type: DataType.STRING(32), comment: "区" }) district!: string; @Column({ type: DataType.STRING(256), comment: "详细地址" }) address!: string; @Column({ type: DataType.STRING(32), field: "contact_person", comment: "联系人" }) contactPerson!: string; @Column({ type: DataType.STRING(20), field: "contact_phone", comment: "联系电话" }) contactPhone!: string; @Column({ type: DataType.STRING(10), field: "postal_code", comment: "邮编" }) postalCode!: string; @Column({ type: DataType.STRING(32), comment: "传真" }) fax!: string; @Column({ type: DataType.STRING(32), field: "customer_level", comment: "客户级别(学校/医院/企业等)" }) customerLevel!: string; @Column({ type: DataType.SMALLINT, allowNull: false, defaultValue: 1, comment: "状态:1意向/2签约/3运维中/4终止" }) status!: number; @Column({ type: DataType.BIGINT, field: "salesman_id", comment: "负责业务员(关联sys_user.id),references->sys_user.id" }) salesmanId!: number; @HasMany(() => CustomerDepartment, { foreignKey: "customerId" }) customerDepartments!: CustomerDepartment[]; @HasMany(() => CustomerAccount, { foreignKey: "customerId" }) customerAccounts!: CustomerAccount[]; @CreatedAt created_at!: Date; @UpdatedAt updated_at!: Date; }