Compare commits
10 Commits
3415f75673
...
c21362da54
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c21362da54 | ||
|
|
9052c7069f | ||
|
|
6ab9bd6198 | ||
|
|
0532bcba4b | ||
|
|
8f6d28162d | ||
|
|
c5ad929f5a | ||
|
|
fb958bc065 | ||
|
|
861b30ea00 | ||
|
|
e7aaf5ba6c | ||
|
|
25284c8d0e |
@@ -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
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"build": {
|
||||
"context": "..",
|
||||
"dockerfile": "./Dockerfile"
|
||||
},
|
||||
"forwardPorts": [9501]
|
||||
}
|
||||
21
.env
21
.env
@@ -2,11 +2,11 @@ APP_NAME=hyperf-data
|
||||
APP_ENV=prod
|
||||
|
||||
DB_DRIVER=mysql
|
||||
DB_HOST=localhost
|
||||
DB_HOST=192.168.28.199
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=hyperf_data
|
||||
DB_USERNAME=hyperf_data
|
||||
DB_PASSWORD=4cfDRXZSksn7npiP
|
||||
DB_DATABASE=dhd_official
|
||||
DB_USERNAME=dhd_official
|
||||
DB_PASSWORD=123456
|
||||
DB_CHARSET=utf8mb4
|
||||
DB_COLLATION=utf8mb4_unicode_ci
|
||||
DB_PREFIX=
|
||||
@@ -18,12 +18,11 @@ REDIS_DB=0
|
||||
|
||||
JSON_RPC_HOST=0.0.0.0
|
||||
JSON_RPC_PORT=9666
|
||||
SWOOLE_WORKER_NUM=1
|
||||
|
||||
NACOS_HOST=192.168.28.199
|
||||
NACOS_HOST=192.168.28.218
|
||||
NACOS_PORT=8848
|
||||
NACOS_USERNAME=nacos
|
||||
NACOS_PASSWORD=nacos
|
||||
NACOS_NAMESPACE_ID=e42b853c-5195-478b-b5e3-6d49f6a45053
|
||||
NACOS_GROUP=api
|
||||
NACOS_SERVICE_NAME=DataCampusService
|
||||
# NACOS_USERNAME=nacos
|
||||
# NACOS_PASSWORD=nacos
|
||||
NACOS_NAMESPACE_ID=b373566c-00e8-49bf-b5dd-6bc0ebe2be16
|
||||
NACOS_GROUP=dev
|
||||
NACOS_SERVICE_NAME=DataService
|
||||
54
.github/workflows/Dockerfile
vendored
54
.github/workflows/Dockerfile
vendored
@@ -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"]
|
||||
12
.github/workflows/build.yml
vendored
12
.github/workflows/build.yml
vendored
@@ -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 .
|
||||
25
.github/workflows/release.yml
vendored
25
.github/workflows/release.yml
vendored
@@ -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
|
||||
58
app/JsonRpc/Service/CampusService.php
Normal file
58
app/JsonRpc/Service/CampusService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\JsonRpc\Service;
|
||||
|
||||
use Aether\AetherModel;
|
||||
use Aether\AetherValidator;
|
||||
use Aether\Exception\BusinessException;
|
||||
use App\Exception\CampusNotFound;
|
||||
use App\Exception\TeacherNotFound;
|
||||
@@ -11,10 +13,10 @@ use App\Model\Campus;
|
||||
use App\Model\Teacher;
|
||||
use App\Validator\CampusValidator;
|
||||
use App\Validator\TeacherValidator;
|
||||
use DHD\Contract\DataServiceInterface;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
use MicroService\Contract\DataServiceInterface;
|
||||
|
||||
#[RpcService(name: 'DataService', server: 'jsonrpc-http', protocol: 'jsonrpc-http', publishTo: 'nacos')]
|
||||
class DataService implements DataServiceInterface
|
||||
@@ -31,6 +33,12 @@ class DataService implements DataServiceInterface
|
||||
#[Inject]
|
||||
protected TeacherValidator $teacherValidator;
|
||||
|
||||
#[Inject]
|
||||
protected CampusService $campusService;
|
||||
|
||||
#[Inject]
|
||||
protected TeacherService $teacherService;
|
||||
|
||||
/**
|
||||
* 获取校区列表.
|
||||
*/
|
||||
@@ -108,6 +116,19 @@ class DataService implements DataServiceInterface
|
||||
->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);
|
||||
}
|
||||
|
||||
protected function getModel(): AetherModel
|
||||
{
|
||||
return $this->campusModel;
|
||||
}
|
||||
|
||||
protected function getValidator(): AetherValidator
|
||||
{
|
||||
return $this->teacherValidator;
|
||||
}
|
||||
}
|
||||
|
||||
28
app/JsonRpc/Service/TeacherService.php
Normal file
28
app/JsonRpc/Service/TeacherService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
use Aether\AetherModel;
|
||||
use Aether\Contract\TreeableInterface;
|
||||
use Aether\Traits\AetherTree;
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\Database\Model\Relations\BelongsTo;
|
||||
@@ -26,8 +28,9 @@ use Hyperf\Database\Model\Relations\HasMany;
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $deleted_at
|
||||
*/
|
||||
class Campus extends AetherModel
|
||||
class Campus extends AetherModel implements TreeableInterface
|
||||
{
|
||||
use AetherTree;
|
||||
protected ?string $table = 'da_campus';
|
||||
|
||||
protected array $fillable = [
|
||||
@@ -52,10 +55,12 @@ class Campus extends AetherModel
|
||||
];
|
||||
|
||||
protected array $search = [
|
||||
'name' => 'like',
|
||||
'level' => '=',
|
||||
'parent_id' => '=',
|
||||
'city' => 'like',
|
||||
'province' => 'like',
|
||||
'status' => '=',
|
||||
];
|
||||
|
||||
protected array|bool|string $sortable = false;
|
||||
@@ -119,4 +124,14 @@ class Campus extends AetherModel
|
||||
->where('status', 1)
|
||||
->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
protected function getParentIdField(): string
|
||||
{
|
||||
return 'parent_id';
|
||||
}
|
||||
|
||||
protected function getSortField(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use Hyperf\Database\Model\Relations\BelongsTo;
|
||||
* @property string $introduction 教师简介
|
||||
* @property int $campus_id 所属校区ID
|
||||
* @property int $status 状态:0-禁用,1-启用
|
||||
* @property int $sort_order 排序
|
||||
* @property int $sort 排序
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $deleted_at
|
||||
|
||||
@@ -32,7 +32,7 @@ class CampusValidator extends AetherValidator
|
||||
],
|
||||
'update' => [
|
||||
'rules' => [
|
||||
'id' => 'required|integer|min:1',
|
||||
// 'id' => 'required|integer|min:1',
|
||||
'name' => 'required|string|max:255',
|
||||
'parent_id' => 'nullable|integer|min:0',
|
||||
'level' => 'nullable|integer|in:1,2,3',
|
||||
@@ -41,7 +41,7 @@ class CampusValidator extends AetherValidator
|
||||
'address' => 'nullable|string|max:500',
|
||||
],
|
||||
'messages' => [
|
||||
'id.required' => '校区ID不能为空',
|
||||
// 'id.required' => '校区ID不能为空',
|
||||
'name.required' => '校区名称不能为空',
|
||||
'level.in' => '层级只能是1、2、3',
|
||||
],
|
||||
|
||||
@@ -32,7 +32,7 @@ class TeacherValidator extends AetherValidator
|
||||
],
|
||||
'update' => [
|
||||
'rules' => [
|
||||
'id' => 'required|integer|min:1',
|
||||
// 'id' => 'required|integer|min:1',
|
||||
'name' => 'nullable|string|max:50',
|
||||
'age' => 'nullable|integer|min:18|max:65',
|
||||
'gender' => 'nullable|integer|in:1,2',
|
||||
@@ -41,7 +41,7 @@ class TeacherValidator extends AetherValidator
|
||||
'teach_subject' => 'nullable|string|max:100',
|
||||
],
|
||||
'messages' => [
|
||||
'id.required' => '教师ID不能为空',
|
||||
// 'id.required' => '教师ID不能为空',
|
||||
'age.min' => '年龄不能小于18岁',
|
||||
'age.max' => '年龄不能大于65岁',
|
||||
'gender.in' => '性别只能是1(男)或2(女)',
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"aether/hyperf": "dev-master",
|
||||
"dhd/contract": "dev-master",
|
||||
"hyperf/cache": "~3.1.0",
|
||||
"hyperf/command": "~3.1.0",
|
||||
"hyperf/config": "~3.1.0",
|
||||
@@ -52,6 +53,10 @@
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://gitee.com/devAether666/aether-hyperf.git"
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://gitee.com/devAether666/dhd-contract.git"
|
||||
}
|
||||
],
|
||||
"suggest": {
|
||||
@@ -63,8 +68,7 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"MicroService\\": "extend/MicroService/src/"
|
||||
"App\\": "app/"
|
||||
},
|
||||
"files": []
|
||||
},
|
||||
|
||||
579
composer.lock
generated
Executable file → Normal file
579
composer.lock
generated
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
use Aether\Exception\Handler\ApiExceptionHandler;
|
||||
use Aether\Exception\Handler\JsonRpcExceptionHandler;
|
||||
use Aether\Middleware\RequestId;
|
||||
|
||||
/*
|
||||
@@ -16,6 +18,5 @@ return [
|
||||
'http' => [
|
||||
],
|
||||
'jsonrpc-http' => [
|
||||
RequestId::class,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -24,9 +24,10 @@ return [
|
||||
'guzzle' => [
|
||||
'config' => null,
|
||||
],
|
||||
'group_name' => env('NACOS_GROUP', 'DEFAULT_GROUP'),
|
||||
'namespace_id' => env('NACOS_NAMESPACE', 'dev'),
|
||||
'group_name' => env('NACOS_GROUP', 'dev'),
|
||||
'namespace_id' => env('NACOS_NAMESPACE_ID', 'namespace_id'),
|
||||
'heartbeat' => 5,
|
||||
'ephemeral' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -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
19
sync.sh
Executable 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
|
||||
Reference in New Issue
Block a user