Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
6db70c0c
Commit
6db70c0c
authored
Aug 13, 2020
by
v_vjyjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
36f6c035
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
46 deletions
+50
-46
ic-deliver/app/base/db/dao.base.js
+50
-46
No files found.
ic-deliver/app/base/db/dao.base.js
View file @
6db70c0c
...
@@ -9,10 +9,10 @@ class Dao {
...
@@ -9,10 +9,10 @@ class Dao {
this
.
model
=
db
.
models
[
this
.
modelName
];
this
.
model
=
db
.
models
[
this
.
modelName
];
console
.
log
(
this
.
modelName
);
console
.
log
(
this
.
modelName
);
}
}
preCreate
(
u
)
{
preCreate
(
u
)
{
return
u
;
return
u
;
}
}
async
create
(
u
,
t
)
{
async
create
(
u
,
t
)
{
var
u2
=
this
.
preCreate
(
u
);
var
u2
=
this
.
preCreate
(
u
);
if
(
t
)
{
if
(
t
)
{
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
);
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
);
...
@@ -26,11 +26,11 @@ class Dao {
...
@@ -26,11 +26,11 @@ class Dao {
});
});
}
}
}
}
static
getModelName
(
ClassObj
)
{
static
getModelName
(
ClassObj
)
{
return
ClassObj
[
"name"
].
substring
(
0
,
ClassObj
[
"name"
].
lastIndexOf
(
"Dao"
)).
toLowerCase
()
return
ClassObj
[
"name"
].
substring
(
0
,
ClassObj
[
"name"
].
lastIndexOf
(
"Dao"
)).
toLowerCase
()
}
}
async
refQuery
(
qobj
)
{
async
refQuery
(
qobj
)
{
var
w
=
qobj
.
refwhere
?
qobj
.
refwhere
:
{};
var
w
=
qobj
.
refwhere
?
qobj
.
refwhere
:
{};
if
(
qobj
.
levelinfo
)
{
if
(
qobj
.
levelinfo
)
{
w
[
qobj
.
levelinfo
.
levelfield
]
=
qobj
.
levelinfo
.
level
;
w
[
qobj
.
levelinfo
.
levelfield
]
=
qobj
.
levelinfo
.
level
;
}
}
...
@@ -38,8 +38,8 @@ class Dao {
...
@@ -38,8 +38,8 @@ class Dao {
w
[
qobj
.
parentinfo
.
parentfield
]
=
qobj
.
parentinfo
.
parentcode
;
w
[
qobj
.
parentinfo
.
parentfield
]
=
qobj
.
parentinfo
.
parentcode
;
}
}
//如果需要控制数据权限
//如果需要控制数据权限
if
(
qobj
.
datapriv
)
{
if
(
qobj
.
datapriv
)
{
w
[
"id"
]
=
{
[
this
.
db
.
Op
.
in
]:
qobj
.
datapriv
};
w
[
"id"
]
=
{
[
this
.
db
.
Op
.
in
]:
qobj
.
datapriv
};
}
}
if
(
qobj
.
likestr
)
{
if
(
qobj
.
likestr
)
{
w
[
qobj
.
fields
[
0
]]
=
{
[
this
.
db
.
Op
.
like
]:
"%"
+
qobj
.
likestr
+
"%"
};
w
[
qobj
.
fields
[
0
]]
=
{
[
this
.
db
.
Op
.
like
]:
"%"
+
qobj
.
likestr
+
"%"
};
...
@@ -48,11 +48,11 @@ class Dao {
...
@@ -48,11 +48,11 @@ class Dao {
return
this
.
model
.
findAll
({
where
:
w
,
attributes
:
qobj
.
fields
});
return
this
.
model
.
findAll
({
where
:
w
,
attributes
:
qobj
.
fields
});
}
}
}
}
async
bulkDelete
(
ids
)
{
async
bulkDelete
(
ids
)
{
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}
});
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}
});
return
en
;
return
en
;
}
}
async
bulkDeleteByWhere
(
whereParam
,
t
)
{
async
bulkDeleteByWhere
(
whereParam
,
t
)
{
var
en
=
null
;
var
en
=
null
;
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
whereParam
.
transaction
=
t
;
whereParam
.
transaction
=
t
;
...
@@ -61,34 +61,34 @@ class Dao {
...
@@ -61,34 +61,34 @@ class Dao {
return
await
this
.
model
.
destroy
(
whereParam
);
return
await
this
.
model
.
destroy
(
whereParam
);
}
}
}
}
async
delete
(
qobj
,
t
)
{
async
delete
(
qobj
,
t
)
{
var
en
=
null
var
en
=
null
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
en
=
await
this
.
model
.
findOne
({
where
:
{
id
:
qobj
.
id
},
transaction
:
t
});
en
=
await
this
.
model
.
findOne
({
where
:
{
id
:
qobj
.
id
},
transaction
:
t
});
if
(
en
!=
null
)
{
if
(
en
!=
null
)
{
await
en
.
destroy
({
transaction
:
t
});
await
en
.
destroy
({
transaction
:
t
});
return
en
return
en
}
}
}
else
{
}
else
{
en
=
await
this
.
model
.
findOne
({
where
:
{
id
:
qobj
.
id
}
});
en
=
await
this
.
model
.
findOne
({
where
:
{
id
:
qobj
.
id
}
});
if
(
en
!=
null
)
{
if
(
en
!=
null
)
{
return
en
.
destroy
();
return
en
.
destroy
();
}
}
return
en
return
en
}
}
}
}
extraModelFilter
(
pobj
)
{
extraModelFilter
(
pobj
)
{
//return {"key":"include","value":{model:this.db.models.app}};
//return {"key":"include","value":{model:this.db.models.app}};
return
null
;
return
null
;
}
}
extraWhere
(
obj
,
where
)
{
extraWhere
(
obj
,
where
)
{
return
where
;
return
where
;
}
}
orderBy
()
{
orderBy
()
{
//return {"key":"include","value":{model:this.db.models.app}};
//return {"key":"include","value":{model:this.db.models.app}};
return
[[
"created_at"
,
"DESC"
]];
return
[[
"created_at"
,
"DESC"
]];
}
}
buildQuery
(
qobj
)
{
buildQuery
(
qobj
)
{
var
linkAttrs
=
[];
var
linkAttrs
=
[];
const
pageNo
=
qobj
.
pageInfo
.
pageNo
;
const
pageNo
=
qobj
.
pageInfo
.
pageNo
;
const
pageSize
=
qobj
.
pageInfo
.
pageSize
;
const
pageSize
=
qobj
.
pageInfo
.
pageSize
;
...
@@ -146,7 +146,7 @@ class Dao {
...
@@ -146,7 +146,7 @@ class Dao {
console
.
log
(
qc
);
console
.
log
(
qc
);
return
qc
;
return
qc
;
}
}
buildaggs
(
qobj
)
{
buildaggs
(
qobj
)
{
var
aggsinfos
=
[];
var
aggsinfos
=
[];
if
(
qobj
.
aggsinfo
)
{
if
(
qobj
.
aggsinfo
)
{
qobj
.
aggsinfo
.
sum
.
forEach
(
aggitem
=>
{
qobj
.
aggsinfo
.
sum
.
forEach
(
aggitem
=>
{
...
@@ -160,7 +160,7 @@ class Dao {
...
@@ -160,7 +160,7 @@ class Dao {
}
}
return
aggsinfos
;
return
aggsinfos
;
}
}
async
findAggs
(
qobj
,
qcwhere
)
{
async
findAggs
(
qobj
,
qcwhere
)
{
var
aggArray
=
this
.
buildaggs
(
qobj
);
var
aggArray
=
this
.
buildaggs
(
qobj
);
if
(
aggArray
.
length
!=
0
)
{
if
(
aggArray
.
length
!=
0
)
{
qcwhere
[
"attributes"
]
=
{};
qcwhere
[
"attributes"
]
=
{};
...
@@ -173,19 +173,23 @@ class Dao {
...
@@ -173,19 +173,23 @@ class Dao {
}
}
}
}
async
findAndCountAll
(
qobj
,
t
)
{
convertAggResult
(
aggresult
)
{
return
aggresult
}
async
findAndCountAll
(
qobj
,
t
)
{
var
qc
=
this
.
buildQuery
(
qobj
);
var
qc
=
this
.
buildQuery
(
qobj
);
var
apps
=
await
this
.
model
.
findAndCountAll
(
qc
);
var
apps
=
await
this
.
model
.
findAndCountAll
(
qc
);
var
aggresult
=
await
this
.
findAggs
(
qobj
,
qc
);
var
aggresult
=
await
this
.
findAggs
(
qobj
,
qc
);
let
convertAggResult
=
this
.
convertAggResult
(
aggresult
);
var
rtn
=
{};
var
rtn
=
{};
rtn
.
results
=
apps
;
rtn
.
results
=
apps
;
rtn
.
aggresult
=
aggr
esult
;
rtn
.
aggresult
=
convertAggR
esult
;
return
rtn
;
return
rtn
;
}
}
preUpdate
(
obj
)
{
preUpdate
(
obj
)
{
return
obj
;
return
obj
;
}
}
async
update
(
obj
,
tm
)
{
async
update
(
obj
,
tm
)
{
var
obj2
=
this
.
preUpdate
(
obj
);
var
obj2
=
this
.
preUpdate
(
obj
);
if
(
tm
!=
null
&&
tm
!=
'undefined'
)
{
if
(
tm
!=
null
&&
tm
!=
'undefined'
)
{
return
this
.
model
.
update
(
obj2
,
{
where
:
{
id
:
obj2
.
id
},
transaction
:
tm
});
return
this
.
model
.
update
(
obj2
,
{
where
:
{
id
:
obj2
.
id
},
transaction
:
tm
});
...
@@ -193,7 +197,7 @@ class Dao {
...
@@ -193,7 +197,7 @@ class Dao {
return
this
.
model
.
update
(
obj2
,
{
where
:
{
id
:
obj2
.
id
}
});
return
this
.
model
.
update
(
obj2
,
{
where
:
{
id
:
obj2
.
id
}
});
}
}
}
}
async
bulkCreate
(
ids
,
t
)
{
async
bulkCreate
(
ids
,
t
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
return
await
this
.
model
.
bulkCreate
(
ids
,
{
transaction
:
t
});
return
await
this
.
model
.
bulkCreate
(
ids
,
{
transaction
:
t
});
}
else
{
}
else
{
...
@@ -201,21 +205,21 @@ class Dao {
...
@@ -201,21 +205,21 @@ class Dao {
}
}
}
}
async
updateByWhere
(
setObj
,
whereObj
,
t
)
{
async
updateByWhere
(
setObj
,
whereObj
,
t
)
{
let
inWhereObj
=
{}
let
inWhereObj
=
{}
if
(
t
&&
t
!=
'undefined'
)
{
if
(
t
&&
t
!=
'undefined'
)
{
if
(
whereObj
&&
whereObj
!=
'undefined'
)
{
if
(
whereObj
&&
whereObj
!=
'undefined'
)
{
inWhereObj
[
"where"
]
=
whereObj
;
inWhereObj
[
"where"
]
=
whereObj
;
inWhereObj
[
"transaction"
]
=
t
;
inWhereObj
[
"transaction"
]
=
t
;
}
else
{
}
else
{
inWhereObj
[
"transaction"
]
=
t
;
inWhereObj
[
"transaction"
]
=
t
;
}
}
}
else
{
}
else
{
inWhereObj
[
"where"
]
=
whereObj
;
inWhereObj
[
"where"
]
=
whereObj
;
}
}
return
this
.
model
.
update
(
setObj
,
inWhereObj
);
return
this
.
model
.
update
(
setObj
,
inWhereObj
);
}
}
async
customExecAddOrPutSql
(
sql
,
paras
=
null
)
{
async
customExecAddOrPutSql
(
sql
,
paras
=
null
)
{
return
this
.
db
.
query
(
sql
,
paras
);
return
this
.
db
.
query
(
sql
,
paras
);
}
}
/**
/**
...
@@ -224,19 +228,19 @@ class Dao {
...
@@ -224,19 +228,19 @@ class Dao {
* p.group.aliasField=' as xxx'
* p.group.aliasField=' as xxx'
* @param {*} p
* @param {*} p
*/
*/
async
statGroupBy
(
p
,
paras
,
t
)
{
async
statGroupBy
(
p
,
paras
,
t
)
{
let
groupFields
=
p
.
group
.
byFields
.
join
(
","
)
let
groupFields
=
p
.
group
.
byFields
.
join
(
","
)
let
aggField
=
p
.
group
.
aggField
?
p
.
group
.
aggField
:
''
let
aggField
=
p
.
group
.
aggField
?
p
.
group
.
aggField
:
''
let
tblName
=
p
.
group
.
tblName
?
p
.
group
.
tblName
:
''
let
tblName
=
p
.
group
.
tblName
?
p
.
group
.
tblName
:
''
let
where
=
p
.
group
.
where
?
p
.
group
.
where
:
''
let
where
=
p
.
group
.
where
?
p
.
group
.
where
:
''
let
having
=
p
.
group
.
having
?
p
.
group
.
having
:
''
let
having
=
p
.
group
.
having
?
p
.
group
.
having
:
''
let
aliasField
=
p
.
group
.
aliasField
?
p
.
group
.
aliasField
:
''
let
aliasField
=
p
.
group
.
aliasField
?
p
.
group
.
aliasField
:
''
let
actionType
=
p
.
group
.
actionType
?
p
.
group
.
actionType
:
'count'
let
actionType
=
p
.
group
.
actionType
?
p
.
group
.
actionType
:
'count'
let
sql
=
`select
${
groupFields
}
,
${
actionType
}
(
${
aggField
}
)
${
aliasField
}
from
${
tblName
}
${
where
}
group by
${
groupFields
}
${
having
}
WITH ROLLUP`
let
sql
=
`select
${
groupFields
}
,
${
actionType
}
(
${
aggField
}
)
${
aliasField
}
from
${
tblName
}
${
where
}
group by
${
groupFields
}
${
having
}
WITH ROLLUP`
return
this
.
customQuery
(
sql
,
paras
,
t
)
return
this
.
customQuery
(
sql
,
paras
,
t
)
}
}
async
customQuery
(
sql
,
paras
,
t
)
{
async
customQuery
(
sql
,
paras
,
t
)
{
var
tmpParas
=
null
;
//||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
var
tmpParas
=
null
;
//||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
if
(
t
&&
t
!=
'undefined'
)
{
if
(
t
&&
t
!=
'undefined'
)
{
if
(
paras
==
null
||
paras
==
'undefined'
)
{
if
(
paras
==
null
||
paras
==
'undefined'
)
{
...
@@ -251,15 +255,15 @@ class Dao {
...
@@ -251,15 +255,15 @@ class Dao {
}
}
return
this
.
db
.
query
(
sql
,
tmpParas
);
return
this
.
db
.
query
(
sql
,
tmpParas
);
}
}
async
findCount
(
whereObj
=
null
)
{
async
findCount
(
whereObj
=
null
)
{
return
this
.
model
.
count
(
whereObj
,
{
logging
:
false
}).
then
(
c
=>
{
return
this
.
model
.
count
(
whereObj
,
{
logging
:
false
}).
then
(
c
=>
{
return
c
;
return
c
;
});
});
}
}
async
findSum
(
fieldName
,
whereObj
=
null
)
{
async
findSum
(
fieldName
,
whereObj
=
null
)
{
return
this
.
model
.
sum
(
fieldName
,
whereObj
);
return
this
.
model
.
sum
(
fieldName
,
whereObj
);
}
}
async
getPageList
(
pageIndex
,
pageSize
,
whereObj
=
null
,
orderObj
=
null
,
attributesObj
=
null
,
includeObj
=
null
)
{
async
getPageList
(
pageIndex
,
pageSize
,
whereObj
=
null
,
orderObj
=
null
,
attributesObj
=
null
,
includeObj
=
null
)
{
var
tmpWhere
=
{};
var
tmpWhere
=
{};
tmpWhere
.
limit
=
pageSize
;
tmpWhere
.
limit
=
pageSize
;
tmpWhere
.
offset
=
(
pageIndex
-
1
)
*
pageSize
;
tmpWhere
.
offset
=
(
pageIndex
-
1
)
*
pageSize
;
...
@@ -275,15 +279,15 @@ class Dao {
...
@@ -275,15 +279,15 @@ class Dao {
if
(
includeObj
!=
null
&&
includeObj
.
length
>
0
)
{
if
(
includeObj
!=
null
&&
includeObj
.
length
>
0
)
{
tmpWhere
.
include
=
includeObj
;
tmpWhere
.
include
=
includeObj
;
tmpWhere
.
distinct
=
true
;
tmpWhere
.
distinct
=
true
;
}
else
{
}
else
{
tmpWhere
.
raw
=
true
;
tmpWhere
.
raw
=
true
;
}
}
return
await
this
.
model
.
findAndCountAll
(
tmpWhere
);
return
await
this
.
model
.
findAndCountAll
(
tmpWhere
);
}
}
async
findOne
(
obj
)
{
async
findOne
(
obj
)
{
return
this
.
model
.
findOne
({
"where"
:
obj
});
return
this
.
model
.
findOne
({
"where"
:
obj
});
}
}
async
findById
(
oid
)
{
async
findById
(
oid
)
{
return
this
.
model
.
findById
(
oid
);
return
this
.
model
.
findById
(
oid
);
}
}
}
}
...
...
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