EventOverviewService.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace common\services;
  3. use common\components\AjaxException;
  4. use common\models\EventOverview;
  5. use yii\db\ActiveQuery;
  6. class EventOverviewService
  7. {
  8. /**
  9. * @param $id
  10. * @return EventOverview
  11. * @throws AjaxException
  12. */
  13. public static function getEventOverviewById($id): EventOverview
  14. {
  15. /** @var EventOverview $EventOverview */
  16. $EventOverview = EventOverview::find()->where(["delete_time" => 0, "id" => $id])->one();
  17. if (!$EventOverview) {
  18. throw new AjaxException("该事件概览不存在!");
  19. }
  20. return $EventOverview;
  21. }
  22. /**
  23. * @return ActiveQuery
  24. */
  25. public static function getEventOverviewQuery(): ActiveQuery
  26. {
  27. return EventOverview::find()->where(["delete_time" => 0]);
  28. }
  29. /**
  30. * 通过案例ID删除应急处置
  31. * @param $accident_id
  32. */
  33. public static function deleteByAccidentCasesId($accident_id): void
  34. {
  35. EventOverview::updateAll(["delete_time" => time()], ["accident_id" => $accident_id]);
  36. }
  37. public static function dealWithList($data, $accident_id)
  38. {
  39. $sourceDataList = array_column(EventSourceDataService::getSourceDataListByAccidentId($accident_id), null, "id");
  40. /** @var EventOverview[] $data */
  41. foreach ($data as $value) {
  42. //将数组从json转化出来
  43. OperationalAdjustmentsService::dealWithSourceData($value, $sourceDataList);
  44. if ($value->end_time == 0) {
  45. $value->end_time = "";
  46. }
  47. }
  48. return $data;
  49. }
  50. }