Browse Source

任务管理和人员管理

dev
zhaobing 2 years ago
parent
commit
31e10ec03e
  1. 24
      api/app/lib/controllers/auth/index.js
  2. 101
      api/app/lib/controllers/data/task.js
  3. 16
      api/app/lib/controllers/organization/user.js
  4. 8
      api/app/lib/index.js
  5. 87
      api/app/lib/models/task_manage.js
  6. 8
      api/app/lib/models/user.js
  7. 16
      api/app/lib/routes/data/index.js
  8. 2
      web/client/src/layout/containers/layout/index.js
  9. 2
      web/client/src/layout/index.js

24
api/app/lib/controllers/auth/index.js

@ -4,23 +4,31 @@ const MD5 = require('crypto-js/md5');
const moment = require('moment');
const uuid = require('uuid');
async function login (ctx, next) {
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;
console.log('params.username', params)
let password = Hex.stringify(MD5(params.password));
const userRes = await models.User.findOne({
where: {
username: params.username,
$or: [{ username: params.username },
{ phone: params.username }
],
password: password,
delete: false,
},
attributes: { exclude: ['password', 'delete'] },
});
if (!userRes) {
console.log('userRes', userRes)
if (!userRes.isAdmin) {
ctx.status = 400;
ctx.body = {
"message": "不是管理员,禁止登录"
}
}
else if (!userRes) {
ctx.status = 400;
ctx.body = {
"message": "账号或密码错误"
@ -65,7 +73,7 @@ async function login (ctx, next) {
* 微信小程序登录
* @@requires.body {phone-手机号, password-密码} ctx
*/
async function wxLogin (ctx, next) {
async function wxLogin(ctx, next) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const models = ctx.fs.dc.models;
@ -87,7 +95,7 @@ async function wxLogin (ctx, next) {
ctx.body = { message: "该用户已被禁用" }
} else {
const token = uuid.v4();
let userRslt = Object.assign({
authorized: true,
token: token,
@ -114,7 +122,7 @@ async function wxLogin (ctx, next) {
}
}
async function logout (ctx) {
async function logout(ctx) {
try {
const { token, code } = ctx.request.body;
const models = ctx.fs.dc.models;

101
api/app/lib/controllers/data/task.js

@ -0,0 +1,101 @@
'use strict';
async function getTask(ctx) {
try {
const models = ctx.fs.dc.models
const query = ctx.query
const whereopt = {
isdanger: query.isdanger
}
console.log('whereopt', whereopt)
const whereRoadOpt = {
id: query.id
}
console.log('wherwhereRoadOpteopt', whereRoadOpt)
const taskRes = await models.TaskManage.findAndCountAll({
order: [['id', 'DESC']],
attributes: ['id', 'dangerDescription', 'isdanger', 'issuanceTime', 'reportTime'],
include: [
{
attributes: ['routeName', 'routeCode'],
model: models.Road,
where: query.id == undefined ? {} : whereRoadOpt
},
{
attributes: ['name'],
model: models.User
}
],
where: query.isdanger == undefined ? {} : whereopt
})
ctx.body = taskRes
console.log('tas', taskRes)
ctx.status = 200
}
catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: '获取失败'
}
}
}
//删除任务
async function delTask(ctx) {
try {
const models = ctx.fs.dc.models
const { id } = ctx.params
console.log('params', id)
await models.TaskManage.destroy({ where: { id: id } })
ctx.status = 204
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: '删除失败'
}
}
}
//编辑任务
async function editTask(ctx) {
//const transaction = await ctx.fs.dc.orm.transaction();
try {
const models = ctx.fs.dc.models
const params = ctx.request.body
if (!params.id) {
const road = await models.Road.findOne({ where: { routeCode: params.routeCode } })
const user = await models.User.findOne({ where: { name: params.name } })
console.log('params', road.id, user.id)
await models.TaskManage.create({
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim()
})
} else {
const road = await models.Road.findOne({ where: { routeCode: params.routeCode } })
const user = await models.User.findOne({ where: { name: params.name } })
await models.TaskManage.update({
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim()
}, { where: { id: params.id } })
}
ctx.status = 204
//await transaction.commit();
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: '新增失败'
}
}
}
module.exports = {
getTask, delTask, editTask
};

16
api/app/lib/controllers/organization/user.js

@ -2,7 +2,7 @@
const Hex = require('crypto-js/enc-hex');
const MD5 = require('crypto-js/md5');
async function getUser (ctx, next) {
async function getUser(ctx, next) {
try {
const models = ctx.fs.dc.models;
const { depId } = ctx.params
@ -26,7 +26,7 @@ async function getUser (ctx, next) {
}
}
async function getUserAll (ctx, next) {
async function getUserAll(ctx, next) {
try {
const models = ctx.fs.dc.models;
const userRes = await models.User.findAll({
@ -48,11 +48,11 @@ async function getUserAll (ctx, next) {
}
}
async function creatUser (ctx, next) {
async function creatUser(ctx, next) {
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
console.log('data', data)
let repeatUserNameCount = await models.User.count({
where: {
phone: data.phone,
@ -74,6 +74,7 @@ async function creatUser (ctx, next) {
delete: false,
phone: data.phone,
remark: 'th',
isAdmin: data.isAdmin
})
ctx.status = 204;
@ -87,7 +88,7 @@ async function creatUser (ctx, next) {
}
async function updateUser (ctx, next) {
async function updateUser(ctx, next) {
let errMsg = "修改用户失败"
try {
const models = ctx.fs.dc.models;
@ -114,6 +115,7 @@ async function updateUser (ctx, next) {
enable: data.enable,
delete: false,
phone: data.phone,
isAdmin: data.isAdmin
}, {
where: {
id: userId
@ -130,7 +132,7 @@ async function updateUser (ctx, next) {
}
}
async function deleteUser (ctx, next) {
async function deleteUser(ctx, next) {
try {
const models = ctx.fs.dc.models;
const { userIds } = ctx.params;
@ -174,7 +176,7 @@ async function deleteUser (ctx, next) {
// }
// }
async function setPassword (ctx, next) {
async function setPassword(ctx, next) {
try {
const models = ctx.fs.dc.models;
const { userId } = ctx.params;

8
api/app/lib/index.js

@ -26,7 +26,7 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
require(`./models/${filename}`)(dc)
});
const { User, Department, Report, FileType, Road, Files, FileRoad } = dc.models;
const { User, Department, Report, FileType, Road, Files, FileRoad, TaskManage } = dc.models;
// 定义外键
User.belongsTo(Department, { foreignKey: 'departmentId', targetKey: 'id' });
Department.hasMany(User, { foreignKey: 'departmentId', sourceKey: 'id' });
@ -40,4 +40,10 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
// Files.belongsTo(Road, { foreignKey: 'roadId', targetKey: 'id' });
// Road.hasMany(Files, { foreignKey: 'roadId', targetKey: 'id' });
//定义外键
TaskManage.belongsTo(User, { foreignKey: 'userid', targetKey: 'id' })
User.hasMany(TaskManage, { foreignKey: 'userid', targetKey: 'id' })
//
TaskManage.belongsTo(Road, { foreignKey: 'roadid', targetKey: 'id' })
Road.hasMany(TaskManage, { foreignKey: 'roadid', targetKey: 'id' })
};

87
api/app/lib/models/task_manage.js

@ -0,0 +1,87 @@
/* eslint-disable*/
'use strict';
module.exports = dc => {
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const TaskManage = sequelize.define("taskManage", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: "id",
primaryKey: true,
field: "id",
autoIncrement: true
},
roadid: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: "道路id",
primaryKey: false,
field: "roadid",
autoIncrement: false,
references: {
key: "id",
model: "road"
}
},
dangerDescription: {
type: DataTypes.CHAR,
allowNull: true,
defaultValue: null,
comment: "隐患说明",
primaryKey: false,
field: "danger_description",
autoIncrement: false
},
issuanceTime: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: null,
comment: "下发时间",
primaryKey: false,
field: "issuance_time",
autoIncrement: false
},
userid: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: "用户id",
primaryKey: false,
field: "userid",
autoIncrement: false,
references: {
key: "id",
model: "user"
}
},
isdanger: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: null,
comment: "是否存在安全隐患,flase(不存在)",
primaryKey: false,
field: "isdanger",
autoIncrement: false
},
reportTime: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: null,
comment: "上报时间",
primaryKey: false,
field: "report_time",
autoIncrement: false
}
}, {
tableName: "task_manage",
comment: "",
indexes: []
});
dc.models.TaskManage = TaskManage;
return TaskManage;
};

8
api/app/lib/models/user.js

@ -14,6 +14,14 @@ module.exports = dc => {
field: "id",
autoIncrement: true
},
isAdmin: {
type: DataTypes.BOOLEAN,
defaultValue: null,
comment: null,
primaryKey: false,
field: "isadmin",
autoIncrement: false
},
name: {
type: DataTypes.STRING,
allowNull: false,

16
api/app/lib/routes/data/index.js

@ -8,7 +8,7 @@ const overspeed = require('../../controllers/data/overspeed');
const bus = require('../../controllers/data/bus');
const publicity = require('../../controllers/data/publicity');
const dataIndex = require('../../controllers/data/index');
const task = require('../../controllers/data/task')
module.exports = function (app, router, opts) {
// 数据导出
@ -21,7 +21,7 @@ module.exports = function (app, router, opts) {
// 运政
//货运
async function setFreightType (ctx, next) {
async function setFreightType(ctx, next) {
ctx.request.body = {
...(ctx.request.body || {}),
type: 'freight'
@ -38,7 +38,7 @@ module.exports = function (app, router, opts) {
router.del('/vehicle/freight/:id', setFreightType, vehicle.del);
//客运车
async function setVehicleType (ctx, next) {
async function setVehicleType(ctx, next) {
ctx.request.body = {
...(ctx.request.body || {}),
type: 'vehicle'
@ -55,7 +55,7 @@ module.exports = function (app, router, opts) {
router.del('/vehicle/:id', setVehicleType, vehicle.del);
// 路政
async function setRoadManageType (ctx, next) {
async function setRoadManageType(ctx, next) {
ctx.request.body = {
...(ctx.request.body || {}),
type: 'road_manage'
@ -172,4 +172,12 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['DEL/publicity/:publicityId'] = { content: '删除宣传数据', visible: false };
router.del('/publicity/:publicityId', publicity.publicityDel);
//publicity END
// task
app.fs.api.logAttr['GET/task'] = { content: '获取任务列表', visible: false };
router.get('/task', task.getTask);
app.fs.api.logAttr['DEL/task/:id'] = { content: '删除任务', visible: false };
router.del('/task/:id', task.delTask);
app.fs.api.logAttr['PUT/editTask'] = { content: '编辑任务', visible: false };
router.put('/editTask', task.editTask);
//task END
};

2
web/client/src/layout/containers/layout/index.js

@ -132,7 +132,7 @@ const LayoutContainer = props => {
)
}
function mapStateToProps (state) {
function mapStateToProps(state) {
const { global, auth, ajaxResponse } = state;
return {
title: global.title,

2
web/client/src/layout/index.js

@ -90,7 +90,7 @@ const Root = props => {
let actions = {
layout: layoutActions
}
for (let s of sections) {
if (!s.key) console.warn('请给你的section添加一个key值,section name:' + s.name);
for (let r of s.routes) {

Loading…
Cancel
Save