const { DataTypes } = require('sequelize'); const connect = require('./connect'); const { isProd } = require('../../config'); /* type: DataTypes.STRING, allowNull: false, defaultValue:'', comment: '名', */ function formatTime(m) { // m.reserves && (m.reserves = JSON.parse(m.reserves)); // m.reservesExtent && (m.reservesExtent = JSON.parse(m.reservesExtent)); // m.reservesResult && (m.reservesResult = JSON.parse(m.reservesResult)); // m.sampleResult && (m.sampleResult = JSON.parse(m.sampleResult)); // m.extra && (m.extra = JSON.parse(m.extra)); // m.adapt && (m.adapt = JSON.parse(m.adapt)); // m.turn && (m.turn = JSON.parse(m.turn)); // m.plant && (m.plant = JSON.parse(m.plant)); // m.landUse && (m.landUse = JSON.parse(m.landUse)); // m.boundary && (m.boundary = JSON.parse(m.boundary)); } 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', }, extent: { type: DataTypes.DECIMAL(12, 2), defaultValue: 0, comment: '项目区域面积', }, sCount: { type: DataTypes.INTEGER, defaultValue: 0, comment: '样地数', }, conclusion: { type: DataTypes.STRING, defaultValue: '', comment: '结论内容', }, field: { type: DataTypes.DECIMAL(12, 2), defaultValue: 0, comment: '实地监测碳减量', }, satellite: { type: DataTypes.DECIMAL(12, 2), defaultValue: 0, comment: '卫星监测碳减量', }, boundary: { type: DataTypes.JSON, comment: '上传项目边界', }, landUse: { type: DataTypes.JSON, comment: '上传土地利用情况', }, plant: { type: DataTypes.JSON, comment: '植物净初级生产力', }, turn: { type: DataTypes.JSON, comment: '碳逆转风险监测', }, adapt: { type: DataTypes.JSON, comment: '适应性条件检查', }, extra: { type: DataTypes.JSON, comment: '额外性论证检查', }, sampleResult: { type: DataTypes.JSON, comment: '样地抽样结果', }, reservesResult: { type: DataTypes.JSON, comment: '碳储量监测结果', }, contrast: { type: DataTypes.STRING, comment: '对比数据上传', }, reservesExtent: { type: DataTypes.JSON, comment: '单位面积碳储量', }, reserves: { type: DataTypes.JSON, 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;