CaseController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <?php
  2. namespace frontend\modules\api\controllers;
  3. use common\models\AccidentCasesRelateToDictionary;
  4. use common\models\AccidentCasesStudy;
  5. use common\models\Dictionary;
  6. use common\models\EmergencyResponseRelateToRulesPoints;
  7. use common\models\OperationalAdjustmentsRelateToRulesPoints;
  8. use common\models\SearchHistory;
  9. use common\services\AdminLogService;
  10. use common\services\CaseService;
  11. use common\services\EmergencyResponseService;
  12. use common\services\EventOverviewService;
  13. use common\services\OperationalAdjustmentsService;
  14. use common\services\RulesPointsService;
  15. use common\services\RulesService;
  16. use Exception;
  17. use frontend\modules\api\components\BaseAdminController;
  18. use Yii;
  19. use yii\base\InvalidConfigException;
  20. use yii\web\Response;
  21. class CaseController extends BaseAdminController
  22. {
  23. /**
  24. * 搜索历史
  25. * @return Response
  26. */
  27. public function actionSearchHistory()
  28. {
  29. $SearchHistoryList = SearchHistory::find()->where(["uid" => $this->uid])->orderBy("update_time desc")->asArray()->limit(10)->all();
  30. if (isset($SearchHistoryList[9])) {
  31. //个人历史记录超过10条,就删掉
  32. SearchHistory::deleteAll(["and", ["uid" => $this->uid], ["<", "update_time", $SearchHistoryList[9]["update_time"]]]);
  33. }
  34. $list = array_column($SearchHistoryList, "content");
  35. return $this->asJson($list);
  36. }
  37. /**
  38. * 推荐案例
  39. * @param $accident_id
  40. * @return Response
  41. * @throws Exception
  42. */
  43. public function actionRecommend($accident_id)
  44. {
  45. /**
  46. * 推荐顺序为:1.相同的事件类型,2.相同的时间特征,3.相同的发生位置。
  47. * 逻辑:
  48. * 先找到相同的事件类型,
  49. * 如果没有,找相同的时间特征,如果没有,找相同的发生位置,如果没有,返回空
  50. * 如果有,找出10个
  51. * 如果不足10个,找相同的时间特征替代
  52. * 如果总数仍不足10个,找相同的发生位置。
  53. * 最多显示10条记录
  54. */
  55. $limit = 10;
  56. $AccidentCases = CaseService::getCaseById($accident_id);
  57. //事件类型目前按照一级字段来推荐
  58. $AccidentCasesList = CaseService::getCaseShowQuery()->andWhere(["and", ["type_first" => $AccidentCases->type_first], ["<>", "id", $AccidentCases->id]])->limit($limit)->orderBy("start_time desc")->all();
  59. $list = CaseService::dealWithFocusList($AccidentCasesList);
  60. $totalCount = count($list);
  61. if ($totalCount < $limit) {
  62. //查找相同时间特征
  63. $idNotIn = array_column($AccidentCasesList, "id");
  64. $AccidentCasesList = CaseService::getCaseShowQuery()->andWhere(["and", ["time_type" => $AccidentCases->time_type], ["<>", "id", $AccidentCases->id], ["NOT IN", "id", $idNotIn]])->limit($limit - $totalCount)->orderBy("start_time desc")->all();
  65. $list = array_merge($list, CaseService::dealWithFocusList($AccidentCasesList));
  66. }
  67. $totalCount = count($list);
  68. if ($totalCount < $limit) {
  69. //查找相同的发生位置
  70. $idNotIn = array_column($AccidentCasesList, "id");
  71. $AccidentCasesList = CaseService::getCaseShowQuery()->andWhere(["and", ["position_base_second" => $AccidentCases->position_base_second], ["position_extra_second" => $AccidentCases->position_extra_second], ["<>", "id", $AccidentCases->id], ["NOT IN", "id", $idNotIn]])->limit($limit - $totalCount)->orderBy("start_time desc")->all();
  72. $list = array_merge($list, CaseService::dealWithFocusList($AccidentCasesList));
  73. }
  74. $data["data"] = $list;
  75. return $this->asJson($data);
  76. }
  77. /**
  78. * 案例搜索
  79. * @param int $current
  80. * @param int $page
  81. * @return Response
  82. * @throws InvalidConfigException
  83. */
  84. public function actionListNew(int $current = 1, int $page = 10)
  85. {
  86. //通用
  87. $post = Yii::$app->request->post();
  88. $query = CaseService::getCaseShowQuery()
  89. ->limit($page)
  90. ->offset(($current - 1) * $page);
  91. //排序
  92. $this->initSequence($query, "start_time desc");
  93. //搜索
  94. if (!isset($post["action"])) {
  95. $post["action"] = "fulltext";
  96. }
  97. $needSaveHistoryLog = true;
  98. if ($post["action"] == "fulltext") {
  99. //全文搜索
  100. list($info, $total) = $this->fullSearch($query, $post);
  101. //保存搜索记录
  102. if (trim($post["fulltext_content"]) != "") {
  103. $SearchHistory = SearchHistory::findOne(["uid" => $this->uid, "content" => trim($post["fulltext_content"])]);
  104. if (!$SearchHistory) {
  105. $SearchHistory = new SearchHistory();
  106. $SearchHistory->uid = $this->uid;
  107. $SearchHistory->content = trim($post["fulltext_content"]);
  108. $SearchHistory->type = 1;
  109. }
  110. $SearchHistory->update_time = time();
  111. $SearchHistory->save();
  112. } else {
  113. if ($current == 1 && $page == 5) {
  114. $needSaveHistoryLog = false;
  115. }
  116. }
  117. } elseif ($post["action"] == "list") {
  118. //列表搜索
  119. list($info, $total) = $this->listSearch($query, $post);
  120. } else {
  121. //高级搜索
  122. list($info, $total) = $this->advanceSearch($query, $post);
  123. }
  124. //
  125. if ($needSaveHistoryLog) {
  126. $model = "";
  127. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  128. AdminLogService::saveLogWithUpdateHistory($origin, $model, 0, "", $this->getAllParams());
  129. }
  130. //
  131. $data["data"] = CaseService::dealWithList($info);
  132. $data["total"] = $total;
  133. return $this->asJson($data);
  134. }
  135. protected function fullSearch($query, $post)
  136. {
  137. $fulltextContent = trim($post["fulltext_content"]);
  138. if ($fulltextContent != "") {
  139. //先从字典表进行模糊查询,找出id并找到对应的表进行匹配
  140. $DictionaryIdList = array_column(Dictionary::find()->where(["and", ["<>", "pid", 0], ["like", "name", $fulltextContent]])->all(), "id");
  141. $AccidentCasesRelationship = array_column(AccidentCasesRelateToDictionary::find()->where(["accident_cases_id" => $DictionaryIdList])->select("distinct(accident_cases_id)")->asArray()->all(), "accident_cases_id");
  142. //规章制度
  143. $rulesList = RulesService::getQuery()->where(["or", ["like", "rule_name", $fulltextContent], ["like", "rule_content", $fulltextContent]])->asArray()->all();
  144. $rulesIds = array_column($rulesList, "id");
  145. $rulesPointsList = RulesPointsService::getRulesPointsQuery()->where([
  146. "or",
  147. ["like", "name", $fulltextContent],
  148. ["like", "content", $fulltextContent],
  149. ["rule_id" => $rulesIds]
  150. ])->asArray()->all();
  151. $rulesPointsIds = array_column($rulesPointsList, "id");
  152. //通过规章点找出相关的应急处置和运营调整
  153. $EmergencyResponseIds = array_column(EmergencyResponseRelateToRulesPoints::find()->where(["rules_point_id" => $rulesPointsIds])->all(), "emergency_response_id");
  154. $OperationalAdjustmentsIds = array_column(OperationalAdjustmentsRelateToRulesPoints::find()->where(["rules_point_id" => $rulesPointsIds])->all(), "operational_adjustments_id");
  155. //将事件概览、应急处置和运营调整的搜索加进来
  156. $EmergencyResponseList = EmergencyResponseService::getEmergencyResponseQuery()
  157. ->andWhere([
  158. "or",
  159. ["like", "content", $fulltextContent],
  160. ["like", "important_content", $fulltextContent],
  161. ["like", "assess", $fulltextContent],
  162. ["like", "assess_two", $fulltextContent],
  163. ["id" => $EmergencyResponseIds],
  164. ])
  165. ->select("distinct(accident_id)")
  166. ->asArray()->all();
  167. $EmergencyResponse = array_column($EmergencyResponseList, "accident_id");
  168. $EventOverviewList = EventOverviewService::getEventOverviewQuery()
  169. ->andWhere([
  170. "or",
  171. ["like", "content", $fulltextContent],
  172. ["like", "important_content", $fulltextContent],
  173. ["like", "assess", $fulltextContent],
  174. ["like", "assess_two", $fulltextContent],
  175. ["id" => $OperationalAdjustmentsIds],
  176. ])
  177. ->select("distinct(accident_id)")
  178. ->asArray()->all();
  179. $EventOverview = array_column($EventOverviewList, "accident_id");
  180. $OperationalAdjustmentsList = OperationalAdjustmentsService::getQuery()
  181. ->andWhere([
  182. "or",
  183. ["like", "content", $fulltextContent],
  184. ["like", "important_content", $fulltextContent],
  185. ["like", "assess", $fulltextContent],
  186. ["like", "assess_two", $fulltextContent],
  187. ])
  188. ->select("distinct(accident_id)")
  189. ->asArray()->all();
  190. $OperationalAdjustments = array_column($OperationalAdjustmentsList, "accident_id");
  191. //整合ids
  192. $ids = array_merge($AccidentCasesRelationship, $EmergencyResponse, $EventOverview, $OperationalAdjustments);
  193. $ids = array_values(array_unique($ids));
  194. $query->andWhere([
  195. "or",
  196. ["id" => $ids],
  197. ["like", "title", $fulltextContent],
  198. ["like", "train_number_times", $fulltextContent],
  199. ["like", "position", $fulltextContent],
  200. ]);
  201. }
  202. //组合数据
  203. return [$query->all(), $query->count()];
  204. }
  205. protected function listSearch($query, $post)
  206. {
  207. //应急处置表字段 emergency_response_type emergency_response fault abnormal
  208. $post["emergency_response_type"] = [];
  209. $post["emergency_response"] = "";
  210. //运营调整字段 operational_adjustments_type operational_adjustments
  211. $post["operational_adjustments_type"] = [];
  212. $post["operational_adjustments"] = "";
  213. // ids
  214. $ids = [];
  215. //post数据
  216. $hasIdsSearch = false;
  217. foreach ($post["list_content"] as $value) {
  218. if ($value["count"] != []) {
  219. switch ($value["name"]) {
  220. case "事件性质":
  221. $query = $this->addArrayConditionToQuery("level", $query, $value["count"]);
  222. break;
  223. case "事件类型":
  224. //事件类型 数组保存
  225. $AccidentCasesRelationship = array_column(AccidentCasesRelateToDictionary::find()->where(["dictionary_id" => $value["count"]])->select("distinct(accident_cases_id)")->asArray()->all(), "accident_cases_id");
  226. $ids = array_merge($ids, $AccidentCasesRelationship);
  227. $hasIdsSearch = true;
  228. break;
  229. case "所属线路":
  230. $query = $this->addArrayConditionToQuery("line", $query, $value["count"]);
  231. break;
  232. case "日期特征":
  233. $query = $this->addArrayConditionToQuery("day_type", $query, $value["count"]);
  234. break;
  235. case "时间特征":
  236. $query = $this->addArrayConditionToQuery("time_type", $query, $value["count"]);
  237. break;
  238. // case "应急处置信息":
  239. // $post["emergency_response_type"] = $value["count"];
  240. // break;
  241. // case "运营调整信息":
  242. // $post["operational_adjustments_type"] = $value["count"];
  243. // break;
  244. case "最大晚点":
  245. $orData = ["or"];
  246. $delayDataNums = 0;
  247. foreach ($value["count"] as $count) {
  248. $condition = $this->getMaximumDelay($count);
  249. if (isset($condition[0]) && isset($condition[1])) {
  250. $orData[] = ["and", [">=", "maximum_delay", $condition[0]], ["<=", "maximum_delay", $condition[1]]];
  251. } else if (isset($condition[0])) {
  252. $orData[] = [">=", "maximum_delay", $condition[0]];
  253. }
  254. $delayDataNums++;
  255. }
  256. if ($delayDataNums == 1) {
  257. $query->andWhere($orData[1]);
  258. } else {
  259. $query->andWhere($orData);
  260. }
  261. break;
  262. case "所属年份":
  263. $this->setYearSearch($query, $value["count"]);
  264. break;
  265. default:
  266. break;
  267. }
  268. }
  269. }
  270. // //应急处置表字段
  271. // $ids = array_merge($ids, $this->getIdsByEmergencyResponse($post));
  272. // //运营调整字段
  273. // $ids = array_merge($ids, $this->getIdsByOperationalAdjustments($post));
  274. if ($ids != []) {
  275. $query->andWhere(["id" => $ids]);
  276. }
  277. if ($hasIdsSearch && $query->where === ["delete_time" => 0, "status" => 1]) {
  278. //在有ids搜索的前提下其他搜索都没有
  279. return [[], 0];
  280. }
  281. //组合数据
  282. return [$query->all(), $query->count()];
  283. }
  284. protected function getMaximumDelay($maximum_delay)
  285. {
  286. $maximumDelayArray = [
  287. [0, 0],
  288. [2, 5],
  289. [5, 15],
  290. [15, 30],
  291. [30]
  292. ];
  293. return $maximumDelayArray[$maximum_delay];
  294. }
  295. protected function setYearSearch($query, $yearDictionaryIds)
  296. {
  297. $orData = ["or"];
  298. $delayDataNums = 0;
  299. /** @var Dictionary[] $yearInfoList */
  300. $yearInfoList = Dictionary::find()->where(["status" => 1, "id" => $yearDictionaryIds])->all();
  301. foreach ($yearInfoList as $yearInfo) {
  302. $yearStart = strtotime($yearInfo->name . "-01-01");
  303. $yearEnd = strtotime($yearInfo->name . "-12-31");
  304. $orData[] = ["and", [">=", "start_time", $yearStart], ["<=", "start_time", $yearEnd]];
  305. $delayDataNums++;
  306. }
  307. if ($delayDataNums == 1) {
  308. $query->andWhere($orData[1]);
  309. } else {
  310. $query->andWhere($orData);
  311. }
  312. }
  313. protected function advanceSearch($query, $post)
  314. {
  315. $hasIdsSearch = false;
  316. $ids = [];
  317. $dictionaryIds = [];
  318. //主要筛选条件
  319. if ($post["years"] !== []) {
  320. $this->setYearSearch($query, $post["years"]);
  321. }
  322. //字符串
  323. $query = $this->addConditionToQuery("title", $query, true);
  324. //下拉框
  325. $query = $this->addConditionToQuery("level", $query);
  326. if ($post["type_base"] !== []) {
  327. $dictionaryIds = array_merge($dictionaryIds, $post["type_base"]);
  328. }
  329. if (isset($post["duty_category"])) {
  330. $dictionaryIds[] = $post["duty_category"];
  331. }
  332. // $query = $this->addConditionToQuery("duty_category", $query);
  333. $query = $this->addConditionToQuery("day_type", $query);
  334. $query = $this->addConditionToQuery("time_type", $query);
  335. //时间范围
  336. $query = $this->addStartEndConditionToQuery("start_time", $query, true);
  337. $query = $this->addStartEndConditionToQuery("elimination_time", $query, true);
  338. $query = $this->addStartEndConditionToQuery("recovery_time", $query, true);
  339. //下拉框
  340. //发生位置
  341. if ($post["position_base_second"] !== "") {
  342. $dictionaryIds[] = $post["position_base_second"];
  343. }
  344. if ($post["substation_type"] !== "") {
  345. $dictionaryIds[] = $post["substation_type"];
  346. }
  347. // if(isset($post["train_number"])){
  348. // $dictionaryIds[] = $post["train_number"];
  349. // }
  350. $query = $this->addConditionToQuery("train_number", $query);
  351. // $query = $this->addConditionToQuery("substation_type", $query);
  352. $query = $this->addConditionToQuery("line", $query);
  353. $query = $this->addConditionToQuery("automation_level", $query);
  354. $query = $this->addConditionToQuery("train_group", $query);
  355. $query = $this->addConditionToQuery("train_model", $query);
  356. $query = $this->addConditionToQuery("incidence", $query);
  357. //数字min&&max array[0],array[1]
  358. $query = $this->addStartEndConditionToQuery("headway", $query);
  359. $query = $this->addStartEndConditionToQuery("online_trains_number", $query);
  360. $query = $this->addStartEndConditionToQuery("emergency_duration", $query);
  361. $query = $this->addStartEndConditionToQuery("affect_trains_number", $query);
  362. $query = $this->addStartEndConditionToQuery("power_loss_duration", $query);
  363. if (isset($post["maximum_delay"])) {
  364. $maximumDelay = $this->getMaximumDelay($post["maximum_delay"]);
  365. if ($maximumDelay < 4) {
  366. $query = $this->addStartEndConditionToQuery("maximum_delay", $query, false, $maximumDelay);
  367. } else {
  368. $query = $query->andWhere([">=", "maximum_delay", $maximumDelay]);
  369. }
  370. }
  371. $query = $this->addStartEndConditionToQuery("train_delayed_two_minutes", $query);
  372. $query = $this->addStartEndConditionToQuery("train_delayed_five_minutes", $query);
  373. $query = $this->addStartEndConditionToQuery("get_off_trains_number", $query);
  374. $query = $this->addStartEndConditionToQuery("skip_stop_trains_number", $query);
  375. //计算案例关系表
  376. if ($dictionaryIds != []) {
  377. $AccidentCasesRelationship = array_column(AccidentCasesRelateToDictionary::find()->where(["dictionary_id" => $dictionaryIds])->select("distinct(accident_cases_id)")->asArray()->all(), "accident_cases_id");
  378. $ids = array_merge($dictionaryIds, $AccidentCasesRelationship);
  379. $hasIdsSearch = true;
  380. }
  381. //附加表字段
  382. //应急处置表字段 emergency_response_type emergency_response fault abnormal
  383. if (isset($post["emergency_response_type"]) && $post["emergency_response_type"] != null) {
  384. $post["emergency_response_type"] = [$post["emergency_response_type"]];
  385. $ids = array_merge($ids, $this->getIdsByEmergencyResponse($post));
  386. $hasIdsSearch = true;
  387. }
  388. //事件概览字段 event_overview
  389. if (isset($post["event_overview"]) && $post["event_overview"] != "") {
  390. $EventOverview = array_column(EventOverviewService::getEventOverviewQuery()->andWhere(["like", "content", $post["event_overview"]])->select("distinct(accident_id)")->asArray()->all(), "accident_id");
  391. $ids = array_merge($ids, $EventOverview);
  392. $hasIdsSearch = true;
  393. }
  394. //运营调整字段 operational_adjustments_type operational_adjustments
  395. if (isset($post["operational_adjustments_type"]) && $post["operational_adjustments_type"] != "") {
  396. $post["operational_adjustments_type"] = [$post["operational_adjustments_type"]];
  397. $ids = array_merge($ids, $this->getIdsByOperationalAdjustments($post));
  398. $hasIdsSearch = true;
  399. }
  400. if ($ids != []) {
  401. $query->andWhere(["id" => $ids]);
  402. }
  403. error_log(json_encode($ids));
  404. if ($hasIdsSearch && $query->where === ["delete_time" => 0, "status" => 1]) {
  405. //在有ids搜索的前提下其他搜索都没有
  406. return [[], 0];
  407. }
  408. //组合数据
  409. return [$query->all(), $query->count()];
  410. }
  411. protected function getIdsByOperationalAdjustments($post)
  412. {
  413. $ids = [];
  414. if ($post["operational_adjustments_type"] != [] || $post["operational_adjustments"] != "") {
  415. $OperationalAdjustments = OperationalAdjustmentsService::getQuery();
  416. if ($post["operational_adjustments_type"] != []) {
  417. $OperationalAdjustments->andWhere(["type_first" => $post["operational_adjustments_type"]]);
  418. }
  419. if ($post["operational_adjustments"] != "") {
  420. $OperationalAdjustments->andWhere(["content" => $post["operational_adjustments"]]);
  421. }
  422. $OperationalAdjustments = array_column($OperationalAdjustments->select("distinct(accident_id)")->asArray()->all(), "accident_id");
  423. $ids = array_merge($ids, $OperationalAdjustments);
  424. }
  425. return $ids;
  426. }
  427. protected function getIdsByEmergencyResponse($post)
  428. {
  429. $ids = [];
  430. if ($post["emergency_response_type"] != [] || $post["emergency_response"] != "") {
  431. $EmergencyResponse = EmergencyResponseService::getEmergencyResponseQuery();
  432. if ($post["emergency_response_type"] != []) {
  433. $EmergencyResponse->andWhere(["type_first" => $post["emergency_response_type"]]);
  434. }
  435. if ($post["emergency_response"] != "") {
  436. $EmergencyResponse->andWhere(["like", "content", $post["emergency_response"]]);
  437. }
  438. $EmergencyResponse = array_column($EmergencyResponse->select("distinct(accident_id)")->asArray()->all(), "accident_id");
  439. $ids = array_merge($ids, $EmergencyResponse);
  440. }
  441. return $ids;
  442. }
  443. /**
  444. * 案例详情
  445. * @param $id
  446. * @return Response
  447. * @throws Exception
  448. */
  449. public function actionDetail($id): Response
  450. {
  451. $data = CaseService::getCaseDetail($id, "detail");
  452. //返回数据
  453. $model = "";
  454. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  455. AdminLogService::saveLogWithUpdateHistory($origin, $model, $data["id"], $data["title"], $this->getAllParams());
  456. return $this->asJson($data);
  457. }
  458. /**
  459. * 案例详情(通过日历里面点查看)
  460. * @param $id
  461. * @return Response
  462. * @throws Exception
  463. */
  464. public function actionDetailLog($id): Response
  465. {
  466. $data = CaseService::getCaseDetail($id, "detail");
  467. return $this->asJson($data);
  468. }
  469. /**
  470. * 案例对比
  471. * @param $ids
  472. * @return Response
  473. * @throws Exception
  474. */
  475. public function actionCompare($ids): Response
  476. {
  477. $ids = explode(",", $ids);
  478. $data = [];
  479. foreach ($ids as $id) {
  480. $data[] = CaseService::getCaseDetail($id, "detail");
  481. }
  482. return $this->asJson($data);
  483. }
  484. /**
  485. * @throws InvalidConfigException
  486. */
  487. public function actionStudyList(int $current = 1, int $page = 10)
  488. {
  489. $query = AccidentCasesStudy::find()->alias("s")
  490. ->join('LEFT JOIN', 'accident_cases a', 'a.id = s.accident_id')
  491. ->select(CaseService::getCaseStudySqlSelectInfo())
  492. ->asArray()
  493. ->limit($page)->offset(($current - 1) * $page);
  494. $this->initSequence($query, "s.id desc");
  495. $query = $this->addConditionToQueryNew('s.username','username', $query, true);
  496. $query = $this->addConditionToQueryNew('s.name','name', $query, true);
  497. $query = $this->addConditionToQueryNew('a.title','title', $query, true);
  498. $query = $this->addStartEndConditionToQueryNew("s.start_time",'start_time', $query);
  499. $data['data'] = $query->all();
  500. $data['total'] = $query->count();
  501. return $this->asJson($data);
  502. }
  503. /**
  504. * @throws InvalidConfigException
  505. */
  506. public function actionMyStudyList(int $current = 1, int $page = 10)
  507. {
  508. $query = AccidentCasesStudy::find()->alias("s")
  509. ->join('LEFT JOIN', 'accident_cases a', 'a.id = s.accident_id')
  510. ->select(CaseService::getCaseStudySqlSelectInfo())
  511. ->asArray()
  512. ->limit($page)->offset(($current - 1) * $page);
  513. $this->initSequence($query, "s.id desc");
  514. $query = $this->addConditionToQueryNew('s.username', $query, true);
  515. $query = $this->addConditionToQueryNew('s.name', $query, true);
  516. $query = $this->addConditionToQueryNew('a.title', $query, true);
  517. $query = $this->addStartEndConditionToQueryNew("s.start_time", $query);
  518. $query = $query->andWhere(["uid" => $this->userInfo->id]);
  519. $data['data'] = $query->all();
  520. $data['total'] = $query->count();
  521. return $this->asJson($data);
  522. }
  523. }