Compare commits

..

10 Commits

Author SHA1 Message Date
Aether
c21362da54 。。 2025-10-17 15:42:10 +08:00
Aether
9052c7069f .. 2025-10-16 20:06:23 +08:00
Aether
6ab9bd6198 .. 2025-10-15 17:10:03 +08:00
Aether
0532bcba4b .. 2025-10-15 15:16:25 +08:00
Aether
8f6d28162d .. 2025-10-14 15:14:59 +08:00
Aether
c5ad929f5a sync.sh 2025-10-14 14:38:46 +08:00
Aether
fb958bc065 . 2025-10-13 17:46:08 +08:00
Aether
861b30ea00 .. 2025-10-11 17:22:33 +08:00
Aether
e7aaf5ba6c .. 2025-10-10 19:38:16 +08:00
Aether
25284c8d0e .. 2025-10-10 17:17:55 +08:00
19 changed files with 542 additions and 432 deletions

View File

@@ -1,52 +0,0 @@
# Dev Container Dockerfile
#
# @link https://www.hyperf.io
# @document https://hyperf.wiki
# @contact group@hyperf.io
# @license https://github.com/hyperf/hyperf/blob/master/LICENSE
FROM hyperf/hyperf:8.3-alpine-v3.19-swoole
LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT" app.name="Hyperf"
##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone
ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
APP_ENV=dev \
SCAN_CACHEABLE=(false)
# update
RUN set -ex \
# show php version and extensions
&& php -v \
&& php -m \
&& php --ri swoole \
# ---------- some config ----------
&& cd /etc/php* \
# - config PHP
&& { \
echo "upload_max_filesize=128M"; \
echo "post_max_size=128M"; \
echo "memory_limit=1G"; \
echo "date.timezone=${TIMEZONE}"; \
} | tee conf.d/99_overrides.ini \
# - config timezone
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
# ---------- clear works ----------
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
WORKDIR /opt/www
# Composer Cache
# COPY ./composer.* /opt/www/
# RUN composer install --no-dev --no-scripts
COPY . /opt/www
RUN composer install && php bin/hyperf.php
EXPOSE 9501

View File

@@ -1,7 +0,0 @@
{
"build": {
"context": "..",
"dockerfile": "./Dockerfile"
},
"forwardPorts": [9501]
}

21
.env
View File

@@ -2,11 +2,11 @@ APP_NAME=hyperf-data
APP_ENV=prod APP_ENV=prod
DB_DRIVER=mysql DB_DRIVER=mysql
DB_HOST=localhost DB_HOST=192.168.28.199
DB_PORT=3306 DB_PORT=3306
DB_DATABASE=hyperf_data DB_DATABASE=dhd_official
DB_USERNAME=hyperf_data DB_USERNAME=dhd_official
DB_PASSWORD=4cfDRXZSksn7npiP DB_PASSWORD=123456
DB_CHARSET=utf8mb4 DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci DB_COLLATION=utf8mb4_unicode_ci
DB_PREFIX= DB_PREFIX=
@@ -18,12 +18,11 @@ REDIS_DB=0
JSON_RPC_HOST=0.0.0.0 JSON_RPC_HOST=0.0.0.0
JSON_RPC_PORT=9666 JSON_RPC_PORT=9666
SWOOLE_WORKER_NUM=1
NACOS_HOST=192.168.28.199 NACOS_HOST=192.168.28.218
NACOS_PORT=8848 NACOS_PORT=8848
NACOS_USERNAME=nacos # NACOS_USERNAME=nacos
NACOS_PASSWORD=nacos # NACOS_PASSWORD=nacos
NACOS_NAMESPACE_ID=e42b853c-5195-478b-b5e3-6d49f6a45053 NACOS_NAMESPACE_ID=b373566c-00e8-49bf-b5dd-6bc0ebe2be16
NACOS_GROUP=api NACOS_GROUP=dev
NACOS_SERVICE_NAME=DataCampusService NACOS_SERVICE_NAME=DataService

View File

@@ -1,54 +0,0 @@
# Default Dockerfile
#
# @link https://www.hyperf.io
# @document https://hyperf.wiki
# @contact group@hyperf.io
# @license https://github.com/hyperf/hyperf/blob/master/LICENSE
FROM hyperf/hyperf:8.3-alpine-v3.19-swoole
LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT" app.name="Hyperf"
##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone
ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
APP_ENV=prod \
SCAN_CACHEABLE=(true)
# update
RUN set -ex \
# show php version and extensions
&& php -v \
&& php -m \
&& php --ri swoole \
# ---------- some config ----------
&& cd /etc/php* \
# - config PHP
&& { \
echo "upload_max_filesize=128M"; \
echo "post_max_size=128M"; \
echo "memory_limit=1G"; \
echo "date.timezone=${TIMEZONE}"; \
} | tee conf.d/99_overrides.ini \
# - config timezone
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
# ---------- clear works ----------
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
WORKDIR /opt/www
# Composer Cache
# COPY ./composer.* /opt/www/
# RUN composer install --no-dev --no-scripts
COPY . /opt/www
RUN print "\n" | composer install -o && php bin/hyperf.php
EXPOSE 9501
ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"]

View File

@@ -1,12 +0,0 @@
name: Build Docker
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build
run: cp -rf .github/workflows/Dockerfile . && docker build -t hyperf .

View File

@@ -1,25 +0,0 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
name: Release
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

View File

@@ -0,0 +1,58 @@
<?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\Campus;
use App\Validator\CampusValidator;
use Hyperf\Di\Annotation\Inject;
class CampusService extends AetherCrudService
{
#[Inject]
protected Campus $campusModel;
#[Inject]
protected CampusValidator $campusValidator;
/**
* 获取省份列表.
*/
public function getProvinces(): array
{
return $this->campusModel->level(1)
->enabled()
->orderBy('name')
->get(['id', 'name', 'province'])
->toArray();
}
/**
* 根据省份获取城市列表.
* @throws BusinessException
*/
public function getCitiesByProvince(string $province): array
{
return $this->campusModel->level(2)
->province($province)
->enabled()
->orderBy('name')
->get(['id', 'name', 'city'])
->toArray();
}
protected function getModel(): AetherModel
{
return $this->campusModel;
}
protected function getValidator(): AetherValidator
{
return $this->campusValidator;
}
}

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace App\JsonRpc\Service; namespace App\JsonRpc\Service;
use Aether\AetherModel;
use Aether\AetherValidator;
use Aether\Exception\BusinessException; use Aether\Exception\BusinessException;
use App\Exception\CampusNotFound; use App\Exception\CampusNotFound;
use App\Exception\TeacherNotFound; use App\Exception\TeacherNotFound;
@@ -11,10 +13,10 @@ use App\Model\Campus;
use App\Model\Teacher; use App\Model\Teacher;
use App\Validator\CampusValidator; use App\Validator\CampusValidator;
use App\Validator\TeacherValidator; use App\Validator\TeacherValidator;
use DHD\Contract\DataServiceInterface;
use Exception; use Exception;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\RpcServer\Annotation\RpcService; use Hyperf\RpcServer\Annotation\RpcService;
use MicroService\Contract\DataServiceInterface;
#[RpcService(name: 'DataService', server: 'jsonrpc-http', protocol: 'jsonrpc-http', publishTo: 'nacos')] #[RpcService(name: 'DataService', server: 'jsonrpc-http', protocol: 'jsonrpc-http', publishTo: 'nacos')]
class DataService implements DataServiceInterface class DataService implements DataServiceInterface
@@ -31,6 +33,12 @@ class DataService implements DataServiceInterface
#[Inject] #[Inject]
protected TeacherValidator $teacherValidator; protected TeacherValidator $teacherValidator;
#[Inject]
protected CampusService $campusService;
#[Inject]
protected TeacherService $teacherService;
/** /**
* 获取校区列表. * 获取校区列表.
*/ */
@@ -108,6 +116,19 @@ class DataService implements DataServiceInterface
->toArray(); ->toArray();
} }
public function getCampusByIds(array $ids): array
{
if (empty($ids)) {
return [];
}
return $this->campusModel
->whereIn('id', $ids)
->where('status', 1)
->get()
->keyBy('id')
->toArray();
}
/** /**
* 获取教师列表. * 获取教师列表.
*/ */
@@ -158,4 +179,14 @@ class DataService implements DataServiceInterface
{ {
return $this->teacherModel->deleteById($id); return $this->teacherModel->deleteById($id);
} }
protected function getModel(): AetherModel
{
return $this->campusModel;
}
protected function getValidator(): AetherValidator
{
return $this->teacherValidator;
}
} }

View File

@@ -0,0 +1,28 @@
<?php
namespace App\JsonRpc\Service;
use Aether\AetherCrudService;
use Aether\AetherModel;
use Aether\AetherValidator;
use App\Model\Teacher;
use App\Validator\TeacherValidator;
use Hyperf\Di\Annotation\Inject;
class TeacherService extends AetherCrudService
{
#[Inject]
protected Teacher $teacherModel;
#[Inject]
protected TeacherValidator $teacherValidator;
protected function getModel(): AetherModel
{
return $this->teacherModel;
}
protected function getValidator(): AetherValidator
{
return $this->teacherValidator;
}
}

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\Model; namespace App\Model;
use Aether\AetherModel; use Aether\AetherModel;
use Aether\Contract\TreeableInterface;
use Aether\Traits\AetherTree;
use Carbon\Carbon; use Carbon\Carbon;
use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Relations\BelongsTo; use Hyperf\Database\Model\Relations\BelongsTo;
@@ -26,8 +28,9 @@ use Hyperf\Database\Model\Relations\HasMany;
* @property Carbon $updated_at * @property Carbon $updated_at
* @property Carbon $deleted_at * @property Carbon $deleted_at
*/ */
class Campus extends AetherModel class Campus extends AetherModel implements TreeableInterface
{ {
use AetherTree;
protected ?string $table = 'da_campus'; protected ?string $table = 'da_campus';
protected array $fillable = [ protected array $fillable = [
@@ -52,10 +55,12 @@ class Campus extends AetherModel
]; ];
protected array $search = [ protected array $search = [
'name' => 'like',
'level' => '=', 'level' => '=',
'parent_id' => '=', 'parent_id' => '=',
'city' => 'like', 'city' => 'like',
'province' => 'like', 'province' => 'like',
'status' => '=',
]; ];
protected array|bool|string $sortable = false; protected array|bool|string $sortable = false;
@@ -119,4 +124,14 @@ class Campus extends AetherModel
->where('status', 1) ->where('status', 1)
->whereNull('deleted_at'); ->whereNull('deleted_at');
} }
protected function getParentIdField(): string
{
return 'parent_id';
}
protected function getSortField(): string
{
return '';
}
} }

View File

@@ -22,7 +22,7 @@ use Hyperf\Database\Model\Relations\BelongsTo;
* @property string $introduction 教师简介 * @property string $introduction 教师简介
* @property int $campus_id 所属校区ID * @property int $campus_id 所属校区ID
* @property int $status 状态0-禁用1-启用 * @property int $status 状态0-禁用1-启用
* @property int $sort_order 排序 * @property int $sort 排序
* @property Carbon $created_at * @property Carbon $created_at
* @property Carbon $updated_at * @property Carbon $updated_at
* @property Carbon $deleted_at * @property Carbon $deleted_at

View File

