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
1eac633e
Commit
1eac633e
authored
Jul 03, 2020
by
sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 消息接口
parent
0082ac61
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
682 additions
and
200 deletions
+682
-200
center-manage/app/base/controller/impl/msg/msgCtl.js
+188
-0
center-manage/app/base/db/dao.base.js
+37
-30
center-manage/app/base/db/impl/common/connection.js
+109
-64
center-manage/app/base/db/impl/msg/msguserDao.js
+8
-0
center-manage/app/base/db/models/msg/msg.js
+88
-58
center-manage/app/base/db/models/msg/msguser.js
+62
-48
center-manage/app/base/service/impl/msg/msgSve.js
+183
-0
center-manage/app/base/system.js
+7
-0
No files found.
center-manage/app/base/controller/impl/msg/msgCtl.js
0 → 100644
View file @
1eac633e
var
system
=
require
(
"../../../system"
);
const
http
=
require
(
"http"
);
const
querystring
=
require
(
'querystring'
);
var
settings
=
require
(
"../../../../config/settings"
);
const
CtlBase
=
require
(
"../../ctl.base"
);
class
MsgCtl
extends
CtlBase
{
constructor
()
{
super
(
"msg"
,
CtlBase
.
getServiceName
(
MsgCtl
));
}
/**
* 创建消息
* @param {
* msgType,
* app_id,
* app_key(跳转链接时需要)
// * company_id(需要给某个交付商发送,暂时不考虑)
* sender (如果不传默认系统发的)
* sender_id
* emergency_level(紧急级别暂时不考虑)
* jump_address (详情跳转地址)
* target:[{id:"",name:''}] 发送给目标人 (非系统消息时必填)
* } pobj
* @param {*} qobj
* @param {*} req
*/
async
create
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
title
)
{
return
system
.
getResult
(
null
,
"title can not be empty,100290"
);
}
if
(
!
pobj
.
content
)
{
return
system
.
getResult
(
null
,
"content can not be empty,100290"
);
}
if
(
!
pobj
.
sender
||
!
pobj
.
sender_id
)
{
return
system
.
getResult
(
null
,
"发送者信息 can not be empty,100290"
);
}
if
(
pobj
.
jump_address
&&
!
pobj
.
app_key
)
{
return
system
.
getResult
(
null
,
"需要跳转时,app_key不能为空"
);
}
if
(
!
pobj
.
msgType
)
{
return
system
.
getResult
(
null
,
"msgType can not be empty,100290"
);
}
if
(
pobj
.
msgType
!==
system
.
Msg
.
SYS
&&
!
pobj
.
target
)
{
return
system
.
getResult
(
null
,
"非系统公告,target 不能为空"
);
}
if
(
pobj
.
msgType
===
system
.
Msg
.
SINGLE
&&
Object
.
prototype
.
toString
.
call
(
pobj
.
target
)
!==
'[object Object]'
)
{
return
system
.
getResult
(
null
,
"单条消息时,target格式是对象"
);
}
if
((
pobj
.
msgType
===
system
.
Msg
.
SINGLE
&&
pobj
.
target
)
&&
!
pobj
.
target
.
id
)
{
return
system
.
getResult
(
null
,
"单条消息时,目标用户id不能为空"
);
}
if
(
pobj
.
msgType
===
system
.
Msg
.
MULTI
&&
Object
.
prototype
.
toString
.
call
(
pobj
.
target
)
!==
"[object Array]"
)
{
return
system
.
getResult
(
null
,
"多条消息时,target格式是数组"
);
}
if
((
pobj
.
msgType
===
system
.
Msg
.
MULTI
&&
pobj
.
target
)
&&
pobj
.
target
.
length
<=
0
)
{
return
system
.
getResult
(
null
,
"多条消息时,target数组不能为空"
);
}
if
((
pobj
.
msgType
===
system
.
Msg
.
MULTI
&&
pobj
.
target
)
&&
pobj
.
target
.
length
>
0
)
{
for
(
let
val
of
pobj
.
target
)
{
if
(
!
val
.
id
)
{
return
system
.
getResult
(
null
,
"目标用户id不能为空"
);
}
}
}
try
{
const
rs
=
await
this
.
service
.
create
(
pobj
,
qobj
,
req
);
return
system
.
getResult
(
rs
);
}
catch
(
err
)
{
return
system
.
getResult
(
null
,
err
.
message
)
}
}
/**
* 返回未提醒 消息
* @param {*} pobj
* @param {*} qobj
* @param {*} req
*/
async
findRemindMessage
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
userid
)
{
return
system
.
getResult
(
null
,
"userid can not be empty,100290"
);
}
try
{
const
rs
=
await
this
.
service
.
findRemindMessage
(
pobj
,
qobj
,
req
);
return
system
.
getResult
(
rs
);
}
catch
(
err
)
{
return
system
.
getResult
(
null
,
err
.
message
)
}
}
/**
* 查询 未读消息条数
* @param {*} pobj
* @param {*} qobj
* @param {*} req
*/
async
findUnreadCount
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
userid
)
{
return
system
.
getResult
(
null
,
"userid can not be empty,100290"
);
}
pobj
.
is_read
=
false
;
try
{
const
rs
=
await
this
.
service
.
findUnreadCount
(
pobj
,
qobj
,
req
);
return
system
.
getResult
(
rs
);
}
catch
(
err
)
{
return
system
.
getResult
(
null
,
err
.
message
)
}
}
/**
* 更新已读未读
* @param {
* all true| false 全部已读未读
* } pobj
* @param {*} qobj
* @param {*} req
*/
async
updateStatus
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
userid
)
{
return
system
.
getResult
(
null
,
"userid can not be empty,100290"
);
}
if
(
!
pobj
.
id
&&
!
pobj
.
all
)
{
return
system
.
getResult
(
null
,
"id can not be empty,100290"
);
}
try
{
const
rs
=
await
this
.
service
.
updateStatus
(
pobj
,
qobj
,
req
);
return
system
.
getResult
(
rs
);
}
catch
(
err
)
{
return
system
.
getResult
(
null
,
err
.
message
)
}
}
/**
* 查询系统公告
* @param {*} pobj
* @param {*} qobj
* @param {*} req
*/
async
findSystemMsgCount
(
pobj
,
qobj
,
req
)
{
try
{
pobj
.
type
=
'recently'
;
const
rs
=
await
this
.
service
.
findSystemMsgCount
(
pobj
,
qobj
,
req
);
return
system
.
getResult
(
rs
);
}
catch
(
err
)
{
return
system
.
getResult
(
null
,
err
.
message
)
}
}
/**
* 消息列表
* @param {*} pobj
* @param {*} qobj
* @param {*} req
*/
async
list
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
msgType
)
{
return
system
.
getResult
(
null
,
"msgType can not be empty,100290"
);
}
if
(
!
pobj
.
userid
)
{
return
system
.
getResult
(
null
,
"userid can not be empty,100290"
);
}
try
{
const
rs
=
await
this
.
service
.
list
(
pobj
,
qobj
,
req
);
return
system
.
getResult
(
rs
);
}
catch
(
err
)
{
return
system
.
getResult
(
null
,
err
.
message
)
}
}
/**
* 各个消息类型条数统计
*/
async
groupCount
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
userid
)
{
return
system
.
getResult
(
null
,
"userid can not be empty,100290"
);
}
try
{
const
rs
=
await
this
.
service
.
groupCount
(
pobj
,
qobj
,
req
);
return
system
.
getResult
(
rs
);
}
catch
(
err
)
{
return
system
.
getResult
(
null
,
err
.
message
)
}
}
}
module
.
exports
=
MsgCtl
;
center-manage/app/base/db/dao.base.js
View file @
1eac633e
...
...
@@ -16,7 +16,7 @@ class Dao {
var
u2
=
this
.
preCreate
(
u
);
if
(
t
)
{
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
);
console
.
log
(
this
.
model
);
console
.
log
(
this
.
model
);
return
this
.
model
.
create
(
u2
,
{
transaction
:
t
}).
then
(
u
=>
{
return
u
;
});
...
...
@@ -30,7 +30,7 @@ class Dao {
return
ClassObj
[
"name"
].
substring
(
0
,
ClassObj
[
"name"
].
lastIndexOf
(
"Dao"
)).
toLowerCase
()
}
async
refQuery
(
qobj
)
{
var
w
=
qobj
.
refwhere
?
qobj
.
refwhere
:
{};
var
w
=
qobj
.
refwhere
?
qobj
.
refwhere
:
{};
if
(
qobj
.
levelinfo
)
{
w
[
qobj
.
levelinfo
.
levelfield
]
=
qobj
.
levelinfo
.
level
;
}
...
...
@@ -38,8 +38,8 @@ class Dao {
w
[
qobj
.
parentinfo
.
parentfield
]
=
qobj
.
parentinfo
.
parentcode
;
}
//如果需要控制数据权限
if
(
qobj
.
datapriv
)
{
w
[
"id"
]
=
{
[
this
.
db
.
Op
.
in
]:
qobj
.
datapriv
};
if
(
qobj
.
datapriv
)
{
w
[
"id"
]
=
{
[
this
.
db
.
Op
.
in
]:
qobj
.
datapriv
};
}
if
(
qobj
.
likestr
)
{
w
[
qobj
.
fields
[
0
]]
=
{
[
this
.
db
.
Op
.
like
]:
"%"
+
qobj
.
likestr
+
"%"
};
...
...
@@ -48,12 +48,12 @@ class Dao {
return
this
.
model
.
findAll
({
where
:
w
,
attributes
:
qobj
.
fields
});
}
}
async
bulkDelete
(
ids
,
t
)
{
if
(
t
)
{
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
},
transaction
:
t
});
async
bulkDelete
(
ids
,
t
)
{
if
(
t
)
{
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
},
transaction
:
t
});
return
en
;
}
else
{
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}});
}
else
{
var
en
=
await
this
.
model
.
destroy
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
ids
}
}
});
return
en
}
...
...
@@ -70,13 +70,13 @@ class Dao {
async
delete
(
qobj
,
t
)
{
var
en
=
null
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
)
{
await
en
.
destroy
({
transaction
:
t
});
return
en
}
}
else
{
en
=
await
this
.
model
.
findOne
({
where
:
{
id
:
qobj
.
id
}
});
en
=
await
this
.
model
.
findOne
({
where
:
{
id
:
qobj
.
id
}
});
if
(
en
!=
null
)
{
return
en
.
destroy
();
}
...
...
@@ -92,9 +92,9 @@ class Dao {
}
orderBy
(
qobj
)
{
//return {"key":"include","value":{model:this.db.models.app}};
if
(
!
qobj
.
orderInfo
||
qobj
.
orderInfo
.
length
==
0
)
{
if
(
!
qobj
.
orderInfo
||
qobj
.
orderInfo
.
length
==
0
)
{
return
[[
"created_at"
,
"DESC"
]];
}
else
{
}
else
{
return
qobj
.
orderInfo
;
}
...
...
@@ -178,10 +178,10 @@ class Dao {
qcwhere
[
"attributes"
]
=
aggArray
;
qcwhere
[
"raw"
]
=
true
;
//提高效率去掉关联和排序,数据记录数量,为聚合
let
tmpwhere
=
{
attributes
:
qcwhere
.
attributes
,
raw
:
true
,
where
:
qcwhere
.
where
let
tmpwhere
=
{
attributes
:
qcwhere
.
attributes
,
raw
:
true
,
where
:
qcwhere
.
where
}
var
aggResult
=
await
this
.
model
.
findOne
(
tmpwhere
);
return
aggResult
;
...
...
@@ -192,11 +192,11 @@ class Dao {
}
async
findAndCountAll
(
qobj
,
t
)
{
var
qc
=
this
.
buildQuery
(
qobj
);
let
findList
=
{}
let
count
=
await
this
.
findCount
({
where
:
qc
.
where
})
let
findList
=
{}
let
count
=
await
this
.
findCount
({
where
:
qc
.
where
})
var
rows
=
await
this
.
model
.
findAll
(
qc
);
findList
[
"count"
]
=
count
findList
[
"rows"
]
=
rows
findList
[
"count"
]
=
count
findList
[
"rows"
]
=
rows
var
aggresult
=
await
this
.
findAggs
(
qobj
,
qc
);
var
rtn
=
{};
rtn
.
results
=
findList
;
...
...
@@ -223,16 +223,16 @@ class Dao {
}
async
updateByWhere
(
setObj
,
whereObj
,
t
)
{
let
inWhereObj
=
{}
let
inWhereObj
=
{}
if
(
t
&&
t
!=
'undefined'
)
{
if
(
whereObj
&&
whereObj
!=
'undefined'
)
{
inWhereObj
[
"where"
]
=
whereObj
;
inWhereObj
[
"where"
]
=
whereObj
;
inWhereObj
[
"transaction"
]
=
t
;
}
else
{
inWhereObj
[
"transaction"
]
=
t
;
}
}
else
{
inWhereObj
[
"where"
]
=
whereObj
;
}
else
{
inWhereObj
[
"where"
]
=
whereObj
;
}
return
this
.
model
.
update
(
setObj
,
inWhereObj
);
}
...
...
@@ -278,19 +278,26 @@ class Dao {
if
(
includeObj
!=
null
&&
includeObj
.
length
>
0
)
{
tmpWhere
.
include
=
includeObj
;
tmpWhere
.
distinct
=
true
;
}
else
{
}
else
{
tmpWhere
.
raw
=
true
;
}
return
await
this
.
model
.
findAndCountAll
(
tmpWhere
);
}
async
findOne
(
obj
)
{
return
this
.
model
.
findOne
({
"where"
:
obj
});
async
findOne
(
obj
,
attributes
=
[])
{
if
(
attributes
.
length
>
0
)
{
return
this
.
model
.
findOne
({
"where"
:
obj
,
attributes
,
row
:
true
});
}
else
{
return
this
.
model
.
findOne
({
"where"
:
obj
,
row
:
true
});
}
}
async
findOneWithTm
(
obj
,
t
)
{
return
this
.
model
.
findOne
({
"where"
:
obj
,
transaction
:
t
});
async
findOneWithTm
(
obj
,
t
)
{
return
this
.
model
.
findOne
({
"where"
:
obj
,
transaction
:
t
});
}
async
findById
(
oid
)
{
return
this
.
model
.
findById
(
oid
);
}
async
findAll
(
obj
,
include
=
[],
other
=
{})
{
return
this
.
model
.
findAll
({
"where"
:
obj
,
include
,
row
:
true
,
...
other
});
}
}
module
.
exports
=
Dao
;
center-manage/app/base/db/impl/common/connection.js
View file @
1eac633e
const
Sequelize
=
require
(
'sequelize'
);
const
settings
=
require
(
"../../../../config/settings"
)
const
fs
=
require
(
"fs"
)
const
path
=
require
(
"path"
);
const
settings
=
require
(
"../../../../config/settings"
)
const
fs
=
require
(
"fs"
)
const
path
=
require
(
"path"
);
var
glob
=
require
(
"glob"
);
class
DbFactory
{
constructor
(){
const
dbConfig
=
settings
.
database
();
this
.
db
=
new
Sequelize
(
dbConfig
.
dbname
,
dbConfig
.
user
,
dbConfig
.
password
,
dbConfig
.
config
);
this
.
db
.
Sequelize
=
Sequelize
;
this
.
db
.
Op
=
Sequelize
.
Op
;
const
Op
=
Sequelize
.
Op
class
DbFactory
{
constructor
()
{
const
dbConfig
=
settings
.
database
();
this
.
db
=
new
Sequelize
(
dbConfig
.
dbname
,
dbConfig
.
user
,
dbConfig
.
password
,
{
...
dbConfig
.
config
,
operatorsAliases
:
{
$eq
:
Op
.
eq
,
$ne
:
Op
.
ne
,
$gte
:
Op
.
gte
,
$gt
:
Op
.
gt
,
$lte
:
Op
.
lte
,
$lt
:
Op
.
lt
,
$not
:
Op
.
not
,
$in
:
Op
.
in
,
$notIn
:
Op
.
notIn
,
$is
:
Op
.
is
,
$like
:
Op
.
like
,
$notLike
:
Op
.
notLike
,
$iLike
:
Op
.
iLike
,
$notILike
:
Op
.
notILike
,
$regexp
:
Op
.
regexp
,
$notRegexp
:
Op
.
notRegexp
,
$iRegexp
:
Op
.
iRegexp
,
$notIRegexp
:
Op
.
notIRegexp
,
$between
:
Op
.
between
,
$notBetween
:
Op
.
notBetween
,
$overlap
:
Op
.
overlap
,
$contains
:
Op
.
contains
,
$contained
:
Op
.
contained
,
$adjacent
:
Op
.
adjacent
,
$strictLeft
:
Op
.
strictLeft
,
$strictRight
:
Op
.
strictRight
,
$noExtendRight
:
Op
.
noExtendRight
,
$noExtendLeft
:
Op
.
noExtendLeft
,
$and
:
Op
.
and
,
$or
:
Op
.
or
,
$any
:
Op
.
any
,
$all
:
Op
.
all
,
$values
:
Op
.
values
,
$col
:
Op
.
col
}
});
this
.
db
.
Sequelize
=
Sequelize
;
this
.
db
.
Op
=
Sequelize
.
Op
;
this
.
initModels
();
this
.
initRelations
();
}
async
initModels
(){
var
self
=
this
;
var
modelpath
=
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
))
+
"/models/"
;
var
models
=
glob
.
sync
(
modelpath
+
"/**/*.js"
);
async
initModels
()
{
var
self
=
this
;
var
modelpath
=
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
))
+
"/models/"
;
var
models
=
glob
.
sync
(
modelpath
+
"/**/*.js"
);
console
.
log
(
models
.
length
);
models
.
forEach
(
function
(
m
)
{
console
.
log
(
m
);
self
.
db
.
import
(
m
);
models
.
forEach
(
function
(
m
)
{
console
.
log
(
m
);
self
.
db
.
import
(
m
);
});
console
.
log
(
"init models...."
);
}
async
initRelations
(){
this
.
db
.
models
.
dataauth
.
belongsTo
(
this
.
db
.
models
.
user
,
{
constraints
:
false
,
});
async
initRelations
()
{
this
.
db
.
models
.
dataauth
.
belongsTo
(
this
.
db
.
models
.
user
,
{
constraints
:
false
,
});
/*建立用户和角色之间的关系*/
this
.
db
.
models
.
user
.
belongsToMany
(
this
.
db
.
models
.
role
,
{
as
:
"Roles"
,
through
:
'p_userrole'
,
constraints
:
false
,
});
this
.
db
.
models
.
role
.
belongsToMany
(
this
.
db
.
models
.
user
,
{
as
:
"Users"
,
through
:
'p_userrole'
,
constraints
:
false
,
});
/*组织机构自引用*/
//this.db.models.org.belongsTo(this.db.models.org,{constraints: false,});
//this.db.models.org.hasMany(this.db.models.org,{constraints: false,});
//组织机构和角色是多对多关系,建立兼职岗位,给岗位赋予多个角色,从而同步修改用户的角色
//通过岗位接口去修改用户的角色
//this.db.models.role.belongsToMany(this.db.models.org,{through: this.db.models.orgrole,constraints: false,});
//this.db.models.org.belongsToMany(this.db.models.role,{through: this.db.models.orgrole,constraints: false,});
//组织机构和用户是1对多,
this
.
db
.
models
.
user
.
belongsToMany
(
this
.
db
.
models
.
role
,
{
as
:
"Roles"
,
through
:
'p_userrole'
,
constraints
:
false
,
});
this
.
db
.
models
.
role
.
belongsToMany
(
this
.
db
.
models
.
user
,
{
as
:
"Users"
,
through
:
'p_userrole'
,
constraints
:
false
,
});
/*组织机构自引用*/
//this.db.models.org.belongsTo(this.db.models.org,{constraints: false,});
//this.db.models.org.hasMany(this.db.models.org,{constraints: false,});
//组织机构和角色是多对多关系,建立兼职岗位,给岗位赋予多个角色,从而同步修改用户的角色
//通过岗位接口去修改用户的角色
//this.db.models.role.belongsToMany(this.db.models.org,{through: this.db.models.orgrole,constraints: false,});
//this.db.models.org.belongsToMany(this.db.models.role,{through: this.db.models.orgrole,constraints: false,});
//组织机构和用户是1对多,
// this.db.models.user.belongsTo(this.db.models.org,{constraints: false,});
// this.db.models.org.hasMany(this.db.models.user,{constraints: false,});
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
role
.
belongsTo
(
this
.
db
.
models
.
app
,
{
constraints
:
false
,});
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
app
,
{
constraints
:
false
,
});
this
.
db
.
models
.
role
.
belongsTo
(
this
.
db
.
models
.
app
,
{
constraints
:
false
,
});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
app
,
{
constraints
:
false
,
});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,
});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
role
,
{
constraints
:
false
,
});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
role
,{
constraints
:
false
,});
this
.
db
.
models
.
app
.
belongsTo
(
this
.
db
.
models
.
user
,
{
as
:
"creator"
,
constraints
:
false
,
});
this
.
db
.
models
.
app
.
belongsTo
(
this
.
db
.
models
.
user
,{
as
:
"creator"
,
constraints
:
false
,});
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,
});
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
this
.
db
.
models
.
company
.
hasMany
(
this
.
db
.
models
.
user
,{
as
:
'us'
,
constraints
:
false
,});
this
.
db
.
models
.
company
.
hasMany
(
this
.
db
.
models
.
user
,
{
as
:
'us'
,
constraints
:
false
,
});
this
.
db
.
models
.
role
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,
});
this
.
db
.
models
.
role
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,
});
// this.db.models.org.belongsTo(this.db.models.company,{constraints: false,});
this
.
db
.
models
.
route
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
plugin
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
route
.
belongsTo
(
this
.
db
.
models
.
app
,
{
constraints
:
false
,
});
this
.
db
.
models
.
plugin
.
belongsTo
(
this
.
db
.
models
.
app
,
{
constraints
:
false
,
});
//渠道和渠道路径方法映射
this
.
db
.
models
.
pathtomethod
.
belongsTo
(
this
.
db
.
models
.
channel
,
{
constraints
:
false
,
});
this
.
db
.
models
.
channel
.
hasMany
(
this
.
db
.
models
.
pathtomethod
,
{
as
:
"pts"
,
constraints
:
false
,
});
//产品相关
this
.
db
.
models
.
productprice
.
belongsTo
(
this
.
db
.
models
.
product
,
{
constraints
:
false
,
});
this
.
db
.
models
.
product
.
hasMany
(
this
.
db
.
models
.
productprice
,
{
as
:
"skus"
,
constraints
:
false
,
});
this
.
db
.
models
.
product
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,
});
//产品价格引用定价策略
this
.
db
.
models
.
productprice
.
belongsTo
(
this
.
db
.
models
.
pricestrategy
,
{
constraints
:
false
,
});
this
.
db
.
models
.
productprice
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,
});
//成本项目属于productprice
this
.
db
.
models
.
productcost
.
belongsTo
(
this
.
db
.
models
.
productprice
,
{
constraints
:
false
,
});
this
.
db
.
models
.
productprice
.
hasMany
(
this
.
db
.
models
.
productcost
,
{
as
:
"costs"
,
constraints
:
false
,
});
//渠道和渠道路径方法映射
this
.
db
.
models
.
pathtomethod
.
belongsTo
(
this
.
db
.
models
.
channel
,{
constraints
:
false
,
});
this
.
db
.
models
.
channel
.
hasMany
(
this
.
db
.
models
.
pathtomethod
,{
as
:
"pts"
,
constraints
:
false
,
});
// 消息 -> 用户消息关联 1:n
this
.
db
.
models
.
msg
.
hasMany
(
this
.
db
.
models
.
msguser
,
{
constraints
:
false
});
this
.
db
.
models
.
msguser
.
belongsTo
(
this
.
db
.
models
.
msg
,
{
constraints
:
false
});
//产品相关
this
.
db
.
models
.
productprice
.
belongsTo
(
this
.
db
.
models
.
product
,{
constraints
:
false
,});
this
.
db
.
models
.
product
.
hasMany
(
this
.
db
.
models
.
productprice
,{
as
:
"skus"
,
constraints
:
false
,});
this
.
db
.
models
.
product
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
//产品价格引用定价策略
this
.
db
.
models
.
productprice
.
belongsTo
(
this
.
db
.
models
.
pricestrategy
,{
constraints
:
false
,});
this
.
db
.
models
.
productprice
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
//成本项目属于productprice
this
.
db
.
models
.
productcost
.
belongsTo
(
this
.
db
.
models
.
productprice
,{
constraints
:
false
,});
this
.
db
.
models
.
productprice
.
hasMany
(
this
.
db
.
models
.
productcost
,{
as
:
"costs"
,
constraints
:
false
,});
}
//async getCon(){,用于使用替换table模型内字段数据使用
getCon
()
{
var
that
=
this
;
//async getCon(){,用于使用替换table模型内字段数据使用
getCon
()
{
var
that
=
this
;
// await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.');
// }).catch(err => {
...
...
@@ -92,7 +137,7 @@ class DbFactory{
// throw err;
// });
//同步模型
if
(
settings
.
env
==
"dev"
)
{
if
(
settings
.
env
==
"dev"
)
{
//console.log(pa);
// pconfigObjs.forEach(p=>{
...
...
@@ -109,7 +154,7 @@ class DbFactory{
return
this
.
db
;
}
}
module
.
exports
=
DbFactory
;
module
.
exports
=
DbFactory
;
// const dbf=new DbFactory();
// dbf.getCon().then((db)=>{
// //console.log(db);
...
...
center-manage/app/base/db/impl/msg/msguserDao.js
0 → 100644
View file @
1eac633e
const
system
=
require
(
"../../../system"
);
const
Dao
=
require
(
"../../dao.base"
);
class
MsguserDao
extends
Dao
{
constructor
()
{
super
(
Dao
.
getModelName
(
MsguserDao
));
}
}
module
.
exports
=
MsguserDao
;
center-manage/app/base/db/models/msg/msg
history
.js
→
center-manage/app/base/db/models/msg/msg.js
View file @
1eac633e
const
system
=
require
(
"../../../system"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
const
appconfig
=
system
.
getSysConfig
();
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"msg
history
"
,
{
msgType
:{
type
:
DataTypes
.
ENUM
,
return
db
.
define
(
"msg"
,
{
msgType
:
{
type
:
DataTypes
.
ENUM
,
allowNull
:
false
,
values
:
Object
.
keys
(
appconfig
.
pdict
.
msgType
),
},
app_id
:
DataTypes
.
INTEGER
,
company_id
:
DataTypes
.
INTEGER
,
sender
:
DataTypes
.
STRING
,
senderId
:
DataTypes
.
INTEGER
,
target
:
DataTypes
.
STRING
,
targetId
:
DataTypes
.
INTEGER
,
content
:
{
type
:
DataTypes
.
TEXT
(
'long'
),
allowNull
:
false
,
},
//需要在后台补充
isRead
:{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
,
app_id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
true
},
app_key
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
true
},
company_id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
true
},
sender
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
true
},
sender_id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
true
},
title
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
false
},
emergency_level
:
{
type
:
DataTypes
.
INTEGER
,
defaultValue
:
0
},
content
:
{
type
:
DataTypes
.
TEXT
(
'long'
),
allowNull
:
false
,
},
jump_address
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
true
},
other
:
{
allowNull
:
true
,
type
:
DataTypes
.
JSON
},
is_undo
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
}
},{
paranoid
:
false
,
//假的删除
underscored
:
true
,
version
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
// define the table's name
tableName
:
'msg_history'
,
validate
:
{
},
{
paranoid
:
false
,
//假的删除
underscored
:
true
,
version
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
// define the table's name
tableName
:
'msg_history'
,
validate
:
{
},
indexes
:
[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
},
indexes
:
[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
center-manage/app/base/db/models/msg/msg
notice
.js
→
center-manage/app/base/db/models/msg/msg
user
.js
View file @
1eac633e
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"msgnotice"
,
{
fromuser
:
DataTypes
.
STRING
,
//需要在后台补充
fromId
:
DataTypes
.
INTEGER
,
touser
:
DataTypes
.
STRING
,
//需要在后台补充
toId
:
DataTypes
.
INTEGER
,
isAccepted
:
DataTypes
.
BOOLEAN
,
lastMsgId
:
DataTypes
.
INTEGER
},{
paranoid
:
true
,
//假的删除
underscored
:
true
,
version
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
// define the table's name
tableName
:
'msg_notice'
,
validate
:
{
return
db
.
define
(
"msguser"
,
{
user_id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
},
user
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
true
},
is_read
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
},
is_remind
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
},
msg_id
:
{
type
:
DataTypes
.
INTEGER
,
defaultValue
:
false
}
},
{
paranoid
:
true
,
//假的删除
underscored
:
true
,
version
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
// define the table's name
tableName
:
'msg_history_p_user_relationships'
,
validate
:
{
},
indexes
:
[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
},
indexes
:
[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
center-manage/app/base/service/impl/msg/msgSve.js
0 → 100644
View file @
1eac633e
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
const
moment
=
require
(
"moment"
);
class
MsgService
extends
ServiceBase
{
constructor
()
{
super
(
"msg"
,
ServiceBase
.
getDaoName
(
MsgService
));
this
.
msguserDao
=
system
.
getObject
(
"db.msg.msguserDao"
);
}
async
create
(
pobj
,
qobj
,
req
)
{
let
{
msgType
,
app_id
,
app_key
,
sender
,
sender_id
,
title
,
content
,
jump_address
,
other
,
target
}
=
pobj
;
let
msg
=
{
msgType
,
app_id
,
app_key
,
sender
:
sender
,
sender_id
:
sender_id
,
title
,
content
,
jump_address
,
other
}
return
this
.
db
.
transaction
(
async
(
t
)
=>
{
const
msgData
=
await
this
.
dao
.
create
(
msg
,
t
);
if
(
msgType
!==
system
.
Msg
.
SYS
&&
Object
.
prototype
.
toString
.
call
(
target
)
===
'[object Object]'
)
{
await
this
.
msguserDao
.
create
({
user_id
:
target
.
id
,
user
:
target
.
name
,
msg_id
:
msgData
.
id
},
t
);
}
if
(
msgType
!==
system
.
Msg
.
SYS
&&
Object
.
prototype
.
toString
.
call
(
target
)
===
"[object Array]"
)
{
let
msgusers
=
[];
for
(
let
val
of
target
)
{
msgusers
.
push
({
user_id
:
val
.
id
,
user
:
val
.
name
,
msg_id
:
msgData
.
id
})
}
await
this
.
msguserDao
.
bulkCreate
(
msgusers
,
t
);
}
return
'SUCCESS'
})
}
async
findRemindMessage
(
pobj
,
qobj
,
req
)
{
let
{
userid
}
=
pobj
;
const
msgData
=
await
this
.
msguserDao
.
findAll
({
user_id
:
userid
,
is_remind
:
false
},
[
{
model
:
this
.
db
.
models
.
msg
,
where
:
{
is_undo
:
false
},
}
]);
const
ids
=
msgData
.
map
(
item
=>
item
.
id
)
if
(
ids
.
length
>
0
)
{
this
.
msguserDao
.
updateByWhere
({
is_remind
:
true
},
{
id
:
{
$in
:
ids
}
});
}
return
msgData
;
}
async
findUnreadCount
(
pobj
,
qobj
,
req
)
{
let
{
userid
,
is_read
}
=
pobj
;
const
msgCount
=
await
this
.
msguserDao
.
findCount
({
where
:
{
user_id
:
userid
,
is_read
},
include
:
[
{
model
:
this
.
db
.
models
.
msg
,
where
:
{
is_undo
:
false
},
attributes
:
[
"id"
]
}
]
});
return
{
count
:
msgCount
};
}
async
updateStatus
(
pobj
,
qobj
,
req
)
{
let
{
id
,
userid
,
all
}
=
pobj
;
let
where
=
{
is_read
:
false
,
user_id
:
userid
};
if
(
!
all
)
{
where
.
id
=
id
}
await
this
.
msguserDao
.
updateByWhere
({
is_read
:
true
},
where
);
return
"SUCESS"
}
async
findSystemMsgCount
(
pobj
,
qobj
,
req
)
{
let
{
type
}
=
pobj
;
let
where
=
{
msgType
:
system
.
Msg
.
SYS
,
is_undo
:
false
,
}
if
(
type
===
"recently"
)
{
// 查询 三天内的
where
.
created_at
=
{
$between
:
[
moment
().
subtract
(
'days'
,
3
).
endOf
(
'day'
).
format
(
'YYYY-MM-DD HH:mm:ss'
),
moment
().
endOf
(
'day'
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
]
}
}
const
msgCount
=
await
this
.
dao
.
findCount
({
where
});
return
{
count
:
msgCount
};
}
async
groupCount
(
pobj
,
qobj
,
req
)
{
let
{
userid
}
=
pobj
;
let
[
read
,
unRead
,
system
]
=
await
Promise
.
all
(
[
this
.
findUnreadCount
({
userid
,
is_read
:
true
}),
this
.
findUnreadCount
({
userid
,
is_read
:
false
}),
this
.
findSystemMsgCount
({
type
:
"all"
})
]
);
return
{
read
:
read
.
count
,
unRead
:
unRead
.
count
,
system
:
system
.
count
}
}
async
list
(
pobj
,
qobj
,
req
)
{
let
{
userid
,
msgType
,
pageSize
=
10
,
pageNo
=
1
}
=
pobj
;
let
msgData
=
[];
let
other
=
{
limit
:
pageSize
,
offset
:
(
pageNo
-
1
)
*
pageSize
,
order
:
[[
"created_at"
,
"DESC"
]]
};
if
([
"read"
,
"unread"
].
includes
(
msgType
))
{
msgData
=
await
this
.
msguserDao
.
findAll
({
user_id
:
userid
,
is_read
:
msgType
===
"read"
},
[
{
model
:
this
.
db
.
models
.
msg
,
where
:
{
is_undo
:
false
}
}
],
other
);
}
if
(
msgType
===
"system"
)
{
msgData
=
await
this
.
dao
.
findAll
({
msgType
:
system
.
Msg
.
SYS
,
is_undo
:
false
,
},
[],
other
);
msgData
=
msgData
.
map
(
item
=>
{
return
{
msg
:
item
}
})
}
return
msgData
;
}
}
module
.
exports
=
MsgService
;
center-manage/app/base/system.js
View file @
1eac633e
...
...
@@ -275,6 +275,13 @@ Date.prototype.Format = function (fmt) { //author: meizz
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
==
1
)
?
(
o
[
k
])
:
((
"00"
+
o
[
k
]).
substr
((
""
+
o
[
k
]).
length
)));
return
fmt
;
}
System
.
Msg
=
{
// "sys": "系统", "single": "单点", "multi": "群发"
SYS
:
"sys"
,
SINGLE
:
"single"
,
MULTI
:
"multi"
}
/*
编码说明,
1000----1999 为请求参数验证和app权限验证
...
...
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