diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 00a14ce..18401bb 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -1,49 +1,51 @@ { - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "启动 API", - "program": "${workspaceRoot}/server.js", - "env": { - "NODE_ENV": "development" - }, - "args": [ - "-p 4900", - // 研发 - "-g postgres://postgres:123456@10.8.30.166:5432/XunJian", - // 测试 - // "--apiEmisUrl http://10.8.30.161:1111", - "--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5", - "--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa", - "--qnbkt dev-hr", - // "--qndmn http://resources.anxinyun.cn", - "--qndmn http://rjkwed13l.hn-bkt.clouddn.com", - "--aliOssAccessKey LTAI5tNDfn7UhStYQcn3JBtw", - "--aliOssSecretKey rnoXtDWQA1djJ5Xqcdn1OSEol0lVyv", - "--aliOssBucket test-c371", - "--aliOssRegion oss-cn-hangzhou", - ] - }, - { - "type": "node", - "request": "launch", - "name": "run mocha", - "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", - "stopOnEntry": false, - "args": [ - "app/test/*.test.js", - "--no-timeouts" - ], - "cwd": "${workspaceRoot}", - "runtimeExecutable": null, - "env": { - "NODE_ENV": "development" - } - } - ] + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "启动 API", + "program": "${workspaceRoot}/server.js", + "env": { + "NODE_ENV": "development" + }, + "args": [ + "-p 4900", + // 研发 + "-g postgres://postgres:123456@10.8.30.166:5432/XunJian", + // 测试 + // "--apiEmisUrl http://10.8.30.161:1111", + // "--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5", + // "--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa", + // "--qnbkt dev-hr", + // "--qndmn http://resources.anxinyun.cn", + // "--qndmn http://rjkwed13l.hn-bkt.clouddn.com", + // "--aliOssAccessKey LTAI5tNDfn7UhStYQcn3JBtw", + // "--aliOssSecretKey rnoXtDWQA1djJ5Xqcdn1OSEol0lVyv", + // "--aliOssBucket test-c371", + // "--aliOssRegion oss-cn-hangzhou", + "--apiAnxinyunUrl https://openapi.anxinyun.cn/api/v1", + "--axyProject 1a271f12-52f2-4d16-8dad-ec0c92d3e0cc/03bzzdh/123456", + ] + }, + { + "type": "node", + "request": "launch", + "name": "run mocha", + "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", + "stopOnEntry": false, + "args": [ + "app/test/*.test.js", + "--no-timeouts" + ], + "cwd": "${workspaceRoot}", + "runtimeExecutable": null, + "env": { + "NODE_ENV": "development" + } + } + ] } \ No newline at end of file diff --git a/api/app/lib/controllers/bigScreen/index .js b/api/app/lib/controllers/bigScreen/index .js new file mode 100644 index 0000000..d21f3ae --- /dev/null +++ b/api/app/lib/controllers/bigScreen/index .js @@ -0,0 +1,67 @@ +'use strict'; +const Hex = require('crypto-js/enc-hex'); +const MD5 = require('crypto-js/md5'); +const moment = require('moment'); + + + +let axyTokenCache = { + token: null, + orgId: null, + expireTime: null //过期时间 +} + +const getAnxinyunToken = async function (ctx) { + try { + + if (!axyTokenCache.token || moment() > moment(axyTokenCache.expireTime)) { + if (ctx.app.fs.opts.axyProject.split('/').length === 3) { + const dataToAxy = { + p: ctx.app.fs.opts.axyProject.split('/')[0], + username: ctx.app.fs.opts.axyProject.split('/')[1], + password: ctx.app.fs.opts.axyProject.split('/')[2], + } + const axyResponse = await ctx.app.fs.anxinyun.post('project/login', { data: dataToAxy }) + if (axyResponse.authorized) { + axyTokenCache.token = axyResponse.token //放进缓存 + axyTokenCache.orgId = axyResponse.orgId //放进缓存 + axyTokenCache.expireTime = moment().add(20, 'hour').format('YYYY-MM-DD HH:mm:ss') + } + } + } + return axyTokenCache + } catch (error) { + ctx.fs.logger.error(`sechedule: laborAttendance, error: ${error}`); + } +} +async function axyData (ctx, next) { + + try { + let { type, url, params = {} } = ctx.request.body; + let data = await getAnxinyunToken(ctx) + if (url && url.indexOf('{orgId}') != -1) { + url = url.replace(`{orgId}`, data.orgId) + } + + const res = await ctx.app.fs.anxinyun[type](`${url}?token=${data.token}`, { data: params.data || {}, query: params.query || {} }) + ctx.status = 200; + ctx.body = res; + } catch (err) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); + ctx.status = 400; + ctx.body = { name: 'FindError', message: '获取安心云数据失败' }; + } +} + + + + + + + + + + +module.exports = { + axyData, +} \ No newline at end of file diff --git a/api/app/lib/controllers/organization/authority.js b/api/app/lib/controllers/organization/authority.js deleted file mode 100644 index bcb5a68..0000000 --- a/api/app/lib/controllers/organization/authority.js +++ /dev/null @@ -1,87 +0,0 @@ -async function getResource(ctx, next) { - try { - const models = ctx.fs.dc.models; - - const res = await models.Resource.findAll({ - where: { parentResource: null }, - include: [{ - model: models.Resource, - }] - }) - - ctx.body = res; - ctx.status = 200; - - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": "查询所有权限数据失败" - } - } -} -async function getUserResource(ctx, next) { - try { - const models = ctx.fs.dc.models; - const { userId } = ctx.query; - - const res = await models.UserResource.findAll({ - where: { userId: userId }, - include: [{ - model: models.Resource, - }] - }) - - ctx.body = res; - ctx.status = 200; - - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": "查询用户权限数据失败" - } - } -} - -async function updateUserRes(ctx, next) { - const transaction = await ctx.fs.dc.orm.transaction(); - try { - const models = ctx.fs.dc.models; - const { userId, resCode } = ctx.request.body; - - const res = await models.UserResource.findAll({ - attributes: ["resourceId"], - raw: true, - where: { userId: userId } - }) - - const addRes = resCode.filter(r => !res.some(rr => rr.resourceId == r)).map(r => { return { userId: userId, resourceId: r } }); - const delRes = res.filter(r => !resCode.includes(r.resourceId)).map(r => r.resourceId); - addRes.length && await models.UserResource.bulkCreate(addRes, { transaction: transaction }); - delRes.length && await models.UserResource.destroy({ - where: { - resourceId: { $in: delRes }, - userId: userId - }, - transaction: transaction - }) - - ctx.status = 204; - await transaction.commit(); - - } catch (error) { - await transaction.rollback(); - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": "更新用户权限数据失败" - } - } -} - -module.exports = { - getResource, - getUserResource, - updateUserRes -}; \ No newline at end of file diff --git a/api/app/lib/controllers/organization/user.js b/api/app/lib/controllers/organization/user.js deleted file mode 100644 index 8aaf88b..0000000 --- a/api/app/lib/controllers/organization/user.js +++ /dev/null @@ -1,389 +0,0 @@ -'use strict'; -const Hex = require('crypto-js/enc-hex'); -const MD5 = require('crypto-js/md5'); - -// async function getDepMessage (ctx, next) { -// try { -// const { fs: { api: { userInfo } } } = ctx -// const models = ctx.fs.dc.models; - -// let deptWhere = {} -// if (userInfo.username !== 'SuperAdmin') { -// deptWhere.id = userInfo.departmentId -// } -// let depType1 = await models.Department.findAll({ -// order: [['id', 'asc']], -// // include: [{ -// // model: models.User, -// // required: false, -// // where: { delete: false }, -// // attributes: { exclude: ['password'] }, -// // }], -// where: deptWhere, -// }) - -// let depRslt = [] -// const getDep = async (d) => { -// let subordinate = [] -// let depRes = await models.Department.findAll({ -// order: [['id', 'asc']], -// // include: [{ -// // model: models.User, -// // required: false, -// // where: { delete: false }, -// // attributes: { exclude: ['password'] }, -// // }], -// where: { -// dependence: d.id -// }, -// }) -// if (depRes.length) -// for (let d of depRes) { -// let dep = d.dataValues -// dep.subordinate = await getDep(d.dataValues) -// subordinate.push(dep) -// } -// return subordinate -// } -// for (let d of depType1) { -// let dep_1 = d.dataValues -// dep_1.subordinate = await getDep(d.dataValues) -// depRslt.push(dep_1) -// } - -// ctx.status = 200; -// ctx.body = depRslt -// } catch (error) { -// ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); -// ctx.status = 400; -// ctx.body = { -// "message": "获取部门信息失败" -// } -// } -// } - -async function getDepMessage(ctx, next) { - let error = { name: 'FindError', message: '获取部门列表失败' }; - let rslt = []; - try { - const models = ctx.fs.dc.models; - let list = await models.Department.findAll({}); - - let deptMap = [] - list.filter(l => !l.dependence).map(ld => {//一级 - deptMap.push({ - id: ld.id, - name: ld.name, - dependence: ld.dependence, - subordinate: [] - }) - }) - - list.filter(l => l.dependence).map(ld => {//二级 - let parent = deptMap.find(dm => dm.id == ld.dependence); - if (parent) { - parent.subordinate.push({ - id: ld.id, - name: ld.name, - dependence: ld.dependence, - subordinate: [] - }) - } - }) - rslt = deptMap; - - error = null; - } catch (err) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); - } - if (error) { - ctx.status = 400; - ctx.body = error; - } else { - ctx.status = 200; - ctx.body = rslt; - } -} - -async function createDept(ctx, next) { - const models = ctx.fs.dc.models; - try { - let rslt = ctx.request.body; - await models.Department.create(Object.assign({}, rslt, { read: 1 })) - ctx.status = 204; - ctx.body = { message: '新建部门成功' } - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { message: '新建部门失败' } - } -} - -async function updateDept(ctx, next) { - try { - const models = ctx.fs.dc.models; - const { id } = ctx.params; - const body = ctx.request.body; - await models.Department.update( - body, - { where: { id: id } } - ) - ctx.status = 204; - ctx.body = { message: '修改部门成功' } - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { message: '修改部门失败' } - } -} - -async function delDept(ctx, next) { - let errMsg = "删除部门失败"; - try { - const models = ctx.fs.dc.models; - const { id } = ctx.params; - let list = await models.Department.findAll({}); - let deptIds = list.map(l => l.id); - const allUsers = await models.User.findAll({ - where: { - departmentId: { $in: deptIds }, - delete: false - } - }) - const childrenDept = await models.Department.findAll({ where: { dependence: id } }) - const childrenUser = allUsers.filter(au => au.departmentId == id); - if (childrenUser.length || childrenDept.length) { - errMsg = '请先删除部门下的用户或子部门'; - throw errMsg; - } - await models.Department.destroy({ where: { id: id } }); - await models.Department.destroy({ where: { dependence: id } }); - ctx.status = 204; - ctx.body = { message: '删除部门成功' } - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { message: error } - } -} - -async function getUser(ctx, next) { - try { - const models = ctx.fs.dc.models; - const { depId } = ctx.params; - let userRes = null; - if (depId !== 'null') { - userRes = await models.User.findAll({ - where: { - departmentId: parseInt(depId), - delete: false - }, - attributes: { exclude: ['password'] }, - order: [['id', 'asc']], - }) - } else { - userRes = await models.User.findAll({ - where: { - delete: false - }, - attributes: { exclude: ['password'] }, - order: [['id', 'asc']], - include: [{ - required: true, - model: models.Department, - attributes: ['id', 'name'], - }] - }) - } - - ctx.status = 200; - ctx.body = userRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": "获取用户信息失败" - } - } -} - -async function creatUser(ctx, next) { - let errMsg = "新建用户失败" - try { - const models = ctx.fs.dc.models; - const data = ctx.request.body; - - let repeatUserNameCount = await models.User.count({ - where: { - username: data.phone, - delete: false - } - }) - - if (repeatUserNameCount) { - errMsg = '已有当前用户名' - throw errMsg - } - - await models.User.create({ - name: data.name, - username: data.phone, - password: Hex.stringify(MD5(data.password)), - departmentId: data.departmentId, - email: data.email, - enable: data.enable, - delete: false, - phone: data.phone, - post: data.post, - }) - - ctx.status = 204; - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": errMsg - } - } -} - - -async function updateUser(ctx, next) { - let errMsg = "修改用户失败" - try { - const models = ctx.fs.dc.models; - const data = ctx.request.body; - const { id } = ctx.params; - - let repeatUserNameCount = await models.User.count({ - where: { - username: data.username - } - }) - - if (repeatUserNameCount) { - errMsg = '已有当前用户名' - throw errMsg - } - - await models.User.update({ - name: data.name, - username: data.phone, - departmentId: data.departmentId, - email: data.email, - enable: data.enable, - delete: false, - phone: data.phone, - post: data.post, - }, { - where: { - id: id - } - }); - - ctx.status = 204; - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": errMsg - } - } -} - -async function deleteUser(ctx, next) { - try { - const models = ctx.fs.dc.models; - const { ids } = ctx.params; - const userIds = ids.split(','); - await models.User.update({ - delete: true, - }, { - where: { - id: { $in: userIds }, - } - }); - ctx.status = 204; - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": "删除用户失败" - } - } -} - -async function resetPwd(ctx, next) { - try { - const models = ctx.fs.dc.models; - const { id } = ctx.params; - const data = ctx.request.body; - await models.User.update({ - password: Hex.stringify(MD5(data.password)), - }, { - where: { - id: id, - } - }); - ctx.status = 204; - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": "重置用户密码失败" - } - } -} - -/** - * 修改用户密码 - * @params {userId-用户Id} ctx - * @request.body {password-用户新密码} ctx - */ -async function updateUserPassword(ctx, next) { - try { - const models = ctx.fs.dc.models; - const { userId } = ctx.params; - const { password } = ctx.request.body; - if (!password) { - ctx.status = 400; - ctx.body = { "message": "请输入修改密码" }; - return; - } - const userRes = await models.User.findOne({ - where: { - id: userId - }, - attributes: ['id'] - }); - if (userRes) { - await models.User.update({ password: Hex.stringify(MD5(password)) }, { where: { id: userId, } }); - ctx.status = 204; - } else { - ctx.status = 400; - ctx.body = { - "message": "用户不存在" - } - } - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - "message": "修改用户密码失败" - } - } -} - - -module.exports = { - getDepMessage, - createDept, - updateDept, - delDept, - getUser, - creatUser, - updateUser, - deleteUser, - resetPwd, - updateUserPassword -} \ No newline at end of file diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 5cb7374..ee32d26 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -6,12 +6,12 @@ const utils = require('./utils') const routes = require('./routes'); //const redisConnect = require('./service/redis') const socketConect = require('./service/socket') -//const paasRequest = require('./service/paasRequest'); +const paasRequest = require('./service/paasRequest'); const authenticator = require('./middlewares/authenticator'); //const clickHouseClient = require('./service/clickHouseClient') const schedule = require('./schedule') // const apiLog = require('./middlewares/api-log'); - + module.exports.entry = function (app, router, opts) { app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.'); @@ -26,7 +26,7 @@ module.exports.entry = function (app, router, opts) { socketConect(app, opts) // 实例其他平台请求方法 - //paasRequest(app, opts) + paasRequest(app, opts) // clickHouse 数据库 client //clickHouseClient(app, opts) diff --git a/api/app/lib/routes/organization/authority.js b/api/app/lib/routes/organization/authority.js deleted file mode 100644 index 99de6df..0000000 --- a/api/app/lib/routes/organization/authority.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -const Authority = require('../../controllers/organization/authority'); - -module.exports = function (app, router, opts) { - /** - * @api {GET} resource 查询所有权限码. - * @apiVersion 1.0.0 - * @apiGroup Org - */ - app.fs.api.logAttr['GET/resource'] = { content: '查询所有权限码', visible: true }; - router.get('resource', Authority.getResource); - /** - * @api {GET} user/resource 查询用户权限. - * @apiVersion 1.0.0 - * @apiGroup Org - */ - app.fs.api.logAttr['GET/user/resource'] = { content: '查询用户权限', visible: true }; - router.get('user/resource', Authority.getUserResource); - - /** - * @api {POST} user/resource 更新用户权限. - * @apiVersion 1.0.0 - * @apiGroup Org - */ - app.fs.api.logAttr['POST/user/resource'] = { content: '更新用户权限', visible: true }; - router.post('user/resource', Authority.updateUserRes); -}; \ No newline at end of file diff --git a/api/app/lib/routes/organization/index.js b/api/app/lib/routes/organization/index.js new file mode 100644 index 0000000..2d6c26f --- /dev/null +++ b/api/app/lib/routes/organization/index.js @@ -0,0 +1,9 @@ +'use strict'; + +const data = require('../../controllers/bigScreen/index '); + +module.exports = function (app, router, opts) { + + app.fs.api.logAttr['POST/axyData'] = { content: '获取安心云数据', visible: true }; + router.post('/axyData', data.axyData); +}; \ No newline at end of file diff --git a/api/app/lib/routes/organization/user.js b/api/app/lib/routes/organization/user.js deleted file mode 100644 index 5b63e32..0000000 --- a/api/app/lib/routes/organization/user.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -const user = require('../../controllers/organization/user'); - -module.exports = function (app, router, opts) { - - app.fs.api.logAttr['GET/organization/department'] = { content: '获取部门信息', visible: false }; - router.get('/organization/department', user.getDepMessage); - - app.fs.api.logAttr['POST/organization/dept/add'] = { content: '新增部门', visible: true }; - router.post('/organization/dept/add', user.createDept); - - app.fs.api.logAttr['PUT/organization/dept/:id/modify'] = { content: '修改部门', visible: true }; - router.put('/organization/dept/:id/modify', user.updateDept); - - app.fs.api.logAttr['DELETE/organization/dept/:id'] = { content: '删除部门', visible: true }; - router.del('/organization/dept/:id', user.delDept); - - app.fs.api.logAttr['GET/organization/department/:depId/user'] = { content: '获取部门下用户信息', visible: false }; - router.get('/organization/department/:depId/user', user.getUser); - - app.fs.api.logAttr['POST/organization/department/user'] = { content: '创建部门下用户信息', visible: false }; - router.post('/organization/department/user', user.creatUser); - - app.fs.api.logAttr['PUT/organization/department/user/:id'] = { content: '修改部门下用户信息', visible: false }; - router.put('/organization/department/user/:id', user.updateUser); - - app.fs.api.logAttr['DEL/organization/department/user/:ids'] = { content: '删除部门下用户信息', visible: false }; - router.del('/organization/department/user/:ids', user.deleteUser); - - app.fs.api.logAttr['PUT/organization/department/user/resetPwd/:id'] = { content: '重置用户密码', visible: false }; - router.put('/organization/department/user/resetPwd/:id', user.resetPwd); - - /** - * @api {PUT} user/password/:id 修改用户密码 - * @apiVersion 1.0.0 - * @apiGroup Organization - */ - app.fs.api.logAttr['PUT/user/password/:userId'] = { content: '修改用户密码', visible: false }; - router.put('/user/password/:userId', user.updateUserPassword); -}; \ No newline at end of file diff --git a/api/app/lib/schedule/clearExpiredData.js b/api/app/lib/schedule/clearExpiredData.js deleted file mode 100644 index 00daf06..0000000 --- a/api/app/lib/schedule/clearExpiredData.js +++ /dev/null @@ -1,53 +0,0 @@ -const moment = require('moment') -const rimraf = require('rimraf'); -const fs = require("fs"); -const path = require("path") - -let TEST = false -// TEST = true - -module.exports = function (app, opts) { - const clearExpiredData = app.fs.scheduleInit( - { - interval: '42 24 4 */3 * *', - immediate: TEST, - proRun: !TEST, - }, - async () => { - try { - const { models } = app.fs.dc - const now = moment().format('YYYY-MM-DD HH:mm:ss') - await models.UserToken.destroy({ - where: { - expired: { $lt: now } - } - }) - await models.PhoneValidateCode.destroy({ - where: { - expired: { $lt: now } - } - }) - fs.readdir(path.join(__dirname, `../../downloadFiles`), function (err, files) { - if (err) { - return; - } - files.forEach((file) => { - fs.stat(path.join(__dirname, `../../downloadFiles/${file}`), (err, stats) => { - if (err) { - //return; - } else { - rimraf.sync(path.join(__dirname, `../../downloadFiles/${file}`)); - } - }); - }); - }); - } catch (error) { - app.fs.logger.error(`sechedule: clearExpiredToken, error: ${error}`); - } - } - ); - - return { - clearExpiredData - } -} \ No newline at end of file diff --git a/api/app/lib/schedule/hideDangerStatistic.js b/api/app/lib/schedule/hideDangerStatistic.js deleted file mode 100644 index 1b469bb..0000000 --- a/api/app/lib/schedule/hideDangerStatistic.js +++ /dev/null @@ -1,208 +0,0 @@ -const fs = require('fs'); -const moment = require('moment') -const path = require('path') -const OSS = require('ali-oss'); -const uuid = require('uuid'); - -const TEST = false -// const TEST = true - -module.exports = function (app, opts) { - const hideDangerStatistic = app.fs.scheduleInit( - // 按月、季度、年统计隐患整改 - { - interval: '0 32 4 1 */1 *', - immediate: TEST, - proRun: !TEST, - }, - async () => { - const { aliOss } = opts - const { utils: { simpleExcelDown } } = app.fs; - - try { - const { models } = app.fs.dc - const today = moment() - const date = today.date() - const month = today.month() + 1 - const quarter = today.quarter() - const year = today.year() - - const client = new OSS({ - // yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。 - region: aliOss.region, - // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。 - accessKeyId: aliOss.accessKey, - accessKeySecret: aliOss.secretKey, - // 填写Bucket名称,例如examplebucket。 - bucket: aliOss.bucket, - }); - - - const statistic = async (startTime, endTime, type, timeShow, typeEnglish, time) => { - const siteRectifyRes = await models.HideDangerRectifySites.findAll({ - where: {}, - distinct: true, - include: [{ - model: models.Site, - attributes: ['id', 'name'], - }, { - model: models.HideDangerDispose, - order: [['id', 'ASC']], - // include: [{ - // model: models.User, - // attributes: ['id', 'displayName'], - // }] - }, { - model: models.HideDangerRectify, - where: { - createTime: { - $between: [ - startTime.format('YYYY-MM-DD HH:mm:ss'), - endTime.format('YYYY-MM-DD HH:mm:ss') - ] - } - }, - },] - }) - - let reportHeader = [{ - title: "工程项目名称", - key: "siteName", - }, { - title: "整改任务名称", - key: "name", - }, { - title: "提交时间", - key: "submitTime", - }, { - title: "审批状态", - key: "state", - },] - let reportData = [] - - let siteMap = new Set() - let completedRectifyCount = 0 - let uncompletedRectifyCount = 0 - for (let s of siteRectifyRes) { - siteMap.add(s.siteId); - - let sts = s.status - let stsChinese = '' - if (sts == 0) { - stsChinese = '待整改' - } else if (sts == 1) { - stsChinese = '待审批' - } else if (sts == 2) { - stsChinese = '待复审' - } else if (sts == 3 || sts == 4) { - stsChinese = '审批驳回' - } else if (sts == 5) { - stsChinese = '审批通过' - } - - if ( - s.hideDangerDisposes.length - && s.hideDangerDisposes.some(sd => sd.type == 3 && sd.admit) - ) { - completedRectifyCount++ - } else { - uncompletedRectifyCount++ - } - - reportData.push({ - siteName: s.dataValues.site.dataValues.name, - name: s.dataValues.hideDangerRectify.dataValues.name, - submitTime: s.dataValues.lastDisposeTime ? moment(s.dataValues.lastDisposeTime).format('YYYY-MM-DD HH:mm:ss') : '', - state: stsChinese - }) - } - const fileName = `中鼎国际隐患整改数据报表-${type}-${timeShow}` + '.xlsx' - const filePath = await simpleExcelDown({ - data: reportData, header: reportHeader, fileName - }) - // const fileData = fs.readFileSync(filePath); - - // 保存文件到云 - - let uploadPath = path.posix.join('hideDangerReport', uuid.v4(), fileName); - let uploadResult = await client.put( - uploadPath, - filePath, - // { contentLength: size } - ); - //保存信息到数据库 - const existReportRes = await models.HideDangerReport.findOne({ - where: { - type: typeEnglish, - time: String(time), - } - }) - const storageData = { - siteCount: siteMap.size, - rectifyCount: completedRectifyCount + uncompletedRectifyCount, - completedRectifyCount, - uncompletedRectifyCount, - report: uploadResult.name, - type: typeEnglish, - time: String(time), - } - if (existReportRes) { - await models.HideDangerReport.update(storageData, { - where: { - id: existReportRes.id - } - }) - } else { - await models.HideDangerReport.create(storageData) - } - - } - - if (month == 1) { - // 统计一下上一年 - let startTime = today.clone().subtract(1, 'year').startOf('year') - let endTime = today.clone().subtract(1, 'year').endOf('year') - await statistic( - startTime, - endTime, - '年报', - `${startTime.year()}${startTime.month() + 1}-${endTime.month() + 1}`, - 'year', - startTime.year() - ) - } - if ([1, 4, 7, 10].includes(month)) { - // 统计一下上季度 - let startTime = today.clone().subtract(3, 'month').startOf('month') - let endTime = today.clone().subtract(1, 'month').endOf('month') - await statistic( - startTime, - endTime, - '季报', - `${startTime.year()}${startTime.month() + 1}-${endTime.month() + 1}`, - 'quarter', - `${startTime.year()}-${month == 1 ? 'Q4' : month == 4 ? 'Q1' : month == 7 ? 'Q2' : 'Q3'}` - ) - } - // 统计一下上个月 - let startTime = today.clone().subtract(1, 'month').startOf('month') - let endTime = today.clone().subtract(1, 'month').endOf('month') - await statistic( - startTime, - endTime, - '月报', - `${startTime.year()}${startTime.month() + 1}`, - 'month', - startTime.format('YYYY-MM') - ) - - } catch (error) { - app.fs.logger.error(`sechedule: hideDangerStatistic, error: ${error}`); - } - } - ); - - return { - hideDangerStatistic - } -} \ No newline at end of file diff --git a/api/app/lib/schedule/metting.js b/api/app/lib/schedule/metting.js deleted file mode 100644 index 9c98a36..0000000 --- a/api/app/lib/schedule/metting.js +++ /dev/null @@ -1,64 +0,0 @@ -const moment = require('moment') - -const TEST = false -// const TEST = true - -module.exports = function (app, opts) { - const mettingGenerate = app.fs.scheduleInit( - { - interval: '0 0 0 */1 * *', - immediate: TEST, - proRun: !TEST, - }, - async () => { - try { - const { models } = app.fs.dc - const today = moment() - const date = today.date() - const dateFormat = moment().format('YYYY-MM-DD') - let sites = await models.Site.findAll({ - where: { del: false }, - attributes: ['id', 'name'] - }); - let datasM = [], datasB = [], datasD = [], datas6 = [] - sites.map(s => { - datasM.push({ - siteId: s.id, - type: '月度安全例会', - date: dateFormat - }); - datasB.push({ - siteId: s.id, - type: '班前会', - date: dateFormat - }); - datasD.push({ - siteId: s.id, - type: '日调度会', - date: dateFormat - }); - datas6.push({ - siteId: s.id, - type: '逢六教育培训', - date: dateFormat - }) - }) - if (date == 1) { - await models.Metting.bulkCreate(datasM) - } - await models.Metting.bulkCreate(datasB) - await models.Metting.bulkCreate(datasD) - if (parseInt(date) % 10 == 6) { - await models.Metting.bulkCreate(datas6) - } - - } catch (error) { - app.fs.logger.error(`sechedule: mettingGenerate, error: ${error}`); - } - } - ); - - return { - mettingGenerate - } -} \ No newline at end of file diff --git a/api/config.js b/api/config.js index 6550c23..74acdee 100644 --- a/api/config.js +++ b/api/config.js @@ -11,34 +11,18 @@ const dev = process.env.NODE_ENV == 'development'; args.option(['p', 'port'], '启动端口'); args.option(['g', 'pg'], 'postgre 服务 URL'); -// 七牛云存储参数 -args.option('qnak', 'qiniuAccessKey'); -args.option('qnsk', 'qiniuSecretKey'); -args.option('qnbkt', 'qiniuBucket'); -args.option('qndmn', 'qiniuDomain'); -args.option('aliOssAccessKey', '阿里OSS AccessKey'); -args.option('aliOssSecretKey', '阿里OSS SecretKey'); -args.option('aliOssBucket', '阿里OSS Bucket'); -args.option('aliOssRegion', '阿里OSS Region'); +args.option('apiAnxinyunUrl', "安心云api"); +args.option('axyProject', '安心云泵站项目信息'); const flags = args.parse(process.argv); const XUNJIAN_DB = process.env.XUNJIAN_DB || flags.pg; +const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl +const AXY_BZ_PROJECT = process.env.AXY_BZ_PROJECT || flags.axyProject -// 七牛云存储参数 -const QINIU_DOMAIN_QNDMN_RESOURCE = process.env.ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE || flags.qndmn; -const QINIU_BUCKET_RESOURCE = process.env.ANXINCLOUD_QINIU_BUCKET_RESOURCE || flags.qnbkt; -const QINIU_AK = process.env.ANXINCLOUD_QINIU_ACCESSKEY || flags.qnak; -const QINIU_SK = process.env.ANXINCLOUD_QINIU_SECRETKEY || flags.qnsk; -//阿里OSS -const ALI_OSS_ACCESSKEY = process.env.ALI_OSS_ACCESSKEY || flags.aliOssAccessKey; -const ALI_OSS_SECRETKET = process.env.ALI_OSS_SECRETKET || flags.aliOssSecretKey; -const ALI_OSS_BUCKET = process.env.ALI_OSS_BUCKET || flags.aliOssBucket; -const ALI_OSS_REGION = process.env.ALI_OSS_REGION || flags.aliOssRegion; - -if (!XUNJIAN_DB || !QINIU_DOMAIN_QNDMN_RESOURCE || !QINIU_BUCKET_RESOURCE || !QINIU_AK || !QINIU_SK) { +if (!XUNJIAN_DB || !API_ANXINYUN_URL || !AXY_BZ_PROJECT) { console.log('缺少启动参数,异常退出'); args.showHelp(); process.exit(-1); @@ -51,12 +35,6 @@ const product = { { entry: require('@fs/attachment').entry, opts: { - qiniu: { - domain: QINIU_DOMAIN_QNDMN_RESOURCE, - bucket: QINIU_BUCKET_RESOURCE, - accessKey: QINIU_AK, - secretKey: QINIU_SK - }, maxSize: 104857600, // 100M } }, { @@ -66,33 +44,12 @@ const product = { exclude: [ // "*" ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 - qiniu: { - domain: QINIU_DOMAIN_QNDMN_RESOURCE, - bucket: QINIU_BUCKET_RESOURCE, - accessKey: QINIU_AK, - secretKey: QINIU_SK - }, - aliOss: { - accessKey: ALI_OSS_ACCESSKEY, - secretKey: ALI_OSS_SECRETKET, - bucket: ALI_OSS_BUCKET, - region: ALI_OSS_REGION - }, - sms: { - ///阿里云-安心云 - accessKey: 'LTAI5tAFdjz7j38aNF2C9Qe8', - accessSecret: '1trYkmiqfBtvZL6BxkNH2uQcQQPs0S' - }, - email: { - enabled: true, - host: 'smtp.exmail.qq.com', - port: 465, - sender: { - name: '中鼎服务', - address: 'fsiot@free-sun.com.cn', - password: 'Fs2689' - } - }, + // apiAnxinyunUrl: API_ANXINYUN_URL, + axyProject: AXY_BZ_PROJECT, + pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs + name: 'anxinyun', + root: API_ANXINYUN_URL + }], } } ], diff --git a/web/client/assets/images/login/button-b.png b/web/client/assets/images/login/button-b.png new file mode 100644 index 0000000..f88c67e Binary files /dev/null and b/web/client/assets/images/login/button-b.png differ diff --git a/web/client/assets/images/login/icon_y.png b/web/client/assets/images/login/icon_y.png new file mode 100644 index 0000000..23864d3 Binary files /dev/null and b/web/client/assets/images/login/icon_y.png differ diff --git a/web/client/assets/images/login/icon_z.png b/web/client/assets/images/login/icon_z.png new file mode 100644 index 0000000..36a54c3 Binary files /dev/null and b/web/client/assets/images/login/icon_z.png differ diff --git a/web/client/assets/images/login/input-b.png b/web/client/assets/images/login/input-b.png new file mode 100644 index 0000000..700523e Binary files /dev/null and b/web/client/assets/images/login/input-b.png differ diff --git a/web/client/assets/images/login/login-b.gif b/web/client/assets/images/login/login-b.gif new file mode 100644 index 0000000..3b95856 Binary files /dev/null and b/web/client/assets/images/login/login-b.gif differ diff --git a/web/client/assets/images/login/login_a.png b/web/client/assets/images/login/login_a.png deleted file mode 100644 index 4c8a97e..0000000 Binary files a/web/client/assets/images/login/login_a.png and /dev/null differ diff --git a/web/client/assets/images/login/login_b.png b/web/client/assets/images/login/login_b.png deleted file mode 100644 index 9e04927..0000000 Binary files a/web/client/assets/images/login/login_b.png and /dev/null differ diff --git a/web/client/assets/images/login/register-bg.png b/web/client/assets/images/login/register-bg.png new file mode 100644 index 0000000..3a9a52a Binary files /dev/null and b/web/client/assets/images/login/register-bg.png differ diff --git a/web/client/assets/images/login/word.png b/web/client/assets/images/login/word.png new file mode 100644 index 0000000..ea8f2f0 Binary files /dev/null and b/web/client/assets/images/login/word.png differ diff --git a/web/client/assets/images/monitor/ball-A.png b/web/client/assets/images/monitor/ball-A.png new file mode 100644 index 0000000..f06fec4 Binary files /dev/null and b/web/client/assets/images/monitor/ball-A.png differ diff --git a/web/client/assets/images/monitor/ball-V.png b/web/client/assets/images/monitor/ball-V.png new file mode 100644 index 0000000..f31c444 Binary files /dev/null and b/web/client/assets/images/monitor/ball-V.png differ diff --git a/web/client/assets/images/monitor/bg-header.png b/web/client/assets/images/monitor/bg-header.png index b8b51a0..bc50cc9 100644 Binary files a/web/client/assets/images/monitor/bg-header.png and b/web/client/assets/images/monitor/bg-header.png differ diff --git a/web/client/assets/images/monitor/headerTitle.png b/web/client/assets/images/monitor/headerTitle.png new file mode 100644 index 0000000..cc7e716 Binary files /dev/null and b/web/client/assets/images/monitor/headerTitle.png differ diff --git a/web/client/assets/images/monitor/pedestal.png b/web/client/assets/images/monitor/pedestal.png new file mode 100644 index 0000000..6cd4bbe Binary files /dev/null and b/web/client/assets/images/monitor/pedestal.png differ diff --git a/web/client/assets/images/monitor/pump-head.png b/web/client/assets/images/monitor/pump-head.png new file mode 100644 index 0000000..12cba2c Binary files /dev/null and b/web/client/assets/images/monitor/pump-head.png differ diff --git a/web/client/assets/images/monitor/site.png b/web/client/assets/images/monitor/site.png new file mode 100644 index 0000000..295218a Binary files /dev/null and b/web/client/assets/images/monitor/site.png differ diff --git a/web/client/assets/images/monitor/title.png b/web/client/assets/images/monitor/title.png new file mode 100644 index 0000000..3b3b2b5 Binary files /dev/null and b/web/client/assets/images/monitor/title.png differ diff --git a/web/client/src/layout/actions/global.js b/web/client/src/layout/actions/global.js index 3615ef1..e052973 100644 --- a/web/client/src/layout/actions/global.js +++ b/web/client/src/layout/actions/global.js @@ -36,7 +36,9 @@ export function initApiRoot () { dispatch({ type: INIT_API_ROOT, payload: { - apiRoot: res.root + apiRoot: res.root, + axyApi: res.axyApi, + axyProject: res.axyProject, } }) }); diff --git a/web/client/src/layout/reducers/global.js b/web/client/src/layout/reducers/global.js index 5e69530..23baf8b 100644 --- a/web/client/src/layout/reducers/global.js +++ b/web/client/src/layout/reducers/global.js @@ -1,52 +1,61 @@ 'use strict'; import Immutable from 'immutable'; -import { INIT_LAYOUT, RESIZE } from '../actions/global'; +import { INIT_LAYOUT, RESIZE,INIT_API_ROOT } from '../actions/global'; import { SET_GLOBAL_SITE_LIST, CLEAR_GLOBAL_SITE_LIST } from '../actions/site' -function global(state = { - title: '', - copyright: '', - sections: [], - actions: {}, - plugins: {}, - clientHeight: 768, - clientWidth: 1024, - sites: [] +function global (state = { + title: '', + copyright: '', + sections: [], + actions: {}, + plugins: {}, + clientHeight: 768, + clientWidth: 1024, + sites: [], + axyApi: '', + axyProject: '' }, action) { - const payload = action.payload; - switch (action.type) { - case RESIZE: - return Immutable.fromJS(state).merge({ - clientHeight: payload.clientHeight, - clientWidth: payload.clientWidth - }).toJS(); - case INIT_LAYOUT: - return { - title: payload.title, - copyright: payload.copyright, - sections: payload.sections, - actions: payload.actions, - plugins: payload.plugins, - clientHeight: state.clientHeight, - detailsComponent: null, - sites: [] - }; - // case INIT_RESOURCE_ROOT: - // return Immutable.fromJS(state).merge(payload).toJS(); - // case INIT_PAGE_HEADER_DETAILS: - // return Immutable.fromJS(state).merge({ - // detailsComponent: payload.component - // }).toJS(); - case SET_GLOBAL_SITE_LIST: - return Immutable.fromJS(state).merge({ - sites: payload.data - }).toJS(); - case CLEAR_GLOBAL_SITE_LIST: - return Immutable.fromJS(state).merge({ - sites: [] - }).toJS(); - default: - return state; - } + const payload = action.payload; + switch (action.type) { + case RESIZE: + return Immutable.fromJS(state).merge({ + clientHeight: payload.clientHeight, + clientWidth: payload.clientWidth + }).toJS(); + case INIT_LAYOUT: + return { + title: payload.title, + copyright: payload.copyright, + sections: payload.sections, + actions: payload.actions, + plugins: payload.plugins, + clientHeight: state.clientHeight, + detailsComponent: null, + sites: [], + axyApi: payload.axyApi, + axyProject: payload.axyProject, + }; + case INIT_API_ROOT: + return Immutable.fromJS(state).merge({ + axyApi: payload.axyApi, + axyProject: payload.axyProject, + }).toJS(); + // case INIT_RESOURCE_ROOT: + // return Immutable.fromJS(state).merge(payload).toJS(); + // case INIT_PAGE_HEADER_DETAILS: + // return Immutable.fromJS(state).merge({ + // detailsComponent: payload.component + // }).toJS(); + case SET_GLOBAL_SITE_LIST: + return Immutable.fromJS(state).merge({ + sites: payload.data + }).toJS(); + case CLEAR_GLOBAL_SITE_LIST: + return Immutable.fromJS(state).merge({ + sites: [] + }).toJS(); + default: + return state; + } } export default global; \ No newline at end of file diff --git a/web/client/src/sections/auth/actions/auth.js b/web/client/src/sections/auth/actions/auth.js index 6fb0d4d..3fdc65d 100644 --- a/web/client/src/sections/auth/actions/auth.js +++ b/web/client/src/sections/auth/actions/auth.js @@ -1,62 +1,66 @@ 'use strict'; -import { ApiTable } from '$utils' +import { ApiTable, AxyRequest, AxyApiTable } from '$utils' import { Request } from '@peace/utils' +import superagent from "superagent" +// import config from "../../../../../config" export const INIT_AUTH = 'INIT_AUTH'; export function initAuth () { - const user = JSON.parse(sessionStorage.getItem('user')) || {}; - return { - type: INIT_AUTH, - payload: { - user: user - } - }; + const user = JSON.parse(sessionStorage.getItem('user')) || {}; + return { + type: INIT_AUTH, + payload: { + user: user + } + }; } + export const REQUEST_LOGIN = 'REQUEST_LOGIN'; export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; export const LOGIN_ERROR = 'LOGIN_ERROR'; -export function login ({ username, password, phone, code }) { - return dispatch => { - dispatch({ type: REQUEST_LOGIN }); - - return Request.post(ApiTable.login, { username, password, phone, code }) - .then(user => { - sessionStorage.setItem('user', JSON.stringify(user)); - dispatch({ - type: LOGIN_SUCCESS, - payload: { user: user }, - }); - }, error => { - let { body } = error.response; - dispatch({ - type: LOGIN_ERROR, - payload: { - error: body && body.message ? body.message : '登录失败' - } - }) +export function login ({ username, password, phone, code, axyApi, axyProject }) { + return dispatch => { + dispatch({ type: REQUEST_LOGIN }); + + return Request.post(ApiTable.login, { username, password, phone, code }) + .then(user => { + sessionStorage.setItem('user', JSON.stringify(user)); + dispatch({ + type: LOGIN_SUCCESS, + payload: { user: user }, }); - } + }, error => { + let { body } = error.response; + dispatch({ + type: LOGIN_ERROR, + payload: { + error: body && body.message ? body.message : '登录失败' + } + }) + }); + } } export const LOGOUT = 'LOGOUT'; export function logout (user) { - const token = user.token; - const url = ApiTable.logout; - sessionStorage.removeItem('user'); - localStorage.removeItem('zhongding_selected_sider') - localStorage.removeItem('zhongding_open_sider') - Request.put(url, { - token: token - }); - return { - type: LOGOUT - }; + const token = user.token; + const url = ApiTable.logout; + sessionStorage.removeItem('user'); + localStorage.removeItem('zhongding_selected_sider') + localStorage.removeItem('zhongding_open_sider') + Request.put(url, { + token: token + }); + + return { + type: LOGOUT + }; } export default { - initAuth, - login, - logout + initAuth, + login, + logout } \ No newline at end of file diff --git a/web/client/src/sections/auth/containers/login.js b/web/client/src/sections/auth/containers/login.js index 034eab3..708058f 100644 --- a/web/client/src/sections/auth/containers/login.js +++ b/web/client/src/sections/auth/containers/login.js @@ -11,7 +11,7 @@ import { login, LOGIN_ERROR } from '../actions/auth'; import { ExclamationCircleOutlined } from '@ant-design/icons'; import { Uploads } from '$components' import { LockOutlined, UserOutlined } from '@ant-design/icons'; -import '../style.less'; +import './login.less'; const FormItem = Form.Item; @@ -74,7 +74,7 @@ const Login = props => { alignItems: 'center', justifyContent: 'center', color: 'aliceblue', - backgroundImage: 'url(/assets/images/login/login_b.png)', + backgroundImage: 'url(/assets/images/login/login-b.gif)', backgroundSize: 'cover', position: 'relative', }} @@ -82,66 +82,86 @@ const Login = props => { {/* */}