mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-25 05:50:19 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ff58c4e6d | ||
|
|
ecef8ddd72 | ||
|
|
2f96e27adb | ||
|
|
10bd7e9485 | ||
|
|
f6fa4c3064 | ||
|
|
64a525133b | ||
|
|
485b9f32df | ||
|
|
dc6859f4f0 | ||
|
|
f861f2ba3f | ||
|
|
3a9b39b94b | ||
|
|
9a5d3461fe | ||
|
|
6add2094a6 | ||
|
|
843e5a9ad4 | ||
|
|
a8d41e289c | ||
|
|
3a591a5574 | ||
|
|
6076b4cde1 | ||
|
|
b158849d07 | ||
|
|
e4d448a661 | ||
|
|
42b51243a7 | ||
|
|
8dd87d0172 | ||
|
|
c92a94bdd2 | ||
|
|
c7ce98f1d5 | ||
|
|
6fb6ac2d6c | ||
|
|
fe539baa34 | ||
|
|
9aa7399484 | ||
|
|
eaa97e7eb8 | ||
|
|
dd7e37ef6e | ||
|
|
64c46118b0 | ||
|
|
bdc5f69ae0 | ||
|
|
35616394bc | ||
|
|
f463e76f5e | ||
|
|
fb7b57210a | ||
|
|
6ccd791574 | ||
|
|
13b12d80da | ||
|
|
571de25e81 | ||
|
|
08c2b02be9 | ||
|
|
6e0a3387cd | ||
|
|
c5f6e1262f | ||
|
|
27212da8df | ||
|
|
9d89d33701 | ||
|
|
5754979918 | ||
|
|
bf66fa386b | ||
|
|
e91338a2e6 | ||
|
|
58616d4927 | ||
|
|
2b2ac20feb | ||
|
|
7c11f8ab37 | ||
|
|
cc7fde9a27 | ||
|
|
ed56a73821 | ||
|
|
7e7fa6af65 | ||
|
|
5d591bca35 | ||
|
|
0b8e15cad1 | ||
|
|
d96b963385 | ||
|
|
671040a3a7 | ||
|
|
429353fa54 | ||
|
|
8003603ffd | ||
|
|
f8e767511b | ||
|
|
6a97980a18 | ||
|
|
2ab0df8e17 | ||
|
|
97a3ca223f | ||
|
|
bee9f61aa9 | ||
|
|
c193eb155e | ||
|
|
cc5ac0c659 | ||
|
|
752d063d5f | ||
|
|
06229d0d1f | ||
|
|
4ac8f5a354 | ||
|
|
6628715e40 | ||
|
|
d84dc0dd48 | ||
|
|
253e2a58be | ||
|
|
5f8daf56b1 | ||
|
|
cdd5aedadd | ||
|
|
52809a01d8 | ||
|
|
b459413c0e | ||
|
|
b147c4faaa | ||
|
|
e63ccb0541 | ||
|
|
ea878ca627 | ||
|
|
2dc2a998ce | ||
|
|
f747e01285 | ||
|
|
d9a53805ee | ||
|
|
9c3fc0dede | ||
|
|
cc409fbab6 |
@@ -20,6 +20,7 @@ jobs:
|
||||
run: |
|
||||
git branch
|
||||
ls -l
|
||||
sed -i 's/${basePath}:${basePort}/${basePath}/g' web/src/view/systemTools/formCreate/index.vue
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v2.1.2
|
||||
with:
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
name: Docker-CICD
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out branch
|
||||
uses: actions/checkout@v2
|
||||
- name: Login to Aliyun Registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ${{ secrets.ALIYUN_REGISTRY }}
|
||||
username: ${{ secrets.ALIYUN_DOCKERHUB_USER }}
|
||||
password: ${{ secrets.ALIYUN_DOCKERHUB_PASSWORD }}
|
||||
- name: Sed Config
|
||||
shell: bash
|
||||
run: |
|
||||
sed -i 's#./entrypoint.sh"#./entrypoint.sh","actions"#g' Dockerfile
|
||||
sed -i "s#COPY build/ /usr/share/nginx/html/#COPY . /opt/gva#g" Dockerfile
|
||||
sed -i 16c"\ && cd /opt/gva/server/ && go mod tidy && cd /opt/gva/web/ && yarn" Dockerfile
|
||||
sed -i "s#open: true#open: false#g" web/vite.config.js
|
||||
make images TAGS_OPT="latest"
|
||||
docker push registry.cn-hangzhou.aliyuncs.com/gva/web:latest
|
||||
docker push registry.cn-hangzhou.aliyuncs.com/gva/server:latest
|
||||
docker push registry.cn-hangzhou.aliyuncs.com/gva/all:latest
|
||||
@@ -0,0 +1,114 @@
|
||||
name: GIN-VUE-ADMIN Docker Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [stopstopstop]
|
||||
#workflow_dispatch:
|
||||
# inputs:
|
||||
# webtag:
|
||||
# description: 'Set web tag, Default latest'
|
||||
# required: true
|
||||
# default: "latest"
|
||||
# servertag:
|
||||
# description: 'Set server tag, Default latest'
|
||||
# required: true
|
||||
# default: "latest"
|
||||
|
||||
jobs:
|
||||
GIN_VUE_ADMIN_WEB:
|
||||
name: GIN VUE ADMIN WEB
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Private Actions Checkout
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: Docker Setup QEMU
|
||||
uses: docker/setup-qemu-action@v1.2.0
|
||||
- name: Docker Setup Buildx
|
||||
uses: docker/setup-buildx-action@v1.6.0
|
||||
- name: Docker Login
|
||||
uses: docker/login-action@v1.10.0
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Docker Login in Aliyun
|
||||
uses: docker/login-action@v1.10.0
|
||||
with:
|
||||
registry: ${{ secrets.DOCKERHUB_REGISTRY_ALIYUN }}
|
||||
username: ${{ secrets.DOCKERHUB_ACCOUNT_ALIYUN }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD_ALIYUN }}
|
||||
- name: Build and push Docker images
|
||||
uses: docker/build-push-action@v2.7.0
|
||||
with:
|
||||
context: .
|
||||
# 这里是适配 arm64 ,主要看你们的程序是否支持 arm64
|
||||
platforms: linux/amd64,linux/arm64
|
||||
file: web/Dockerfile
|
||||
push: true
|
||||
# 这里是给docker 打标签,默认不上传 latest
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/web:${{ github.event.inputs.webtag }}
|
||||
${{ secrets.DOCKERHUB_REGISTRY_ALIYUN }}/${{ secrets.DOCKERHUB_USERNAME_ALIYUN }}web:${{ github.event.inputs.webtag }}
|
||||
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/web:${{ github.event.inputs.webtag }}.cache
|
||||
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/web:${{ github.event.inputs.webtag }}.cache,mode=max
|
||||
# 漏洞扫描
|
||||
- name: Scan for vulnerabilities
|
||||
uses: crazy-max/ghaction-container-scan@v1
|
||||
with:
|
||||
image: ${{ secrets.DOCKERHUB_USERNAME }}/web:${{ github.event.inputs.webtag }}
|
||||
dockerfile: web/Dockerfile
|
||||
# 更新 docker 描述页面
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: ${{ secrets.DOCKERHUB_USERNAME }}/web
|
||||
|
||||
GIN_VUE_ADMIN_SERVER:
|
||||
name: GIN VUE ADMIN SERVER
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Private Actions Checkout
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: Docker Setup QEMU
|
||||
uses: docker/setup-qemu-action@v1.2.0
|
||||
- name: Docker Setup Buildx
|
||||
uses: docker/setup-buildx-action@v1.6.0
|
||||
- name: Docker Login
|
||||
uses: docker/login-action@v1.10.0
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Docker Login in Aliyun
|
||||
uses: docker/login-action@v1.10.0
|
||||
with:
|
||||
registry: ${{ secrets.DOCKERHUB_REGISTRY_ALIYUN }}
|
||||
username: ${{ secrets.DOCKERHUB_ACCOUNT_ALIYUN }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD_ALIYUN }}
|
||||
- name: Build and push Docker images
|
||||
uses: docker/build-push-action@v2.7.0
|
||||
with:
|
||||
context: .
|
||||
# 这里是适配 arm64 ,主要看你们的程序是否支持 arm64
|
||||
platforms: linux/amd64,linux/arm64
|
||||
file: server/Dockerfile
|
||||
push: true
|
||||
# 这里是给docker 打标签,默认不上传 latest
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.event.inputs.servertag }}
|
||||
${{ secrets.DOCKERHUB_REGISTRY_ALIYUN }}/${{ secrets.DOCKERHUB_USERNAME_ALIYUN }}server:${{ github.event.inputs.servertag }}
|
||||
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.event.inputs.servertag }}.cache
|
||||
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.event.inputs.servertag }}.cache,mode=max
|
||||
# 漏洞扫描
|
||||
- name: Scan for vulnerabilities
|
||||
uses: crazy-max/ghaction-container-scan@v1
|
||||
with:
|
||||
image: ${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.event.inputs.servertag }}
|
||||
dockerfile: server/Dockerfile
|
||||
# 更新 docker 描述页面
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: ${{ secrets.DOCKERHUB_USERNAME }}/server
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
FROM centos:7
|
||||
WORKDIR /opt
|
||||
ENV LANG=en_US.utf8
|
||||
COPY entrypoint.sh .
|
||||
COPY build/ /usr/share/nginx/html/
|
||||
COPY server/config.yaml /usr/share/nginx/html/config.yaml
|
||||
COPY web/.docker-compose/nginx/conf.d/nginx.conf /etc/nginx/conf.d/nginx.conf
|
||||
RUN set -ex \
|
||||
&& echo "LANG=en_US.utf8" > /etc/locale.conf \
|
||||
&& echo "net.core.somaxconn = 1024" >> /etc/sysctl.conf \
|
||||
&& echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf \
|
||||
&& yum -y install yum -y install *epel* \
|
||||
&& yum -y localinstall http://mirrors.ustc.edu.cn/mysql-repo/mysql57-community-release-el7.rpm \
|
||||
&& yum -y install mysql-community-server git redis nginx go npm --nogpgcheck && chmod +x ./entrypoint.sh \
|
||||
&& npm install -g yarn && go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct \
|
||||
&& echo "start" > /dev/null
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
@@ -0,0 +1,61 @@
|
||||
SHELL = /bin/bash
|
||||
|
||||
CONFIG_FILE = config.yaml
|
||||
PROJECT_NAME = github.com/flipped-aurora/gin-vue-admin/server
|
||||
#SCRIPT_DIR = $(shell pwd)/etc/script
|
||||
BUILD_IMAGE_SERVER = golang:1.16
|
||||
BUILD_IMAGE_WEB = node:16
|
||||
IMAGE_NAME = gva
|
||||
REPOSITORY = registry.cn-hangzhou.aliyuncs.com/${IMAGE_NAME}
|
||||
|
||||
ifeq ($(TAGS_OPT),)
|
||||
TAGS_OPT = 2.5.0b
|
||||
else
|
||||
endif
|
||||
|
||||
#容器环境前后端共同打包
|
||||
build: build-web build-server
|
||||
docker run --name build-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_SERVER} make build-local
|
||||
|
||||
#容器环境打包前端
|
||||
build-web:
|
||||
docker run --name build-web-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_WEB} make build-web-local
|
||||
|
||||
#容器环境打包后端
|
||||
build-server:
|
||||
docker run --name build-server-local --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE_SERVER} make build-server-local
|
||||
|
||||
#构建web镜像
|
||||
build-image-web:
|
||||
@cd web/ && docker build -t ${REPOSITORY}/web:${TAGS_OPT} .
|
||||
|
||||
#构建server镜像
|
||||
build-image-server:
|
||||
@cd server/ && docker build -t ${REPOSITORY}/server:${TAGS_OPT} .
|
||||
|
||||
#本地环境打包前后端
|
||||
build-local:
|
||||
if [ -d "build" ];then rm -rf build; else echo "OK!"; fi \
|
||||
&& if [ -f "/.dockerenv" ];then echo "OK!"; else make build-web-local && make build-server-local; fi \
|
||||
&& mkdir build && cp -r web/dist build/ && cp server/server build/ && cp -r server/resource build/resource
|
||||
|
||||
#本地环境打包前端
|
||||
build-web-local:
|
||||
@cd web/ && if [ -d "dist" ];then rm -rf dist; else echo "OK!"; fi \
|
||||
&& yarn config set registry http://mirrors.cloud.tencent.com/npm/ \
|
||||
&& yarn install && yarn build
|
||||
|
||||
#本地环境打包后端
|
||||
build-server-local:
|
||||
@cd server/ && if [ -f "server" ];then rm -rf server; else echo "OK!"; fi \
|
||||
&& go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct \
|
||||
&& go env -w CGO_ENABLED=0 && go env && go mod tidy \
|
||||
&& go build -ldflags "-B 0x$(shell head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -X main.Version=${TAGS_OPT}" -v
|
||||
|
||||
#打包前后端二合一镜像
|
||||
image: build
|
||||
docker build -t ${REPOSITORY}/all-one:${TAGS_OPT} .
|
||||
|
||||
#尝鲜版
|
||||
images: build build-image-web build-image-server
|
||||
docker build -t ${REPOSITORY}/all:${TAGS_OPT} .
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
<img src="https://qmplusimg.henrongyi.top/%E6%8E%88%E6%9D%83.png" width="1000">
|
||||
|
||||
5.如果您需要服务器的话 2C4G8M 80GB 腾讯云 一年74 三年222 在这里购买:https://curl.qcloud.com/sArxMfaw
|
||||
5.如果您需要服务器的话 2核2G腾讯云服务器45元/年 在这里购买:https://cloud.tencent.com/act/new?fromSource=gwzcw.4325959.4325959.4325959&utm_medium=cps&utm_id=gwzcw.4325959.4325959.4325959&cps_key=962a7fdaa930cda1c06e36a7608e95cc
|
||||
|
||||
阿里云服务器 1c2g1m 38一年 在这里购买:https://www.aliyun.com/minisite/goods?userCode=xqe01uob
|
||||
|
||||
@@ -212,17 +212,76 @@ swag init
|
||||
├── timer (定时器接口封装)
|
||||
└── upload (oss接口封装)
|
||||
|
||||
└─web (前端文件)
|
||||
├─public (发布模板)
|
||||
└─src (源码包)
|
||||
├─api (向后台发送ajax的封装层)
|
||||
├─assets (静态文件)
|
||||
├─components(组件)
|
||||
├─router (前端路由)
|
||||
├─store (vuex 状态管理仓)
|
||||
├─style (通用样式文件)
|
||||
├─utils (前端工具库)
|
||||
└─view (前端页面)
|
||||
web
|
||||
├── babel.config.js
|
||||
├── Dockerfile
|
||||
├── favicon.ico
|
||||
├── index.html -- 主页面
|
||||
├── limit.js -- 助手代码
|
||||
├── package.json -- 包管理器代码
|
||||
├── src -- 源代码
|
||||
│ ├── api -- api 组
|
||||
│ ├── App.vue -- 主页面
|
||||
│ ├── assets -- 静态资源
|
||||
│ ├── components -- 全局组件
|
||||
│ ├── core -- gva 组件包
|
||||
│ │ ├── config.js -- gva网站配置文件
|
||||
│ │ ├── gin-vue-admin.js -- 注册欢迎文件
|
||||
│ │ └── global.js -- 统一导入文件
|
||||
│ ├── directive -- v-auth 注册文件
|
||||
│ ├── main.js -- 主文件
|
||||
│ ├── permission.js -- 路由中间件
|
||||
│ ├── pinia -- pinia 状态管理器,取代vuex
|
||||
│ │ ├── index.js -- 入口文件
|
||||
│ │ └── modules -- modules
|
||||
│ │ ├── dictionary.js
|
||||
│ │ ├── router.js
|
||||
│ │ └── user.js
|
||||
│ ├── router -- 路由声明文件
|
||||
│ │ └── index.js
|
||||
│ ├── style -- 全局样式
|
||||
│ │ ├── base.scss
|
||||
│ │ ├── basics.scss
|
||||
│ │ ├── element_visiable.scss -- 此处可以全局覆盖 element-plus 样式
|
||||
│ │ ├── iconfont.css -- 顶部几个icon的样式文件
|
||||
│ │ ├── main.scss
|
||||
│ │ ├── mobile.scss
|
||||
│ │ └── newLogin.scss
|
||||
│ ├── utils -- 方法包库
|
||||
│ │ ├── asyncRouter.js -- 动态路由相关
|
||||
│ │ ├── btnAuth.js -- 动态权限按钮相关
|
||||
│ │ ├── bus.js -- 全局mitt声明文件
|
||||
│ │ ├── date.js -- 日期相关
|
||||
│ │ ├── dictionary.js -- 获取字典方法
|
||||
│ │ ├── downloadImg.js -- 下载图片方法
|
||||
│ │ ├── format.js -- 格式整理相关
|
||||
│ │ ├── image.js -- 图片相关方法
|
||||
│ │ ├── page.js -- 设置页面标题
|
||||
│ │ ├── request.js -- 请求
|
||||
│ │ └── stringFun.js -- 字符串文件
|
||||
| ├── view -- 主要view代码
|
||||
| | ├── about -- 关于我们
|
||||
| | ├── dashboard -- 面板
|
||||
| | ├── error -- 错误
|
||||
| | ├── example --上传案例
|
||||
| | ├── iconList -- icon列表
|
||||
| | ├── init -- 初始化数据
|
||||
| | | ├── index -- 新版本
|
||||
| | | ├── init -- 旧版本
|
||||
| | ├── layout -- layout约束页面
|
||||
| | | ├── aside
|
||||
| | | ├── bottomInfo -- bottomInfo
|
||||
| | | ├── screenfull -- 全屏设置
|
||||
| | | ├── setting -- 系统设置
|
||||
| | | └── index.vue -- base 约束
|
||||
| | ├── login --登录
|
||||
| | ├── person --个人中心
|
||||
| | ├── superAdmin -- 超级管理员操作
|
||||
| | ├── system -- 系统检测页面
|
||||
| | ├── systemTools -- 系统配置相关页面
|
||||
| | └── routerHolder.vue -- page 入口页面
|
||||
├── vite.config.js -- vite 配置文件
|
||||
└── yarn.lock
|
||||
|
||||
```
|
||||
|
||||
@@ -305,6 +364,12 @@ swag init
|
||||
|
||||
如果你觉得这个项目对你有帮助,你可以请作者喝饮料 :tropical_drink: [点我](https://www.gin-vue-admin.com/docs/coffee)
|
||||
|
||||
## 10. 商用注意事项
|
||||
## 10. 友情链接
|
||||
|
||||
[H5-Dooring | H5页面制作神器](https://github.com/MrXujiang/h5-Dooring)
|
||||
|
||||
[go-zero 微服务框架|缩短从需求到上线的距离](https://github.com/zeromicro/go-zero)
|
||||
|
||||
## 11. 商用注意事项
|
||||
|
||||
如果您将此项目用于商业用途,请遵守Apache2.0协议并保留作者技术支持声明。
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
version: "3"
|
||||
|
||||
# 声明一个名为network的networks,subnet为network的子网地址,默认网关是177.7.0.1
|
||||
networks:
|
||||
network:
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: '177.7.0.0/16'
|
||||
|
||||
# 设置mysql,redis持久化保存
|
||||
volumes:
|
||||
mysql:
|
||||
redis:
|
||||
|
||||
services:
|
||||
web:
|
||||
image: node:16
|
||||
container_name: gva-web
|
||||
hostname: gva-web #可以通过容器名访问
|
||||
restart: always
|
||||
ports:
|
||||
- '8080:8080'
|
||||
depends_on:
|
||||
- server
|
||||
working_dir: /gva-web # 如果docker 设置了workdir 则此处不需要设置
|
||||
#若网络不太好,请自行换源,如下
|
||||
#command: bash -c "yarn config set registry https://registry.npm.taobao.org --global && yarn install && yarn serve"
|
||||
command: bash -c "yarn install && yarn serve"
|
||||
volumes:
|
||||
- ./web:/gva-web
|
||||
networks:
|
||||
network:
|
||||
ipv4_address: 177.7.0.11
|
||||
|
||||
server:
|
||||
image: golang:1.16
|
||||
container_name: gva-server
|
||||
hostname: gva-server
|
||||
restart: always
|
||||
ports:
|
||||
- '8888:8888'
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
volumes:
|
||||
- ./server:/gva-server
|
||||
working_dir: /gva-server # 如果docker 设置了workdir 则此处不需要设置
|
||||
command: bash -c "go env -w GOPROXY=https://goproxy.cn,direct && go mod tidy && go run main.go"
|
||||
links:
|
||||
- mysql
|
||||
- redis
|
||||
networks:
|
||||
network:
|
||||
ipv4_address: 177.7.0.12
|
||||
|
||||
mysql:
|
||||
image: mysql:8.0.21 # 如果您是 arm64 架构:如 MacOS 的 M1,请修改镜像为 image: mysql/mysql-server:8.0.21
|
||||
container_name: gva-mysql
|
||||
hostname: gva-mysql
|
||||
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集
|
||||
restart: always
|
||||
ports:
|
||||
- "13306:3306" # host物理直接映射端口为13306
|
||||
environment:
|
||||
MYSQL_DATABASE: 'qmPlus' # 初始化启动时要创建的数据库的名称
|
||||
MYSQL_ROOT_PASSWORD: 'Aa@6447985' # root管理员用户密码
|
||||
volumes:
|
||||
- mysql:/var/lib/mysql
|
||||
networks:
|
||||
network:
|
||||
ipv4_address: 177.7.0.13
|
||||
|
||||
redis:
|
||||
image: redis:6.0.6
|
||||
container_name: gva-redis # 容器名
|
||||
hostname: gva-redis
|
||||
restart: always
|
||||
ports:
|
||||
- '16379:6379'
|
||||
volumes:
|
||||
- redis:/data
|
||||
networks:
|
||||
network:
|
||||
ipv4_address: 177.7.0.14
|
||||
+13
-3
@@ -1,12 +1,18 @@
|
||||
version: "3"
|
||||
|
||||
# 声明一个名为network的networks,subnet为network的子网地址,默认网关是177.7.0.1
|
||||
networks:
|
||||
network:
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: '177.7.0.0/16'
|
||||
|
||||
|
||||
# 设置mysql,redis持久化保存
|
||||
volumes:
|
||||
mysql:
|
||||
redis:
|
||||
|
||||
services:
|
||||
web:
|
||||
build:
|
||||
@@ -42,7 +48,7 @@ services:
|
||||
ipv4_address: 177.7.0.12
|
||||
|
||||
mysql:
|
||||
image: mysql:8.0.21
|
||||
image: mysql:8.0.21 # 如果您是 arm64 架构:如 MacOS 的 M1,请修改镜像为 image: mysql/mysql-server:8.0.21
|
||||
container_name: gva-mysql
|
||||
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集
|
||||
restart: always
|
||||
@@ -51,6 +57,8 @@ services:
|
||||
environment:
|
||||
MYSQL_DATABASE: 'qmPlus' # 初始化启动时要创建的数据库的名称
|
||||
MYSQL_ROOT_PASSWORD: 'Aa@6447985' # root管理员用户密码
|
||||
volumes:
|
||||
- mysql:/var/lib/mysql
|
||||
networks:
|
||||
network:
|
||||
ipv4_address: 177.7.0.13
|
||||
@@ -61,6 +69,8 @@ services:
|
||||
restart: always
|
||||
ports:
|
||||
- '16379:6379'
|
||||
volumes:
|
||||
- redis:/data
|
||||
networks:
|
||||
network:
|
||||
ipv4_address: 177.7.0.14
|
||||
ipv4_address: 177.7.0.14
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
if [ ! -d "/var/lib/mysql/gva" ]; then
|
||||
mysqld --initialize-insecure --user=mysql --datadir=/var/lib/mysql
|
||||
mysqld --daemonize --user=mysql
|
||||
sleep 5s
|
||||
mysql -uroot -e "create database gva default charset 'utf8' collate 'utf8_bin'; grant all on gva.* to 'root'@'127.0.0.1' identified by '123456'; flush privileges;"
|
||||
else
|
||||
mysqld --daemonize --user=mysql
|
||||
fi
|
||||
redis-server &
|
||||
if [ "$1" = "actions" ]; then
|
||||
cd /opt/gva/server && go run main.go &
|
||||
cd /opt/gva/web/ && yarn serve &
|
||||
else
|
||||
/usr/sbin/nginx &
|
||||
cd /usr/share/nginx/html/ && ./server &
|
||||
fi
|
||||
echo "gva ALL start!!!"
|
||||
tail -f /dev/null
|
||||
@@ -1,120 +0,0 @@
|
||||
package autocode
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
|
||||
autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AutoCodeExampleApi struct{}
|
||||
|
||||
var autoCodeExampleService = service.ServiceGroupApp.AutoCodeServiceGroup.AutoCodeExampleService
|
||||
|
||||
// @Tags AutoCodeExample
|
||||
// @Summary 创建AutoCodeExample
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.AutoCodeExample true "AutoCodeExample模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建AutoCodeExample"
|
||||
// @Router /autoCodeExample/createAutoCodeExample [post]
|
||||
func (autoCodeExampleApi *AutoCodeExampleApi) CreateAutoCodeExample(c *gin.Context) {
|
||||
var autoCodeExample autocode.AutoCodeExample
|
||||
_ = c.ShouldBindJSON(&autoCodeExample)
|
||||
if err := autoCodeExampleService.CreateAutoCodeExample(autoCodeExample); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags AutoCodeExample
|
||||
// @Summary 删除AutoCodeExample
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.AutoCodeExample true "AutoCodeExample模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除AutoCodeExample"
|
||||
// @Router /autoCodeExample/deleteAutoCodeExample [delete]
|
||||
func (autoCodeExampleApi *AutoCodeExampleApi) DeleteAutoCodeExample(c *gin.Context) {
|
||||
var autoCodeExample autocode.AutoCodeExample
|
||||
_ = c.ShouldBindJSON(&autoCodeExample)
|
||||
if err := autoCodeExampleService.DeleteAutoCodeExample(autoCodeExample); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags AutoCodeExample
|
||||
// @Summary 更新AutoCodeExample
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.AutoCodeExample true "更新AutoCodeExample"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新AutoCodeExample"
|
||||
// @Router /autoCodeExample/updateAutoCodeExample [put]
|
||||
func (autoCodeExampleApi *AutoCodeExampleApi) UpdateAutoCodeExample(c *gin.Context) {
|
||||
var autoCodeExample autocode.AutoCodeExample
|
||||
_ = c.ShouldBindJSON(&autoCodeExample)
|
||||
if err := autoCodeExampleService.UpdateAutoCodeExample(&autoCodeExample); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags AutoCodeExample
|
||||
// @Summary 用id查询AutoCodeExample
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query autocode.AutoCodeExample true "用id查询AutoCodeExample"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询AutoCodeExample"
|
||||
// @Router /autoCodeExample/findAutoCodeExample [get]
|
||||
func (autoCodeExampleApi *AutoCodeExampleApi) FindAutoCodeExample(c *gin.Context) {
|
||||
var autoCodeExample autocode.AutoCodeExample
|
||||
_ = c.ShouldBindQuery(&autoCodeExample)
|
||||
if err := utils.Verify(autoCodeExample, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err, reAutoCodeExample := autoCodeExampleService.GetAutoCodeExample(autoCodeExample.ID); err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"reAutoCodeExample": reAutoCodeExample}, "查询成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags AutoCodeExample
|
||||
// @Summary 分页获取AutoCodeExample列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query autocodeReq.AutoCodeExampleSearch true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取AutoCodeExample列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /autoCodeExample/getAutoCodeExampleList [get]
|
||||
func (autoCodeExampleApi *AutoCodeExampleApi) GetAutoCodeExampleList(c *gin.Context) {
|
||||
var pageInfo autocodeReq.AutoCodeExampleSearch
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
if err, list, total := autoCodeExampleService.GetAutoCodeExampleInfoList(pageInfo); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/system"
|
||||
)
|
||||
@@ -9,7 +8,6 @@ import (
|
||||
type ApiGroup struct {
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
AutoCodeApiGroup autocode.ApiGroup
|
||||
}
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ExcelApi struct{}
|
||||
@@ -27,6 +28,10 @@ type ExcelApi struct{}
|
||||
func (e *ExcelApi) ExportExcel(c *gin.Context) {
|
||||
var excelInfo example.ExcelInfo
|
||||
_ = c.ShouldBindJSON(&excelInfo)
|
||||
if strings.Index(excelInfo.FileName, "..") > -1 {
|
||||
response.FailWithMessage("包含非法字符", c)
|
||||
return
|
||||
}
|
||||
filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
|
||||
err := excelService.ParseInfoList2Excel(excelInfo.InfoList, filePath)
|
||||
if err != nil {
|
||||
@@ -89,12 +94,18 @@ func (e *ExcelApi) LoadExcel(c *gin.Context) {
|
||||
func (e *ExcelApi) DownloadTemplate(c *gin.Context) {
|
||||
fileName := c.Query("fileName")
|
||||
filePath := global.GVA_CONFIG.Excel.Dir + fileName
|
||||
ok, err := utils.PathExists(filePath)
|
||||
if !ok || err != nil {
|
||||
|
||||
fi, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("文件不存在!", zap.Error(err))
|
||||
response.FailWithMessage("文件不存在", c)
|
||||
return
|
||||
}
|
||||
if fi.IsDir() {
|
||||
global.GVA_LOG.Error("不支持下载文件夹!", zap.Error(err))
|
||||
response.FailWithMessage("不支持下载文件夹", c)
|
||||
return
|
||||
}
|
||||
c.Writer.Header().Add("success", "true")
|
||||
c.File(filePath)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,18 @@ func (u *FileUploadAndDownloadApi) UploadFile(c *gin.Context) {
|
||||
response.OkWithDetailed(exampleRes.ExaFileResponse{File: file}, "上传成功", c)
|
||||
}
|
||||
|
||||
// EditFileName 编辑文件名或者备注
|
||||
func (u *FileUploadAndDownloadApi) EditFileName(c *gin.Context) {
|
||||
var file example.ExaFileUploadAndDownload
|
||||
_ = c.ShouldBindJSON(&file)
|
||||
if err := fileUploadAndDownloadService.EditFileName(file); err != nil {
|
||||
global.GVA_LOG.Error("编辑失败!", zap.Error(err))
|
||||
response.FailWithMessage("编辑失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("编辑成功", c)
|
||||
}
|
||||
|
||||
// @Tags ExaFileUploadAndDownload
|
||||
// @Summary 删除文件
|
||||
// @Security ApiKeyAuth
|
||||
|
||||
@@ -36,7 +36,7 @@ func (a *AuthorityBtnApi) GetAuthorityBtn(c *gin.Context) {
|
||||
// @Produce application/json
|
||||
// @Param data body request.SysAuthorityBtnReq true "菜单id, 角色id, 选中的按钮id"
|
||||
// @Success 200 {object} response.Response{msg=string} "返回列表成功"
|
||||
// @Router /authorityBtn/getAuthorityBtn [post]
|
||||
// @Router /authorityBtn/setAuthorityBtn [post]
|
||||
func (a *AuthorityBtnApi) SetAuthorityBtn(c *gin.Context) {
|
||||
var req request.SysAuthorityBtnReq
|
||||
_ = c.ShouldBindJSON(&req)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
@@ -33,6 +34,7 @@ func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
a.PackageT = strings.Title(a.Package)
|
||||
autoCode, err := autoCodeService.PreviewTemp(a)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("预览失败!", zap.Error(err))
|
||||
@@ -69,6 +71,7 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) {
|
||||
apiIds = ids
|
||||
}
|
||||
}
|
||||
a.PackageT = strings.Title(a.Package)
|
||||
err := autoCodeService.CreateTemp(a, apiIds...)
|
||||
if err != nil {
|
||||
if errors.Is(err, system.AutoMoveErr) {
|
||||
@@ -101,8 +104,9 @@ func (autoApi *AutoCodeApi) GetDB(c *gin.Context) {
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetTables
|
||||
@@ -139,6 +143,94 @@ func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) {
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// CreatePackage
|
||||
// @Tags AutoCode
|
||||
// @Summary 创建package
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysAutoCode true "创建package"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
|
||||
// @Router /autoCode/createPackage [post]
|
||||
func (autoApi *AutoCodeApi) CreatePackage(c *gin.Context) {
|
||||
var a system.SysAutoCode
|
||||
_ = c.ShouldBindJSON(&a)
|
||||
if err := utils.Verify(a, utils.AutoPackageVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := autoCodeService.CreateAutoCode(&a)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建成功!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// GetPackage
|
||||
// @Tags AutoCode
|
||||
// @Summary 获取package
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
|
||||
// @Router /autoCode/getPackage [post]
|
||||
func (autoApi *AutoCodeApi) GetPackage(c *gin.Context) {
|
||||
pkgs, err := autoCodeService.GetPackage()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"pkgs": pkgs}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// DelPackage
|
||||
// @Tags AutoCode
|
||||
// @Summary 删除package
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysAutoCode true "创建package"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "删除package成功"
|
||||
// @Router /autoCode/delPackage [post]
|
||||
func (autoApi *AutoCodeApi) DelPackage(c *gin.Context) {
|
||||
var a system.SysAutoCode
|
||||
_ = c.ShouldBindJSON(&a)
|
||||
err := autoCodeService.DelPackage(a)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// DelPackage
|
||||
// @Tags AutoCode
|
||||
// @Summary 创建插件模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysAutoCode true "创建插件模板"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建插件模板成功"
|
||||
// @Router /autoCode/createPlug [post]
|
||||
func (autoApi *AutoCodeApi) AutoPlug(c *gin.Context) {
|
||||
var a system.AutoPlugReq
|
||||
_ = c.ShouldBindJSON(&a)
|
||||
a.Snake = strings.ToLower(a.PlugName)
|
||||
a.NeedModel = a.HasRequest || a.HasResponse
|
||||
err := autoCodeService.CreatePlug(a)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("预览失败!", zap.Error(err))
|
||||
response.FailWithMessage("预览失败", c)
|
||||
} else {
|
||||
response.Ok(c)
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
|
||||
}
|
||||
|
||||
@@ -58,11 +58,11 @@ func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "请求参数"
|
||||
// @Param data body systemReq.RollBack true "请求参数"
|
||||
// @Success 200 {object} response.Response{msg=string} "回滚自动生成代码"
|
||||
// @Router /autoCode/rollback [post]
|
||||
func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
|
||||
var info request.GetById
|
||||
var info systemReq.RollBack
|
||||
_ = c.ShouldBindJSON(&info)
|
||||
if err := autoCodeHistoryService.RollBack(&info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
|
||||
@@ -105,7 +105,7 @@ func (b *BaseApi) tokenNext(c *gin.Context, user system.SysUser) {
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.Register true "用户名, 昵称, 密码, 角色ID"
|
||||
// @Success 200 {object} response.Response{data=systemRes.SysUserResponse,msg=string} "用户注册账号,返回包括用户信息"
|
||||
// @Router /user/register [post]
|
||||
// @Router /user/admin_register [post]
|
||||
func (b *BaseApi) Register(c *gin.Context) {
|
||||
var r systemReq.Register
|
||||
_ = c.ShouldBindJSON(&r)
|
||||
@@ -272,20 +272,35 @@ func (b *BaseApi) DeleteUser(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/setUserInfo [put]
|
||||
func (b *BaseApi) SetUserInfo(c *gin.Context) {
|
||||
var user system.SysUser
|
||||
var user systemReq.ChangeUserInfo
|
||||
_ = c.ShouldBindJSON(&user)
|
||||
user.Username = ""
|
||||
user.Password = ""
|
||||
user.AuthorityId = ""
|
||||
if err := utils.Verify(user, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err, ReqUser := userService.SetUserInfo(user); err != nil {
|
||||
|
||||
if len(user.AuthorityIds) != 0 {
|
||||
err := userService.SetUserAuthorities(user.ID, user.AuthorityIds)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Error(err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
}
|
||||
}
|
||||
|
||||
if err := userService.SetUserInfo(system.SysUser{
|
||||
GVA_MODEL: global.GVA_MODEL{
|
||||
ID: user.ID,
|
||||
},
|
||||
NickName: user.NickName,
|
||||
HeaderImg: user.HeaderImg,
|
||||
Phone: user.Phone,
|
||||
Email: user.Email,
|
||||
SideMode: user.SideMode,
|
||||
}); err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Error(err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c)
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,17 +313,23 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) {
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/SetSelfInfo [put]
|
||||
func (b *BaseApi) SetSelfInfo(c *gin.Context) {
|
||||
var user system.SysUser
|
||||
var user systemReq.ChangeUserInfo
|
||||
_ = c.ShouldBindJSON(&user)
|
||||
user.Username = ""
|
||||
user.Password = ""
|
||||
user.AuthorityId = ""
|
||||
user.ID = utils.GetUserID(c)
|
||||
if err, ReqUser := userService.SetUserInfo(user); err != nil {
|
||||
if err := userService.SetUserInfo(system.SysUser{
|
||||
GVA_MODEL: global.GVA_MODEL{
|
||||
ID: user.ID,
|
||||
},
|
||||
NickName: user.NickName,
|
||||
HeaderImg: user.HeaderImg,
|
||||
Phone: user.Phone,
|
||||
Email: user.Email,
|
||||
SideMode: user.SideMode,
|
||||
}); err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Error(err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c)
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -111,12 +111,13 @@ autocode:
|
||||
# 请不要手动配置,他会在项目加载的时候识别出根路径
|
||||
root: ""
|
||||
server: /server
|
||||
server-api: /api/v1/autocode
|
||||
server-plug: /plugin/%s
|
||||
server-api: /api/v1/%s
|
||||
server-initialize: /initialize
|
||||
server-model: /model/autocode
|
||||
server-request: /model/autocode/request/
|
||||
server-router: /router/autocode
|
||||
server-service: /service/autocode
|
||||
server-model: /model/%s
|
||||
server-request: /model/%s/request/
|
||||
server-router: /router/%s
|
||||
server-service: /service/%s
|
||||
web: /web/src
|
||||
web-api: /api
|
||||
web-form: /view
|
||||
@@ -150,10 +151,13 @@ tencent-cos:
|
||||
base-url: 'https://gin.vue.admin'
|
||||
path-prefix: 'github.com/flipped-aurora/gin-vue-admin/server'
|
||||
|
||||
# aws s3 configuration
|
||||
# aws s3 configuration (minio compatible)
|
||||
aws-s3:
|
||||
bucket: xxxxx-10005608
|
||||
region: ap-shanghai
|
||||
endpoint: ''
|
||||
s3-force-path-style: false
|
||||
disable-ssl: false
|
||||
secret-id: xxxxxxxx
|
||||
secret-key: xxxxxxxx
|
||||
base-url: https://gin.vue.admin
|
||||
|
||||
+11
-10
@@ -1,17 +1,18 @@
|
||||
package config
|
||||
|
||||
type Autocode struct {
|
||||
TransferRestart bool `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"`
|
||||
TransferRestart bool `mapstructure:"transfer-restart" json:"transfer-restart" yaml:"transfer-restart"`
|
||||
Root string `mapstructure:"root" json:"root" yaml:"root"`
|
||||
Server string `mapstructure:"server" json:"server" yaml:"server"`
|
||||
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
|
||||
SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"`
|
||||
SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
|
||||
SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"`
|
||||
SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
|
||||
SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
|
||||
SApi string `mapstructure:"server-api" json:"server-api" yaml:"server-api"`
|
||||
SPlug string `mapstructure:"server-plug" json:"server-plug" yaml:"server-plug"`
|
||||
SInitialize string `mapstructure:"server-initialize" json:"server-initialize" yaml:"server-initialize"`
|
||||
SModel string `mapstructure:"server-model" json:"server-model" yaml:"server-model"`
|
||||
SRequest string `mapstructure:"server-request" json:"server-request" yaml:"server-request"`
|
||||
SRouter string `mapstructure:"server-router" json:"server-router" yaml:"server-router"`
|
||||
SService string `mapstructure:"server-service" json:"server-service" yaml:"server-service"`
|
||||
Web string `mapstructure:"web" json:"web" yaml:"web"`
|
||||
WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
|
||||
WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
|
||||
WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
|
||||
WApi string `mapstructure:"web-api" json:"web-api" yaml:"web-api"`
|
||||
WForm string `mapstructure:"web-form" json:"web-form" yaml:"web-form"`
|
||||
WTable string `mapstructure:"web-table" json:"web-table" yaml:"web-table"`
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
type Captcha struct {
|
||||
KeyLong int `mapstructure:"key-long" json:"keyLong" yaml:"key-long"` // 验证码长度
|
||||
ImgWidth int `mapstructure:"img-width" json:"imgWidth" yaml:"img-width"` // 验证码宽度
|
||||
ImgHeight int `mapstructure:"img-height" json:"imgHeight" yaml:"img-height"` // 验证码高度
|
||||
KeyLong int `mapstructure:"key-long" json:"key-long" yaml:"key-long"` // 验证码长度
|
||||
ImgWidth int `mapstructure:"img-width" json:"img-width" yaml:"img-width"` // 验证码宽度
|
||||
ImgHeight int `mapstructure:"img-height" json:"img-height" yaml:"img-height"` // 验证码高度
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package config
|
||||
|
||||
type Casbin struct {
|
||||
ModelPath string `mapstructure:"model-path" json:"modelPath" yaml:"model-path"` // 存放casbin模型的相对路径
|
||||
ModelPath string `mapstructure:"model-path" json:"model-path" yaml:"model-path"` // 存放casbin模型的相对路径
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ type Server struct {
|
||||
System System `mapstructure:"system" json:"system" yaml:"system"`
|
||||
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
|
||||
// auto
|
||||
AutoCode Autocode `mapstructure:"autoCode" json:"autoCode" yaml:"autoCode"`
|
||||
AutoCode Autocode `mapstructure:"autocode" json:"autocode" yaml:"autocode"`
|
||||
// gorm
|
||||
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
|
||||
Pgsql Pgsql `mapstructure:"pgsql" json:"pgsql" yaml:"pgsql"`
|
||||
@@ -17,10 +17,10 @@ type Server struct {
|
||||
// oss
|
||||
Local Local `mapstructure:"local" json:"local" yaml:"local"`
|
||||
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
|
||||
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
|
||||
HuaWeiObs HuaWeiObs `mapstructure:"hua-wei-obs" json:"huaWeiObs" yaml:"hua-wei-obs"`
|
||||
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
|
||||
AwsS3 AwsS3 `mapstructure:"aws-s3" json:"awsS3" yaml:"aws-s3"`
|
||||
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyun-oss" yaml:"aliyun-oss"`
|
||||
HuaWeiObs HuaWeiObs `mapstructure:"hua-wei-obs" json:"hua-wei-obs" yaml:"hua-wei-obs"`
|
||||
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencent-cos" yaml:"tencent-cos"`
|
||||
AwsS3 AwsS3 `mapstructure:"aws-s3" json:"aws-s3" yaml:"aws-s3"`
|
||||
|
||||
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
|
||||
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
|
||||
|
||||
+10
-10
@@ -4,16 +4,16 @@ type DB struct {
|
||||
Disable bool `mapstructure:"disable" json:"disable" yaml:"disable"`
|
||||
Type string `mapstructure:"type" json:"type" yaml:"type"`
|
||||
AliasName string `mapstructure:"alias-name" json:"alias-name" yaml:"alias-name"`
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
|
||||
Port string `mapstructure:"port" json:"port" yaml:"port"` //:端口
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
||||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
||||
LogMode string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
||||
LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"`
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
|
||||
Port string `mapstructure:"port" json:"port" yaml:"port"` //:端口
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
||||
Dbname string `mapstructure:"db-name" json:"db-name" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
||||
LogMode string `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
||||
LogZap bool `mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"`
|
||||
}
|
||||
|
||||
func (m *DB) Dsn() string {
|
||||
|
||||
@@ -5,7 +5,7 @@ type Email struct {
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
||||
From string `mapstructure:"from" json:"from" yaml:"from"` // 收件人
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
|
||||
IsSSL bool `mapstructure:"is-ssl" json:"isSSL" yaml:"is-ssl"` // 是否SSL
|
||||
IsSSL bool `mapstructure:"is-ssl" json:"is-ssl" yaml:"is-ssl"` // 是否SSL
|
||||
Secret string `mapstructure:"secret" json:"secret" yaml:"secret"` // 密钥
|
||||
Nickname string `mapstructure:"nickname" json:"nickname" yaml:"nickname"` // 昵称
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,16 +1,16 @@
|
||||
package config
|
||||
|
||||
type Mysql struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址
|
||||
Port string `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
||||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
||||
LogMode string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
||||
LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` // 是否通过zap写入日志文件
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址
|
||||
Port string `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
||||
Dbname string `mapstructure:"db-name" json:"db-name" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
||||
LogMode string `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
||||
LogZap bool `mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"` // 是否通过zap写入日志文件
|
||||
}
|
||||
|
||||
func (m *Mysql) Dsn() string {
|
||||
|
||||
+10
-10
@@ -1,16 +1,16 @@
|
||||
package config
|
||||
|
||||
type Pgsql struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
|
||||
Port string `mapstructure:"port" json:"port" yaml:"port"` //:端口
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
||||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
||||
LogMode string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
||||
LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` // 是否通过zap写入日志文件
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
|
||||
Port string `mapstructure:"port" json:"port" yaml:"port"` //:端口
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
||||
Dbname string `mapstructure:"db-name" json:"db-name" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
||||
LogMode string `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
||||
LogZap bool `mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"` // 是否通过zap写入日志文件
|
||||
}
|
||||
|
||||
// Dsn 基于配置文件获取 dsn
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package config
|
||||
|
||||
type JWT struct {
|
||||
SigningKey string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"` // jwt签名
|
||||
ExpiresTime int64 `mapstructure:"expires-time" json:"expiresTime" yaml:"expires-time"` // 过期时间
|
||||
BufferTime int64 `mapstructure:"buffer-time" json:"bufferTime" yaml:"buffer-time"` // 缓冲时间
|
||||
Issuer string `mapstructure:"issuer" json:"issuer" yaml:"issuer"` // 签发者
|
||||
SigningKey string `mapstructure:"signing-key" json:"signing-key" yaml:"signing-key"` // jwt签名
|
||||
ExpiresTime int64 `mapstructure:"expires-time" json:"expires-time" yaml:"expires-time"` // 过期时间
|
||||
BufferTime int64 `mapstructure:"buffer-time" json:"buffer-time" yaml:"buffer-time"` // 缓冲时间
|
||||
Issuer string `mapstructure:"issuer" json:"issuer" yaml:"issuer"` // 签发者
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package config
|
||||
|
||||
type AliyunOSS struct {
|
||||
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
|
||||
AccessKeyId string `mapstructure:"access-key-id" json:"accessKeyId" yaml:"access-key-id"`
|
||||
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"`
|
||||
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"`
|
||||
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"`
|
||||
BasePath string `mapstructure:"base-path" json:"basePath" yaml:"base-path"`
|
||||
AccessKeyId string `mapstructure:"access-key-id" json:"access-key-id" yaml:"access-key-id"`
|
||||
AccessKeySecret string `mapstructure:"access-key-secret" json:"access-key-secret" yaml:"access-key-secret"`
|
||||
BucketName string `mapstructure:"bucket-name" json:"bucket-name" yaml:"bucket-name"`
|
||||
BucketUrl string `mapstructure:"bucket-url" json:"bucket-url" yaml:"bucket-url"`
|
||||
BasePath string `mapstructure:"base-path" json:"base-path" yaml:"base-path"`
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package config
|
||||
|
||||
type AwsS3 struct {
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
|
||||
Region string `mapstructure:"region" json:"region" yaml:"region"`
|
||||
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
|
||||
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"`
|
||||
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"`
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
|
||||
Region string `mapstructure:"region" json:"region" yaml:"region"`
|
||||
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
|
||||
S3ForcePathStyle bool `mapstructure:"s3-force-path-style" json:"s3-force-path-style" yaml:"s3-force-path-style"`
|
||||
DisableSSL bool `mapstructure:"disable-ssl" json:"disable-ssl" yaml:"disable-ssl"`
|
||||
SecretID string `mapstructure:"secret-id" json:"secret-id" yaml:"secret-id"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secret-key" yaml:"secret-key"`
|
||||
BaseURL string `mapstructure:"base-url" json:"base-url" yaml:"base-url"`
|
||||
PathPrefix string `mapstructure:"path-prefix" json:"path-prefix" yaml:"path-prefix"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ type HuaWeiObs struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"`
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
|
||||
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
|
||||
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
|
||||
AccessKey string `mapstructure:"access-key" json:"access-key" yaml:"access-key"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secret-key" yaml:"secret-key"`
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package config
|
||||
|
||||
type Qiniu struct {
|
||||
Zone string `mapstructure:"zone" json:"zone" yaml:"zone"` // 存储区域
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` // 空间名称
|
||||
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"` // CDN加速域名
|
||||
UseHTTPS bool `mapstructure:"use-https" json:"useHttps" yaml:"use-https"` // 是否使用https
|
||||
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"` // 秘钥AK
|
||||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` // 秘钥SK
|
||||
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"` // 上传是否使用CDN上传加速
|
||||
Zone string `mapstructure:"zone" json:"zone" yaml:"zone"` // 存储区域
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` // 空间名称
|
||||
ImgPath string `mapstructure:"img-path" json:"img-path" yaml:"img-path"` // CDN加速域名
|
||||
UseHTTPS bool `mapstructure:"use-https" json:"use-https" yaml:"use-https"` // 是否使用https
|
||||
AccessKey string `mapstructure:"access-key" json:"access-key" yaml:"access-key"` // 秘钥AK
|
||||
SecretKey string `mapstructure:"secret-key" json:"secret-key" yaml:"secret-key"` // 秘钥SK
|
||||
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"use-cdn-domains" yaml:"use-cdn-domains"` // 上传是否使用CDN上传加速
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package config
|
||||
type TencentCOS struct {
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
|
||||
Region string `mapstructure:"region" json:"region" yaml:"region"`
|
||||
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
|
||||
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"`
|
||||
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"`
|
||||
SecretID string `mapstructure:"secret-id" json:"secret-id" yaml:"secret-id"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secret-key" yaml:"secret-key"`
|
||||
BaseURL string `mapstructure:"base-url" json:"base-url" yaml:"base-url"`
|
||||
PathPrefix string `mapstructure:"path-prefix" json:"path-prefix" yaml:"path-prefix"`
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package config
|
||||
|
||||
type System struct {
|
||||
Env string `mapstructure:"env" json:"env" yaml:"env"` // 环境值
|
||||
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"` // 端口值
|
||||
DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"` // 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql
|
||||
OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"` // Oss类型
|
||||
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"` // 多点登录拦截
|
||||
UseRedis bool `mapstructure:"use-redis" json:"useRedis" yaml:"use-redis"` // 使用redis
|
||||
LimitCountIP int `mapstructure:"iplimit-count" json:"iplimitCount" yaml:"iplimit-count"`
|
||||
LimitTimeIP int `mapstructure:"iplimit-time" json:"iplimitTime" yaml:"iplimit-time"`
|
||||
Env string `mapstructure:"env" json:"env" yaml:"env"` // 环境值
|
||||
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"` // 端口值
|
||||
DbType string `mapstructure:"db-type" json:"db-type" yaml:"db-type"` // 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql
|
||||
OssType string `mapstructure:"oss-type" json:"oss-type" yaml:"oss-type"` // Oss类型
|
||||
UseMultipoint bool `mapstructure:"use-multipoint" json:"use-multipoint" yaml:"use-multipoint"` // 多点登录拦截
|
||||
UseRedis bool `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis"` // 使用redis
|
||||
LimitCountIP int `mapstructure:"iplimit-count" json:"iplimit-count" yaml:"iplimit-count"`
|
||||
LimitTimeIP int `mapstructure:"iplimit-time" json:"iplimit-time" yaml:"iplimit-time"`
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package config
|
||||
|
||||
type Zap struct {
|
||||
Level string `mapstructure:"level" json:"level" yaml:"level"` // 级别
|
||||
Format string `mapstructure:"format" json:"format" yaml:"format"` // 输出
|
||||
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // 日志前缀
|
||||
Director string `mapstructure:"director" json:"director" yaml:"director"` // 日志文件夹
|
||||
ShowLine bool `mapstructure:"show-line" json:"showLine" yaml:"showLine"` // 显示行
|
||||
EncodeLevel string `mapstructure:"encode-level" json:"encodeLevel" yaml:"encode-level"` // 编码级
|
||||
StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktraceKey" yaml:"stacktrace-key"` // 栈名
|
||||
LogInConsole bool `mapstructure:"log-in-console" json:"logInConsole" yaml:"log-in-console"` // 输出控制台
|
||||
Level string `mapstructure:"level" json:"level" yaml:"level"` // 级别
|
||||
Format string `mapstructure:"format" json:"format" yaml:"format"` // 输出
|
||||
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // 日志前缀
|
||||
Director string `mapstructure:"director" json:"director" yaml:"director"` // 日志文件夹
|
||||
ShowLine bool `mapstructure:"show-line" json:"show-line" yaml:"show-line"` // 显示行
|
||||
EncodeLevel string `mapstructure:"encode-level" json:"encode-level" yaml:"encode-level"` // 编码级
|
||||
StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktrace-key" yaml:"stacktrace-key"` // 栈名
|
||||
LogInConsole bool `mapstructure:"log-in-console" json:"log-in-console" yaml:"log-in-console"` // 输出控制台
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func RunWindowsServer() {
|
||||
|
||||
fmt.Printf(`
|
||||
欢迎使用 github.com/flipped-aurora/gin-vue-admin/server
|
||||
当前版本:V2.5.0
|
||||
当前版本:V2.5.1
|
||||
加群方式:微信号:shouzi_1994 QQ群:622360840
|
||||
GVA讨论社区:https://support.qq.com/products/371961
|
||||
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
|
||||
|
||||
+7
-5
@@ -33,11 +33,13 @@ func Zap() (logger *zap.Logger) {
|
||||
return lev >= zap.ErrorLevel
|
||||
})
|
||||
|
||||
now := time.Now().Format("2006-01-02")
|
||||
|
||||
cores := [...]zapcore.Core{
|
||||
getEncoderCore(fmt.Sprintf("./%s/server_debug.log", global.GVA_CONFIG.Zap.Director), debugPriority),
|
||||
getEncoderCore(fmt.Sprintf("./%s/server_info.log", global.GVA_CONFIG.Zap.Director), infoPriority),
|
||||
getEncoderCore(fmt.Sprintf("./%s/server_warn.log", global.GVA_CONFIG.Zap.Director), warnPriority),
|
||||
getEncoderCore(fmt.Sprintf("./%s/server_error.log", global.GVA_CONFIG.Zap.Director), errorPriority),
|
||||
getEncoderCore(fmt.Sprintf("./%s/%s/debug.log", global.GVA_CONFIG.Zap.Director, now), debugPriority),
|
||||
getEncoderCore(fmt.Sprintf("./%s/%s/info.log", global.GVA_CONFIG.Zap.Director, now), infoPriority),
|
||||
getEncoderCore(fmt.Sprintf("./%s/%s/warn.log", global.GVA_CONFIG.Zap.Director, now), warnPriority),
|
||||
getEncoderCore(fmt.Sprintf("./%s/%s/error.log", global.GVA_CONFIG.Zap.Director, now), errorPriority),
|
||||
}
|
||||
logger = zap.New(zapcore.NewTee(cores[:]...), zap.AddCaller())
|
||||
|
||||
@@ -91,7 +93,7 @@ func getEncoderCore(fileName string, level zapcore.LevelEnabler) (core zapcore.C
|
||||
return zapcore.NewCore(getEncoder(), writer, level)
|
||||
}
|
||||
|
||||
// 自定义日志输出时间格式
|
||||
// CustomTimeEncoder 自定义日志输出时间格式
|
||||
func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
|
||||
enc.AppendString(t.Format(global.GVA_CONFIG.Zap.Prefix + "2006/01/02 - 15:04:05.000"))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
adapter "github.com/casbin/gorm-adapter/v3"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
|
||||
sysModel "github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service/system"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const initOrderEnsureTables = system.InitOrderExternal - 1
|
||||
|
||||
type ensureTables struct{}
|
||||
|
||||
// auto run
|
||||
func init() {
|
||||
system.RegisterInit(initOrderEnsureTables, &ensureTables{})
|
||||
}
|
||||
|
||||
func (ensureTables) InitializerName() string {
|
||||
return "ensure_tables_created"
|
||||
}
|
||||
func (e *ensureTables) InitializeData(ctx context.Context) (next context.Context, err error) {
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
func (e *ensureTables) DataInserted(ctx context.Context) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *ensureTables) MigrateTable(ctx context.Context) (context.Context, error) {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
return ctx, system.ErrMissingDBContext
|
||||
}
|
||||
tables := []interface{}{
|
||||
sysModel.SysApi{},
|
||||
sysModel.SysUser{},
|
||||
sysModel.SysBaseMenu{},
|
||||
sysModel.SysAuthority{},
|
||||
sysModel.JwtBlacklist{},
|
||||
sysModel.SysDictionary{},
|
||||
sysModel.SysAutoCodeHistory{},
|
||||
sysModel.SysOperationRecord{},
|
||||
sysModel.SysDictionaryDetail{},
|
||||
sysModel.SysBaseMenuParameter{},
|
||||
sysModel.SysBaseMenuBtn{},
|
||||
sysModel.SysAuthorityBtn{},
|
||||
sysModel.SysAutoCode{},
|
||||
|
||||
adapter.CasbinRule{},
|
||||
|
||||
example.ExaFile{},
|
||||
example.ExaCustomer{},
|
||||
example.ExaFileChunk{},
|
||||
example.ExaFileUploadAndDownload{},
|
||||
}
|
||||
for _, t := range tables {
|
||||
_ = db.AutoMigrate(&t)
|
||||
// 视图 authority_menu 会被当成表来创建,引发冲突错误(更新版本的gorm似乎不会)
|
||||
// 由于 AutoMigrate() 基本无需考虑错误,因此显式忽略
|
||||
}
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
func (e *ensureTables) TableCreated(ctx context.Context) bool {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
tables := []interface{}{
|
||||
sysModel.SysApi{},
|
||||
sysModel.SysUser{},
|
||||
sysModel.SysBaseMenu{},
|
||||
sysModel.SysAuthority{},
|
||||
sysModel.JwtBlacklist{},
|
||||
sysModel.SysDictionary{},
|
||||
sysModel.SysAutoCodeHistory{},
|
||||
sysModel.SysOperationRecord{},
|
||||
sysModel.SysDictionaryDetail{},
|
||||
sysModel.SysBaseMenuParameter{},
|
||||
sysModel.SysBaseMenuBtn{},
|
||||
sysModel.SysAuthorityBtn{},
|
||||
sysModel.SysAutoCode{},
|
||||
|
||||
adapter.CasbinRule{},
|
||||
|
||||
example.ExaFile{},
|
||||
example.ExaCustomer{},
|
||||
example.ExaFileChunk{},
|
||||
example.ExaFileUploadAndDownload{},
|
||||
}
|
||||
yes := true
|
||||
for _, t := range tables {
|
||||
yes = yes && db.Migrator().HasTable(t)
|
||||
}
|
||||
return yes
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
|
||||
@@ -42,6 +41,8 @@ func RegisterTables(db *gorm.DB) {
|
||||
system.SysBaseMenuParameter{},
|
||||
system.SysBaseMenuBtn{},
|
||||
system.SysAuthorityBtn{},
|
||||
system.SysAutoCode{},
|
||||
|
||||
// 示例模块表
|
||||
example.ExaFile{},
|
||||
example.ExaCustomer{},
|
||||
@@ -50,7 +51,7 @@ func RegisterTables(db *gorm.DB) {
|
||||
|
||||
// 自动化模块表
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
||||
autocode.AutoCodeExample{},
|
||||
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,9 +2,7 @@ package initialize
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
email "github.com/flipped-aurora/gva-plugins/email" // 在线仓库模式go
|
||||
//"github.com/flipped-aurora/gin-vue-admin/server/plugin/email" // 本地插件仓库地址模式
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/example_plugin"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/email"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils/plugin"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -17,10 +15,6 @@ func PluginInit(group *gin.RouterGroup, Plugin ...plugin.Plugin) {
|
||||
}
|
||||
|
||||
func InstallPlugin(PublicGroup *gin.RouterGroup, PrivateGroup *gin.RouterGroup) {
|
||||
// 添加开放权限的插件 示例
|
||||
PluginInit(PublicGroup,
|
||||
example_plugin.ExamplePlugin)
|
||||
|
||||
// 添加跟角色挂钩权限的插件 示例 本地示例模式于在线仓库模式注意上方的import 可以自行切换 效果相同
|
||||
PluginInit(PrivateGroup, email.CreateEmailPlug(
|
||||
global.GVA_CONFIG.Email.To,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
_ "github.com/flipped-aurora/gin-vue-admin/server/source/example"
|
||||
_ "github.com/flipped-aurora/gin-vue-admin/server/source/system"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// do nothing,only import source package so that inits can be registered
|
||||
}
|
||||
@@ -16,7 +16,8 @@ import (
|
||||
|
||||
func Routers() *gin.Engine {
|
||||
Router := gin.Default()
|
||||
|
||||
systemRouter := router.RouterGroupApp.System
|
||||
exampleRouter := router.RouterGroupApp.Example
|
||||
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
|
||||
// VUE_APP_BASE_API = /
|
||||
// VUE_APP_BASE_PATH = http://localhost
|
||||
@@ -37,10 +38,6 @@ func Routers() *gin.Engine {
|
||||
global.GVA_LOG.Info("register swagger handler")
|
||||
// 方便统一添加路由组前缀 多服务器上线使用
|
||||
|
||||
// 获取路由组实例
|
||||
systemRouter := router.RouterGroupApp.System
|
||||
exampleRouter := router.RouterGroupApp.Example
|
||||
autocodeRouter := router.RouterGroupApp.Autocode
|
||||
PublicGroup := Router.Group("")
|
||||
{
|
||||
// 健康监测
|
||||
@@ -74,7 +71,7 @@ func Routers() *gin.Engine {
|
||||
exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
|
||||
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
||||
autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup)
|
||||
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ func Cors() gin.HandlerFunc {
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token,X-Token,X-User-Id")
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS,DELETE,PUT")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type, New-Token, New-Expires-At")
|
||||
c.Header("Access-Control-Allow-Credentials", "true")
|
||||
|
||||
// 放行所有OPTIONS方法
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -32,6 +33,8 @@ func ErrorToEmail() gin.HandlerFunc {
|
||||
username = user.Username
|
||||
}
|
||||
body, _ := ioutil.ReadAll(c.Request.Body)
|
||||
// 再重新写回请求体body中,ioutil.ReadAll会清空c.Request.Body中的数据
|
||||
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
||||
record := system.SysOperationRecord{
|
||||
Ip: c.ClientIP(),
|
||||
Method: c.Request.Method,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
@@ -21,6 +22,14 @@ import (
|
||||
|
||||
var operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService
|
||||
|
||||
var respPool sync.Pool
|
||||
|
||||
func init() {
|
||||
respPool.New = func() interface{} {
|
||||
return make([]byte, 1024)
|
||||
}
|
||||
}
|
||||
|
||||
func OperationRecord() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var body []byte
|
||||
@@ -64,11 +73,18 @@ func OperationRecord() gin.HandlerFunc {
|
||||
Body: string(body),
|
||||
UserID: userId,
|
||||
}
|
||||
// 存在某些未知错误 TODO
|
||||
//values := c.Request.Header.Values("content-type")
|
||||
//if len(values) >0 && strings.Contains(values[0], "boundary") {
|
||||
// record.Body = "file"
|
||||
//}
|
||||
|
||||
// 上传文件时候 中间件日志进行裁断操作
|
||||
if strings.Index(c.GetHeader("Content-Type"), "multipart/form-data") > -1 {
|
||||
if len(record.Body) > 1024 {
|
||||
// 截断
|
||||
newBody := respPool.Get().([]byte)
|
||||
copy(newBody, record.Body)
|
||||
record.Body = string(newBody)
|
||||
defer respPool.Put(newBody[:0])
|
||||
}
|
||||
}
|
||||
|
||||
writer := responseBodyWriter{
|
||||
ResponseWriter: c.Writer,
|
||||
body: &bytes.Buffer{},
|
||||
@@ -84,6 +100,24 @@ func OperationRecord() gin.HandlerFunc {
|
||||
record.Latency = latency
|
||||
record.Resp = writer.body.String()
|
||||
|
||||
if strings.Index(c.Writer.Header().Get("Pragma"), "public") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Expires"), "0") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Cache-Control"), "must-revalidate, post-check=0, pre-check=0") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Content-Type"), "application/force-download") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Content-Type"), "application/octet-stream") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Content-Type"), "application/vnd.ms-excel") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Content-Type"), "application/download") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Content-Disposition"), "attachment") > -1 ||
|
||||
strings.Index(c.Writer.Header().Get("Content-Transfer-Encoding"), "binary") > -1 {
|
||||
if len(record.Resp) > 1024 {
|
||||
// 截断
|
||||
newBody := respPool.Get().([]byte)
|
||||
copy(newBody, record.Resp)
|
||||
record.Body = string(newBody)
|
||||
defer respPool.Put(newBody[:0])
|
||||
}
|
||||
}
|
||||
|
||||
if err := operationRecordService.CreateSysOperationRecord(record); err != nil {
|
||||
global.GVA_LOG.Error("create operation record error:", zap.Error(err))
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
// 自动生成模板SysDictionaryDetail
|
||||
package autocode
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type AutoCodeExample struct {
|
||||
global.GVA_MODEL
|
||||
AutoCodeExampleField string `json:"autoCodeExampleField" form:"autoCodeExampleField" gorm:"column:auto_code_example_field;comment:仅作示例条目无实际作用"` // 展示值
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// 自动生成模板SysDictionaryDetail
|
||||
package request
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type AutoCodeExampleSearch struct {
|
||||
autocode.AutoCodeExample
|
||||
request.PageInfo
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package request
|
||||
type PageInfo struct {
|
||||
Page int `json:"page" form:"page"` // 页码
|
||||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
||||
Keyword string `json:"keyword" form:"keyword"` //关键字
|
||||
}
|
||||
|
||||
// GetById Find by id structure
|
||||
|
||||
@@ -11,3 +11,7 @@ type ExaFileUploadAndDownload struct {
|
||||
Tag string `json:"tag" gorm:"comment:文件标签"` // 文件标签
|
||||
Key string `json:"key" gorm:"comment:编号"` // 编号
|
||||
}
|
||||
|
||||
func (ExaFileUploadAndDownload) TableName() string {
|
||||
return "exa_file_upload_and_downloads"
|
||||
}
|
||||
|
||||
@@ -5,3 +5,9 @@ import "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
type SysAutoHistory struct {
|
||||
request.PageInfo
|
||||
}
|
||||
|
||||
// GetById Find by id structure
|
||||
type RollBack struct {
|
||||
ID int `json:"id" form:"id"` // 主键ID
|
||||
DeleteTable bool `json:"deleteTable" form:"deleteTable"` // 是否删除表
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func DefaultCasbin() []CasbinInfo {
|
||||
{Path: "/menu/getMenu", Method: "POST"},
|
||||
{Path: "/jwt/jsonInBlacklist", Method: "POST"},
|
||||
{Path: "/base/login", Method: "POST"},
|
||||
{Path: "/user/register", Method: "POST"},
|
||||
{Path: "/user/admin_register", Method: "POST"},
|
||||
{Path: "/user/changePassword", Method: "POST"},
|
||||
{Path: "/user/setUserAuthority", Method: "POST"},
|
||||
{Path: "/user/setUserInfo", Method: "PUT"},
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package request
|
||||
|
||||
import model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
|
||||
// User register structure
|
||||
type Register struct {
|
||||
Username string `json:"userName"`
|
||||
@@ -35,3 +37,14 @@ type SetUserAuthorities struct {
|
||||
ID uint
|
||||
AuthorityIds []string `json:"authorityIds"` // 角色ID
|
||||
}
|
||||
|
||||
type ChangeUserInfo struct {
|
||||
ID uint `gorm:"primarykey"` // 主键ID
|
||||
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
|
||||
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户角色ID
|
||||
AuthorityIds []string `json:"authorityIds" gorm:"-"` // 角色ID
|
||||
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
|
||||
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
|
||||
SideMode string `json:"sideMode" gorm:"comment:用户侧边主题"` // 用户侧边主题
|
||||
Authorities []model.SysAuthority `json:"-" gorm:"many2many:sys_user_authority;"`
|
||||
}
|
||||
|
||||
@@ -11,3 +11,7 @@ type SysApi struct {
|
||||
ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组
|
||||
Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE
|
||||
}
|
||||
|
||||
func (SysApi) TableName() string {
|
||||
return "sys_apis"
|
||||
}
|
||||
|
||||
@@ -5,15 +5,19 @@ import (
|
||||
)
|
||||
|
||||
type SysAuthority struct {
|
||||
CreatedAt time.Time // 创建时间
|
||||
UpdatedAt time.Time // 更新时间
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
|
||||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
|
||||
ParentId string `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
|
||||
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`
|
||||
Children []SysAuthority `json:"children" gorm:"-"`
|
||||
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
|
||||
Users []SysUser `json:"-" gorm:"many2many:sys_user_authority;"`
|
||||
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
|
||||
CreatedAt time.Time // 创建时间
|
||||
UpdatedAt time.Time // 更新时间
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
|
||||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
|
||||
ParentId string `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
|
||||
DataAuthorityId []*SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;"`
|
||||
Children []SysAuthority `json:"children" gorm:"-"`
|
||||
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
|
||||
Users []SysUser `json:"-" gorm:"many2many:sys_user_authority;"`
|
||||
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
|
||||
}
|
||||
|
||||
func (SysAuthority) TableName() string {
|
||||
return "sys_authorities"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package system
|
||||
|
||||
type SysAuthorityBtn struct {
|
||||
AuthorityId string
|
||||
SysMenuID uint
|
||||
SysBaseMenuBtnID uint
|
||||
SysBaseMenuBtn SysBaseMenuBtn
|
||||
AuthorityId string `gorm:"comment:角色ID"`
|
||||
SysMenuID uint `gorm:"comment:菜单ID"`
|
||||
SysBaseMenuBtnID uint `gorm:"comment:菜单按钮ID"`
|
||||
SysBaseMenuBtn SysBaseMenuBtn ` gorm:"comment:按钮详情"`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package system
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
)
|
||||
|
||||
// AutoCodeStruct 初始版本自动化代码工具
|
||||
type AutoCodeStruct struct {
|
||||
@@ -14,6 +17,8 @@ type AutoCodeStruct struct {
|
||||
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
|
||||
Fields []*Field `json:"fields"`
|
||||
DictTypes []string `json:"-"`
|
||||
Package string `json:"package"`
|
||||
PackageT string `json:"-"`
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
@@ -29,3 +34,35 @@ type Field struct {
|
||||
}
|
||||
|
||||
var AutoMoveErr error = errors.New("创建代码成功并移动文件成功")
|
||||
|
||||
type SysAutoCode struct {
|
||||
global.GVA_MODEL
|
||||
PackageName string `json:"packageName" gorm:"comment:包名"`
|
||||
Label string `json:"label" gorm:"comment:展示名"`
|
||||
Desc string `json:"desc" gorm:"comment:描述"`
|
||||
}
|
||||
|
||||
type AutoPlugReq struct {
|
||||
PlugName string `json:"plugName"` // 必然大写开头
|
||||
Snake string `json:"snake"` // 后端自动转为 snake
|
||||
RouterGroup string `json:"routerGroup"`
|
||||
HasGlobal bool `json:"hasGlobal"`
|
||||
HasRequest bool `json:"hasRequest"`
|
||||
HasResponse bool `json:"hasResponse"`
|
||||
NeedModel bool `json:"needModel"`
|
||||
Global []struct {
|
||||
Key string `json:"key"`
|
||||
Type string `json:"type"`
|
||||
Desc string `json:"desc"`
|
||||
} `json:"global"`
|
||||
Request []struct {
|
||||
Key string `json:"key"`
|
||||
Type string `json:"type"`
|
||||
Desc string `json:"desc"`
|
||||
} `json:"request"`
|
||||
Response []struct {
|
||||
Key string `json:"key"`
|
||||
Type string `json:"type"`
|
||||
Desc string `json:"desc"`
|
||||
} `json:"response"`
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
// SysAutoCodeHistory 自动迁移代码记录,用于回滚,重放使用
|
||||
type SysAutoCodeHistory struct {
|
||||
global.GVA_MODEL
|
||||
Package string `json:"package"`
|
||||
TableName string `json:"tableName"`
|
||||
RequestMeta string `gorm:"type:text" json:"requestMeta,omitempty"` // 前端传入的结构化信息
|
||||
AutoCodePath string `gorm:"type:text" json:"autoCodePath,omitempty"` // 其他meta信息 path;path
|
||||
|
||||
@@ -35,3 +35,7 @@ type SysBaseMenuParameter struct {
|
||||
Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key
|
||||
Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值
|
||||
}
|
||||
|
||||
func (SysBaseMenu) TableName() string {
|
||||
return "sys_base_menus"
|
||||
}
|
||||
|
||||
@@ -14,3 +14,7 @@ type SysDictionary struct {
|
||||
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:描述"` // 描述
|
||||
SysDictionaryDetails []SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
|
||||
}
|
||||
|
||||
func (SysDictionary) TableName() string {
|
||||
return "sys_dictionaries"
|
||||
}
|
||||
|
||||
@@ -14,3 +14,7 @@ type SysDictionaryDetail struct {
|
||||
Sort int `json:"sort" form:"sort" gorm:"column:sort;comment:排序标记"` // 排序标记
|
||||
SysDictionaryID int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
|
||||
}
|
||||
|
||||
func (SysDictionaryDetail) TableName() string {
|
||||
return "sys_dictionary_details"
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package system
|
||||
|
||||
import "github.com/gookit/color"
|
||||
|
||||
type InitDBFunc interface {
|
||||
Init() (err error)
|
||||
}
|
||||
|
||||
const (
|
||||
Mysql = "mysql"
|
||||
Pgsql = "pgsql"
|
||||
InitSuccess = "\n[%v] --> 初始数据成功!\n"
|
||||
AuthorityMenu = "\n[%v] --> %v 视图已存在!\n"
|
||||
InitDataExist = "\n[%v] --> %v 表的初始数据已存在!\n"
|
||||
InitDataFailed = "\n[%v] --> %v 表初始数据失败! \nerr: %+v\n"
|
||||
InitDataSuccess = "\n[%v] --> %v 表初始数据成功!\n"
|
||||
)
|
||||
|
||||
type InitData interface {
|
||||
TableName() string
|
||||
Initialize() error
|
||||
CheckDataExist() bool
|
||||
}
|
||||
|
||||
// MysqlDataInitialize Mysql 初始化接口使用封装
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func MysqlDataInitialize(inits ...InitData) error {
|
||||
var entity SysMenu
|
||||
for i := 0; i < len(inits); i++ {
|
||||
if inits[i].TableName() == entity.TableName() {
|
||||
if k := inits[i].CheckDataExist(); k {
|
||||
color.Info.Printf(AuthorityMenu, Mysql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if inits[i].CheckDataExist() {
|
||||
color.Info.Printf(InitDataExist, Mysql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := inits[i].Initialize(); err != nil {
|
||||
color.Info.Printf(InitDataFailed, Mysql, err)
|
||||
return err
|
||||
} else {
|
||||
color.Info.Printf(InitDataSuccess, Mysql, inits[i].TableName())
|
||||
}
|
||||
}
|
||||
color.Info.Printf(InitSuccess, Mysql)
|
||||
return nil
|
||||
}
|
||||
|
||||
// PgsqlDataInitialize Pgsql 初始化接口使用封装
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func PgsqlDataInitialize(inits ...InitData) error {
|
||||
var entity SysMenu
|
||||
for i := 0; i < len(inits); i++ {
|
||||
if inits[i].TableName() == entity.TableName() {
|
||||
if k := inits[i].CheckDataExist(); k {
|
||||
color.Info.Printf(AuthorityMenu, Pgsql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if inits[i].CheckDataExist() {
|
||||
color.Info.Printf(InitDataExist, Pgsql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := inits[i].Initialize(); err != nil {
|
||||
color.Info.Printf(InitDataFailed, Pgsql, err)
|
||||
continue
|
||||
} else {
|
||||
color.Info.Printf(InitDataSuccess, Pgsql, inits[i].TableName())
|
||||
}
|
||||
}
|
||||
color.Info.Printf(InitSuccess, Pgsql)
|
||||
return nil
|
||||
}
|
||||
@@ -18,6 +18,10 @@ type SysUser struct {
|
||||
AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
|
||||
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
|
||||
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
|
||||
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户角色ID
|
||||
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
|
||||
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
|
||||
}
|
||||
|
||||
func (SysUser) TableName() string {
|
||||
return "sys_users"
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package example_plugin
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var ExamplePlugin = new(pluginExample)
|
||||
|
||||
type pluginExample struct{}
|
||||
|
||||
func (*pluginExample) Register(group *gin.RouterGroup) {
|
||||
//如需细分权限 可以在此处use中间件 gva项目包名已改为github模式
|
||||
//所以整个plugin可以直接独立到外层开启为新的项目 然后用包的形式导入也是可以完整运行的
|
||||
// 例:
|
||||
/*
|
||||
group.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()).GET("hello", func(context *gin.Context) {
|
||||
context.JSON(200, "hello world")
|
||||
})
|
||||
*/
|
||||
group.GET("hello", func(context *gin.Context) {
|
||||
context.JSON(200, "hello world")
|
||||
})
|
||||
}
|
||||
|
||||
func (*pluginExample) RouterPath() string {
|
||||
return "group"
|
||||
}
|
||||
+14
-14
@@ -1,10 +1,10 @@
|
||||
package autocode
|
||||
package {{.Package}}
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/{{.Package}}"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
|
||||
{{.Package}}Req "github.com/flipped-aurora/gin-vue-admin/server/model/{{.Package}}/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
type {{.StructName}}Api struct {
|
||||
}
|
||||
|
||||
var {{.Abbreviation}}Service = service.ServiceGroupApp.AutoCodeServiceGroup.{{.StructName}}Service
|
||||
var {{.Abbreviation}}Service = service.ServiceGroupApp.{{.PackageT}}ServiceGroup.{{.StructName}}Service
|
||||
|
||||
|
||||
// Create{{.StructName}} 创建{{.StructName}}
|
||||
@@ -23,11 +23,11 @@ var {{.Abbreviation}}Service = service.ServiceGroupApp.AutoCodeServiceGroup.{{.S
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.{{.StructName}} true "创建{{.StructName}}"
|
||||
// @Param data body {{.Package}}.{{.StructName}} true "创建{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/create{{.StructName}} [post]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} autocode.{{.StructName}}
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
if err := {{.Abbreviation}}Service.Create{{.StructName}}({{.Abbreviation}}); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
@@ -43,11 +43,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Con
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.{{.StructName}} true "删除{{.StructName}}"
|
||||
// @Param data body {{.Package}}.{{.StructName}} true "删除{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} autocode.{{.StructName}}
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
if err := {{.Abbreviation}}Service.Delete{{.StructName}}({{.Abbreviation}}); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
@@ -83,11 +83,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gi
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.{{.StructName}} true "更新{{.StructName}}"
|
||||
// @Param data body {{.Package}}.{{.StructName}} true "更新{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /{{.Abbreviation}}/update{{.StructName}} [put]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} autocode.{{.StructName}}
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
if err := {{.Abbreviation}}Service.Update{{.StructName}}({{.Abbreviation}}); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
@@ -103,11 +103,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Con
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query autocode.{{.StructName}} true "用id查询{{.StructName}}"
|
||||
// @Param data query {{.Package}}.{{.StructName}} true "用id查询{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} autocode.{{.StructName}}
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
_ = c.ShouldBindQuery(&{{.Abbreviation}})
|
||||
if err, re{{.Abbreviation}} := {{.Abbreviation}}Service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
@@ -123,11 +123,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Conte
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query autocodeReq.{{.StructName}}Search true "分页获取{{.StructName}}列表"
|
||||
// @Param data query {{.Package}}Req.{{.StructName}}Search true "分页获取{{.StructName}}列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Context) {
|
||||
var pageInfo autocodeReq.{{.StructName}}Search
|
||||
var pageInfo {{.Package}}Req.{{.StructName}}Search
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
if err, list, total := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// 自动生成模板{{.StructName}}
|
||||
package autocode
|
||||
package {{.Package}}
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/{{.Package}}"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
)
|
||||
|
||||
type {{.StructName}}Search struct{
|
||||
autocode.{{.StructName}}
|
||||
{{.Package}}.{{.StructName}}
|
||||
request.PageInfo
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package autocode
|
||||
package {{.Package}}
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1"
|
||||
@@ -13,7 +13,7 @@ type {{.StructName}}Router struct {
|
||||
func (s *{{.StructName}}Router) Init{{.StructName}}Router(Router *gin.RouterGroup) {
|
||||
{{.Abbreviation}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord())
|
||||
{{.Abbreviation}}RouterWithoutRecord := Router.Group("{{.Abbreviation}}")
|
||||
var {{.Abbreviation}}Api = v1.ApiGroupApp.AutoCodeApiGroup.{{.StructName}}Api
|
||||
var {{.Abbreviation}}Api = v1.ApiGroupApp.{{.PackageT}}ApiGroup.{{.StructName}}Api
|
||||
{
|
||||
{{.Abbreviation}}Router.POST("create{{.StructName}}", {{.Abbreviation}}Api.Create{{.StructName}}) // 新建{{.StructName}}
|
||||
{{.Abbreviation}}Router.DELETE("delete{{.StructName}}", {{.Abbreviation}}Api.Delete{{.StructName}}) // 删除{{.StructName}}
|
||||
+11
-11
@@ -1,10 +1,10 @@
|
||||
package autocode
|
||||
package {{.Package}}
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/{{.Package}}"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
|
||||
{{.Package}}Req "github.com/flipped-aurora/gin-vue-admin/server/model/{{.Package}}/request"
|
||||
)
|
||||
|
||||
type {{.StructName}}Service struct {
|
||||
@@ -12,14 +12,14 @@ type {{.StructName}}Service struct {
|
||||
|
||||
// Create{{.StructName}} 创建{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service) Create{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service) Create{{.StructName}}({{.Abbreviation}} {{.Package}}.{{.StructName}}) (err error) {
|
||||
err = global.GVA_DB.Create(&{{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete{{.StructName}} 删除{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.Abbreviation}} {{.Package}}.{{.StructName}}) (err error) {
|
||||
err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
@@ -27,32 +27,32 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.
|
||||
// Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]autocode.{{.StructName}}{},"id in ?",ids.Ids).Error
|
||||
err = global.GVA_DB.Delete(&[]{{.Package}}.{{.StructName}}{},"id in ?",ids.Ids).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Update{{.StructName}} 更新{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Update{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Update{{.StructName}}({{.Abbreviation}} {{.Package}}.{{.StructName}}) (err error) {
|
||||
err = global.GVA_DB.Save(&{{.Abbreviation}}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Get{{.StructName}} 根据id获取{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} autocode.{{.StructName}}) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} {{.Package}}.{{.StructName}}) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error
|
||||
return
|
||||
}
|
||||
|
||||
// Get{{.StructName}}InfoList 分页获取{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList(info autoCodeReq.{{.StructName}}Search) (err error, list interface{}, total int64) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList(info {{.Package}}Req.{{.StructName}}Search) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
db := global.GVA_DB.Model(&autocode.{{.StructName}}{})
|
||||
var {{.Abbreviation}}s []autocode.{{.StructName}}
|
||||
db := global.GVA_DB.Model(&{{.Package}}.{{.StructName}}{})
|
||||
var {{.Abbreviation}}s []{{.Package}}.{{.StructName}}
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
{{- range .Fields}}
|
||||
{{- if .FieldSearchType}}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package autocode
|
||||
package {{ .PackageName }}
|
||||
|
||||
type ApiGroup struct {
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
||||
AutoCodeExampleApi
|
||||
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package subcontract
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed api_enter.go.tpl
|
||||
var API []byte
|
||||
|
||||
//go:embed router_enter.go.tpl
|
||||
var Router []byte
|
||||
|
||||
//go:embed service_enter.go.tpl
|
||||
var Server []byte
|
||||
@@ -0,0 +1,7 @@
|
||||
package {{ .PackageName }}
|
||||
|
||||
type RouterGroup struct {
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
||||
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package {{ .PackageName }}
|
||||
|
||||
|
||||
type ServiceGroup struct {
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
||||
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
<el-button size="small" type="primary" @click="onDelete">确定</el-button>
|
||||
</div>
|
||||
<template #reference>
|
||||
<el-button icon="delete" size="small" style="margin-left: 10px;" :disabled="!multipleSelection.length">删除</el-button>
|
||||
<el-button icon="delete" size="small" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="deleteVisible = true">删除</el-button>
|
||||
</template>
|
||||
</el-popover>
|
||||
</div>
|
||||
@@ -0,0 +1,32 @@
|
||||
package example_plugin
|
||||
|
||||
// 我们为您准备了一个需要提供api的插件模板 您只需要按照此模板注册路由即可 插件使用请把此包放置在plugin下
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var ExamplePlugin = new(pluginExample)
|
||||
|
||||
type pluginExample struct{}
|
||||
|
||||
func NewPluginExample() *pluginExample {
|
||||
// 此处为注册生命周期 可以在此处写初始化内容
|
||||
return &pluginExample{}
|
||||
}
|
||||
|
||||
func (*pluginExample) Register(group *gin.RouterGroup) {
|
||||
//如需细分权限 可以在此处use中间件 gva项目包名已改为github模式
|
||||
//所以整个plugin可以直接独立到外层开启为新的项目 然后用包的形式导入也是可以完整运行的
|
||||
|
||||
group.GET("hello",
|
||||
func(context *gin.Context) {
|
||||
// 此处请填写handle函数
|
||||
// 您依然可以模仿gva分层进行插件制作 当然您也可以按照您所习惯的分层模式开发
|
||||
context.JSON(200, "hello world")
|
||||
})
|
||||
}
|
||||
|
||||
func (*pluginExample) RouterPath() string {
|
||||
// 此处为您插件的总路由path 录入本插件安装进入项目后 会自动产生路由 /[主项目跟路由(如果有的话)]/group/xxxx
|
||||
return "group"
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
## GVA 阿里云短信发送功能插件
|
||||
#### 开发者:GIN-VUE-ADMIN 官方
|
||||
|
||||
### 使用步骤
|
||||
|
||||
#### 1. 前往GVA主程序下的initialize/router.go 在Routers 方法最末尾按照你需要的及安全模式添加本插件
|
||||
例:
|
||||
本插件可以采用gva的配置文件 也可以直接写死内容作为配置 建议为gva添加配置文件结构 然后将配置传入
|
||||
PluginInit(PublicGroup, sms.CreateAliSmsPlug("短信的AccessKey ID", "短信的AccessKey Secret", "短信的 SignName"))
|
||||
|
||||
### 2. 配置说明
|
||||
|
||||
#### 2-1 全局配置结构体说明
|
||||
|
||||
type AliSms struct {
|
||||
AccessKeyId string `mapstructure:"accessKeyId" json:"accessKeyId" yaml:"accessKeyId"` // 短信的AccessKey ID
|
||||
AccessSecret string `mapstructure:"accessSecret" json:"accessSecret" yaml:"accessSecret"` // 短信的AccessKey Secret
|
||||
SignName string `mapstructure:"signName" json:"signName" yaml:"signName"` // 短信的 SignName
|
||||
}
|
||||
|
||||
#### 2-2 入参结构说明
|
||||
|
||||
type AliModel struct {
|
||||
Phones []string `json:"phones"` // 需要发送的手机(可传入多个)
|
||||
TemplateCode string `json:"templateCode"` // 短信模板的code
|
||||
TemplateParam string `json:"templateParam"` // 短信模板的填充
|
||||
}
|
||||
|
||||
templateParam: 模板使用json字符串 {"code":"xxx"} 对应你模板里面的变量key和value
|
||||
|
||||
### 3. 方法API
|
||||
// 无
|
||||
|
||||
### 4. 可直接调用的接口
|
||||
|
||||
发送邮件接口接口: /aliSms/sendSms [post] 已配置swagger
|
||||
入参:
|
||||
type AliModel struct {
|
||||
Phones []string `json:"phones"` // 需要发送的手机(可传入多个)
|
||||
TemplateCode string `json:"templateCode"` // 短信模板的code
|
||||
TemplateParam string `json:"templateParam"` // 短信模板的填充
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
{{ if .NeedModel }} "github.com/flipped-aurora/gin-vue-admin/server/plugin/{{ .Snake}}/model" {{ end }}
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/{{ .Snake}}/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type {{ .PlugName}}Api struct{}
|
||||
|
||||
// @Tags {{ .PlugName}}
|
||||
// @Summary 请手动填写接口功能
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
|
||||
// @Router /{{ .RouterGroup}}/routerName[post]
|
||||
func (p *{{ .PlugName}}Api) ApiName(c *gin.Context) {
|
||||
{{- if .HasRequest}}
|
||||
var plug model.Request
|
||||
_ = c.ShouldBindJSON(&plug)
|
||||
{{ end -}}
|
||||
if err{{- if .HasResponse }},res {{ end -}}:= service.ServiceGroupApp.PlugService({{ if .HasRequest }}plug{{ end -}}); err != nil {
|
||||
global.GVA_LOG.Error("失败!", zap.Error(err))
|
||||
response.FailWithMessage("失败", c)
|
||||
} else {
|
||||
{{if .HasResponse }}
|
||||
response.OkWithDetailed(res,"成功",c)
|
||||
{{else}}
|
||||
response.OkWithData("成功", c)
|
||||
{{ end -}}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package api
|
||||
|
||||
type ApiGroup struct {
|
||||
{{ .PlugName}}Api
|
||||
}
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
||||
@@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
{{- if .HasGlobal }}
|
||||
type {{ .PlugName }} struct {
|
||||
{{- range .Global }}
|
||||
{{ .Key }} {{ .Type }} {{- if ne .Desc "" }} // {{ .Desc }} {{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
{{ end -}}
|
||||
@@ -0,0 +1,8 @@
|
||||
package global
|
||||
|
||||
{{- if .HasGlobal }}
|
||||
|
||||
import "github.com/flipped-aurora/gin-vue-admin/server/plugin/{{ .Snake}}/config"
|
||||
|
||||
var GlobalConfig = new(config.{{ .PlugName}})
|
||||
{{ end -}}
|
||||
@@ -0,0 +1,29 @@
|
||||
package {{ .Snake}}
|
||||
|
||||
import (
|
||||
{{- if .HasGlobal }}
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/{{ .Snake}}/global"
|
||||
{{- end }}
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/{{ .Snake}}/router"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type {{ .PlugName}}Plugin struct {
|
||||
}
|
||||
|
||||
func Create{{ .PlugName}}Plug({{- range .Global}} {{.Key}} {{.Type}} {{- end }})*{{ .PlugName}}Plugin {
|
||||
{{- if .HasGlobal }}
|
||||
{{- range .Global}}
|
||||
global.GlobalConfig.{{.Key}} = {{.Key}}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
return &{{ .PlugName}}Plugin{}
|
||||
}
|
||||
|
||||
func (*{{ .PlugName}}Plugin) Register(group *gin.RouterGroup) {
|
||||
router.RouterGroupApp.Init{{ .PlugName}}Router(group)
|
||||
}
|
||||
|
||||
func (*{{ .PlugName}}Plugin) RouterPath() string {
|
||||
return "{{ .RouterGroup}}"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
{{- if .HasRequest }}
|
||||
type Request struct {
|
||||
{{- range .Request }}
|
||||
{{ .Key }} {{ .Type }} {{- if ne .Desc "" }} // {{ .Desc }} {{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
{{ end -}}
|
||||
|
||||
{{- if .HasResponse }}
|
||||
type Response struct {
|
||||
{{- range .Response }}
|
||||
{{ .Key }} {{ .Type }} {{- if ne .Desc "" }} // {{ .Desc }} {{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
{{ end -}}
|
||||
@@ -0,0 +1,7 @@
|
||||
package router
|
||||
|
||||
type RouterGroup struct {
|
||||
{{ .PlugName}}Router
|
||||
}
|
||||
|
||||
var RouterGroupApp = new(RouterGroup)
|
||||
@@ -0,0 +1,17 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/{{ .Snake}}/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type {{ .PlugName}}Router struct {
|
||||
}
|
||||
|
||||
func (s *{{ .PlugName}}Router) Init{{ .PlugName}}Router(Router *gin.RouterGroup) {
|
||||
plugRouter := Router
|
||||
plugApi := api.ApiGroupApp.{{ .PlugName}}Api
|
||||
{
|
||||
plugRouter.POST("routerName", plugApi.ApiName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package service
|
||||
|
||||
type ServiceGroup struct {
|
||||
{{ .PlugName}}Service
|
||||
}
|
||||
|
||||
var ServiceGroupApp = new(ServiceGroup)
|
||||
@@ -0,0 +1,14 @@
|
||||
package service
|
||||
|
||||
{{- if .NeedModel }}
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/{{ .Snake}}/model"
|
||||
)
|
||||
{{ end }}
|
||||
|
||||
type {{ .PlugName}}Service struct{}
|
||||
|
||||
func (e *{{ .PlugName}}Service) PlugService({{- if .HasRequest }}req model.Request {{ end -}}) (err error{{- if .HasResponse }},res model.Response{{ end -}}) {
|
||||
// 写你的业务逻辑
|
||||
return nil{{- if .HasResponse }},res {{ end }}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package autocode
|
||||
|
||||
import (
|
||||
v1 "github.com/flipped-aurora/gin-vue-admin/server/api/v1"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AutoCodeExampleRouter struct{}
|
||||
|
||||
func (s *AutoCodeExampleRouter) InitSysAutoCodeExampleRouter(Router *gin.RouterGroup) {
|
||||
autoCodeExampleRouter := Router.Group("autoCodeExample").Use(middleware.OperationRecord())
|
||||
autoCodeExampleRouterWithoutRecord := Router.Group("autoCodeExample")
|
||||
autoCodeExampleApi := v1.ApiGroupApp.AutoCodeApiGroup.AutoCodeExampleApi
|
||||
{
|
||||
autoCodeExampleRouter.POST("createSysAutoCodeExample", autoCodeExampleApi.CreateAutoCodeExample) // 新建AutoCodeExample
|
||||
autoCodeExampleRouter.DELETE("deleteSysAutoCodeExample", autoCodeExampleApi.DeleteAutoCodeExample) // 删除AutoCodeExample
|
||||
autoCodeExampleRouter.PUT("updateSysAutoCodeExample", autoCodeExampleApi.UpdateAutoCodeExample) // 更新AutoCodeExample
|
||||
}
|
||||
{
|
||||
autoCodeExampleRouterWithoutRecord.GET("findSysAutoCodeExample", autoCodeExampleApi.FindAutoCodeExample) // 根据ID获取AutoCodeExample
|
||||
autoCodeExampleRouterWithoutRecord.GET("getSysAutoCodeExampleList", autoCodeExampleApi.GetAutoCodeExampleList) // 获取AutoCodeExample列表
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package autocode
|
||||
|
||||
type RouterGroup struct {
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
||||
AutoCodeExampleRouter
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/system"
|
||||
)
|
||||
@@ -9,7 +8,6 @@ import (
|
||||
type RouterGroup struct {
|
||||
System system.RouterGroup
|
||||
Example example.RouterGroup
|
||||
Autocode autocode.RouterGroup
|
||||
}
|
||||
|
||||
var RouterGroupApp = new(RouterGroup)
|
||||
|
||||
@@ -14,9 +14,10 @@ func (e *FileUploadAndDownloadRouter) InitFileUploadAndDownloadRouter(Router *gi
|
||||
fileUploadAndDownloadRouter.POST("upload", exaFileUploadAndDownloadApi.UploadFile) // 上传文件
|
||||
fileUploadAndDownloadRouter.POST("getFileList", exaFileUploadAndDownloadApi.GetFileList) // 获取上传文件列表
|
||||
fileUploadAndDownloadRouter.POST("deleteFile", exaFileUploadAndDownloadApi.DeleteFile) // 删除指定文件
|
||||
fileUploadAndDownloadRouter.POST("editFileName", exaFileUploadAndDownloadApi.EditFileName) // 编辑文件名或者备注
|
||||
fileUploadAndDownloadRouter.POST("breakpointContinue", exaFileUploadAndDownloadApi.BreakpointContinue) // 断点续传
|
||||
fileUploadAndDownloadRouter.GET("findFile", exaFileUploadAndDownloadApi.FindFile) // 查询当前文件成功的切片
|
||||
fileUploadAndDownloadRouter.POST("breakpointContinueFinish", exaFileUploadAndDownloadApi.BreakpointContinueFinish) // 查询当前文件成功的切片
|
||||
fileUploadAndDownloadRouter.POST("removeChunk", exaFileUploadAndDownloadApi.RemoveChunk) // 查询当前文件成功的切片
|
||||
fileUploadAndDownloadRouter.POST("breakpointContinueFinish", exaFileUploadAndDownloadApi.BreakpointContinueFinish) // 切片传输完成
|
||||
fileUploadAndDownloadRouter.POST("removeChunk", exaFileUploadAndDownloadApi.RemoveChunk) // 删除切片
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,14 @@ func (s *AutoCodeRouter) InitAutoCodeRouter(Router *gin.RouterGroup) {
|
||||
autoCodeRouter := Router.Group("autoCode")
|
||||
autoCodeApi := v1.ApiGroupApp.SystemApiGroup.AutoCodeApi
|
||||
{
|
||||
autoCodeRouter.GET("getDB", autoCodeApi.GetDB) // 获取数据库
|
||||
autoCodeRouter.GET("getTables", autoCodeApi.GetTables) // 获取对应数据库的表
|
||||
autoCodeRouter.GET("getColumn", autoCodeApi.GetColumn) // 获取指定表所有字段信息
|
||||
autoCodeRouter.POST("preview", autoCodeApi.PreviewTemp) // 获取自动创建代码预览
|
||||
autoCodeRouter.POST("createTemp", autoCodeApi.CreateTemp) // 创建自动化代码
|
||||
autoCodeRouter.GET("getDB", autoCodeApi.GetDB) // 获取数据库
|
||||
autoCodeRouter.GET("getTables", autoCodeApi.GetTables) // 获取对应数据库的表
|
||||
autoCodeRouter.GET("getColumn", autoCodeApi.GetColumn) // 获取指定表所有字段信息
|
||||
autoCodeRouter.POST("preview", autoCodeApi.PreviewTemp) // 获取自动创建代码预览
|
||||
autoCodeRouter.POST("createTemp", autoCodeApi.CreateTemp) // 创建自动化代码
|
||||
autoCodeRouter.POST("createPackage", autoCodeApi.CreatePackage) // 创建package包
|
||||
autoCodeRouter.POST("getPackage", autoCodeApi.GetPackage) // 获取package包
|
||||
autoCodeRouter.POST("delPackage", autoCodeApi.DelPackage) // 删除package包
|
||||
autoCodeRouter.POST("createPlug", autoCodeApi.AutoPlug) // 自动插件包模板
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) {
|
||||
userRouterWithoutRecord := Router.Group("user")
|
||||
baseApi := v1.ApiGroupApp.SystemApiGroup.BaseApi
|
||||
{
|
||||
userRouter.POST("register", baseApi.Register) // 用户注册账号
|
||||
userRouter.POST("admin_register", baseApi.Register) // 管理员注册账号
|
||||
userRouter.POST("changePassword", baseApi.ChangePassword) // 用户修改密码
|
||||
userRouter.POST("setUserAuthority", baseApi.SetUserAuthority) // 设置用户权限
|
||||
userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 删除用户
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
package autocode
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
|
||||
)
|
||||
|
||||
type AutoCodeExampleService struct{}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: CreateAutoCodeExample
|
||||
//@description: 创建自动化示例数据
|
||||
//@param: autoCodeExampleService *AutoCodeExampleService
|
||||
//@return: err error
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) CreateAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) {
|
||||
err = global.GVA_DB.Create(&autoCodeExample).Error
|
||||
return err
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: DeleteAutoCodeExample
|
||||
//@description: 删除自动化示例数据
|
||||
//@param: autoCodeExample autocode.AutoCodeExample
|
||||
//@return: err error
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) DeleteAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) {
|
||||
err = global.GVA_DB.Delete(&autoCodeExample).Error
|
||||
return err
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: UpdateAutoCodeExample
|
||||
//@description: 更新自动化示例数据
|
||||
//@param: autoCodeExample *autocode.AutoCodeExample
|
||||
//@return: err error
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) UpdateAutoCodeExample(autoCodeExample *autocode.AutoCodeExample) (err error) {
|
||||
err = global.GVA_DB.Save(autoCodeExample).Error
|
||||
return err
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetAutoCodeExampleDetail
|
||||
//@description: 根据id获取自动化示例数据
|
||||
//@param: id uint
|
||||
//@return: err error, autoCodeExample autocode.AutoCodeExample
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExample(id uint) (err error, autoCodeExample autocode.AutoCodeExample) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&autoCodeExample).Error
|
||||
return
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetAutoCodeExampleInfoList
|
||||
//@description: 分页获取自动化示例数据
|
||||
//@param: info request.AutoCodeExampleSearch
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExampleInfoList(info request.AutoCodeExampleSearch) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
db := global.GVA_DB.Model(&autocode.AutoCodeExample{})
|
||||
var autoCodeExamples []autocode.AutoCodeExample
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
if info.AutoCodeExampleField != "" {
|
||||
db = db.Where("label LIKE ?", "%"+info.AutoCodeExampleField+"%")
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = db.Limit(limit).Offset(offset).Find(&autoCodeExamples).Error
|
||||
return err, autoCodeExamples, total
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package autocode
|
||||
|
||||
type ServiceGroup struct {
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
|
||||
AutoCodeExampleService
|
||||
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service/autocode"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service/system"
|
||||
)
|
||||
|
||||
type ServiceGroup struct {
|
||||
SystemServiceGroup system.ServiceGroup
|
||||
ExampleServiceGroup example.ServiceGroup
|
||||
AutoCodeServiceGroup autocode.ServiceGroup
|
||||
SystemServiceGroup system.ServiceGroup
|
||||
ExampleServiceGroup example.ServiceGroup
|
||||
}
|
||||
|
||||
var ServiceGroupApp = new(ServiceGroup)
|
||||
|
||||
@@ -23,7 +23,7 @@ func (e *FileUploadAndDownloadService) Upload(file example.ExaFileUploadAndDownl
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: FindFile
|
||||
//@description: 删除文件切片记录
|
||||
//@description: 查询文件记录
|
||||
//@param: id uint
|
||||
//@return: error, model.ExaFileUploadAndDownload
|
||||
|
||||
@@ -53,6 +53,12 @@ func (e *FileUploadAndDownloadService) DeleteFile(file example.ExaFileUploadAndD
|
||||
return err
|
||||
}
|
||||
|
||||
// EditFileName 编辑文件名或者备注
|
||||
func (e *FileUploadAndDownloadService) EditFileName(file example.ExaFileUploadAndDownload) (err error) {
|
||||
var fileFromDb example.ExaFileUploadAndDownload
|
||||
return global.GVA_DB.Where("id = ?", file.ID).First(&fileFromDb).Update("name", file.Name).Error
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetFileRecordInfoList
|
||||
//@description: 分页获取数据
|
||||
@@ -62,8 +68,12 @@ func (e *FileUploadAndDownloadService) DeleteFile(file example.ExaFileUploadAndD
|
||||
func (e *FileUploadAndDownloadService) GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
keyword := info.Keyword
|
||||
db := global.GVA_DB.Model(&example.ExaFileUploadAndDownload{})
|
||||
var fileLists []example.ExaFileUploadAndDownload
|
||||
if len(keyword) > 0 {
|
||||
db = db.Where("name LIKE ?", "%"+keyword+"%")
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
@@ -89,6 +90,9 @@ func (apiService *ApiService) GetAPIInfoList(api system.SysApi, info request.Pag
|
||||
} else {
|
||||
OrderStr = order
|
||||
}
|
||||
} else { // didn't matched any order key in `orderMap`
|
||||
err = fmt.Errorf("非法的排序字段: %v", order)
|
||||
return err, apiList, total
|
||||
}
|
||||
|
||||
err = db.Order(OrderStr).Find(&apiList).Error
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/format"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/resource/autocode_template/subcontract"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
@@ -19,48 +27,88 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
autoPath = "autocode_template/"
|
||||
basePath = "resource/template"
|
||||
autoPath = "autocode_template/"
|
||||
autocodePath = "resource/autocode_template"
|
||||
plugPath = "resource/plug_template"
|
||||
packageService = "service/%s/enter.go"
|
||||
packageServiceName = "service"
|
||||
packageRouter = "router/%s/enter.go"
|
||||
packageRouterName = "router"
|
||||
packageAPI = "api/v1/%s/enter.go"
|
||||
packageAPIName = "api/v1"
|
||||
)
|
||||
|
||||
var injectionPaths []injectionMeta
|
||||
type autoPackage struct {
|
||||
path string
|
||||
temp string
|
||||
name string
|
||||
}
|
||||
|
||||
func Init() {
|
||||
if len(injectionPaths) != 0 {
|
||||
return
|
||||
}
|
||||
var (
|
||||
packageInjectionMap map[string]astInjectionMeta
|
||||
injectionPaths []injectionMeta
|
||||
)
|
||||
|
||||
func Init(Package string) {
|
||||
injectionPaths = []injectionMeta{
|
||||
{
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "gorm.go"),
|
||||
funcName: "MysqlTables",
|
||||
structNameF: "autocode.%s{},",
|
||||
structNameF: Package + ".%s{},",
|
||||
},
|
||||
{
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "router.go"),
|
||||
funcName: "Routers",
|
||||
structNameF: "autocodeRouter.Init%sRouter(PrivateGroup)",
|
||||
structNameF: Package + "Router.Init%sRouter(PrivateGroup)",
|
||||
},
|
||||
{
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SApi, "enter.go"),
|
||||
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SApi, Package), "enter.go"),
|
||||
funcName: "ApiGroup",
|
||||
structNameF: "%sApi",
|
||||
},
|
||||
{
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SRouter, "enter.go"),
|
||||
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SRouter, Package), "enter.go"),
|
||||
funcName: "RouterGroup",
|
||||
structNameF: "%sRouter",
|
||||
},
|
||||
{
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SService, "enter.go"),
|
||||
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SService, Package), "enter.go"),
|
||||
funcName: "ServiceGroup",
|
||||
structNameF: "%sService",
|
||||
},
|
||||
}
|
||||
|
||||
packageInjectionMap = map[string]astInjectionMeta{
|
||||
packageServiceName: {
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, "service", "enter.go"),
|
||||
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
|
||||
packageNameF: "%s",
|
||||
groupName: "ServiceGroup",
|
||||
structNameF: "%sServiceGroup",
|
||||
},
|
||||
packageRouterName: {
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, "router", "enter.go"),
|
||||
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
|
||||
packageNameF: "%s",
|
||||
groupName: "RouterGroup",
|
||||
structNameF: "%s",
|
||||
},
|
||||
packageAPIName: {
|
||||
path: filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, "api/v1", "enter.go"),
|
||||
importCodeF: "github.com/flipped-aurora/gin-vue-admin/server/%s/%s",
|
||||
packageNameF: "%s",
|
||||
groupName: "ApiGroup",
|
||||
structNameF: "%sApiGroup",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type injectionMeta struct {
|
||||
@@ -69,8 +117,17 @@ type injectionMeta struct {
|
||||
structNameF string // 带格式化的
|
||||
}
|
||||
|
||||
type astInjectionMeta struct {
|
||||
path string
|
||||
importCodeF string
|
||||
structNameF string
|
||||
packageNameF string
|
||||
groupName string
|
||||
}
|
||||
|
||||
type tplData struct {
|
||||
template *template.Template
|
||||
autoPackage string
|
||||
locationPath string
|
||||
autoCodePath string
|
||||
autoMoveFilePath string
|
||||
@@ -168,7 +225,7 @@ func makeDictTypes(autoCode *system.AutoCodeStruct) {
|
||||
func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
|
||||
makeDictTypes(&autoCode)
|
||||
// 增加判断: 重复创建struct
|
||||
if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.StructName) {
|
||||
if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.StructName, autoCode.Package) {
|
||||
return RepeatErr
|
||||
}
|
||||
dataList, fileList, needMkdir, err := autoCodeService.getNeedList(&autoCode)
|
||||
@@ -206,7 +263,7 @@ func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruc
|
||||
idBf.WriteString(";")
|
||||
}
|
||||
if autoCode.AutoMoveFile { // 判断是否需要自动转移
|
||||
Init()
|
||||
Init(autoCode.Package)
|
||||
for index := range dataList {
|
||||
autoCodeService.addAutoMoveFile(&dataList[index])
|
||||
}
|
||||
@@ -233,11 +290,14 @@ func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruc
|
||||
}
|
||||
}
|
||||
|
||||
if global.GVA_CONFIG.AutoCode.TransferRestart {
|
||||
// endless 会复用之前的指令
|
||||
// 如果是你 goland debug/run 后用的还是之前打包的文件,没有做到真正意义上的重启
|
||||
// 故此,拿掉迁移后的重启功能
|
||||
}
|
||||
var gormPath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "gorm.go")
|
||||
var routePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "router.go")
|
||||
var imporStr = fmt.Sprintf("github.com/flipped-aurora/gin-vue-admin/server/model/%s", autoCode.Package)
|
||||
_ = ImportReference(routePath, "", "", autoCode.Package, "")
|
||||
_ = ImportReference(gormPath, imporStr, "", "", "")
|
||||
|
||||
} else { // 打包
|
||||
if err = utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
|
||||
return err
|
||||
@@ -253,6 +313,7 @@ func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruc
|
||||
injectionCodeMeta.String(),
|
||||
autoCode.TableName,
|
||||
idBf.String(),
|
||||
autoCode.Package,
|
||||
)
|
||||
} else {
|
||||
err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory(
|
||||
@@ -263,6 +324,7 @@ func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruc
|
||||
injectionCodeMeta.String(),
|
||||
autoCode.StructName,
|
||||
idBf.String(),
|
||||
autoCode.Package,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -325,19 +387,19 @@ func (autoCodeService *AutoCodeService) addAutoMoveFile(data *tplData) {
|
||||
if strings.Contains(fileSlice[1], "server") {
|
||||
if strings.Contains(fileSlice[n-2], "router") {
|
||||
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server,
|
||||
global.GVA_CONFIG.AutoCode.SRouter, base)
|
||||
fmt.Sprintf(global.GVA_CONFIG.AutoCode.SRouter, data.autoPackage), base)
|
||||
} else if strings.Contains(fileSlice[n-2], "api") {
|
||||
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SApi, base)
|
||||
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SApi, data.autoPackage), base)
|
||||
} else if strings.Contains(fileSlice[n-2], "service") {
|
||||
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SService, base)
|
||||
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SService, data.autoPackage), base)
|
||||
} else if strings.Contains(fileSlice[n-2], "model") {
|
||||
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SModel, base)
|
||||
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SModel, data.autoPackage), base)
|
||||
} else if strings.Contains(fileSlice[n-2], "request") {
|
||||
data.autoMoveFilePath = filepath.Join(global.GVA_CONFIG.AutoCode.Root,
|
||||
global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SRequest, base)
|
||||
global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SRequest, data.autoPackage), base)
|
||||
}
|
||||
} else if strings.Contains(fileSlice[1], "web") {
|
||||
if strings.Contains(fileSlice[n-1], "js") {
|
||||
@@ -422,7 +484,7 @@ func (autoCodeService *AutoCodeService) getNeedList(autoCode *system.AutoCodeStr
|
||||
utils.TrimSpace(field)
|
||||
}
|
||||
// 获取 basePath 文件夹下所有tpl文件
|
||||
tplFileList, err := autoCodeService.GetAllTplFile(basePath, nil)
|
||||
tplFileList, err := autoCodeService.GetAllTplFile(autocodePath, nil)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
@@ -431,7 +493,7 @@ func (autoCodeService *AutoCodeService) getNeedList(autoCode *system.AutoCodeStr
|
||||
needMkdir = make([]string, 0, len(tplFileList)) // 当文件夹下存在多个tpl文件时,改为map更合理
|
||||
// 根据文件路径生成 tplData 结构体,待填充数据
|
||||
for _, value := range tplFileList {
|
||||
dataList = append(dataList, tplData{locationPath: value})
|
||||
dataList = append(dataList, tplData{locationPath: value, autoPackage: autoCode.Package})
|
||||
}
|
||||
// 生成 *Template, 填充 template 字段
|
||||
for index, value := range dataList {
|
||||
@@ -444,7 +506,7 @@ func (autoCodeService *AutoCodeService) getNeedList(autoCode *system.AutoCodeStr
|
||||
// resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js
|
||||
// resource/template/readme.txt.tpl -> autoCode/readme.txt
|
||||
for index, value := range dataList {
|
||||
trimBase := strings.TrimPrefix(value.locationPath, basePath+"/")
|
||||
trimBase := strings.TrimPrefix(value.locationPath, autocodePath+"/")
|
||||
if trimBase == "readme.txt.tpl" {
|
||||
dataList[index].autoCodePath = autoPath + "readme.txt"
|
||||
continue
|
||||
@@ -487,3 +549,267 @@ func injectionCode(structName string, bf *strings.Builder) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (autoCodeService *AutoCodeService) CreateAutoCode(s *system.SysAutoCode) error {
|
||||
if s.PackageName == "autocode" || s.PackageName == "system" || s.PackageName == "example" || s.PackageName == "" {
|
||||
return errors.New("不能使用已保留的package name")
|
||||
}
|
||||
if !errors.Is(global.GVA_DB.Where("package_name = ?", s.PackageName).First(&system.SysAutoCode{}).Error, gorm.ErrRecordNotFound) {
|
||||
return errors.New("存在相同PackageName")
|
||||
}
|
||||
if e := autoCodeService.CreatePackageTemp(s.PackageName); e != nil {
|
||||
return e
|
||||
}
|
||||
return global.GVA_DB.Create(&s).Error
|
||||
}
|
||||
|
||||
func (autoCodeService *AutoCodeService) GetPackage() (pkgList []system.SysAutoCode, err error) {
|
||||
err = global.GVA_DB.Find(&pkgList).Error
|
||||
return pkgList, err
|
||||
}
|
||||
|
||||
func (autoCodeService *AutoCodeService) DelPackage(a system.SysAutoCode) error {
|
||||
return global.GVA_DB.Delete(&a).Error
|
||||
}
|
||||
|
||||
func (autoCodeService *AutoCodeService) CreatePackageTemp(packageName string) error {
|
||||
Init(packageName)
|
||||
pendingTemp := []autoPackage{{
|
||||
path: packageService,
|
||||
name: packageServiceName,
|
||||
temp: string(subcontract.Server),
|
||||
}, {
|
||||
path: packageRouter,
|
||||
name: packageRouterName,
|
||||
temp: string(subcontract.Router),
|
||||
}, {
|
||||
path: packageAPI,
|
||||
name: packageAPIName,
|
||||
temp: string(subcontract.API),
|
||||
}}
|
||||
for i, s := range pendingTemp {
|
||||
pendingTemp[i].path = filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, filepath.Clean(fmt.Sprintf(s.path, packageName)))
|
||||
}
|
||||
// 选择模板
|
||||
for _, s := range pendingTemp {
|
||||
err := os.MkdirAll(filepath.Dir(s.path), 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(s.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
temp, err := template.New("").Parse(s.temp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = temp.Execute(f, struct {
|
||||
PackageName string `json:"package_name"`
|
||||
}{packageName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 创建完成后在对应的位置插入结构代码
|
||||
for _, v := range pendingTemp {
|
||||
meta := packageInjectionMap[v.name]
|
||||
if err := ImportReference(meta.path, fmt.Sprintf(meta.importCodeF, v.name, packageName), fmt.Sprintf(meta.structNameF, strings.Title(packageName)), fmt.Sprintf(meta.packageNameF, packageName), meta.groupName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Visitor struct {
|
||||
ImportCode string
|
||||
StructName string
|
||||
PackageName string
|
||||
GroupName string
|
||||
}
|
||||
|
||||
func (vi *Visitor) Visit(node ast.Node) ast.Visitor {
|
||||
switch n := node.(type) {
|
||||
case *ast.GenDecl:
|
||||
// 查找有没有import context包
|
||||
// Notice:没有考虑没有import任何包的情况
|
||||
if n.Tok == token.IMPORT && vi.ImportCode != "" {
|
||||
vi.addImport(n)
|
||||
// 不需要再遍历子树
|
||||
return nil
|
||||
}
|
||||
if n.Tok == token.TYPE && vi.StructName != "" && vi.PackageName != "" && vi.GroupName != "" {
|
||||
vi.addStruct(n)
|
||||
return nil
|
||||
}
|
||||
case *ast.FuncDecl:
|
||||
if n.Name.Name == "Routers" {
|
||||
vi.addFuncBodyVar(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
return vi
|
||||
}
|
||||
|
||||
func (vi *Visitor) addStruct(genDecl *ast.GenDecl) ast.Visitor {
|
||||
for i := range genDecl.Specs {
|
||||
switch n := genDecl.Specs[i].(type) {
|
||||
case *ast.TypeSpec:
|
||||
if strings.Index(n.Name.Name, "Group") > -1 {
|
||||
switch t := n.Type.(type) {
|
||||
case *ast.StructType:
|
||||
f := &ast.Field{
|
||||
Names: []*ast.Ident{
|
||||
&ast.Ident{
|
||||
Name: vi.StructName,
|
||||
Obj: &ast.Object{
|
||||
Kind: ast.Var,
|
||||
Name: vi.StructName,
|
||||
},
|
||||
},
|
||||
},
|
||||
Type: &ast.SelectorExpr{
|
||||
X: &ast.Ident{
|
||||
Name: vi.PackageName,
|
||||
},
|
||||
Sel: &ast.Ident{
|
||||
Name: vi.GroupName,
|
||||
},
|
||||
},
|
||||
}
|
||||
t.Fields.List = append(t.Fields.List, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vi
|
||||
}
|
||||
|
||||
func (vi *Visitor) addImport(genDecl *ast.GenDecl) ast.Visitor {
|
||||
// 是否已经import
|
||||
hasImported := false
|
||||
for _, v := range genDecl.Specs {
|
||||
importSpec := v.(*ast.ImportSpec)
|
||||
// 如果已经包含
|
||||
if importSpec.Path.Value == strconv.Quote(vi.ImportCode) {
|
||||
hasImported = true
|
||||
}
|
||||
}
|
||||
if !hasImported {
|
||||
genDecl.Specs = append(genDecl.Specs, &ast.ImportSpec{
|
||||
Path: &ast.BasicLit{
|
||||
Kind: token.STRING,
|
||||
Value: strconv.Quote(vi.ImportCode),
|
||||
},
|
||||
})
|
||||
}
|
||||
return vi
|
||||
}
|
||||
|
||||
func (vi *Visitor) addFuncBodyVar(funDecl *ast.FuncDecl) ast.Visitor {
|
||||
hasVar := false
|
||||
for _, v := range funDecl.Body.List {
|
||||
switch varSpec := v.(type) {
|
||||
case *ast.AssignStmt:
|
||||
for i := range varSpec.Lhs {
|
||||
switch nn := varSpec.Lhs[i].(type) {
|
||||
case *ast.Ident:
|
||||
if nn.Name == vi.PackageName+"Router" {
|
||||
hasVar = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hasVar {
|
||||
assignStmt := &ast.AssignStmt{
|
||||
Lhs: []ast.Expr{
|
||||
&ast.Ident{
|
||||
Name: vi.PackageName + "Router",
|
||||
Obj: &ast.Object{
|
||||
Kind: ast.Var,
|
||||
Name: vi.PackageName + "Router",
|
||||
},
|
||||
},
|
||||
},
|
||||
Tok: token.DEFINE,
|
||||
Rhs: []ast.Expr{
|
||||
&ast.SelectorExpr{
|
||||
X: &ast.SelectorExpr{
|
||||
X: &ast.Ident{
|
||||
Name: "router",
|
||||
},
|
||||
Sel: &ast.Ident{
|
||||
Name: "RouterGroupApp",
|
||||
},
|
||||
},
|
||||
Sel: &ast.Ident{
|
||||
Name: strings.Title(vi.PackageName),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
funDecl.Body.List = append(funDecl.Body.List, funDecl.Body.List[1])
|
||||
index := 1
|
||||
copy(funDecl.Body.List[index+1:], funDecl.Body.List[index:])
|
||||
funDecl.Body.List[index] = assignStmt
|
||||
}
|
||||
return vi
|
||||
}
|
||||
|
||||
func ImportReference(filepath, importCode, structName, packageName, groupName string) error {
|
||||
fSet := token.NewFileSet()
|
||||
fParser, err := parser.ParseFile(fSet, filepath, nil, parser.ParseComments)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
importCode = strings.TrimSpace(importCode)
|
||||
v := &Visitor{
|
||||
ImportCode: importCode,
|
||||
StructName: structName,
|
||||
PackageName: packageName,
|
||||
GroupName: groupName,
|
||||
}
|
||||
if importCode == "" {
|
||||
ast.Print(fSet, fParser)
|
||||
}
|
||||
|
||||
ast.Walk(v, fParser)
|
||||
|
||||
var output []byte
|
||||
buffer := bytes.NewBuffer(output)
|
||||
err = format.Node(buffer, fSet, fParser)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// 写回数据
|
||||
return ioutil.WriteFile(filepath, buffer.Bytes(), 0o600)
|
||||
}
|
||||
|
||||
// 自动创建插件模板
|
||||
func (autoCodeService *AutoCodeService) CreatePlug(plug system.AutoPlugReq) error {
|
||||
tplFileList, _ := autoCodeService.GetAllTplFile(plugPath, nil)
|
||||
for _, tpl := range tplFileList {
|
||||
temp, err := template.ParseFiles(tpl)
|
||||
fmt.Println(err)
|
||||
pathArr := strings.SplitAfter(tpl, "/")
|
||||
if strings.Index(pathArr[2], "tpl") < 0 {
|
||||
dirPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SPlug, plug.Snake+"/"+pathArr[2]))
|
||||
os.MkdirAll(dirPath, 0755)
|
||||
}
|
||||
file := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, fmt.Sprintf(global.GVA_CONFIG.AutoCode.SPlug, plug.Snake+"/"+tpl[len(plugPath):len(tpl)-4]))
|
||||
f, _ := os.OpenFile(file, os.O_WRONLY|os.O_CREATE, 0666)
|
||||
e := temp.Execute(f, plug)
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
return e
|
||||
}
|
||||
defer f.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
|
||||
"github.com/pkg/errors"
|
||||
@@ -74,17 +72,17 @@ func (a *autoCodePgsql) GetColumn(tableName string, dbName string) (data []respo
|
||||
where attribute.attrelid =
|
||||
(select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )) as column_comment
|
||||
FROM INFORMATION_SCHEMA.COLUMNS columns
|
||||
WHERE table_catalog = '@table_catalog'
|
||||
WHERE table_catalog = '?'
|
||||
and table_schema = 'public'
|
||||
and table_name = '@table_name';
|
||||
and table_name = '?';
|
||||
`
|
||||
var entities []response.Column
|
||||
db, _err := gorm.Open(postgres.Open(global.GVA_CONFIG.Pgsql.LinkDsn(dbName)), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)})
|
||||
if _err != nil {
|
||||
return nil, errors.Wrapf(err, "[pgsql] 连接 数据库(%s)的表(%s)失败!", dbName, tableName)
|
||||
}
|
||||
sql = strings.ReplaceAll(sql, "@table_catalog", dbName)
|
||||
sql = strings.ReplaceAll(sql, "@table_name", tableName)
|
||||
err = db.Raw(sql).Scan(&entities).Error
|
||||
//sql = strings.ReplaceAll(sql, "@table_catalog", dbName)
|
||||
//sql = strings.ReplaceAll(sql, "@table_name", tableName)
|
||||
err = db.Raw(sql, dbName, tableName).Scan(&entities).Error
|
||||
return entities, err
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user