明树Git Lab

Commit 22bcd01f authored by zfp1's avatar zfp1

update

parent 2ceedc38
Pipeline #106720 passed with stage
in 3 seconds
......@@ -3,6 +3,89 @@ const _ = require("lodash");
const { Op } = require('sequelize');
// ---------------- 信息报送 RcXxbs ----------------
// 创建信息报送
async function createXxbs(req, res, next) {
try {
req.body.creator = req.user.id;
let ret = await DB.RcXxbs.create(req.body);
return res.sendData(ret);
} catch (error) {
next(error);
}
}
// 更新信息报送
async function updateXxbs(req, res, next) {
try {
if (!req.body.id) return res.sendError(errorMessage.paramsError);
let ret = await DB.RcXxbs.findOne({ where: { id: req.body.id }, raw: true });
if (!(ret && ret.id)) return res.sendError(errorMessage.resourceNotFound);
await DB.RcXxbs.update(req.body, { where: { id: req.body.id } });
return res.sendData({});
} catch (error) {
next(error);
}
}
// 获取单个信息报送
async function getXxbs(req, res, next) {
try {
if (!req.body.id) return res.sendError(errorMessage.paramsError);
let info = await DB.RcXxbs.findOne({ where: { id: req.body.id, del: 0 }, raw: true });
if (!(info && info.id)) return res.sendError(errorMessage.resourceNotFound);
return res.sendData(info);
} catch (error) {
next(error);
}
}
// 获取信息报送列表
async function getXxbsList(req, res, next) {
try {
let page = req.body.page || 1;
let limit = req.body.pagesize || req.body.pageSize || 10;
let offset = (page - 1) * limit;
let search = {};
search.order = [['createdAt', 'DESC']];
search.limit = limit;
search.offset = offset;
let where = { del: 0 };
if (req.body.wjmc) {
where.wjmc = { [Op.like]: `%${req.body.wjmc}%` };
}
if (req.body.bzr) {
where.bzr = { [Op.like]: `%${req.body.bzr}%` };
}
if (req.body.projectId) {
where.projectId = req.body.projectId;
}
if (req.body.nd) {
where.nd = req.body.nd;
}
search.where = where;
if (req.body.attributes && req.body.attributes.length) {
search.attributes = req.body.attributes;
}
let ret = await DB.RcXxbs.findAndCountAll(search);
return res.sendData(ret);
} catch (error) {
next(error);
}
}
// 删除信息报送
async function deleteXxbs(req, res, next) {
try {
await DB.RcXxbs.update({ del: 1 }, { where: { id: req.body.id } });
return res.sendData({});
} catch (error) {
next(error);
}
}
// ---------------- 投资规划 RcTzgh ----------------
// 创建投资规划
async function createTzgh(req, res, next) {
......@@ -95,20 +178,8 @@ async function deleteTzgh(req, res, next) {
async function createTxjs(req, res, next) {
try {
req.body.creator = req.user.id;
if (!req.body.projectId) {
return res.sendError(errorMessage.paramsError);
}
// 创建主表
let ret = await DB.RcTxjs.create(req.body);
// 处理附件/子表
let wjs = (req.body.rcTxjsWjs || []).map(o => { o.projectId = req.body.projectId; o.sourceId = ret.id; return o });
if (wjs.length) {
await DB.RcTxjsWj.bulkCreate(wjs);
}
return res.sendData(ret);
} catch (error) {
next(error);
}
......@@ -116,27 +187,13 @@ async function createTxjs(req, res, next) {
async function updateTxjs(req, res, next) {
try {
if (!(req.body.id && req.body.projectId)) {
if (!req.body.id) {
return res.sendError(errorMessage.paramsError);
}
let ret = await DB.RcTxjs.findOne({ where: { id: req.body.id }, raw: true });
if (!(ret && ret.id)) {
return res.sendError(errorMessage.resourceNotFound);
}
// 处理子表 rc 文件
let arr = req.body.rcTxjsWjs || [];
let ids = [], infos = [], newArr = [];
(arr || []).map(o => {
if (!o.id) {
if (!_.isEmpty(o)) { o.projectId = req.body.projectId; o.sourceId = ret.id; newArr.push(o); }
} else { ids.push(o.id); infos.push(o); }
return o;
});
await DB.RcTxjsWj.destroy({ where: { projectId: req.body.projectId, sourceId: ret.id, id: { [Op.notIn]: ids } } });
if (newArr.length) await DB.RcTxjsWj.bulkCreate(newArr);
await Promise.all(infos.map(item => { return DB.RcTxjsWj.update(item, { where: { id: item.id } }) }));
await DB.RcTxjs.update(req.body, { where: { id: req.body.id } });
return res.sendData({});
} catch (error) {
......@@ -145,18 +202,13 @@ async function updateTxjs(req, res, next) {
}
async function getTxjs(req, res, next) {
try {
let search = {};
if (req.body.id) search.id = req.body.id;
if (req.body.projectId) search.projectId = req.body.projectId;
if (_.isEmpty(search)) {
if (!req.body.id) {
return res.sendError(errorMessage.paramsError);
}
let tx = await DB.RcTxjs.findOne({ where: search, raw: true });
if (!(tx && tx.id && tx.projectId)) {
let tx = await DB.RcTxjs.findOne({ where: { id: req.body.id }, raw: true });
if (!(tx && tx.id)) {
return res.sendError(errorMessage.resourceNotFound);
}
let wjs = await DB.RcTxjsWj.findAll({ where: { projectId: tx.projectId, sourceId: tx.id }, raw: true });
tx.rcTxjsWjs = wjs || [];
return res.sendData(tx);
} catch (error) {
next(error);
......@@ -169,23 +221,21 @@ async function getTxjsList(req, res, next) {
let page = req.body.page || 1;
let limit = req.body.pagesize || req.body.pageSize || 10;
let offset = (page - 1) * limit;
let search = {};
search.order = [['createdAt', 'DESC']];
search.limit = limit;
search.offset = offset;
let where = { del: 0 };
if (req.body.projectName) {
where = {
[Op.or]: [
{ projectName: { [Op.like]: `%${req.body.projectName}%` } },
],
del: 0
if (req.body.wjmc) {
where.wjmc = { [Op.like]: `%${req.body.wjmc}%` };
}
if (req.body.wjcj) {
where.wjcj = req.body.wjcj;
}
if (req.body.wjlb) {
where.wjlb = req.body.wjlb;
}
search.where = where;
if (req.body.attributes && req.body.attributes.length) {
search.attributes = req.body.attributes;
}
......@@ -421,4 +471,11 @@ module.exports = {
getTzgh,
getTzghList,
deleteTzgh,
// 信息报送
createXxbs,
updateXxbs,
getXxbs,
getXxbsList,
deleteXxbs,
}
\ No newline at end of file
......@@ -75,15 +75,17 @@ const ThYyqtzhszb = require('./model/jt/thYyqtzhszb');
const ThYyqtzjc = require('./model/jt/thYyqtzjc');
const ThYyqtzjcTzfx = require('./model/jt/thYyqtzjcTzfx');
const ThYyqtzjcZxjc = require('./model/jt/thYyqtzjcZxjc');
const ThYyqtzjcrcjc = require('./model/jt/thYyqtzjcrcjc');
// const ThYyqtzjcrcjc = require('./model/jt/thYyqtzjcrcjc');
const ThYjgl = require("./model/jt/thYjgl");
const RcTxjs = require('./model/jt/rcTxjs');
const RcTxjsWj = require('./model/jt/rcTxjswj');
const RcCgqygl = require('./model/jt/rcCgqygl');
const RcCgqyglTzfh = require('./model/jt/rcCgqyglTzfh');
const RcCgqyglWtyy = require('./model/jt/rcCgqyglWtyy');
const RcTzgh = require('./model/jt/rcTzgh');
const RcXxbs = require('./model/jt/rcXxbs');
const RcTwhgl = require('./model/jt/rcTwhgl');
/**
* 业务表
*/
......@@ -139,15 +141,15 @@ global.DB = {
TzZdfx,
TzZdfxcz,
TzZdfxcwzb,
TzZdfxqk,
// TzZdfxcwzb,
// TzZdfxqk,
TzJsqtzjc,
TzJsqtzjcTzfx,
TzJsqtzjcrcjc,
// TzJsqtzjcrcjc,
TzJsqtzjcZxjc,
TzZdsxsp,
TzZdsxspfl,
// TzZdsxspfl,
TzXmtc,
TzXmtcCwzb,
......@@ -158,17 +160,16 @@ global.DB = {
ThYyqtzjc,
ThYyqtzjcTzfx,
ThYyqtzjcZxjc,
ThYyqtzjcrcjc,
// ThYyqtzjcrcjc,
ThYjgl,
RcTxjs,
RcTxjsWj,
RcCgqygl,
RcCgqyglTzfh,
RcCgqyglWtyy,
RcTzgh,
RcTwhgl,
RcXxbs,
}
......
......@@ -32,9 +32,7 @@ const RcTwhgl = sequelize.define('RcTwhgl', {
comment: '会议地点'
},
meetingLevel: {
type: DataTypes.ENUM('company', 'department', 'project'),
allowNull: false,
defaultValue: 'company',
type: DataTypes.STRING,
comment: '会议层级:company-公司级,department-部门级,project-项目级'
},
attendingLeaders: {
......
......@@ -9,19 +9,40 @@ const RcTxjs = sequelize.define('RcTxjs', {
primaryKey: true,
autoIncrement: true
},
projectName: {
wjmc: {
type: DataTypes.STRING,
comment: "项目名称",
comment: "文件名称",
},
bbsj: {
type: DataTypes.DATE,
get() {
const rawValue = this.getDataValue('bbsj');
return rawValue ? moment(rawValue).format('YYYY-MM-DD') : '';
}
},
wjcj: {
type: DataTypes.STRING,
comment: "文件层级",
},
wjlb: {
type: DataTypes.STRING,
comment: "文件类别",
},
fjsc: {
type: DataTypes.JSON,
comment: "附件上传",
},
creator: {
type: DataTypes.INTEGER,
comment: "创建人"
},
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
},
// projectId: {
// type: DataTypes.INTEGER,
// comment: "所属项目ID",
// },
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
......
const { DataTypes } = require('sequelize');
const sequelize = require('../index');
const moment = require('moment');
//投中管理- 建设期投资检查
const RcTxjsWj = sequelize.define('RcTxjsWj', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
wjlx: {
type: DataTypes.STRING,
comment: "文件类型"
},
wj: {
type: DataTypes.JSON,
comment: "文件上传"
},
wjsm: {
type: DataTypes.TEXT,
comment: "文件说明"
},
cj: {
type: DataTypes.STRING,
comment: "层级"
},
sourceId: {
type: DataTypes.INTEGER,
comment: "所属主表id"
},
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
},
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
comment: "0 正常 1 删除"
},
createdAt: {
type: DataTypes.DATE,
defaultValue: new Date(),
get() {
const rawValue = this.getDataValue('createdAt');
return rawValue ? moment(rawValue).format('YYYY-MM-DD HH:mm:ss') : '';
}
},
updatedAt: { // 同样处理 updatedAt
type: DataTypes.DATE,
defaultValue: new Date(),
get() {
const rawValue = this.getDataValue('updatedAt');
return rawValue ? moment(rawValue).format('YYYY-MM-DD HH:mm:ss') : '';
}
}
}, {
tableName: 'jt_rc_rctxwj', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
RcTxjsWj.sync({
// force: false,
// force: true ,//会删除已存在表并重新创建
alter: true
})
.then(() => {
console.log('RcTxjsWj 表同步成功');
});
module.exports = RcTxjsWj;
\ No newline at end of file
......@@ -2,8 +2,8 @@ const { DataTypes } = require('sequelize');
const sequelize = require('../index');
const moment = require('moment');
//投中管理- 建设期投资检查
const RcTxjsWj = sequelize.define('RcTxjsWj', {
//投中管理- 投资规划
const RcTzgh = sequelize.define('RcTzgh', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
......@@ -66,10 +66,10 @@ const RcTxjsWj = sequelize.define('RcTxjsWj', {
projectId: {
type: DataTypes.INTEGER,
comment: "所属项目ID",
},
// projectId: {
// type: DataTypes.INTEGER,
// comment: "所属项目ID",
// },
del: {
type: DataTypes.INTEGER,
defaultValue: 0,
......@@ -96,19 +96,19 @@ const RcTxjsWj = sequelize.define('RcTxjsWj', {
}
}
}, {
tableName: 'jt_rc_rctxwj', // 指定表名(如果与模型名不同)
tableName: 'jt_rc_tzgh', // 指定表名(如果与模型名不同)
timestamps: true, // 是否自动添加 createdAt 和 updatedAt 字段(覆盖全局设置)
});
// 同步模型到数据库(创建表)
RcTxjsWj.sync({
RcTzgh.sync({
// force: false,
// force: true ,//会删除已存在表并重新创建
alter: true
})
.then(() => {
console.log('RcTxjsWj 表同步成功');
console.log('RcTzgh 表同步成功');
});
module.exports = RcTxjsWj;
\ No newline at end of file
module.exports = RcTzgh;
\ No newline at end of file
......@@ -10,7 +10,32 @@ const RcXxbs = sequelize.define('RcXxbs', {
autoIncrement: true
},
nd: {
type: DataTypes.DATE,
get() {
const rawValue = this.getDataValue('nd');
return rawValue ? moment(rawValue).format('YYYY') : '';
}
},
wjmc: {
type: DataTypes.STRING,
comment: "文件名称",
},
fjsc: {
type: DataTypes.JSON,
comment: "附件上传",
},
bzr: {
type: DataTypes.STRING,
comment: "编制人",
},
bzrbm: {
type: DataTypes.STRING(500),
comment: "编制人部门",
},
sourceId: {
......
......@@ -166,10 +166,11 @@ router.post('/deleteTzgh', projectRcController.deleteTzgh);
//4.4 信息报送
router.post('/createXxbs', projectRcController.createXxbs);
router.post('/updateXxbs', projectRcController.updateXxbs);
router.post('/getXxbs', projectRcController.getXxbs);
router.post('/getXxbsList', projectRcController.getXxbsList);
router.post('/deleteXxbs', projectRcController.deleteXxbs);
//4.5 投委会管理
router.post('/createTwhgl', projectRcController.createTwhgl);
router.post('/updateTwhgl', projectRcController.updateTwhgl);
......
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