Browse Source

数据导出接口

release_0.0.4
巴林闲侠 3 years ago
parent
commit
448e0d6dd4
  1. 87
      api/app/lib/controllers/data/index.js
  2. 250
      api/app/lib/models/project.js
  3. 4
      api/app/lib/models/publicity.js
  4. 16
      api/app/lib/models/report.js
  5. 1485
      api/app/lib/models/road.js
  6. 98
      api/app/lib/models/statistic.js
  7. 3
      api/sequelize-automate.config.js

87
api/app/lib/controllers/data/index.js

@ -7,90 +7,75 @@ async function dataExport (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api const { userId } = ctx.fs.api
const { ids } = ctx.query; const { exp, ids, roadLevel, municipalType } = ctx.query;
const fileList = [ if (!exp) {
{ throw '参数错误';
n: '道路', }
tableName: 'road',
defaultKey: ['level'], const modalList = [
defaultValue: ['村'],
},
{
n: '道路',
tableName: 'road',
defaultKey: ['level'],
defaultValue: ['县'],
},
{ {
n: '道路', n: '道路',
tableName: 'road', k: 'road',
defaultKey: ['level'], tableName: 'Road',
defaultValue: ['乡'],
}, },
{ {
n: '桥梁', n: '桥梁',
tableName: 'bridge' k: 'bridge',
}, tableName: 'Bridge'
{
n: '运政车辆',
tableName: 'municipal_vehicle',
defaultKey: ['type'],
defaultValue: ['出租车'],
}, },
{ {
n: '运政车辆', n: '运政车辆',
tableName: 'municipal_vehicle', k: 'vehicle',
defaultKey: ['type'], tableName: 'MunicipalVehicle',
defaultValue: ['危货'],
}, },
{ {
n: '运政业户', n: '运政业户',
tableName: 'municipal_business', k: 'business',
defaultKey: ['type'], tableName: 'MunicipalBusiness',
defaultValue: ['出租车'],
},
{
n: '运政业户',
tableName: 'municipal_business',
defaultKey: ['type'],
defaultValue: ['危货'],
},
{
n: '工程一览',
tableName: 'project',
defaultKey: ['done', 'type'],
defaultValue: [false, 'road'],
}, },
{ {
n: '工程一览', n: '工程一览',
tableName: 'project', k: 'project',
defaultKey: ['done', 'type'], tableName: 'Project',
defaultValue: [false, 'bridge'],
}, },
{ {
n: '治超', n: '治超',
tableName: 'overspeed', k: 'overspeed',
tableName: 'Overspeed',
}, },
{ {
n: '公交线路', n: '公交线路',
tableName: 'bus_line', k: 'busLine',
tableName: 'BusLine',
}, },
{ {
n: '公交车辆', n: '公交车辆',
tableName: 'bus_car', k: 'busCar',
tableName: 'BusCar',
}, },
] ]
const modalOption = modalList.find(item => item.k == exp);
if (!modalOption) {
throw '参数错误';
}
let findOption = { let findOption = {
where: {} where: {}
} }
if (ids) { if (ids) {
findOption.where.id = { $in: ids.split(',') } findOption.where.id = { $in: ids.split(',') }
} }
if (roadLevel) {
findOption.where.level = roadLevel
}
if (municipalType) {
findOption.where.type = municipalType
}
const exportData = await models.BusCar.findAll(findOption) const exportData = await models[modalOption.tableName].findAll(findOption)
const tableAttributes = models.BusCar.tableAttributes const tableAttributes = models[modalOption.tableName].tableAttributes
let header = [] let header = []
for (let k in tableAttributes) { for (let k in tableAttributes) {
if (k != 'id') { if (k != 'id') {
@ -103,7 +88,7 @@ async function dataExport (ctx) {
} }
header.sort((a, b) => { return a.index - b.index }) header.sort((a, b) => { return a.index - b.index })
const fileName = `摄像头信息列表_${moment().format('YYYYMMDDHHmmss')}` + '.csv' const fileName = `${modalOption.n}_${moment().format('YYYYMMDDHHmmss')}` + '.csv'
const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName }) const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName })
const fileData = fs.readFileSync(filePath); const fileData = fs.readFileSync(filePath);

250
api/app/lib/models/project.js

