|
|
@@ -6,25 +6,27 @@ namespace App\Services;
|
|
|
|
|
|
use App\LaborReport;
|
|
|
use Carbon\Carbon;
|
|
|
-use DateTime;
|
|
|
-use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Str;
|
|
|
-use Ramsey\Uuid\Type\Integer;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
|
|
|
|
|
|
class LaborReportsCountingRecordService
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
- protected $modelClass=LaborReportsCountingRecord::class;
|
|
|
+
|
|
|
+ private $ttl;
|
|
|
+
|
|
|
public function __construct(LaborReport $laborReport)
|
|
|
{
|
|
|
+ $this->ttl = config('cache.expirations.commonFrequent');
|
|
|
$laborReport::$withoutAppends = false;
|
|
|
}
|
|
|
+
|
|
|
public function userGroupsCount($start, $end)
|
|
|
{
|
|
|
- $resultByCache = Cache::remember('userGroupsCount_' . $start . '_' . $end, 600, function () use ($start, $end) {
|
|
|
+
|
|
|
+ $resultByCache = Cache::remember('userGroupsCount_' . $start . '_' . $end, $this->ttl, function () use ($start, $end) {
|
|
|
return LaborReport::query()->selectRaw('user_workgroup_id,count(user_workgroup_id) amount')
|
|
|
->with('userWorkgroup', 'laborReportStatus')
|
|
|
->whereDate('created_at', '>=', $start)
|
|
|
@@ -103,7 +105,7 @@ class LaborReportsCountingRecordService
|
|
|
break;
|
|
|
case '年';
|
|
|
foreach (Carbon::parse($start)->yearsUntil($end, 1)->toArray() as $item) {
|
|
|
- $dataArray[] = $item->year.'';
|
|
|
+ $dataArray[] = $item->year . '';
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
@@ -127,7 +129,7 @@ class LaborReportsCountingRecordService
|
|
|
$dataList->each(function ($item) use ($unit) {
|
|
|
$date = $item->date_target;
|
|
|
$key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
|
|
|
- Cache::put($key, $item);
|
|
|
+ Cache::put($key, $item, $this->ttl);
|
|
|
});
|
|
|
break;
|
|
|
case '月':
|
|
|
@@ -143,7 +145,7 @@ class LaborReportsCountingRecordService
|
|
|
$dataList->each(function ($item) use ($unit) {
|
|
|
$date = $item->date_target;
|
|
|
$key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
|
|
|
- Cache::put($key, $item);
|
|
|
+ Cache::put($key, $item, $this->ttl);
|
|
|
});
|
|
|
break;
|
|
|
case '年':
|
|
|
@@ -158,7 +160,7 @@ class LaborReportsCountingRecordService
|
|
|
$dataList->each(function ($item) use ($unit) {
|
|
|
$date = $item->date_target;
|
|
|
$key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
|
|
|
- Cache::put($key, $item);
|
|
|
+ Cache::put($key, $item, $this->ttl);
|
|
|
});
|
|
|
break;
|
|
|
default:
|