Zhouzhendong пре 5 година
родитељ
комит
0dd8e35bd4

+ 51 - 0
app/Console/Commands/CreateWeightStatistic.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Order;
+use App\OrderBin;
+use App\OrderPackageCountingRecord;
+use App\Services\BatchService;
+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\Cache;
+use Illuminate\Support\Facades\DB;
+
+class CreateWeightStatistic extends Command
+{
+    protected $signature = 'create:weightStatistic';
+
+    protected $description = 'every day create weight statistic data';
+
+    public function handle()
+    {
+        $yesterday = date("Y-m-d",strtotime("-1 day"));
+        $sql = <<<sql
+SELECT DATE_FORMAT(created_at,'%Y-%m-%d') date,
+SUM(CASE WHEN weighed_at IS NULL THEN 1 ELSE 0 END) AS count,
+COUNT(1) total FROM order_packages WHERE created_at BETWEEN '{$yesterday} 00:00:00' AND '{$yesterday} 23:59:59' GROUP BY date
+sql;
+        $result = DB::selectOne(DB::raw($sql));
+        if (!$result)$obj = [
+            "targeted_at"    => $yesterday,
+            "un_weigh_count" => 0,
+            "total_count"    => 0
+        ]; else $obj = [
+            "targeted_at"    => $result->date,
+            "un_weigh_count" => $result->count,
+            "total_count"    => $result->total,
+        ];
+        /** @var \stdClass $model */
+        $model = OrderPackageCountingRecord::query()->create($obj);
+        Cache::put("weight.".$yesterday,[
+            "date"=>$yesterday,
+            "total"=>$model->total_count,
+            "count"=>$model->un_weigh_count,
+            "value"=>$model->total_count ? round($model->un_weigh_count/$model->total_count,2)*100 : 0
+        ]);
+    }
+}

+ 3 - 0
app/Console/Kernel.php

@@ -3,6 +3,7 @@
 namespace App\Console;
 
 use App\Console\Commands\ClearCancelledOrderTask;
+use App\Console\Commands\CreateWeightStatistic;
 use App\Console\Commands\FluxOrderFix;
 use App\Console\Commands\InventoryDailyLoggingOwner;
 use App\Console\Commands\LogExpireDelete;
@@ -42,6 +43,7 @@ class Kernel extends ConsoleKernel
         SyncWmsCommoditiesInformation::class,
         ClearCancelledOrderTask::class,
         WasSyncWmsAsnInformation::class,
