OperationalAdjustmentsService.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace common\services;
  3. use common\components\AjaxException;
  4. use common\models\EmergencyResponse;
  5. use common\models\OperationalAdjustments;
  6. use common\util\EmergencyResponseDimensionObj;
  7. use Exception;
  8. use yii\db\ActiveQuery;
  9. class OperationalAdjustmentsService
  10. {
  11. /**
  12. * @param $id
  13. * @return OperationalAdjustments
  14. * @throws AjaxException
  15. */
  16. public static function getOperationalAdjustmentsById($id)
  17. {
  18. /** @var OperationalAdjustments $OperationalAdjustments */
  19. $OperationalAdjustments = OperationalAdjustments::find()->where(["delete_time" => 0, "id" => $id])->one();
  20. if (!$OperationalAdjustments) {
  21. throw new AjaxException("该运营调整不存在!");
  22. }
  23. return $OperationalAdjustments;
  24. }
  25. /**
  26. * @return ActiveQuery
  27. */
  28. public static function getQuery(): ActiveQuery
  29. {
  30. return OperationalAdjustments::find()->where(["delete_time" => 0]);
  31. }
  32. /**
  33. * 通过案例ID删除应急处置
  34. * @param $accident_id
  35. */
  36. public static function deleteByAccidentCasesId($accident_id): void
  37. {
  38. OperationalAdjustments::updateAll(["delete_time" => time()], ["accident_id" => $accident_id]);
  39. }
  40. /**
  41. * @param $data
  42. * @param $accident_id
  43. * @return array
  44. */
  45. public static function dealWithList($data, $accident_id): array
  46. {
  47. $sourceDataList = array_column(EventSourceDataService::getSourceDataListByAccidentId($accident_id), null, "id");
  48. /** @var EmergencyResponse[]|OperationalAdjustments[] $data */
  49. foreach ($data as $value) {
  50. //将数组从json转化出来
  51. self::dealWithRules($value);
  52. self::dealWithSourceData($value, $sourceDataList);
  53. if ($value->end_time == 0) {
  54. $value->end_time = "";
  55. }
  56. }
  57. return $data;
  58. }
  59. public static function listAddDimension($data): void
  60. {
  61. $OperationalAdjustmentsIdList = [];
  62. foreach ($data as $value) {
  63. $OperationalAdjustmentsIdList[] = $value->id;
  64. }
  65. $newOperationalAdjustmentsDimensionList = [];
  66. $OperationalAdjustmentsDimensionList = OperationalAdjustmentsDimensionService::getListByOperationalAdjustmentsId($OperationalAdjustmentsIdList);
  67. foreach ($OperationalAdjustmentsDimensionList as $OperationalAdjustmentsDimension) {
  68. $newOperationalAdjustmentsDimensionList[$OperationalAdjustmentsDimension->operational_adjustments_id][] = new EmergencyResponseDimensionObj($OperationalAdjustmentsDimension);
  69. }
  70. foreach ($data as $value) {
  71. $value->dimension = $newOperationalAdjustmentsDimensionList[$value->id];
  72. }
  73. }
  74. public static function dealWithRules($model)
  75. {
  76. $model->rules = json_decode($model->rules, true);
  77. }
  78. public static function dealWithSourceData($model, $sourceDataList)
  79. {
  80. $sourceDataIdList = json_decode($model->source_data, true);
  81. $sourceDataObj = [];
  82. foreach ($sourceDataIdList as $sourceDataId) {
  83. if (isset($sourceDataList[$sourceDataId])) {
  84. $sourceDataObj[] = $sourceDataList[$sourceDataId];
  85. }
  86. }
  87. $model->source_data = $sourceDataObj;
  88. }
  89. }