Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
without authentication
meibuyu-common
Commits
e94d391c
Commit
e94d391c
authored
Mar 01, 2023
by
zhangdongying
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新增调用示例
parent
fa0a82bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
12 deletions
+122
-12
AppOperateLogService.php
src/GlobalLog/AppOperateLogService.php
+30
-12
OperateTypeEnum.php
src/GlobalLog/Enum/OperateTypeEnum.php
+22
-0
AppOperateLogExample.php
src/GlobalLog/Example/AppOperateLogExample.php
+70
-0
No files found.
src/GlobalLog/AppOperateLogService.php
View file @
e94d391c
...
...
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace
Meibuyu\Common\GlobalLog
;
use
Hyperf\Contract\ConfigInterface
;
use
Hyperf\DbConnection\Model\Model
;
use
Hyperf\HttpServer\Contract\RequestInterface
;
use
Meibuyu\Common\GlobalLog\Service\OperateLogService
;
use
Meibuyu\Micro\Model\Auth
;
...
...
@@ -74,15 +75,32 @@ class AppOperateLogService
}
}
/**
* 格式化原始数据
*
* @param mixed $data 原始数据
* @return string
*/
public
function
formatSourceData
(
$data
)
:
string
{
if
(
$data
instanceof
Model
)
{
return
self
::
encodeArrayToJson
(
$data
->
toArray
());
}
elseif
(
is_array
(
$data
))
{
return
self
::
encodeArrayToJson
(
$data
);
}
else
{
return
(
string
)
$data
;
}
}
/**
* 添加用户操作日志
*
* @param string $tableName 表名
* @param string $recordId 记录ID
* @param string $operateType 操作类型
* @param string|array $param 参数
* @param string|array $before 修改之前数据
* @param string|array $after 修改之后数据
* @param string|array
|Model
$param 参数
* @param string|array
|Model
$before 修改之前数据
* @param string|array
|Model
$after 修改之后数据
* @param string $remark 备注
* @return bool
* @throws \Exception
...
...
@@ -107,9 +125,9 @@ class AppOperateLogService
$tableName
,
$recordId
,
$operateType
,
is_array
(
$param
)
?
self
::
encodeArrayToJson
(
$param
)
:
(
string
)
$param
,
is_array
(
$before
)
?
self
::
encodeArrayToJson
(
$before
)
:
(
string
)
$before
,
is_array
(
$after
)
?
self
::
encodeArrayToJson
(
$after
)
:
(
string
)
$after
,
$this
->
formatSourceData
(
$param
)
,
$this
->
formatSourceData
(
$before
)
,
$this
->
formatSourceData
(
$after
)
,
$remark
);
}
...
...
@@ -121,9 +139,9 @@ class AppOperateLogService
* @param string $tableName 表名
* @param string $recordId 记录ID
* @param string $operateType 操作类型
* @param string|array $param 参数
* @param string|array $before 修改之前数据
* @param string|array $after 修改之后数据
* @param string|array
|Model
$param 参数
* @param string|array
|Model
$before 修改之前数据
* @param string|array
|Model
$after 修改之后数据
* @param string $remark 备注
* @return bool
* @throws \Exception
...
...
@@ -149,9 +167,9 @@ class AppOperateLogService
$tableName
,
$recordId
,
$operateType
,
is_array
(
$param
)
?
self
::
encodeArrayToJson
(
$param
)
:
(
string
)
$param
,
is_array
(
$before
)
?
self
::
encodeArrayToJson
(
$before
)
:
(
string
)
$before
,
is_array
(
$after
)
?
self
::
encodeArrayToJson
(
$after
)
:
(
string
)
$after
,
$this
->
formatSourceData
(
$param
)
,
$this
->
formatSourceData
(
$before
)
,
$this
->
formatSourceData
(
$after
)
,
$remark
);
}
...
...
src/GlobalLog/Enum/OperateTypeEnum.php
View file @
e94d391c
<?php
/**
* 操作类型枚举
*
* @author zhangdongying
* @date 2023-03-01
*/
declare
(
strict_types
=
1
);
namespace
Meibuyu\Common\GlobalLog\Enum
;
class
OperateTypeEnum
{
// 新增
const
ADD
=
'ADD'
;
// 修改
const
UPDATE
=
'UPDATE'
;
// 删除
const
DELETE
=
'DELETE'
;
}
\ No newline at end of file
src/GlobalLog/Example/AppOperateLogExample.php
0 → 100644
View file @
e94d391c
<?php
/**
* 操作日志示例
*
* @author zhangdongying
* @date 2023-03-01
*/
declare
(
strict_types
=
1
);
namespace
Meibuyu\Common\GlobalLog\Example
;
use
Meibuyu\Common\GlobalLog\AppOperateLogService
;
use
Meibuyu\Common\GlobalLog\Enum\OperateTypeEnum
;
use
Psr\Container\ContainerInterface
;
class
AppOperateLogExample
{
/**
* 容器实例
*/
protected
$container
;
/**
* 初始化
*
* @param ContainerInterface $container 容器实例
* @throws \Throwable
*/
public
function
__construct
(
ContainerInterface
$container
)
{
$this
->
container
=
$container
;
}
/**
* addUserOperateLog 调用示例
*
* @return void
* @throws \Throwable
*/
public
function
addUserOperateLogExample
()
{
$this
->
container
->
get
(
AppOperateLogService
::
class
)
->
addUserOperateLog
(
'products'
,
'1'
,
OperateTypeEnum
::
UPDATE
,
[
'product_id'
=>
1
,
'name'
=>
'bbb'
],
[
'id'
=>
1
,
'name'
=>
'aaa'
],
[
'id'
=>
2
,
'name'
=>
'bbb'
]
);
}
/**
* addSystemOperateLog 调用示例
*
* @return void
* @throws \Throwable
*/
public
function
addSystemOperateLogExample
()
{
$this
->
container
->
get
(
AppOperateLogService
::
class
)
->
addSystemOperateLog
(
'product_data_update'
,
'products'
,
'1'
,
OperateTypeEnum
::
UPDATE
,
[
'product_id'
=>
1
,
'name'
=>
'bbb'
],
[
'id'
=>
1
,
'name'
=>
'aaa'
],
[
'id'
=>
2
,
'name'
=>
'bbb'
]
);
}
}
\ No newline at end of file
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