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
2869aea0
Commit
2869aea0
authored
Nov 22, 2024
by
hj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新提交
parent
ddb46597
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
238 additions
and
1 deletion
+238
-1
server/app/Console/Commands/ChemSrcCommand.php
server/app/Console/Commands/ChemSrcCommand.php
+73
-0
server/app/Providers/AppServiceProvider.php
server/app/Providers/AppServiceProvider.php
+2
-1
server/app/Services/ThirdPlatform/Api/ChemSrcApiService.php
server/app/Services/ThirdPlatform/Api/ChemSrcApiService.php
+39
-0
server/app/Services/ThirdPlatform/ChemSrcService.php
server/app/Services/ThirdPlatform/ChemSrcService.php
+105
-0
server/app/Support/Traits/Helpers.php
server/app/Support/Traits/Helpers.php
+8
-0
server/database/seeds/local/ThridApiPlatformSeeder.php
server/database/seeds/local/ThridApiPlatformSeeder.php
+11
-0
No files found.
server/app/Console/Commands/ChemSrcCommand.php
0 → 100644
View file @
2869aea0
<?php
namespace
App\Console\Commands
;
use
App\Jobs\WuxiLabJob
;
use
App\Services\ThirdPlatform\ChemSrcService
;
use
App\Services\ThirdPlatform\WuxiLabNewService
;
use
App\Services\ThirdPlatform\WuxiLabService
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\ConfirmableTrait
;
class
ChemSrcCommand
extends
Command
{
use
ConfirmableTrait
;
/**
* 命令行的名称及用法。
*
* @var string
*/
protected
$signature
=
'chemsrc:job
{--action_type= : 任务操作类型}
{--params= : 任务参数}'
;
/**
* 命令行的概述。
*
* @var string
*/
protected
$description
=
'化源网任务命令行'
;
/**
* 创建新的命令实例。
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* 运行命令。
* @throws \Exception
*/
public
function
handle
()
{
if
(
!
$this
->
confirmToProceed
())
{
return
1
;
}
if
(
$this
->
hasArgument
(
'help'
)){
$this
->
help
();
}
else
{
$action_type
=
$this
->
option
(
'action_type'
);
$params
=
$this
->
option
(
'params'
);
if
(
empty
(
$action_type
)){
$this
->
error
(
'缺少命令参数,请输入具体的参数命令.如需帮助请输入 --help'
);
exit
;
}
$service
=
app
(
ChemSrcService
::
class
);
$service
->
notWuhuaCasList
();
}
}
public
function
help
()
{
$helpStr
=
"参数帮助说明"
;
$this
->
comment
(
$this
->
setHelp
(
$helpStr
)
->
getProcessedHelp
());
$this
->
line
(
"action_type: 具体动作参数
\n\n
initProductToExcel => 初始化批量商品
\n
batchUpdateProduct => 批量更新商品
\n\n
params : 操作需要传入的参数.非必填项"
);
}
}
server/app/Providers/AppServiceProvider.php
View file @
2869aea0
...
@@ -79,7 +79,8 @@ class AppServiceProvider extends ServiceProvider
...
@@ -79,7 +79,8 @@ class AppServiceProvider extends ServiceProvider
\App\Console\Commands\TestJobCommand
::
class
,
\App\Console\Commands\TestJobCommand
::
class
,
\App\Console\Commands\RhawnToolsJobCommand
::
class
,
\App\Console\Commands\RhawnToolsJobCommand
::
class
,
\App\Console\Commands\InvoiceJobCommand
::
class
,
\App\Console\Commands\InvoiceJobCommand
::
class
,
\App\Console\Commands\WuxiLabNewJobCommand
::
class
\App\Console\Commands\WuxiLabNewJobCommand
::
class
,
\App\Console\Commands\ChemSrcCommand
::
class
]);
]);
}
}
...
...
server/app/Services/ThirdPlatform/Api/ChemSrcApiService.php
0 → 100644
View file @
2869aea0
<?php
namespace
App\Services\ThirdPlatform\Api
;
use
App\Repositories\Contracts\ThirdApiPlatformRepository
;
use
App\Services\ThirdPlatform\PlatformAbstractService
;
use
App\Support\Facades\SimpleLogs
;
use
App\Support\Traits\HttpClientHelpers
;
class
ChemSrcApiService
extends
PlatformAbstractService
{
use
HttpClientHelpers
;
public
function
__construct
(
ThirdApiPlatformRepository
$thirdApiPlatformRepository
)
{
parent
::
__construct
(
$thirdApiPlatformRepository
);
$this
->
setPlatformName
(
'chemsrc'
);
$this
->
getPlatformInfo
();
}
public
function
getCasWebInfo
(
$cas
)
{
try
{
if
(
$this
->
checkPlatformStatus
())
{
$cas
=
urlencode
(
urlencode
(
iconv
(
"gbk"
,
"UTF-8"
,
$cas
)));
return
$this
->
clientRequest
(
'get'
,
$this
->
platformInfo
[
'platform_url'
]
.
'/searchResult/'
.
$cas
.
'/'
,
[]);
}
}
catch
(
\Exception
$e
){
$this
->
requestError
(
$e
);
}
}
protected
function
requestError
(
$response
)
{
SimpleLogs
::
writeLog
(
$response
->
getMessage
(),
'WuxiApi error'
,
'error'
);
throw
$response
;
}
}
server/app/Services/ThirdPlatform/ChemSrcService.php
0 → 100644
View file @
2869aea0
<?php
namespace
App\Services\ThirdPlatform
;
use
App\Repositories\Contracts\ThirdApiPlatformRepository
;
use
App\Rhawn\Services\RhawnProductService
;
use
App\Services\ThirdPlatform\Api\ChemSrcApiService
;
use
App\Support\Facades\SimpleLogs
;
use
App\Support\Traits\Helpers
;
use
Illuminate\Support\Facades\DB
;
class
ChemSrcService
{
use
Helpers
;
public
function
__construct
()
{
$this
->
apiService
=
(
new
ChemSrcApiService
(
app
(
ThirdApiPlatformRepository
::
class
)));
$this
->
rhawnChemicalsService
=
app
(
RhawnProductService
::
class
);
}
public
function
batchUpdateCas
(
$updateData
)
{
if
(
empty
(
$updateData
[
'cas'
])){
return
false
;
}
$cas
=
$updateData
[
'cas'
];
$molId
=
$updateData
[
'mol_id'
];
try
{
$responseHtml
=
$this
->
apiService
->
getCasWebInfo
(
$cas
);
if
(
$responseHtml
){
$wuhuaList
=
[];
$wuhuaDivRegx
=
'/id=[\\\'|\"]wuHuaDiv[\\\'|\"]>(?<wuhuaHtml>[\s\S]+?)<div\s{0,}class=[\\\'|\"]cata-div row[\\\'|\"]/i'
;
preg_match
(
$wuhuaDivRegx
,
$responseHtml
,
$wuhuaHtml
);
if
(
!
empty
(
$wuhuaHtml
))
{
$wuhuaDetailRegx
=
'/<th[\s\S]*?>(?<title>[\s\S]*?)<\/th>[\s\S]*?<td[\s\S]*?>(?<content>[\s\S]*?)<\/td>/i'
;
preg_match_all
(
$wuhuaDetailRegx
,
$wuhuaHtml
[
'wuhuaHtml'
],
$wuhuaDetailList
);
if
(
!
empty
(
$wuhuaDetailList
)){
foreach
(
$wuhuaDetailList
[
'title'
]
as
$key
=>
$title
){
$wuhuaList
[
$title
]
=
str_replace
(
" "
,
""
,
str_replace
(
"
\r\n
"
,
""
,
$wuhuaDetailList
[
'content'
][
$key
]));
}
}
}
if
(
!
empty
(
$wuhuaList
)){
$baikeMysql
=
DB
::
connection
(
'baike_mysql'
);
$baikeMysql
->
table
(
'tp_mol_wuhua'
)
->
updateOrInsert
([
'cas'
=>
$cas
],
[
'mol_id'
=>
$molId
,
'content'
=>
json_encode
([
$wuhuaList
],
JSON_UNESCAPED_UNICODE
)
]);
}
return
true
;
}
}
catch
(
\Throwable
$exception
){
SimpleLogs
::
writeLog
(
$exception
->
getMessage
(),
__CLASS__
.
':batchUpdateCas'
,
'error'
);
}
}
public
function
notWuhuaCasList
()
{
try
{
$status
=
$this
->
apiService
->
checkPlatformStatus
();
if
(
$status
){
$limit
=
100
;
$page
=
0
;
ini_set
(
'memory_limit'
,
'3072M'
);
while
(
true
)
{
$baikeMysql
=
DB
::
connection
(
'baike_mysql'
);
$casList
=
$baikeMysql
->
table
(
'tp_mol_data'
)
->
offset
(
$page
*
$limit
)
->
limit
(
$limit
)
->
get
()
->
toArray
();
$waitSearchCasList
=
array_unique
(
array_column
(
$casList
,
'cas'
));
$waitSearchCasListSort
=
array_column
(
$casList
,
null
,
'cas'
);
$wuhuaList
=
$baikeMysql
->
table
(
'tp_mol_wuhua'
)
->
whereIn
(
'cas'
,
$waitSearchCasList
)
->
get
()
->
toArray
();
$wuhuaCasList
=
array_unique
(
array_column
(
$wuhuaList
,
'cas'
));
$waitGetCasWuhuaList
=
array_diff
(
$waitSearchCasList
,
$wuhuaCasList
);
if
(
!
empty
(
$waitGetCasWuhuaList
))
{
foreach
(
$waitGetCasWuhuaList
as
$cas
)
{
if
(
!
empty
(
$waitSearchCasListSort
[
$cas
]))
{
$this
->
apiService
->
pushQueue
([
'params'
=>
[
'cas'
=>
$cas
,
'mol_id'
=>
$waitSearchCasListSort
[
$cas
]
->
id
],
'consumer'
=>
__CLASS__
,
'method'
=>
'batchUpdateCas'
],
'chemsrc_wuhua_crawl'
);
}
}
}
$page
++
;
}
}
}
catch
(
\Throwable
$exception
){
SimpleLogs
::
writeLog
(
$exception
->
getMessage
(),
__CLASS__
.
':notWuhuaCasList'
,
'error'
);
}
}
}
server/app/Support/Traits/Helpers.php
View file @
2869aea0
...
@@ -164,4 +164,12 @@ trait Helpers
...
@@ -164,4 +164,12 @@ trait Helpers
return
$mixed
;
return
$mixed
;
}
}
function
stripHtml
(
$str
)
:
string
{
$str
=
str_replace
(
"<br>"
,
""
,
$str
);
//$str = htmlspecialchars($str);
$str
=
htmlspecialchars_decode
(
$str
);
return
strip_tags
(
$str
);
}
}
}
server/database/seeds/local/ThridApiPlatformSeeder.php
View file @
2869aea0
...
@@ -86,6 +86,17 @@ class ThridApiPlatformSeeder extends Seeder
...
@@ -86,6 +86,17 @@ class ThridApiPlatformSeeder extends Seeder
'platform_status'
=>
'1'
,
'platform_status'
=>
'1'
,
'platform_token'
=>
''
,
'platform_token'
=>
''
,
],
],
[
'platform_name'
=>
'chemsrc'
,
'platform_title'
=>
'化源网'
,
'platform_url'
=>
'https://www.chemsrc.com'
,
'platform_desc'
=>
''
,
'platform_icon'
=>
''
,
'platform_params'
=>
''
,
'platform_type'
=>
'third'
,
'platform_status'
=>
'1'
,
'platform_token'
=>
''
,
],
];
];
...
...
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