+        CreateWeightStatistic::class,
     ];
 
     /**
@@ -66,6 +68,7 @@ class Kernel extends ConsoleKernel
         $schedule->command('SyncWmsCommoditiesInformation')->everyMinute();
         $schedule->command('clear:cancelledOrder')->everyTenMinutes();
         $schedule->command('WasSyncWmsAsnInformation')->everyMinute();
+        $schedule->command('create:weightStatistic')->dailyAt("00:30");
     }
 
     /**

+ 68 - 9
app/Http/Controllers/ControlPanelController.php

@@ -3,7 +3,9 @@
 namespace App\Http\Controllers;
 
 use App\Components\AsyncResponse;
+use App\OrderPackageCountingRecord;
 use App\Owner;
+use App\Services\CacheService;
 use App\Services\CheckActiveMenuService;
 use App\Services\LaborReportsCountingRecordService;
 use App\Services\NewOrderCountingRecordService;
@@ -11,6 +13,7 @@ use App\Services\RealtimePendingOrdersService;
 use App\Services\UserService;
 use App\User;
 use Carbon\Carbon;
+use Carbon\CarbonPeriod;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cache;
@@ -134,16 +137,72 @@ class ControlPanelController extends Controller
         });
     }
 
+    /**
+     * 获取称重统计数据API
+     */
     public function weightApi()
     {
-        $ownerIds = app("UserService")->getPermittingOwnerIds(Auth::user());
-        if (!$ownerIds)$this->success();
-
-        $start = request("start");
-        $end   = request("end");
-        
-        //是否包含当天
-        //天 周 月 年
-        //缓存优先级-》缓存失效策略
+        //转化为Carbon
+        $start = Carbon::parse(request("start"));
+        $end   = Carbon::parse(request("end"));
+
+        //定义三个数组 空间换时间 避免结果集二次转换
+        $title = []; //标题
+        $data = []; //核心数据,二维数组
+        foreach (CarbonPeriod::create($start,$end) as $date){
+            /** @var $date Carbon */
+            $str = $date->format("Y-m-d");
+            $data[] = $this->getTargetData($str);
+            $title[] = $str;
+        }
+
+        //大于31天转换为月份显示
+        if ($end->diffInDays($start) > 31){
+            $title = [];
+            $sign = []; //标记是否已被插入
+            $dataTemp = []; //临时存储
+
+            foreach ($data as $datum){
+                $month = substr($datum["date"],0,7);
+                if (!isset($sign[$month])){
+                    $dataTemp[] = ["date"=>$month,"total"=>$datum["total"],"count"=>$datum["count"],"value"=>$datum["value"]];
+                    $title[] = $month;
+                    $sign[$month] = count($dataTemp)-1;
+                }else{
+                    $dataTemp[$sign[$month]]["total"] += $datum["total"];
+                    $dataTemp[$sign[$month]]["count"] += $datum["count"];
+                    $dataTemp[$sign[$month]]["value"] = $dataTemp[$sign[$month]]["total"] ?
+                        round($dataTemp[$sign[$month]]["count"]/$dataTemp[$sign[$month]]["total"],2)*100 : 0;
+                }
+            }
+            $data = $dataTemp;
+        }
+        $this->success(["title"=>$title,"data"=>$data]);
+    }
+
+    /**
+     * 根据指定日期获取目标统计数据
+     *
+     * @param string $date
+     * @return array|null
+     */
+    private function getTargetData(string $date)
+    {
+        if ($date == date("Y-m-d")){
+            $sql = <<<sql
+SELECT DATE_FORMAT(created_at,'%Y-%m-%d') date,
+SUM(CASE WHEN weighed_at IS NULL THEN 1 ELSE 0 END) AS count,
+COUNT(1) total FROM order_packages WHERE created_at >= '{$date} 00:00:00' GROUP BY date
+sql;
+
+            $pack = DB::selectOne(DB::raw($sql));
+            if (!$pack)return ["date"=>$date,"total"=>0,"count"=>0,"value"=>0];
+            return ["date"=>$pack->date,"total"=>$pack->total,"count"=>$pack->count,"value"=>round($pack->count/$pack->total,2)*100];
+        }
+        return app(CacheService::class)->getOrExecute("weight.".$date,function ()use($date){
+            $count = OrderPackageCountingRecord::query()->where("targeted_at",$date)->first();
+            if (!$count)return ["date"=>$date,"total"=>0,"count"=>0,"value"=>0];
+            return ["date"=>$count->targeted_at,"total"=>$count->total_count,"count"=>$count->un_weigh_count,"value"=>$count->total_count ? round($count->un_weigh_count/$count->total_count,2)*100 : 0];
+        },config("cache.expirations.forever"));
     }
 }

+ 28 - 53
app/Http/Controllers/TestController.php

@@ -44,6 +44,7 @@ use App\OrderCommodity;
 use App\OrderIssue;
 use App\OrderPackage;
 use App\OrderPackageCommodities;
+use App\OrderPackageCountingRecord;
 use App\OrderTracking;
 use App\Owner;
 use App\OwnerPriceOperation;
@@ -93,6 +94,7 @@ use App\Warehouse;
 use App\Waybill;
 use App\WaybillPriceModel;
 use Carbon\Carbon;
+use Carbon\CarbonPeriod;
 use ChangeColumnOrderIdToOrderIssues;
 use Doctrine\DBAL\Query\QueryBuilder;
 use Illuminate\Database\Eloquent\Builder;
@@ -126,61 +128,34 @@ class TestController extends Controller
         return call_user_func([$this, $method], $request);
     }
 
