明树Git Lab

Commit 5b49b936 authored by zfp1's avatar zfp1

update

parent 1e45275f
const errorMessage = require("../utils/errorMessage");
const _ = require("lodash");
const { Op, where } = require('sequelize');
const { Op } = require('sequelize');
const userModule = require('../module/userModule');
async function getProjectFields(req, res, next) {
try {
......@@ -43,7 +45,13 @@ async function getProjectFields(req, res, next) {
next(error);
}
}
/**
* 创建提交 创建
* @param {*} req
* @param {*} res
* @param {*} next
* @returns
*/
async function createProject(req, res, next) {
try {
const body = req.body;
......@@ -137,6 +145,24 @@ async function createProject(req, res, next) {
*/
//B. 找到本公司审批人员发送消息-- 如果找不到人 则提示项目已保存,联系管理员添加【项目公司项目审批人】角色
//A. 创建发起记录
if(buttonType === 'submit') {
await DB.FlowRecord.create({
userId: req.user.id,
actionName: '发起项目复核',
projectId: project.id,
});
let approvers = await userModule.getProjectApprover(req.user.id, 'xmgs_xmspr');
if (!( approvers && approvers.length > 0 )) {
return res.sendError('项目已保存,请联系管理员为本公司添加【项目公司项目审批人】角色人员');
}
await DB.Message.createProjectMessage({
projectId: project.id,
creator: req.user.id,
receivers: approvers.map(o => o.id),
type: 2,
content: `项目【${project.name}】已发起,请尽快处理!`
});
}
return res.sendData(project);
} catch (error) {
next(error);
......@@ -144,6 +170,13 @@ async function createProject(req, res, next) {
}
/**
* 更新提交 更新
* @param {*} req
* @param {*} res
* @param {*} next
* @returns
*/
async function updateProject(req, res, next) {
try {
let body = req.body;
......@@ -258,8 +291,9 @@ async function updateProject(req, res, next) {
}
const ret = await DB.Project.update(projectInfo, { where: { id: body.id } });
/**
* 根据前端加入的参数区分按钮 更新草稿并提交 更新草稿
* 根据前端加入的参数区分按钮 更新草稿并提交 更新草稿 TODO:
*/
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -267,6 +301,31 @@ async function updateProject(req, res, next) {
}
async function reviewProject(req, res, next) {
try {
let {id} = req.body;
if (!id) {
return res.sendError(errorMessage.resourceNotFound)
}
let project = await DB.Project.findOne({ where: { id } });
if (!project) {
return res.sendError(errorMessage.resourceNotFound)
}
/**
* 1. 更新项目状态 3 复核通过 复核不通过则回到状态1
*/
if(buttonType === 'approve') {
await DB.Project.update({ status: 3 }, { where: { id } });
} else {
await DB.Project.update({ status: 1 }, { where: { id } });
}
return res.sendData();
} catch (error) {
next(error)
}
}
async function getProjectInfo(req, res, next) {
try {
if (!req.body.id) {
......
......@@ -2,7 +2,7 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
const User = require('./system/user');
const User = require('../system/user');
const Project = sequelize.define('Project', {
// 定义字段
......@@ -21,6 +21,10 @@ const Project = sequelize.define('Project', {
key: 'id',
},
},
projectLiuZhuanType: {
type: DataTypes.STRING,
comment: "项目流转状态 草稿、待初审、初审退回、待终审、终审退回、待立项审批、立项审批退回、已立项、已暂停、已结束等",
},
/**
* 项目基本信息
*/
......
// models/flowRecord.js
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
const User = require('./system/user');
const { act } = require('react');
/**
* 记录流程动作记录
*/
const flowRecord = sequelize.define('flowRecord', {
// 定义字段
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
userId: {
type: DataTypes.INTEGER,
comment: "用户ID",
references: {
model: User,
key: 'id'
}
},
actionName: {
type: DataTypes.STRING(100),
comment: "动作名称 发起项目复核 项目复核通过 项目复核退回 项目终审退回 项目终审通过 项目立项审批通过 项目立项审批不通过等"
},
projectId: {
type: DataTypes.INTEGER,
comment: "项目ID"
},
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: "0 正常 1 删除"
},
}, {
tableName: 'system_user', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
flowRecord.sync({
// force: false,
// force: true ,//会删除已存在表并重新创建
// alter: true
})
.then(() => {
console.log('flowRecord 表同步成功');
});
module.exports = flowRecord;
\ No newline at end of file
......@@ -31,20 +31,19 @@ const Message = sequelize.define('Message', {
allowNull: false,
comment: "消息内容"
},
/**
* 其他待存字段
*/
type: {
type: DataTypes.INTEGER,
allowNull: true,
comment: "消息类型 1 系统消息 2 项目初步审核 3.项目终审"
},
status: {
/**
* 其他待存字段
*/
projectId: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: "0 未读 1 已读"
comment: "关联项目ID"
},
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
......
......@@ -13,10 +13,10 @@ const Role = sequelize.define('Role', {
type: DataTypes.STRING,
commnet: "角色名称",
},
// key: {
// type: DataTypes.STRING,
// commnet: "角色标识",
// },
key: {
type: DataTypes.STRING,
commnet: "角色标识",
},
// enable: {
// type: DataTypes.BOOLEAN,
// defaultValue: true,
......
......@@ -95,9 +95,16 @@ async function setRoleMenu(roleId, menuIds, rolemenus) {
}
}
async function getProjectApprover(userId, roleCode) {
// 获取当前用户公司的 具体角色 的用户列表
let user = await DB.User.findOne({ where: { id: userId } });
return [];
}
module.exports = {
setUserRole,
setUserDepart,
setRoleMenu,
getProjectApprover,
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment