diff --git a/app/controller/KnowledgeLibraryController.php b/app/controller/KnowledgeLibraryController.php new file mode 100644 index 0000000..95927da --- /dev/null +++ b/app/controller/KnowledgeLibraryController.php @@ -0,0 +1,36 @@ + '', + 'url' => '', + ]); + validate(KnowledgeLibraryValidate::class)->check($params, 'save'); + return success($service->saveData($params)); + } + + public function index(KnowledgeLibraryService $service): Response + { + $params = requestOnly([ + 'name' => '', + 'begin_time' => '', + 'end_time' => '' + ]); + return success($service->listData($params)); + } + + public function delete(KnowledgeLibraryService $service): Response + { + $id = input('id'); + return success($service->deleteData($id)); + } + +} \ No newline at end of file diff --git a/app/dao/KnowledgeLibraryDao.php b/app/dao/KnowledgeLibraryDao.php new file mode 100644 index 0000000..92ca1bb --- /dev/null +++ b/app/dao/KnowledgeLibraryDao.php @@ -0,0 +1,15 @@ +setParams(['perm' => ['questionsDelete']]); }); + + //智能体知识库 + Route::group('/knowledge', function () { + //新增 + Route::post('/save', [KnowledgeLibraryController::class, 'save'])->setParams(['perm' => ['questionsSave']]); + //列表 + Route::get('/index', [KnowledgeLibraryController::class, 'index'])->setParams(['perm' => ['questionsIndex']]); + //删除 + Route::post('/delete', [KnowledgeLibraryController::class, 'delete'])->setParams(['perm' => ['questionsDelete']]); + }); })->middleware([ AdminAuthorizationMiddleware::class, PermissionsMiddleware::class diff --git a/app/service/DistillationQuestionsService.php b/app/service/DistillationQuestionsService.php index 0c6611f..24afc17 100644 --- a/app/service/DistillationQuestionsService.php +++ b/app/service/DistillationQuestionsService.php @@ -99,11 +99,11 @@ class DistillationQuestionsService extends BaseService */ public function readData(mixed $id): array { - $user_group = $this->dao->get(['id' => $id], ['*'], ['distillation']); - if (empty($user_group)) { + $question = $this->dao->get(['id' => $id], ['*'], ['distillation']); + if (empty($question)) { throw new ApiException('数据不存在'); } - return $user_group->toArray(); + return $question->toArray(); } /** diff --git a/app/service/KnowledgeLibraryService.php b/app/service/KnowledgeLibraryService.php new file mode 100644 index 0000000..029a9e4 --- /dev/null +++ b/app/service/KnowledgeLibraryService.php @@ -0,0 +1,81 @@ +dao = $dao; + } + + /** + * 保存信息 + * @param array $params + * @return array + */ + public function saveData(array $params): array + { + Db::startTrans(); + try { + $data = $this->dao->save($params); + Db::commit(); + } catch (\Exception $exception) { + Db::rollback(); + throw new ApiException($exception->getMessage()); + } + return $data->toArray(); + } + + /** + * 获取列表 + * @param array $params + * @return array + */ + public function listData(array $params): array + { + $query = [ + 'delete_time' => 0 + ]; + if (isNotBlank($params['name'])) { + $query[] = ['name', 'like', '%' . $params['name'] . '%']; + } + if (isNotBlank($params['begin_time'])) { + $query[] = ['create_time', '>=', strtotime($params['begin_time'])]; + } + if (isNotBlank($params['end_time'])) { + $query[] = ['create_time', '<=', strtotime($params['end_time'] . ' 23:59:59')]; + } + $list = $this->dao->getList($query); + $count = $this->dao->getCount($query); + return compact('list', 'count'); + } + + /** + * 删除信息 + * @param mixed $id + * @return array + */ + public function deleteData(mixed $id): array + { + // 落库 + Db::startTrans(); + try { + $this->dao->update($id, ['delete_time' => time()]); + Db::commit(); + } catch (\Exception $exception) { + Db::rollback(); + throw new ApiException($exception->getMessage()); + } + return ['id' => $id]; + } + +} \ No newline at end of file diff --git a/app/validate/KnowledgeLibraryValidate.php b/app/validate/KnowledgeLibraryValidate.php new file mode 100644 index 0000000..3116e2e --- /dev/null +++ b/app/validate/KnowledgeLibraryValidate.php @@ -0,0 +1,19 @@ + [ + 'name' => 'require|max:90', + 'url' => 'require', + ], + ]; + protected $message = [ + 'name.require' => '知识库别名不能为空', + 'url.require' => '文件地址不能为空', + ]; +} \ No newline at end of file diff --git a/plugin/piadmin/app/service/AttachmentService.php b/plugin/piadmin/app/service/AttachmentService.php index 1b1ba7c..9b44e5f 100644 --- a/plugin/piadmin/app/service/AttachmentService.php +++ b/plugin/piadmin/app/service/AttachmentService.php @@ -37,7 +37,7 @@ class AttachmentService extends BaseService $path = parse_url($aliyunOssUrl, PHP_URL_PATH); //封装数据 $data = [ - 'id' => IdUtils::uuid(), +// 'id' => IdUtils::uuid(), 'storage' => Attachment::getStorage(), 'type' => $file->getUploadMimeType(), 'name' => "$uniqueName.$fileExt",