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 {
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api
const { ids } = ctx.query;
const { exp, ids, roadLevel, municipalType } = ctx.query;
const fileList = [
{
n: '道路',
tableName: 'road',
defaultKey: ['level'],
defaultValue: ['村'],
},
{
n: '道路',
tableName: 'road',
defaultKey: ['level'],
defaultValue: ['县'],
},
if (!exp) {
throw '参数错误';
}
const modalList = [
{
n: '道路',
tableName: 'road',
defaultKey: ['level'],
defaultValue: ['乡'],
k: 'road',
tableName: 'Road',
},
{
n: '桥梁',
tableName: 'bridge'
},
{
n: '运政车辆',
tableName: 'municipal_vehicle',
defaultKey: ['type'],
defaultValue: ['出租车'],
k: 'bridge',
tableName: 'Bridge'
},
{
n: '运政车辆',
tableName: 'municipal_vehicle',
defaultKey: ['type'],
defaultValue: ['危货'],
k: 'vehicle',
tableName: 'MunicipalVehicle',
},
{
n: '运政业户',
tableName: 'municipal_business',
defaultKey: ['type'],
defaultValue: ['出租车'],
},
{
n: '运政业户',
tableName: 'municipal_business',
defaultKey: ['type'],
defaultValue: ['危货'],
},
{
n: '工程一览',
tableName: 'project',
defaultKey: ['done', 'type'],
defaultValue: [false, 'road'],
k: 'business',
tableName: 'MunicipalBusiness',
},
{
n: '工程一览',
tableName: 'project',
defaultKey: ['done', 'type'],
defaultValue: [false, 'bridge'],
k: 'project',
tableName: 'Project',
},
{
n: '治超',
tableName: 'overspeed',
k: 'overspeed',
tableName: 'Overspeed',
},
{
n: '公交线路',
tableName: 'bus_line',
k: 'busLine',
tableName: 'BusLine',
},
{
n: '公交车辆',
tableName: 'bus_car',
k: 'busCar',
tableName: 'BusCar',
},
]
const modalOption = modalList.find(item => item.k == exp);
if (!modalOption) {
throw '参数错误';
}
let findOption = {
where: {}
}
if (ids) {
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 tableAttributes = models.BusCar.tableAttributes
const exportData = await models[modalOption.tableName].findAll(findOption)
const tableAttributes = models[modalOption.tableName].tableAttributes
let header = []
for (let k in tableAttributes) {
if (k != 'id') {
@ -103,7 +88,7 @@ async function dataExport (ctx) {
}
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 fileData = fs.readFileSync(filePath);

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

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

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

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

3
api/sequelize-automate.config.js

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

Loading…
Cancel
Save