..
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\JsonRpc\Service;
|
||||
|
||||
use Aether\AetherCrudService;
|
||||
use Aether\AetherModel;
|
||||
use Aether\AetherValidator;
|
||||
use Aether\Exception\BusinessException;
|
||||
use App\Model\Teacher;
|
||||
use App\Validator\TeacherValidator;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
use MicroService\Contract\TeacherServiceInterface;
|
||||
|
||||
#[RpcService(
|
||||
name: 'DataTeacher',
|
||||
server: 'jsonrpc-http',
|
||||
protocol: 'jsonrpc-http',
|
||||
publishTo: 'nacos'
|
||||
)]
|
||||
class TeacherService extends AetherCrudService implements TeacherServiceInterface
|
||||
{
|
||||
#[Inject]
|
||||
protected Teacher $model;
|
||||
|
||||
#[Inject]
|
||||
protected TeacherValidator $validator;
|
||||
|
||||
public function getTeacherById(int $id): array
|
||||
{
|
||||
$teacher = Teacher::find($id);
|
||||
if (! $teacher || $teacher->status != 1) {
|
||||
throw new BusinessException('教师不存在或已禁用', 10101);
|
||||
}
|
||||
return $teacher->toArray();
|
||||
}
|
||||
|
||||
public function getTeachersByIds(array $ids): array
|
||||
{
|
||||
return Teacher::whereIn('id', $ids)
|
||||
->enabled()
|
||||
->orderBy('sort_order', 'asc')
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getTeachersByCampusId(int $campusId, int $page = 1, int $size = 20): array
|
||||
{
|
||||
$query = Teacher::campusId($campusId)
|
||||
->enabled()
|
||||
->orderBy('sort_order', 'asc');
|
||||
|
||||
$total = $query->count();
|
||||
$list = $query->forPage($page, $size)->get()->toArray();
|
||||
|
||||
return [
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'list' => $list,
|
||||
];
|
||||
}
|
||||
|
||||
public function getTeachersBySubject(string $subject, int $page = 1, int $size = 20): array
|
||||
{
|
||||
$query = Teacher::subject($subject)
|
||||
->enabled()
|
||||
->orderBy('sort_order', 'asc');
|
||||
|
||||
$total = $query->count();
|
||||
$list = $query->forPage($page, $size)->get()->toArray();
|
||||
|
||||
return [
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'list' => $list,
|
||||
];
|
||||
}
|
||||
|
||||
public function searchTeachers(string $keyword, int $page = 1, int $size = 20): array
|
||||
{
|
||||
$query = Teacher::search($keyword)
|
||||
->enabled()
|
||||
->orderBy('sort_order', 'asc');
|
||||
|
||||
$total = $query->count();
|
||||
$list = $query->forPage($page, $size)->get()->toArray();
|
||||
|
||||
return [
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'list' => $list,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getModel(): AetherModel
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
protected function getValidator(): AetherValidator
|
||||
{
|
||||
return $this->validator;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user