@ -2,123 +2,135 @@
'use strict'; 'use strict';
module.exports = dc => { module.exports = dc => {
const DataTypes = dc.ORM; const DataTypes = dc.ORM;
const sequelize = dc.orm; const sequelize = dc.orm;
const Project = sequelize.define("project", { const Project = sequelize.define("project", {
id: { id: {
type: DataTypes.INTEGER, index: 1,
allowNull: false, type: DataTypes.INTEGER,
defaultValue: null, allowNull: false,
comment: null, defaultValue: null,
primaryKey: true, comment: null,
field: "id", primaryKey: true,
autoIncrement: true, field: "id",
unique: "project_id_uindex" autoIncrement: true,
}, unique: "project_id_uindex"
entryName: { },
type: DataTypes.STRING, entryName: {
allowNull: true, index: 2,
defaultValue: null, type: DataTypes.STRING,
comment: "项目名称", allowNull: true,
primaryKey: false, defaultValue: null,
field: "entry_name", comment: "项目名称",
autoIncrement: false primaryKey: false,
}, field: "entry_name",
projectMileage: { autoIncrement: false
type: DataTypes.STRING, },
allowNull: true, projectMileage: {
defaultValue: null, index: 3,
comment: "工程里程", type: DataTypes.STRING,
primaryKey: false, allowNull: true,
field: "project_mileage", defaultValue: null,
autoIncrement: false comment: "工程里程",
}, primaryKey: false,
investment: { field: "project_mileage",
type: DataTypes.STRING, autoIncrement: false
allowNull: true, },
defaultValue: null, investment: {
comment: "投资", index: 4,
primaryKey: false, type: DataTypes.STRING,
field: "investment", allowNull: true,
autoIncrement: false defaultValue: null,
}, comment: "投资",
buildUnit: { primaryKey: false,
type: DataTypes.STRING, field: "investment",
allowNull: true, autoIncrement: false
defaultValue: null, },
comment: "建设单位", buildUnit: {
primaryKey: false, index: 5,
field: "build_unit", type: DataTypes.STRING,
autoIncrement: false allowNull: true,
}, defaultValue: null,
constructionControlUnit: { comment: "建设单位",
type: DataTypes.STRING, primaryKey: false,
allowNull: true, field: "build_unit",
defaultValue: null, autoIncrement: false
comment: "监理单位", },
primaryKey: false, constructionControlUnit: {
field: "construction_control_unit", index: 6,
autoIncrement: false type: DataTypes.STRING,
}, allowNull: true,
designUnit: { defaultValue: null,
type: DataTypes.STRING, comment: "监理单位",
allowNull: true, primaryKey: false,
defaultValue: null, field: "construction_control_unit",
comment: "设计单位", autoIncrement: false
primaryKey: false, },
field: "design_unit", designUnit: {
autoIncrement: false index: 7,
}, type: DataTypes.STRING,
constructionUnit: { allowNull: true,
type: DataTypes.STRING, defaultValue: null,
allowNull: true, comment: "设计单位",
defaultValue: null, primaryKey: false,
comment: "施工单位", field: "design_unit",
primaryKey: false, autoIncrement: false
field: "construction_unit", },
autoIncrement: false constructionUnit: {
}, index: 8,
supervisorAndSupervisor: { type: DataTypes.STRING,
type: DataTypes.STRING, allowNull: true,
allowNull: true, defaultValue: null,
defaultValue: null, comment: "施工单位",
comment: "监督负责人及监督人员", primaryKey: false,
primaryKey: false, field: "construction_unit",
field: "supervisor_and_supervisor", autoIncrement: false
autoIncrement: false },
}, supervisorAndSupervisor: {
projectProgress: { index: 9,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "项目进展情况", comment: "监督负责人及监督人员",
primaryKey: false, primaryKey: false,
field: "project_progress", field: "supervisor_and_supervisor",
autoIncrement: false autoIncrement: false
}, },
done: { projectProgress: {
type: DataTypes.BOOLEAN, index: 10,
allowNull: false, type: DataTypes.STRING,
defaultValue: null, allowNull: true,
comment: null, defaultValue: null,
primaryKey: false, comment: "项目进展情况",
field: "done", primaryKey: false,
autoIncrement: false field: "project_progress",
}, autoIncrement: false
type: { },
type: DataTypes.STRING, done: {
allowNull: false, index: 11,
defaultValue: null, type: DataTypes.BOOLEAN,
comment: "类型 道路:road / 桥梁:bridge", allowNull: false,
primaryKey: false, defaultValue: null,
field: "type", comment: null,
autoIncrement: false primaryKey: false,
} field: "done",
}, { autoIncrement: false
tableName: "project", },
comment: "", type: {
indexes: [] index: 12,
}); type: DataTypes.STRING,
dc.models.Project = Project; allowNull: false,
return Project; defaultValue: null,
comment: "类型 道路:road / 桥梁:bridge",
primaryKey: false,
field: "type",
autoIncrement: false
}
}, {
tableName: "project",
comment: "",
indexes: []
});
dc.models.Project = Project;
return Project;
}; };

4
api/app/lib/models/publicity.js

