mongo_db->where(array("warning_id"=> $id))->find_one($this->collection_name); } public function get_warning_with_objectid($oid){ if(!empty($oid)) { $_id = $this->mongo_db->get_mongo_id($oid); return $this->mongo_db->where(array("_id" => $_id))->find_one($this->collection_name); } } public function select_warning($field,$warning_id){ return $this->mongo_db->where(array("warning_id"=> $warning_id))->select($field)->find_one($this->collection_name); } public function aggregate($begin_datetime,$end_datetime,$group,$project=NULL,$where=NULL,$limit=NULL,$offset=NULL,$order = NULL){ return $this->mongo_db->where_between("create_time",$begin_datetime,$end_datetime)->where($where)->order_by($order)->limit($limit)->offset($offset)->aggregate($this->collection_name,$group,$project); } public function list_warning($limit,$offset,$like = NULL,$where = NULL,$order = NULL){ if(!$order){ $order = array("create_time"=>"DESC"); } if($like && $where){ return $this->mongo_db->like("warning_name",$like)->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name); }else if($like && !$where){ return $this->mongo_db->like("warning_name",$like)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name); }else if(!$like && $where){ return $this->mongo_db->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name); }else{ return $this->mongo_db->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name); } } /** * 获取数据条数 */ public function count_warning($like = NULL,$where = NULL){ if($like && $where){ return $this->mongo_db->like("warning_name",$like)->where($where)->count($this->collection_name); }else if($like && !$where){ return $this->mongo_db->like("warning_name",$like)->count($this->collection_name); }else if(!$like && $where){ return $this->mongo_db->where($where)->count($this->collection_name); }else{ return $this->mongo_db->count($this->collection_name); } } /** *新增告警 */ public function insert_warning($warning_data){ return $this->mongo_db->insert($this->collection_name, $warning_data); } /** *更新告警 */ public function update_warning($warning_data){ $data['filter'] = array("warning_id"=>$warning_data['warning_id']); $data['update'] = $warning_data; return $this->mongo_db->update($this->collection_name,$data); } /** * 更新单个字段或多个字段的值 * @param $field * @param $wheres * @param null $value * @return mixed */ public function set_val($field,$wheres,$value = NULL){ if(is_array($field)){ return $this->mongo_db->set_wheres($wheres)->set($field)->update_all($this->collection_name); }else { return $this->mongo_db->set_wheres($wheres)->set($field, $value)->update_all($this->collection_name); } } /** * 删除告警 */ public function delete_warningr($id){ return $this->mongo_db->where(array("warning_id"=>$id))->delete($this->collection_name); } /** * 删除多个告警 */ public function delete_all_warning($ids){ return $this->mongo_db->where_in("warning_id",$ids)->delete_all($this->collection_name); } }