|
|
@@ -2,42 +2,88 @@
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
+use App\Services\BatchService;
|
|
|
+use App\Services\common\BatchUpdateService;
|
|
|
use App\Services\DocWaveHeaderService;
|
|
|
+use App\Services\LogService;
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
class SyncBatchTask extends Command
|
|
|
{
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- */
|
|
|
protected $signature = 'sync:batch';
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- */
|
|
|
protected $description = 'sync wms batch task';
|
|
|
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
+ /** @var DocWaveHeaderService $service */
|
|
|
+ private $service;
|
|
|
+ /** @var BatchService $batchService */
|
|
|
+ private $batchService;
|
|
|
+
|
|
|
public function __construct()
|
|
|
{
|
|
|
parent::__construct();
|
|
|
+ $this->service = app(DocWaveHeaderService::class);
|
|
|
+ $this->batchService = app(BatchService::class);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Execute the console command.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
public function handle()
|
|
|
{
|
|
|
- /** @var DocWaveHeaderService $service */
|
|
|
- $service = app(DocWaveHeaderService::class);
|
|
|
- $date = $service->getSyncDate();
|
|
|
- $flux = $service->get(["edittime"=>$date],["edittime"=>"gtOrEqual"]);
|
|
|
- if (!$flux)return;
|
|
|
+ $this->dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ private function dispose()
|
|
|
+ {
|
|
|
+ //获取更新时间与WMS数据
|
|
|
+ $date = $this->service->getSyncDate();
|
|
|
+ $waves = $this->service->get(["edittime"=>$date],["edittime"=>"gtOrEqual"]);
|
|
|
+ if (!$waves)return;
|
|
|
+
|
|
|
+ //获取本地数据对比差异
|
|
|
+ $codes = array_column($waves->toArray(),"waveno");
|
|
|
+ $map = [];
|
|
|
+ $batches = $this->batchService->get(["code"=>$codes]);
|
|
|
+ if ($batches){
|
|
|
+ foreach ($batches as $batch)$map[$batch->code] = $batch->id;
|
|
|
+ }
|
|
|
+ $update = [["id","status","remark","updated_at"]];
|
|
|
+ $insert = [];
|
|
|
+ foreach ($waves as $wave){
|
|
|
+ $status = $wave->wavestatus == '40' ? "未处理" : ($wave->wavestatus == '90' ? '取消' : '已处理');
|
|
|
+ if (isset($map[$wave->waveno])){
|
|
|
+ $update[] = [
|
|
|
+ "id" => $map[$wave->waveno],
|
|
|
+ "status" => $status,
|
|
|
+ "remark"=>$wave->descr,
|
|
|
+ "updated_at"=>$wave->edittime,
|
|
|
+ ];
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $insert[] = [
|
|
|
+ "code" => $wave->waveno,
|
|
|
+ "status" => $status,
|
|
|
+ "remark"=>$wave->descr,
|
|
|
+ "created_at"=>$wave->addtime,
|
|
|
+ "updated_at"=>$wave->edittime,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ //存在则更新
|
|
|
+ if (count($update)>1){
|
|
|
+ $bool = app(BatchUpdateService::class)->batchUpdate("batches",$update);
|
|
|
+ if ($bool)LogService::log(__METHOD__,"SUCCESS-同步更新波次成功",json_encode($update));
|
|
|
+ else{
|
|
|
+ LogService::log(__METHOD__,"ERROR-同步更新波次失败",json_encode($update));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //不存在则录入
|
|
|
+ if ($insert){
|
|
|
+ $this->batchService->insert($insert);
|
|
|
+ LogService::log(__METHOD__,"SUCCESS-同步插入波次成功",json_encode($insert));
|
|
|
+ }
|
|
|
|
|
|
+ $lastDate = $waves[0]->edittime;
|
|
|
+ $this->service->setSyncDate($lastDate);
|
|
|
}
|
|
|
}
|