@ -6,6 +6,7 @@ module.exports = dc => {
const sequelize = dc.orm; const sequelize = dc.orm;
const Publicity = sequelize.define("publicity", { const Publicity = sequelize.define("publicity", {
id: { id: {
index: 1,
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
@ -16,6 +17,7 @@ module.exports = dc => {
unique: "publicity_id_uindex" unique: "publicity_id_uindex"
}, },
name: { name: {
index: 2,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
@ -25,6 +27,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
video: { video: {
index: 3,
type: DataTypes.ARRAY(DataTypes.INTEGER), type: DataTypes.ARRAY(DataTypes.INTEGER),
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -34,6 +37,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
enable: { enable: {
index: 4,
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
allowNull: false, allowNull: false,
defaultValue: true, defaultValue: true,

16
api/app/lib/models/report.js

@ -6,6 +6,7 @@ module.exports = dc => {
const sequelize = dc.orm; const sequelize = dc.orm;
const Report = sequelize.define("report", { const Report = sequelize.define("report", {
id: { id: {
index: 1,
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
@ -16,6 +17,7 @@ module.exports = dc => {
unique: "report_id_uindex" unique: "report_id_uindex"
}, },
reportType: { reportType: {
index: 2,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
@ -25,6 +27,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
projectType: { projectType: {
index: 3,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
@ -34,6 +37,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
road: { road: {
index: 4,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -43,6 +47,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
roadSectionStart: { roadSectionStart: {
index: 5,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -52,6 +57,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
roadSectionEnd: { roadSectionEnd: {
index: 6,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -61,6 +67,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
longitude: { longitude: {
index: 7,
type: DataTypes.DOUBLE, type: DataTypes.DOUBLE,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -70,6 +77,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
latitude: { latitude: {
index: 8,
type: DataTypes.DOUBLE, type: DataTypes.DOUBLE,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -79,6 +87,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
content: { content: {
index: 9,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -88,6 +97,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
scenePic: { scenePic: {
index: 10,
type: DataTypes.ARRAY(DataTypes.STRING), type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -97,6 +107,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
conserveBeforePic: { conserveBeforePic: {
index: 11,
type: DataTypes.ARRAY(DataTypes.STRING), type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -106,6 +117,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
conserveUnderwayPic: { conserveUnderwayPic: {
index: 12,
type: DataTypes.ARRAY(DataTypes.STRING), type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -115,6 +127,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
conserveAfterPic: { conserveAfterPic: {
index: 13,
type: DataTypes.ARRAY(DataTypes.STRING), type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -124,6 +137,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
userId: { userId: {
index: 14,
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -133,6 +147,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
time: { time: {
index: 15,
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
@ -142,6 +157,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
address: { address: {
index: 16,
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,

1485
api/app/lib/models/road.js

File diff suppressed because it is too large

98
api/app/lib/models/statistic.js

@ -2,51 +2,55 @@
'use strict'; 'use strict';
module.exports = dc => { module.exports = dc => {
const DataTypes = dc.ORM; const DataTypes = dc.ORM;
const sequelize = dc.orm; const sequelize = dc.orm;
const Statistic = sequelize.define("statistic", { const Statistic = sequelize.define("statistic", {
id: { id: {
type: DataTypes.INTEGER, index: 1,
allowNull: false, type: DataTypes.INTEGER,
defaultValue: null, allowNull: false,
comment: null, defaultValue: null,
primaryKey: true, comment: null,
field: "id", primaryKey: true,
autoIncrement: true, field: "id",
unique: "vehicle_id_uindex" autoIncrement: true,
}, unique: "vehicle_id_uindex"
name: { },
type: DataTypes.STRING, name: {
allowNull: false, index: 2,
defaultValue: null, type: DataTypes.STRING,
comment: null, allowNull: false,
primaryKey: false, defaultValue: null,
field: "name", comment: null,
autoIncrement: false primaryKey: false,
}, field: "name",
count: { autoIncrement: false
type: DataTypes.INTEGER, },
allowNull: false, count: {
defaultValue: "0", index: 3,
comment: null, type: DataTypes.INTEGER,
primaryKey: false, allowNull: false,
field: "count", defaultValue: "0",
autoIncrement: false comment: null,
}, primaryKey: false,
type: { field: "count",
type: DataTypes.STRING, autoIncrement: false
allowNull: false, },
defaultValue: null, type: {
comment: null, index: 4,
primaryKey: false, type: DataTypes.STRING,
field: "type", allowNull: false,
autoIncrement: false defaultValue: null,
} comment: null,
}, { primaryKey: false,
tableName: "statistic", field: "type",
comment: "", autoIncrement: false
indexes: [] }
}); }, {
dc.models.Statistic = Statistic; tableName: "statistic",
return Statistic; comment: "",
indexes: []
});
dc.models.Statistic = Statistic;
return Statistic;
}; };

3
api/sequelize-automate.config.js

@ -18,6 +18,7 @@ module.exports = {
timestamps: false, timestamps: false,
}, },
}, },
// !!! 所有 model 都有自定义脚本所不能生成的内容 执行此脚本需谨慎
options: { options: {
type: 'freesun', // 指定 models 代码风格 type: 'freesun', // 指定 models 代码风格
camelCase: true, // Models 文件中代码是否使用驼峰命名 camelCase: true, // Models 文件中代码是否使用驼峰命名
@ -27,7 +28,7 @@ module.exports = {
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
tables: null, // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 tables: null, // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
skipTables: ['report', 'publicity'], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面
attrLength: false, // 在生成模型的字段中 是否生成 如 var(128)这种格式,公司一般使用 String ,则配置为 false attrLength: false, // 在生成模型的字段中 是否生成 如 var(128)这种格式,公司一般使用 String ,则配置为 false

Loading…
Cancel
Save