Commit 410ecfa4 by lixinming

修改无法联查的bug

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