作者 邓超

es

@@ -45,7 +45,7 @@ class SyncMailToEs { @@ -45,7 +45,7 @@ class SyncMailToEs {
45 public $es; 45 public $es;
46 46
47 public function handler(){ 47 public function handler(){
48 - $this->es = new Es('hg_ai_emails'); 48 +// $this->es = new Es('hg_ai_emails');
49 if(in_array($this->table,['lists','lists_auto','lists_hot'])){ 49 if(in_array($this->table,['lists','lists_auto','lists_hot'])){
50 50
51 if($this->type=='create'){ 51 if($this->type=='create'){
@@ -70,16 +70,18 @@ class SyncMailToEs { @@ -70,16 +70,18 @@ class SyncMailToEs {
70 return ; 70 return ;
71 } 71 }
72 else if($this->table == 'lists'){ 72 else if($this->table == 'lists'){
73 - $id = $this->data['email_id'].'_'.$this->data['folder_id'].'_'.$this->data['uid'];  
74 - if(empty($this->data['is_auto'])){  
75 - $this->data['is_auto'] = 0;  
76 - }  
77 - $this->es->save($id,$this->getData($this->data)); 73 + redis()->rPush('sync_to_es',$this->data['id']);
  74 +// $id = $this->data['email_id'].'_'.$this->data['folder_id'].'_'.$this->data['uid'];
  75 +// if(empty($this->data['is_auto'])){
  76 +// $this->data['is_auto'] = 0;
  77 +// }
  78 +// $this->es->save($id,$this->getData($this->data));
78 } 79 }
79 else if($this->table == 'lists_auto'){ 80 else if($this->table == 'lists_auto'){
80 - $data = db()->first(listsSql::first('`id` = '.$this->data['list_id']));  
81 - $id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid'];  
82 - $this->es->save($id,$this->getData($data)); 81 + redis()->rPush('sync_to_es',$this->data['list_id']);
  82 +// $data = db()->first(listsSql::first('`id` = '.$this->data['list_id']));
  83 +// $id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid'];
  84 +// $this->es->save($id,$this->getData($data));
83 } 85 }
84 86
85 } 87 }
@@ -95,39 +97,17 @@ class SyncMailToEs { @@ -95,39 +97,17 @@ class SyncMailToEs {
95 // } 97 // }
96 if($this->table == 'lists'){ 98 if($this->table == 'lists'){
97 // 更新es 99 // 更新es
98 - $lists = db()->all(listsSql::all($this->where)); 100 + $lists = db()->all(listsSql::all($this->where,'`id`'));
99 foreach ($lists as $list){ 101 foreach ($lists as $list){
100 - $id = $list['email_id'].'_'.$list['folder_id'].'_'.$list['uid'];  
101 - $this->es->save($id,$this->getData($list)); 102 + redis()->rPush('sync_to_es',$list['id']);
  103 +// $id = $list['email_id'].'_'.$list['folder_id'].'_'.$list['uid'];
  104 +// $this->es->save($id,$this->getData($list));
102 } 105 }
103 } 106 }
104 107
105 } 108 }
106 109
107 110
108 - public function getData($data){  
109 - if(!empty($data['id'])){  
110 - $data['uuid'] = $data['id'];  
111 - unset($data['id']);  
112 - }  
113 - if(!empty($data['from'])){  
114 - $data['from'] = [  
115 - 'email' => $data['from'],  
116 - 'name' => $data['from_name']??''  
117 - ];  
118 - unset($data['from_name']);  
119 - }  
120 - unset($data['date']);  
121 - if(!empty($data['created_at'])){  
122 - $data['created_at'] = date('Y-m-d\TH:i:s',strtotime($data['created_at']));  
123 - }  
124 - if(!empty($data['updated_at'])){  
125 - $data['updated_at'] = date('Y-m-d\TH:i:s',strtotime($data['updated_at']));  
126 - }  
127 - $data['references'] = empty($data['references']) ? '' : $data['references'];  
128 - return $data;  
129 - }  
130 -  
131 111
132 112
133 113
@@ -218,7 +218,7 @@ trait DbQuery { @@ -218,7 +218,7 @@ trait DbQuery {
218 $query = $this->query([$sql,$data]); 218 $query = $this->query([$sql,$data]);
219 219
220 if($query){ 220 if($query){
221 - $data['uuid'] = $this->getClient()->lastInsertId(); 221 + $data['id'] = $this->getClient()->lastInsertId();
222 // es 同步数据 222 // es 同步数据
223 \Event\Event::call('\Event\SyncMailToEs','create',$table, $data); 223 \Event\Event::call('\Event\SyncMailToEs','create',$table, $data);
224 return true; 224 return true;