Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openApi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hj
openApi
Commits
fa7e9203
Commit
fa7e9203
authored
Sep 21, 2023
by
hj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
265b7bc5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
247 additions
and
178 deletions
+247
-178
server/app/Http/Controllers/Middleware/Requestlogs.php
server/app/Http/Controllers/Middleware/Requestlogs.php
+21
-15
server/app/Jobs/RequestLogJob.php
server/app/Jobs/RequestLogJob.php
+51
-0
server/app/Repositories/Contracts/SystemJournalRepository.php
...er/app/Repositories/Contracts/SystemJournalRepository.php
+9
-0
server/app/Repositories/Eloquent/SystemJournalRepositoryEloquent.php
...Repositories/Eloquent/SystemJournalRepositoryEloquent.php
+43
-0
server/app/Repositories/Models/SystemJournal.php
server/app/Repositories/Models/SystemJournal.php
+37
-0
server/app/Services/SystemJournalService.php
server/app/Services/SystemJournalService.php
+44
-0
server/database/migrations/2022_03_23_064135_create_permission_tables.php
...migrations/2022_03_23_064135_create_permission_tables.php
+0
-162
server/database/migrations/2023_03_30_020139_create_finance_invoices_record_update_api_response_table.php
...ate_finance_invoices_record_update_api_response_table.php
+1
-1
server/database/migrations/2023_05_10_232452_create_system_journal_table.php
...rations/2023_05_10_232452_create_system_journal_table.php
+41
-0
No files found.
server/app/Http/Controllers/Middleware/Requestlogs.php
View file @
fa7e9203
...
...
@@ -12,6 +12,7 @@
namespace
App\Http\Controllers\Middleware
;
use
App\Exceptions\ServerRunTimeException
;
use
App\Jobs\RequestLogJob
;
use
App\Services\CustomerService
;
use
App\Services\ThirdPlatform\ThirdPlatformService
;
use
App\Services\ThirdPlatform\ZhenKhService
;
...
...
@@ -19,6 +20,7 @@ use Closure;
use
Illuminate\Auth\Access\AuthorizationException
;
use
Illuminate\Contracts\Auth\Factory
as
Auth
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Str
;
use
Jiannei\Response\Laravel\Support\Facades\Response
;
use
App\Support\Traits\Helpers
;
use
Symfony\Component\HttpFoundation\Response
as
SymfonyResponse
;
...
...
@@ -57,28 +59,32 @@ class Requestlogs
*/
public
function
handle
(
$request
,
Closure
$next
,
$guard
=
null
)
{
$start
=
$request
->
request
->
server
(
'REQUEST_TIME_FLOAT'
);
//$end = microtime(true);
$request
=
$request
->
request
->
all
();
if
(
$files
=
$request
->
request
->
allFiles
())
{
foreach
(
$files
as
$key
=>
$uploadedFile
)
{
$request
[
$key
]
=
[
'originalName'
=>
$uploadedFile
->
getClientOriginalName
(),
'mimeType'
=>
$uploadedFile
->
getClientMimeType
(),
];
if
(
!
$request
->
header
(
'authorization'
)){
return
Response
::
fail
(
'token 不存在!'
,
500
,
''
);
}
$token
=
trim
(
str_ireplace
(
'bearer'
,
''
,
$request
->
header
(
'authorization'
)));
try
{
$decodeToken
=
$this
->
decodeToken
(
$token
);
if
(
empty
(
$decodeToken
)
||
(
!
is_array
(
$decodeToken
)
&&
!
$decodeToken
[
'hash'
])){
return
Response
::
fail
(
'客户token无效'
,
500
,
''
);
}
}
catch
(
\Throwable
$exception
){
return
Response
::
fail
(
$exception
->
getMessage
(),
500
,
''
);
}
$start
=
$request
->
server
->
get
(
'REQUEST_TIME_FLOAT'
);
$uniqueId
=
$request
->
headers
->
get
(
'X-Unique-Id'
)
?:
Str
::
uuid
()
->
toString
();
$context
=
[
'request'
=>
$request
,
'account'
=>
auth
()
->
user
(),
'request'
=>
$request
->
request
->
all
(),
'uniqueId'
=>
$uniqueId
,
'token'
=>
$decodeToken
[
'hash'
],
'start'
=>
$start
,
//'end' => $end,
//'duration' => format_duration($end - $start),
];
$job
=
new
RequestLogJob
(
\config
(
'logging.request.message'
),
$context
,
request
()
->
server
());
$job
->
handle
();
return
$next
(
$request
);
}
...
...
server/app/Jobs/RequestLogJob.php
0 → 100644
View file @
fa7e9203
<?php
namespace
App\Jobs
;
use
App\Services\SystemJournalService
;
use
Illuminate\Bus\Queueable
;
use
Illuminate\Queue\InteractsWithQueue
;
use
Monolog\Logger
;
use
Monolog\Processor\WebProcessor
;
use
Psr\Log\LoggerInterface
;
class
RequestLogJob
extends
Job
{
use
InteractsWithQueue
;
use
Queueable
;
private
$context
;
private
$message
;
private
$serverData
;
public
function
__construct
(
string
$message
,
array
$context
=
null
,
array
$serverData
=
null
)
{
$this
->
message
=
$message
;
$this
->
context
=
$context
;
$this
->
serverData
=
$serverData
;
}
public
function
handle
()
{
$logger
=
null
;
if
(
config
(
'logging.request.enabled'
))
{
app
()
->
forgetInstance
(
LoggerInterface
::
class
);
$logger
=
app
(
LoggerInterface
::
class
)
->
getLogger
();
if
(
$logger
instanceof
Logger
)
{
$logger
->
pushProcessor
(
new
WebProcessor
(
$this
->
serverData
));
}
}
try
{
app
(
SystemJournalService
::
class
)
->
writeToDbLog
(
$this
->
context
,
$this
->
serverData
);
if
(
$logger
)
{
$logger
->
debug
(
$this
->
message
,
$this
->
context
);
}
}
catch
(
\Throwable
$exception
){
$this
->
context
[
'exception'
]
=
$exception
;
if
(
$logger
)
{
$logger
->
error
(
$this
->
message
,
$this
->
context
);
}
}
}
}
server/app/Repositories/Contracts/SystemJournalRepository.php
0 → 100644
View file @
fa7e9203
<?php
namespace
App\Repositories\Contracts
;
use
Prettus\Repository\Contracts\RepositoryInterface
;
interface
SystemJournalRepository
extends
RepositoryInterface
{
}
server/app/Repositories/Eloquent/SystemJournalRepositoryEloquent.php
0 → 100644
View file @
fa7e9203
<?php
namespace
App\Repositories\Eloquent
;
use
App\Repositories\Contracts\SystemJournalRepository
;
use
App\Repositories\Criteria\RequestCriteria
;
use
App\Repositories\BaseRepository
;
use
App\Repositories\Models\SystemJournal
;
class
SystemJournalRepositoryEloquent
extends
BaseRepository
implements
SystemJournalRepository
{
protected
$fieldSearchable
=
[
];
/**
* Specify Model class name.
*
* @return string
*/
public
function
model
()
{
return
SystemJournal
::
class
;
}
/**
* Boot up the repository, pushing criteria.
*
* @throws \Prettus\Repository\Exceptions\RepositoryException
*/
public
function
boot
()
{
$this
->
pushCriteria
(
app
(
RequestCriteria
::
class
));
}
public
function
createJournal
(
$logs
)
{
$saveParams
=
$logs
;
$saveParams
[
'created_at'
]
=
date
(
'Y-m-d H:i:s'
,
time
());
$saveParams
[
'updated_at'
]
=
date
(
'Y-m-d H:i:s'
,
time
());
return
$this
->
create
(
$saveParams
);
}
}
server/app/Repositories/Models/SystemJournal.php
0 → 100644
View file @
fa7e9203
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
App\Repositories\Models
;
class
SystemJournal
extends
Model
{
protected
$table
=
'system_journal'
;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected
$fillable
=
[
'uniqueid'
,
'request_type'
,
'request_route'
,
'request_params'
,
'operation_params'
,
'token'
,
'ip'
,
'duration'
,
'device_info'
,
'created_at'
,
'updated_at'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected
$hidden
=
[
];
}
server/app/Services/SystemJournalService.php
0 → 100644
View file @
fa7e9203
<?php
namespace
App\Services
;
use
App\Repositories\Contracts\SystemJournalRepository
;
use
App\Repositories\Criteria\SystemJournalCriteria
;
use
App\Repositories\Transformers\SystemJournalTransformer
;
use
App\Support\Traits\Helpers
;
use
Illuminate\Support\Str
;
use
longlang\phpkafka\Protocol\DescribeLogDirs\DescribableLogDirTopic
;
class
SystemJournalService
{
use
Helpers
;
public
function
__construct
(
SystemJournalRepository
$systemJournalRepository
)
{
$this
->
systemJournalRepository
=
$systemJournalRepository
;
}
public
function
writeToDbLog
(
&
$context
,
$serverData
)
{
$request
=
$context
;
$dbLog
=
[];
$dbLog
[
'uniqueid'
]
=
$request
[
'uniqueId'
];
$dbLog
[
'request_type'
]
=
$serverData
[
'REQUEST_METHOD'
];
$dbLog
[
'request_route'
]
=
Str
::
replace
(
'?'
.
$serverData
[
'QUERY_STRING'
],
''
,
$serverData
[
'REQUEST_URI'
]);
$dbLog
[
'request_params'
]
=
json_encode
(
$request
[
'request'
]);
$dbLog
[
'token'
]
=
$request
[
'token'
];
$dbLog
[
'ip'
]
=
$serverData
[
'REMOTE_ADDR'
];
$dbLog
[
'device_info'
]
=
$serverData
[
'HTTP_USER_AGENT'
];
$context
[
'end'
]
=
microtime
(
true
);
$context
[
'duration'
]
=
format_duration
(
$context
[
'end'
]
-
$context
[
'start'
]);
$dbLog
[
'duration'
]
=
$context
[
'duration'
];
$result
=
$this
->
systemJournalRepository
->
createJournal
(
$dbLog
);
return
(
bool
)
$result
;
}
}
server/database/migrations/2022_03_23_064135_create_permission_tables.php
deleted
100644 → 0
View file @
265b7bc5
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Schema
;
class
CreatePermissionTables
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
$tableNames
=
config
(
'permission.table_names'
);
$columnNames
=
config
(
'permission.column_names'
);
if
(
empty
(
$tableNames
))
{
throw
new
\Exception
(
'Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.'
);
}
/*
* 权限表
* 所有的菜单、搜索、列表中的操作权限都在这里。
*/
Schema
::
create
(
$tableNames
[
'permissions'
],
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
string
(
'name'
);
$table
->
unsignedBigInteger
(
'menu_id'
);
$table
->
string
(
'action'
)
->
comment
(
'权限的行为'
);
$table
->
enum
(
'permission_type'
,[
'menu'
,
'data'
,
'button'
])
->
nullable
()
->
comment
(
'权限类型'
);
$table
->
unsignedTinyInteger
(
'sys_default'
)
->
default
(
0
)
->
comment
(
'是否系统默认'
);
$table
->
text
(
'remark'
)
->
nullable
()
->
comment
(
'备注'
);
$table
->
string
(
'guard_name'
)
->
comment
(
'权限插件保留字段'
);
$table
->
timestamps
();
});
$columns
=
[
'name'
,
'guard_name'
];
Schema
::
table
(
$tableNames
[
'permissions'
],
function
(
Blueprint
$table
)
use
(
$tableNames
,
$columns
){
DB
::
statement
(
'ALTER TABLE '
.
$tableNames
[
'permissions'
]
.
' ROW_FORMAT=DYNAMIC;'
);
//外键关联menus表id
/*$table->foreign('menu_id')
->references('id')
->on('menus')
->onUpdate('CASCADE')
->onDelete('CASCADE');*/
$table
->
index
(
$columns
);
$table
->
unique
(
$columns
);
});
Schema
::
create
(
$tableNames
[
'roles'
],
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
string
(
'name'
)
->
comment
(
'名称'
);
$table
->
unsignedTinyInteger
(
'is_default'
)
->
default
(
0
)
->
comment
(
'是否默认'
);
$table
->
text
(
'remark'
)
->
nullable
()
->
comment
(
'备注'
);
$table
->
string
(
'guard_name'
)
->
comment
(
'权限插件保留字段'
);
$table
->
timestamps
();
});
$columns
=
[
'name'
,
'guard_name'
];
Schema
::
table
(
$tableNames
[
'roles'
],
function
(
Blueprint
$table
)
use
(
$tableNames
,
$columns
){
DB
::
statement
(
'ALTER TABLE '
.
$tableNames
[
'roles'
]
.
' ROW_FORMAT=DYNAMIC;'
);
$table
->
index
(
$columns
);
$table
->
unique
(
$columns
);
});
Schema
::
create
(
$tableNames
[
'model_has_permissions'
],
function
(
Blueprint
$table
)
use
(
$tableNames
,
$columnNames
)
{
$table
->
unsignedBigInteger
(
'permission_id'
);
$table
->
string
(
'model_type'
);
$table
->
unsignedBigInteger
(
$columnNames
[
'model_morph_key'
]);
$table
->
foreign
(
'permission_id'
)
->
references
(
'id'
)
->
on
(
$tableNames
[
'permissions'
])
->
onDelete
(
'cascade'
);
});
Schema
::
table
(
$tableNames
[
'model_has_permissions'
],
function
(
Blueprint
$table
)
use
(
$tableNames
,
$columnNames
){
DB
::
statement
(
'ALTER TABLE '
.
$tableNames
[
'model_has_permissions'
]
.
' ROW_FORMAT=DYNAMIC;'
);
$table
->
index
([
$columnNames
[
'model_morph_key'
],
'model_type'
],
'model_has_permissions_model_id_model_type_index'
);
$table
->
primary
([
'permission_id'
,
$columnNames
[
'model_morph_key'
],
'model_type'
],
'model_has_permissions_permission_model_type_primary'
);
});
Schema
::
create
(
$tableNames
[
'model_has_roles'
],
function
(
Blueprint
$table
)
use
(
$tableNames
,
$columnNames
)
{
$table
->
unsignedBigInteger
(
'role_id'
);
$table
->
string
(
'model_type'
);
$table
->
unsignedBigInteger
(
$columnNames
[
'model_morph_key'
]);
$table
->
foreign
(
'role_id'
)
->
references
(
'id'
)
->
on
(
$tableNames
[
'roles'
])
->
onDelete
(
'cascade'
);
});
Schema
::
table
(
$tableNames
[
'model_has_roles'
],
function
(
Blueprint
$table
)
use
(
$tableNames
,
$columnNames
){
DB
::
statement
(
'ALTER TABLE '
.
$tableNames
[
'model_has_roles'
]
.
' ROW_FORMAT=DYNAMIC;'
);
$table
->
index
([
$columnNames
[
'model_morph_key'
],
'model_type'
],
'model_has_roles_model_id_model_type_index'
);
$table
->
primary
([
'role_id'
,
$columnNames
[
'model_morph_key'
],
'model_type'
],
'model_has_roles_role_model_type_primary'
);
});
Schema
::
create
(
$tableNames
[
'role_has_permissions'
],
function
(
Blueprint
$table
)
use
(
$tableNames
)
{
$table
->
unsignedBigInteger
(
'permission_id'
);
$table
->
unsignedBigInteger
(
'role_id'
);
$table
->
foreign
(
'permission_id'
)
->
references
(
'id'
)
->
on
(
$tableNames
[
'permissions'
])
->
onDelete
(
'cascade'
);
$table
->
foreign
(
'role_id'
)
->
references
(
'id'
)
->
on
(
$tableNames
[
'roles'
])
->
onDelete
(
'cascade'
);
});
Schema
::
table
(
$tableNames
[
'role_has_permissions'
],
function
(
Blueprint
$table
)
use
(
$tableNames
,
$columnNames
){
DB
::
statement
(
'ALTER TABLE '
.
$tableNames
[
'role_has_permissions'
]
.
' ROW_FORMAT=DYNAMIC;'
);
$table
->
primary
([
'permission_id'
,
'role_id'
],
'role_has_permissions_permission_id_role_id_primary'
);
;
});
app
(
'cache'
)
->
store
(
config
(
'permission.cache.store'
)
!=
'default'
?
config
(
'permission.cache.store'
)
:
null
)
->
forget
(
config
(
'permission.cache.key'
));
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
$tableNames
=
config
(
'permission.table_names'
);
if
(
empty
(
$tableNames
))
{
throw
new
\Exception
(
'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'
);
}
Schema
::
drop
(
$tableNames
[
'role_has_permissions'
]);
Schema
::
drop
(
$tableNames
[
'model_has_roles'
]);
Schema
::
drop
(
$tableNames
[
'model_has_permissions'
]);
Schema
::
drop
(
$tableNames
[
'roles'
]);
Schema
::
drop
(
$tableNames
[
'permissions'
]);
}
}
server/database/migrations/2023_03_30_020139_create_finance_invoices_record_update_api_response_table.php
View file @
fa7e9203
...
...
@@ -13,7 +13,7 @@ class CreateFinanceInvoicesRecordUpdateApiResponseTable extends Migration
*/
public
function
up
()
{
Schema
::
creat
e
(
'finance_invoice_record'
,
function
(
Blueprint
$table
)
{
Schema
::
tabl
e
(
'finance_invoice_record'
,
function
(
Blueprint
$table
)
{
$table
->
text
(
'api_response'
)
->
nullable
()
->
comment
(
'api返回接口'
);
});
}
...
...
server/database/migrations/2023_05_10_232452_create_system_journal_table.php
0 → 100644
View file @
fa7e9203
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateSystemJournalTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'system_journal'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
string
(
'uniqueid'
)
->
comment
(
'uniqueid'
)
->
nullable
(
false
);
$table
->
string
(
'request_type'
)
->
nullable
(
false
)
->
comment
(
'请求类型'
);
$table
->
string
(
'request_route'
)
->
nullable
(
false
)
->
comment
(
'请求路径'
);
$table
->
longText
(
'request_params'
)
->
nullable
(
false
)
->
comment
(
'请求参数'
);
$table
->
string
(
'token'
)
->
nullable
(
false
)
->
comment
(
'操作账号'
);
$table
->
string
(
'ip'
)
->
nullable
(
false
)
->
comment
(
'ip地址'
);
$table
->
string
(
'duration'
)
->
nullable
(
false
)
->
comment
(
'操作时长'
);
$table
->
text
(
'device_info'
)
->
nullable
(
false
)
->
comment
(
'设备信息'
);
$table
->
timestamps
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'system_journal'
);
}
}
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