|
@@ -64,25 +64,21 @@ class Asset extends Model
|
|
|
//获取子级需求数量
|
|
|
public function getTotalRequirementsCountAttribute()
|
|
|
{
|
|
|
- $totalRequirementsCount = $this->requirements()->count(); // 当前资产的需求数量
|
|
|
-
|
|
|
- foreach ($this->children as $child) {
|
|
|
- $totalRequirementsCount += $child->getTotalRequirementsCountAttribute(); // 递归调用子资产的方法
|
|
|
- }
|
|
|
-
|
|
|
- return $totalRequirementsCount;
|
|
|
+ $childIds = [];
|
|
|
+ Asset::where('path','like','%,'.$this->id.',%')->get('id')->each(function ($id)use (&$childIds){
|
|
|
+ $childIds[]=$id['id'];
|
|
|
+ });
|
|
|
+ return Requirement::whereIn('asset_id',$childIds)->count();
|
|
|
}
|
|
|
|
|
|
//获取子级计划数量
|
|
|
public function getTotalPlansCountAttribute()
|
|
|
{
|
|
|
- $totalPlansCount = $this->plans()->count(); // 当前资产的需求数量
|
|
|
-
|
|
|
- foreach ($this->children as $child) {
|
|
|
- $totalPlansCount += $child->getTotalPlansCountAttribute(); // 递归调用子资产的方法
|
|
|
- }
|
|
|
-
|
|
|
- return $totalPlansCount;
|
|
|
+ $childIds = [];
|
|
|
+ Asset::where('path','like','%,'.$this->id.',%')->get('id')->each(function ($id)use (&$childIds){
|
|
|
+ $childIds[]=$id['id'];
|
|
|
+ });
|
|
|
+ return Plan::whereIn('asset_id',$childIds)->count();
|
|
|
}
|
|
|
|
|
|
public function library(){
|