Browse Source
feat(ai): 新增AI创作指令管理功能
feat(ai): 新增AI创作指令管理功能
- 新增AI创作指令模型AiCommand及对应数据表gro_ai_command - 实现指令的增删改查接口,支持按名称、类型、时间范围筛选 - 添加指令校验规则,确保必填字段完整性 - 集成权限控制,为指令管理分配独立权限点 - 优化企业画像分类与精华词库查询逻辑,关联文件与问题详情master
8 changed files with 268 additions and 2 deletions
-
58app/controller/AiCommandController.php
-
15app/dao/AiCommandDao.php
-
33app/model/AiCommand.php
-
15app/route/route.php
-
117app/service/AiCommandService.php
-
2app/service/DistillationWordService.php
-
2app/service/EnterprisePortraitCategoryService.php
-
28app/validate/AiCommandValidate.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)); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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; |
||||
|
|
||||
|
} |
||||
@ -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]; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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' => '指令内容不能为空' |
||||
|
]; |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue