deartibers
2 years ago
29 changed files with 995 additions and 91 deletions
@ -0,0 +1,257 @@ |
|||
'use strict'; |
|||
const moment = require('moment') |
|||
|
|||
async function get (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
const { limit, page, orderBy, orderDirection, keyword, forbidden, paraphraseCustom } = ctx.query |
|||
|
|||
const sequelize = ctx.fs.dc.ORM; |
|||
let findOption = { |
|||
attributes: { |
|||
include: [ |
|||
[sequelize.fn('COUNT', sequelize.col('cameraStatusLogs.id')), 'logCount'] |
|||
] |
|||
}, |
|||
where: {}, |
|||
order: [ |
|||
[orderBy || 'id', orderDirection || 'DESC'] |
|||
], |
|||
distinct: true, |
|||
subQuery: false, |
|||
group: [ |
|||
'cameraStatus.id', |
|||
'cameraStatusLogs.status_id', |
|||
// 'cameraStatusResolves.id'
|
|||
], |
|||
include: [ |
|||
// {
|
|||
// model: models.CameraStatusResolve,
|
|||
// attributes: { exclude: ['statusId'] },
|
|||
// required: false,
|
|||
// duplicating: true
|
|||
// },
|
|||
{ |
|||
model: models.CameraStatusLog, |
|||
attributes: [], |
|||
duplicating: false, |
|||
required: false, |
|||
} |
|||
], |
|||
} |
|||
if (orderBy) { |
|||
if (orderBy == 'logCount') { |
|||
findOption.order = sequelize.literal(`"logCount" ${orderDirection || 'DESC'}`) |
|||
} |
|||
} |
|||
if (limit) { |
|||
findOption.limit = limit |
|||
} |
|||
if (page && limit) { |
|||
findOption.offset = page * limit |
|||
} |
|||
if (keyword) { |
|||
findOption.where['$or'] = { |
|||
describe: { |
|||
$like: `%${keyword}%` |
|||
}, |
|||
paraphrase: { |
|||
$like: `%${keyword}%` |
|||
}, |
|||
paraphraseCustom: { |
|||
$like: `%${keyword}%` |
|||
}, |
|||
} |
|||
} |
|||
if (forbidden) { |
|||
if (forbidden === 'true') { |
|||
findOption.where.forbidden = true |
|||
} else if (forbidden === 'false') { |
|||
findOption.where.forbidden = false |
|||
} |
|||
} |
|||
if (paraphraseCustom) { |
|||
if (paraphraseCustom === 'true') { |
|||
findOption.where.paraphraseCustom = null |
|||
} else if (paraphraseCustom === 'false') { |
|||
findOption.where.paraphraseCustom = { |
|||
$ne: null |
|||
} |
|||
} |
|||
} |
|||
|
|||
const statusRes = await models.CameraStatus.findAll(findOption) |
|||
|
|||
delete findOption.order |
|||
delete findOption.limit |
|||
delete findOption.offset |
|||
delete findOption.attributes |
|||
delete findOption.group |
|||
const count = await models.CameraStatus.count(findOption) |
|||
|
|||
const statusIds = statusRes.map(r => r.id) |
|||
const statusResolveRes = await models.CameraStatusResolve.findAll({ |
|||
where: { |
|||
statusId: { |
|||
$in: statusIds |
|||
} |
|||
} |
|||
}) |
|||
|
|||
for (let { dataValues: s } of statusRes) { |
|||
const corResolve = statusResolveRes.filter(r => r.statusId === s.id) |
|||
s.resolve = corResolve |
|||
} |
|||
|
|||
ctx.status = 200; |
|||
ctx.body = { |
|||
count, |
|||
rows: statusRes, |
|||
} |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function getSimpleAll (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const statusRes = await models.CameraStatus.findAll({ |
|||
attributes: ['id', 'platform', 'status', 'describe'], |
|||
}) |
|||
ctx.status = 200; |
|||
ctx.body = statusRes |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function banned (ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const data = ctx.request.body; |
|||
|
|||
// 库记录
|
|||
await models.CameraStatus.update({ |
|||
forbidden: data.forbidden |
|||
}, { |
|||
where: { |
|||
id: data.statusId |
|||
} |
|||
}) |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function paraphraseCustom (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
const data = ctx.request.body |
|||
|
|||
await models.CameraStatus.update({ |
|||
paraphraseCustom: data.paraphrase, |
|||
}, { |
|||
where: { |
|||
id: { $in: data.statusId } |
|||
} |
|||
}) |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function resolveEdit (ctx) { |
|||
const transaction = await ctx.fs.dc.orm.transaction(); |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
const data = ctx.request.body |
|||
|
|||
await models.CameraStatusResolve.destroy({ |
|||
where: { |
|||
statusId: data.statusId |
|||
}, |
|||
transaction |
|||
}) |
|||
|
|||
await models.CameraStatusResolve.bulkCreate( |
|||
data.resolve.map(r => { |
|||
return { |
|||
statusId: data.statusId, |
|||
resolve: r |
|||
} |
|||
}), |
|||
{ transaction } |
|||
) |
|||
|
|||
await transaction.commit(); |
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
await transaction.rollback(); |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function statusCheck (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
const { status, platform, describe } = ctx.query |
|||
|
|||
if (!status || !platform) { |
|||
throw 'status and platform is required' |
|||
} |
|||
|
|||
const statusRes = await models.CameraStatus.findOne({ |
|||
where: { |
|||
status, |
|||
platform, |
|||
}, |
|||
include: [{ |
|||
model: models.CameraStatusResolve, |
|||
attributes: { exclude: ['statusId'] }, |
|||
}], |
|||
}) |
|||
|
|||
if (!statusRes && describe) { |
|||
await models.CameraStatus.create({ |
|||
status, platform, describe |
|||
}) |
|||
} |
|||
|
|||
ctx.status = 200; |
|||
ctx.body = statusRes |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
get, |
|||
getSimpleAll, |
|||
banned, |
|||
paraphraseCustom, |
|||
resolveEdit, |
|||
statusCheck, |
|||
}; |
@ -0,0 +1,85 @@ |
|||
'use strict'; |
|||
const moment = require('moment') |
|||
|
|||
async function edit (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function get (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function banned (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function del (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function copy (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
async function detail (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { userId, token } = ctx.fs.api |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
|
|||
module.exports = { |
|||
edit, get, banned, del, copy, detail |
|||
}; |
@ -0,0 +1,79 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatus = sequelize.define("cameraStatus", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_status_id_uindex" |
|||
}, |
|||
platform: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "平台分类 yingshi gb", |
|||
primaryKey: false, |
|||
field: "platform", |
|||
autoIncrement: false |
|||
}, |
|||
status: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "status", |
|||
autoIncrement: false |
|||
}, |
|||
describe: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "错误描述", |
|||
primaryKey: false, |
|||
field: "describe", |
|||
autoIncrement: false |
|||
}, |
|||
paraphrase: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "释义", |
|||
primaryKey: false, |
|||
field: "paraphrase", |
|||
autoIncrement: false |
|||
}, |
|||
forbidden: { |
|||
type: DataTypes.BOOLEAN, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "是否禁用", |
|||
primaryKey: false, |
|||
field: "forbidden", |
|||
autoIncrement: false |
|||
}, |
|||
paraphraseCustom: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "自定义释义", |
|||
primaryKey: false, |
|||
field: "paraphrase_custom", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "camera_status", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatus = CameraStatus; |
|||
return CameraStatus; |
|||
}; |
@ -0,0 +1,47 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatusLog = sequelize.define("cameraStatusLog", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_status_log_id_uindex_2" |
|||
}, |
|||
statusId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "status_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "cameraStatus" |
|||
} |
|||
}, |
|||
time: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "time", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "camera_status_log", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatusLog = CameraStatusLog; |
|||
return CameraStatusLog; |
|||
}; |
@ -0,0 +1,79 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatusPushConfig = sequelize.define("cameraStatusPushConfig", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_online_status_push_config_id_uindex" |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "name", |
|||
autoIncrement: false |
|||
}, |
|||
pushWay: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "推送方式 email / phone", |
|||
primaryKey: false, |
|||
field: "push_way", |
|||
autoIncrement: false |
|||
}, |
|||
noticeWay: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "通知方式 offline / online / timing", |
|||
primaryKey: false, |
|||
field: "notice_way", |
|||
autoIncrement: false |
|||
}, |
|||
createUser: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_user", |
|||
autoIncrement: false |
|||
}, |
|||
forbidden: { |
|||
type: DataTypes.BOOLEAN, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "forbidden", |
|||
autoIncrement: false |
|||
}, |
|||
timing: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "定时推送时间", |
|||
primaryKey: false, |
|||
field: "timing", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "camera_status_push_config", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatusPushConfig = CameraStatusPushConfig; |
|||
return CameraStatusPushConfig; |
|||
}; |
@ -0,0 +1,61 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatusPushLog = sequelize.define("cameraStatusPushLog", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_status_push_log_id_uindex" |
|||
}, |
|||
pushConfigId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "push_config_id", |
|||
autoIncrement: false |
|||
}, |
|||
receiver: { |
|||
type: DataTypes.JSONB, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "receiver", |
|||
autoIncrement: false |
|||
}, |
|||
time: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "time", |
|||
autoIncrement: false |
|||
}, |
|||
pushWay: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "push_way", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "camera_status_push_log", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatusPushLog = CameraStatusPushLog; |
|||
return CameraStatusPushLog; |
|||
}; |
@ -0,0 +1,51 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatusPushMonitor = sequelize.define("cameraStatusPushMonitor", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_status_push_monitor_id_uindex" |
|||
}, |
|||
configId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "config_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "cameraStatusPushConfig" |
|||
} |
|||
}, |
|||
cameraId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "camera_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "camera" |
|||
} |
|||
} |
|||
}, { |
|||
tableName: "camera_status_push_monitor", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatusPushMonitor = CameraStatusPushMonitor; |
|||
return CameraStatusPushMonitor; |
|||
}; |
@ -0,0 +1,47 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatusPushReceiver = sequelize.define("cameraStatusPushReceiver", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_status_push_receiver_id_uindex" |
|||
}, |
|||
configId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "config_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "cameraStatusPushConfig" |
|||
} |
|||
}, |
|||
receiver: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "接受者信息 邮箱或者电话号码", |
|||
primaryKey: false, |
|||
field: "receiver", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "camera_status_push_receiver", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatusPushReceiver = CameraStatusPushReceiver; |
|||
return CameraStatusPushReceiver; |
|||
}; |
@ -0,0 +1,47 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CameraStatusResolve = sequelize.define("cameraStatusResolve", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "camera_status_resolve_id_uindex" |
|||
}, |
|||
statusId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "status_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "cameraStatus" |
|||
} |
|||
}, |
|||
resolve: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "resolve", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "camera_status_resolve", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CameraStatusResolve = CameraStatusResolve; |
|||
return CameraStatusResolve; |
|||
}; |
@ -0,0 +1,44 @@ |
|||
'use strict'; |
|||
|
|||
const status = require('../../controllers/status'); |
|||
const push = require('../../controllers/status/push'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
app.fs.api.logAttr['GET/status'] = { content: '获取状态码', visible: false }; |
|||
router.get('/status', status.get); |
|||
|
|||
app.fs.api.logAttr['GET/status/simple_all'] = { content: '获取全部状态码简略信息', visible: false }; |
|||
router.get('/status/simple_all', status.getSimpleAll); |
|||
|
|||
app.fs.api.logAttr['PUT/status/banned'] = { content: '禁用状态码自定义', visible: false }; |
|||
router.put('/status/banned', status.banned); |
|||
|
|||
app.fs.api.logAttr['POST/status/custom'] = { content: '自定义状态码释义', visible: false }; |
|||
router.post('/status/custom', status.paraphraseCustom); |
|||
|
|||
app.fs.api.logAttr['POST/status/resolve'] = { content: '编辑解决方案', visible: false }; |
|||
router.post('/status/resolve', status.resolveEdit); |
|||
|
|||
app.fs.api.logAttr['GET/status/check'] = { content: '查取指定状态码信息', visible: false }; |
|||
router.get('/status/check', status.statusCheck); |
|||
|
|||
// 信鸽推送
|
|||
app.fs.api.logAttr['POST/status/push'] = { content: '编辑推送配置', visible: false }; |
|||
router.post('/status/push', push.edit); |
|||
|
|||
app.fs.api.logAttr['GET/status/push'] = { content: '获取推送配置', visible: false }; |
|||
router.get('/status/push', push.get); |
|||
|
|||
app.fs.api.logAttr['PUT/status/push/banned'] = { content: '禁用推送配置', visible: false }; |
|||
router.put('/status/push/banned', push.banned); |
|||
|
|||
app.fs.api.logAttr['DEL/status/push/:pushId'] = { content: '删除推送配置', visible: false }; |
|||
router.delete('/status/push/:pushId', push.del); |
|||
|
|||
app.fs.api.logAttr['GET/status/push/:pushId/copy'] = { content: '赋值推送配置', visible: false }; |
|||
router.get('/status/push/:pushId/copy', push.copy); |
|||
|
|||
app.fs.api.logAttr['GET/status/push/:pushId/detail'] = { content: '获取推送配置详情', visible: false }; |
|||
router.get('/status/push/:pushId/detail', push.detail); |
|||
// 信鸽推送 END
|
|||
}; |
@ -0,0 +1,3 @@ |
|||
{ |
|||
"editor.wordWrap": "on" |
|||
} |
@ -0,0 +1,17 @@ |
|||
{ |
|||
// 使用 IntelliSense 了解相关属性。 |
|||
// 悬停以查看现有属性的描述。 |
|||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 |
|||
"version": "0.2.0", |
|||
"configurations": [ |
|||
{ |
|||
"type": "node", |
|||
"request": "launch", |
|||
"name": "启动程序", |
|||
"skipFiles": [ |
|||
"<node_internals>/**" |
|||
], |
|||
"program": "${workspaceFolder}\\index.js" |
|||
} |
|||
] |
|||
} |
@ -0,0 +1,69 @@ |
|||
try { |
|||
const { Pool, Client } = require('pg') |
|||
const XLSX = require('xlsx') |
|||
const path = require('path') |
|||
|
|||
// 连接数据库
|
|||
const pool = new Pool({ |
|||
user: 'postgres', |
|||
host: '10.8.30.32', |
|||
database: 'video_access', |
|||
password: '123', |
|||
port: 5432, |
|||
}) |
|||
|
|||
const fun = async () => { |
|||
// note: we don't try/catch this because if connecting throws an exception
|
|||
// we don't need to dispose of the client (it will be undefined)
|
|||
const client = await pool.connect() |
|||
try { |
|||
await client.query('BEGIN') |
|||
|
|||
// 读取数据文件
|
|||
let workbook = XLSX.readFile(path.join(__dirname, '云录制错误码.xlsx')) |
|||
let firstSheetName = workbook.SheetNames[0]; |
|||
let worksheet = workbook.Sheets[firstSheetName]; |
|||
let res = XLSX.utils.sheet_to_json(worksheet); |
|||
|
|||
// console.log(res);
|
|||
|
|||
for (let d of res) { |
|||
let statusRes = await client.query(`SELECT * FROM camera_status WHERE status=$1`, [d['错误码']]); |
|||
let statusRows = statusRes.rows |
|||
|
|||
if (statusRows.length) { |
|||
|
|||
} else { |
|||
console.log(`增加${d['错误码']}`); |
|||
const statusInQuery = `INSERT INTO "camera_status" (platform, status, describe, paraphrase) VALUES($1, $2, $3, $4) RETURNING id;` |
|||
const statusRows = (await client.query(statusInQuery, ['yingshi', d['错误码'], d['错误描述'], d['释义']])).rows |
|||
// console.log(statusRows);
|
|||
if (d['解决方案']) { |
|||
let resolveArr = d['解决方案'].split(';'); |
|||
// await client.query(`DELETE FROM "camera_status_solution" WHERE status_id=$1`, [statusRows[0].id]);
|
|||
for (let r of resolveArr) { |
|||
await client.query( |
|||
`INSERT INTO "camera_status_resolve" (status_id, resolve) VALUES($1, $2) RETURNING id;`, |
|||
[statusRows[0].id, r] |
|||
) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
// await client.query('ROLLBACK')
|
|||
await client.query('COMMIT') |
|||
console.log('执行完毕~') |
|||
} catch (e) { |
|||
await client.query('ROLLBACK') |
|||
console.log('执行错误~') |
|||
throw e |
|||
} finally { |
|||
client.release(); |
|||
} |
|||
} |
|||
|
|||
fun() |
|||
} catch (error) { |
|||
console.error(error) |
|||
} |
@ -0,0 +1,16 @@ |
|||
{ |
|||
"name": "appkey-generator", |
|||
"version": "1.0.0", |
|||
"description": "tool", |
|||
"main": "index.js", |
|||
"scripts": { |
|||
"test": "mocha", |
|||
"start": "set NODE_ENV=development&&node index" |
|||
}, |
|||
"author": "liu", |
|||
"license": "ISC", |
|||
"dependencies": { |
|||
"pg": "^7.18.2", |
|||
"xlsx": "^0.17.1" |
|||
} |
|||
} |
Binary file not shown.
Loading…
Reference in new issue