明树Git Lab

Commit b88b2e7f authored by zfp1's avatar zfp1

update

parent 62a1612d
const errorMessage = require("../utils/errorMessage");
const _ = require("lodash");
const { Op } = require('sequelize');
const sequelize = require('sequelize');
const userModule = require('../module/userModule');
......@@ -77,8 +78,10 @@ async function createProject(req, res, next) {
let projectInfo = _.omit(body, ['projectJsgms', 'projectGdxxs', 'projectXmtzzes', 'projectBjtjs',
'projectSpyjs', 'projectFxgls', 'projectTzzts', 'projectJczts', 'projectZqrzs', 'projectCwpjzbs', 'projectLcbjds',
'lxzl', 'lxpfwj', 'xgshcl']);
projectInfo.projectCreator = req.user.id;
projectInfo.projectLiuZhuanType = 1; // 草稿状态
let project = await DB.Project.create(projectInfo);
project = project.toJSON();
// 处理 projectJsgms
let projectJsgms = body.projectJsgms || [];
projectJsgms = projectJsgms.map(o => { o.projectId = project.id; return o });
......@@ -136,6 +139,7 @@ async function createProject(req, res, next) {
xgshcl = xgshcl.map(o => { return { fileId: o.id, projectId: project.id, proFieldKey: 'xgshcl' } });
// 处理文件
let proFiles = _.concat(lxzl, lxpfwj, xgshcl);
console.log(proFiles, "=================")
await DB.ProjectFile.bulkCreate(proFiles);
/**
......@@ -156,17 +160,19 @@ async function createProject(req, res, next) {
});
let approvers = await userModule.getProjectApprover(req.user.id, 'xmgs_xmspr');
if (!(approvers && approvers.length > 0)) {
return res.sendError('项目已保存,请联系管理员为本公司添加【项目初审】角色人员');
return res.sendError({code: '60001', msg: '项目已保存,请联系管理员为本公司添加【项目初审】角色人员'});
}
await DB.Message.createProjectMessage({
await DB.Message.create({
projectId: project.id,
creator: req.user.id,
receivers: approvers.map(o => o.id),
type: 2,
title: `项目【${project.name}】已发起,请尽快处理!`,
content: `项目【${project.name}】已发起,请尽快处理!`
});
await DB.Project.update({ projectLiuZhuanType: 3 }, { where: { id: project.id } });
}
console.log(project)
return res.sendData(project);
} catch (error) {
next(error);
......@@ -296,12 +302,12 @@ async function updateProject(req, res, next) {
if (!(approvers && approvers.length > 0)) {
return res.sendError('项目已保存,请联系管理员为本公司添加【项目初审】角色人员');
}
await DB.Message.createProjectMessage({
await DB.Message.create({
projectId: project.id,
creator: req.user.id,
receivers: approvers.map(o => o.id),
type: 2,
content: `项目【${project.name}】已发起,请尽快处理!`
content: `项目【${project.name}】已发起初审,请尽快处理!`
});
projectInfo.projectLiuZhuanType = 3; // 待初审
}
......@@ -335,11 +341,40 @@ async function preJugProject(req, res, next) {
* 1. 更新项目状态 5 初审通过 初审不通过则回到状态1
*/
if (req.body.buttonType === 'approve') {
await DB.Project.update({ projectLiuZhuanType: 3 }, { where: { id } });
await DB.Project.update({ projectLiuZhuanType: 5 }, { where: { id } });
//处理项目流转记录 及消息发送TODO:
await DB.FlowRecord.create({
userId: req.user.id,
actionName: '项目初审通过,提交终审',
projectId: project.id,
});
let approvers = await userModule.getProjectApprover(req.user.id, 'jt_xmzs');
if (!(approvers && approvers.length > 0)) {
return res.sendError('项目已保存,请联系管理员为本公司添加【项目初审】角色人员');
}
await DB.Message.create({
projectId: project.id,
creator: req.user.id,
receivers: approvers.map(o => o.id),
type: 2,
content: `项目【${project.name}】已发起终审,请尽快处理!`
});
} else {
await DB.Project.update({ projectLiuZhuanType: 1 }, { where: { id } });
//处理项目流转记录 及消息发送TODO:
await DB.FlowRecord.create({
userId: req.user.id,
actionName: '项目初审不通过,退回处理',
projectId: project.id,
});
let approvers = [project.projectCreator]
await DB.Message.create({
projectId: project.id,
creator: req.user.id,
receivers: approvers.map(o => o.id),
type: 2,
content: `项目【${project.name}】已退回,请尽快处理!`
});
}
return res.sendData();
......@@ -355,25 +390,30 @@ async function preJugProject(req, res, next) {
* @returns
*/
async function finalJugProject(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. 更新项目状态 5 终审通过 初审不通过则回到状态1
*/
if (req.body.buttonType === 'approve') {
await DB.Project.update({ projectLiuZhuanType: 7 }, { where: { id } });
//处理项目流转记录 及消息发送TODO:
} else {
await DB.Project.update({ projectLiuZhuanType: 1 }, { where: { id } });
//处理项目流转记录 及消息发送TODO:
}
try {//TODO:逻辑有道商榷
// 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. 更新项目状态 7 终审通过 终审不通过则回到状态1
// */
// if (req.body.buttonType === 'approve') {
// await DB.Project.update({ projectLiuZhuanType: 7 }, { where: { id } });
// //处理项目流转记录 及消息发送TODO:
// await DB.FlowRecord.create({
// userId: req.user.id,
// actionName: '项目终审通过,等待立项',
// projectId: project.id,
// });
// } else {
// await DB.Project.update({ projectLiuZhuanType: 1 }, { where: { id } });
// //处理项目流转记录 及消息发送TODO:
// }
return res.sendData();
} catch (error) {
......@@ -444,7 +484,7 @@ async function getProjectInfo(req, res, next) {
},
{
model: DB.ProjectTzzt,
as: 'projectTzzts',
as: 'projectTzzts',
// where: { del: 0 },
// attributes: [],
},
......@@ -512,7 +552,7 @@ async function listProject(req, res, next) {
}
search.limit = limit;
search.offset = offset;
if(req.body.attributes.length) {
if (req.body.attributes.length) {
search.attributes = req.body.attributes;
}
let ret = await DB.Project.findAndCountAll(search);
......@@ -595,6 +635,58 @@ async function exportExcel(req, res, next) {
}
}
async function getOwnProjects(req, res, next) {
try {
let page = req.body.page || 1;
let limit = req.body.pageSize || 10;
let offset = (page - 1) * limit;
let search = { where: { del: 0 } };
//确定可见范围,结合当前人角色
let messs = await DB.Message.findAll({
//项目审批信息接收方
where: {
[Op.and]: [
sequelize.where(
sequelize.fn('JSON_CONTAINS',
sequelize.col('receivers'),
sequelize.cast(req.user.id, 'JSON'),
'$'
),
true
),
,
{ projectId: { [Op.ne]: null } },
]
},
attributes: ['projectId']
});
console.log(messs)
let projectIds = messs.map(o => { return o && o.projectId });
//
search.where = {
[Op.or]: [
{ projectCreator: req.user.id },
{ id: { [Op.in]: projectIds } }
]
};
if (req.body.name) {
search.where[[Op.or]].push({ name: { [Op.like]: `%${req.body.name}%` } });
}
search.limit = limit;
search.offset = offset;
if (req.body.attributes && req.body.attributes.length) {
search.attributes = req.body.attributes;
}
console.log(search, "-==")
let ret = await DB.Project.findAndCountAll(search);
return res.sendData(ret);
} catch (error) {
next(error);
}
}
module.exports = {
getProjectFields,
createProject,
......@@ -605,4 +697,5 @@ module.exports = {
exportExcel,
preJugProject,
finalJugProject,
getOwnProjects,
}
\ No newline at end of file
......@@ -23,7 +23,11 @@ const Project = sequelize.define('Project', {
},
projectLiuZhuanType: {
type: DataTypes.STRING,
comment: "项目流转状态 1. 待初审、3 待初审、1初审退回、5待终审、1终审退回、7待立项审批、立项审批退回、已立项、已暂停、已结束等",
comment: "项目流转状态 1. 待提交、3 待初审、1初审退回、5待终审、1终审退回、7待立项审批、立项审批退回、已立项、已暂停、已结束等",
},
projectLiuZhuanTypeDes: {
type: DataTypes.STRING,
comment: "项目流转状态说明 待提交 待初审 初审退回 待终审 终审退回 待立项审批 立项审批退回 已立项 已结束等",
},
/**
* 项目基本信息
......
......@@ -35,13 +35,13 @@ const flowRecord = sequelize.define('flowRecord', {
comment: "0 正常 1 删除"
},
}, {
tableName: 'system_user', // 指定表名(如果与模型名不同)
tableName: 'system_flowrecord', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
flowRecord.sync({
// force: false,
force: false,
// force: true ,//会删除已存在表并重新创建
// alter: true
})
......
......@@ -134,7 +134,7 @@ async function getProjectApprover(userId, roleCode) {
// 获取当前用户公司的 具体角色 的用户列表
let user = await DB.User.findOne({ where: { id: userId } });
return [];
return [user];
}
module.exports = {
......
......@@ -18,7 +18,9 @@ router.post('/getProjectFields', projectController.getProjectFields);
router.post('/exportExcel', projectController.exportExcel);
router.post('/preJugProject', projectController.preJugProject); //初审
router.post('/finalJugProject', projectController.finalJugProject); //终审
router.post('/finalJugProject', projectController.finalJugProject); //终审 --暂时没有
router.post('/getOwnProjects', projectController.getOwnProjects);
......
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