process assets job

This commit is contained in:
2019-05-29 02:06:05 -05:00
parent 576ff0b407
commit 07a3edf5b4
2 changed files with 60 additions and 2 deletions

View File

@@ -42,6 +42,17 @@ class ProcessAssetsJob implements ShouldQueue
private $page; private $page;
private $esi; private $esi;
protected $location_array = [
'CorpDeliveres',
'CorpSAG1',
'CorpSAG3',
'CorpSAG4',
'CorpSAG5',
'CorpSAG6',
'CorpSAG7',
'StructureFuel',
];
/** /**
* Create a new job instance. * Create a new job instance.
* *
@@ -73,10 +84,58 @@ class ProcessAssetsJob implements ShouldQueue
$assets = $this->GePageOfAssets(); $assets = $this->GePageOfAssets();
foreach($assets as $asset) { foreach($assets as $asset) {
$found = Asset::where([
'item_id' => $asset['item_id'],
])->get();
//Update the asset if we found it, otherwise add the asset to the database
if(!$found) {
if(in_array($asset['location_flag'], $this->location_array)) {
$this->StoreNewAsset($asset);
}
} else {
$this->UpdateAsset($asset);
}
} }
} }
private function UpdateAsset($asset) {
if(isset($asset['is_blueprint_copy'])) {
Asset::where([
'item_id' => $asset['item_id'],
])->update([
'is_blueprint_copy' => $asset['is_blueprint_copy'],
]);
}
Asset::where([
'item_id' => $asset['item_id'],
])->update([
'is_singleton' => $asset['is_singleton'],
'item_id' => $asset['item_id'],
'location_flag' => $asset['location_flag'],
'location_id' => $asset['location_id'],
'location_type' => $asset['location_type'],
'quantity' => $asset['quantity'],
'type_id' => $asset['type_id'],
]);
}
private function StoreNewAsset($asset) {
$new = new Asset;
if(isset($asset['is_blueprint_copy'])) {
$new->is_blueprint_copy = $asset['is_blueprint_copy'];
}
$new->is_singleton = $asset['is_singleton'];
$new->item_id = $asset['item_id'];
$new->location_flag = $asset['location_flag'];
$new->location_id = $asset['location_id'];
$new->location_type = $asset['location_type'];
$new->quantity = $asset['quantity'];
$new->type_id = $asset['type_id'];
$new->save();
}
private function GetPageOfAssets() { private function GetPageOfAssets() {
try { try {
$assets = $this->esi->page($this->page) $assets = $this->esi->page($this->page)

View File

@@ -42,7 +42,6 @@ class ProcessStructureJob implements ShouldQueue
private $page; private $page;
private $esi; private $esi;
/** /**
* Create a new job instance. * Create a new job instance.
* *