Neo4j.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace app\controller;
  3. use app\model\XyZskInspection;
  4. use think\facade\Request;
  5. use think\facade\Log;
  6. use Exception;
  7. use app\model\XyZskDisease;
  8. use app\model\XyZskMedicine;
  9. class Neo4j extends CommonTwoController
  10. {
  11. // 获取列表数据(Admin|Grid)
  12. public function index()
  13. {
  14. $start = Request::param('start') ?? 0;
  15. $perPage = Request::param('perPage') ?? 10;
  16. $label = Request::param('label') ?? 'SickNess';
  17. $tag = Request::param('tag') ?? 'zy';
  18. $name = Request::param('name') ?? '';
  19. if($name) {
  20. $list = $this->getNodes($tag , 'n' , $label , $start , $perPage , 'name' , $name);
  21. } else {
  22. $list = $this->getNodes($tag , 'n' , $label , $start , $perPage);
  23. }
  24. return json($list);
  25. }
  26. public function add()
  27. {
  28. // $page = Request::param('page') ?? 1;
  29. // $pagesize = 10;
  30. // $limit = ($page - 1) * $pagesize;
  31. // $medicines = XyZskMedicine::select()->toArray();
  32. //
  33. // $medicines = array_column($medicines , 'name');
  34. // foreach($medicines as $medicine)
  35. // {
  36. // $query = "match (n:MedicineProduction) where n.name= " . "'" . $medicine . "'" . "return n";
  37. // $data = $this->getAboutInfo($query);
  38. // //return $this->_json_succ($data[0]['n']);
  39. //
  40. // $n = $data[0]['n'] ?? '';
  41. //
  42. // $m = XyZskMedicine::where('name', $medicine)->find();
  43. // $m->pinyin = $n['pinyin'] ?? '';
  44. // $m->medicineNature = $n['medicineNature'] ?? '';
  45. // $m->oldUse = $n['oldUse']?? '';
  46. // $m->chilldUse = $n['chilldUse']?? '';
  47. // $m->medicinePregnant = $n['medicinePregnant']?? '';
  48. // $m->usageDosage = $n['usageDosage']?? '';
  49. // $m->notes = $n['notes'] ?? '';
  50. // $m->periodValidity = $n['periodValidity'] ?? '';
  51. // $m->indication = $n['indication']?? '';
  52. //
  53. // $m->storage = $n['storage'] ?? '';
  54. // $m->character = $n['character'] ?? '';
  55. // $m->contraindication = $n['contraindication']?? '';
  56. // $m->pharmacologyToxicology = $n['pharmacologyToxicology']?? '';
  57. // $m->specification = $n['specification']?? '';
  58. //
  59. // $m->approvalNumber = $n['approvalNumber']?? '';
  60. // $m->productionEnterprise = $n['productionEnterprise']?? '';
  61. // $m->relateSick = $n['relateSick']?? '';
  62. //
  63. // $m->untowardEffect = $n['untowardEffect']?? '';
  64. // $m->majorConstituent = $n['majorConstituent']?? '';
  65. // $m->pname = $n['pname']?? '';
  66. // $m->medicineInteractions = $n['medicineInteractions']?? '';
  67. //
  68. // $m->save();
  69. // }
  70. // exit;
  71. // $start = Request::param('start') ?? 0;
  72. // $perPage = Request::param('perPage') ?? 2000;
  73. // $label = Request::param('label') ?? 'Disease';
  74. // $data = $this->getNodes('' , 'n' , $label , $start , $perPage);
  75. // $list = $data['list'];
  76. //
  77. //
  78. // foreach($list as $value)
  79. // {
  80. // $check = XyZskDisease::where('name' , $value['name'])->find();
  81. // if(!$check) {
  82. // $result = XyZskDisease::create($value);
  83. // }
  84. // }
  85. // return $this->_json_succ($result);
  86. // $page = Request::param('page') ?? 10;
  87. // $pagesize = 1000;
  88. // $limit = ($page - 1) * $pagesize;
  89. //
  90. // $data = XyZskDisease::limit($limit , $pagesize)->select()->toArray();
  91. // foreach($data as $key => $value) {
  92. // $query1 = "match (n:Disease)-[r:LinkInspection]-(m:Thing) where n.name= "."'".$value['name']."'"." return m";
  93. // $data1 = $this->getAboutInfo($query1);
  94. // $data2 = array_column($data1, 'm');
  95. //
  96. // $XyZskInspection = new XyZskInspection();
  97. // foreach($data2 as $val)
  98. // {
  99. // $XyZskInspection->disease_name = $value['name'];
  100. // $XyZskInspection->name = $val['name'] ?? '';
  101. // $XyZskInspection->overview = $val['overview'] ?? '';
  102. // $XyZskInspection->principle = $val['principle'] ?? '';
  103. // $XyZskInspection->reagent = $val['reagent'] ?? '';
  104. // $XyZskInspection->operation = $val['operation'] ?? '';
  105. // $XyZskInspection->clinicalSignificance = $val['clinicalSignificance'] ?? '';
  106. // $XyZskInspection->normalValue = $val['normalValue'] ?? '';
  107. // $XyZskInspection->annotation = $val['annotation'] ?? '';
  108. // $res = $XyZskInspection->save();
  109. // }
  110. // }
  111. // foreach($data as $key => $value) {
  112. // $query1 = "match (n:Disease)-[r:LinkMedicineDisease]-(m:Thing) where n.name= "."'".$value['name']."'"." return m";
  113. // $data1 = $this->getAboutInfo($query1);
  114. // $data2 = array_column($data1, 'm');
  115. //
  116. // $XyZskMedicine = new XyZskMedicine();
  117. // foreach($data2 as $val)
  118. // {
  119. // $XyZskMedicine->disease_name = $value['name'];
  120. // $XyZskMedicine->name = $val['name'] ?? '';
  121. // $XyZskMedicine->pinyi = $val['piny'] ?? '';
  122. // $XyZskMedicine->medicineNature = $val['medicineNature'] ?? '';
  123. // $XyZskMedicine->oldUse = $val['oldUse'] ?? '';
  124. // $XyZskMedicine->chilldUse = $val['operation'] ?? '';
  125. // $XyZskMedicine->usageDosage = $val['usageDosage'] ?? '';
  126. // $XyZskMedicine->notes = $val['notes'] ?? '';
  127. // $XyZskMedicine->periodValidity = $val['periodValidity'] ?? '';
  128. //
  129. // $XyZskMedicine->indication = $val['indication'] ?? '';
  130. // $XyZskMedicine->storage = $val['storage'] ?? '';
  131. // $XyZskMedicine->character = $val['character'] ?? '';
  132. // $XyZskMedicine->contraindication = $val['contraindication'] ?? '';
  133. //
  134. // $XyZskMedicine->pharmacologyToxicology = $val['pharmacologyToxicology'] ?? '';
  135. // $XyZskMedicine->specification = $val['specification'] ?? '';
  136. // $XyZskMedicine->approvalNumber = $val['approvalNumber'] ?? '';
  137. // $XyZskMedicine->productionEnterprise = $val['productionEnterprise'] ?? '';
  138. // $XyZskMedicine->relateSick = $val['relateSick'] ?? '';
  139. // $XyZskMedicine->untowardEffect = $val['untowardEffect'] ?? '';
  140. // $XyZskMedicine->majorConstituent = $val['majorConstituent'] ?? '';
  141. //
  142. // $res = $XyZskMedicine->save();
  143. // }
  144. // }
  145. //
  146. // return $this->_json_succ($res);
  147. }
  148. public function updateMedicine()
  149. {
  150. $page = Request::param('page') ?? 10;
  151. $pagesize = 1000;
  152. $limit = ($page - 1) * $pagesize;
  153. $medicines = XyZskMedicine::limit($limit , $pagesize)->select()->toArray();
  154. foreach($medicines as $medicine) {
  155. $query = "match (n:MedicineProduction) where n.name= "."'".$medicine['name']."'"." return n";
  156. $data = $this->getAboutInfo($query);
  157. $n = $data['n'];
  158. return $this->_json_succ($n);
  159. }
  160. }
  161. // 创建节点
  162. public function createLabel()
  163. {
  164. $data = Request::all();
  165. if(empty($data)) {
  166. return $this->_json_error('请求有误!');
  167. }
  168. $label = $data['label'];
  169. unset($data['label']);
  170. try {
  171. $result = $this->createNode('n' , $label , $data);
  172. }catch(Exception $e){
  173. return $this->_json_error($e->getMessage());
  174. }
  175. return $this->_json_succ($result);
  176. }
  177. // 获取单个数据详情
  178. public function singleNode()
  179. {
  180. $id = Request::param('id') ?? 401;
  181. $zsk = Request::param('zsk') ?? 'zy';
  182. $data = $this->getNodeById($zsk , $id);
  183. return json($data);
  184. }
  185. // 获取id
  186. public function getLableById()
  187. {
  188. $id = Request::param('id');
  189. $zsk = Request::param('zsk') ?? 'zy';
  190. $labels = $this->getNodeById($zsk , $id , 1);
  191. return json($labels);
  192. }
  193. // 数据更新
  194. public function setNodeById()
  195. {
  196. $query = Request::param('query');
  197. $tag = Request::param('tag') ?? 'zy';
  198. Log::info('setnode' , ['tag' => $tag , 'query' => $query]);
  199. return json($this->setNode($query , $tag));
  200. }
  201. }