@@ -32,7 +32,7 @@ class CampusValidator extends AetherValidator
], ],
'update' => [ 'update' => [
'rules' => [ 'rules' => [
'id' => 'required|integer|min:1', // 'id' => 'required|integer|min:1',
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'parent_id' => 'nullable|integer|min:0', 'parent_id' => 'nullable|integer|min:0',
'level' => 'nullable|integer|in:1,2,3', 'level' => 'nullable|integer|in:1,2,3',
@@ -41,7 +41,7 @@ class CampusValidator extends AetherValidator
'address' => 'nullable|string|max:500', 'address' => 'nullable|string|max:500',
], ],
'messages' => [ 'messages' => [
'id.required' => '校区ID不能为空', // 'id.required' => '校区ID不能为空',
'name.required' => '校区名称不能为空', 'name.required' => '校区名称不能为空',
'level.in' => '层级只能是1、2、3', 'level.in' => '层级只能是1、2、3',
], ],

View File

@@ -32,7 +32,7 @@ class TeacherValidator extends AetherValidator
], ],
'update' => [ 'update' => [
'rules' => [ 'rules' => [
'id' => 'required|integer|min:1', // 'id' => 'required|integer|min:1',
'name' => 'nullable|string|max:50', 'name' => 'nullable|string|max:50',
'age' => 'nullable|integer|min:18|max:65', 'age' => 'nullable|integer|min:18|max:65',
'gender' => 'nullable|integer|in:1,2', 'gender' => 'nullable|integer|in:1,2',
@@ -41,7 +41,7 @@ class TeacherValidator extends AetherValidator
'teach_subject' => 'nullable|string|max:100', 'teach_subject' => 'nullable|string|max:100',
], ],
'messages' => [ 'messages' => [
'id.required' => '教师ID不能为空', // 'id.required' => '教师ID不能为空',
'age.min' => '年龄不能小于18岁', 'age.min' => '年龄不能小于18岁',
'age.max' => '年龄不能大于65岁', 'age.max' => '年龄不能大于65岁',
'gender.in' => '性别只能是1(男)或2(女)', 'gender.in' => '性别只能是1(男)或2(女)',

View File

@@ -14,6 +14,7 @@
"require": { "require": {
"php": ">=8.1", "php": ">=8.1",
"aether/hyperf": "dev-master", "aether/hyperf": "dev-master",
"dhd/contract": "dev-master",
"hyperf/cache": "~3.1.0", "hyperf/cache": "~3.1.0",
"hyperf/command": "~3.1.0", "hyperf/command": "~3.1.0",
"hyperf/config": "~3.1.0", "hyperf/config": "~3.1.0",
@@ -52,6 +53,10 @@
{ {
"type": "git", "type": "git",
"url": "https://gitee.com/devAether666/aether-hyperf.git" "url": "https://gitee.com/devAether666/aether-hyperf.git"
},
{
"type": "git",
"url": "https://gitee.com/devAether666/dhd-contract.git"
} }
], ],
"suggest": { "suggest": {
@@ -63,8 +68,7 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "app/", "App\\": "app/"
"MicroService\\": "extend/MicroService/src/"
}, },
"files": [] "files": []
}, },

579
composer.lock generated Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,8 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use Aether\Exception\Handler\ApiExceptionHandler;
use Aether\Exception\Handler\JsonRpcExceptionHandler;
use Aether\Middleware\RequestId; use Aether\Middleware\RequestId;
/* /*
@@ -16,6 +18,5 @@ return [
'http' => [ 'http' => [
], ],
'jsonrpc-http' => [ 'jsonrpc-http' => [
RequestId::class,
], ],
]; ];

View File

@@ -24,9 +24,10 @@ return [
'guzzle' => [ 'guzzle' => [
'config' => null, 'config' => null,
], ],
'group_name' => env('NACOS_GROUP', 'DEFAULT_GROUP'), 'group_name' => env('NACOS_GROUP', 'dev'),
'namespace_id' => env('NACOS_NAMESPACE', 'dev'), 'namespace_id' => env('NACOS_NAMESPACE_ID', 'namespace_id'),
'heartbeat' => 5, 'heartbeat' => 5,
'ephemeral' => true,
], ],
], ],
]; ];

View File

@@ -1,43 +0,0 @@
<?php
declare(strict_types=1);
namespace MicroService\Contract;
interface DataServiceInterface
{
// ----------------- 校区服务 -----------------
public function getCampuses(array $data): array;
public function getCampusBy(int $id): array;
public function createCampus(array $data): int;
public function updateCampus(int $id, array $data): int;
public function deleteCampus(int $id): bool;
/**
* 获取省份列表.
*/
public function getProvinces(): array;
/**
* 根据省份获取城市列表.
* @param string $province 省份名称
*/
public function getCitiesByProvince(string $province): array;
// ----------------- 教师服务 -----------------
public function getTeachers(array $data): array;
public function getTeacherBy(int $id): array;
public function createTeacher(array $data): int;
public function updateTeacher(int $id, array $data): int;
public function deleteTeacher(int $id): bool;
}

19
sync.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
rsync -avz \
--exclude='.git' \
--exclude='.env' \
--exclude='.idea' \
--exclude='runtime' \
--delete \
/home/aether/work/hyperf_data/ \
root@192.168.28.199:/www/wwwroot/dhd_hyperf/hyperf_data/
# 执行成功后提示
if [ $? -eq 0 ]; then
echo "------------------------"
echo "同步完成!代码已部署到服务器"
else
echo "------------------------"
echo "同步失败,请检查错误信息"
fi