$sql="select item_id from knl_article order by id desc";
$row=$this->db->fetchRow($sql);
try{
$this->db->beginTransaction();
$sql="insert into knl_article (item_id) select item_id from knl_dcvalue where dc_type_id=66 and text_value='Article' and item_id>".$row['item_id'];
$this->db->query($sql);
$sql="update knl_article k set title=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=64) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
$this->db->query($sql);
$sql="update knl_article k set url=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=25) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
$this->db->query($sql);
$sql="update knl_article k set publisher=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=39) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
$this->db->query($sql);
$sql="update knl_article k set ts_issued=t.text_value from (select text_value,item_id from knl_dcvalue where dc_type_id=15) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
$this->db->query($sql);
$sql="update knl_article k set ts_created=cast(t.text_value as timestamp without time zone) from (select text_value,item_id from knl_dcvalue where dc_type_id=12) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
$this->db->query($sql);
$sql="update knl_article k set keywords[t.place]=t.text_value from (select text_value,item_id,place from knl_dcvalue where dc_type_id=57) as t where k.item_id=t.item_id and k.item_id>".$row['item_id'];
$this->db->query($sql);
$sql="insert into knl_keyword (keyword,item_id,place) select text_value,item_id,place from knl_dcvalue where dc_type_id=57 and item_id>".$row['item_id'];
$this->db->query($sql);
$sql="insert into knl_author (author,item_id,place) select text_value,item_id,place from knl_dcvalue where dc_type_id=3 and item_id>".$row['item_id'];
$this->db->query($sql);
$this->db->query("delete from knl_keyword where item_id not in (select item_id from knl_article)");
$this->db->query("delete from knl_author where item_id not in (select item_id from knl_article)");
$this->db->commit();
}catch(Exception$e){
$this->db->rollBack();
$this->view->msg=$e->getMessage();
}
$this->view->msg='与文献平台同步成功!';
}
$sql="select (select count(*) from knl_article) as westdccount,(select count(*) from knl_dcvalue where dc_type_id=66 and text_value='Article') as seekcount";