EmergencyResponseService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace common\services;
  3. use common\components\AjaxException;
  4. use common\models\EmergencyResponse;
  5. use common\util\EmergencyResponseDimensionObj;
  6. use common\util\EmergencyResponseObj;
  7. use yii\db\ActiveQuery;
  8. class EmergencyResponseService
  9. {
  10. /**
  11. * @param $id
  12. * @return EmergencyResponse
  13. * @throws AjaxException
  14. */
  15. public static function getEmergencyResponseById($id): EmergencyResponse
  16. {
  17. /** @var EmergencyResponse $EmergencyResponse */
  18. $EmergencyResponse = EmergencyResponse::find()->where(["delete_time" => 0, "id" => $id])->one();
  19. if (!$EmergencyResponse) {
  20. throw new AjaxException("该应急处置不存在!");
  21. }
  22. return $EmergencyResponse;
  23. }
  24. /**
  25. * @return ActiveQuery
  26. */
  27. public static function getEmergencyResponseQuery(): ActiveQuery
  28. {
  29. return EmergencyResponse::find()->where(["delete_time" => 0]);
  30. }
  31. /**
  32. * 通过案例ID删除应急处置
  33. * @param $accident_id
  34. */
  35. public static function deleteByAccidentCasesId($accident_id): void
  36. {
  37. EmergencyResponse::updateAll(["delete_time" => time()], ["accident_id" => $accident_id]);
  38. }
  39. /**
  40. * @param $data
  41. * @param $accident_id
  42. * @return array
  43. */
  44. public static function dealWithList($data, $accident_id): array
  45. {
  46. return OperationalAdjustmentsService::dealWithList($data, $accident_id);
  47. }
  48. public static function listAddDimension($data): void
  49. {
  50. $EmergencyResponseIdList = [];
  51. foreach ($data as $value) {
  52. $EmergencyResponseIdList[] = $value->id;
  53. }
  54. $newEmergencyResponseDimensionList = [];
  55. $EmergencyResponseDimensionList = EmergencyResponseDimensionService::getListByEmergencyResponseId($EmergencyResponseIdList);
  56. foreach ($EmergencyResponseDimensionList as $EmergencyResponseDimension) {
  57. $newEmergencyResponseDimensionList[$EmergencyResponseDimension->emergency_response_id][] = new EmergencyResponseDimensionObj($EmergencyResponseDimension);
  58. }
  59. foreach ($data as $value) {
  60. $value->dimension = $newEmergencyResponseDimensionList[$value->id];
  61. }
  62. }
  63. public static function getEmergencyResponseObjList($list)
  64. {
  65. $data = [];
  66. foreach ($list as $value) {
  67. $data[] = new EmergencyResponseObj($value);;
  68. }
  69. return $data;
  70. }
  71. }