CompoundController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\UserDict;
  4. use Illuminate\Http\Request;
  5. use App\Http\Api\DictApi;
  6. class CompoundController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return \Illuminate\Http\Response
  12. */
  13. public function index()
  14. {
  15. //
  16. }
  17. /**
  18. * Store a newly created resource in storage.
  19. *
  20. * @param \Illuminate\Http\Request $request
  21. * @return \Illuminate\Http\Response
  22. */
  23. public function store(Request $request)
  24. {
  25. /**
  26. *
  27. */
  28. $dict_id = DictApi::getSysDict('robot_compound');
  29. if(!$dict_id){
  30. return $this->error('没有找到 robot_compound 字典');
  31. }
  32. //删除旧数据
  33. $del = UserDict::where('dict_id',$dict_id)
  34. ->whereIn('word',$request->get('index'))
  35. ->delete();
  36. foreach ($request->get('words') as $key => $word) {
  37. $new = new UserDict;
  38. $new->id = app('snowflake')->id();
  39. $new->word = $word['word'];
  40. $new->factors = $word['factors'];
  41. $new->dict_id = $dict_id;
  42. $new->source = '_ROBOT_';
  43. $new->create_time = (int)(microtime(true)*1000);
  44. $new->type = $word['type'];
  45. $new->grammar = $word['grammar'];
  46. $new->parent = $word['parent'];
  47. $new->confidence = $word['confidence'];
  48. $new->note = $word['confidence'];
  49. $new->language = 'cm';
  50. $new->creator_id = 1;
  51. $new->flag = 0;//标记为维护状态
  52. $new->save();
  53. }
  54. return $this->ok(count($request->get('words')));
  55. }
  56. /**
  57. * Display the specified resource.
  58. *
  59. * @param \App\Models\DhammaTerm $dhammaTerm
  60. * @return \Illuminate\Http\Response
  61. */
  62. public function show(string $word)
  63. {
  64. //
  65. $dict_id = DictApi::getSysDict('robot_compound');
  66. if(!$dict_id){
  67. return $this->error('没有找到 robot_compound 字典');
  68. }
  69. $result = UserDict::where('dict_id',$dict_id)
  70. ->where('word',$word)
  71. ->orderBy('confidence','desc')
  72. ->get();
  73. return $this->ok(['rows'=>$result,'count'=>count($result)]);
  74. }
  75. /**
  76. * Update the specified resource in storage.
  77. *
  78. * @param \Illuminate\Http\Request $request
  79. * @param \App\Models\DhammaTerm $dhammaTerm
  80. * @return \Illuminate\Http\Response
  81. */
  82. public function update(Request $request, DhammaTerm $dhammaTerm)
  83. {
  84. //
  85. }
  86. /**
  87. * Remove the specified resource from storage.
  88. *
  89. * @param \App\Models\DhammaTerm $dhammaTerm
  90. * @return \Illuminate\Http\Response
  91. */
  92. public function destroy(DhammaTerm $dhammaTerm)
  93. {
  94. //
  95. }
  96. }