-    public function updateInventory()
+    public function syncWeight()
     {
-        $inventoryAccounts = InventoryAccount::query()->get();
-        $updateParams = [[
-            'id', 'processed', 'ignored', 'updated_at'
-        ]];
-        $updated_at = Carbon::now()->toDateTimeString();
-        foreach ($inventoryAccounts as $inventoryAccount) {
-            if ($inventoryAccount->getIgnoredAmount() > 0) {
-                $updateParams[] = [
-                    'id' => $inventoryAccount->id,
-                    'processed' => $inventoryAccount->getProcessedAmount(),
-                    'ignored' => $inventoryAccount->getIgnoredAmount(),
-                    'updated_at' => $updated_at,
-                ];
-            }
-        }
-        if (count($updateParams) > 1) {
-            app(BatchUpdateService::class)->batchUpdate('inventory_accounts', $updateParams);
-        }
-    }
-    public function disposeDetail($date = null)
-    {
-        DB::transaction(function ()use($date){
-            if (!$date){
-                $valueStore = ValueStore::query()->where("name","wave_detail_last_sync_date")->lockForUpdate()->first();
-                $date = $valueStore->value ?? Carbon::now()->subSeconds(65)->toDateTimeString();
-            }
-            $count = DB::connection("oracle")->selectOne(DB::raw("SELECT count(*) count FROM DOC_WAVE_DETAILS WHERE EDITTIME >= TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')"),[$date]);
-            if ($count->count > 1000){
-                $sql = <<<sql
-    SELECT * FROM (SELECT ORDERNO,WAVENO,SEQNO,EDITTIME, ROWNUM AS rowno FROM (
-    SELECT * FROM DOC_WAVE_DETAILS WHERE EDITTIME >= TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')
- ORDER BY EDITTIME) WHERE ROWNUM <= 1000)wave WHERE wave.rowno >= 0
+        foreach (CarbonPeriod::create("2020-12-01","2021-01-25") as $date){
+            /** @var $date Carbon */
+            $yesterday = $date->format("Y-m-d");
+            $sql = <<<sql
+SELECT DATE_FORMAT(created_at,'%Y-%m-%d') date,
+SUM(CASE WHEN weighed_at IS NULL THEN 1 ELSE 0 END) AS count,
+COUNT(1) total FROM order_packages WHERE created_at BETWEEN '{$yesterday} 00:00:00' AND '{$yesterday} 23:59:59' GROUP BY date
 sql;
-                $details = DB::connection("oracle")->select(DB::raw($sql),[$date]);
-                //$this->detailExe($details);
-                $this->disposeDetail($details[count($details)-1]->edittime);dump($details[count($details)-1]->edittime);
-            }else{
-                $sql = "SELECT ORDERNO,WAVENO,SEQNO FROM DOC_WAVE_DETAILS WHERE EDITTIME >= TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')";
-                $details = DB::connection("oracle")->select(DB::raw($sql),[$date]);dd($details ? $details[count($details)-1]->edittime : Carbon::now()->toDateTimeString());
-                //$this->detailExe($details);
-                //ValueStore::query()->where("name","wave_detail_last_sync_date")->update(["value"=>$details ? $details[count($details)-1]->edittime : Carbon::now()->toDateTimeString()]);
-            }
-        });
-    }
-    public function test1(){
-        $cities = City::query()->with("province")->where("province_id","!=",0)->get();
-        foreach ($cities as $city){
-            if ($city->name=='汕头/汕尾'){
-                app("RegionService")->getCity("汕头",$city->province->name);
-                app("RegionService")->getCity("汕尾",$city->province->name);
-                continue;
-            }
-            app("RegionService")->getCity($city->name,$city->province->name);
+            $result = DB::selectOne(DB::raw($sql));
+            if (!$result)$obj = [
+                "targeted_at"    => $yesterday,
+                "un_weigh_count" => 0,
+                "total_count"    => 0
+            ]; else $obj = [
+                "targeted_at"    => $result->date,
+                "un_weigh_count" => $result->count,
+                "total_count"    => $result->total,
+            ];
+            /** @var \stdClass $model */
+            $model = OrderPackageCountingRecord::query()->create($obj);
+            Cache::put("weight.".$yesterday,[
+                "date"=>$yesterday,
+                "total"=>$model->total_count,
+                "count"=>$model->un_weigh_count,
+                "value"=>$model->total_count ? round($model->un_weigh_count/$model->total_count,2)*100 : 0
+            ]);
         }
     }
 

+ 86 - 11
resources/views/control/panel.blade.php

@@ -347,12 +347,23 @@
                 @endcan
             </div>
             <div class="row my-3">
-                <div class="col-6 card">
-                    <div class="card-header">
-
-                    </div>
-                    <div class="card-body">
-                        <div id="weight"></div>
+                <div class="col-6">
+                    <div class="card">
+                        <div class="card-header">
+                            <div class="row">
+                                <el-date-picker size="small" class="col-6 date" @blur="loadWeightInfo()" type="daterange" align="right"
+                                                v-model="searchOption.weightDate" unlink-panels range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
+                                </el-date-picker>
+                                <label class="col-3 offset-3">
+                                    <select class="form-control rounded" v-model="searchOption.weightSelect" @change="switchWeightDate()">
+                                        <option v-for="(date,i) in dateOptions" :value="i">@{{ date.text }}</option>
+                                    </select>
+                                </label>
+                            </div>
+                        </div>
+                        <div class="card-body row">
+                            <div id="weight" class="col-12" style="min-height: 500px"></div>
+                        </div>
                     </div>
                 </div>
             </div>
@@ -419,6 +430,16 @@
                         }
                     }]
                 },
