|
|
@@ -3,10 +3,14 @@
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
use App\Services\BatchService;
|
|
|
+use App\Services\CacheService;
|
|
|
use App\Services\common\BatchUpdateService;
|
|
|
use App\Services\DocWaveHeaderService;
|
|
|
use App\Services\LogService;
|
|
|
+use App\ValueStore;
|
|
|
+use Carbon\Carbon;
|
|
|
use Illuminate\Console\Command;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class SyncBatchTask extends Command
|
|
|
{
|
|
|
@@ -28,15 +32,16 @@ class SyncBatchTask extends Command
|
|
|
|
|
|
public function handle()
|
|
|
{
|
|
|
- $this->dispose();
|
|
|
+ $this->disposeHeader();
|
|
|
+ $this->disposeDetail();
|
|
|
}
|
|
|
|
|
|
- private function dispose()
|
|
|
+ private function disposeHeader()
|
|
|
{
|
|
|
//获取更新时间与WMS数据
|
|
|
$date = $this->service->getSyncDate();
|
|
|
$waves = $this->service->get(["edittime"=>$date],["edittime"=>"gtOrEqual"]);
|
|
|
- if (!$waves)return;
|
|
|
+ if (count($waves) < 1)return;
|
|
|
|
|
|
//获取本地数据对比差异
|
|
|
$codes = array_column($waves->toArray(),"waveno");
|
|
|
@@ -84,8 +89,56 @@ class SyncBatchTask extends Command
|
|
|
$this->batchService->insert($insert);
|
|
|
LogService::log(__METHOD__,"SUCCESS-同步插入波次成功",json_encode($insert));
|
|
|
}
|
|
|
-
|
|
|
$lastDate = $waves[0]->edittime;
|
|
|
$this->service->setSyncDate($lastDate);
|
|
|
}
|
|
|
+
|
|
|
+ public function disposeDetail()
|
|
|
+ {
|
|
|
+ $date = app(CacheService::class)->getOrExecute("wave_detail_last_sync_date",function (){
|
|
|
+ $valueStore = ValueStore::query()->where("name","wave_detail_last_sync_date")->first();
|
|
|
+ return $valueStore->value ?? Carbon::now()->subSeconds(65)->toDateTimeString();
|
|
|
+ });
|
|
|
+ $sql = "SELECT WM_CONCAT(ORDERNO) orderno,WAVENO FROM DOC_WAVE_DETAILS WHERE EDITTIME > TO_DATE(?,'yyyy-mm-dd hh24:mi:ss') GROUP BY WAVENO";
|
|
|
+ $details = DB::connection("oracle")->select(DB::raw($sql),[$date]);
|
|
|
+ if (count($details) < 1)return;
|
|
|
+ $map = [];
|
|
|
+ $nos = [];
|
|
|
+ foreach ($details as $detail){
|
|
|
+ $map[$detail->waveno] = explode(",",$detail->orderno);
|
|
|
+ $nos[] = $detail->waveno;
|
|
|
+ }
|
|
|
+ $batches = $this->batchService->get(["code"=>$nos]);
|
|
|
+ foreach ($batches as $batch){
|
|
|
+ app("OrderService")->update(["code"=>$map[$batch->code]],["batch_id"=>$batch->id]);
|
|
|
+ unset($map[$batch->code]);
|
|
|
+ }
|
|
|
+ if ($map){
|
|
|
+ $waveCodes = array_keys($map);
|
|
|
+ $waves = $this->service->get(["waveno"=>$waveCodes],["waveno"=>"in"]);
|
|
|
+ $insert = [];
|
|
|
+ foreach ($waves as $wave){
|
|
|
+ $status = $wave->wavestatus == '40' ? "未处理" : ($wave->wavestatus == '90' ? '取消' : '已处理');
|
|
|
+ $owner = app("OwnerService")->codeGetOwner($wave->customerid);
|
|
|
+ $insert[] = [
|
|
|
+ "code" => $wave->waveno,
|
|
|
+ "status" => $status,
|
|
|
+ "remark"=>$wave->descr,
|
|
|
+ "created_at"=>$wave->addtime,
|
|
|
+ "updated_at"=>$wave->edittime,
|
|
|
+ "owner_id"=>$owner->id,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($insert){
|
|
|
+ $this->batchService->insert($insert);
|
|
|
+ LogService::log(__METHOD__,"SUCCESS-同步插入波次成功",json_encode($insert));
|
|
|
+ $batches = $this->batchService->get(["code"=>$waveCodes]);
|
|
|
+ foreach ($batches as $batch){
|
|
|
+ app("OrderService")->update(["code"=>$map[$batch->code]],["batch_id"=>$batch->id]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ValueStore::query()->where("name","wave_last_sync_date")->update(["value"=>Carbon::now()->subSeconds(1)->toDateTimeString()]);
|
|
|
+ }
|
|
|
}
|