Warning.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * Class 告警信息管理类
  5. */
  6. class Warning extends MY_Controller{
  7. function __construct(){
  8. parent::__construct();
  9. $this->load->helper('form');
  10. $this->load->model("warning_model");
  11. $this->load->library('MY_pagination');
  12. $this->load->helper('url');
  13. $this->assign("warning_type",$this->warning_type);
  14. $this->assign("warning_level",$this->warning_level);
  15. $this->assign("warning_status",$this->warning_status);
  16. }
  17. /**
  18. * 状态数量统计
  19. */
  20. private function counts()
  21. {
  22. $count10 = $this->warning_model->count_warning(null, $wheres = array('status' => "10"));
  23. $count20 = $this->warning_model->count_warning(null, $wheres = array('status' => "20"));
  24. $count30 = $this->warning_model->count_warning(null, $wheres = array('status' => "30"));
  25. $count40 = $this->warning_model->count_warning(null, $wheres = array('status' => "40"));
  26. $this->assign("count10", $count10);
  27. $this->assign("count20", $count20);
  28. $this->assign("count30", $count30);
  29. $this->assign("count40", $count40);
  30. }
  31. /**
  32. * 告警列表页
  33. */
  34. public function index(){
  35. $url = site_url("warning/index?");
  36. $wheres = array();
  37. $order_info = array("status"=>"ASC","create_time"=>"DESC");
  38. $warning_name = $this->input->get("warning_name",TRUE);
  39. $branch_id = $this->input->get("branch_id",TRUE);
  40. $type = $this->input->get("type",TRUE);
  41. $status = $this->input->get("status",TRUE);
  42. $order = $this->input->get("order",TRUE);
  43. $page_num = $this->input->get("per_page",TRUE);
  44. $page_size = $this->input->get("page_size",TRUE);
  45. if($warning_name){
  46. $url .= "&warning_name=".$warning_name;
  47. }
  48. if($branch_id){
  49. $wheres['branch.branch_id'] = $branch_id;
  50. $url .= "&branch_id=".$branch_id;
  51. }
  52. if($type){
  53. $wheres['type'] = $type;
  54. $url .= "&type=".$type;
  55. }
  56. if($status) {
  57. $wheres['status'] = $status;
  58. $url .= "&status=".$status;
  59. }
  60. if($order){
  61. $orders = explode(" ",$order);
  62. if(count($orders)==2) {
  63. $order_info[$orders[0]] = $orders[1];
  64. $url .= "&order=".$order;
  65. }
  66. }
  67. if($page_size){
  68. $this->page_size = $page_size;
  69. $url .= "&page_size=".$page_size;
  70. }
  71. $count = $this->warning_model->count_warning($warning_name,$wheres);
  72. $this->assign("count",$count);
  73. $config = $this->page_config($count,$this->page_size,$url);
  74. $this->my_pagination->initialize ($config);
  75. if($page_num && $page_num>1) {
  76. $offset = (intval($page_num)-1)*$this->page_size;
  77. }else {
  78. $offset = 0;
  79. }
  80. $warning_list = $this->warning_model->list_warning($this->page_size,$offset,$warning_name,$wheres,$order_info);
  81. $this->counts();
  82. $this->assign("warning_name",$warning_name);
  83. $this->assign("type",$type);
  84. $this->assign("branch_id",$branch_id);
  85. $this->assign("status",$status);
  86. $this->assign("order",$order);
  87. $this->assign("page_size",$this->page_size);
  88. $this->assign("page",$this->my_pagination->create_pages());
  89. $this->assign("warning_list",$warning_list);
  90. $this->display("warning/index.html");
  91. }
  92. public function view($warning_id){
  93. $warning_info = $this->warning_model->get_warning_with_id($warning_id);
  94. $this->assign("warning",$warning_info);
  95. $this->display("warning/view.html");
  96. }
  97. /**
  98. * 已忽略告警信息列表页
  99. */
  100. public function ignoreindex(){
  101. $url = site_url("warning/ignoreindex?");
  102. $wheres = array();
  103. $order_info = array();
  104. $warning_name = $this->input->get("warning_name",TRUE);
  105. $type = $this->input->get("type",TRUE);
  106. $order = $this->input->get("order",TRUE);
  107. $page_num = $this->input->get("per_page",TRUE);
  108. $page_size = $this->input->get("page_size",TRUE);
  109. if($warning_name){
  110. $url .= "&warning_name=".$warning_name;
  111. }
  112. if($type){
  113. $wheres['type'] = $type;
  114. $url .= "&type=".$type;
  115. }
  116. $wheres['status'] = "20";
  117. if($order){
  118. $orders = explode(" ",$order);
  119. if(count($orders)==2) {
  120. $order_info[$orders[0]] = $orders[1];
  121. $url .= "&order=".$order;
  122. }
  123. }
  124. if($page_size){
  125. $this->page_size = $page_size;
  126. $url .= "&page_size=".$page_size;
  127. }
  128. $count = $this->warning_model->count_warning($warning_name,$wheres);
  129. $config = $this->page_config($count,$this->page_size,$url);
  130. $this->my_pagination->initialize ($config);
  131. if($page_num && $page_num>1) {
  132. $offset = (intval($page_num)-1)*$this->page_size;
  133. }else {
  134. $offset = 0;
  135. }
  136. $warning_list = $this->warning_model->list_warning($this->page_size,$offset,$warning_name,$wheres,$order_info);
  137. $this->assign("count",$count);
  138. $this->assign("warning_name",$warning_name);
  139. $this->assign("type",$type);
  140. $this->assign("order",$order);
  141. $this->assign("page_size",$this->page_size);
  142. $this->assign("page",$this->my_pagination->create_pages());
  143. $this->assign("warning_list",$warning_list);
  144. $this->display("warning/ignoreindex.html");
  145. }
  146. /**
  147. * 忽略告警信息
  148. * @param $warning_id 告警信息ID
  149. */
  150. public function ignore($warning_id){
  151. $msg = array();
  152. $warning_info = $this->warning_model->get_warning_with_id($warning_id);
  153. if($warning_info){
  154. $warning_info['status'] = "20";
  155. $this->warning_model->update_warning($warning_info);
  156. $msg['msg'] = "忽略告警信息成功!";
  157. $msg['icon'] = 1;
  158. }else{
  159. $msg['msg'] = "告警信息不存在或者已经被删除!";
  160. $msg['icon'] = 2;
  161. }
  162. $this->response($msg);
  163. }
  164. /**
  165. * 批量忽略告警信息
  166. */
  167. public function ignoreselect(){
  168. $warning_ids = $this->input->post("warning_ids",true);
  169. $msg['msg'] = "忽略告警信息成功!";
  170. $msg['icon'] = 1;
  171. $ids = explode(",",$warning_ids);
  172. foreach($ids as $key=>$val){
  173. if($val){
  174. $warning_info = $this->warning_model->get_warning_with_objectid($val);
  175. if($warning_info){
  176. $warning_info['status'] = "20";
  177. $this->warning_model->update_warning($warning_info);
  178. }
  179. }
  180. }
  181. $this->response($msg);
  182. }
  183. }