请解释如下代码,并使用ES6+改进
"use strict";
module.exports = function (t) {
var {
BIGINT: e,
STRING: a,
TINYINT: r,
INTEGER: i,
DECIMAL: s,
} = t.Sequelize;
return t.model.define(
"tower",
{
id: { type: i, primaryKey: !0, autoIncrement: !0 },
parent_id: a(12),
user_id: a(12),
area_path: a(128),
tower_id: a(64),
tower_type: a(24),
location: { type: t.Sequelize.GEOMETRY("POINT"), allowNull: !0 },
gps_height: s(8, 2),
name: a(32),
remark: a(2048),
ext_info: {
type: a(5024),
defaultValue: "{}",
set: function (t) {
"object" == typeof (t = t || {}) && (t = JSON.stringify(t)),
this.setDataValue("ext_info", t);
},
get: function () {
let t = this.getDataValue("ext_info");
return t ? (t = "object" != typeof t ? JSON.parse(t) : t) : {};
},
},
last_time: e,
last_ip: a(64),
status: { type: r, defaultValue: 0 },
health: { type: r, defaultValue: 0 },
},
{
indexes: [
{ method: "Hash", fields: ["parent_id"] },
{ method: "Hash", fields: ["user_id"] },
{ method: "Hash", fields: ["area_path"] },
{ method: "Hash", fields: ["tower_id"] },
{ method: "Hash", fields: ["tower_type"] },
{ method: "Hash", fields: ["status"] },
],
getterMethods: {
status_name: function () {
try {
return ["删除", "停用", "离线", "在线"][
this.getDataValue("status") + 2
];
} catch (t) {
return "未知";
}
},
area_id: function () {
var t = this.getDataValue("area_path");
try {
return t.substr(t.lastIndexOf("/") + 1);
} catch (t) {
return "";
}
},
lat: function () {
var t = this.getDataValue("location");
try {
return t.coordinates[1];
} catch (t) {
return "";
}
},
lng: function () {
var t = this.getDataValue("location");
try {
return t.coordinates[0];
} catch (t) {
return "";
}
},
},
}
);
};