+                dateOptions:[{text:'当天',start:moment().format('yyyy-MM-DD'),end:moment().format('yyyy-MM-DD')},
+                    {text:"昨天",start:moment().subtract("1","day").format('yyyy-MM-DD'),end:moment().subtract("1","day").format('yyyy-MM-DD')},
+                    {text:"本周",start:moment().weekday(1).format('yyyy-MM-DD'),end:moment().weekday(7).format('yyyy-MM-DD')},
+                    {text:"上周",start:moment().weekday(-6).format('yyyy-MM-DD'),end:moment().weekday(0).format('yyyy-MM-DD')},
+                    {text:"本月",start:moment().startOf("month").format('yyyy-MM-DD'),end:moment().endOf("month").format('yyyy-MM-DD')},
+                    {text:"上月",start:moment().month(moment().month() - 1).startOf('month').format('yyyy-MM-DD'),end:moment().month(moment().month() - 1).endOf('month').format('yyyy-MM-DD')},
+                    {text:"本季度",start:moment(moment().quarter(moment().quarter()).startOf('quarter').valueOf()).format('yyyy-MM-DD'),end:moment(moment().quarter(moment().quarter()).endOf('quarter').valueOf()).format('yyyy-MM-DD')},
+                    {text:"上季度",start:moment(moment().quarter(moment().quarter() - 1).startOf('quarter').valueOf()).format('yyyy-MM-DD'),end:moment(moment().quarter(moment().quarter() - 1).endOf('quarter').valueOf()).format('yyyy-MM-DD')},
+                    {text:"本年",start:moment(moment().year(moment().year()).startOf('year').valueOf()).format('yyyy-MM-DD'),end:moment(moment().year(moment().year()).endOf('year').valueOf()).format('yyyy-MM-DD')},
+                    {text:"去年",start:moment(moment().year(moment().year() - 1).startOf('year').valueOf()).format('yyyy-MM-DD'),end:moment(moment().year(moment().year() - 1).endOf('year').valueOf()).format('yyyy-MM-DD')}],
                 logisticsCountingRecordsData: [moment().subtract('1', 'month').format('yyyy-MM-DD'),
                     moment(new Date()).format('yyyy-MM-DD')],
                 warehouseCountingRecordsData: [moment().subtract('1', 'month').format('yyyy-MM-DD'),
@@ -464,7 +485,11 @@
                 laborReportsCountingRecordsYearShow: false,
                 laborReportsCountingRecordsStart: moment().subtract('1', 'month').format('yyyy-MM-DD'),
                 laborReportsCountingRecordsEnd: moment(new Date()).format('yyyy-MM-DD'),
-                load:{},
+                cardPool:{},
+                searchOption:{
+                    weightDate:[],
+                    weightSelect:"",
+                },
             },
             watch:{
                 selectOrderOwners:function(val,oldval){
@@ -485,6 +510,8 @@
                 }
             },
             mounted: function () {
+                this.searchOption.weightSelect = 5;
+                this.searchOption.weightDate = [this.dateOptions[5].start,this.dateOptions[5].end];
                 $('#list').removeClass('d-none');
                 let _this = this;
                 this.warehouses = {
@@ -517,6 +544,8 @@
                 this.laborReportsUserGroupsCountChart = echarts.init(document.getElementById('laborReportsUserGroupsCount'));
                 this.initLaborReportsUserGroupsCountChart();
 
+                this.cardPool.weight = echarts.init(document.getElementById("weight"));
+                this.loadWeightInfo();
             },
             methods: {
                 switchDataPanel_forOrderCountingRecords(fromUnit, toUnit) {
@@ -855,10 +884,56 @@
                     });
                 },
                 loadWeightInfo(){
-                    this.$set(this.load,"weight",true);
-                    /*window.tempTip.postBasicRequest("{{url('apiLocal/control/panel/menu/weightApi')}}",{},res=>{
-
-                    });*/
+                    window.tempTip.setDuration(3000);
+                    if (!this.searchOption.weightDate[0]){
+                        window.tempTip.show("开始时间未选择");
+                        return;
+                    }
+                    if (!this.searchOption.weightDate[1]){
+                        window.tempTip.show("结束时间未选择");
+                        return;
+                    }
+                    this.cardPool.weight.showLoading('default',{text:"加 载 中",color:'#C0C0C0'});
+                    let url = "{{url('apiLocal/control/panel/menu/weightApi')}}";
+                    let params = {start:this.searchOption.weightDate[0],end:this.searchOption.weightDate[1]};
+                    window.tempTip.postBasicRequest(url,params,res=>{
+                        this.cardPool.weight.hideLoading();
+                        this.cardPool.weight.setOption(this._setWeightData(res.title,res.data));
+                    });
+                },
+                switchWeightDate(){
+                    let obj = this.dateOptions[this.searchOption.weightSelect];
+                    this.searchOption.weightDate = [obj.start,obj.end];
+                    this.loadWeightInfo();
+                },
+                _setWeightData(title, data){
+                    return {
+                        tooltip: {
+                            trigger: 'item',
+                            formatter: function (params) {
+                                return params.data.date+"<br>"+"总量:<span class='text-success font-weight-bold'>"+params.data.total+"</span><br>"+"未称:<span class='text-info font-weight-bold'>"+params.data.count+"</span>";
+                            }
+                        }, xAxis: {
+                            data: title
+                        }, yAxis: {
+                            axisLabel: {
+                                show: true,
+                                interval: 'auto',
+                                formatter: '{value} %'
+                            },
+                        }, label:{
+                            show:true,
+                            position: 'top',
+                            formatter: '{c}%',
+                            color:"red"
+                        }, series: [{
+                            type: "bar",
+                            data: data,
+                            itemStyle:{
+                                color:"RGB(62,157,231)",
+                            }
+                        }]
+                    };
                 },
             }
         });

+ 45 - 0
serves/excelExportGo/logs/2021-01-25.log

@@ -0,0 +1,45 @@
+
+[ERROR]   17:36:23
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:23
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:27
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:27
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:47
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:48
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:50
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:50
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:51
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:51
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:52
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:52
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:53
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:53
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:53
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:53
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:54
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:54
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:54
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:54
+   /excel/export.go:30  设置换行格式失败!
+[ERROR]   17:36:57
+   /api/controller/controller.go:18   参数解析失败!
+[ERROR]   17:36:57
+   /excel/export.go:30  设置换行格式失败!