const { DataTypes } = require('sequelize'); const connect = require('./connect'); const { isProd } = require('../../config'); /* type: DataTypes.STRING, allowNull: false, defaultValue:'', comment: '名', */ function formatTime(m) { // m.ratio && (m.ratio = JSON.parse(m.ratio)); } const model = connect.define( __filename.slice(__dirname.length + 1).replace('.js', ''), { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, comment: 'id', }, name: { type: DataTypes.STRING, allowNull: false, defaultValue: '', comment: '样本名', }, cityId: { type: DataTypes.INTEGER, defaultValue: 0, comment: '城市ID', }, provinceId: { type: DataTypes.INTEGER, defaultValue: 0, comment: '省ID', }, regionId: { type: DataTypes.INTEGER, defaultValue: 0, comment: '区域ID', }, volume: { type: DataTypes.DECIMAL(12, 2), defaultValue: 0, comment: '积蓄量', }, reserves: { type: DataTypes.DECIMAL(12, 2), defaultValue: 0, comment: '储蓄量', }, plantCount: { type: DataTypes.INTEGER, defaultValue: 0, comment: '种植总量', }, treeHeight: { type: DataTypes.DECIMAL(12, 2), defaultValue: 0, comment: '树高', }, treeDiameter: { type: DataTypes.DECIMAL(12, 2), defaultValue: 0, comment: '树径', }, img: { type: DataTypes.STRING, defaultValue: '', comment: '样本影像', }, result: { type: DataTypes.STRING, defaultValue: '', comment: '样本结果', }, report: { type: DataTypes.STRING, defaultValue: '', comment: '报告', }, ratio: { type: DataTypes.JSON, comment: '成长系数', }, lastTime: { type: DataTypes.STRING, defaultValue: '', comment: '上次修改时间', }, time: { type: DataTypes.STRING, defaultValue: '', comment: '样本时间', }, }, { comment: '样本', hooks: { beforeFind(option) { if (!option.order) { option.order = [['id', 'desc']]; } }, afterFind(m) { m && (Array.isArray(m) ? m.forEach(item => formatTime(item)) : formatTime(m)); }, }, } ); module.exports = model;