Browse Source

feat(ai): 新增AI创作指令管理功能

- 新增AI创作指令模型AiCommand及对应数据表gro_ai_command
- 实现指令的增删改查接口,支持按名称、类型、时间范围筛选
- 添加指令校验规则,确保必填字段完整性
- 集成权限控制,为指令管理分配独立权限点
- 优化企业画像分类与精华词库查询逻辑,关联文件与问题详情
master
zhangf@suq.cn 1 week ago
parent
commit
45ee7a9d44
  1. 58
      app/controller/AiCommandController.php
  2. 15
      app/dao/AiCommandDao.php
  3. 33
      app/model/AiCommand.php
  4. 15
      app/route/route.php
  5. 117
      app/service/AiCommandService.php
  6. 2
      app/service/DistillationWordService.php
  7. 2
      app/service/EnterprisePortraitCategoryService.php
  8. 28
      app/validate/AiCommandValidate.php

58
app/controller/AiCommandController.php

@ -0,0 +1,58 @@
<?php
namespace app\controller;
use app\service\AiCommandService;
use app\validate\AiCommandValidate;
use plugin\piadmin\app\utils\ArrayUtils;
use support\Response;
class AiCommandController
{
public function save(AiCommandService $service): Response
{
$params = requestOnly([
'name' => '',
'type' => '',
'content' => ''
]);
validate(AiCommandValidate::class)->check($params, 'save');
return success($service->saveData($params));
}
public function update(AiCommandService $service): Response
{
$params = requestOnly([
'id' => '',
'name' => '',
'type' => '',
'content' => ''
]);
validate(AiCommandValidate::class)->check($params, 'update');
return success($service->updateData(ArrayUtils::filterNotEmpty($params)));
}
public function index(AiCommandService $service): Response
{
$params = requestOnly([
'name' => '',
'type' => '',
'begin_time' => '',
'end_time' => ''
]);
return success($service->listData($params));
}
public function read(AiCommandService $service): Response
{
$id = input('id');
return success($service->readData($id));
}
public function delete(AiCommandService $service): Response
{
$id = input('id');
return success($service->deleteData($id));
}
}

15
app/dao/AiCommandDao.php

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

33
app/model/AiCommand.php

@ -0,0 +1,33 @@
<?php
namespace app\model;
use plugin\piadmin\app\base\BaseModel;
/**
* AI创作指令模型
*/
class AiCommand extends BaseModel
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'gro_ai_command';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
}

15
app/route/route.php

@ -78,6 +78,21 @@ Route::group('/service/v1', function () {
//删除
Route::post('/delete', [EnterprisePortraitLIbraryController::class, 'delete'])->setParams(['perm' => ['enterpriseLibraryDelete']]);
});
//AI创作指令
Route::group('/aiCommand', function () {
//新增
Route::post('/save', [AiCommandController::class, 'save'])->setParams(['perm' => ['aiCommandSave']]);
//修改
Route::post('/update', [AiCommandController::class, 'update'])->setParams(['perm' => ['aiCommandUpdate']]);
//列表
Route::get('/index', [AiCommandController::class, 'index'])->setParams(['perm' => ['aiCommandIndex']]);
//详情
Route::get('/read', [AiCommandController::class, 'read'])->setParams(['perm' => ['aiCommandRead']]);
//删除
Route::post('/delete', [AiCommandController::class, 'delete'])->setParams(['perm' => ['aiCommandDelete']]);
});
})->middleware([
AdminAuthorizationMiddleware::class,
PermissionsMiddleware::class

117
app/service/AiCommandService.php

@ -0,0 +1,117 @@
<?php
namespace app\service;
use app\dao\AiCommandDao;
use plugin\piadmin\app\base\BaseService;
use plugin\piadmin\app\exception\ApiException;
use support\think\Db;
class AiCommandService extends BaseService
{
protected $dao;
public function __construct(AiCommandDao $dao)
{
$this->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 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['type'])) {
$query[] = ['type', '=', $params['type']];
}
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, 'id,name,type,create_time');
$count = $this->dao->getCount($query);
return compact('list', 'count');
}
/**
* 获取信息
* @param mixed $id
* @return array
*/
public function readData(mixed $id): array
{
$aiCommand = $this->dao->get(['id' => $id]);
if (empty($aiCommand)) {
throw new ApiException('数据不存在');
}
return $aiCommand->toArray();
}
/**
* 删除信息
* @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];
}
}

2
app/service/DistillationWordService.php

@ -178,7 +178,7 @@ class DistillationWordService extends BaseService
$query = [
'delete_time' => 0
];
$list = $this->dao->getList($query);
$list = $this->dao->getList($query, '*', 0, 0, 'id DESC', [], ['questions']);
return $list;
}
}

2
app/service/EnterprisePortraitCategoryService.php

@ -122,7 +122,7 @@ class EnterprisePortraitCategoryService extends BaseService
$query = [
'delete_time' => 0
];
$list = $this->dao->getList($query);
$list = $this->dao->getList($query, '*', 0, 0, 'id DESC', [], ['files']);
return $list;
}
}

28
app/validate/AiCommandValidate.php

@ -0,0 +1,28 @@
<?php
namespace app\validate;
use plugin\piadmin\app\base\BaseValidate;
class AiCommandValidate extends BaseValidate
{
protected $group = [
'save' => [
'name' => 'require',
'type' => 'require',
'content' => 'require',
],
'update' => [
'id' => 'require',
'name' => 'require',
'type' => 'require',
'content' => 'require',
],
];
protected $message = [
'id.require' => '指令ID不能为空',
'name.require' => '指令名称不能为空',
'type.require' => '写作类型不能为空',
'content.require' => '指令内容不能为空'
];
}
Loading…
Cancel
Save