Commit 15b097ce by chenjinjing

no message

parent 90b13405
......@@ -9,28 +9,28 @@ import { BizError } from "../../util/bizError";
* @param param
* @returns
*/
export async function selectOneDataByParam(tableName:string, param:any) {
export async function selectOneDataByParam(tableName:string, column:any, param:any) {
let model = modelMap[tableName];
if (!model) throw new BizError(ERRORENUM.不存在表);
let data = model.findOnceData(param);
let data = model.findOnceData(column, param);
return {data};
}
export async function selectDataListByParam(tableName:string, param:any) {
export async function selectDataListByParam(tableName:string, column:any, param:any) {
let model = modelMap[tableName];
if (!model) throw new BizError(ERRORENUM.不存在表);
let data = model.findManyData(param);
let data = model.findManyData(column, param);
return {data};
}
export async function selectDataListToPageByParam(tableName:string, param:any, pageNumber:number, pageSize:number) {
export async function selectDataListToPageByParam(tableName:string, column:any, param:any, pageNumber:number, pageSize:number) {
pageSize = pageSize || 10;
let model = modelMap[tableName];
if (!model) throw new BizError(ERRORENUM.不存在表);
let data = model.findDataToPage(param, (pageNumber-1)*10, pageSize );
let data = model.findDataToPage(column, param, (pageNumber-1)*10, pageSize );
return {data};
}
......@@ -50,4 +50,14 @@ export async function aggragateParam(tableName:string, param:any) {
let data = await model.aggragateData(param);
return {data};
}
export async function selectDataToTableAssociation(tableName:string, associatedTable:string, column:any, param:any) {
let model = modelMap[tableName];
if (!model) throw new BizError(ERRORENUM.不存在表);
let data = await model.findDataToTableAssociation(associatedTable, column, param);
return {data};
}
\ No newline at end of file
......@@ -13,7 +13,8 @@ export const TablesConfig = {
unique:true //表示该列的值必须唯一
},
branchName: {type:Sequelize.STRING(100), allowNull:false}, //支部名称
}
},
association: [{}]
},
"后台用户表":{
tableName:'adminUser',
......@@ -28,7 +29,8 @@ export const TablesConfig = {
pwd:{type:Sequelize.STRING(100), allowNull:false}, //密码
token:{type:Sequelize.STRING(100), allowNull:false},
tokenMs:{type:Sequelize.DATE, allowNull:false}
}
},
association: [{}]
},
"党员基础信息表":{
tableName:'partyMember',
......@@ -63,7 +65,13 @@ export const TablesConfig = {
tokenMs:{ type:Sequelize.DATE, allowNull:false },
adminToken:{type:Sequelize.STRING(100), allowNull:false},
adminTokenMs:{ type:Sequelize.DATE, allowNull:false },
}
},
association: [
{type: "hasOne", table1: "branch", table2: "partyMember"},
{type: "hasOne", table1: "administrativePosition", table2: "partyMember"},
{type: "hasMany", table1: "partyPositions", table2: "partyMember"},
{type: "hasMany", table1: "department", table2: "partyMember"},
]
},
"行政职务表":{
tableName:'administrativePosition',
......@@ -76,7 +84,8 @@ export const TablesConfig = {
unique:true //表示该列的值必须唯一
},
administrativePositionName: {type:Sequelize.STRING(100), allowNull:false}
}
},
association: [{}]
},
"党内职务表":{
tableName:'partyPositions',
......@@ -89,7 +98,8 @@ export const TablesConfig = {
unique:true //表示该列的值必须唯一
},
partyPositionsName: {type:Sequelize.STRING(100), allowNull:false}
}
},
association: [{}]
},
"所属科室表":{
tableName:'department',
......@@ -102,7 +112,8 @@ export const TablesConfig = {
unique:true //表示该列的值必须唯一
},
departmentName: {type:Sequelize.STRING(100), allowNull:false}
}
},
association: [{}]
},
"支部制度表":{
tableName:'branchSystem',
......@@ -122,7 +133,10 @@ export const TablesConfig = {
fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选
fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间
}
},
association: [
{type: "hasMany", table1: "branch", table2: "branchSystem"}
]
},
"组织生活表":{
tableName:'organizationalLife',
......@@ -141,7 +155,10 @@ export const TablesConfig = {
fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选
fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间
}
},
association: [
{type: "hasMany", table1: "branch", table2: "organizationalLife"}
]
},
"专题活动表":{
tableName:'thematicActivities',
......@@ -159,7 +176,10 @@ export const TablesConfig = {
fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选
fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间
}
},
association: [
{type: "hasMany", table1: "branch", table2: "thematicActivities"}
]
},
"党建动态表":{
tableName:'partyBuildingDynamic',
......@@ -177,7 +197,10 @@ export const TablesConfig = {
fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选
fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间
}
},
association: [
{type: "hasMany", table1: "branch", table2: "partyBuildingDynamic"}
]
},
"党费管理表":{
tableName:'partyExpenses',
......@@ -195,7 +218,11 @@ export const TablesConfig = {
bId: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //支部表id 外键 [1,2] --多选
payTime: {type:Sequelize.DATE, allowNull:true}, //缴费时间
payAmount: {type:Sequelize.INTEGER, allowNull:false}, //缴费金额(元)
}
},
association: [
{type: "hasMany", table1: "partyMember", table2: "partyExpenses"},
{type: "hasMany", table1: "branch", table2: "partyExpenses"}
]
},
"党建先锋表":{
tableName:'partyVanguard',
......@@ -214,7 +241,24 @@ export const TablesConfig = {
grantTime: {type:Sequelize.DATE, allowNull:false},//授予时间
bId: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //支部表id 外键 [1,2] --多选
isUse: {type:Sequelize.BOOLEAN, allowNull:false, defaultValue:true}, //是否使用
}
},
association: [
{type: "hasMany", table1: "branch", table2: "partyVanguard"}
]
},
"课程类型":{
tableName:'courseType',
schema:{
ctId: {
type:Sequelize.INTEGER(20), //表示属性的数据类型
allowNull:false, //表示当前列是否允许为空, false表示该列不能为空
primaryKey:true, //表示主键
autoIncrement:true, //允许自增
unique:true //表示该列的值必须唯一
},
courseTypeName: {type:Sequelize.STRING(100), allowNull:false}
},
association: [{}]
},
"党员学习表":{
tableName:'memberLearning',
......@@ -234,7 +278,10 @@ export const TablesConfig = {
fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选
fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间
}
},
association: [
{type: "hasOne", table1: "courseType", table2: "memberLearning"}
]
},
"学习进度表":{
tableName:'rateLearning',
......@@ -250,20 +297,11 @@ export const TablesConfig = {
mlId: {type:Sequelize.INTEGER, allowNull:false}, //党员学习id 外键
rateOfLearning: {type:Sequelize.INTEGER, allowNull:false, defaultValue:0}, //学习进度
learningCompleted: {type:Sequelize.INTEGER, allowNull:false, defaultValue:1}//是否已完成 1:正在进行、2:阅读完成
}
},
"课程类型":{
tableName:'courseType',
schema:{
ctId: {
type:Sequelize.INTEGER(20), //表示属性的数据类型
allowNull:false, //表示当前列是否允许为空, false表示该列不能为空
primaryKey:true, //表示主键
autoIncrement:true, //允许自增
unique:true //表示该列的值必须唯一
},
courseTypeName: {type:Sequelize.STRING(100), allowNull:false}
}
},
association: [
{type: "hasOne", table1: "partyMember", table2: "rateLearning"},
{type: "hasOne", table1: "memberLearning", table2: "rateLearning"}
]
},
"学习强国":{
tableName:'learningPower',
......@@ -282,7 +320,10 @@ export const TablesConfig = {
fileName: {type:Sequelize.STRING(100), allowNull:false, defaultValue:'[]'}, //文件名称 ["",""] --多选
fileType: {type:Sequelize.INTEGER, allowNull:false}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:false, defaultValue:Sequelize.NOW}, //上传时间
}
},
association: [
{type: "hasMany", table1: "branch", table2: "learningPower"}
]
},
"党建质量":{
tableName:'partyQuality',
......@@ -302,6 +343,9 @@ export const TablesConfig = {
totalScore: {type:Sequelize.INTEGER, allowNull:false, defaultValue:0}, //总分
currentScore: {type:Sequelize.INTEGER, allowNull:false, defaultValue:0}, //当前得分
completionProgress: {type:Sequelize.STRING(100), allowNull:false} //完成进度
}
},
association: [
{type: "hasMany", table1: "branch", table2: "partyQuality"}
]
},
}
\ No newline at end of file
......@@ -23,7 +23,8 @@ export async function initModel() {
modelMap[tableName].findManyData = findManyDataBind;
modelMap[tableName].findDataCount = findDataCountBind;
modelMap[tableName].findDataToPage = findDataToPageBind;
modelMap[tableName].aggragateData = aggragateDataBind
modelMap[tableName].aggragateData = aggragateDataBind;
modelMap[tableName].findDataToTableAssociation = findDataToTableAssociationBind;
}
}
......@@ -49,13 +50,13 @@ async function deleteOneBind(param) {
}
async function findOnceDataBind(param) {
return await this.findOne(param);
async function findOnceDataBind(column, param) {
return await this.findOne({attribute:column, where:param});
}
async function findManyDataBind(param) {
return await this.find(param);
async function findManyDataBind(column, param) {
return await this.find({attribute:column, where:param});
}
......@@ -64,8 +65,8 @@ async function findDataCountBind(param) {
}
async function findDataToPageBind(param, skipCount:number, limit:number) {
return await this.find(param).skip(skipCount).limit(limit);
async function findDataToPageBind(column, param, skipCount:number, limit:number) {
return await this.find({attribute:column, where:param}).skip(skipCount).limit(limit);
}
......@@ -74,4 +75,14 @@ async function aggragateDataBind(param) {
}
async function findDataToTableAssociationBind(associatedTable:string, column:any, param:any) {
return await this.find({
include: [{
model: associatedTable,
attributes: column, //指定关联表查询的字段
}],
where: param
})
}
export {modelMap};
\ No newline at end of file
......@@ -9,7 +9,7 @@ let baseDB = {};
export async function initMysqlModel() {
for (let tableNameCN in TablesConfig) {
let { tableName, schema } = TablesConfig[tableNameCN];
let { tableName, schema, association } = TablesConfig[tableNameCN];
let schemaConf = {
freezeTableName:true, //true表示使用给定的表名,false表示模型名后加s作为表名
......@@ -17,10 +17,25 @@ export async function initMysqlModel() {
};
let model = mysqlDB.define( tableName, schema, schemaConf);
baseDB[tableName] = model.sync({}).then();
association.forEach( item => {
if (item) {
let {type, table1, table2} = item;
if (type == "hasOne") {
table1.hasOne(table2);
table2.belongsTo(table1);
} else if (type == "hasMany") {
table1.hasMany(table2);
table2.belongsTo(table1);
}
}
})
}
}
export { baseDB };
\ 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