Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
ts-api-demo
Project
Project
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
wmvm
ts-api-demo
Commits
8593e6dc
Commit
8593e6dc
authored
Nov 29, 2024
by
ml
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
国际化新接口
parent
aacb2918
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
339 additions
and
260 deletions
+339
-260
i18n.control.ts
src/functional/mvc/control/i18n.control.ts
+10
-27
i18nlog.control.ts
src/functional/mvc/control/i18nlog.control.ts
+1
-2
i18n.service.ts
src/functional/mvc/service/i18n.service.ts
+238
-153
i18nlog.service.ts
src/functional/mvc/service/i18nlog.service.ts
+80
-68
index.ts
src/functional/router/v1/index.ts
+6
-6
access-limit.ts
src/setting/access-limit.ts
+4
-4
No files found.
src/functional/mvc/control/i18n.control.ts
View file @
8593e6dc
...
@@ -27,7 +27,7 @@ export const list = async (req: any, infoPageVO: I18nInfoPageVO) => {
...
@@ -27,7 +27,7 @@ export const list = async (req: any, infoPageVO: I18nInfoPageVO) => {
}
}
};
};
/**
/**
* 添加国际化信息
* 添加国际化信息
-发布版本
* @param req
* @param req
* @param infoVO
* @param infoVO
*/
*/
...
@@ -35,7 +35,6 @@ export const add = async (req: any, infoVO: I18nInfoVO) => {
...
@@ -35,7 +35,6 @@ export const add = async (req: any, infoVO: I18nInfoVO) => {
let
func_name
=
"i18nCtrl.add"
;
let
func_name
=
"i18nCtrl.add"
;
let
cmd
=
req
.
path
;
let
cmd
=
req
.
path
;
try
{
try
{
await
preCheck
(
infoVO
);
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
res
=
await
i18nService
.
add
(
infoVO
,
currentUserId
,
ip
);
let
res
=
await
i18nService
.
add
(
infoVO
,
currentUserId
,
ip
);
...
@@ -46,19 +45,19 @@ export const add = async (req: any, infoVO: I18nInfoVO) => {
...
@@ -46,19 +45,19 @@ export const add = async (req: any, infoVO: I18nInfoVO) => {
return
Res3Utils
.
getErrorResult
(
e
);
return
Res3Utils
.
getErrorResult
(
e
);
}
}
};
};
/**
/**
*
修改国际化信息
*
添加国际化信息-发布版本-预览
* @param req
* @param req
* @param infoVO
* @param infoVO
*/
*/
export
const
update
=
async
(
req
:
any
,
infoVO
:
I18nInfoVO
)
=>
{
export
const
preview
=
async
(
req
:
any
,
infoVO
:
I18nInfoVO
)
=>
{
let
func_name
=
"i18nCtrl.
update
"
;
let
func_name
=
"i18nCtrl.
preview
"
;
let
cmd
=
req
.
path
;
let
cmd
=
req
.
path
;
try
{
try
{
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
infoVO
.
id
);
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
res
=
await
i18nService
.
update
(
infoVO
,
currentUserId
,
ip
);
let
res
=
await
i18nService
.
preview
(
infoVO
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
catch
(
e
)
{
catch
(
e
)
{
...
@@ -67,18 +66,15 @@ export const update = async (req: any, infoVO: I18nInfoVO) => {
...
@@ -67,18 +66,15 @@ export const update = async (req: any, infoVO: I18nInfoVO) => {
}
}
};
};
/**
/**
*
删除国际化信息
*
国际化信息版本列表
* @param req
* @param req
* @param infoVO
* @param infoVO
*/
*/
export
const
del
=
async
(
req
:
any
,
infoVO
:
I18nInfoVO
)
=>
{
export
const
versionList
=
async
(
req
:
any
,
infoVO
:
I18nInfoVO
)
=>
{
let
func_name
=
"i18nCtrl.
del
"
;
let
func_name
=
"i18nCtrl.
versionList
"
;
let
cmd
=
req
.
path
;
let
cmd
=
req
.
path
;
try
{
try
{
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
infoVO
.
id
);
let
res
=
await
i18nService
.
versionList
();
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
res
=
await
i18nService
.
del
(
infoVO
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
catch
(
e
)
{
catch
(
e
)
{
...
@@ -88,16 +84,3 @@ export const del = async (req: any, infoVO: I18nInfoVO) => {
...
@@ -88,16 +84,3 @@ export const del = async (req: any, infoVO: I18nInfoVO) => {
};
};
/**
* 校验
* @param infoVO
*/
async
function
preCheck
(
infoVO
:
I18nInfoVO
)
{
if
(
!
[
1
,
2
,
3
,
4
,
5
].
includes
(
infoVO
.
platform
))
{
throw
ErrorCode
.
PARAM_MISS
;
}
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
infoVO
.
module
);
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
infoVO
.
code
);
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
infoVO
.
lang
);
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
infoVO
.
content
);
}
\ No newline at end of file
src/functional/mvc/control/i18nlog.control.ts
View file @
8593e6dc
...
@@ -36,8 +36,7 @@ export const revert = async (req: any, i18nInfoLogVO: I18nInfoLogVO) => {
...
@@ -36,8 +36,7 @@ export const revert = async (req: any, i18nInfoLogVO: I18nInfoLogVO) => {
try
{
try
{
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
i18nInfoLogVO
.
id
);
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
i18nInfoLogVO
.
version
);
ApiAssert
.
notNull
(
ErrorCode
.
PARAM_MISS
,
i18nInfoLogVO
.
info_id
);
let
res
=
await
i18nLogService
.
revert
(
i18nInfoLogVO
,
currentUserId
,
ip
);
let
res
=
await
i18nLogService
.
revert
(
i18nInfoLogVO
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
...
...
src/functional/mvc/service/i18n.service.ts
View file @
8593e6dc
// @madex/ex-ts-dao 是 ts 的 dao, 代码在 bitbucket/ex-js-dao 的 ts 分支上
// @madex/ex-ts-dao 是 ts 的 dao, 代码在 bitbucket/ex-js-dao 的 ts 分支上
import
{
i18nInfo
,
i18nInfo
Log
,
ormDB
}
from
"@madex/ex-ts-dao"
;
import
{
i18nInfo
,
i18nInfo
History
,
ormDB
}
from
"@madex/ex-ts-dao"
;
import
*
as
i18nLogService
from
"../service/i18nlog.service"
;
import
*
as
i18nLogService
from
"../service/i18nlog.service"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
addOptLog
}
from
"./userOptLog.service"
;
import
{
addOptLog
}
from
"./userOptLog.service"
;
import
{
sendRobotMessage
,
ROBOT_KEYS
}
from
"../../../utils/robotUtils"
;
import
{
sendRobotMessage
,
ROBOT_KEYS
}
from
"../../../utils/robotUtils"
;
let
{
logger
}
=
require
(
'@madex/ex-js-public'
);
let
{
logger
}
=
require
(
'@madex/ex-js-public'
);
let
_
=
require
(
'lodash'
);
export
interface
I18nInfoVO
{
export
interface
I18nInfoVO
{
id
?:
number
;
info_json
:
string
;
}
export
interface
I18nInfoPageVO
extends
I18nInfoVO
{
page
?:
number
;
size
?:
number
platform
:
number
;
platform
:
number
;
...
@@ -16,47 +23,28 @@ export interface I18nInfoVO {
...
@@ -16,47 +23,28 @@ export interface I18nInfoVO {
code
?:
string
|
any
;
code
?:
string
|
any
;
sub_code
?:
string
|
any
;
zh_cn
?:
string
|
any
;
lang
?:
string
;
desc
?:
string
|
any
;
content
?:
string
|
any
;
createdAt
?:
Date
|
any
;
updatedAt
?:
Date
|
any
;
}
export
interface
I18nInfoPageVO
extends
I18nInfoVO
{
page
?:
number
;
size
?:
number
}
}
export
const
list
=
async
(
infoPageVO
:
I18nInfoPageVO
)
=>
{
export
const
list
=
async
(
infoPageVO
:
I18nInfoPageVO
)
=>
{
let
condition
=
{};
if
(
infoPageVO
.
code
)
{
if
(
infoPageVO
.
platform
)
{
infoPageVO
.
code
=
{
[
ormDB
.
Op
.
like
]:
`
${
infoPageVO
.
code
}
%`
}
;
condition
[
'platform'
]
=
Number
(
infoPageVO
.
platform
)
;
}
}
if
(
infoPageVO
.
module
)
{
if
(
infoPageVO
.
sub_code
)
{
condition
[
'module'
]
=
Number
(
infoPageVO
.
module
);
infoPageVO
.
sub_code
=
{
[
ormDB
.
Op
.
like
]:
`
${
infoPageVO
.
sub_code
}
%`
};
}
}
if
(
infoPageVO
.
desc
)
{
if
(
infoPageVO
.
code
)
{
infoPageVO
.
desc
=
{
[
ormDB
.
Op
.
like
]:
`
${
infoPageVO
.
desc
}
%`
}
;
condition
[
'code'
]
=
infoPageVO
.
code
;
}
}
if
(
infoPageVO
.
updatedAt
)
{
if
(
infoPageVO
.
zh_cn
)
{
infoPageVO
.
updatedAt
=
{
[
ormDB
.
Op
.
gte
]:
new
Date
(
infoPageVO
.
updatedAt
).
getTime
()
};
condition
[
'zh_cn'
]
=
{
[
ormDB
.
Op
.
like
]:
`
${
infoPageVO
.
zh_cn
}
%`
};
}
}
let
page
=
Number
(
infoPageVO
.
page
);
let
page
=
Number
(
infoPageVO
.
page
);
let
size
=
Number
(
infoPageVO
.
size
);
let
size
=
Number
(
infoPageVO
.
size
);
let
where
=
Object
.
assign
(
infoPageVO
);
delete
infoPageVO
.
page
;
delete
infoPageVO
.
size
;
let
resList
=
await
i18nInfo
.
prototype
.
findAndCount
({
let
resList
=
await
i18nInfo
.
prototype
.
findAndCount
({
where
:
where
,
where
:
condition
,
limit
:
size
,
limit
:
size
,
offset
:
(
page
-
1
)
*
size
,
offset
:
(
page
-
1
)
*
size
,
order
:
[[
"id"
,
"asc"
]],
order
:
[[
"id"
,
"asc"
]],
...
@@ -65,155 +53,252 @@ export const list = async (infoPageVO: I18nInfoPageVO) => {
...
@@ -65,155 +53,252 @@ export const list = async (infoPageVO: I18nInfoPageVO) => {
return
resList
;
return
resList
;
};
};
export
const
add
=
async
(
infoVO
:
I18nInfoVO
,
currentUserId
:
any
,
ip
:
any
)
=>
{
export
const
add
=
async
(
infoVO
:
I18nInfoVO
,
currentUserId
:
any
,
ip
:
any
)
=>
{
if
(
!
infoVO
.
createdAt
)
{
infoVO
.
createdAt
=
new
Date
();
let
infoJson
=
infoVO
.
info_json
;
if
(
!
infoJson
)
{
throw
ErrorCode
.
PARAM_MISS
;
}
let
infoList
=
JSON
.
parse
(
infoJson
);
let
lastVersionList
=
await
getLastVersionList
();
let
timestamp
=
new
Date
().
getTime
();
let
insertHistoryList
:
any
=
[];
let
idList
:
any
=
[];
let
lastVersionMap
:
any
=
{};
for
(
let
item
of
lastVersionList
)
{
let
key
=
item
[
'platform'
]
+
'_'
+
item
[
'module'
]
+
'_'
+
item
[
'code'
];
lastVersionMap
[
key
]
=
item
;
idList
.
push
(
item
[
'id'
]);
item
[
'info_id'
]
=
item
[
'id'
];
item
[
'created_at'
]
=
item
[
'updated_at'
];
delete
item
[
'id'
];
insertHistoryList
.
push
(
item
);
}
let
version
=
await
getVersion
();
let
insertOrUpdateList
:
any
=
[];
for
(
let
insertOne
of
infoList
)
{
if
(
!
insertOne
.
platform
||
!
insertOne
.
module
||
!
insertOne
.
code
)
{
throw
ErrorCode
.
PARAM_MISS
;
}
}
if
(
!
infoVO
.
updatedAt
)
{
let
key
=
insertOne
[
'platform'
]
+
'_'
+
insertOne
[
'module'
]
+
'_'
+
insertOne
[
'code'
];
infoVO
.
updatedAt
=
new
Date
();
insertOne
.
version
=
version
;
insertOne
.
sub_code
=
insertOne
.
sub_code
?
insertOne
.
sub_code
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
sub_code
:
''
);
insertOne
.
zh_cn
=
insertOne
.
zh_cn
?
insertOne
.
zh_cn
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
zh_cn
:
''
);
insertOne
.
en_us
=
insertOne
.
en_us
?
insertOne
.
en_us
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
en_us
:
''
);
insertOne
.
ja_jp
=
insertOne
.
ja_jp
?
insertOne
.
ja_jp
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
ja_jp
:
''
);
insertOne
.
ko_kr
=
insertOne
.
ko_kr
?
insertOne
.
ko_kr
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
ko_kr
:
''
);
insertOne
.
vi_vn
=
insertOne
.
vi_vn
?
insertOne
.
vi_vn
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
vi_vn
:
''
);
insertOne
.
ar_ae
=
insertOne
.
ar_ae
?
insertOne
.
ar_ae
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
ar_ae
:
''
);
insertOne
.
created_at
=
timestamp
;
insertOne
.
updated_at
=
timestamp
;
insertOrUpdateList
.
push
(
insertOne
);
}
}
let
dbInfo
=
await
i18nInfo
.
prototype
.
findOne
({
let
tx
;
try
{
tx
=
await
ormDB
.
transaction
();
//先迁移历史表
if
(
insertHistoryList
.
length
)
{
await
i18nInfoHistory
.
prototype
.
bulkCreate
(
insertHistoryList
,
{
transaction
:
tx
});
}
//更新版本
if
(
lastVersionList
.
length
)
{
await
i18nInfo
.
prototype
.
update
({
version
:
version
,
updated_at
:
timestamp
},
{
where
:
{
where
:
{
platform
:
infoVO
.
platform
,
id
:
idList
module
:
infoVO
.
module
,
code
:
infoVO
.
code
,
lang
:
infoVO
.
lang
,
},
},
raw
:
true
transaction
:
tx
})
}
//批量插入或更新
if
(
insertOrUpdateList
.
length
)
{
await
i18nInfo
.
prototype
.
bulkCreate
(
insertOrUpdateList
,
{
updateOnDuplicate
:
[
'sub_code'
,
'zh_cn'
,
'en_us'
,
'ja_jp'
,
'ko_kr'
,
'vi_vn'
,
'ar_ae'
,
'updated_at'
],
transaction
:
tx
});
});
if
(
dbInfo
)
{
throw
ErrorCode
.
DATA_EXIST
;
}
}
await
i18nInfo
.
prototype
.
create
(
infoVO
);
await
tx
.
commit
();
}
catch
(
e
)
{
if
(
tx
)
{
await
tx
.
rollback
();
}
logger
.
error
(
'i18nInfo.add.error:'
+
e
);
throw
e
;
}
//管理后台操作日志
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'新增国际化信息'
,
ip
,
JSON
.
stringify
(
infoVO
)
,
'国际化管理'
);
addOptLog
(
currentUserId
,
0
,
'新增国际化信息'
,
ip
,
insertOrUpdateList
.
length
,
'国际化管理'
);
sendRobotMessage
(
ROBOT_KEYS
.
COMMON_KEY
,
`新增国际化信息:
${
JSON
.
stringify
(
infoVO
)}
`
);
sendRobotMessage
(
ROBOT_KEYS
.
COMMON_KEY
,
`新增国际化信息:
${
JSON
.
stringify
(
infoVO
)}
`
);
return
'ok'
;
return
'ok'
;
};
};
export
const
update
=
async
(
infoVO
:
I18nInfoVO
,
currentUserId
:
any
,
ip
:
any
)
=>
{
export
const
preview
=
async
(
infoVO
:
I18nInfoVO
,
currentUserId
:
any
,
ip
:
any
)
=>
{
let
transaction
:
any
;
try
{
let
infoJson
=
infoVO
.
info_json
;
let
dbOneI18nInfo
=
await
i18nInfo
.
prototype
.
findOne
({
if
(
!
infoJson
)
{
raw
:
true
,
throw
ErrorCode
.
PARAM_MISS
;
where
:
{
id
:
infoVO
.
id
}
}
});
let
infoList
=
JSON
.
parse
(
infoJson
);
if
(
!
dbOneI18nInfo
)
{
let
lastVersionList
=
await
getLastVersionList
();
throw
ErrorCode
.
DATA_NOT_EXIST
;
let
timestamp
=
new
Date
().
getTime
();
let
lastVersionMap
:
any
=
{};
for
(
let
item
of
lastVersionList
)
{
let
key
=
item
[
'platform'
]
+
'_'
+
item
[
'module'
]
+
'_'
+
item
[
'code'
];
delete
item
[
'id'
];
delete
item
[
'version'
];
delete
item
[
'created_at'
];
lastVersionMap
[
key
]
=
item
;
}
}
//查询是否有重复的
let
dbInfo
=
await
i18nInfo
.
prototype
.
findOne
({
where
:
{
for
(
let
insertOne
of
infoList
)
{
platform
:
infoVO
.
platform
,
if
(
!
insertOne
.
platform
||
!
insertOne
.
module
||
!
insertOne
.
code
)
{
module
:
infoVO
.
module
,
throw
ErrorCode
.
PARAM_MISS
;
code
:
infoVO
.
code
,
lang
:
infoVO
.
lang
,
id
:
{
[
ormDB
.
Op
.
ne
]:
infoVO
.
id
}
},
raw
:
true
});
if
(
dbInfo
)
{
throw
ErrorCode
.
DATA_EXIST
;
}
}
let
key
=
insertOne
[
'platform'
]
+
'_'
+
insertOne
[
'module'
]
+
'_'
+
insertOne
[
'code'
];
delete
infoVO
.
id
;
insertOne
.
sub_code
=
insertOne
.
sub_code
?
insertOne
.
sub_code
:
let
i18nInfoLogOne
=
await
buildOneI18nInfoLog
(
dbOneI18nInfo
,
infoVO
);
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
sub_code
:
''
);
transaction
=
await
ormDB
.
transaction
();
insertOne
.
zh_cn
=
insertOne
.
zh_cn
?
insertOne
.
zh_cn
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
zh_cn
:
''
);
insertOne
.
en_us
=
insertOne
.
en_us
?
insertOne
.
en_us
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
en_us
:
''
);
await
i18nInfo
.
prototype
.
update
(
infoVO
,
{
insertOne
.
ja_jp
=
insertOne
.
ja_jp
?
insertOne
.
ja_jp
:
where
:
{
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
ja_jp
:
''
);
id
:
dbOneI18nInfo
.
id
},
transaction
:
transaction
,
});
//日志
await
i18nLogService
.
add
(
i18nInfoLogOne
,
transaction
);
await
transaction
.
commit
();
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'修改国际化信息'
,
ip
,
JSON
.
stringify
(
infoVO
),
'国际化管理'
);
sendRobotMessage
(
ROBOT_KEYS
.
COMMON_KEY
,
`修改国际化信息:id:
${
infoVO
.
id
}
,修改为:
${
JSON
.
stringify
(
infoVO
)}
`
);
return
'ok'
;
insertOne
.
ko_kr
=
insertOne
.
ko_kr
?
insertOne
.
ko_kr
:
}
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
ko_kr
:
''
);
catch
(
e
)
{
logger
.
error
(
`i18nService.update.error:
${
e
}
`
);
insertOne
.
vi_vn
=
insertOne
.
vi_vn
?
insertOne
.
vi_vn
:
if
(
transaction
)
{
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
vi_vn
:
''
);
await
transaction
.
rollback
();
insertOne
.
ar_ae
=
insertOne
.
ar_ae
?
insertOne
.
ar_ae
:
(
lastVersionMap
[
key
]
?
lastVersionMap
[
key
].
ar_ae
:
''
);
insertOne
.
updated_at
=
timestamp
;
lastVersionMap
[
key
]
=
insertOne
;
}
}
throw
e
;
let
resList
:
any
=
[];
for
(
let
key
of
_
.
keys
(
lastVersionMap
))
{
resList
.
push
(
lastVersionMap
[
key
]);
}
}
return
'ok'
;
};
};
export
const
del
=
async
(
infoVO
:
I18nInfoVO
,
currentUserId
:
any
,
ip
:
any
)
=>
{
export
const
versionList
=
async
()
=>
{
let
transaction
:
any
;
let
options
=
{
try
{
attributes
:
[
'version'
,
'created_at'
,
'updated_at'
],
let
dbOneI18nInfo
=
await
i18nInfo
.
prototype
.
findOne
({
where
:
{},
raw
:
true
,
order
:
[[
'version'
,
'desc'
]],
where
:
{
group
:
[
'version'
,
'created_at'
,
'updated_at'
],
id
:
infoVO
.
id
raw
:
true
}
});
if
(
!
dbOneI18nInfo
)
{
throw
ErrorCode
.
DATA_NOT_EXIST
;
}
}
delete
infoVO
.
id
;
let
task1
=
i18nInfo
.
prototype
.
findAll
(
options
)
;
let
i18nInfoLogOne
=
await
buildOneI18nInfoLog
(
dbOneI18nInfo
,
infoVO
);
let
task2
=
i18nInfoHistory
.
prototype
.
findAll
(
options
);
let
[
currentInfo
,
historyInfo
]
=
await
Promise
.
all
([
task1
,
task2
]);
transaction
=
await
ormDB
.
transaction
();
return
{
current_version
:
currentInfo
,
history_version
:
historyInfo
}
};
await
i18nInfo
.
prototype
.
destroy
({
where
:
{
/**
id
:
dbOneI18nInfo
.
id
* 查询版本记录
},
*/
transaction
:
transaction
,
export
async
function
getLastVersionList
()
{
return
await
i18nInfo
.
prototype
.
findAll
({
where
:
{},
order
:
[[
'id'
,
'asc'
]],
raw
:
true
});
});
//日志
}
await
i18nLogService
.
add
(
i18nInfoLogOne
,
transaction
);
await
transaction
.
commit
();
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'删除国际化信息'
,
ip
,
JSON
.
stringify
(
infoVO
),
'国际化管理'
);
sendRobotMessage
(
ROBOT_KEYS
.
COMMON_KEY
,
`删除国际化信息:id:
${
infoVO
.
id
}
`
);
return
'ok'
;
async
function
getVersion
()
{
let
version
:
any
;
let
options
=
{
where
:
{},
order
:
[[
'version'
,
'desc'
]],
raw
:
true
}
}
catch
(
e
)
{
let
task1
=
i18nInfo
.
prototype
.
findOne
(
options
);
logger
.
error
(
`i18nService.del.error:
${
e
}
`
);
let
task2
=
i18nInfoHistory
.
prototype
.
findOne
(
options
);
if
(
transaction
)
{
let
[
oneInfo
,
oneHistory
]
=
await
Promise
.
all
([
task1
,
task2
]);
await
transaction
.
rollback
();
if
(
oneInfo
&&
oneHistory
)
{
version
=
_
.
max
([
oneInfo
.
version
,
oneHistory
.
version
]);
}
}
throw
e
;
else
if
(
oneInfo
&&
!
oneHistory
)
{
version
=
oneInfo
.
version
;
}
}
};
else
{
return
'1.0.0'
;
}
return
addVersion
(
version
,
1
);
}
async
function
buildOneI18nInfoLog
(
dbOneI18nInfo
:
any
,
infoVO
:
I18nInfoVO
)
{
/**
* 版本号+1
* @param version
* @param add
*/
function
addVersion
(
version
:
string
,
add
:
number
)
{
let
i18nInfoLogOne
=
{
let
versionStrArr
=
version
.
split
(
'.'
);
//修改前
let
versionNumArr
:
number
[]
=
[]
info_id
:
dbOneI18nInfo
.
id
,
for
(
let
i
=
0
;
i
<
versionStrArr
.
length
;
i
++
)
{
platform
:
dbOneI18nInfo
.
platform
,
versionNumArr
[
i
]
=
Number
(
versionStrArr
[
i
]);
module
:
dbOneI18nInfo
.
module
,
}
code
:
dbOneI18nInfo
.
code
,
sub_code
:
dbOneI18nInfo
.
sub_code
,
lang
:
dbOneI18nInfo
.
lang
,
desc
:
dbOneI18nInfo
.
desc
,
content
:
dbOneI18nInfo
.
content
,
//修改后
for
(
let
i
=
versionNumArr
.
length
-
1
;
i
>=
0
;
i
--
)
{
platform_after
:
infoVO
.
platform
?
infoVO
.
platform
:
dbOneI18nInfo
.
platform
,
versionNumArr
[
i
]
+=
add
;
module_after
:
infoVO
.
module
?
infoVO
.
module
:
dbOneI18nInfo
.
module
,
while
(
versionNumArr
[
i
]
>=
10
)
{
code_after
:
infoVO
.
code
?
infoVO
.
code
:
dbOneI18nInfo
.
code
,
versionNumArr
[
i
]
-=
10
;
sub_code_after
:
infoVO
.
sub_code
?
infoVO
.
sub_code
:
dbOneI18nInfo
.
sub_code
,
if
(
i
>
0
)
{
lang_after
:
infoVO
.
lang
?
infoVO
.
lang
:
dbOneI18nInfo
.
lang
,
versionNumArr
[
i
-
1
]
++
;
desc_after
:
infoVO
.
desc
?
infoVO
.
desc
:
dbOneI18nInfo
.
desc
,
}
content_after
:
infoVO
.
content
?
infoVO
.
content
:
dbOneI18nInfo
.
content
}
add
=
0
;
}
}
return
versionNumArr
.
join
(
'.'
);
return
i18nInfoLogOne
;
}
}
src/functional/mvc/service/i18nlog.service.ts
View file @
8593e6dc
// @madex/ex-ts-dao 是 ts 的 dao, 代码在 bitbucket/ex-js-dao 的 ts 分支上
// @madex/ex-ts-dao 是 ts 的 dao, 代码在 bitbucket/ex-js-dao 的 ts 分支上
import
{
i18nInfo
,
i18nInfo
Log
,
ormDB
}
from
"@madex/ex-ts-dao"
;
import
{
i18nInfo
,
i18nInfo
History
,
ormDB
}
from
"@madex/ex-ts-dao"
;
import
*
as
i18nService
from
"./i18n.service"
;
import
*
as
i18nService
from
"./i18n.service"
;
import
{
I18nInfoPageVO
,
I18nInfoVO
}
from
"./i18n.service"
;
import
{
getLastVersionList
,
I18nInfoPageVO
,
I18nInfoVO
}
from
"./i18n.service"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
addOptLog
}
from
"./userOptLog.service"
;
import
{
ROBOT_KEYS
,
sendRobotMessage
}
from
"../../../utils/robotUtils"
;
let
{
logger
}
=
require
(
'@madex/ex-js-public'
);
export
interface
I18nInfoLogVO
extends
I18nInfoPageVO
{
export
interface
I18nInfoLogVO
extends
I18nInfoPageVO
{
info_id
?:
number
;
info_id
?:
number
;
version
:
string
;
}
}
export
async
function
list
(
i18nInfoLogVO
:
I18nInfoLogVO
)
{
export
async
function
list
(
i18nInfoLogVO
:
I18nInfoLogVO
)
{
let
condition
=
{};
if
(
i18nInfoLogVO
.
code
)
{
if
(
i18nInfoLogVO
.
platform
)
{
i18nInfoLogVO
.
code
=
{
[
ormDB
.
Op
.
like
]:
`
${
i18nInfoLogVO
.
code
}
%`
}
;
condition
[
'platform'
]
=
Number
(
i18nInfoLogVO
.
platform
)
;
}
}
if
(
i18nInfoLogVO
.
module
)
{
if
(
i18nInfoLogVO
.
sub_code
)
{
condition
[
'module'
]
=
Number
(
i18nInfoLogVO
.
module
);
i18nInfoLogVO
.
sub_code
=
{
[
ormDB
.
Op
.
like
]:
`
${
i18nInfoLogVO
.
sub_code
}
%`
};
}
}
if
(
i18nInfoLogVO
.
desc
)
{
if
(
i18nInfoLogVO
.
code
)
{
i18nInfoLogVO
.
desc
=
{
[
ormDB
.
Op
.
like
]:
`
${
i18nInfoLogVO
.
desc
}
%`
}
;
condition
[
'code'
]
=
i18nInfoLogVO
.
code
;
}
}
if
(
i18nInfoLogVO
.
updatedAt
)
{
if
(
i18nInfoLogVO
.
zh_cn
)
{
i18nInfoLogVO
.
updatedAt
=
{
[
ormDB
.
Op
.
gte
]:
new
Date
(
i18nInfoLogVO
.
updatedAt
).
getTime
()
};
condition
[
'zh_cn'
]
=
{
[
ormDB
.
Op
.
like
]:
`
${
i18nInfoLogVO
.
zh_cn
}
%`
};
}
}
let
page
=
Number
(
i18nInfoLogVO
.
page
);
let
page
=
Number
(
i18nInfoLogVO
.
page
);
let
size
=
Number
(
i18nInfoLogVO
.
size
);
let
size
=
Number
(
i18nInfoLogVO
.
size
);
let
where
=
Object
.
assign
(
i18nInfoLogVO
);
let
resList
=
await
i18nInfoHistory
.
prototype
.
findAndCount
({
delete
i18nInfoLogVO
.
page
;
where
:
condition
,
delete
i18nInfoLogVO
.
size
;
let
resList
=
await
i18nInfoLog
.
prototype
.
findAndCount
({
where
:
where
,
limit
:
size
,
limit
:
size
,
offset
:
(
page
-
1
)
*
size
,
offset
:
(
page
-
1
)
*
size
,
order
:
[[
"
updatedAt"
,
"de
sc"
]],
order
:
[[
"
id"
,
"a
sc"
]],
raw
:
true
raw
:
true
});
});
return
resList
;
return
resList
;
}
}
export
const
add
=
async
(
infoLogVO
:
any
,
tx
:
any
)
=>
{
if
(
!
infoLogVO
.
createdAt
)
{
infoLogVO
.
createdAt
=
new
Date
();
}
if
(
!
infoLogVO
.
updatedAt
)
{
infoLogVO
.
updatedAt
=
new
Date
();
}
await
i18nInfoLog
.
prototype
.
create
(
infoLogVO
,
{
transaction
:
tx
,
});
};
export
async
function
revert
(
i18nInfoLogVO
:
I18nInfoLogVO
,
currentUserId
:
any
,
ip
:
any
)
{
export
async
function
revert
(
i18nInfoLogVO
:
I18nInfoLogVO
,
currentUserId
:
any
,
ip
:
any
)
{
let
dbOneI18nInfoLog
=
await
i18nInfoLog
.
prototype
.
findOne
({
let
dbHistoryList
=
await
i18nInfoHistory
.
prototype
.
findAll
({
raw
:
true
,
where
:
{
where
:
{
id
:
i18nInfoLogVO
.
id
version
:
i18nInfoLogVO
.
version
}
},
order
:
[[
'info_id'
,
'asc'
]],
raw
:
true
,
});
});
if
(
!
dbOneI18nInfoLog
)
{
throw
ErrorCode
.
DATA_NOT_EXIST
;
let
insertInfoList
:
any
=
[];
let
insertHistoryList
:
any
=
[];
for
(
let
item
of
dbHistoryList
)
{
delete
item
.
info_id
;
delete
item
.
id
;
insertInfoList
.
push
(
item
);
}
}
let
infoId
=
dbOneI18nInfoLog
.
info_id
;
let
dbOneI18nInfo
=
await
i18nInfo
.
prototype
.
findOne
({
let
currentVersionList
=
await
getLastVersionList
();
raw
:
true
,
where
:
{
let
current_version
=
""
;
id
:
infoId
for
(
let
item
of
currentVersionList
)
{
current_version
=
item
.
version
;
let
info_id
=
item
.
id
;
item
.
info_id
=
info_id
;
item
.
created_at
=
item
.
updated_at
;
delete
item
.
id
;
insertHistoryList
.
push
(
item
)
}
}
let
tx
;
try
{
tx
=
await
ormDB
.
transaction
();
if
(
insertInfoList
.
length
)
{
//删除历史版本
await
i18nInfoHistory
.
prototype
.
destroy
({
where
:
{
version
:
i18nInfoLogVO
.
version
},
transaction
:
tx
});
});
let
itemInfo
=
{
//删除当前版本
platform
:
dbOneI18nInfoLog
.
platform
,
await
i18nInfo
.
prototype
.
destroy
({
module
:
dbOneI18nInfoLog
.
module
,
where
:
{},
code
:
dbOneI18nInfoLog
.
code
,
transaction
:
tx
sub_code
:
dbOneI18nInfoLog
.
sub_code
,
});
lang
:
dbOneI18nInfoLog
.
lang
,
//当前版本存入历史
desc
:
dbOneI18nInfoLog
.
desc
,
await
i18nInfoHistory
.
prototype
.
bulkCreate
(
insertHistoryList
,
{
content
:
dbOneI18nInfoLog
.
content
,
transaction
:
tx
createdAt
:
dbOneI18nInfoLog
.
createdAt
,
});
updatedAt
:
dbOneI18nInfoLog
.
updatedAt
,
//恢复到传入的历史版本
}
await
i18nInfo
.
prototype
.
bulkCreate
(
insertInfoList
);
if
(
!
dbOneI18nInfo
)
{
await
i18nService
.
add
(
itemInfo
,
currentUserId
,
ip
);
}
}
else
{
await
tx
.
commit
();
delete
itemInfo
.
createdAt
;
await
i18nInfo
.
prototype
.
update
(
itemInfo
,
{
where
:
{
id
:
infoId
}
}
});
catch
(
e
)
{
if
(
tx
)
{
await
tx
.
rollback
();
}
}
await
i18nInfoLog
.
prototype
.
destroy
({
logger
.
error
(
'i18nInfo.add.error:'
+
e
);
where
:
{
throw
e
;
id
:
Number
(
i18nInfoLogVO
.
id
)
}
}
});
//管理后台操作日志
return
'ok'
;
addOptLog
(
currentUserId
,
0
,
'国际化信息版本回退'
,
ip
,
`当前版本:
${
current_version
}
,回退到:
${
i18nInfoLogVO
.
version
}
`
,
'国际化管理'
);
sendRobotMessage
(
ROBOT_KEYS
.
COMMON_KEY
,
`国际化信息版本回退:当前版本:
${
current_version
}
,回退到:
${
i18nInfoLogVO
.
version
}
`
);
return
'success'
;
}
}
\ No newline at end of file
src/functional/router/v1/index.ts
View file @
8593e6dc
...
@@ -55,12 +55,12 @@ const getFunc = {
...
@@ -55,12 +55,12 @@ const getFunc = {
const
postFunc
=
{
const
postFunc
=
{
//技术部-其他管理-国际化管理
//技术部-其他管理-国际化管理
'i18n/info/list'
:
i18nCtrl
.
list
,
'i18n/info/list'
:
i18nCtrl
.
list
,
//当前版本信息列表
'i18n/info/add'
:
i18nCtrl
.
add
,
'i18n/info/add'
:
i18nCtrl
.
add
,
//发布版本
'i18n/info/
update'
:
i18nCtrl
.
update
,
'i18n/info/
preview'
:
i18nCtrl
.
preview
,
//发布版本-预览
'i18n/info/
del'
:
i18nCtrl
.
del
,
'i18n/info/
version/list'
:
i18nCtrl
.
versionList
,
//版本列表
'i18n/info/
log/list'
:
i18nLogCtrl
.
list
,
'i18n/info/
history/list'
:
i18nLogCtrl
.
list
,
//历史版本信息列表
'i18n/info/
log/revert'
:
i18nLogCtrl
.
revert
,
'i18n/info/
history/revert'
:
i18nLogCtrl
.
revert
,
//版本回退
//金融部-交易管理-交易对配置
//金融部-交易管理-交易对配置
'spotPair/save'
:
spotPairCtrl
.
save
,
//新增
'spotPair/save'
:
spotPairCtrl
.
save
,
//新增
'spotPair/update'
:
spotPairCtrl
.
update
,
//修改
'spotPair/update'
:
spotPairCtrl
.
update
,
//修改
...
...
src/setting/access-limit.ts
View file @
8593e6dc
...
@@ -12,10 +12,10 @@ let cmdWhiteList = {
...
@@ -12,10 +12,10 @@ let cmdWhiteList = {
//技术部-其他管理-国际化管理
//技术部-其他管理-国际化管理
'i18n/info/list'
:
1
,
'i18n/info/list'
:
1
,
'i18n/info/add'
:
1
,
'i18n/info/add'
:
1
,
'i18n/info/
update
'
:
1
,
'i18n/info/
preview
'
:
1
,
'i18n/info/
del
'
:
1
,
'i18n/info/
version/list
'
:
1
,
'i18n/info/
log
/list'
:
1
,
'i18n/info/
history
/list'
:
1
,
'i18n/info/
log
/revert'
:
1
,
'i18n/info/
history
/revert'
:
1
,
//金融部-交易管理-交易对配置
//金融部-交易管理-交易对配置
'spotPair/save'
:
1
,
'spotPair/save'
:
1
,
'spotPair/update'
:
1
,
'spotPair/update'
:
1
,
...
...
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