Browse Source

feat(portrait): 新增企业画像图库功能

- 新增企业画像图库分类模型及控制器
- 新增企业画像图库模型及控制器
- 实现图库分类的增删改查功能
- 实现图库文件的增删查功能
- 添加相关验证规则和路由配置
- 更新知识库模型注释描述
- 修复路由权限标识错误问题
master
zhangf@suq.cn 1 week ago
parent
commit
b83b16f6fc
  1. 53
      app/controller/EnterprisePortraitCategoryController.php
  2. 39
      app/controller/EnterprisePortraitLibraryController.php
  3. 15
      app/dao/EnterprisePortraitCategoryDao.php
  4. 15
      app/dao/EnterprisePortraitLibraryDao.php
  5. 2
      app/model/DistillationQuestions.php
  6. 37
      app/model/EnterprisePortraitCategory.php
  7. 37
      app/model/EnterprisePortraitLibrary.php
  8. 2
      app/model/KnowLedgeLibrary.php
  9. 32
      app/route/route.php
  10. 120
      app/service/EnterprisePortraitCategoryService.php
  11. 92
      app/service/EnterprisePortraitLibraryService.php
  12. 22
      app/validate/EnterprisePortraitCategoryValidate.php
  13. 19
      app/validate/EnterprisePortraitLibraryValidate.php

53
app/controller/EnterprisePortraitCategoryController.php

@ -0,0 +1,53 @@
<?php
namespace app\controller;
use app\service\EnterprisePortraitCategoryService;
use app\validate\EnterprisePortraitCategoryValidate;
use plugin\piadmin\app\utils\ArrayUtils;
use support\Response;
class EnterprisePortraitCategoryController
{
public function save(EnterprisePortraitCategoryService $service): Response
{
$params = requestOnly([
'name' => '',
]);
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));
}
}

39
app/controller/EnterprisePortraitLibraryController.php

@ -0,0 +1,39 @@
<?php
namespace app\controller;
use app\service\EnterprisePortraitLibraryService;
use app\validate\EnterprisePortraitLibraryValidate;
use support\Response;
class EnterprisePortraitLibraryController
{
public function save(EnterprisePortraitLibraryService $service): Response
{
$params = requestOnly([
'category_id' => '',
'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));
}
}

15
app/dao/EnterprisePortraitCategoryDao.php

@ -0,0 +1,15 @@
<?php
namespace app\dao;
use app\model\EnterprisePortraitCategory;
use plugin\piadmin\app\base\BaseDao;
class EnterprisePortraitCategoryDao extends BaseDao
{
protected function setModel(): string
{
return EnterprisePortraitCategory::class;
}
}

15
app/dao/EnterprisePortraitLibraryDao.php

@ -0,0 +1,15 @@
<?php
namespace app\dao;
use app\model\EnterprisePortraitLibrary;
use plugin\piadmin\app\base\BaseDao;
class EnterprisePortraitLibraryDao extends BaseDao
{
protected function setModel(): string
{
return EnterprisePortraitLibrary::class;
}
}

2
app/model/DistillationQuestions.php

@ -5,7 +5,7 @@ namespace app\model;
use plugin\piadmin\app\base\BaseModel;
/**
* 蒸馏词关联目标转化词模型
* 蒸馏词关联拓展问题模型
*/
class DistillationQuestions extends BaseModel
{

37
app/model/EnterprisePortraitCategory.php

@ -0,0 +1,37 @@
<?php
namespace app\model;
use plugin\piadmin\app\base\BaseModel;
/**
* 企业画像图库-分类模型
*/
class EnterprisePortraitCategory extends BaseModel
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'geo_enterprise_portrait_category';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
public function files()
{
return $this->hasMany(EnterprisePortraitLibrary::class, 'category_id', 'id');
}
}

37
app/model/EnterprisePortraitLibrary.php

@ -0,0 +1,37 @@
<?php
namespace app\model;
use plugin\piadmin\app\base\BaseModel;
/**
* 企业画像图库模型
*/
class EnterprisePortraitLibrary extends BaseModel
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'geo_enterprise_portrait_library';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
public function category()
{
return $this->belongsTo(EnterprisePortraitCategory::class, 'category_id', 'id');
}
}

2
app/model/KnowLedgeLibrary.php

@ -5,7 +5,7 @@ namespace app\model;
use plugin\piadmin\app\base\BaseModel;
/**
* 蒸馏词模型
* 智能体知识库模型
*/
class KnowLedgeLibrary extends BaseModel
{

32
app/route/route.php

@ -1,6 +1,8 @@
<?php
use app\controller\DistillationQuestionsController;
use app\controller\EnterprisePortraitCategoryController;
use app\controller\EnterprisePortraitLibraryController;
use app\controller\KnowledgeLibraryController;
use app\controller\DistillationWordController;
use plugin\piadmin\app\middleware\AdminAuthorizationMiddleware;
@ -41,11 +43,35 @@ Route::group('/service/v1', function () {
//智能体知识库
Route::group('/knowledge', function () {
//新增
Route::post('/save', [KnowledgeLibraryController::class, 'save'])->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,

120
app/service/EnterprisePortraitCategoryService.php

@ -0,0 +1,120 @@
<?php
namespace app\service;
use app\dao\EnterprisePortraitCategoryDao;
use app\dao\EnterprisePortraitLibraryDao;
use plugin\piadmin\app\base\BaseService;
use plugin\piadmin\app\exception\ApiException;
use support\think\Db;
class EnterprisePortraitCategoryService extends BaseService
{
protected $dao;
protected $libraryDao;
public function __construct(EnterprisePortraitCategoryDao $dao)
{
$this->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];
}
}

92
app/service/EnterprisePortraitLibraryService.php

@ -0,0 +1,92 @@
<?php
namespace app\service;
use app\dao\EnterprisePortraitCategoryDao;
use app\dao\EnterprisePortraitLibraryDao;
use plugin\piadmin\app\base\BaseService;
use plugin\piadmin\app\exception\ApiException;
use support\think\Db;
class EnterprisePortraitLibraryService extends BaseService
{
protected $dao;
protected $categoryDao;
public function __construct(EnterprisePortraitLibraryDao $dao)
{
$this->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];
}
}

22
app/validate/EnterprisePortraitCategoryValidate.php

@ -0,0 +1,22 @@
<?php
namespace app\validate;
use plugin\piadmin\app\base\BaseValidate;
class EnterprisePortraitCategoryValidate extends BaseValidate
{
protected $group = [
'save' => [
'name' => 'require',
],
'update' => [
'id' => 'require',
'name' => 'require',
]
];
protected $message = [
'id.require' => 'ID不能为空',
'name.require' => '分类不能为空',
];
}

19
app/validate/EnterprisePortraitLibraryValidate.php

@ -0,0 +1,19 @@
<?php
namespace app\validate;
use plugin\piadmin\app\base\BaseValidate;
class EnterprisePortraitLibraryValidate extends BaseValidate
{
protected $group = [
'save' => [
'category_id' => 'require',
'url' => 'require',
],
];
protected $message = [
'category_id.require' => '分类ID不能为空',
'url.require' => '图片地址不能为空',
];
}
Loading…
Cancel
Save