Commit 410ecfa4 by lixinming

修改无法联查的bug

parent 81133662
import { Op, Sequelize } from "sequelize";
import { ERRORENUM } from "../../config/errorEnum";
import { modelMap } from "../../model/modelBind";
import { mysqlModelMap } from "../../model/sqlModelBind";
import { BizError } from "../../util/bizError";
......@@ -124,7 +124,7 @@ export async function selectDataCountByParam(tableModel, param) {
export async function associationSelect(tableName:string, param) {
let model = modelMap[tableName];
let model = mysqlModelMap[tableName];
if (!model) throw new BizError(ERRORENUM.不存在表);
let data = await model.aggragateData(param);
......@@ -144,10 +144,10 @@ export async function associationSelect(tableName:string, param) {
export async function selectDataToTableAssociation(tableModel, includeConf, param, column) {
let include = [];
for (let tableName in includeConf) {
if (!modelMap[tableName]) throw new BizError(ERRORENUM.不存在表, `尝试进行多表联查,但是不存在${tableName}`);
if (!mysqlModelMap[tableName]) throw new BizError(ERRORENUM.不存在表, `尝试进行多表联查,但是不存在${tableName}`);
include.push({
attributes : includeConf[tableName],
module : modelMap[tableName]
model : mysqlModelMap[tableName]
});
}
......@@ -161,7 +161,7 @@ export async function selectDataToTableAssociation(tableModel, includeConf, para
/**
* 多表联查
* 多表联查 分页
* @param tableModel
* @param includeConf {"表名":["",""] }
* @param param
......@@ -171,11 +171,12 @@ export async function selectDataToTableAssociation(tableModel, includeConf, para
export async function selectDataToTableAssociationToPage(tableModel, includeConf, param, column, pageNumber:number, pageSize:number) {
let include = [];
for (let tableName in includeConf) {
if (!modelMap[tableName]) throw new BizError(ERRORENUM.不存在表, `尝试进行多表联查,但是不存在${tableName}`);
if (!mysqlModelMap[tableName]) throw new BizError(ERRORENUM.不存在表, `尝试进行多表联查,但是不存在${tableName}`);
include.push({
attributes : includeConf[tableName],
module : modelMap[tableName]
model : mysqlModelMap[tableName]
});
// include.push({model:mysqlModelMap[tableName]});
}
let selectParam:any = analysisParamToWhere(param, column);
......
......@@ -69,7 +69,10 @@ export const TablesConfig = [
adminToken:{type:Sequelize.STRING(100), allowNull:true},
adminTokenMs:{ type:Sequelize.DATE, allowNull:true },
},
association: [ ]
association: [
{type: "hasMany", check: "partyExpenses", foreignKey:"pmId"},
{type: "hasMany", check: "rateLearning", foreignKey:"pmId"},
]
},
{
tableNameCn:'支部制度表',
......@@ -171,9 +174,7 @@ export const TablesConfig = [
payTime: {type:Sequelize.DATE, allowNull:true}, //缴费时间
payAmount: {type:Sequelize.INTEGER, allowNull:true}, //缴费金额(元)
},
association: [
{type: "hasMany", check: "partyMember"},
]
association: []
},
{
tableNameCn:'党建先锋表',
......@@ -216,7 +217,9 @@ export const TablesConfig = [
fileType: {type:Sequelize.INTEGER, allowNull:true}, //文件类型
uploadTime: {type:Sequelize.DATE, allowNull:true, defaultValue:Sequelize.NOW}, //上传时间
},
association: []
association: [
{type: "hasMany", check: "rateLearning",foreignKey:"mlId"},
]
},
{
tableNameCn:'学习进度表',
......@@ -234,12 +237,7 @@ export const TablesConfig = [
rateOfLearning: {type:Sequelize.INTEGER, allowNull:false, defaultValue:0}, //学习进度
learningCompleted: {type:Sequelize.INTEGER, allowNull:false, defaultValue:1}//是否已完成 1:正在进行、2:阅读完成
},
association: [
{type: "belongsTo", check:"partyMember", foreignKey: "pmId", targetKey:"pmId"},
{type: "belongsTo", check:"memberLearning", foreignKey: "mlId", targetKey:"mlId"},
// {type: "hasOne", check: "partyMember"},
// {type: "hasOne", check: "memberLearning"}
]
association: []
},
{
tableNameCn:'学习强国',
......
......@@ -29,18 +29,18 @@ export async function initMysqlModel() {
let { tableName, association } = TablesConfig[i];
association.forEach( (item:any) => {
if (item) {
let {type, check} = item;
let {type, check, foreignKey} = item;
if (type == "hasOne") {
mysqlModelMap[check].hasOne(mysqlModelMap[tableName]);
} else if (type == "hasMany") {
mysqlModelMap[check].hasMany(mysqlModelMap[tableName]);
mysqlModelMap[tableName].hasMany(mysqlModelMap[check], {foreignKey});
}
mysqlModelMap[tableName].belongsTo(mysqlModelMap[check], {
foreignKey: item.foreignKey,
targetKey: item.targetKey
});
mysqlModelMap[check].belongsTo(mysqlModelMap[tableName], {foreignKey});
console.log("---->", mysqlModelMap[tableName].getTableName());
console.log("====>", mysqlModelMap[check].getTableName());
}
});
}
......
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