diff --git a/app/controller/EnterprisePortraitCategoryController.php b/app/controller/EnterprisePortraitCategoryController.php new file mode 100644 index 0000000..8384e28 --- /dev/null +++ b/app/controller/EnterprisePortraitCategoryController.php @@ -0,0 +1,53 @@ + '', + ]); + validate(EnterprisePortraitCategoryValidate::class)->check($params, 'save'); + return success($service->saveData($params)); + } + + public function update(EnterprisePortraitCategoryService $service): Response + { + $params = requestOnly([ + 'id' => '', + 'name' => '', + ]); + validate(EnterprisePortraitCategoryValidate::class)->check($params, 'update'); + return success($service->updateData(ArrayUtils::filterNotEmpty($params))); + } + + public function index(EnterprisePortraitCategoryService $service): Response + { + $params = requestOnly([ + 'name' => '', + 'begin_time' => '', + 'end_time' => '' + ]); + return success($service->listData($params)); + } + + public function read(EnterprisePortraitCategoryService $service): Response + { + $id = input('id'); + return success($service->readData($id)); + } + + public function delete(EnterprisePortraitCategoryService $service): Response + { + $id = input('id'); + return success($service->deleteData($id)); + } + + +} \ No newline at end of file diff --git a/app/controller/EnterprisePortraitLibraryController.php b/app/controller/EnterprisePortraitLibraryController.php new file mode 100644 index 0000000..e484f93 --- /dev/null +++ b/app/controller/EnterprisePortraitLibraryController.php @@ -0,0 +1,39 @@ + '', + 'url' => '', + ]); + validate(EnterprisePortraitLibraryValidate::class)->check($params, 'save'); + return success($service->saveData($params)); + } + + public function index(EnterprisePortraitLibraryService $service): Response + { + $params = requestOnly([ + 'category_id' => '', + 'category' => '', + 'use_count' => '', + 'begin_time' => '', + 'end_time' => '' + ]); + return success($service->listData($params)); + } + + public function delete(EnterprisePortraitLibraryService $service): Response + { + $id = input('id'); + return success($service->deleteData($id)); + } + + +} \ No newline at end of file diff --git a/app/dao/EnterprisePortraitCategoryDao.php b/app/dao/EnterprisePortraitCategoryDao.php new file mode 100644 index 0000000..40492ed --- /dev/null +++ b/app/dao/EnterprisePortraitCategoryDao.php @@ -0,0 +1,15 @@ +hasMany(EnterprisePortraitLibrary::class, 'category_id', 'id'); + } +} \ No newline at end of file diff --git a/app/model/EnterprisePortraitLibrary.php b/app/model/EnterprisePortraitLibrary.php new file mode 100644 index 0000000..197fb81 --- /dev/null +++ b/app/model/EnterprisePortraitLibrary.php @@ -0,0 +1,37 @@ +belongsTo(EnterprisePortraitCategory::class, 'category_id', 'id'); + } +} \ No newline at end of file diff --git a/app/model/KnowLedgeLibrary.php b/app/model/KnowLedgeLibrary.php index 2bb29e8..5f28e1d 100644 --- a/app/model/KnowLedgeLibrary.php +++ b/app/model/KnowLedgeLibrary.php @@ -5,7 +5,7 @@ namespace app\model; use plugin\piadmin\app\base\BaseModel; /** - * 蒸馏词模型 + * 智能体知识库模型 */ class KnowLedgeLibrary extends BaseModel { diff --git a/app/route/route.php b/app/route/route.php index c1f86ea..beb57ca 100644 --- a/app/route/route.php +++ b/app/route/route.php @@ -1,6 +1,8 @@ setParams(['perm' => ['questionsSave']]); + Route::post('/save', [KnowledgeLibraryController::class, 'save'])->setParams(['perm' => ['knowledgeSave']]); //列表 - Route::get('/index', [KnowledgeLibraryController::class, 'index'])->setParams(['perm' => ['questionsIndex']]); + Route::get('/index', [KnowledgeLibraryController::class, 'index'])->setParams(['perm' => ['knowledgeIndex']]); //删除 - Route::post('/delete', [KnowledgeLibraryController::class, 'delete'])->setParams(['perm' => ['questionsDelete']]); + Route::post('/delete', [KnowledgeLibraryController::class, 'delete'])->setParams(['perm' => ['knowledgeDelete']]); + }); + + //企业画像图库 + Route::group('/enterprise', function () { + //分类 + Route::group('/category', function () { + //新增 + Route::post('/save', [EnterprisePortraitCategoryController::class, 'save'])->setParams(['perm' => ['enterpriseCategorySave']]); + //修改 + Route::post('/update', [EnterprisePortraitCategoryController::class, 'update'])->setParams(['perm' => ['enterpriseCategoryUpdate']]); + //列表 + Route::get('/index', [EnterprisePortraitCategoryController::class, 'index'])->setParams(['perm' => ['enterpriseCategoryIndex']]); + //详情 + Route::get('/read', [EnterprisePortraitCategoryController::class, 'read'])->setParams(['perm' => ['enterpriseCategoryRead']]); + //删除 + Route::post('/delete', [EnterprisePortraitCategoryController::class, 'delete'])->setParams(['perm' => ['enterpriseCategoryDelete']]); + }); + + //新增 + Route::post('/save', [EnterprisePortraitLIbraryController::class, 'save'])->setParams(['perm' => ['enterpriseLibrarySave']]); + //列表 + Route::get('/index', [EnterprisePortraitLIbraryController::class, 'index'])->setParams(['perm' => ['enterpriseLibraryIndex']]); + //删除 + Route::post('/delete', [EnterprisePortraitLIbraryController::class, 'delete'])->setParams(['perm' => ['enterpriseLibraryDelete']]); }); })->middleware([ AdminAuthorizationMiddleware::class, diff --git a/app/service/EnterprisePortraitCategoryService.php b/app/service/EnterprisePortraitCategoryService.php new file mode 100644 index 0000000..1e8806d --- /dev/null +++ b/app/service/EnterprisePortraitCategoryService.php @@ -0,0 +1,120 @@ +dao = $dao; + $this->libraryDao = app()->make(EnterprisePortraitLibraryDao::class); + } + + /** + * 保存信息 + * @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 updateData(array $params): array + { + // 落库 + Db::startTrans(); + try { + $this->dao->update(['id' => $params['id']], $params); + Db::commit(); + } catch (\Exception $exception) { + Db::rollback(); + throw new ApiException($exception->getMessage()); + } + return $params; + } + + /** + * 获取列表 + * @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, '*', 0, 0, 'id DESC', [], ['files']); + $count = $this->dao->getCount($query); + return compact('list', 'count'); + } + + /** + * 获取信息 + * @param mixed $id + * @return array + */ + public function readData(mixed $id): array + { + $category = $this->dao->get(['id' => $id]); + if (empty($category)) { + throw new ApiException('数据不存在'); + } + return $category->toArray(); + } + + /** + * 删除信息 + * @param mixed $id + * @return array + */ + public function deleteData(mixed $id): array + { + // 落库 + Db::startTrans(); + try { + //删除表 + $this->dao->update($id, ['delete_time' => time()]); + //删图库 + $this->libraryDao->update(['category_id' => $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/service/EnterprisePortraitLibraryService.php b/app/service/EnterprisePortraitLibraryService.php new file mode 100644 index 0000000..955b3a7 --- /dev/null +++ b/app/service/EnterprisePortraitLibraryService.php @@ -0,0 +1,92 @@ +dao = $dao; + $this->categoryDao = app()->make(EnterprisePortraitCategoryDao::class); + } + + /** + * 保存信息 + * @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['category_id']) && empty($params['category'])) { + $query[] = ['category_id', '=', $params['category_id']]; + } + if (isNotBlank($params['category'])) { + $cids = $this->categoryDao->getColumn([['name', 'like', '%' . $params['category'] . '%']], 'id'); + $query[] = ['category_id', 'in', $cids]; + } + if (isNotBlank($params['use_count'])) { + $query[] = ['use_count', '=', $params['use_count']]; + } + 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, '*', 0, 0, 'id desc', ['category']); + $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/EnterprisePortraitCategoryValidate.php b/app/validate/EnterprisePortraitCategoryValidate.php new file mode 100644 index 0000000..042d8c0 --- /dev/null +++ b/app/validate/EnterprisePortraitCategoryValidate.php @@ -0,0 +1,22 @@ + [ + 'name' => 'require', + ], + 'update' => [ + 'id' => 'require', + 'name' => 'require', + ] + ]; + protected $message = [ + 'id.require' => 'ID不能为空', + 'name.require' => '分类不能为空', + ]; +} \ No newline at end of file diff --git a/app/validate/EnterprisePortraitLibraryValidate.php b/app/validate/EnterprisePortraitLibraryValidate.php new file mode 100644 index 0000000..16fb630 --- /dev/null +++ b/app/validate/EnterprisePortraitLibraryValidate.php @@ -0,0 +1,19 @@ + [ + 'category_id' => 'require', + 'url' => 'require', + ], + ]; + protected $message = [ + 'category_id.require' => '分类ID不能为空', + 'url.require' => '图片地址不能为空', + ]; +} \ No newline at end of file