deartibers
2 years ago
18 changed files with 724 additions and 50 deletions
@ -0,0 +1,77 @@ |
|||
'use strict'; |
|||
const Hex = require('crypto-js/enc-hex'); |
|||
const MD5 = require('crypto-js/md5'); |
|||
const moment = require('moment'); |
|||
const uuid = require('uuid'); |
|||
|
|||
async function login (ctx, next) { |
|||
// const transaction = await ctx.fs.dc.orm.transaction();
|
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const params = ctx.request.body; |
|||
|
|||
const emisLoginRes = await ctx.app.fs.emisRequest.post('login', { |
|||
data: params |
|||
}) |
|||
|
|||
if (!emisLoginRes) { |
|||
throw "账号或密码错误" |
|||
} else { |
|||
const pomsRegisterRes = await models.User.findOne({ |
|||
where: { |
|||
pepUserId: emisLoginRes.id |
|||
} |
|||
}) |
|||
if (!pomsRegisterRes) { |
|||
throw '当前账号尚未在此系统启用' |
|||
} |
|||
emisLoginRes.pomsUserInfo = pomsRegisterRes.dataValues |
|||
|
|||
await models.User.update({ |
|||
lastInTime: moment().format(), |
|||
inTimes: pomsRegisterRes.inTimes + 1 |
|||
}, { |
|||
where: { |
|||
id: emisLoginRes.id |
|||
} |
|||
}) |
|||
|
|||
ctx.status = 200; |
|||
ctx.body = emisLoginRes; |
|||
} |
|||
// await transaction.commit();
|
|||
} catch (error) { |
|||
// await transaction.rollback();
|
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: |
|||
typeof error == 'string' ? error |
|||
: error.response.body.message || "登录失败" |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function logout (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const params = ctx.request.body; |
|||
|
|||
await ctx.app.fs.emisRequest.put('logout', { |
|||
data: params |
|||
}) |
|||
|
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
login, |
|||
logout, |
|||
}; |
@ -0,0 +1,65 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const ActionLog = sequelize.define("actionLog", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "action_log_id_uindex" |
|||
}, |
|||
userId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "user_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "user" |
|||
} |
|||
}, |
|||
time: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "time", |
|||
autoIncrement: false |
|||
}, |
|||
action: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "动态内容", |
|||
primaryKey: false, |
|||
field: "action", |
|||
autoIncrement: false |
|||
}, |
|||
expandParams: { |
|||
type: DataTypes.JSONB, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "expand_params", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "action_log", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.ActionLog = ActionLog; |
|||
return ActionLog; |
|||
}; |
@ -0,0 +1,97 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AlarmPushConfig = sequelize.define("alarmPushConfig", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "alarm_push_config_id_uindex" |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "name", |
|||
autoIncrement: false |
|||
}, |
|||
pepProjectId: { |
|||
type: DataTypes.ARRAY(DataTypes.INTEGER), |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "pep_project_id", |
|||
autoIncrement: false |
|||
}, |
|||
alarmType: { |
|||
type: DataTypes.ARRAY(DataTypes.STRING), |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "监听的告警类型", |
|||
primaryKey: false, |
|||
field: "alarm_type", |
|||
autoIncrement: false |
|||
}, |
|||
receiverPepUserId: { |
|||
type: DataTypes.ARRAY(DataTypes.INTEGER), |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "接收人id 项企", |
|||
primaryKey: false, |
|||
field: "receiver_pep_user_id", |
|||
autoIncrement: false |
|||
}, |
|||
timeType: { |
|||
type: DataTypes.ARRAY(DataTypes.STRING), |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "通知时效", |
|||
primaryKey: false, |
|||
field: "time_type", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
createUserId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_user_id", |
|||
autoIncrement: false |
|||
}, |
|||
disable: { |
|||
type: DataTypes.BOOLEAN, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "disable", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "alarm_push_config", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AlarmPushConfig = AlarmPushConfig; |
|||
return AlarmPushConfig; |
|||
}; |
@ -0,0 +1,88 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AppAlarm = sequelize.define("appAlarm", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "app_alarm_id_uindex" |
|||
}, |
|||
serialNumber: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "自定义编号", |
|||
primaryKey: false, |
|||
field: "serial_number", |
|||
autoIncrement: false |
|||
}, |
|||
pepProjectId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "对应的项目id", |
|||
primaryKey: false, |
|||
field: "pep_project_id", |
|||
autoIncrement: false |
|||
}, |
|||
appDomain: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "应用域名", |
|||
primaryKey: false, |
|||
field: "app_domain", |
|||
autoIncrement: false |
|||
}, |
|||
alarmContent: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "告警信息", |
|||
primaryKey: false, |
|||
field: "alarm_content", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
updateTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "update_time", |
|||
autoIncrement: false |
|||
}, |
|||
confirm: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "确认信息", |
|||
primaryKey: false, |
|||
field: "confirm", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "app_alarm", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AppAlarm = AppAlarm; |
|||
return AppAlarm; |
|||
}; |
@ -0,0 +1,52 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const AppInspection = sequelize.define("appInspection", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "app_inspection_id_uindex" |
|||
}, |
|||
pepProjectId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "pep_project_id", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
screenshot: { |
|||
type: DataTypes.ARRAY(DataTypes.STRING), |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "截图存储路径", |
|||
primaryKey: false, |
|||
field: "screenshot", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "app_inspection", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.AppInspection = AppInspection; |
|||
return AppInspection; |
|||
}; |
@ -0,0 +1,56 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const ProjectApp = sequelize.define("projectApp", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "project_app_id_uindex" |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "name", |
|||
autoIncrement: false |
|||
}, |
|||
url: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "url", |
|||
autoIncrement: false |
|||
}, |
|||
projectId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "project_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "projectCorrelation" |
|||
} |
|||
} |
|||
}, { |
|||
tableName: "project_app", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.ProjectApp = ProjectApp; |
|||
return ProjectApp; |
|||
}; |
@ -0,0 +1,70 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const ProjectCorrelation = sequelize.define("projectCorrelation", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "project_correlation_id_uindex" |
|||
}, |
|||
anxinProjectId: { |
|||
type: DataTypes.ARRAY(DataTypes.INTEGER), |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "anxin_project_id", |
|||
autoIncrement: false |
|||
}, |
|||
pepProjectId: { |
|||
type: DataTypes.ARRAY(DataTypes.INTEGER), |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "项目管理的项目id", |
|||
primaryKey: false, |
|||
field: "pep_project_id", |
|||
autoIncrement: false |
|||
}, |
|||
createTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_time", |
|||
autoIncrement: false |
|||
}, |
|||
createUser: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "create_user", |
|||
autoIncrement: false |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "name", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "project_correlation", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.ProjectCorrelation = ProjectCorrelation; |
|||
return ProjectCorrelation; |
|||
}; |
@ -0,0 +1,47 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const QuickLink = sequelize.define("quickLink", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "quick_link_id_uindex" |
|||
}, |
|||
userId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "user_id", |
|||
autoIncrement: false, |
|||
references: { |
|||
key: "id", |
|||
model: "user" |
|||
} |
|||
}, |
|||
link: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "link", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "quick_link", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.QuickLink = QuickLink; |
|||
return QuickLink; |
|||
}; |
@ -0,0 +1,88 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const User = sequelize.define("user", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "user_id_uindex" |
|||
}, |
|||
pepUserId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: "项企对应用户id", |
|||
primaryKey: false, |
|||
field: "pep_user_id", |
|||
autoIncrement: false |
|||
}, |
|||
role: { |
|||
type: DataTypes.ARRAY(DataTypes.STRING), |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "角色 也对应权限 admin 管理员 / all 全部角色 / data_analyst 数据分析 / after_sale 售后运维 / resource_manage 资源管理 / customer_service 客户服务", |
|||
primaryKey: false, |
|||
field: "role", |
|||
autoIncrement: false |
|||
}, |
|||
correlationProject: { |
|||
type: DataTypes.ARRAY(DataTypes.INTEGER), |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "关联的项目管理的项目id", |
|||
primaryKey: false, |
|||
field: "correlation_project", |
|||
autoIncrement: false |
|||
}, |
|||
lastInTime: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "last_in_time", |
|||
autoIncrement: false |
|||
}, |
|||
inTimes: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: "0", |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "in_times", |
|||
autoIncrement: false |
|||
}, |
|||
onlineDuration: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "在线时长 单位 s", |
|||
primaryKey: false, |
|||
field: "online_duration", |
|||
autoIncrement: false |
|||
}, |
|||
lastInAddress: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "上次登录地点", |
|||
primaryKey: false, |
|||
field: "last_in_address", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "user", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.User = User; |
|||
return User; |
|||
}; |
@ -0,0 +1,17 @@ |
|||
'use strict'; |
|||
|
|||
const auth = require('../../controllers/auth'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
/** |
|||
* @api {Post} login 登录. |
|||
* @apiVersion 1.0.0 |
|||
* @apiGroup Auth |
|||
*/ |
|||
app.fs.api.logAttr['POST/login'] = { content: '登录', visible: true }; |
|||
router.post('/login', auth.login); |
|||
|
|||
app.fs.api.logAttr['PUT/logout'] = { content: '登出', visible: false }; |
|||
router.put('/logout', auth.logout); |
|||
|
|||
}; |
@ -1,33 +1,40 @@ |
|||
'use strict'; |
|||
const moment = require('moment') |
|||
|
|||
module.exports = async function factory (app, opts) { |
|||
|
|||
app.socket.on('connection', async (socket) => { |
|||
console.info('WEB_SOCKET ' + socket.handshake.query.token + ' 已连接:' + socket.id); |
|||
console.info('WEB_SOCKET token:' + socket.handshake.query.token + ' 已连接:id ' + socket.id + ' 时间:' + moment(socket.handshake.time).format()); |
|||
|
|||
socket.on('disconnecting', async (reason) => { |
|||
console.info('WEB_SOCKET ' + socket.handshake.query.token + ' 已断开连接:' + reason); |
|||
const connectSeconds = moment().diff(moment(socket.handshake.time), 'seconds') |
|||
|
|||
console.info('WEB_SOCKET token:' + socket.handshake.query.token + ' 已断开连接:' + reason + ' 连接时长:' + connectSeconds + 's'); |
|||
|
|||
const { models } = app.fs.dc |
|||
await models.User.increment({ |
|||
onlineDuration: connectSeconds |
|||
}, { |
|||
where: { |
|||
id: socket.handshake.query.pomsUserId |
|||
} |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
// 使用测试 保持链接
|
|||
setInterval(async () => { |
|||
const { connected } = app.socket.sockets |
|||
|
|||
const roomId = 'ROOM_' + Math.random() |
|||
// if (connected) {
|
|||
// for (let c in connected) {
|
|||
// connected[c].join(roomId)
|
|||
// }
|
|||
// app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, })
|
|||
// }
|
|||
|
|||
app.socket.emit('TEST', { someProperty: '【广播】呼叫青铜时代号!!!', }) |
|||
|
|||
// app.socket.emit('CAMERA_ONLINE', {
|
|||
// ipctype: 'yingshi',
|
|||
// online: Math.random() > 0.5 ? 'ON' : 'OFF',
|
|||
// gbId: Math.floor(Math.random() * 100),
|
|||
// name: 'cameraName'
|
|||
// })
|
|||
}, 3000) |
|||
// setInterval(async () => {
|
|||
// const { connected } = app.socket.sockets
|
|||
|
|||
// const roomId = 'ROOM_' + Math.random()
|
|||
// // if (connected) {
|
|||
// // for (let c in connected) {
|
|||
// // connected[c].join(roomId)
|
|||
// // }
|
|||
// // app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, })
|
|||
// // }
|
|||
|
|||
// app.socket.emit('TEST', { someProperty: '【广播】呼叫青铜时代号!!!', })
|
|||
|
|||
// }, 3000)
|
|||
} |
|||
|
Loading…
Reference in new issue