Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yafangsuo_dataServer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
yafangsuo_dataServer
Commits
410ecfa4
Commit
410ecfa4
authored
Sep 13, 2023
by
lixinming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改无法联查的bug
parent
81133662
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
24 deletions
+23
-24
findData.ts
src/biz/mysql/findData.ts
+8
-7
mysqlTableConfig.ts
src/config/mysqlTableConfig.ts
+9
-11
sqlModelBind.ts
src/model/sqlModelBind.ts
+6
-6
No files found.
src/biz/mysql/findData.ts
View file @
410ecfa4
import
{
Op
,
Sequelize
}
from
"sequelize"
;
import
{
ERRORENUM
}
from
"../../config/errorEnum"
;
import
{
m
odelMap
}
from
"../../model/m
odelBind"
;
import
{
m
ysqlModelMap
}
from
"../../model/sqlM
odelBind"
;
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
=
m
ysqlM
odelMap
[
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
(
!
m
ysqlM
odelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
include
.
push
({
attributes
:
includeConf
[
tableName
],
mod
ule
:
m
odelMap
[
tableName
]
mod
el
:
mysqlM
odelMap
[
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
(
!
m
ysqlM
odelMap
[
tableName
])
throw
new
BizError
(
ERRORENUM
.
不存在表
,
`尝试进行多表联查,但是不存在
${
tableName
}
`
);
include
.
push
({
attributes
:
includeConf
[
tableName
],
mod
ule
:
m
odelMap
[
tableName
]
mod
el
:
mysqlM
odelMap
[
tableName
]
});
// include.push({model:mysqlModelMap[tableName]});
}
let
selectParam
:
any
=
analysisParamToWhere
(
param
,
column
);
...
...
src/config/mysqlTableConfig.ts
View file @
410ecfa4
...
...
@@ -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
:
'学习强国'
,
...
...
src/model/sqlModelBind.ts
View file @
410ecfa4
...
...
@@ -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
());
}
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment