Commit bb758afb authored by hangjun83's avatar hangjun83

openapi

parent f5ad2f39
......@@ -35,6 +35,12 @@ class WuxiLabJob extends Job
}
$service->initCreateProductsToExcel($params['limit']);
break;
case 'batchUpdatePackages' :
if(!isset($params) || $params == 0){
$params['limit'] = 1000;
}
$service->batchUpdatePackagesInfo();
break;
case 'batchUpdateProduct' :
$service->batchUpdateProducts();
break;
......
......@@ -69,4 +69,14 @@ class RhawnRawRepositoryEloquent extends BaseRepository implements RhawnRawRepos
return $packagesList->toArray();
}
public function getProductPackagesThroughGroupByPackUnit()
{
$packages = RhawnProducts::query()
->select('p_pack','p_pack_unit')
->groupBy('p_pack','p_pack_unit')
->get();
return $packages->toArray();
}
}
......@@ -39,4 +39,9 @@ class RhawnChemicalsService
$packageList = $this->rhawnRawRepository->getProductPackage($rawIds);
return $packageList;
}
public function getProductPackagesThroughGroupByPackUnit()
{
return $this->rhawnRawRepository->getProductPackagesThroughGroupByPackUnit();
}
}
......@@ -32,19 +32,57 @@ class WuxiApiService
* @param $product
* @return bool
*/
public function pushBatchUpdateProduct($product){
public function pushBatchUpdateProduct($product)
{
$this->__checkPlatform();
try{
$params = [];
$params['chemicalProducts'] = $this->mergeApiMetaData($product);
$response = $this->getPostClient('https://api.uploadcatalog.com/api/v1/update',$params, [
$this->platformInfo['platform_params']['username'], $this->platformInfo['platform_params']['password']
]);
return $this->apiResponse($response);
}catch(\Exception $e){
return $this->requestError($e);
}
}
public function backgroundLogin()
{
$this->__checkPlatform();
$response = $this->getPostClient('https://www.uploadcatalog.com/json_login',[
'username' => $this->platformInfo['platform_params']['username'],
'password' => $this->platformInfo['platform_params']['password']
],null,[
'cookie' => 'org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=zh_CN; JSESSIONID=B2A024B5414E017F114AE4BCD29A6055'
]);
return json_decode($response,true)['token'];
}
private function __checkPlatform(){
if(!$this->platformInfo){
throw new \LogicException('第三方平台信息无法获取!',500);
}
}
public function pushBatchUpdatePackages($packages,$token)
{
$this->__checkPlatform();
try{
$params = [];
$params['chemicalProducts'] = $this->mergeApiMetaData($product);
$params['company_id'] = '6789';
$params['product_type'] = 'CHAMICAL';
$response = $this->getPostClient('https://api.uploadcatalog.com/api/v1/update',$params, [
$this->platformInfo['platform_params']['username'], $this->platformInfo['platform_params']['password']
$params = array_merge($params,$packages);
$cookie = 'org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=zh_CN;Auth-Token='.$token.';';
$response = $this->getPostClient('https://www.uploadcatalog.com/package/specification/save',$params,null, [
'cookie' => $cookie
]);
return $this->apiResponse($response);
......
......@@ -14,6 +14,7 @@ namespace App\Services;
use App\Export\BaseExport;
use App\Export\WuxiLab\WuxiLabExport;
use App\Repositories\Contracts\ThirdApiPlatformRepository;
use App\Repositories\Models\RhawnProducts;
use App\Services\Kafka\KafkaService;
use App\Services\ThirdPlatform\Api\WuxiApiService;
use App\Services\ThirdPlatform\PlatformAbstractService;
......@@ -58,15 +59,6 @@ class WuxiLabService extends PlatformAbstractService
}
}
if(!empty($rawList)){
/*if(
$this->batchUpdateApi(
['rawList' => $rawList,'packageList' => $newPackages]
)
){
//$page = intval($count / $limit) * $limit;
$page ++;
usleep(3000);
}*/
app(KafkaService::class)->produerSend(
[
'params' => ['rawList' => $rawList,'packageList' => $newPackages],
......@@ -81,6 +73,33 @@ class WuxiLabService extends PlatformAbstractService
}
}
public function batchUpdatePackagesInfo()
{
$service = app(WuxiApiService::class);
$token = $service->backgroundLogin();
$wuxiLabPackage = ['bottle','box','bp','case','ea','g','gal','hole','kg','kit','l','m','m2','mg','ml','mm','mmol','mu',
'ng','nmole','od','package','pair','piece','pmole','RL','sets','test', 'unit','vial','xa','µci','µg','µl','µmol'];
$rhawnChemicalsService = app(RhawnChemicalsService::class);
$packagesUnit = $rhawnChemicalsService->getProductPackagesThroughGroupByPackUnit();
foreach($packagesUnit as $unit){
if(in_array($unit['p_pack_unit'],$wuxiLabPackage)){
$service->pushBatchUpdatePackages([
'unit_quantity' => $unit['p_pack'], 'unit_type' => $unit['p_pack_unit'], 'unit_description' => $unit['p_pack'].$unit['p_pack_unit']
],$token);
}
}
$token = $service->pushBatchUpdatePackages([
'unit_quantity' => '10', 'unit_type' => 'g', 'unit_description' => 'g'
],$token);
}
public function batchUpdateApi($updateData)
{
$result = app(WuxiApiService::class)->pushBatchUpdateProduct($updateData);
......
......@@ -13,14 +13,9 @@ trait HttpClientHelpers
$client = app(\GuzzleHttp\Client::class);
$options = [];
if(!is_null($header)){
$options['headers'] = $header;
}
if($json) {
$options['headers'] = [
'Content-type'=> 'application/json',
"Accept" => "application/json"
'Content-Type'=> 'application/json;charset=UTF-8',
];
$options['json'] = $paramsBody;
......@@ -33,6 +28,12 @@ trait HttpClientHelpers
$options['auth'] = $auth;
}
$options['headers']['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36';
if(!is_null($header)){
$options['headers'] = array_merge($options['headers'],$header);
}
$options['debug'] = env('API_DEBUG');
$response = $client->request('post',$uri,$options);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment