Compare commits

...
129 Commits
Author SHA1 Message Date
wenjianzhang 974d5b2889 Merge pull request #438 from go-admin-team/1.3.x 2021-06-01 07:42:05 +08:00
zhangwenjian fb42953fbe Merge branch '1.3.x' of https://github.com/go-admin-team/go-admin into 1.3.x 2021-06-01 07:35:06 +08:00
zhangwenjian 277129e830 docs📝 update 2021-06-01 07:34:48 +08:00
wenjianzhang cdc5c1246e Merge pull request #437 from ninstein/patch-5
bugfix:必填字段判断错误修复
2021-06-01 00:21:34 +08:00
zhangwenjian c0f920d43c fix🐛 定时任务,触发函数,无法正常关闭(#432) 2021-06-01 00:17:35 +08:00
ninstein b5bfece9f1 bugfix:必填字段判断错误修复 2021-05-31 21:12:04 +08:00
linwenxiang 2cb81654a6 fix 🐛 修复queue redis模式阿里云不工作问题 2021-05-31 14:43:43 +08:00
wenjianzhang da16b4af7a fix🐛 query built from **** sources 2021-05-30 22:17:11 +08:00
wenjianzhang fda4a944fc Merge pull request #434 from go-admin-team/1.3.x
1.3.x
2021-05-30 21:11:42 +08:00
wenjianzhang 9026da4a6d Merge pull request #433 from ninstein/patch-3
fix🐛 修复“关联表下拉”字段搜索未生效bug
2021-05-30 21:02:46 +08:00
ninstein 7d8c5a1ce7 bugfix:修复“关联表下拉”字段搜索未生效bug
并允许清空搜索值
2021-05-30 19:38:22 +08:00
wenjianzhang 75b10f0fb7 Merge branch 'master' into master 2021-05-29 18:20:48 +08:00
wenjianzhang 6f923d7ea7 Merge pull request #430 from go-admin-team/1.3.x
docs📝 update README
2021-05-29 15:28:56 +08:00
wenjianzhang bc2e68c288 Merge pull request #431 from ninstein/patch-2
format🥚 列表页时间字段美化
2021-05-29 15:20:51 +08:00
ninstein a02f01453d 列表页时间字段美化 2021-05-28 22:09:43 +08:00
wenjianzhang c1b0e9ab8b docs📝 update README 2021-05-28 18:36:57 +08:00
wenjianzhang ea4375b408 docs📝 update 2021-05-28 17:33:37 +08:00
wenjianzhang 1c0060fd14 Merge pull request #429 from go-admin-team/1.3.x
fix🐛 修复查询bug
2021-05-28 17:28:12 +08:00
wenjianzhang 4c127c8c4b fix🐛 remove invalid identifier character U+00A0 2021-05-28 17:18:20 +08:00
wenjianzhang 5be2070cbc Merge pull request #428 from ninstein/patch-1
fix🐛 修复查询bug
2021-05-28 16:08:20 +08:00
ninstein 16d98cb386 Update sys_content.go
修复查询bug
2021-05-28 15:58:07 +08:00
wenjianzhang f22c4e5dc8 Merge branch 'go-admin-team:master' into master 2021-05-28 10:17:05 +08:00
wenjianzhang 7d7fc530d1 Merge pull request #427 from go-admin-team/1.3.x
fix🐛 修复参数根据id获取功能
2021-05-23 18:23:13 +08:00
zhangwenjian 18d9b77cca format🥚 格式化代码 2021-05-23 18:13:47 +08:00
zhangwenjian 7491ff4459 fix🐛 修复参数根据id获取功能 2021-05-23 18:12:36 +08:00
zhangwenjian c89b0ca8e1 Merge branch '1.3.x' of https://github.com/go-admin-team/go-admin into 1.3.x 2021-05-22 23:38:27 +08:00
zhangwenjian a3de9cd569 docs📝 修改version 2021-05-22 23:38:00 +08:00
wenjianzhang 5e10b631f6 fix🐛 修复部门数据权限 2021-05-22 23:34:44 +08:00
wenjianzhang d71ff80e12 Merge branch 'master' into 1.3.x 2021-05-22 23:28:02 +08:00
zhangwenjian 1b2bf70df1 docs📝 修改readme 2021-05-22 23:25:31 +08:00
zhangwenjian cbdfa61268 fix🐛 修复部门数据权限 2021-05-22 23:24:30 +08:00
wenjianzhang 8a58fb5b3b Update README.md 2021-05-22 22:58:12 +08:00
wenjianzhang eeaa05f5b4 Merge pull request #420 from go-admin-team/1.3.x
publish🚀 1.3.5
2021-05-13 14:58:16 +08:00
wenjianzhang 4904c9ed20 publish🚀 1.3.5 2021-05-13 10:49:04 +08:00
wenjianzhang 9a6f93854b Merge pull request #419 from go-admin-team/1.3.x
publish🚀  1.3.4
2021-05-13 10:47:51 +08:00
wenjianzhang 99699c0065 feat✨ 1.3.4 2021-05-13 10:46:49 +08:00
wenjianzhang 85685dbda1 Merge pull request #418 from go-admin-team/1.3.x
gen中修改创建人和修改人设置默认值
2021-05-13 10:43:45 +08:00
wenjianzhang 3a4bfe915b feat✨ gen中修改创建人和修改人为0 2021-05-13 09:18:06 +08:00
wenjianzhang 57067907d3 refactor🎨 参数设置删除修改 2021-05-10 17:25:43 +08:00
wenjianzhang d91ddf265d Merge pull request #417 from go-admin-team/1.3.x
1.3.x
2021-05-10 16:45:12 +08:00
wenjianzhang 59e8645f56 fix🐛 update 2021-05-10 16:44:21 +08:00
zhangwenjian ddc3a1d403 refactor🎨 初始化gen创建者信息 2021-05-10 01:18:13 +08:00
zhangwenjian 816b10681b refactor🎨 升级go.mod 2021-05-10 01:17:21 +08:00
wenjianzhang f4e07371c5 Merge pull request #413 from go-admin-team/1.3.x
fix🐛 gen问题修正
2021-05-08 17:17:55 +08:00
wenjianzhang 6a2557064c fix🐛 gen问题修正 2021-05-08 17:16:52 +08:00
wenjianzhang 4a592f515a fix🐛 文件管理\内容管理\分类程序\定时任务的已知问题(#397) 2021-05-08 17:11:59 +08:00
wenjianzhang 9bc2791b26 fix🐛 文件管理\内容管理\分类程序\定时任务的已知问题 2021-05-08 17:02:56 +08:00
wenjianzhang e126fd38bc publish🚀 1.3.3 2021-05-07 20:09:13 +08:00
wenjianzhang c6d94c03fb feat✨ 更新service 2021-05-07 19:57:45 +08:00
wenjianzhang 50a5d6f48d feat✨ 更新service 2021-05-07 19:57:09 +08:00
wenjianzhang 508a18a809 feat✨ 更新readme 2021-05-07 19:11:39 +08:00
wenjianzhang 946a53cb2b feat✨ 模版格式化 2021-05-07 19:02:06 +08:00
wenjianzhang c6ccd844f5 feat✨ 去除生成方法版本信息 2021-05-07 18:54:11 +08:00
wenjianzhang debe808f83 feat✨ 优化dto模版 2021-05-07 18:52:42 +08:00
wenjianzhang e219463505 feat✨ 升级模版 2021-05-07 18:46:12 +08:00
wenjianzhang 009866ee31 feat✨ :更新api写法,同步调整模版 2021-05-07 17:56:15 +08:00
linwenxiang 13ff9d9e63 feat ✨ 优化api写法 2021-04-27 10:06:22 +08:00
wenjianzhang 5957fb280c config🔧 :修改配置文件 2021-04-27 10:06:22 +08:00
wenjianzhang 44d196eaef config🔧 :修改配置文件 2021-04-27 10:06:22 +08:00
linwenxiang bf7934c20a fix 🐛 优化迁移功能 2021-04-26 14:47:31 +08:00
linwenxiang 845558cc65 fix 🐛 修复初始化数据库账号登录不了问题 2021-04-26 10:45:45 +08:00
lwnmengjing 22250dbbba Merge pull request #400 from go-admin-team/dev
migrate ✅ 优化migrate
2021-04-23 15:37:13 +08:00
linwenxiang 7290742ac0 dep ⬇️ 升级依赖 2021-04-23 15:33:59 +08:00
linwenxiang 97d9590d05 doc ✅ 修复swagger文档 2021-04-23 14:59:53 +08:00
linwenxiang 1a111f0666 migrate ✅ 优化migrate 2021-04-23 14:25:31 +08:00
linwenxiang e40047a88e feat ✨ 去除数据库写log对queue驱动的依赖,调整cache,分离出queue和locker 2021-04-20 11:08:46 +08:00
wenjianzhang 3df83cb057 Merge pull request #396 from jfcg/master
Create codeql-analysis.yml
2021-04-13 20:46:10 +08:00
Serhat Şevki Dinçer cfd284e42e rm schedule from codeql 2021-04-13 00:01:00 +03:00
wenjianzhang 3211b47d40 Update README.md 2021-04-12 22:40:43 +08:00
Serhat Şevki Dinçer f21de0706a Create codeql-analysis.yml 2021-04-12 15:44:02 +03:00
wenjianzhang 7abe98b723 Merge branch 'dev' of https://github.com/go-admin-team/go-admin into dev 2021-04-09 12:33:45 +08:00
linwenxiang 413ca6d353 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	scripts/k8s/deploy.yml
2021-04-08 21:41:42 +08:00
linwenxiang b69bc87468 feat ✨ 验证码store支持go-admin cache 2021-04-08 21:33:36 +08:00
wenjianzhang a1a41f0a86 Merge branch 'dev' of https://github.com/go-admin-team/go-admin into dev 2021-04-08 18:43:53 +08:00
wenjianzhang 14db1e802c feat ✨: 添加字段验证 2021-04-08 18:43:17 +08:00
wenjianzhang 221a47423d fix🐛 :修改扩展配置文件名称 2021-04-08 17:17:13 +08:00
wenjianzhang daadb14618 fix🐛 :修改扩展配置文件名称 2021-04-08 17:13:42 +08:00
linwenxiang 40cd55da90 ci 💚 修改k8s yaml配置 2021-04-08 13:53:44 +08:00
linwenxiang eddfe26308 feat ✨ 验证码store支持go-admin cache 2021-04-07 23:01:32 +08:00
linwenxiang e034e5b1ea ci 💚 修改k8s yaml配置 2021-04-06 18:10:53 +08:00
linwenxiang 36bdeb3faa ci 💚 修改k8s yaml配置 2021-04-06 18:09:23 +08:00
linwenxiang 7112323a5e perf 👌: 统一配置参数 2021-03-31 21:56:38 +08:00
linwenxiang ea4ffb8867 Merge branch 'dev' 2021-03-31 21:07:16 +08:00
linwenxiang 225970c005 Merge remote-tracking branch 'origin/dev' into dev
# Conflicts:
#	go.mod
2021-03-31 21:02:59 +08:00
linwenxiang 24370899ab perf 👌: 升级go-admin-core依赖 2021-03-31 21:02:12 +08:00
wenjianzhang 510bdd94f9 docs📝 :修正版本信息 2021-03-31 19:45:07 +08:00
wenjianzhang 2a27c91656 config🔧 :core升级 2021-03-31 19:44:08 +08:00
wenjianzhang 3767274755 config🔧 :修改配置文件 2021-03-31 19:09:47 +08:00
wenjianzhang aefdb47c32 feat ✨: 配置文件扩展项使用 2021-03-31 19:06:25 +08:00
wenjianzhang 30feaae7e7 fix🐛 :修复文件路径判断函数 (#382) 2021-03-31 18:59:58 +08:00
lwnmengjing 8557e1e160 Merge pull request #384 from go-admin-team/dev
admin中的公共中间件,提到common 495a9c5
2021-03-30 22:56:52 +08:00
linwenxiang dd16744676 refactor 🎨: admin中的公共中间件,提到common 2021-03-29 09:05:05 +08:00
linwenxiang 495a9c54aa refactor 🎨: admin中的公共中间件,提到common 2021-03-28 23:27:01 +08:00
wenjianzhang afab1ef7c9 docs📝 :修正readme 2021-03-26 15:08:15 +08:00
wenjianzhang 5e99363e9a docs📝 :修正readme 2021-03-26 15:06:12 +08:00
wenjianzhang 86c7c64a32 fix🐛 :修复角色数据权限更新失(#380) 2021-03-26 14:36:18 +08:00
wenjianzhang 44b9666302 fix🐛 :修复内容模块问题(#357)
fix🐛 :修复内容模块问题(#357)
2021-03-26 13:53:44 +08:00
wenjianzhang 91c9a2c7f9 fix🐛 :修复内容模块问题(#357) 2021-03-26 13:42:12 +08:00
wenjianzhang a65930b35b fix🐛 :修复已知bug (#377) 2021-03-26 09:03:21 +08:00
linwenxiang 9023b620fb Merge branch 'master' into dev 2021-03-25 22:28:24 +08:00
linwenxiang f188b34253 feat ✨: 使用runtime cache中的mq功能优化日志存储
perf 👌: 启用mq将日志存储从中间件中移除到消费者
2021-03-25 22:26:33 +08:00
wenjianzhang 8faf6c9aba docs📝 :更新readme 2021-03-25 19:14:42 +08:00
wenjianzhang 547a5eb8e4 fix🐛 :修复初始化Duplicate column name 'is_frontend' (#376) 2021-03-25 18:35:09 +08:00
linwenxiang 2459c877e0 Merge branch 'dev' 2021-03-25 14:47:12 +08:00
linwenxiang 93625a6d9f format 🥚:模版生成优化 2021-03-25 14:45:39 +08:00
linwenxiang 58b439f553 修复个人中心修改密码不生效问题 2021-03-25 11:34:30 +08:00
linwenxiang 78c67185fd 升级core依赖 2021-03-24 23:00:09 +08:00
lwnmengjing 265cc9350d Merge pull request #374 from go-admin-team/dev
优化生成的swagger
2021-03-24 22:49:33 +08:00
linwenxiang 4182bac3a2 修改模版,优化生成的swagger 2021-03-24 22:20:23 +08:00
linwenxiang 12893fc09d 修复swagger无法生成文档 2021-03-24 18:52:59 +08:00
linwenxiang 6fb7da87a3 优化logger设置获取流程 2021-03-24 16:49:04 +08:00
wenjianzhang 0ecf56cd8c docs📝 :更新 2021-03-17 19:21:28 +08:00
wenjianzhang 0c802ad366 feat✨ :菜单配置迁移脚本功能 2021-03-17 19:15:49 +08:00
wenjianzhang 0be7735855 publish🚀 v1.3.0 2021-03-17 16:42:47 +08:00
wenjianzhang 9c73558382 feat✨ :更新 2021-03-17 16:29:45 +08:00
wenjianzhang 4e370665dd feat✨ :去除系统配置表数据的sql 2021-03-17 16:26:28 +08:00
wenjianzhang 0194561056 Merge branch 'dev' of https://github.com/go-admin-team/go-admin into dev 2021-03-17 14:30:20 +08:00
wenjianzhang 5b69883a9f fix🐛 :系统配置初始化sql 2021-03-17 14:30:16 +08:00
linwenxiang b1789e5785 优化api返回方法 2021-03-17 12:43:52 +08:00
wenjianzhang 5756286641 fix🐛 :去掉迁移脚本中的数据库名称 2021-03-17 11:23:17 +08:00
wenjianzhang 6746dbd9cf feat✨ :参数配置中添加是否前台控制 2021-03-17 11:16:53 +08:00
wenjianzhang 2134d9fa58 fix🐛 :修复日志状态显示问题 2021-03-17 11:16:02 +08:00
wenjianzhang a8c00c5be1 fix🐛 :修复请求日志数据获取为空问题 2021-03-17 11:15:35 +08:00
wenjianzhang 51bc4423f7 feat✨ :系统配置统一使用参数设置功能
注意:系统配置表将设置为过时功能
2021-03-17 10:18:47 +08:00
linwenxiang 55a85babf8 升级go-admin-core依赖 2021-03-16 17:21:17 +08:00
linwenxiang c9f705e4f5 Merge remote-tracking branch 'origin/dev' into dev 2021-03-12 16:03:12 +08:00
linwenxiang 9bf9330410 api层写法统一 2021-03-12 16:02:29 +08:00
wenjianzhang f53ee3008a Update index.go 2021-03-12 12:14:54 +08:00
wenjianzhang 31ec3880da fix🐛 :修改接口默认页面地址 2021-03-12 12:14:15 +08:00
187 changed files with 5917 additions and 5141 deletions
+51
View File
@@ -0,0 +1,51 @@
name: "CodeQL"
on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
+60
View File
@@ -0,0 +1,60 @@
name: build
on:
push:
branches: [ dev-lwx ]
pull_request:
branches: [ dev-lwx ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.15
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: |
CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin .
mv go-admin ./scripts
- uses: Azure/docker-login@v1
with:
login-server: registry.cn-shanghai.aliyuncs.com
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- run: |
docker build ./scripts -t registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}
docker push registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}
- uses: Azure/k8s-set-context@v1
with:
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- uses: Azure/k8s-create-secret@v1
with:
namespace: 'go-admin'
container-registry-url: registry.cn-shanghai.aliyuncs.com
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
secret-name: aliyuncs-k8s-secret
- uses: Azure/k8s-deploy@v1
with:
namespace: 'go-admin'
manifests: 'scripts/k8s/deploy.yml'
images: 'registry.cn-shanghai.aliyuncs.com/go-admin-team/go-admin:${{ github.sha }}'
imagepullsecrets: 'aliyuncs-k8s-secret'
kubectl-version: 'latest'
+1
View File
@@ -21,3 +21,4 @@ cmd/migrate/migration/version-local/*
# go sum
go.sum
config/settings.deva.yml
+1 -1
View File
@@ -23,4 +23,4 @@ COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
EXPOSE 8000
CMD ["/go-admin","server","-c", "/config/settings.yml"]
CMD ["/go-admin","server","-c", "/config/settings.yml"]
+289
View File
@@ -0,0 +1,289 @@
# go-admin
<img align="right" width="320" src="https://gitee.com/mydearzwj/image/raw/master/img/go-admin.svg">
[![Build Status](https://github.com/wenjianzhang/go-admin/workflows/build/badge.svg)](https://github.com/go-admin-team/go-admin)
[![Release](https://img.shields.io/github/release/go-admin-team/go-admin.svg?style=flat-square)](https://github.com/go-admin-team/go-admin/releases)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/go-admin-team/go-admin)
[English](https://github.com/go-admin-team/go-admin/blob/master/README.md) | 简体中文
基于Gin + Vue + Element UI的前后端分离权限管理系统,系统初始化极度简单,只需要配置文件中,修改数据库连接,系统支持多指令操作,迁移指令可以让初始化数据库信息变得更简单,服务指令可以很简单的启动api服务
[在线文档](https://doc.go-admin.dev)
[github在线文档](https://wenjianzhang.github.io)
[gitee在线文档](http://mydearzwj.gitee.io/go-admin-doc/)
[前端项目](https://github.com/go-admin-team/go-admin-ui)
[视频教程](https://space.bilibili.com/565616721/channel/detail?cid=125737)
## ✨ 特性
- 遵循 RESTful API 设计规范
- 基于 GIN WEB API 框架,提供了丰富的中间件支持(用户认证、跨域、访问日志、追踪ID等)
- 基于Casbin的 RBAC 访问控制模型
- JWT 认证
- 支持 Swagger 文档(基于swaggo)
- 基于 GORM 的数据库存储,可扩展多种类型数据库
- 配置文件简单的模型映射,快速能够得到想要的配置
- 代码生成工具
- 表单构建工具
- 多指令模式
- TODO: 单元测试
## 🎁 内置
1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。
2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。
3. 岗位管理:配置系统用户所属担任职务。
4. 菜单管理:配置系统菜单,操作权限,按钮权限标识,接口权限等。
5. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。
6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。
7. 参数管理:对系统动态配置常用参数。
8. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。
9. 登录日志:系统登录日志记录查询包含登录异常。
1. 接口文档:根据业务代码自动生成相关的api接口文档。
1. 代码生成:根据数据表结构生成对应的增删改查相对应业务,全程可视化操作,让基本业务可以零代码实现。
1. 表单构建:自定义页面样式,拖拉拽实现页面布局。
1. 服务监控:查看一些服务器的基本信息。
1. 内容管理:demo功能,下设分类管理、内容管理。可以参考使用方便快速入门。
## 准备工作
你需要在本地安装 [go] [gin] [node](http://nodejs.org/) 和 [git](https://git-scm.com/)
同时配套了系列教程包含视频和文档,如何从下载完成到熟练使用,强烈建议大家先看完这些教程再来实践本项目!!!
### 轻松实现go-admin写出第一个应用 - 文档教程
[步骤一 - 基础内容介绍](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html)
[步骤二 - 实际应用 - 编写增删改查](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html)
### 手把手教你从入门到放弃 - 视频教程
[如何启动go-admin](https://www.bilibili.com/video/BV1z5411x7JG)
[使用生成工具轻松实现业务](https://www.bilibili.com/video/BV1Dg4y1i79D)
[v1.1.0版本代码生成工具-释放双手](https://www.bilibili.com/video/BV1N54y1i71P) [进阶]
[多命令启动方式讲解以及IDE配置](https://www.bilibili.com/video/BV1Fg4y1q7ph)
[go-admin菜单的配置说明](https://www.bilibili.com/video/BV1Wp4y1D715) [必看]
[如何配置菜单信息以及接口信息](https://www.bilibili.com/video/BV1zv411B7nG) [必看]
[go-admin权限配置使用说明](https://www.bilibili.com/video/BV1rt4y197d3) [必看]
[go-admin数据权限使用说明](https://www.bilibili.com/video/BV1LK4y1s71e) [必看]
**如有问题请先看上述使用文档和文章,若不能满足,欢迎 issue 和 pr ,视频教程和文档持续更新中**
## 📦 本地开发
### 开发目录创建
```bash
# 创建开发目录
mkdir goadmin
cd goadmin
```
### 获取代码
> 重点注意:两个项目必须放在同一文件夹下;
```bash
# 获取后端代码
git clone https://github.com/go-admin-team/go-admin.git
# 获取前端代码
git clone https://github.com/go-admin-team/go-admin-ui.git
```
### 启动说明
#### 服务端启动说明
```bash
# 进入 go-admin 后端项目
cd ./go-admin
# 编译项目
go build
# 修改配置
# 文件路径 go-admin/config/settings.yml
vi ./config/setting.yml
# 1. 配置文件中修改数据库信息
# 注意: settings.database 下对应的配置数据
# 2. 确认log路径
```
:::tip ⚠️注意 在windows环境如果没有安装中CGO,会出现这个问题;
```bash
E:\go-admin>go build
# github.com/mattn/go-sqlite3
cgo: exec /missing-cc: exec: "/missing-cc": file does not exist
```
or
```bash
D:\Code\go-admin>go build
# github.com/mattn/go-sqlite3
cgo: exec gcc: exec: "gcc": executable file not found in %PATH%
```
[解决cgo问题进入](https://doc.go-admin.dev/guide/other/faq.html#_5-cgo-exec-missing-cc-exec-missing-cc-file-does-not-exist)
:::
#### 初始化数据库,以及服务启动
``` bash
# 首次配置需要初始化数据库资源信息
# macOS or linux 下使用
$ ./go-admin migrate -c=config/settings.dev.yml
# ⚠️注意:windows 下使用
$ go-admin.exe migrate -c=config/settings.dev.yml
# 启动项目,也可以用IDE进行调试
# macOS or linux 下使用
$ ./go-admin server -c config/settings.yml
# ⚠️注意:windows 下使用
$ go-admin.exe server -c config/settings.yml
```
#### 使用docker 编译启动
```shell
# 编译镜像
docker build -t go-admin .
# 启动容器,第一个go-admin是容器名字,第二个go-admin是镜像名称
# -v 映射配置文件 本地路径:容器路径
docker run --name go-admin -p 8000:8000 -v /config/settings.yml:/config/settings.yml -d go-admin-server
```
#### 文档生成
```bash
go generate
```
#### 交叉编译
```bash
# windows
env GOOS=windows GOARCH=amd64 go build main.go
# or
# linux
env GOOS=linux GOARCH=amd64 go build main.go
```
### UI交互端启动说明
```bash
# 安装依赖
npm install
# 建议不要直接使用 cnpm 安装依赖,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题
npm install --registry=https://registry.npm.taobao.org
# 启动服务
npm run dev
```
## 🎬 在线体验
> admin / 123456
演示地址:[http://www.go-admin.dev](http://www.go-admin.dev/#/login)
## 📨 互动
<table>
<tr>
<td><img src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/wx.png" width="180px"></td>
<td><img src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/qq.png" width="200px"></td>
<td><img src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/qq2.png" width="200px"></td>
</tr>
<tr>
<td>微信</td>
<td>此群已满</td>
<td><a target="_blank" href="https://shang.qq.com/wpa/qunwpa?idkey=0f2bf59f5f2edec6a4550c364242c0641f870aa328e468c4ee4b7dbfb392627b"><img border="0" src="https://pub.idqqimg.com/wpa/images/group.png" alt="go-admin技术交流乙号" title="go-admin技术交流乙号"></a></td>
</tr>
</table>
## 💎 主要成员
<a href="https://github.com/wenjianzhang"> <img src="https://avatars.githubusercontent.com/u/3890175?s=460&u=20eac63daef81588fbac611da676b99859319251&v=4" width="80px"></a>
<a href="https://github.com/lwnmengjing"> <img src="https://avatars.githubusercontent.com/u/12806223?s=400&u=a89272dce50100b77b4c0d5c81c718bf78ebb580&v=4" width="80px"></a>
<a href="https://github.com/chengxiao"> <img src="https://avatars.githubusercontent.com/u/1379545?s=460&u=557da5503d0ac4a8628df6b4075b17853d5edcd9&v=4" width="80px"></a>
<a href="https://github.com/bing127"> <img src="https://avatars.githubusercontent.com/u/31166183?s=460&u=c085bff88df10bb7676c8c0351ba9dcd031d1fb3&v=4" width="80px"></a>
## JetBrains 开源证书支持
`go-admin` 项目一直以来都是在 JetBrains 公司旗下的 GoLand 集成开发环境中进行开发,基于 **free JetBrains Open Source license(s)** 正版免费授权,在此表达我的谢意。
<a href="https://www.jetbrains.com/?from=kubeadm-ha" target="_blank"><img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/jetbrains/jetbrains-variant-4.png" width="250" align="middle"/></a>
## 🤝 特别感谢
1. [chengxiao](https://github.com/chengxiao)
2. [gin](https://github.com/gin-gonic/gin)
2. [casbin](https://github.com/casbin/casbin)
2. [spf13/viper](https://github.com/spf13/viper)
2. [gorm](https://github.com/jinzhu/gorm)
2. [gin-swagger](https://github.com/swaggo/gin-swagger)
2. [jwt-go](https://github.com/dgrijalva/jwt-go)
2. [vue-element-admin](https://github.com/PanJiaChen/vue-element-admin)
2. [ruoyi-vue](https://gitee.com/y_project/RuoYi-Vue)
2. [form-generator](https://github.com/JakHuang/form-generator)
## 🤟 打赏
> 如果你觉得这个项目帮助到了你,你可以帮作者买一杯果汁表示鼓励 :tropical_drink:
<img class="no-margin" src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/pay.png" height="200px" >
## 🤝 链接
[Go开发者成长线路图](http://www.golangroadmap.com/)
## 🔑 License
[MIT](https://github.com/go-admin-team/go-admin/blob/master/LICENSE.md)
Copyright (c) 2020 wenjianzhang
-194
View File
@@ -1,194 +0,0 @@
# go-admin
![build](https://github.com/wenjianzhang/go-admin/workflows/build/badge.svg) ![license](https://img.shields.io/github/license/mashape/apistatus.svg)
English | [简体中文](./README.zh-CN.md)
##### Gin + Vue + Element UI based scaffolding for front and back separation management system
## ✨ Feature
- Follow RESTful API design specifications
- Provides rich middleware support based on GIN WEB API framework (user authentication, cross domain, access log, tracking ID, etc.)
- Casbin-based RBAC access control model
- JWT certification
- Support Swagger documentation (based on swaggo)
- GORM-based database storage that can expand many types of databases
- Simple model mapping of configuration files to quickly get the desired configuration
- TODO: unit test
## 🎁 Built-in functions
1. User management: The user is the system operator. This function mainly completes the system user configuration.
2. Department management: configure the system organization (company, department, group), and display the tree structure to support data permissions.
3. Post management: Configure system users to hold positions.
4. Menu management: configure system menus, operation permissions, button permission labels, etc.
5. Role management: role menu permissions assignment, setting roles to divide data range permissions by organization.
6. Dictionary management: to maintain some fixed data often used in the system.
7. Parameter management: Dynamically configure common parameters for the system.
8. Operation log: system normal operation log record and query; system exception information log record and query.
9. Login log: The system login log record query contains login exceptions.
10. System interface: Automatically generate related api interface documents according to business code.
## Configuration details
1. Configuration file description
```yml
settings:
application:
# Project launch environment
env: dev
# When env: demo, prompts for request operations other than GET
envmsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!"
# Host IP or domain name, default 0.0.0.0
host: 0.0.0.0
# Whether to initialize the database structure and basic data; true: required; false: not required
isinit: false
# JWT encrypted string
jwtsecret: 123abc
# log storage path
logpath: temp/logs/log.log
# application name
name: go-admin
# application port
port: 8000
readtimeout: 1
writertimeout: 2
database:
# database name
database: dbname
# database type
dbtype: mysql
# database host
host: 127.0.0.1
# database password
password: password
# database port
port: 3306
# database username
username: root
redis:
# redis addresss
addr: 0.0.0.0:6379
# db
db: 0
# password
password: password
# read timeout
readtimeout: 50
```
2. file path go-admin/config/settings.yml
## 📦 evelopment
First start instructions
```bash
# Get the code
git clone https://github.com/wenjianzhang/go-admin.git
# Enter working path
cd ./go-admin
# Build the project
go build
# Change setting
vi ./config/setting.yml (Note: Change isinit and database connection)
# 1. Database information in the configuration file
# Note: the corresponding configuration data under settings.database
# 2. Confirm database initialization parameters
# Note: If this is the first time settings.application.isinit is set, please set the current value to true, the system will automatically initialize the database structure and basic data information;
# 3. Confirm the log path
# Start the project or debug with the IDE
./go-admin
# See also instructions in WIKI
```
Document generation
```bash
swag init
```
If there is no `swag` command go get installed
```bash
go get -u github.com/swaggo/swag/cmd/swag
```
Cross compilation
```bash
env GOOS=windows GOARCH=amd64 go build main.go
# or
env GOOS=linux GOARCH=amd64 go build main.go
```
## 🔗 Online Demo
> admin / 123456
Demo address:[http://www.zhangwj.com](http://www.zhangwj.com/#/login)
## 🤝 Open source projects used
[gin](https://github.com/gin-gonic/gin)
[casbin](https://github.com/casbin/casbin)
[spf13/viper](https://github.com/spf13/viper)
[gorm](https://github.com/jinzhu/gorm)
[gin-swagger](https://github.com/swaggo/gin-swagger)
[jwt-go](https://github.com/dgrijalva/jwt-go)
[vue-element-admin](https://github.com/PanJiaChen/vue-element-admin)
[ruoyi-vue](https://gitee.com/y_project/RuoYi-Vue)
## Version
#### 2020-03-15 New Features and Optimization
1. Add user avatar upload
2. Add user password modification
3. Operation log page adjustment
4. Optimize captcha background color
I saw a lot of friends who experience the wrong verification code, so I adjusted the contrast for everyone to experience!
## 🤝 Thanks
[chengxiao](https://github.com/chengxiao)
## License
[MIT](https://github.com/wenjianzhang/go-admin/blob/master/LICENSE.md)
Copyright (c) 2020 wenjianzhang
[中文]qq technical exchange group: 74520518
+150 -154
View File
@@ -1,237 +1,239 @@
<p align="center">
<img width="320" src="https://gitee.com/mydearzwj/image/raw/master/img/go-admin.svg">
</p>
# go-admin
<img align="right" width="320" src="https://gitee.com/mydearzwj/image/raw/master/img/go-admin.svg">
<p align="center">
<a href="https://github.com/wenjianzhang/go-admin">
<img src="https://github.com/wenjianzhang/go-admin/workflows/build/badge.svg" alt="go-admin">
</a>
<a href="https://github.com/wenjianzhang/go-admin">
<img src="https://img.shields.io/github/license/mashape/apistatus.svg" alt="license">
</a>
<a href="http://doc.zhangwj.com/go-admin-site/donate/">
<img src="https://img.shields.io/badge/%24-donate-ff69b4.svg" alt="donate">
</a>
</p>
[![Build Status](https://github.com/wenjianzhang/go-admin/workflows/build/badge.svg)](https://github.com/go-admin-team/go-admin)
[![Release](https://img.shields.io/github/release/go-admin-team/go-admin.svg?style=flat-square)](https://github.com/go-admin-team/go-admin/releases)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/go-admin-team/go-admin)
English | [简体中文](https://github.com/go-admin-team/go-admin/blob/master/README.Zh-cn.md)
The front-end and back-end separation authority management system based on Gin + Vue + Element UI is extremely simple to initialize the system. You only need to modify the database connection in the configuration file. The system supports multi-instruction operations. Migration instructions can make it easier to initialize database information. Service instructions It's easy to start the api service.
[documentation](https://doc.go-admin.dev)
[Front-end project](https://github.com/go-admin-team/go-admin-ui)
[Video tutorial](https://space.bilibili.com/565616721/channel/detail?cid=125737)
## ✨ Feature
- Follow RESTful API design specifications
- Based on the GIN WEB API framework, it provides rich middleware support (user authentication, cross-domain, access log, tracking ID, etc.)
- RBAC access control model based on Casbin
- JWT authentication
- Support Swagger documents (based on swaggo)
- Database storage based on GORM, which can expand multiple types of databases
- Simple model mapping of configuration files to quickly get the desired configuration
- Code generation tool
- Form builder
- Multi-command mode
- TODO: unit test
[English](https://github.com/go-admin-team/go-admin/blob/master/README.en.md) | 简体中文
## 🎁 Internal
1. User management: The user is the system operator, this function mainly completes the system user configuration.
2. Department management: configure the system organization (company, department, group), and display the tree structure to support data permissions.
3. Position management: configure the positions of system users.
4. Menu management: configure the system menu, operation authority, button authority identification, interface authority, etc.
5. Role management: Role menu permission assignment and role setting are divided into data scope permissions by organization.
6. Dictionary management: Maintain some relatively fixed data frequently used in the system.
7. Parameter management: dynamically configure common parameters for the system.
8. Operation log: system normal operation log record and query; system abnormal information log record and query.
9. Login log: The system login log record query contains login exceptions.
1. Interface documentation: Automatically generate related api interface documents according to the business code.
1. Code generation: According to the data table structure, generate the corresponding addition, deletion, modification, and check corresponding business, and the whole process of visual operation, so that the basic business can be implemented with zero code.
1. Form construction: Customize the page style, drag and drop to realize the page layout.
1. Service monitoring: View the basic information of some servers.
1. Content management: demo function, including classification management and content management. You can refer to the easy to use quick start.
##### 基于Gin + Vue + Element UI的前后端分离权限管理系统
## Ready to work
系统初始化极度简单,只需要配置文件中,修改数据库连接,系统启动后会自动初始化数据库信息以及必须的基础数据
You need to install locally [go] [gin] [node](http://nodejs.org/) 和 [git](https://git-scm.com/)
[在线文档国际](https://wenjianzhang.github.io/go-admin-site)
At the same time, a series of tutorials including videos and documents are provided. How to complete the downloading to the proficient use, it is strongly recommended that you read these tutorials before you practice this project! ! !
[在线文档国内](http://mydearzwj.gitee.io/go-admin-site/)
### Easily implement go-admin to write the first application-documentation tutorial
[前端项目](https://github.com/go-admin-team/go-admin-ui)
[Step 1 - basic content introduction](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html)
[视频教程](https://space.bilibili.com/565616721/channel/detail?cid=125737)
[Step 2 - Practical application - writing database operations](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html)
## ✨ 特性
### Teach you from getting started to giving up-video tutorial
- 遵循 RESTful API 设计规范
[How to start go-admin](https://www.bilibili.com/video/BV1z5411x7JG)
- 基于 GIN WEB API 框架,提供了丰富的中间件支持(用户认证、跨域、访问日志、追踪ID等)
[Easily implement business using build tools](https://www.bilibili.com/video/BV1Dg4y1i79D)
- 基于Casbin的 RBAC 访问控制模型
[v1.1.0 version code generation tool-free your hands](https://www.bilibili.com/video/BV1N54y1i71P) [Advanced]
- JWT 认证
[Explanation of multi-command startup mode and IDE configuration](https://www.bilibili.com/video/BV1Fg4y1q7ph)
- 支持 Swagger 文档(基于swaggo)
[Configuration instructions for go-admin menu](https://www.bilibili.com/video/BV1Wp4y1D715) [Must see]
- 基于 GORM 的数据库存储,可扩展多种类型数据库
[How to configure menu information and interface information](https://www.bilibili.com/video/BV1zv411B7nG) [Must see]
- 配置文件简单的模型映射,快速能够得到想要的配置
[go-admin permission configuration instructions](https://www.bilibili.com/video/BV1rt4y197d3) [Must see]
- 代码生成工具
[Instructions for use of go-admin data permissions](https://www.bilibili.com/video/BV1LK4y1s71e) [Must see]
- 表单构建工具
**If you have any questions, please read the above-mentioned usage documents and articles first. If you are not satisfied, welcome to issue and pr. Video tutorials and documents are being updated continuously.**
- 多命令模式
## 📦 Local development
- TODO: 单元测试
## 🎁 内置
1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。
2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。
3. 岗位管理:配置系统用户所属担任职务。
4. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。
5. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。
6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。
7. 参数管理:对系统动态配置常用参数。
8. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。
9. 登录日志:系统登录日志记录查询包含登录异常。
10. 系统接口:根据业务代码自动生成相关的api接口文档。
11. 代码生成:根据数据表结构生成对应的增删改查相对应业务,全部可视化编程,基本业务可以0代码实现。
12. 表单构建:自定义页面样式,拖拉拽实现页面布局。
13. 服务监控:查看一些服务器的基本信息。
## 准备工作
你需要在本地安装 [go] [gin] [node](http://nodejs.org/) 和 [git](https://git-scm.com/)
同时配套了系列教程包含视频和文档,如何从下载完成到熟练使用,强烈建议大家先看完这些教程再来实践本项目!!!
### 轻松实现go-admin写出第一个应用 - 文档教程
[步骤一 - 基础内容介绍](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html)
[步骤二 - 实际应用 - 编写增删改查](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html)
### 手把手教你从入门到放弃 - 视频教程
[如何启动go-admin](https://www.bilibili.com/video/BV1z5411x7JG)
[使用生成工具轻松实现业务](https://www.bilibili.com/video/BV1Dg4y1i79D)
[v1.1.0版本代码生成工具-释放双手](https://www.bilibili.com/video/BV1N54y1i71P) [进阶]
[多命令启动方式讲解以及IDE配置](https://www.bilibili.com/video/BV1Fg4y1q7ph)
[go-admin菜单的配置说明](https://www.bilibili.com/video/BV1Wp4y1D715) [必看]
[如何配置菜单信息以及接口信息](https://www.bilibili.com/video/BV1zv411B7nG) [必看]
[go-admin权限配置使用说明](https://www.bilibili.com/video/BV1rt4y197d3) [必看]
[go-admin数据权限使用说明](https://www.bilibili.com/video/BV1LK4y1s71e) [必看]
**如有问题请先看上述使用文档和文章,若不能满足,欢迎 issue 和 pr ,视频教程和文档持续更新中**
## 🗞 系统架构
<p align="center">
<img src="https://gitee.com/mydearzwj/image/raw/d9f59ea603e3c8a3977491a1bfa8f122e1a80824/img/go-admin-system.png" width="936px" height="491px">
</p>
## 📦 本地开发
### 开发目录创建
### Development directory creation
```bash
# 创建开发目录
# Create a development directory
mkdir goadmin
cd goadmin
```
### 获取代码
### Get the code
> 重点注意:两个项目必须放在同一文件夹下;
> Important note: the two projects must be placed in the same folder;
```bash
# 获取后端代码
# Get backend code
git clone https://github.com/go-admin-team/go-admin.git
# 获取前端代码
# Get the front-end code
git clone https://github.com/go-admin-team/go-admin-ui.git
```
### Startup instructions
### 启动说明
#### 服务端启动说明
#### Server startup instructions
```bash
# 进入 go-admin 后端项目
# Enter the go-admin backend project
cd ./go-admin
# 编译项目
# Compile the project
go build
# 修改配置
# 文件路径 go-admin/config/settings.yml
# Change setting
# File path go-admin/config/settings.yml
vi ./config/setting.yml
# 1. 配置文件中修改数据库信息
# 注意: settings.database 下对应的配置数据
# 2. 确认log路径
# 1. Modify the database information in the configuration file
# Note: The corresponding configuration data under settings.database
# 2. Confirm the log path
```
#### 初始化数据库,以及服务启动
```
# 首次配置需要初始化数据库资源信息
./go-admin migrate -c config/settings.yml
# 启动项目,也可以用IDE进行调试
./go-admin server -c config/settings.yml -p 8000
:::tip ⚠️Note that this problem will occur if CGO is not installed in the windows environment;
```bash
E:\go-admin>go build
# github.com/mattn/go-sqlite3
cgo: exec /missing-cc: exec: "/missing-cc": file does not exist
```
#### 使用docker 编译启动
or
```bash
D:\Code\go-admin>go build
# github.com/mattn/go-sqlite3
cgo: exec gcc: exec: "gcc": executable file not found in %PATH%
```
[Solve the cgo problem and enter](https://doc.go-admin.dev/guide/other/faq.html#_5-cgo-exec-missing-cc-exec-missing-cc-file-does-not-exist)
:::
#### Initialize the database, and start the service
``` bash
# The first configuration needs to initialize the database resource information
# Use under macOS or linux
$ ./go-admin migrate -c=config/settings.dev.yml
# ⚠️Note: Use under windows
$ go-admin.exe migrate -c=config/settings.dev.yml
# Start the project, you can also use the IDE for debugging
# Use under macOS or linux
$ ./go-admin server -c config/settings.yml
# ⚠️Note: Use under windows
$ go-admin.exe server -c config/settings.yml
```
#### Use docker to compile and start
```shell
# 编译镜像
# Compile the image
docker build -t go-admin .
# 启动容器,第一个go-admin是容器名字,第二个go-admin是镜像名称
docker run --name go-admin -p 8000:8000 -d go-admin
# Start the container, the first go-admin is the container name, and the second go-admin is the image name
# -v Mapping configuration file Local path: container path
docker run --name go-admin -p 8000:8000 -v /config/settings.yml:/config/settings.yml -d go-admin-server
```
#### 文档生成
#### Generation Document
```bash
swag init
# 如果没有swag命令 go get安装一下即可
go get -u github.com/swaggo/swag/cmd/swag
go generate
```
#### 交叉编译
#### Cross compile
```bash
# windows
env GOOS=windows GOARCH=amd64 go build main.go
# or
# linux
env GOOS=linux GOARCH=amd64 go build main.go
```
### UI交互端启动说明
### UI interactive terminal startup instructions
```bash
# 安装依赖
npm install
# Installation dependencies
npm install # or cnpm install
# 建议不要直接使用 cnpm 安装依赖,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题
npm install --registry=https://registry.npm.taobao.org
# 启动服务
# Start service
npm run dev
```
## 🎬 在线体验
## 🎬 Online Demo
> admin / 123456
演示地址:[http://www.go-admin.dev](http://www.go-admin.dev/#/login)
## 📨 互动
## 📨 Interactive
<table>
<tr>
<td><img src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/wx.png" width="180px"></td>
<td><img src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/qq.png" width="200px"></td>
<td><img src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/qq2.png" width="200px"></td>
</tr>
<tr>
<td>微信</td>
<td>此群已满</td>
<td>Wechat</td>
<td><a target="_blank" href="https://shang.qq.com/wpa/qunwpa?idkey=0f2bf59f5f2edec6a4550c364242c0641f870aa328e468c4ee4b7dbfb392627b"><img border="0" src="https://pub.idqqimg.com/wpa/images/group.png" alt="go-admin技术交流乙号" title="go-admin技术交流乙号"></a></td>
</tr>
</table>
## 💎 主要成员
## 💎 Members
<a href="https://github.com/wenjianzhang"> <img src="https://avatars.githubusercontent.com/u/3890175?s=460&u=20eac63daef81588fbac611da676b99859319251&v=4" width="80px"></a>
<a href="https://github.com/lwnmengjing"> <img src="https://avatars.githubusercontent.com/u/12806223?s=400&u=a89272dce50100b77b4c0d5c81c718bf78ebb580&v=4" width="80px"></a>
@@ -240,14 +242,14 @@ npm run dev
## JetBrains 开源证书支持
## JetBrains open source certificate support
`go-admin` 项目一直以来都是在 JetBrains 公司旗下的 GoLand 集成开发环境中进行开发,基于 **free JetBrains Open Source license(s)** 正版免费授权,在此表达我的谢意。
The `go-admin` project has always been developed in the GoLand integrated development environment under JetBrains, based on the **free JetBrains Open Source license(s)** genuine free license. I would like to express my gratitude.
<a href="https://www.jetbrains.com/?from=kubeadm-ha" target="_blank"><img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/jetbrains/jetbrains-variant-4.png" width="250" align="middle"/></a>
## 🤝 特别感谢
## 🤝 Thanks
1. [chengxiao](https://github.com/chengxiao)
2. [gin](https://github.com/gin-gonic/gin)
2. [casbin](https://github.com/casbin/casbin)
@@ -257,22 +259,16 @@ npm run dev
2. [jwt-go](https://github.com/dgrijalva/jwt-go)
2. [vue-element-admin](https://github.com/PanJiaChen/vue-element-admin)
2. [ruoyi-vue](https://gitee.com/y_project/RuoYi-Vue)
2. [form-generator](https://github.com/JakHuang/form-generator)
## 🤟 打赏
> 如果你觉得这个项目帮助到了你,你可以帮作者买一杯果汁表示鼓励 :tropical_drink:
## 🤟 Sponsor Us
> If you think this project helped you, you can buy a glass of juice for the author to show encouragement :tropical_drink:
<img class="no-margin" src="https://raw.githubusercontent.com/wenjianzhang/image/master/img/pay.png" height="200px" >
## ❤️ 赞助者
> 有部分是微信名称
zhuqiyun LLL狐 星星之火 cjj770 Sam 唐*i 晓聪 aLong *渊 海马 魏镇坪 + 111 *哥 我的宇哥哥 *声 *节
## 🤝 链接
[Go开发者成长线路图](http://www.golangroadmap.com/)
## 🤝 Link
[Go developer growth roadmap](http://www.golangroadmap.com/)
## 🔑 License
+11 -4
View File
@@ -5,10 +5,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
"go-admin/common/apis"
)
const (
@@ -18,12 +20,17 @@ const (
GB = 1024 * MB
)
type Monitor struct {
apis.Api
}
// @Summary 系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/settings/serverInfo [get]
func ServerInfo(c *gin.Context) {
func (e Monitor) ServerInfo(c *gin.Context) {
e.Context = c
osDic := make(map[string]interface{}, 0)
osDic["goOs"] = runtime.GOOS
@@ -59,7 +66,7 @@ func ServerInfo(c *gin.Context) {
cpuDic["Percent"] = pkg.Round(percent[0], 2)
cpuDic["cpuNum"], _ = cpu.Counts(false)
app.Custum(c, gin.H{
e.Custom(gin.H{
"code": 200,
"os": osDic,
"mem": memDic,
+45 -22
View File
@@ -9,10 +9,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/go-admin-team/go-admin-core/sdk/pkg/utils"
"github.com/google/uuid"
"go-admin/common/apis"
"go-admin/common/file_store"
)
@@ -24,6 +24,12 @@ type FileResponse struct {
Type string `json:"type"`
}
const path = "static/uploadfile/"
type File struct {
apis.Api
}
// @Summary 上传图片
// @Description 获取JSON
// @Tags 公共接口
@@ -33,41 +39,48 @@ type FileResponse struct {
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/public/uploadFile [post]
func UploadFile(c *gin.Context) {
func (e File) UploadFile(c *gin.Context) {
e.Context = c
tag, _ := c.GetPostForm("type")
urlPerfix := fmt.Sprintf("http://%s/", c.Request.Host)
var fileResponse FileResponse
if tag == "" {
app.Error(c, 200, errors.New(""), "缺少标识")
e.Error(500, nil, "缺少标识")
//app.Error(c, 200, errors.New(""), "缺少标识")
return
} else {
switch tag {
case "1": // 单图
var done bool
fileResponse, done = singleFile(c, fileResponse, urlPerfix)
fileResponse, done = e.singleFile(c, fileResponse, urlPerfix)
if done {
return
}
app.OK(c, fileResponse, "上传成功")
e.OK(fileResponse, "上传成功")
return
case "2": // 多图
multipartFile := multipleFile(c, urlPerfix)
app.OK(c, multipartFile, "上传成功")
multipartFile := e.multipleFile(c, urlPerfix)
e.OK(multipartFile, "上传成功")
return
case "3": // base64
fileResponse = baseImg(c, fileResponse, urlPerfix)
app.OK(c, fileResponse, "上传成功")
fileResponse = e.baseImg(c, fileResponse, urlPerfix)
e.OK(fileResponse, "上传成功")
}
}
}
func baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse {
func (e File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse {
files, _ := c.GetPostForm("file")
file2list := strings.Split(files, ",")
ddd, _ := base64.StdEncoding.DecodeString(file2list[1])
guid := uuid.New().String()
fileName := guid + ".jpg"
base64File := "static/uploadfile/" + fileName
err := utils.IsNotExistMkDir(path)
if err != nil {
e.Error(500, errors.New(""), "初始化文件路径失败")
}
base64File := path + fileName
_ = ioutil.WriteFile(base64File, ddd, 0666)
typeStr := strings.Replace(strings.Replace(file2list[0], "data:", "", -1), ";base64", "", -1)
fileResponse = FileResponse{
@@ -78,9 +91,9 @@ func baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileRe
Type: typeStr,
}
source, _ := c.GetPostForm("source")
err := thirdUpload(source, fileName, base64File)
err = thirdUpload(source, fileName, base64File)
if err != nil {
app.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(200, errors.New(""), "上传第三方失败")
return fileResponse
}
if source != "1" {
@@ -90,20 +103,25 @@ func baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileRe
return fileResponse
}
func multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
func (e File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
files := c.Request.MultipartForm.File["file"]
source, _ := c.GetPostForm("source")
var multipartFile []FileResponse
for _, f := range files {
guid := uuid.New().String()
fileName := guid + utils.GetExt(f.Filename)
multipartFileName := "static/uploadfile/" + fileName
e := c.SaveUploadedFile(f, multipartFileName)
err := utils.IsNotExistMkDir(path)
if err != nil {
e.Error(500, errors.New(""), "初始化文件路径失败")
}
multipartFileName := path + fileName
err1 := c.SaveUploadedFile(f, multipartFileName)
fileType, _ := utils.GetType(multipartFileName)
if e == nil {
if err1 == nil {
err := thirdUpload(source, fileName, multipartFileName)
if err != nil {
app.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(500, errors.New(""), "上传第三方失败")
} else {
fileResponse := FileResponse{
Size: pkg.GetFileSize(multipartFileName),
@@ -123,18 +141,23 @@ func multipleFile(c *gin.Context, urlPerfix string) []FileResponse {
return multipartFile
}
func singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) {
func (e File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) {
files, err := c.FormFile("file")
if err != nil {
app.Error(c, 200, errors.New(""), "图片不能为空")
e.Error(200, errors.New(""), "图片不能为空")
return FileResponse{}, true
}
// 上传文件至指定目录
guid := uuid.New().String()
fileName := guid + utils.GetExt(files.Filename)
singleFile := "static/uploadfile/" + fileName
err = utils.IsNotExistMkDir(path)
if err != nil {
e.Error(500, errors.New(""), "初始化文件路径失败")
}
singleFile := path + fileName
_ = c.SaveUploadedFile(files, singleFile)
fileType, _ := utils.GetType(singleFile)
fileResponse = FileResponse{
@@ -147,7 +170,7 @@ func singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (Fi
source, _ := c.GetPostForm("source")
err = thirdUpload(source, fileName, singleFile)
if err != nil {
app.Error(c, 200, errors.New(""), "上传第三方失败")
e.Error(200, errors.New(""), "上传第三方失败")
return FileResponse{}, true
}
fileResponse.Path = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
@@ -17,10 +17,11 @@ type SysChinaAreaData struct {
apis.Api
}
func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
d := new(dto.SysChinaAreaDataSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -29,7 +30,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -43,17 +44,18 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
serviceStudent.Orm = db
err = serviceStudent.GetSysChinaAreaDataPage(d, p, &list, &count)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -62,7 +64,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object models.SysChinaAreaData
@@ -75,17 +77,18 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
serviceSysChinaAreaData.Orm = db
err = serviceSysChinaAreaData.GetSysChinaAreaData(control, p, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -94,12 +97,12 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -111,17 +114,18 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
err = serviceSysChinaAreaData.InsertSysChinaAreaData(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -130,12 +134,12 @@ func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -151,13 +155,14 @@ func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
log := e.GetLogger(c)
func (e SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
e.SetContext(c)
log := e.GetLogger()
control := new(dto.SysChinaAreaDataById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -167,7 +172,7 @@ func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -183,8 +188,8 @@ func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
err = serviceSysChinaAreaData.RemoveSysChinaAreaData(control, p)
if err != nil {
log.Errorf("RemoveSysChinaAreaData error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "删除失败")
e.Error(http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, control.GetId(), "删除成功")
}
e.OK(control.GetId(), "删除成功")
}
-84
View File
@@ -1,84 +0,0 @@
package sys_content
//import (
// "github.com/gin-gonic/gin"
// "github.com/gin-gonic/gin/binding"
//
// "go-admin/app/admin/models"
// "go-admin/tools"
// "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
// "github.com/go-admin-team/go-admin-core/sdk/pkg/response/msg"
//)
//
//func GetSysContentList(c *gin.Context) {
// var data models.SysContent
// var err error
// var pageSize = 10
// var pageIndex = 1
//
// if size := c.Request.FormValue("pageSize"); size != "" {
// pageSize, err = tools.StringToInt(size)
// }
// if index := c.Request.FormValue("pageIndex"); index != "" {
// pageIndex, err = tools.StringToInt(index)
// }
//
// data.CateId = c.Request.FormValue("cateId")
// data.Name = c.Request.FormValue("name")
// data.Status = c.Request.FormValue("status")
//
// data.DataScope = tools.GetUserIdStr(c)
// result, count, err := data.GetPage(pageSize, pageIndex)
// tools.HasError(err, "", -1)
//
// app.PageOK(c, result, count, pageIndex, pageSize, "")
//}
//
//func GetSysContent(c *gin.Context) {
// var data models.SysContent
// data.Id, _ = tools.StringToInt(c.Param("id"))
// result, err := data.Get()
// tools.HasError(err, "抱歉未找到相关信息", -1)
//
// app.OK(c, result, "")
//}
//
//// @Summary 添加内容管理
//// @Description 获取JSON
//// @Tags 内容管理
//// @Accept application/json
//// @Product application/json
//// @Param data body models.SysContent true "data"
//// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
//// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
//// @Router /api/v1/syscontent [post]
//func InsertSysContent(c *gin.Context) {
// var data models.SysContent
// err := c.ShouldBindJSON(&data)
// data.CreateBy = tools.GetUserIdStr(c)
// tools.HasError(err, "", 500)
// result, err := data.Create()
// tools.HasError(err, "", -1)
// app.OK(c, result, "")
//}
//
//func UpdateSysContent(c *gin.Context) {
// var data models.SysContent
// err := c.BindWith(&data, binding.JSON)
// tools.HasError(err, "数据解析失败", -1)
// data.UpdateBy = tools.GetUserIdStr(c)
// result, err := data.Update(data.Id)
// tools.HasError(err, "", -1)
//
// app.OK(c, result, "")
//}
//
//func DeleteSysContent(c *gin.Context) {
// var data models.SysContent
// data.UpdateBy = tools.GetUserIdStr(c)
//
// IDS := tools.IdsStrToIdsIntGroup("id", c)
// _, err := data.BatchDelete(IDS)
// tools.HasError(err, msg.DeletedFail, 500)
// app.OK(c, nil, msg.DeletedSuccess)
//}
+37 -32
View File
@@ -18,10 +18,11 @@ type SysFileDir struct {
apis.Api
}
func (e *SysFileDir) GetSysFileDirList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysFileDir) GetSysFileDirList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
search := new(dto.SysFileDirSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -39,17 +40,18 @@ func (e *SysFileDir) GetSysFileDirList(c *gin.Context) {
list, err = serviceStudent.SetSysFileDir(search)
if err != nil {
log.Errorf("SetSysFileDir error, %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, list, "查询成功")
e.OK(list, "查询成功")
}
func (e *SysFileDir) GetSysFileDir(c *gin.Context) {
func (e SysFileDir) GetSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirById)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -59,7 +61,7 @@ func (e *SysFileDir) GetSysFileDir(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("ShouldBindUri error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
}
var object models.SysFileDir
@@ -70,17 +72,18 @@ func (e *SysFileDir) GetSysFileDir(c *gin.Context) {
err = serviceSysFileDir.GetSysFileDir(control, &object)
if err != nil {
log.Errorf("GetSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
func (e *SysFileDir) InsertSysFileDir(c *gin.Context) {
func (e SysFileDir) InsertSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirControl)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -90,13 +93,13 @@ func (e *SysFileDir) InsertSysFileDir(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("ShouldBindUri error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Warnf("ShouldBind error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
// 设置创建人
@@ -108,17 +111,18 @@ func (e *SysFileDir) InsertSysFileDir(c *gin.Context) {
err = serviceSysFileDir.InsertSysFileDir(control)
if err != nil {
log.Errorf("InsertSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, control.ID, "创建成功")
e.OK(control.ID, "创建成功")
}
func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) {
func (e SysFileDir) UpdateSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirControl)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -127,12 +131,12 @@ func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("ShouldBindUri error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
}
err = c.ShouldBind(control)
if err != nil {
log.Warnf("ShouldBind error: %#v", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
}
// 设置创建人
control.UpdateBy = user.GetUserId(c)
@@ -146,16 +150,17 @@ func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) {
err = serviceSysFileDir.UpdateSysFileDir(control, p)
if err != nil {
log.Errorf("UpdateSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "更新失败")
e.Error(http.StatusInternalServerError, err, "更新失败")
return
}
e.OK(c, control.ID, "更新成功")
e.OK(control.ID, "更新成功")
}
func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) {
func (e SysFileDir) DeleteSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirById)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -166,12 +171,12 @@ func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
}
err = c.ShouldBind(control)
if err != nil {
log.Warnf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
}
// 设置编辑人
@@ -186,8 +191,8 @@ func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) {
err = serviceSysFileDir.RemoveSysFileDir(control, p)
if err != nil {
log.Errorf("RemoveSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "删除失败")
e.Error(http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, control.Id, "删除成功")
e.OK(control.Id, "删除成功")
}
+38 -33
View File
@@ -17,10 +17,11 @@ type SysFileInfo struct {
apis.Api
}
func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysFileInfo) GetSysFileInfoList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
search := new(dto.SysFileInfoSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -28,7 +29,7 @@ func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) {
err = c.ShouldBind(search)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -43,17 +44,18 @@ func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) {
err = serviceStudent.GetSysFileInfoPage(search, p, &list, &count)
if err != nil {
log.Errorf("GetSysFileInfoPage error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.PageOK(c, list, int(count), search.PageIndex, search.PageSize, "查询成功")
e.PageOK(list, int(count), search.PageIndex, search.PageSize, "查询成功")
}
func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) {
func (e SysFileInfo) GetSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoById)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -63,7 +65,7 @@ func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("参数验证错误, error:%s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -78,17 +80,18 @@ func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) {
err = serviceSysFileInfo.GetSysFileInfo(control, p, &object)
if err != nil {
log.Errorf("GetSysFileInfo error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) {
func (e SysFileInfo) InsertSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoControl)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -98,13 +101,13 @@ func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
// 设置创建人
@@ -116,17 +119,18 @@ func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) {
err = serviceSysFileInfo.InsertSysFileInfo(control)
if err != nil {
log.Errorf("InsertSysFileInfo error: %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, control.ID, "创建成功")
e.OK(control.ID, "创建成功")
}
func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
func (e SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoControl)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -135,13 +139,13 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Warnf("参数验证错误, error:%s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
// 设置创建人
@@ -156,16 +160,17 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
err = serviceSysFileInfo.UpdateSysFileInfo(control, p)
if err != nil {
log.Errorf("UpdateSysFileInfo error: %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, control.ID, "更新成功")
e.OK(control.ID, "更新成功")
}
func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) {
func (e SysFileInfo) DeleteSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoById)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -175,13 +180,13 @@ func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) {
err = c.ShouldBindUri(control)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, 422, err, "参数验证失败")
e.Error(422, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, 422, err, "参数验证失败")
e.Error(422, err, "参数验证失败")
return
}
@@ -197,8 +202,8 @@ func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) {
err = serviceSysFileInfo.RemoveSysFileInfo(control, p)
if err != nil {
log.Errorf("RemoveSysFileInfo error: %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, control.Id, "删除成功")
e.OK(control.Id, "删除成功")
}
+14 -14
View File
@@ -5,8 +5,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/service"
"go-admin/common/apis"
"go-admin/common/dto"
@@ -17,9 +15,10 @@ type SysJob struct {
}
// RemoveJobForService 调用service实现
func (e *SysJob) RemoveJobForService(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysJob) RemoveJobForService(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -28,7 +27,7 @@ func (e *SysJob) RemoveJobForService(c *gin.Context) {
err = c.BindUri(&v)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
s := service.SysJob{}
@@ -38,16 +37,17 @@ func (e *SysJob) RemoveJobForService(c *gin.Context) {
err = s.RemoveJob(&v)
if err != nil {
log.Errorf("RemoveJob error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
app.OK(c, nil, s.Msg)
e.OK(nil, s.Msg)
}
// StartJobForService 启动job service实现
func (e *SysJob) StartJobForService(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysJob) StartJobForService(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -56,7 +56,7 @@ func (e *SysJob) StartJobForService(c *gin.Context) {
err = c.BindUri(&v)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
s := service.SysJob{}
@@ -66,8 +66,8 @@ func (e *SysJob) StartJobForService(c *gin.Context) {
err = s.StartJob(&v)
if err != nil {
log.Errorf("GetCrontabKey error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
app.OK(c, nil, s.Msg)
e.OK(nil, s.Msg)
}
+69 -63
View File
@@ -5,9 +5,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/google/uuid"
"go-admin/app/admin/models"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
"go-admin/app/admin/service/dto"
@@ -28,10 +28,11 @@ type SysUser struct {
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/sysUser [get]
// @Security Bearer
func (e *SysUser) GetSysUserList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysUser) GetSysUserList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysUserSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -43,7 +44,7 @@ func (e *SysUser) GetSysUserList(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Warnf("Bind error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -57,24 +58,25 @@ func (e *SysUser) GetSysUserList(c *gin.Context) {
serviceStudent.Orm = db
err = serviceStudent.GetSysUserPage(req, p, &list, &count)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}
// @Summary 获取用户
// @Description 获取JSON
// @Tags 用户
// @Param userId path int true "用户编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sysUser/{userId} [get]
// @Security Bearer
func (e *SysUser) GetSysUser(c *gin.Context) {
log := e.GetLogger(c)
func (e SysUser) GetSysUser(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysUserById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -84,7 +86,7 @@ func (e *SysUser) GetSysUser(c *gin.Context) {
req := control.Generate()
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysUser
@@ -97,11 +99,11 @@ func (e *SysUser) GetSysUser(c *gin.Context) {
serviceSysUser.Orm = db
err = serviceSysUser.GetSysUser(req, p, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
// @Summary 创建用户
@@ -109,14 +111,15 @@ func (e *SysUser) GetSysUser(c *gin.Context) {
// @Tags 用户
// @Accept application/json
// @Product application/json
// @Param data body models.SysUser true "用户数据"
// @Param data body dto.SysUserControl true "用户数据"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sysUser [post]
func (e *SysUser) InsertSysUser(c *gin.Context) {
log := e.GetLogger(c)
func (e SysUser) InsertSysUser(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysUserControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -126,13 +129,13 @@ func (e *SysUser) InsertSysUser(c *gin.Context) {
req := control.Generate()
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -144,11 +147,11 @@ func (e *SysUser) InsertSysUser(c *gin.Context) {
err = serviceSysUser.InsertSysUser(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
// @Summary 修改用户数据
@@ -156,15 +159,16 @@ func (e *SysUser) InsertSysUser(c *gin.Context) {
// @Tags 用户
// @Accept application/json
// @Product application/json
// @Param data body models.SysUser true "body"
// @Param data body dto.SysUserControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/sysuser/{userId} [put]
func (e *SysUser) UpdateSysUser(c *gin.Context) {
func (e SysUser) UpdateSysUser(c *gin.Context) {
control := new(dto.SysUserControl)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -174,13 +178,13 @@ func (e *SysUser) UpdateSysUser(c *gin.Context) {
//更新操作
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -196,7 +200,7 @@ func (e *SysUser) UpdateSysUser(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
// @Summary 删除用户数据
@@ -206,11 +210,12 @@ func (e *SysUser) UpdateSysUser(c *gin.Context) {
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/sysuser/{userId} [delete]
func (e *SysUser) DeleteSysUser(c *gin.Context) {
log := e.GetLogger(c)
func (e SysUser) DeleteSysUser(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysUserById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -221,13 +226,13 @@ func (e *SysUser) DeleteSysUser(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
@@ -245,7 +250,7 @@ func (e *SysUser) DeleteSysUser(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "删除成功")
e.OK(object.GetId(), "删除成功")
}
// @Summary 修改头像
@@ -256,9 +261,10 @@ func (e *SysUser) DeleteSysUser(c *gin.Context) {
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/user/avatar [post]
func (e *SysUser) InsetSysUserAvatar(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysUser) InsetSysUserAvatar(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -277,7 +283,7 @@ func (e *SysUser) InsetSysUserAvatar(c *gin.Context) {
err = c.SaveUploadedFile(file, filPath)
if err != nil {
log.Errorf("save file error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
}
@@ -294,7 +300,7 @@ func (e *SysUser) InsetSysUserAvatar(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, filPath, "修改成功")
e.OK(filPath, "修改成功")
}
// @Summary 重置密码
@@ -303,12 +309,13 @@ func (e *SysUser) InsetSysUserAvatar(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param data body dto.PassWord true "body"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/user/pwd [post]
// @Security Bearer
func (e *SysUser) SysUserUpdatePwd(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysUser) SysUserUpdatePwd(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -318,37 +325,35 @@ func (e *SysUser) SysUserUpdatePwd(c *gin.Context) {
err = c.Bind(&pwd)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
// 数据权限检查
p := actions.GetPermissionFromContext(c)
object := &system.SysUser{
UserId: p.UserId,
Password: pwd.Password,
}
serviceSysUser := service.SysUser{}
serviceSysUser.Orm = db
serviceSysUser.Log = log
err = serviceSysUser.UpdateSysUser(object, p)
err = serviceSysUser.UpdateSysUserPwd(user.GetUserId(c), pwd.OldPassword, pwd.NewPassword, p)
if err != nil {
log.Error(err)
e.Error(http.StatusForbidden, err, "密码修改失败")
return
}
e.OK(c, nil, "密码修改成功")
e.OK(nil, "密码修改成功")
}
// @Summary 获取个人中心用户
// @Description 获取JSON
// @Tags 个人中心
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/user/profile [get]
// @Security Bearer
func (e *SysUser) GetSysUserProfile(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysUser) GetSysUserProfile(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -364,10 +369,10 @@ func (e *SysUser) GetSysUserProfile(c *gin.Context) {
err = serviceSysUser.GetSysUserProfile(id, user, &roles, &posts)
if err != nil {
log.Errorf("get user profile error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "获取用户信息失败")
e.Error(http.StatusInternalServerError, err, "获取用户信息失败")
return
}
e.OK(c, gin.H{
e.OK(gin.H{
"user": user,
"roles": roles,
"posts": posts,
@@ -405,10 +410,11 @@ func (e *SysUser) GetSysUserProfile(c *gin.Context) {
//})
}
func (e *SysUser) GetInfo(c *gin.Context) {
log := e.GetLogger(c)
func (e SysUser) GetInfo(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -426,7 +432,7 @@ func (e *SysUser) GetInfo(c *gin.Context) {
var buttons = make([]string, 1)
buttons[0] = "*:*:*"
RoleMenu := models.RoleMenu{}
RoleMenu := system.RoleMenu{}
RoleMenu.RoleId = user.GetRoleId(c)
var mp = make(map[string]interface{})
@@ -448,7 +454,7 @@ func (e *SysUser) GetInfo(c *gin.Context) {
serviceSysUser.Orm = db
err = serviceSysUser.GetSysUser(req, p, &sysUser)
if err != nil {
e.Error(c, http.StatusUnauthorized, err, "登录失败")
e.Error(http.StatusUnauthorized, err, "登录失败")
return
}
@@ -462,5 +468,5 @@ func (e *SysUser) GetInfo(c *gin.Context) {
mp["userId"] = sysUser.UserId
mp["deptId"] = sysUser.DeptId
mp["name"] = sysUser.NickName
e.OK(c, mp, "")
e.OK(mp, "")
}
+14 -5
View File
@@ -2,15 +2,24 @@ package system
import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/common/apis"
)
func GenerateCaptchaHandler(c *gin.Context) {
type System struct {
apis.Api
}
func (e System) GenerateCaptchaHandler(c *gin.Context) {
e.Context = c
log := e.GetLogger()
id, b64s, err := captcha.DriverDigitFunc()
pkg.HasError(err, "验证码获取失败", 500)
app.Custum(c, gin.H{
if err != nil {
log.Errorf("DriverDigitFunc error, %s", err.Error())
e.Error(500, err, "验证码获取失败")
return
}
e.Custom(gin.H{
"code": 200,
"data": b64s,
"id": id,
+48 -41
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -25,12 +26,13 @@ type SysDictData struct {
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data [get]
// @Security Bearer
func (e *SysDictData) GetSysDictDataList(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictData) GetSysDictDataList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -42,7 +44,7 @@ func (e *SysDictData) GetSysDictDataList(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Warnf("Bind error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -54,23 +56,24 @@ func (e *SysDictData) GetSysDictDataList(c *gin.Context) {
err = s.GetPage(req, &list, &count)
if err != nil {
log.Errorf("GetPage error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}
// @Summary 通过编码获取字典数据
// @Description 获取JSON
// @Tags 字典数据
// @Param dictCode path int true "字典编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data/{dictCode} [get]
// @Security Bearer
func (e *SysDictData) GetSysDictData(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictData) GetSysDictData(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -81,7 +84,7 @@ func (e *SysDictData) GetSysDictData(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Warnf("Bind error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysDictData
@@ -92,11 +95,11 @@ func (e *SysDictData) GetSysDictData(c *gin.Context) {
err = s.Get(req, &object)
if err != nil {
log.Warnf("Get error: %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
// @Summary 添加字典数据
@@ -104,14 +107,15 @@ func (e *SysDictData) GetSysDictData(c *gin.Context) {
// @Tags 字典数据
// @Accept application/json
// @Product application/json
// @Param data body system.DictType true "data"
// @Param data body dto.SysDictDataControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/data [post]
// @Security Bearer
func (e *SysDictData) InsertSysDictData(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictData) InsertSysDictData(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -122,7 +126,7 @@ func (e *SysDictData) InsertSysDictData(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Warnf("Bind error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, _ := req.GenerateM()
@@ -135,11 +139,11 @@ func (e *SysDictData) InsertSysDictData(c *gin.Context) {
err = s.Insert(object.(*system.SysDictData))
if err != nil {
log.Errorf("Insert error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
// @Summary 修改字典数据
@@ -147,14 +151,15 @@ func (e *SysDictData) InsertSysDictData(c *gin.Context) {
// @Tags 字典数据
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "body"
// @Param data body dto.SysDictDataControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/data/{dictCode} [put]
// @Security Bearer
func (e *SysDictData) UpdateSysDictData(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictData) UpdateSysDictData(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -165,7 +170,7 @@ func (e *SysDictData) UpdateSysDictData(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Warnf("request validate error, %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, _ := req.GenerateM()
@@ -177,10 +182,10 @@ func (e *SysDictData) UpdateSysDictData(c *gin.Context) {
err = s.Update(object.(*system.SysDictData))
if err != nil {
log.Errorf("Update error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "更新失败")
e.Error(http.StatusInternalServerError, err, "更新失败")
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
// @Summary 删除字典数据
@@ -190,9 +195,10 @@ func (e *SysDictData) UpdateSysDictData(c *gin.Context) {
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/dict/data/{dictCode} [delete]
func (e *SysDictData) DeleteSysDictData(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictData) DeleteSysDictData(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -203,14 +209,14 @@ func (e *SysDictData) DeleteSysDictData(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Warnf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
if err != nil {
log.Errorf("GenerateM error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
@@ -223,15 +229,16 @@ func (e *SysDictData) DeleteSysDictData(c *gin.Context) {
err = s.Remove(req, object.(*system.SysDictData))
if err != nil {
log.Errorf("Remove error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "删除失败")
e.Error(http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, object.GetId(), "删除成功")
e.OK(object.GetId(), "删除成功")
}
func (e *SysDictData) GetSysDictDataAll(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictData) GetSysDictDataAll(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -243,7 +250,7 @@ func (e *SysDictData) GetSysDictDataAll(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Warnf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -254,9 +261,9 @@ func (e *SysDictData) GetSysDictDataAll(c *gin.Context) {
err = s.GetAll(req, &list)
if err != nil {
log.Errorf("GetAll error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.OK(c, list, "查询成功")
e.OK(list, "查询成功")
}
+47 -40
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -25,12 +26,13 @@ type SysDictType struct {
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type [get]
// @Security Bearer
func (e *SysDictType) GetSysDictTypeList(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictType) GetSysDictTypeList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -41,7 +43,7 @@ func (e *SysDictType) GetSysDictTypeList(c *gin.Context) {
//查询列表
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -52,23 +54,24 @@ func (e *SysDictType) GetSysDictTypeList(c *gin.Context) {
s.Orm = db.Debug()
err = s.GetPage(req, &list, &count)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}
// @Summary 通过字典id获取字典类型
// @Description 获取JSON
// @Tags 字典类型
// @Param dictId path int true "字典类型编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type/{dictId} [get]
// @Security Bearer
func (e *SysDictType) GetSysDictType(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictType) GetSysDictType(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -78,7 +81,7 @@ func (e *SysDictType) GetSysDictType(c *gin.Context) {
req := &dto.SysDictTypeById{}
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysDictType
@@ -88,11 +91,11 @@ func (e *SysDictType) GetSysDictType(c *gin.Context) {
s.Orm = db
err = s.Get(req, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
// @Summary 添加字典类型
@@ -100,14 +103,15 @@ func (e *SysDictType) GetSysDictType(c *gin.Context) {
// @Tags 字典类型
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "data"
// @Param data body dto.SysDictTypeControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/type [post]
// @Security Bearer
func (e *SysDictType) InsertSysDictType(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictType) InsertSysDictType(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -117,7 +121,7 @@ func (e *SysDictType) InsertSysDictType(c *gin.Context) {
req := &dto.SysDictTypeControl{}
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, _ := req.GenerateM()
@@ -130,11 +134,11 @@ func (e *SysDictType) InsertSysDictType(c *gin.Context) {
err = s.Insert(object.(*system.SysDictType))
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
// @Summary 修改字典类型
@@ -142,14 +146,15 @@ func (e *SysDictType) InsertSysDictType(c *gin.Context) {
// @Tags 字典类型
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "body"
// @Param data body dto.SysDictTypeControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/type/{dictId} [put]
// @Security Bearer
func (e *SysDictType) UpdateSysDictType(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictType) UpdateSysDictType(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -159,7 +164,7 @@ func (e *SysDictType) UpdateSysDictType(c *gin.Context) {
//更新操作
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, _ := req.GenerateM()
@@ -173,7 +178,7 @@ func (e *SysDictType) UpdateSysDictType(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
// @Summary 删除字典类型
@@ -183,9 +188,10 @@ func (e *SysDictType) UpdateSysDictType(c *gin.Context) {
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/dict/type/{dictId} [delete]
func (e *SysDictType) DeleteSysDictType(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictType) DeleteSysDictType(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -196,13 +202,13 @@ func (e *SysDictType) DeleteSysDictType(c *gin.Context) {
err = req.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object common.ActiveRecord
object, err = req.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
@@ -217,7 +223,7 @@ func (e *SysDictType) DeleteSysDictType(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "删除成功")
e.OK(object.GetId(), "删除成功")
}
// @Summary 字典类型全部数据
@@ -226,12 +232,13 @@ func (e *SysDictType) DeleteSysDictType(c *gin.Context) {
// @Param dictName query string false "dictName"
// @Param dictId query string false "dictId"
// @Param dictType query string false "dictType"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type-option-select [get]
// @Security Bearer
func (e *SysDictType) GetSysDictTypeAll(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysDictType) GetSysDictTypeAll(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -242,7 +249,7 @@ func (e *SysDictType) GetSysDictTypeAll(c *gin.Context) {
//查询列表
err = req.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -252,9 +259,9 @@ func (e *SysDictType) GetSysDictTypeAll(c *gin.Context) {
s.Orm = db
err = s.GetAll(req, &list)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, list, "查询成功")
e.OK(list, "查询成功")
}
+1 -1
View File
@@ -28,7 +28,7 @@ $(function(){
</script>
</head>
<body>
<iframe id="iframe" frameborder="0" src="http://doc.zhangwj.com/go-admin-site/" style="width:100%;"></iframe>
<iframe id="iframe" frameborder="0" src="https://doc.go-admin.dev" style="width:100%;"></iframe>
</body>
</html>
`
-67
View File
@@ -1,67 +0,0 @@
package system
import (
"go-admin/app/admin/models"
)
// @Summary RoleMenu列表数据
// @Description 获取JSON
// @Tags 角色菜单
// @Param RoleId query string false "RoleId"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/rolemenu [get]
// @Security Bearer
//func GetRoleMenu(c *gin.Context) {
// var Rm models.RoleMenu
// err := c.ShouldBind(&Rm)
// result, err := Rm.Get()
// var res app.Response
// if err != nil {
// res.Msg = "抱歉未找到相关信息"
// c.JSON(http.StatusOK, res.ReturnError(200))
// return
// }
// res.Data = result
// c.JSON(http.StatusOK, res.ReturnOK())
//}
type RoleMenuPost struct {
RoleId string
RoleMenu []models.RoleMenu
}
//func InsertRoleMenu(c *gin.Context) {
//
// var res app.Response
// res.Msg = "添加成功"
// c.JSON(http.StatusOK, res.ReturnOK())
// return
//
//}
// @Summary 删除用户菜单数据
// @Description 删除数据
// @Tags 角色菜单
// @Param id path string true "id"
// @Param menu_id query string false "menu_id"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/rolemenu/{id} [delete]
//func DeleteRoleMenu(c *gin.Context) {
// var t models.RoleMenu
// id := c.Param("id")
// menuId := c.Request.FormValue("menu_id")
// fmt.Println(menuId)
// _, err := t.Delete(id, menuId)
// if err != nil {
// var res app.Response
// res.Msg = "删除失败"
// c.JSON(http.StatusOK, res.ReturnError(200))
// return
// }
// var res app.Response
// res.Msg = "删除成功"
// c.JSON(http.StatusOK, res.ReturnOK())
// return
//}
+15 -13
View File
@@ -23,9 +23,10 @@ type SysSetting struct {
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/setting [get]
func (e *SysSetting) GetSetting(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysSetting) GetSetting(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -37,7 +38,7 @@ func (e *SysSetting) GetSetting(c *gin.Context) {
var model = models.SysSetting{}
err = sysSettingService.GetSysSetting(&model)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
@@ -47,20 +48,21 @@ func (e *SysSetting) GetSetting(c *gin.Context) {
}
}
e.OK(c, model, "查询成功")
e.OK(model, "查询成功")
}
// @Summary 更新或提交系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Param data body models.SysUser true "body"
// @Param data body dto.SysSettingControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/system/setting [post]
func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) {
func (e SysSetting) CreateOrUpdateSetting(c *gin.Context) {
control := new(dto.SysSettingControl)
log := e.GetLogger(c)
db, err := e.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -69,12 +71,12 @@ func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
@@ -83,7 +85,7 @@ func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) {
sysSettingService.Orm = db
err = sysSettingService.UpdateSysSetting(object)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "更新失败")
e.Error(http.StatusInternalServerError, err, "更新失败")
return
}
@@ -92,5 +94,5 @@ func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) {
object.Logo = fmt.Sprintf("http://%s/%s", c.Request.Host, object.Logo)
}
}
e.OK(c, object, "提交成功")
e.OK(object, "提交成功")
}
+96 -51
View File
@@ -5,7 +5,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -17,10 +16,11 @@ type SysConfig struct {
apis.Api
}
func (e *SysConfig) GetSysConfigList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysConfig) GetSysConfigList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysConfigSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -30,7 +30,7 @@ func (e *SysConfig) GetSysConfigList(c *gin.Context) {
err = d.Bind(c)
if err != nil {
log.Errorf("参数验证失败, error:%s", err)
app.Error(c, 500, err, "参数验证失败")
e.Error(500, err, "参数验证失败")
return
}
@@ -42,16 +42,57 @@ func (e *SysConfig) GetSysConfigList(c *gin.Context) {
err = s.GetSysConfigPage(d, &list, &count)
if err != nil {
log.Errorf("GetSysConfigPage 查询失败, error:%s", err)
app.Error(c, 500, err, "查询失败")
e.Error(500, err, "查询失败")
return
}
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
func (e *SysConfig) GetSysConfig(c *gin.Context) {
log := e.GetLogger(c)
// GetSysConfigBySysApp 获取系统配置信息,主要注意这里不在验证数据权限
func (e SysConfig) GetSysConfigBySysApp(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysConfigSearch)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
}
err = d.Bind(c)
if err != nil {
log.Errorf("参数验证失败, error:%s", err)
e.Error(500, err, "参数验证失败")
return
}
// 控制只读前台的数据
d.IsFrontend = 1
list := make([]system.SysConfig, 0)
s := service.SysConfig{}
s.Log = log
s.Orm = db
err = s.GetSysConfigByKey(d, &list)
if err != nil {
log.Errorf("GetSysConfigPage 查询失败, error:%s", err)
e.Error(500, err, "查询失败")
return
}
mp := make(map[string]string)
for i := 0; i < len(list); i++ {
key := list[i].ConfigKey
if key != "" {
mp[key] = list[i].ConfigValue
}
}
e.OK(mp, "查询成功")
}
func (e SysConfig) GetSysConfig(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysConfigById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -59,9 +100,9 @@ func (e *SysConfig) GetSysConfig(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
var object system.SysConfig
@@ -71,19 +112,20 @@ func (e *SysConfig) GetSysConfig(c *gin.Context) {
serviceSysLoginLog.Orm = db
err = serviceSysLoginLog.GetSysConfig(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
func (e *SysConfig) InsertSysConfig(c *gin.Context) {
log := e.GetLogger(c)
func (e SysConfig) InsertSysConfig(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysConfigControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -92,16 +134,16 @@ func (e *SysConfig) InsertSysConfig(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
// 设置创建人
@@ -113,19 +155,20 @@ func (e *SysConfig) InsertSysConfig(c *gin.Context) {
err = serviceSysLoginLog.InsertSysConfig(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
func (e *SysConfig) UpdateSysConfig(c *gin.Context) {
log := e.GetLogger(c)
func (e SysConfig) UpdateSysConfig(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysConfigControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -135,16 +178,16 @@ func (e *SysConfig) UpdateSysConfig(c *gin.Context) {
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -154,18 +197,19 @@ func (e *SysConfig) UpdateSysConfig(c *gin.Context) {
serviceSysLoginLog.Log = log
err = serviceSysLoginLog.UpdateSysConfig(object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "更新失败")
e.Error(http.StatusUnprocessableEntity, err, "更新失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
func (e *SysConfig) DeleteSysConfig(c *gin.Context) {
log := e.GetLogger(c)
func (e SysConfig) DeleteSysConfig(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysConfigById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -175,16 +219,16 @@ func (e *SysConfig) DeleteSysConfig(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
object, err := control.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
@@ -196,18 +240,19 @@ func (e *SysConfig) DeleteSysConfig(c *gin.Context) {
serviceSysLoginLog.Log = log
err = serviceSysLoginLog.RemoveSysConfig(control, object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "删除失败")
e.Error(http.StatusUnprocessableEntity, err, "删除失败")
log.Errorf("Orm获取失败, error:%s", err)
app.Error(c, 500, err, "Orm获取失败")
e.Error(500, err, "Orm获取失败")
return
}
e.OK(c, object.GetId(), "删除成功")
e.OK(object.GetId(), "删除成功")
}
// GetSysConfigByKEYForService 根据Key获取SysConfig的Service
func (e *SysConfig) GetSysConfigByKEYForService(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysConfig) GetSysConfigByKEYForService(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -216,7 +261,7 @@ func (e *SysConfig) GetSysConfigByKEYForService(c *gin.Context) {
err = v.Bind(c)
if err != nil {
log.Errorf("参数验证错误, error:%s", err)
app.Error(c, 422, err, "参数验证失败")
e.Error(422, err, "参数验证失败")
return
}
s := service.SysConfig{}
@@ -225,8 +270,8 @@ func (e *SysConfig) GetSysConfigByKEYForService(c *gin.Context) {
err = s.GetSysConfigByKEY(&v)
if err != nil {
log.Errorf("通过Key获取配置失败, error:%s", err)
app.Error(c, 500, err, "")
e.Error(500, err, "")
return
}
app.OK(c, v, s.Msg)
e.OK(v, s.Msg)
}
+81 -69
View File
@@ -1,10 +1,12 @@
package sys_dept
import (
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -22,13 +24,14 @@ type SysDept struct {
// @Param name query string false "name"
// @Param id query string false "id"
// @Param position query string false "position"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dept [get]
// @Security Bearer
func (e *SysDept) GetSysDeptList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysDept) GetSysDeptList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysDeptSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -37,7 +40,7 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -47,11 +50,11 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) {
serviceStudent.Orm = db
list, err = serviceStudent.SetDeptPage(d)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, list, "查询成功")
e.OK(list, "查询成功")
}
// @Summary 部门列表数据
@@ -59,13 +62,14 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) {
// @Tags 部门
// @Param deptId path string false "deptId"
// @Param position query string false "position"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dept/{deptId} [get]
// @Security Bearer
func (e *SysDept) GetSysDept(c *gin.Context) {
log := e.GetLogger(c)
func (e SysDept) GetSysDept(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysDeptById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -74,7 +78,7 @@ func (e *SysDept) GetSysDept(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysDept
@@ -84,11 +88,11 @@ func (e *SysDept) GetSysDept(c *gin.Context) {
serviceSysOperlog.Orm = db
err = serviceSysOperlog.GetSysDept(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
// @Summary 添加部门
@@ -96,15 +100,16 @@ func (e *SysDept) GetSysDept(c *gin.Context) {
// @Tags 部门
// @Accept application/json
// @Product application/json
// @Param data body models.SysDept true "data"
// @Param data body dto.SysDeptControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dept [post]
// @Security Bearer
func (e *SysDept) InsertSysDept(c *gin.Context) {
log := e.GetLogger(c)
func (e SysDept) InsertSysDept(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysDeptControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -113,12 +118,12 @@ func (e *SysDept) InsertSysDept(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -130,11 +135,11 @@ func (e *SysDept) InsertSysDept(c *gin.Context) {
err = serviceSysDept.InsertSysDept(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
// @Summary 修改部门
@@ -143,15 +148,16 @@ func (e *SysDept) InsertSysDept(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param id path int true "id"
// @Param data body models.SysDept true "body"
// @Param data body dto.SysDeptControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dept/{deptId} [put]
// @Security Bearer
func (e *SysDept) UpdateSysDept(c *gin.Context) {
log := e.GetLogger(c)
func (e SysDept) UpdateSysDept(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysDeptControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -160,12 +166,12 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -178,20 +184,21 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
// @Summary 删除部门
// @Description 删除数据
// @Tags 部门
// @Param data body []int true "body"
// @Param data body dto.SysDeptById true "body"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/dept [delete]
func (e *SysDept) DeleteSysDept(c *gin.Context) {
log := e.GetLogger(c)
func (e SysDept) DeleteSysDept(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysDeptById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -201,7 +208,7 @@ func (e *SysDept) DeleteSysDept(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -211,17 +218,18 @@ func (e *SysDept) DeleteSysDept(c *gin.Context) {
err = serviceSysDept.RemoveSysDept(control)
if err != nil {
log.Errorf("RemoveSysDept error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "删除失败")
e.Error(http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, control.GetId(), "删除成功")
e.OK(control.GetId(), "删除成功")
}
// GetDeptTree 用户管理 左侧部门树
func (e *SysDept) GetDeptTree(c *gin.Context) {
log := e.GetLogger(c)
func (e SysDept) GetDeptTree(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysDeptSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -230,7 +238,7 @@ func (e *SysDept) GetDeptTree(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -240,7 +248,7 @@ func (e *SysDept) GetDeptTree(c *gin.Context) {
serviceStudent.Orm = db
list, err = serviceStudent.SetDeptTree(d)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
@@ -250,33 +258,37 @@ func (e *SysDept) GetDeptTree(c *gin.Context) {
//Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
//result, err := Dept.SetDept(false)
//tools.HasError(err, "抱歉未找到相关信息", -1)
e.OK(c, list, "")
e.OK(list, "")
}
//func (e *SysDept) GetDeptTreeRoleSelect(c *gin.Context) {
// log := e.GetLogger(c)
// db, err := tools.GetOrm(c)
// if err != nil {
// log.Error(err)
// return
// }
//
// s := service.SysDept{}
// s.Orm = db
// s.MsgID = msgID
// id, err := tools.StringToInt(c.Param("roleId"))
// result, err := s.SetDeptLabel()
// if err != nil {
// log.Errorf("SetDeptLabel error, %s", msgID, err.Error())
// e.Error(c, http.StatusInternalServerError, err, "")
// }
// menuIds := make([]int, 0)
// if id != 0 {
// menuIds, err = s.GetRoleDeptId(id)
// tools.HasError(err, "抱歉未找到相关信息", -1)
// }
// e.OK(c, gin.H{
// "depts": result,
// "checkedKeys": menuIds,
// }, "")
//}
func (e SysDept) GetDeptTreeRoleSelect(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
}
s := service.SysDept{}
s.Orm = db
s.Log = log
id, err := pkg.StringToInt(c.Param("roleId"))
result, err := s.SetDeptLabel()
if err != nil {
log.Errorf("SetDeptLabel error, %s", err.Error())
e.Error(http.StatusInternalServerError, err, "")
}
menuIds := make([]int, 0)
if id != 0 {
menuIds, err = s.GetRoleDeptId(id)
if err != nil {
log.Errorf("抱歉未找到相关信息, %s", err.Error())
e.Error(http.StatusInternalServerError, err, "")
}
}
e.OK(gin.H{
"depts": result,
"checkedKeys": menuIds,
}, "")
}
@@ -16,10 +16,11 @@ type SysLoginLog struct {
apis.Api
}
func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysLoginLog) GetSysLoginLogList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysLoginLogSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -28,7 +29,7 @@ func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -39,17 +40,18 @@ func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) {
serviceStudent.Orm = db
err = serviceStudent.GetSysLoginLogPage(d, &list, &count)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysLoginLog) GetSysLoginLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysLoginLogById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -58,7 +60,7 @@ func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysLoginLog
@@ -68,17 +70,18 @@ func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) {
serviceSysLoginLog.Orm = db
err = serviceSysLoginLog.GetSysLoginLog(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysLoginLog) InsertSysLoginLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysLoginLogControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -87,12 +90,12 @@ func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -104,17 +107,18 @@ func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) {
err = serviceSysLoginLog.InsertSysLoginLog(object)
if err != nil {
log.Errorf("InsertSysLoginLog error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysLoginLog) UpdateSysLoginLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysLoginLogControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -123,12 +127,12 @@ func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -139,16 +143,17 @@ func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) {
err = serviceSysLoginLog.UpdateSysLoginLog(object)
if err != nil {
log.Errorf("UpdateSysLoginLog error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "更新失败")
e.Error(http.StatusInternalServerError, err, "更新失败")
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysLoginLogById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -158,12 +163,12 @@ func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.GenerateM()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
@@ -176,8 +181,8 @@ func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
err = serviceSysLoginLog.RemoveSysLoginLog(control, object)
if err != nil {
log.Errorf("RemoveSysLoginLog error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "删除失败")
e.Error(http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, object.GetId(), "删除成功")
e.OK(object.GetId(), "删除成功")
}
+61 -54
View File
@@ -6,7 +6,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
"go-admin/app/admin/models"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
"go-admin/app/admin/service/dto"
@@ -25,10 +24,11 @@ type SysMenu struct {
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menulist [get]
// @Security Bearer
func (e *SysMenu) GetSysMenuList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysMenu) GetSysMenuList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysMenuSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -37,7 +37,7 @@ func (e *SysMenu) GetSysMenuList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -47,11 +47,11 @@ func (e *SysMenu) GetSysMenuList(c *gin.Context) {
serviceSysMenu.Orm = db
list, err = serviceSysMenu.GetSysMenuPage(d)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, list, "查询成功")
e.OK(list, "查询成功")
}
// @Summary Menu详情数据
@@ -62,12 +62,13 @@ func (e *SysMenu) GetSysMenuList(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menu/{id} [get]
// @Security Bearer
func (e *SysMenu) GetSysMenu(c *gin.Context) {
func (e SysMenu) GetSysMenu(c *gin.Context) {
control := new(dto.SysMenuById)
log := e.GetLogger(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -76,7 +77,7 @@ func (e *SysMenu) GetSysMenu(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysMenu
@@ -86,11 +87,11 @@ func (e *SysMenu) GetSysMenu(c *gin.Context) {
serviceSysMenu.Orm = db
err = serviceSysMenu.GetSysMenu(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
// @Summary 创建菜单
@@ -108,12 +109,13 @@ func (e *SysMenu) GetSysMenu(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/menu [post]
// @Security Bearer
func (e *SysMenu) InsertSysMenu(c *gin.Context) {
func (e SysMenu) InsertSysMenu(c *gin.Context) {
control := new(dto.SysMenuControl)
log := e.GetLogger(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -122,12 +124,12 @@ func (e *SysMenu) InsertSysMenu(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -139,11 +141,11 @@ func (e *SysMenu) InsertSysMenu(c *gin.Context) {
err = serviceSysMenu.InsertSysMenu(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
// @Summary 修改菜单
@@ -152,17 +154,18 @@ func (e *SysMenu) InsertSysMenu(c *gin.Context) {
// @Accept application/x-www-form-urlencoded
// @Product application/x-www-form-urlencoded
// @Param id path int true "id"
// @Param data body models.Menu true "body"
// @Param data body dto.SysMenuControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/menu/{id} [put]
// @Security Bearer
func (e *SysMenu) UpdateSysMenu(c *gin.Context) {
func (e SysMenu) UpdateSysMenu(c *gin.Context) {
control := new(dto.SysMenuControl)
log := e.GetLogger(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -171,12 +174,12 @@ func (e *SysMenu) UpdateSysMenu(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -189,22 +192,23 @@ func (e *SysMenu) UpdateSysMenu(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
// @Summary 删除菜单
// @Description 删除数据
// @Tags 菜单
// @Param data body []int true "body"
// @Param data body dto.SysMenuById true "body"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/menu/ [delete]
func (e *SysMenu) DeleteSysMenu(c *gin.Context) {
func (e SysMenu) DeleteSysMenu(c *gin.Context) {
control := new(dto.SysMenuById)
log := e.GetLogger(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -214,7 +218,7 @@ func (e *SysMenu) DeleteSysMenu(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -224,10 +228,10 @@ func (e *SysMenu) DeleteSysMenu(c *gin.Context) {
err = serviceSysMenu.RemoveSysMenu(control)
if err != nil {
log.Errorf("RemoveSysMenu error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "删除失败")
e.Error(http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, control.GetId(), "删除成功")
e.OK(control.GetId(), "删除成功")
}
// @Summary 根据角色名称获取菜单列表数据(左菜单使用)
@@ -238,9 +242,10 @@ func (e *SysMenu) DeleteSysMenu(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menurole [get]
// @Security Bearer
func (e *SysMenu) GetMenuRole(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysMenu) GetMenuRole(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -252,11 +257,11 @@ func (e *SysMenu) GetMenuRole(c *gin.Context) {
result, err := serviceSysMenu.SetMenuRole(user.GetRoleName(c))
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "查询失败")
e.Error(http.StatusInternalServerError, err, "查询失败")
return
}
e.OK(c, result, "")
e.OK(result, "")
}
// @Summary 获取角色对应的菜单id数组
@@ -267,27 +272,28 @@ func (e *SysMenu) GetMenuRole(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menuids/{id} [get]
// @Security Bearer
func (e *SysMenu) GetMenuIDS(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysMenu) GetMenuIDS(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
}
var data models.RoleMenu
var data system.RoleMenu
data.RoleName = c.GetString("role")
data.UpdateBy = user.GetUserIdStr(c)
data.UpdateBy = user.GetUserId(c)
result, err := data.GetIDS(db)
if err != nil {
log.Errorf("GetIDS error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "获取失败")
e.Error(http.StatusInternalServerError, err, "获取失败")
return
}
e.OK(c, result, "")
e.OK(result, "")
}
//// GetMenuTreeRoleselect 角色修改中的菜单列表
//func (e *SysMenu) GetMenuTreeRoleselect(c *gin.Context) {
//func (e SysMenu) GetMenuTreeRoleselect(c *gin.Context) {
// var Menu models.Menu
// var SysRole models.SysRole
//
@@ -322,9 +328,10 @@ func (e *SysMenu) GetMenuIDS(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/menuTreeselect [get]
// @Security Bearer
func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) {
log := e.GetLogger(c)
db, err := e.GetOrm(c)
func (e SysMenu) GetMenuTreeSelect(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -334,7 +341,7 @@ func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) {
err = c.BindUri(d)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -343,7 +350,7 @@ func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) {
serviceSysMenu.Orm = db
result, err := serviceSysMenu.SetSysMenuLabel()
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
s := service.SysRole{}
@@ -352,10 +359,10 @@ func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) {
menuIds, err := s.GetRoleMenuId(db, d.RoleId)
if err != nil {
log.Errorf("GetIDS error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
e.OK(c, gin.H{
e.OK(gin.H{
"menus": result,
"checkedKeys": menuIds,
}, "获取成功")
@@ -16,10 +16,11 @@ type SysOperaLog struct {
apis.Api
}
func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysOperaLog) GetSysOperaLogList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysOperaLogSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -28,7 +29,7 @@ func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -39,17 +40,18 @@ func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) {
serviceStudent.Orm = db
err = serviceStudent.GetSysOperaLogPage(d, &list, &count)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysOperaLog) GetSysOperaLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysOperaLogById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -58,7 +60,7 @@ func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysOperaLog
@@ -68,17 +70,18 @@ func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) {
serviceSysOperlog.Orm = db
err = serviceSysOperlog.GetSysOperaLog(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysOperaLog) InsertSysOperaLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysOperaLogControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -87,12 +90,12 @@ func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -104,17 +107,18 @@ func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) {
err = serviceSysOperaLog.InsertSysOperaLog(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysOperaLog) UpdateSysOperaLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysOperaLogControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -123,12 +127,12 @@ func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -141,13 +145,14 @@ func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) {
log := e.GetLogger(c)
func (e SysOperaLog) DeleteSysOperaLog(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysOperaLogById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -157,7 +162,7 @@ func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -169,5 +174,5 @@ func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, control.GetId(), "删除成功")
e.OK(control.GetId(), "删除成功")
}
+40 -34
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -23,13 +24,14 @@ type SysPost struct {
// @Param postCode query string false "postCode"
// @Param postId query string false "postId"
// @Param status query string false "status"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post [get]
// @Security Bearer
func (e *SysPost) GetSysPostList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysPost) GetSysPostList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysPostSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -38,7 +40,7 @@ func (e *SysPost) GetSysPostList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -49,24 +51,25 @@ func (e *SysPost) GetSysPostList(c *gin.Context) {
serviceStudent.Orm = db
err = serviceStudent.GetSysPostPage(d, &list, &count)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
// @Summary 获取岗位信息
// @Description 获取JSON
// @Tags 岗位
// @Param postId path int true "postId"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post/{postId} [get]
// @Security Bearer
func (e *SysPost) GetSysPost(c *gin.Context) {
log := e.GetLogger(c)
func (e SysPost) GetSysPost(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysPostById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -75,7 +78,7 @@ func (e *SysPost) GetSysPost(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysPost
@@ -85,11 +88,11 @@ func (e *SysPost) GetSysPost(c *gin.Context) {
serviceSysOperlog.Orm = db
err = serviceSysOperlog.GetSysPost(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
// @Summary 添加岗位
@@ -97,15 +100,16 @@ func (e *SysPost) GetSysPost(c *gin.Context) {
// @Tags 岗位
// @Accept application/json
// @Product application/json
// @Param data body models.Post true "data"
// @Param data body dto.SysPostControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/post [post]
// @Security Bearer
func (e *SysPost) InsertSysPost(c *gin.Context) {
log := e.GetLogger(c)
func (e SysPost) InsertSysPost(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysPostControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -114,12 +118,12 @@ func (e *SysPost) InsertSysPost(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -131,11 +135,11 @@ func (e *SysPost) InsertSysPost(c *gin.Context) {
err = serviceSysPost.InsertSysPost(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
// @Summary 修改岗位
@@ -143,15 +147,16 @@ func (e *SysPost) InsertSysPost(c *gin.Context) {
// @Tags 岗位
// @Accept application/json
// @Product application/json
// @Param data body models.Post true "body"
// @Param data body dto.SysPostControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/post/ [put]
// @Security Bearer
func (e *SysPost) UpdateSysPost(c *gin.Context) {
log := e.GetLogger(c)
func (e SysPost) UpdateSysPost(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysPostControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -160,12 +165,12 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -178,7 +183,7 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
// @Summary 删除岗位
@@ -188,10 +193,11 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) {
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 500 {string} string "{"code": 500, "message": "删除失败"}"
// @Router /api/v1/post/{postId} [delete]
func (e *SysPost) DeleteSysPost(c *gin.Context) {
log := e.GetLogger(c)
func (e SysPost) DeleteSysPost(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysPostById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -201,7 +207,7 @@ func (e *SysPost) DeleteSysPost(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -213,5 +219,5 @@ func (e *SysPost) DeleteSysPost(c *gin.Context) {
log.Error(err)
return
}
e.OK(c, control.GetId(), "删除成功")
e.OK(control.GetId(), "删除成功")
}
+50 -43
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -25,13 +26,14 @@ type SysRole struct {
// @Param roleKey query string false "roleKey"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role [get]
// @Security Bearer
func (e *SysRole) GetSysRoleList(c *gin.Context) {
log := e.GetLogger(c)
func (e SysRole) GetSysRoleList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
d := new(dto.SysRoleSearch)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -40,7 +42,7 @@ func (e *SysRole) GetSysRoleList(c *gin.Context) {
//查询列表
err = d.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -51,11 +53,11 @@ func (e *SysRole) GetSysRoleList(c *gin.Context) {
s.Orm = db
err = s.GetSysRolePage(d, &list, &count)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
// @Summary 获取Role数据
@@ -66,10 +68,11 @@ func (e *SysRole) GetSysRoleList(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/role/{id} [get]
// @Security Bearer
func (e *SysRole) GetSysRole(c *gin.Context) {
log := e.GetLogger(c)
func (e SysRole) GetSysRole(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysRoleById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -78,7 +81,7 @@ func (e *SysRole) GetSysRole(c *gin.Context) {
//查看详情
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object system.SysRole
@@ -88,11 +91,11 @@ func (e *SysRole) GetSysRole(c *gin.Context) {
s.Orm = db
err = s.GetSysRole(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
return
}
e.OK(c, object, "查看成功")
e.OK(object, "查看成功")
}
// @Summary 创建角色
@@ -100,15 +103,16 @@ func (e *SysRole) GetSysRole(c *gin.Context) {
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.SysRole true "data"
// @Param data body dto.SysRoleControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/role [post]
// @Security Bearer
func (e *SysRole) InsertSysRole(c *gin.Context) {
log := e.GetLogger(c)
func (e SysRole) InsertSysRole(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysRoleControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -117,12 +121,12 @@ func (e *SysRole) InsertSysRole(c *gin.Context) {
//新增操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
// 设置创建人
@@ -137,15 +141,15 @@ func (e *SysRole) InsertSysRole(c *gin.Context) {
err = s.InsertSysRole(object)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
e.Error(http.StatusInternalServerError, err, "创建失败")
return
}
_, err = global.LoadPolicy(c)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
e.OK(c, object.GetId(), "创建成功")
e.OK(object.GetId(), "创建成功")
}
// @Summary 修改用户角色
@@ -153,15 +157,16 @@ func (e *SysRole) InsertSysRole(c *gin.Context) {
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.SysRole true "body"
// @Param data body dto.SysRoleControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/role/{id} [put]
// @Security Bearer
func (e *SysRole) UpdateSysRole(c *gin.Context) {
log := e.GetLogger(c)
func (e SysRole) UpdateSysRole(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysRoleControl)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -170,12 +175,12 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) {
//更新操作
err = control.Bind(c)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
object, err := control.Generate()
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
e.Error(http.StatusInternalServerError, err, "模型生成失败")
return
}
object.UpdateBy = user.GetUserId(c)
@@ -190,10 +195,10 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) {
}
_, err = global.LoadPolicy(c)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
e.OK(c, object.GetId(), "更新成功")
e.OK(object.GetId(), "更新成功")
}
// @Summary 删除用户角色
@@ -204,10 +209,11 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/role [delete]
// @Security Bearer
func (e *SysRole) DeleteSysRole(c *gin.Context) {
log := e.GetLogger(c)
func (e SysRole) DeleteSysRole(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.SysRoleById)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -217,7 +223,7 @@ func (e *SysRole) DeleteSysRole(c *gin.Context) {
err = control.Bind(c)
if err != nil {
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -227,21 +233,22 @@ func (e *SysRole) DeleteSysRole(c *gin.Context) {
err = s.RemoveSysRole(control)
if err != nil {
log.Error(err)
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
_, err = global.LoadPolicy(c)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
e.OK(c, control.GetId(), "删除成功")
e.OK(control.GetId(), "删除成功")
}
func (e *SysRole) UpdateRoleDataScope(c *gin.Context) {
log := e.GetLogger(c)
func (e SysRole) UpdateRoleDataScope(c *gin.Context) {
e.Context = c
log := e.GetLogger()
control := new(dto.RoleDataScopeReq)
db, err := e.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Error(err)
return
@@ -251,7 +258,7 @@ func (e *SysRole) UpdateRoleDataScope(c *gin.Context) {
err = c.Bind(control)
if err != nil {
log.Errorf("request bind error, %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
data := &system.SysRole{
@@ -265,8 +272,8 @@ func (e *SysRole) UpdateRoleDataScope(c *gin.Context) {
s.Log = log
err = s.UpdateDataScope(data)
if err != nil {
e.Error(c, http.StatusInternalServerError, err, "")
e.Error(http.StatusInternalServerError, err, "")
return
}
e.OK(c, nil, "操作成功")
e.OK(nil, "操作成功")
}
+12 -18
View File
@@ -5,10 +5,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/tools"
"go-admin/common/apis"
)
// @Summary 分页列表数据 / page list data
@@ -17,10 +16,11 @@ import (
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/columns/page [get]
func GetDBColumnList(c *gin.Context) {
log := apis.GetRequestLogger(c)
func (e *Gen) GetDBColumnList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
var data tools.DBColumns
var err error
var pageSize = 10
@@ -37,23 +37,17 @@ func GetDBColumnList(c *gin.Context) {
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
data.TableName = c.Request.FormValue("tableName")
pkg.Assert(data.TableName == "", "table name cannot be empty!", 500)
result, count, err := data.GetPage(db, pageSize, pageIndex)
pkg.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
if err != nil {
log.Errorf("GetPage error, %s", err.Error())
e.Error(500, err, "")
return
}
e.PageOK(result, count, pageIndex, pageSize, "查询成功")
}
+18 -20
View File
@@ -1,15 +1,15 @@
package tools
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/tools"
"go-admin/common/apis"
)
// @Summary 分页列表数据 / page list data
@@ -18,18 +18,21 @@ import (
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/tables/page [get]
func GetDBTableList(c *gin.Context) {
var res app.Response
func (e *Gen) GetDBTableList(c *gin.Context) {
//var res response.Response
var data tools.DBTables
var err error
var pageSize = 10
var pageIndex = 1
log := apis.GetRequestLogger(c)
e.Context = c
log := e.GetLogger()
if config.DatabaseConfig.Driver == "sqlite3" || config.DatabaseConfig.Driver == "postgres" {
res.Msg = "对不起,sqlite3 或 postgres 不支持代码生成!"
c.JSON(http.StatusOK, res.ReturnError(500))
err = errors.New("对不起,sqlite3 或 postgres 不支持代码生成!")
log.Warn(err)
e.Error(403, err, "")
//c.JSON(http.StatusOK, res.ReturnError(500))
return
}
@@ -44,21 +47,16 @@ func GetDBTableList(c *gin.Context) {
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
data.TableName = c.Request.FormValue("tableName")
result, count, err := data.GetPage(db, pageSize, pageIndex)
pkg.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
if err != nil {
log.Errorf("GetPage error, %s", err.Error())
e.Error(500, err, "")
return
}
e.PageOK(result, count, pageIndex, pageSize, "查询成功")
}
+184 -43
View File
@@ -3,43 +3,82 @@ package tools
import (
"bytes"
"net/http"
"strconv"
"text/template"
"time"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models"
"go-admin/app/admin/models/tools"
"go-admin/common/apis"
)
func Preview(c *gin.Context) {
log := apis.GetRequestLogger(c)
type Gen struct {
apis.Api
}
func (e Gen) Preview(c *gin.Context) {
e.Context = c
log := e.GetLogger()
table := tools.SysTables{}
id, err := pkg.StringToInt(c.Param("tableId"))
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
table.TableId = id
t1, err := template.ParseFiles("template/v4/model.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t2, err := template.ParseFiles("template/v4/no_actions/apis.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t3, err := template.ParseFiles("template/v4/js.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t4, err := template.ParseFiles("template/v4/vue.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t5, err := template.ParseFiles("template/v4/no_actions/router_check_role.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t6, err := template.ParseFiles("template/v4/dto.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t7, err := template.ParseFiles("template/v4/no_actions/service.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
@@ -67,22 +106,24 @@ func Preview(c *gin.Context) {
mp["template/router.go.template"] = b5.String()
mp["template/dto.go.template"] = b6.String()
mp["template/service.go.template"] = b7.String()
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
e.OK(mp, "")
}
func GenCodeV3(c *gin.Context) {
log := apis.GetRequestLogger(c)
func (e Gen) GenCode(c *gin.Context) {
e.Context = c
log := e.GetLogger()
table := tools.SysTables{}
id, err := pkg.StringToInt(c.Param("tableId"))
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
@@ -90,15 +131,42 @@ func GenCodeV3(c *gin.Context) {
tab, _ := table.Get(db)
if tab.IsActions == 1 {
ActionsGenV3(tab)
e.ActionsGen(c, tab)
} else {
NOActionsGenV3(tab)
e.NOActionsGen(c, tab)
}
app.OK(c, "", "Code generated successfully!")
e.OK("", "Code generated successfully!")
}
func NOActionsGenV3(tab tools.SysTables) {
func (e Gen) GenApiToFile(c *gin.Context) {
e.Context = c
log := e.GetLogger()
table := tools.SysTables{}
id, err := pkg.StringToInt(c.Param("tableId"))
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
table.TableId = id
tab, _ := table.Get(db)
e.genApiToFile(c, tab)
e.OK("", "Code generated successfully!")
}
func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
e.Context = c
log := e.GetLogger()
basePath := "template/v4/"
routerFile := basePath + "no_actions/router_check_role.go.template"
@@ -108,19 +176,47 @@ func NOActionsGenV3(tab tools.SysTables) {
}
t1, err := template.ParseFiles(basePath + "model.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t2, err := template.ParseFiles(basePath + "no_actions/apis.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t3, err := template.ParseFiles(routerFile)
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t4, err := template.ParseFiles(basePath + "js.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t5, err := template.ParseFiles(basePath + "vue.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t6, err := template.ParseFiles(basePath + "dto.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t7, err := template.ParseFiles(basePath + "no_actions/service.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
_ = pkg.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName)
_ = pkg.PathCreate("./app/" + tab.PackageName + "/models/")
@@ -153,7 +249,32 @@ func NOActionsGenV3(tab tools.SysTables) {
}
func ActionsGenV3(tab tools.SysTables) {
func (e Gen) genApiToFile(c *gin.Context, tab tools.SysTables) {
e.Context = c
log := e.GetLogger()
basePath := "template/"
t1, err := template.ParseFiles(basePath + "api_migrate.template")
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
i := strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
var b1 bytes.Buffer
err = t1.Execute(&b1, struct {
tools.SysTables
GenerateTime string
}{tab, i})
pkg.FileCreate(b1, "./cmd/migrate/migration/version-local/"+i+"_migrate.go")
}
func (e Gen) ActionsGen(c *gin.Context, tab tools.SysTables) {
e.Context = c
log := api.GetRequestLogger(c)
basePath := "template/v4/"
routerFile := basePath + "actions/router_check_role.go.template"
@@ -162,15 +283,35 @@ func ActionsGenV3(tab tools.SysTables) {
}
t1, err := template.ParseFiles(basePath + "model.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t3, err := template.ParseFiles(routerFile)
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t4, err := template.ParseFiles(basePath + "js.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t5, err := template.ParseFiles(basePath + "vue.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
t6, err := template.ParseFiles(basePath + "dto.go.template")
pkg.HasError(err, "", -1)
if err != nil {
log.Error(err)
e.Error(500, err, "")
return
}
_ = pkg.PathCreate("./app/" + tab.PackageName + "/models/")
_ = pkg.PathCreate("./app/" + tab.PackageName + "/router/")
@@ -196,9 +337,9 @@ func ActionsGenV3(tab tools.SysTables) {
pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
}
func GenMenuAndApi(c *gin.Context) {
log := apis.GetRequestLogger(c)
func (e Gen) GenMenuAndApi(c *gin.Context) {
log := api.GetRequestLogger(c)
e.Context = c
table := tools.SysTables{}
timeNow := pkg.GetCurrentTime()
id, err := pkg.StringToInt(c.Param("tableId"))
@@ -207,7 +348,7 @@ func GenMenuAndApi(c *gin.Context) {
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
@@ -437,5 +578,5 @@ func GenMenuAndApi(c *gin.Context) {
ADelete.UpdatedAt = timeNow
ADelete.MenuId, err = ADelete.Create(db)
app.OK(c, "", "数据生成成功!")
}
e.OK("", "数据生成成功!")
}
+97 -75
View File
@@ -6,24 +6,28 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"gorm.io/gorm"
"go-admin/app/admin/models/tools"
"go-admin/common/apis"
)
type SysTable struct {
apis.Api
}
// @Summary 分页列表数据
// @Description 生成表分页列表
// @Tags 工具 - 生成表
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sys/tables/page [get]
func GetSysTableList(c *gin.Context) {
log := apis.GetRequestLogger(c)
func (e *SysTable) GetSysTableList(c *gin.Context) {
e.Context = c
log := e.GetLogger()
var data tools.SysTables
var err error
var pageSize = 10
@@ -37,66 +41,63 @@ func GetSysTableList(c *gin.Context) {
pageIndex, err = pkg.StringToInt(index)
}
db, err := pkg.GetOrm(c)
db, err := e.GetOrm()
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
data.TBName = c.Request.FormValue("tableName")
data.TableComment = c.Request.FormValue("tableComment")
result, count, err := data.GetPage(db, pageSize, pageIndex)
pkg.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
if err != nil {
log.Errorf("GetPage error, %s", err.Error())
e.Error(500, err, "")
return
}
e.PageOK(result, count, pageIndex, pageSize, "查询成功")
}
// @Summary 获取配置
// @Description 获取JSON
// @Tags 工具 - 生成表
// @Param configKey path int true "configKey"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sys/tables/info/{tableId} [get]
// @Security Bearer
func GetSysTables(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := pkg.GetOrm(c)
func (e *SysTable) GetSysTables(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
var data tools.SysTables
data.TableId, _ = pkg.StringToInt(c.Param("tableId"))
result, err := data.Get(db)
pkg.HasError(err, "抱歉未找到相关信息", -1)
if err != nil {
log.Errorf("Get error, %s", err.Error())
e.Error(500, err, "")
return
}
var res app.Response
res.Data = result
mp := make(map[string]interface{})
mp["list"] = result.Columns
mp["info"] = result
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
e.OK(mp, "")
}
func GetSysTablesInfo(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := pkg.GetOrm(c)
func (e *SysTable) GetSysTablesInfo(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
@@ -105,33 +106,39 @@ func GetSysTablesInfo(c *gin.Context) {
data.TBName = c.Request.FormValue("tableName")
}
result, err := data.Get(db)
pkg.HasError(err, "抱歉未找到相关信息", -1)
if err != nil {
log.Errorf("Get error, %s", err.Error())
e.Error(500, err, "抱歉未找到相关信息")
return
}
var res app.Response
res.Data = result
mp := make(map[string]interface{})
mp["list"] = result.Columns
mp["info"] = result
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
e.OK(mp, "")
//res.Data = mp
//c.JSON(http.StatusOK, res.ReturnOK())
}
func GetSysTablesTree(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := pkg.GetOrm(c)
func (e *SysTable) GetSysTablesTree(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
var data tools.SysTables
result, err := data.GetTree(db)
pkg.HasError(err, "抱歉未找到相关信息", -1)
if err != nil {
log.Errorf("GetTree error, %s", err.Error())
e.Error(500, err, "抱歉未找到相关信息")
return
}
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
e.OK(result, "")
}
// @Summary 添加表结构
@@ -144,12 +151,13 @@ func GetSysTablesTree(c *gin.Context) {
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sys/tables/info [post]
// @Security Bearer
func InsertSysTable(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := pkg.GetOrm(c)
func (e *SysTable) InsertSysTable(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
@@ -157,13 +165,20 @@ func InsertSysTable(c *gin.Context) {
for i := 0; i < len(tablesList); i++ {
data, err := genTableInit(db, tablesList, i, c)
if err != nil {
log.Errorf("genTableInit error, %s", err.Error())
e.Error(500, err, "")
return
}
_, err = data.Create(db)
pkg.HasError(err, "", -1)
if err != nil {
log.Errorf("Create error, %s", err.Error())
e.Error(500, err, "")
return
}
}
var res app.Response
res.Msg = "添加成功!"
c.JSON(http.StatusOK, res.ReturnOK())
e.OK(nil, "添加成功")
}
@@ -172,10 +187,13 @@ func genTableInit(tx *gorm.DB, tablesList []string, i int, c *gin.Context) (tool
var dbTable tools.DBTables
var dbColumn tools.DBColumns
data.TBName = tablesList[i]
data.CreateBy = user.GetUserIdStr(c)
data.CreateBy = 0
dbTable.TableName = data.TBName
dbtable, err := dbTable.Get(tx)
if err != nil {
return data, err
}
dbColumn.TableName = data.TBName
tablenamelist := strings.Split(dbColumn.TableName, "_")
@@ -191,7 +209,7 @@ func genTableInit(tx *gorm.DB, tablesList []string, i int, c *gin.Context) (tool
data.Crud = true
dbcolumn, err := dbColumn.GetList(tx)
data.CreateBy = user.GetUserIdStr(c)
data.CreateBy = 0
data.TableComment = dbtable.TableComment
if dbtable.TableComment == "" {
data.TableComment = data.ClassName
@@ -277,27 +295,28 @@ func genTableInit(tx *gorm.DB, tablesList []string, i int, c *gin.Context) (tool
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sys/tables/info [put]
// @Security Bearer
func UpdateSysTable(c *gin.Context) {
func (e *SysTable) UpdateSysTable(c *gin.Context) {
var data tools.SysTables
err := c.Bind(&data)
pkg.HasError(err, "数据解析失败", 500)
log := apis.GetRequestLogger(c)
db, err := pkg.GetOrm(c)
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
data.UpdateBy = user.GetUserIdStr(c)
data.UpdateBy = 0
result, err := data.Update(db)
pkg.HasError(err, "", -1)
var res app.Response
res.Data = result
res.Msg = "修改成功"
c.JSON(http.StatusOK, res.ReturnOK())
if err != nil {
log.Errorf("Update error, %s", err.Error())
e.Error(500, err, "")
return
}
e.OK(result, "修改成功")
}
// @Summary 删除表结构
@@ -307,20 +326,23 @@ func UpdateSysTable(c *gin.Context) {
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/sys/tables/info/{tableId} [delete]
func DeleteSysTables(c *gin.Context) {
log := apis.GetRequestLogger(c)
db, err := pkg.GetOrm(c)
func (e *SysTable) DeleteSysTables(c *gin.Context) {
e.Context = c
log := e.GetLogger()
db, err := e.GetOrm()
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
app.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
var data tools.SysTables
IDS := pkg.IdsStrToIdsIntGroup("tableId", c)
_, err = data.BatchDelete(db, IDS)
pkg.HasError(err, "删除失败", 500)
var res app.Response
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())
if err != nil {
log.Errorf("BatchDelete error, %s", err.Error())
e.Error(500, err, "删除失败")
return
}
e.OK(nil, "删除成功")
}
-87
View File
@@ -1,87 +0,0 @@
package gorm
import (
"go-admin/app/admin/models/system"
"gorm.io/gorm"
)
func InitData(db *gorm.DB) {
list := []system.CasbinRule{
{"p", "admin", "/api/v1/menulist", "GET", "", "", ""},
{"p", "admin", "/api/v1/menu", "POST", "", "", ""},
{"p", "admin", "/api/v1/dict/databytype/", "GET", "", "", ""},
{"p", "admin", "/api/v1/menu", "PUT", "", "", ""},
{"p", "admin", "/api/v1/menu/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/sysUserList", "GET", "", "", ""},
{"p", "admin", "/api/v1/sysUser/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/sysUser/", "GET", "", "", ""},
{"p", "admin", "/api/v1/sysUser", "POST", "", "", ""},
{"p", "admin", "/api/v1/sysUser", "PUT", "", "", ""},
{"p", "admin", "/api/v1/sysUser/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/user/profile", "GET", "", "", ""},
{"p", "admin", "/api/v1/rolelist", "GET", "", "", ""},
{"p", "admin", "/api/v1/role/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/role", "POST", "", "", ""},
{"p", "admin", "/api/v1/role", "PUT", "", "", ""},
{"p", "admin", "/api/v1/role/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/configList", "GET", "", "", ""},
{"p", "admin", "/api/v1/config/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/config", "POST", "", "", ""},
{"p", "admin", "/api/v1/config", "PUT", "", "", ""},
{"p", "admin", "/api/v1/config/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/menurole", "GET", "", "", ""},
{"p", "admin", "/api/v1/roleMenuTreeselect/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/menuTreeselect", "GET", "", "", ""},
{"p", "admin", "/api/v1/rolemenu", "GET", "", "", ""},
{"p", "admin", "/api/v1/rolemenu", "POST", "", "", ""},
{"p", "admin", "/api/v1/rolemenu/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/deptList", "GET", "", "", ""},
{"p", "admin", "/api/v1/dept/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/dept", "POST", "", "", ""},
{"p", "admin", "/api/v1/dept", "PUT", "", "", ""},
{"p", "admin", "/api/v1/dept/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/dict/datalist", "GET", "", "", ""},
{"p", "admin", "/api/v1/dict/data/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/dict/databytype/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/dict/data", "POST", "", "", ""},
{"p", "admin", "/api/v1/dict/data/", "PUT", "", "", ""},
{"p", "admin", "/api/v1/dict/data/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/dict/typelist", "GET", "", "", ""},
{"p", "admin", "/api/v1/dict/type/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/dict/type", "POST", "", "", ""},
{"p", "admin", "/api/v1/dict/type", "PUT", "", "", ""},
{"p", "admin", "/api/v1/dict/type/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/postlist", "GET", "", "", ""},
{"p", "admin", "/api/v1/post/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/post", "POST", "", "", ""},
{"p", "admin", "/api/v1/post", "PUT", "", "", ""},
{"p", "admin", "/api/v1/post/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/menu/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/menuids", "GET", "", "", ""},
{"p", "admin", "/api/v1/loginloglist", "GET", "", "", ""},
{"p", "admin", "/api/v1/loginlog/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/operloglist", "GET", "", "", ""},
{"p", "admin", "/api/v1/getinfo", "GET", "", "", ""},
{"p", "admin", "/api/v1/roledatascope", "PUT", "", "", ""},
{"p", "admin", "/api/v1/roleDeptTreeselect/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/deptTree", "GET", "", "", ""},
{"p", "admin", "/api/v1/configKey/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/logout", "POST", "", "", ""},
{"p", "admin", "/api/v1/user/avatar", "POST", "", "", ""},
{"p", "admin", "/api/v1/user/pwd", "PUT", "", "", ""},
{"p", "admin", "/api/v1/dict/typeoptionselect", "GET", "", "", ""},
{"p", "admin", "/api/v1/sysjobList", "GET", "", "", ""},
{"p", "admin", "/api/v1/sysjob/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/sysjob", "POST", "", "", ""},
{"p", "admin", "/api/v1/sysjob", "PUT", "", "", ""},
{"p", "admin", "/api/v1/sysjob/:id", "DELETE", "", "", ""},
{"p", "admin", "/api/v1/syssettingList", "GET", "", "", ""},
{"p", "admin", "/api/v1/syssetting/:id", "GET", "", "", ""},
{"p", "admin", "/api/v1/syssetting", "POST", "", "", ""},
{"p", "admin", "/api/v1/syssetting", "PUT", "", "", ""},
{"p", "admin", "/api/v1/syssetting/:id", "DELETE", "", "", ""},
}
db.Table("sys_casbin_rule").Create(list)
}
+2 -1
View File
@@ -3,6 +3,7 @@ package models
import (
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"go-admin/common/models"
"gorm.io/gorm"
@@ -33,7 +34,7 @@ type Menu struct {
RoleId int `gorm:"-"`
Children []Menu `json:"children" gorm:"-"`
IsSelect bool `json:"is_select" gorm:"-"`
BaseModel
models.ModelTime
}
func (Menu) TableName() string {
+4 -3
View File
@@ -1,5 +1,7 @@
package models
import "go-admin/common/models"
type SysRole struct {
RoleId int `json:"roleId" gorm:"primaryKey;autoIncrement"` // 角色编码
RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称
@@ -7,12 +9,11 @@ type SysRole struct {
RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码
RoleSort int `json:"roleSort" gorm:""` //角色排序
Flag string `json:"flag" gorm:"size:128;"` //
CreateBy string `json:"createBy" gorm:"size:128;"` //
UpdateBy string `json:"updateBy" gorm:"size:128;"` //
Remark string `json:"remark" gorm:"size:255;"` //备注
Admin bool `json:"admin" gorm:"size:4;"`
DataScope string `json:"dataScope" gorm:"size:128;"`
BaseModel
models.ModelTime
models.ControlBy
Params string `json:"params" gorm:"-"`
MenuIds []int `json:"menuIds" gorm:"-"`
-231
View File
@@ -1,231 +0,0 @@
package models
import (
"gorm.io/gorm"
)
type RoleMenu struct {
RoleId int `gorm:""`
MenuId int `gorm:""`
RoleName string `gorm:"size:128)"`
CreateBy string `gorm:"size:128)"`
UpdateBy string `gorm:"size:128)"`
}
func (RoleMenu) TableName() string {
return "sys_role_menu"
}
type MenuPath struct {
Path string `json:"path"`
}
//func (rm *RoleMenu) Get(tx *gorm.DB) ([]RoleMenu, error) {
// var r []RoleMenu
// table := tx.Table("sys_role_menu")
// if rm.RoleId != 0 {
// table = table.Where("role_id = ?", rm.RoleId)
//
// }
// if err := table.Find(&r).Error; err != nil {
// return nil, err
// }
// return r, nil
//}
func (rm *RoleMenu) GetPermis(tx *gorm.DB) ([]string, error) {
var r []Menu
table := tx.Select("sys_menu.permission").Table("sys_menu").Joins("left join sys_role_menu on sys_menu.menu_id = sys_role_menu.menu_id")
table = table.Where("role_id = ?", rm.RoleId)
table = table.Where("sys_menu.menu_type in('F','C')")
if err := table.Find(&r).Error; err != nil {
return nil, err
}
var list []string
for i := 0; i < len(r); i++ {
list = append(list, r[i].Permission)
}
return list, nil
}
func (rm *RoleMenu) GetIDS(tx *gorm.DB) ([]MenuPath, error) {
var r []MenuPath
table := tx.Select("sys_menu.path").Table("sys_role_menu")
table = table.Joins("left join sys_role on sys_role.role_id=sys_role_menu.role_id")
table = table.Joins("left join sys_menu on sys_menu.id=sys_role_menu.menu_id")
table = table.Where("sys_role.role_name = ? and sys_menu.type=1", rm.RoleName)
if err := table.Find(&r).Error; err != nil {
return nil, err
}
return r, nil
}
//func (rm *RoleMenu) DeleteRoleMenu(roleId int) (bool, error) {
// tx := orm.Eloquent.Begin()
// defer func() {
// if r := recover(); r != nil {
// tx.Rollback()
// }
// }()
//
// if err := tx.Error; err != nil {
// return false, err
// }
//
// if err := tx.Table("sys_role_dept").Where("role_id = ?", roleId).Delete(&rm).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// if err := tx.Table("sys_role_menu").Where("role_id = ?", roleId).Delete(&rm).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// var role SysRole
// if err := tx.Table("sys_role").Where("role_id = ?", roleId).First(&role).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// sql3 := "delete from sys_casbin_rule where v0= '" + role.RoleKey + "';"
// if err := tx.Exec(sql3).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// if err := tx.Commit().Error; err != nil {
// return false, err
// }
//
// return true, nil
//
//}
// 该方法即将弃用
//func (rm *RoleMenu) BatchDeleteRoleMenu(roleIds []int) (bool, error) {
// tx := orm.Eloquent.Begin()
// defer func() {
// if r := recover(); r != nil {
// tx.Rollback()
// }
// }()
//
// if err := tx.Error; err != nil {
// return false, err
// }
//
// if err := tx.Table("sys_role_menu").Where("role_id in (?)", roleIds).Delete(&rm).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// var role []SysRole
// if err := tx.Table("sys_role").Where("role_id in (?)", roleIds).Find(&role).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// sql := ""
// for i := 0; i < len(role); i++ {
// sql += "delete from sys_casbin_rule where v0= '" + role[i].RoleName + "';"
// }
// if err := tx.Exec(sql).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// if err := tx.Commit().Error; err != nil {
// return false, err
// }
// return true, nil
//
//}
//func (rm *RoleMenu) Insert(roleId int, menuId []int) (bool, error) {
// var (
// role SysRole
// menu []Menu
// casbinRuleQueue []system.CasbinRule // casbinRule 待插入队列
// )
//
// // 开始事务
// tx := orm.Eloquent.Begin()
// defer func() {
// if r := recover(); r != nil {
// tx.Rollback()
// }
// }()
//
// if err := tx.Error; err != nil {
// return false, err
// }
//
// // 在事务中做一些数据库操作(从这一点使用'tx',而不是'db')
// if err := tx.Table("sys_role").Where("role_id = ?", roleId).First(&role).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// if err := tx.Table("sys_menu").Where("menu_id in (?)", menuId).Find(&menu).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// //ORM不支持批量插入所以需要拼接 sql 串
// sysRoleMenuSql := "INSERT INTO `sys_role_menu` (`role_id`,`menu_id`,`role_name`) VALUES "
// casbinRuleSql := "INSERT INTO `sys_casbin_rule` (`p_type`,`v0`,`v1`,`v2`) VALUES "
//
// for i, m := range menu {
// // 拼装'role_menu'表批量插入SQL语句
// sysRoleMenuSql += fmt.Sprintf("(%d,%d,'%s')", role.RoleId, m.MenuId, role.RoleKey)
// if i == len(menu)-1 {
// sysRoleMenuSql += ";" //最后一条数据 以分号结尾
// } else {
// sysRoleMenuSql += ","
// }
// if m.MenuType == "A" {
// // 加入队列
// casbinRuleQueue = append(casbinRuleQueue,
// system.CasbinRule{
// V0: role.RoleKey,
// V1: m.Path,
// V2: m.Action,
// })
// }
// }
// // 执行批量插入sys_role_menu
// if err := tx.Exec(sysRoleMenuSql).Error; err != nil {
// tx.Rollback()
// return false, err
// }
//
// // 拼装'sys_casbin_rule'批量插入SQL语句
// // TODO: casbinRuleQueue队列不为空时才会拼装,否则直接忽略不执行'for'循环
// for i, v := range casbinRuleQueue {
// casbinRuleSql += fmt.Sprintf("('p','%s','%s','%s')", v.V0, v.V1, v.V2)
// if i == len(casbinRuleQueue)-1 {
// casbinRuleSql += ";"
// } else {
// casbinRuleSql += ","
// }
// }
// // 执行批量插入sys_casbin_rule
// if len(casbinRuleQueue) > 0 {
// if err := tx.Exec(casbinRuleSql).Error; err != nil {
// tx.Rollback()
// return false, err
// }
// }
//
// if err := tx.Commit().Error; err != nil {
// return false, err
// }
// return true, nil
//}
//func (rm *RoleMenu) Delete(RoleId string, MenuID string) (bool, error) {
// rm.RoleId, _ = tools.StringToInt(RoleId)
// table := orm.Eloquent.Table("sys_role_menu").Where("role_id = ?", RoleId)
// if MenuID != "" {
// table = table.Where("menu_id = ?", MenuID)
// }
// if err := table.Delete(&rm).Error; err != nil {
// return false, err
// }
// return true, nil
//
//}
@@ -8,8 +8,8 @@ type SysCategory struct {
models.Model
Name string `json:"name" gorm:"type:varchar(255);comment:名称"` //
Img string `json:"img" gorm:"type:varchar(255);comment:图标"` //
Sort string `json:"sort" gorm:"type:int(4);comment:排序"` //
Status string `json:"status" gorm:"type:int(1);comment:状态"` //
Sort int `json:"sort" gorm:"type:int(4);comment:排序"` //
Status int `json:"status" gorm:"type:int(1);comment:状态"` //
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"` //
models.ControlBy
models.ModelTime
@@ -26,4 +26,4 @@ func (e *SysCategory) Generate() models.ActiveRecord {
func (e *SysCategory) GetId() interface{} {
return e.Id
}
}
@@ -2,18 +2,15 @@ package models
import (
"go-admin/common/models"
"time"
)
type SysChinaAreaData struct {
models.Model
models.ControlBy
PId string `json:"pId" gorm:"type:int(11);comment:上级编码"`
Name string `json:"name" gorm:"type:varchar(128);comment:名称"`
CreateTime time.Time `json:"createTime" gorm:"type:timestamp;comment:CreateTime"`
UpdateTime time.Time `json:"updateTime" gorm:"type:timestamp;comment:UpdateTime"`
DeleteTime time.Time `json:"deleteTime" gorm:"type:timestamp;comment:DeleteTime"`
models.ControlBy
models.ModelTime
}
func (SysChinaAreaData) TableName() string {
@@ -27,4 +24,4 @@ func (e *SysChinaAreaData) Generate() models.ActiveRecord {
func (e *SysChinaAreaData) GetId() interface{} {
return e.Id
}
}
+33
View File
@@ -0,0 +1,33 @@
package models
import (
"go-admin/common/models"
)
type SysContent struct {
models.Model
CateId int `json:"cateId" gorm:"type:int(11);comment:分类id"`
Name string `json:"name" gorm:"type:varchar(255);comment:名称"`
Status int `json:"status" gorm:"type:int(1);comment:状态"`
Img string `json:"img" gorm:"type:varchar(255);comment:图片"`
Content string `json:"content" gorm:"type:text;comment:内容"`
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"`
Sort int `json:"sort" gorm:"type:int(4);comment:排序"`
models.ControlBy
models.ModelTime
}
// TableName
func (SysContent) TableName() string {
return "sys_content"
}
// Generate
func (e *SysContent) Generate() models.ActiveRecord {
o := *e
return &o
}
func (e *SysContent) GetId() interface{} {
return e.Id
}
@@ -3,7 +3,6 @@ package models
import (
"go-admin/common/models"
"gorm.io/gorm"
"strconv"
)
type SysJob struct {
@@ -18,9 +17,8 @@ type SysJob struct {
Concurrent int `json:"concurrent" gorm:"size:1;"` // 是否并发
Status int `json:"status" gorm:"size:1;"` // 状态
EntryId int `json:"entry_id" gorm:"size:11;"` // job启动时返回的id
CreateBy string `json:"createBy" gorm:"size:128;"` //
UpdateBy string `json:"updateBy" gorm:"size:128;"` //
BaseModel
models.ControlBy
models.ModelTime
DataScope string `json:"dataScope" gorm:"-"`
}
@@ -39,11 +37,11 @@ func (e *SysJob) GetId() interface{} {
}
func (e *SysJob) SetCreateBy(createBy int) {
e.CreateBy = strconv.Itoa(int(createBy))
e.CreateBy = createBy
}
func (e *SysJob) SetUpdateBy(updateBy int) {
e.UpdateBy = strconv.Itoa(int(updateBy))
e.UpdateBy = updateBy
}
// 创建SysJob
-137
View File
@@ -1,137 +0,0 @@
package models
import (
"go-admin/common/models"
)
type SysContent struct {
Id int `json:"id" gorm:"type:int(11);primaryKey;autoIncrement"` // id
CateId string `json:"cateId" gorm:"type:int(11);comment:分类id"`
Name string `json:"name" gorm:"type:varchar(255);comment:名称"`
Status string `json:"status" gorm:"type:int(1);comment:状态"`
Img string `json:"img" gorm:"type:varchar(255);comment:图片"`
Content string `json:"content" gorm:"type:text;comment:内容"`
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"`
Sort string `json:"sort" gorm:"type:int(4);comment:排序"`
models.ControlBy
models.ModelTime
}
func (SysContent) TableName() string {
return "sys_content"
}
func (e *SysContent) Generate() models.ActiveRecord {
o := *e
return &o
}
func (e *SysContent) GetId() interface{} {
return e.Id
}
//// 创建SysContent
//func (e *SysContent) Create() (SysContent, error) {
// var doc SysContent
// result := orm.Eloquent.Table(e.TableName()).Create(&e)
// if result.Error != nil {
// err := result.Error
// return doc, err
// }
// doc = *e
// return doc, nil
//}
//
//// 获取SysContent
//func (e *SysContent) Get() (SysContent, error) {
// var doc SysContent
// table := orm.Eloquent.Table(e.TableName())
//
// if e.Id != 0 {
// table = table.Where("id = ?", e.Id)
// }
//
// if e.CateId != "" {
// table = table.Where("cate_id = ?", e.CateId)
// }
//
// if e.Name != "" {
// table = table.Where("name like ?", "%"+e.Name+"%")
// }
//
// if e.Status != "" {
// table = table.Where("status = ?", e.Status)
// }
//
// if err := table.First(&doc).Error; err != nil {
// return doc, err
// }
// return doc, nil
//}
//
//// 获取SysContent带分页
//func (e *SysContent) GetPage(pageSize int, pageIndex int) ([]SysContent, int, error) {
// var doc []SysContent
//
// table := orm.Eloquent.Table(e.TableName())
//
// if e.CateId != "" {
// table = table.Where("cate_id = ?", e.CateId)
// }
//
// if e.Name != "" {
// table = table.Where("name like ?", "%"+e.Name+"%")
// }
//
// if e.Status != "" {
// table = table.Where("status = ?", e.Status)
// }
//
// // 数据权限控制(如果不需要数据权限请将此处去掉)
// dataPermission := new(system.DataPermission)
// dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
// table, err := dataPermission.GetDataScope(e.TableName(), table)
// if err != nil {
// return nil, 0, err
// }
// var count int64
//
// if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
// return nil, 0, err
// }
// //table.Where("`deleted_at` IS NULL").Count(&count)
// return doc, int(count), nil
//}
//
//// 更新SysContent
//func (e *SysContent) Update(id int) (update SysContent, err error) {
// if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).First(&update).Error; err != nil {
// return
// }
//
// //参数1:是要修改的数据
// //参数2:是修改的数据
// if err = orm.Eloquent.Table(e.TableName()).Model(&update).Where("id = ?", id).Updates(&e).Error; err != nil {
// return
// }
// return
//}
//
//// 删除SysContent
//func (e *SysContent) Delete(id int) (success bool, err error) {
// if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).Delete(&SysContent{}).Error; err != nil {
// success = false
// return
// }
// success = true
// return
//}
//
////批量删除
//func (e *SysContent) BatchDelete(id []int) (Result bool, err error) {
// if err = orm.Eloquent.Table(e.TableName()).Where("id in (?)", id).Delete(&SysContent{}).Error; err != nil {
// return
// }
// Result = true
// return
//}
+4 -3
View File
@@ -2,18 +2,19 @@ package system
import (
"fmt"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/casbin/casbin/v2"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
"go-admin/common/models"
)
type RoleMenu struct {
RoleId int `gorm:""`
MenuId int `gorm:""`
RoleName string `gorm:"size:128"`
CreateBy string `gorm:"size:128"`
UpdateBy string `gorm:"size:128"`
models.ControlBy
}
func (RoleMenu) TableName() string {
+3 -2
View File
@@ -9,8 +9,9 @@ type SysConfig struct {
ConfigName string `json:"configName" gorm:"type:varchar(128);comment:ConfigName"` //
ConfigKey string `json:"configKey" gorm:"type:varchar(128);comment:ConfigKey"` //
ConfigValue string `json:"configValue" gorm:"type:varchar(255);comment:ConfigValue"` //
ConfigType string `json:"configType" gorm:"type:varchar(64);comment:ConfigType"` //
Remark string `json:"remark" gorm:"type:varchar(128);comment:Remark"` //
ConfigType string `json:"configType" gorm:"type:varchar(64);comment:ConfigType"`
IsFrontend int `json:"isFrontend" gorm:"type:varchar(64);comment:是否前台"` //
Remark string `json:"remark" gorm:"type:varchar(128);comment:Remark"` //
models.ControlBy
models.ModelTime
}
+37 -2
View File
@@ -1,9 +1,15 @@
package system
import (
"go-admin/common/models"
"encoding/json"
"errors"
"time"
log "github.com/go-admin-team/go-admin-core/logger"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/storage"
"go-admin/common/models"
)
type SysLoginLog struct {
@@ -35,3 +41,32 @@ func (e *SysLoginLog) Generate() models.ActiveRecord {
func (e *SysLoginLog) GetId() interface{} {
return e.Id
}
// SaveLoginLog 从队列中获取登录日志
func SaveLoginLog(message storage.Messager) (err error) {
//准备db
db := sdk.Runtime.GetDbByKey(message.GetPrefix())
if db == nil {
err = errors.New("db not exist")
log.Errorf("host[%s]'s %s", message.GetPrefix(), err.Error())
return err
}
var rb []byte
rb, err = json.Marshal(message.GetValues())
if err != nil {
log.Errorf("json Marshal error, %s", err.Error())
return err
}
var l SysLoginLog
err = json.Unmarshal(rb, &l)
if err != nil {
log.Errorf("json Unmarshal error, %s", err.Error())
return err
}
err = db.Create(&l).Error
if err != nil {
log.Errorf("db create error, %s", err.Error())
return err
}
return nil
}
+42 -2
View File
@@ -1,9 +1,15 @@
package system
import (
"go-admin/common/models"
"encoding/json"
"errors"
"time"
log "github.com/go-admin-team/go-admin-core/logger"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/storage"
"go-admin/common/models"
)
type SysOperaLog struct {
@@ -43,3 +49,37 @@ func (e *SysOperaLog) Generate() models.ActiveRecord {
func (e *SysOperaLog) GetId() interface{} {
return e.Id
}
// SaveOperaLog 从队列中获取操作日志
func SaveOperaLog(message storage.Messager) (err error) {
//准备db
db := sdk.Runtime.GetDbByKey(message.GetPrefix())
if db == nil {
err = errors.New("db not exist")
log.Errorf("host[%s]'s %s", message.GetPrefix(), err.Error())
return err
}
var rb []byte
rb, err = json.Marshal(message.GetValues())
if err != nil {
log.Errorf("json Marshal error, %s", err.Error())
return err
}
var l SysOperaLog
err = json.Unmarshal(rb, &l)
if err != nil {
log.Errorf("json Unmarshal error, %s", err.Error())
return err
}
if l.Title == "" {
m := &SysMenu{}
db.Model(m).Select("Title").Where("action = ?", l.Method).Where("path = ?", message.GetValues()["_fullPath"]).First(m)
l.Title = m.Title
}
err = db.Create(&l).Error
if err != nil {
log.Errorf("db create error, %s", err.Error())
return err
}
return nil
}
+4 -2
View File
@@ -41,8 +41,8 @@ type SysColumns struct {
FkCol []SysColumns `gorm:"-" json:"fkCol"`
FkLabelId string `gorm:"" json:"fkLabelId"`
FkLabelName string `gorm:"size:255;" json:"fkLabelName"`
CreateBy string `gorm:"column:create_by;size:128;" json:"createBy"`
UpdateBy string `gorm:"column:update_By;size:128;" json:"updateBy"`
CreateBy int `gorm:"column:create_by;size:20;" json:"createBy"`
UpdateBy int `gorm:"column:update_By;size:20;" json:"updateBy"`
models.BaseModel
}
@@ -66,6 +66,7 @@ func (e *SysColumns) GetList(tx *gorm.DB) ([]SysColumns, error) {
func (e *SysColumns) Create(tx *gorm.DB) (SysColumns, error) {
var doc SysColumns
e.CreateBy = 0
result := tx.Table("sys_columns").Create(&e)
if result.Error != nil {
err := result.Error
@@ -82,6 +83,7 @@ func (e *SysColumns) Update(tx *gorm.DB) (update SysColumns, err error) {
//参数1:是要修改的数据
//参数2:是修改的数据
e.UpdateBy = 0
if err = tx.Table("sys_columns").Model(&update).Updates(&e).Error; err != nil {
return
}
+4 -2
View File
@@ -34,8 +34,8 @@ type SysTables struct {
IsLogicalDelete string `gorm:"size:1;" json:"isLogicalDelete"`
LogicalDelete bool `gorm:"size:1;" json:"logicalDelete"`
LogicalDeleteColumn string `gorm:"size:128;" json:"logicalDeleteColumn"`
CreateBy string `gorm:"size:128;" json:"createBy"`
UpdateBy string `gorm:"size:128;" json:"updateBy"`
CreateBy int `gorm:"size:128;" json:"createBy"`
UpdateBy int `gorm:"size:128;" json:"updateBy"`
DataScope string `gorm:"-" json:"dataScope"`
Params Params `gorm:"-" json:"params"`
Columns []SysColumns `gorm:"-" json:"columns"`
@@ -134,6 +134,7 @@ func (e *SysTables) GetTree(tx *gorm.DB) ([]SysTables, error) {
func (e *SysTables) Create(tx *gorm.DB) (SysTables, error) {
var doc SysTables
e.CreateBy = 0
result := tx.Table("sys_tables").Create(&e)
if result.Error != nil {
err := result.Error
@@ -156,6 +157,7 @@ func (e *SysTables) Update(tx *gorm.DB) (update SysTables, err error) {
//参数1:是要修改的数据
//参数2:是修改的数据
e.UpdateBy = 0
if err = tx.Table("sys_tables").Where("table_id = ?", e.TableId).Updates(&e).Error; err != nil {
return
}
+10 -10
View File
@@ -1,18 +1,17 @@
package router
import (
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"os"
"github.com/gin-gonic/gin"
log "github.com/go-admin-team/go-admin-core/logger"
"go-admin/app/admin/middleware"
"go-admin/app/admin/middleware/handler"
common "go-admin/common/middleware"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/api"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
common "go-admin/common/middleware"
"go-admin/common/middleware/handler"
)
// InitRouter 路由初始化,不要怀疑,这里用到了
@@ -35,10 +34,11 @@ func InitRouter() {
}
r.Use(common.Sentinel()).
Use(common.RequestId(pkg.TrafficKey))
middleware.InitMiddleware(r)
Use(common.RequestId(pkg.TrafficKey)).
Use(api.SetRequestLogger)
common.InitMiddleware(r)
// the jwt middleware
authMiddleware, err := middleware.AuthInit()
authMiddleware, err := common.AuthInit()
if err != nil {
log.Fatalf("JWT Init Error, %s", err.Error())
}
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysChinaAreaDataRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_china_area_data.SysChinaAreaData{}
api := sys_china_area_data.SysChinaAreaData{}
r := v1.Group("/sys_china_area_data").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysChinaAreaDataList)
+10 -4
View File
@@ -13,19 +13,25 @@ func init() {
// 需认证的路由代码
func registerSysConfigRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := sys_config.SysConfig{}
r := v1.Group("/config").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
api := &sys_config.SysConfig{}
r.GET("", api.GetSysConfigList)
r.GET("/:id", api.GetSysConfig)
r.POST("", api.InsertSysConfig)
r.PUT("/:id", api.UpdateSysConfig)
r.DELETE("/:id", api.DeleteSysConfig)
r.DELETE("", api.DeleteSysConfig)
}
r1 := v1.Group("/configKey").Use(authMiddleware.MiddlewareFunc())
{
api := &sys_config.SysConfig{}
r1.GET("/:configKey", api.GetSysConfigByKEYForService)
}
}
r2 := v1.Group("/app-config")
{
r2.GET("", api.GetSysConfigBySysApp)
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysDeptRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_dept.SysDept{}
api := sys_dept.SysDept{}
r := v1.Group("/dept").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysDeptList)
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysFileDirRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_file.SysFileDir{}
api := sys_file.SysFileDir{}
r := v1.Group("/sysfiledir").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysFileDirList)
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysFileInfoRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_file.SysFileInfo{}
api := sys_file.SysFileInfo{}
r := v1.Group("/sysfileinfo").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysFileInfoList)
+1 -1
View File
@@ -31,7 +31,7 @@ func registerSysJobRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlew
r.PUT("", actions.PermissionAction(), actions.UpdateAction(new(dto.SysJobControl)))
r.DELETE("", actions.PermissionAction(), actions.DeleteAction(new(dto.SysJobById)))
}
sysJob := &sys_job.SysJob{}
sysJob := sys_job.SysJob{}
v1.GET("/job/remove/:id", sysJob.RemoveJobForService)
v1.GET("/job/start/:id", sysJob.StartJobForService)
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysLoginLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_login_log.SysLoginLog{}
api := sys_login_log.SysLoginLog{}
r := v1.Group("/sys-login-log").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysLoginLogList)
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysMenuRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_menu.SysMenu{}
api := sys_menu.SysMenu{}
//menu := v1.Group("/menu").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
//{
// menu.GET("/:id", system.GetMenu)
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysOperaLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_opera_log.SysOperaLog{}
api := sys_opera_log.SysOperaLog{}
r := v1.Group("/sys-opera-log").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysOperaLogList)
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSyPostRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_post.SysPost{}
api := sys_post.SysPost{}
r := v1.Group("/post").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysPostList)
+1 -1
View File
@@ -13,7 +13,7 @@ func init() {
// 需认证的路由代码
func registerSysRoleRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_role.SysRole{}
api := sys_role.SysRole{}
r := v1.Group("/role").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
{
r.GET("", api.GetSysRoleList)
+49 -33
View File
@@ -1,23 +1,24 @@
package router
import (
"go-admin/app/admin/apis/system/sys_menu"
middleware2 "go-admin/common/middleware"
"mime"
"github.com/gin-gonic/gin"
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
"github.com/go-admin-team/go-admin-core/sdk/pkg/ws"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
"go-admin/app/admin/apis/monitor"
"go-admin/app/admin/apis/public"
"go-admin/app/admin/apis/system"
"go-admin/app/admin/apis/system/dict"
. "go-admin/app/admin/apis/tools"
"go-admin/app/admin/middleware/handler"
"go-admin/app/admin/apis/system/sys_dept"
"go-admin/app/admin/apis/system/sys_menu"
"go-admin/app/admin/apis/tools"
"go-admin/common/middleware"
"go-admin/common/middleware/handler"
_ "go-admin/docs"
"github.com/gin-gonic/gin"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
)
func InitSysRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.RouterGroup {
@@ -45,7 +46,10 @@ func sysBaseRouter(r *gin.RouterGroup) {
}
func sysStaticFileRouter(r *gin.RouterGroup) {
mime.AddExtensionType(".js", "application/javascript")
err := mime.AddExtensionType(".js", "application/javascript")
if err != nil {
return
}
r.Static("/static", "./static")
r.Static("/form-generator", "./static/form-generator")
}
@@ -57,12 +61,18 @@ func sysSwaggerRouter(r *gin.RouterGroup) {
func sysNoCheckRoleRouter(r *gin.RouterGroup) {
v1 := r.Group("/api/v1")
v1.GET("/monitor/server", monitor.ServerInfo)
v1.GET("/getCaptcha", system.GenerateCaptchaHandler)
v1.GET("/gen/preview/:tableId", Preview)
v1.GET("/gen/toproject/:tableId", GenCodeV3)
v1.GET("/gen/todb/:tableId", GenMenuAndApi)
v1.GET("/gen/tabletree", GetSysTablesTree)
m := monitor.Monitor{}
v1.GET("/monitor/server", m.ServerInfo)
sys := system.System{}
v1.GET("/getCaptcha", sys.GenerateCaptchaHandler)
gen := tools.Gen{}
v1.GET("/gen/preview/:tableId", gen.Preview)
v1.GET("/gen/toproject/:tableId", gen.GenCode)
v1.GET("/gen/apitofile/:tableId", gen.GenApiToFile)
v1.GET("/gen/todb/:tableId", gen.GenMenuAndApi)
sysTable := tools.SysTable{}
v1.GET("/gen/tabletree", sysTable.GetSysTablesTree)
registerDBRouter(v1)
registerSysTableRouter(v1)
@@ -73,34 +83,36 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
func registerDBRouter(api *gin.RouterGroup) {
db := api.Group("/db")
{
db.GET("/tables/page", GetDBTableList)
db.GET("/columns/page", GetDBColumnList)
gen := tools.Gen{}
db.GET("/tables/page", gen.GetDBTableList)
db.GET("/columns/page", gen.GetDBColumnList)
}
}
func registerSysTableRouter(v1 *gin.RouterGroup) {
systables := v1.Group("/sys/tables")
{
systables.GET("/page", GetSysTableList)
sysTable := tools.SysTable{}
systables.GET("/page", sysTable.GetSysTableList)
tablesinfo := systables.Group("/info")
{
tablesinfo.POST("", InsertSysTable)
tablesinfo.PUT("", UpdateSysTable)
tablesinfo.DELETE("/:tableId", DeleteSysTables)
tablesinfo.GET("/:tableId", GetSysTables)
tablesinfo.GET("", GetSysTablesInfo)
tablesinfo.POST("", sysTable.InsertSysTable)
tablesinfo.PUT("", sysTable.UpdateSysTable)
tablesinfo.DELETE("/:tableId", sysTable.DeleteSysTables)
tablesinfo.GET("/:tableId", sysTable.GetSysTables)
tablesinfo.GET("", sysTable.GetSysTablesInfo)
}
}
}
func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
r.POST("/login", authMiddleware.LoginHandler)
// Refresh time can be longer than token timeout
r.GET("/refresh_token", authMiddleware.RefreshHandler)
r.Group("").Use(authMiddleware.MiddlewareFunc()).GET("/ws/:id/:channel", ws.WebsocketManager.WsClient)
r.Group("").Use(authMiddleware.MiddlewareFunc()).GET("/wslogout/:id/:channel", ws.WebsocketManager.UnWsClient)
v1 := r.Group("/api/v1")
v1.POST("/login", authMiddleware.LoginHandler)
// Refresh time can be longer than token timeout
v1.GET("/refresh_token", authMiddleware.RefreshHandler)
//registerPageRouter(v1, authMiddleware)
registerBaseRouter(v1, authMiddleware)
registerDictRouter(v1, authMiddleware)
@@ -110,12 +122,14 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := sys_menu.SysMenu{}
v1auth := v1.Group("").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
api2 := sys_dept.SysDept{}
v1auth := v1.Group("").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{
//v1auth.GET("/getinfo", system.GetInfo)
v1auth.GET("/roleMenuTreeselect/:roleId", api.GetMenuTreeSelect)
v1.GET("/menuTreeselect", api.GetMenuTreeSelect)
//v1auth.GET("/roleDeptTreeselect/:roleId", system.GetDeptTreeRoleselect)
v1auth.GET("/roleDeptTreeselect/:roleId", api2.GetDeptTreeRoleSelect)
//GetDeptTreeRoleselect)
v1auth.POST("/logout", handler.LogOut)
}
}
@@ -158,9 +172,9 @@ func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
//}
func registerDictRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
dictApi := &dict.SysDictType{}
dataApi := &dict.SysDictData{}
dicts := v1.Group("/dict").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole())
dictApi := dict.SysDictType{}
dataApi := dict.SysDictData{}
dicts := v1.Group("/dict").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{
dicts.GET("/data", dataApi.GetSysDictDataList)
@@ -190,17 +204,19 @@ func registerDictRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
//}
func registerSysSettingRouter(v1 *gin.RouterGroup) {
api := system.SysSetting{}
m := monitor.Monitor{}
setting := v1.Group("/setting")
{
setting.GET("", api.GetSetting)
setting.POST("", api.CreateOrUpdateSetting)
setting.GET("/serverInfo", monitor.ServerInfo)
setting.GET("/serverInfo", m.ServerInfo)
}
}
func registerPublicRouter(v1 *gin.RouterGroup) {
p := v1.Group("/public")
{
p.POST("/uploadFile", public.UploadFile)
file := public.File{}
p.POST("/uploadFile", file.UploadFile)
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ func init() {
// 需认证的路由代码
func registerSysUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
api := &sys_user.SysUser{}
api := sys_user.SysUser{}
r := v1.Group("/sysUser").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()).Use(actions.PermissionAction())
{
r.GET("", api.GetSysUserList)
+30 -22
View File
@@ -1,8 +1,10 @@
package dto
import (
"errors"
vd "github.com/bytedance/go-tagexpr/v2/validator"
"github.com/gin-gonic/gin"
"go-admin/common/apis"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
"go-admin/common/dto"
@@ -11,9 +13,9 @@ import (
type SysCategorySearch struct {
dto.Pagination `search:"-"`
Name string `form:"name" search:"type:exact;column:name;table:sys_category" comment:"名称"`
Status string `form:"status" search:"type:exact;column:status;table:sys_category" comment:"状态"`
Name string `form:"name" search:"type:exact;column:name;table:sys_category" comment:"名称" vd:"?"`
Status string `form:"status" search:"type:exact;column:status;table:sys_category" comment:"状态" vd:"?"`
CateId int `form:"cateId" search:"type:exact;column:cate_id;table:sys_category" comment:"分类id" vd:"?"`
}
func (m *SysCategorySearch) GetNeedSearch() interface{} {
@@ -21,11 +23,17 @@ func (m *SysCategorySearch) GetNeedSearch() interface{} {
}
func (m *SysCategorySearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
if err = vd.Validate(m); err != nil {
log.Errorf("Validate error: %s", err.Error())
return err
}
return err
}
@@ -35,29 +43,29 @@ func (m *SysCategorySearch) Generate() dto.Index {
}
type SysCategoryControl struct {
ID int `uri:"Id" comment:"标识"` // 标识
Name string `json:"name" comment:"名称"`
Img string `json:"img" comment:"图标"`
Sort string `json:"sort" comment:"排序"`
Status string `json:"status" comment:"状态"`
Remark string `json:"remark" comment:"备注"`
ID int `uri:"Id" comment:"标识"`
Name string `json:"name" comment:"名称" vd:"len($)>0 && $!=' '; msg:'invalid name: 不能是空字符串'"`
Img string `json:"img" comment:"图标" vd:"?"`
Sort int `json:"sort" comment:"排序" vd:"?"`
Status int `json:"status" comment:"状态" vd:"$>0; msg:'invalid status: 状态无效'"`
Remark string `json:"remark" comment:"备注" vd:"?"`
}
func (s *SysCategoryControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
return err
log.Errorf("ShouldBindUri error: %s", err.Error())
return errors.New("数据绑定出错")
}
err = ctx.ShouldBind(s)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
log.Errorf("ShouldBind error: %s", err.Error())
err = errors.New("数据绑定出错")
}
if err1 := vd.Validate(s); err != nil {
log.Errorf("Validate error: %s", err1.Error())
return err1
}
return err
}
@@ -83,7 +91,7 @@ func (s *SysCategoryControl) GetId() interface{} {
}
type SysCategoryById struct {
dto.ObjectById
dto.ObjectById `vd:"?"`
}
func (s *SysCategoryById) Generate() dto.Control {
@@ -93,4 +101,4 @@ func (s *SysCategoryById) Generate() dto.Control {
func (s *SysCategoryById) GenerateM() (common.ActiveRecord, error) {
return &models.SysCategory{}, nil
}
}
+17 -8
View File
@@ -2,10 +2,12 @@ package dto
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/apis"
"go-admin/common/dto"
common "go-admin/common/models"
)
@@ -13,9 +15,10 @@ import (
// SysConfigSearch 列表或者搜索使用结构体
type SysConfigSearch struct {
dto.Pagination `search:"-"`
ConfigName string `form:"configName" search:"type:exact;column:config_name;table:sys_config" comment:""`
ConfigKey string `form:"configKey" search:"type:exact;column:config_key;table:sys_config" comment:""`
ConfigName string `form:"configName" search:"type:contains;column:config_name;table:sys_config" comment:""`
ConfigKey string `form:"configKey" search:"type:contains;column:config_key;table:sys_config" comment:""`
ConfigType string `form:"configType" search:"type:exact;column:config_type;table:sys_config" comment:""`
IsFrontend int `form:"isFrontend" search:"type:exact;column:is_frontend;table:sys_config" comment:""`
}
func (m *SysConfigSearch) GetNeedSearch() interface{} {
@@ -24,7 +27,7 @@ func (m *SysConfigSearch) GetNeedSearch() interface{} {
// Bind 映射上下文中的结构体数据
func (m *SysConfigSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -39,12 +42,13 @@ type SysConfigControl struct {
ConfigKey string `uri:"configKey" json:"configKey" comment:""`
ConfigValue string `json:"configValue" comment:""`
ConfigType string `json:"configType" comment:""`
IsFrontend int `json:"isFrontend"`
Remark string `json:"remark" comment:""`
}
// Bind 映射上下文中的结构体数据
func (s *SysConfigControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -71,6 +75,7 @@ func (s *SysConfigControl) Generate() (*system.SysConfig, error) {
ConfigKey: s.ConfigKey,
ConfigValue: s.ConfigValue,
ConfigType: s.ConfigType,
IsFrontend: s.IsFrontend,
Remark: s.Remark,
}, nil
}
@@ -82,8 +87,8 @@ func (s *SysConfigControl) GetId() interface{} {
// SysConfigById 获取单个或者删除的结构体
type SysConfigById struct {
Id int `uri:"id"`
Ids []int `json:"ids"`
Id int `uri:"id"`
Ids []int `json:"ids"`
}
func (s *SysConfigById) Generate() *SysConfigById {
@@ -92,11 +97,15 @@ func (s *SysConfigById) Generate() *SysConfigById {
}
func (s *SysConfigById) GetId() interface{} {
if len(s.Ids) > 0 {
s.Ids = append(s.Ids, s.Id)
return s.Ids
}
return s.Id
}
func (s *SysConfigById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+11 -8
View File
@@ -2,7 +2,7 @@ package dto
import (
"github.com/gin-gonic/gin"
"go-admin/common/apis"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
"go-admin/common/dto"
@@ -11,6 +11,9 @@ import (
type SysContentSearch struct {
dto.Pagination `search:"-"`
CateId string `form:"cateId" search:"type:exact;column:cate_id;table:sys_content" comment:"分类"`
Name string `form:"name" search:"type:contains;column:name;table:sys_content" comment:"名称"`
Status string `form:"status" search:"type:exact;column:status;table:sys_content" comment:"状态"`
}
func (m *SysContentSearch) GetNeedSearch() interface{} {
@@ -18,7 +21,7 @@ func (m *SysContentSearch) GetNeedSearch() interface{} {
}
func (m *SysContentSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -33,17 +36,17 @@ func (m *SysContentSearch) Generate() dto.Index {
type SysContentControl struct {
ID int `uri:"ID" comment:""` //
CateId string `json:"cateId" comment:""`
CateId int `json:"cateId" comment:""`
Name string `json:"name" comment:""`
Status string `json:"status" comment:""`
Status int `json:"status" comment:""`
Img string `json:"img" comment:""`
Content string `json:"content" comment:""`
Remark string `json:"remark" comment:""`
Sort string `json:"sort" comment:""`
Sort int `json:"sort" comment:""`
}
func (s *SysContentControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -63,7 +66,7 @@ func (s *SysContentControl) Generate() dto.Control {
func (s *SysContentControl) GenerateM() (common.ActiveRecord, error) {
return &models.SysContent{
Id: s.ID,
Model: common.Model{s.ID},
CateId: s.CateId,
Name: s.Name,
Status: s.Status,
@@ -89,4 +92,4 @@ func (s *SysContentById) Generate() dto.Control {
func (s *SysContentById) GenerateM() (common.ActiveRecord, error) {
return &models.SysContent{}, nil
}
}
+4 -4
View File
@@ -2,10 +2,10 @@ package dto
import (
"encoding/json"
"go-admin/common/apis"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -31,7 +31,7 @@ func (m *SysDeptSearch) GetNeedSearch() interface{} {
// Bind 映射上下文中的结构体数据
func (m *SysDeptSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -54,7 +54,7 @@ type SysDeptControl struct {
// Bind 映射上下文中的结构体数据
func (s *SysDeptControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -109,7 +109,7 @@ func (s *SysDeptById) GetId() interface{} {
}
func (s *SysDeptById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+3 -3
View File
@@ -1,10 +1,10 @@
package dto
import (
"go-admin/common/apis"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -25,7 +25,7 @@ func (m *SysDictDataSearch) GetNeedSearch() interface{} {
}
func (m *SysDictDataSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -53,7 +53,7 @@ type SysDictDataControl struct {
}
func (s *SysDictDataControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+3 -3
View File
@@ -2,8 +2,8 @@ package dto
import (
"github.com/gin-gonic/gin"
"go-admin/common/apis"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
common "go-admin/common/models"
@@ -22,7 +22,7 @@ func (m *SysDictTypeSearch) GetNeedSearch() interface{} {
}
func (m *SysDictTypeSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -48,7 +48,7 @@ type SysDictTypeControl struct {
}
func (s *SysDictTypeControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+3 -3
View File
@@ -2,7 +2,7 @@ package dto
import (
"github.com/gin-gonic/gin"
"go-admin/common/apis"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
"go-admin/common/dto"
@@ -24,7 +24,7 @@ func (m *SysFileDirSearch) GetNeedSearch() interface{} {
}
func (m *SysFileDirSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -48,7 +48,7 @@ type SysFileDirControl struct {
}
func (s *SysFileDirControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+2 -2
View File
@@ -2,7 +2,7 @@ package dto
import (
"github.com/gin-gonic/gin"
"go-admin/common/apis"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
"go-admin/common/dto"
@@ -24,7 +24,7 @@ func (m *SysJobSearch) GetNeedSearch() interface{} {
}
func (m *SysJobSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Errorf("Bind error: %s", err)
+4 -4
View File
@@ -1,10 +1,10 @@
package dto
import (
"go-admin/common/apis"
"time"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -24,7 +24,7 @@ func (m *SysLoginLogSearch) GetNeedSearch() interface{} {
}
func (m *SysLoginLogSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -47,7 +47,7 @@ type SysLoginLogControl struct {
}
func (s *SysLoginLogControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -90,7 +90,7 @@ func (s *SysLoginLogById) GetId() interface{} {
}
func (s *SysLoginLogById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+4 -4
View File
@@ -2,10 +2,10 @@ package dto
import (
"encoding/json"
"go-admin/common/apis"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -30,7 +30,7 @@ func (m *SysMenuSearch) GetNeedSearch() interface{} {
// Bind 映射上下文中的结构体数据
func (m *SysMenuSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -60,7 +60,7 @@ type SysMenuControl struct {
// Bind 映射上下文中的结构体数据
func (s *SysMenuControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -122,7 +122,7 @@ func (s *SysMenuById) GetId() interface{} {
}
func (s *SysMenuById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+4 -4
View File
@@ -1,10 +1,10 @@
package dto
import (
"go-admin/common/apis"
"time"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -26,7 +26,7 @@ func (m *SysOperaLogSearch) GetNeedSearch() interface{} {
}
func (m *SysOperaLogSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -57,7 +57,7 @@ type SysOperaLogControl struct {
}
func (s *SysOperaLogControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -112,7 +112,7 @@ func (s *SysOperaLogById) GetId() interface{} {
}
func (s *SysOperaLogById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+4 -4
View File
@@ -2,10 +2,10 @@ package dto
import (
"encoding/json"
"go-admin/common/apis"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -28,7 +28,7 @@ func (m *SysPostSearch) GetNeedSearch() interface{} {
// Bind 映射上下文中的结构体数据
func (m *SysPostSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -48,7 +48,7 @@ type SysPostControl struct {
// Bind 映射上下文中的结构体数据
func (s *SysPostControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -100,7 +100,7 @@ func (s *SysPostById) GetId() interface{} {
}
func (s *SysPostById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+5 -5
View File
@@ -2,10 +2,10 @@ package dto
import (
"encoding/json"
"go-admin/common/apis"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -32,7 +32,7 @@ func (m *SysRoleSearch) GetNeedSearch() interface{} {
// Bind 映射上下文中的结构体数据
func (m *SysRoleSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -50,13 +50,13 @@ type SysRoleControl struct {
Flag string `form:"flag" comment:"标记"` // 标记
Remark string `form:"remark" comment:"备注"` // 备注
Admin bool `form:"admin" comment:"是否管理员"`
DataScope string `form:"dataScope" comment:"是否管理员"`
DataScope string `form:"dataScope"`
MenuIds []int `json:"menuIds"`
}
// Bind 映射上下文中的结构体数据
func (s *SysRoleControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindBodyWith(s, binding.JSON)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -123,4 +123,4 @@ type RoleDataScopeReq struct {
type DeptIdList struct {
DeptId int `json:"DeptId"`
}
}
+3 -3
View File
@@ -2,9 +2,9 @@ package dto
import (
"encoding/json"
"go-admin/common/apis"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
)
@@ -18,7 +18,7 @@ type SysSettingControl struct {
// Bind 映射上下文中的结构体数据
func (s *SysSettingControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(s)
if err != nil {
@@ -70,7 +70,7 @@ func (s *SysSettingById) GetId() interface{} {
}
func (s *SysSettingById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
+5 -4
View File
@@ -2,7 +2,7 @@ package dto
import (
"github.com/gin-gonic/gin"
"go-admin/common/apis"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/system"
"go-admin/common/dto"
@@ -28,7 +28,7 @@ func (m *SysUserSearch) GetNeedSearch() interface{} {
}
func (m *SysUserSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -58,7 +58,7 @@ type SysUserControl struct {
}
func (s *SysUserControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
//err := ctx.ShouldBindUri(s)
//if err != nil {
// log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -113,5 +113,6 @@ func (s *SysUserById) GenerateM() (common.ActiveRecord, error) {
// PassWord 密码
type PassWord struct {
Password string `json:"password"`
NewPassword string `json:"newPassword" binding:"required"`
OldPassword string `json:"oldPassword" binding:"required"`
}
+5 -8
View File
@@ -1,10 +1,10 @@
package dto
import (
"go-admin/common/apis"
"time"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
"go-admin/common/dto"
@@ -22,7 +22,7 @@ func (m *SysChinaAreaDataSearch) GetNeedSearch() interface{} {
}
func (m *SysChinaAreaDataSearch) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
@@ -40,7 +40,7 @@ type SysChinaAreaDataControl struct {
}
func (s *SysChinaAreaDataControl) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -59,9 +59,6 @@ func (s *SysChinaAreaDataControl) Generate() (*models.SysChinaAreaData, error) {
Model: common.Model{Id: s.Id},
PId: s.PId,
Name: s.Name,
CreateTime: s.CreateTime,
UpdateTime: s.UpdateTime,
DeleteTime: s.DeleteTime,
}, nil
}
@@ -83,7 +80,7 @@ func (s *SysChinaAreaDataById) GetId() interface{} {
}
func (s *SysChinaAreaDataById) Bind(ctx *gin.Context) error {
log := apis.GetRequestLogger(ctx)
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
@@ -98,4 +95,4 @@ func (s *SysChinaAreaDataById) Bind(ctx *gin.Context) error {
func (s *SysChinaAreaDataById) SetUpdateBy(id int) {
}
}
@@ -2,6 +2,7 @@ package service
import (
"errors"
common "go-admin/common/models"
"gorm.io/gorm"
@@ -18,10 +19,9 @@ type SysChinaAreaData struct {
// GetSysChinaAreaDataPage 获取SysChinaAreaData列表
func (e *SysChinaAreaData) GetSysChinaAreaDataPage(c *dto.SysChinaAreaDataSearch, p *actions.DataPermission, list *[]models.SysChinaAreaData, count *int64) error {
var err error
var data models.SysChinaAreaData
err = e.Orm.Model(&data).
err := e.Orm.Model(&data).
Scopes(
cDto.MakeCondition(c.GetNeedSearch()),
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
@@ -30,7 +30,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataPage(c *dto.SysChinaAreaDataSearch
Find(list).Limit(-1).Offset(-1).
Count(count).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
e.Log.Errorf("Service GetSysChinaAreaDataPage error:%s", err)
return err
}
return nil
@@ -38,22 +38,20 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataPage(c *dto.SysChinaAreaDataSearch
// GetSysChinaAreaData 获取SysChinaAreaData对象
func (e *SysChinaAreaData) GetSysChinaAreaData(d *dto.SysChinaAreaDataById, p *actions.DataPermission, model *models.SysChinaAreaData) error {
var err error
var data models.SysChinaAreaData
db := e.Orm.Model(&data).
err := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).
First(model, d.GetId())
err = db.Error
First(model, d.GetId()).Error
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
err = errors.New("查看对象不存在或无权查看")
e.Log.Errorf("db error:%s", err)
return err
}
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
if err != nil {
e.Log.Errorf("Service GetSysChinaAreaData error:%s", err)
return err
}
return nil
@@ -61,13 +59,12 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(d *dto.SysChinaAreaDataById, p *a
// InsertSysChinaAreaData 创建SysChinaAreaData对象
func (e *SysChinaAreaData) InsertSysChinaAreaData(model *models.SysChinaAreaData) error {
var err error
var data models.SysChinaAreaData
err = e.Orm.Model(&data).
err := e.Orm.Model(&data).
Create(model).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
e.Log.Errorf("Service InsertSysChinaAreaData error:%s", err)
return err
}
return nil
@@ -75,41 +72,39 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(model *models.SysChinaAreaData
// UpdateSysChinaAreaData 修改SysChinaAreaData对象
func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *models.SysChinaAreaData, p *actions.DataPermission) error {
var err error
var data models.SysChinaAreaData
db := e.Orm.Model(&data).
db := e.Orm.Model(&models.SysChinaAreaData{
Model: common.Model{
Id: c.GetId().(int),
}}).
Scopes(
actions.Permission(data.TableName(), p),
).Where(c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
actions.Permission(c.TableName(), p),
).Updates(c)
if err := db.Error; err != nil {
e.Log.Errorf("Service UpdateSysChinaAreaData error: %s", err)
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
}
return nil
}
// RemoveSysChinaAreaData 删除SysChinaAreaData
func (e *SysChinaAreaData) RemoveSysChinaAreaData(d *dto.SysChinaAreaDataById, p *actions.DataPermission) error {
var err error
var data models.SysChinaAreaData
db := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
if err := db.Error; err != nil {
e.Log.Errorf("Service RemoveSysChinaAreaData error: %s", err)
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
return err
return errors.New("无权删除该数据")
}
return nil
}
+33 -18
View File
@@ -5,6 +5,7 @@ import (
"go-admin/app/admin/models/system"
"go-admin/app/admin/service/dto"
cDto "go-admin/common/dto"
common "go-admin/common/models"
"go-admin/common/service"
"gorm.io/gorm"
)
@@ -26,7 +27,23 @@ func (e *SysConfig) GetSysConfigPage(c *dto.SysConfigSearch, list *[]system.SysC
Find(list).Limit(-1).Offset(-1).
Count(count).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
e.Log.Errorf("Service GetSysConfigPage error:%s", err)
return err
}
return nil
}
func (e *SysConfig) GetSysConfigByKey(c *dto.SysConfigSearch, list *[]system.SysConfig) error {
var err error
var data system.SysConfig
err = e.Orm.Model(&data).
Scopes(
cDto.MakeCondition(c.GetNeedSearch()),
).
Find(list).Error
if err != nil {
e.Log.Errorf("Service GetSysConfigByKey error:%s", err)
return err
}
return nil
@@ -34,19 +51,17 @@ func (e *SysConfig) GetSysConfigPage(c *dto.SysConfigSearch, list *[]system.SysC
// GetSysConfig 获取SysConfig对象
func (e *SysConfig) GetSysConfig(d *dto.SysConfigById, model *system.SysConfig) error {
var err error
var data system.SysConfig
db := e.Orm.Model(&data).
First(model, d.GetId())
err = db.Error
err := e.Orm.Model(&data).
First(model, d.GetId()).Error
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
err = errors.New("查看对象不存在或无权查看")
e.Log.Errorf("db error:%s", err)
e.Log.Errorf("Service GetSysConfigPage error:%s", err)
return err
}
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
if err != nil {
e.Log.Errorf("Service GetSysConfig error:%s", err)
return err
}
return nil
@@ -60,7 +75,7 @@ func (e *SysConfig) InsertSysConfig(model *system.SysConfig) error {
err = e.Orm.Model(&data).
Create(model).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
e.Log.Errorf("Service InsertSysConfig error:%s", err)
return err
}
return nil
@@ -69,12 +84,13 @@ func (e *SysConfig) InsertSysConfig(model *system.SysConfig) error {
// UpdateSysConfig 修改SysConfig对象
func (e *SysConfig) UpdateSysConfig(c *system.SysConfig) error {
var err error
var data system.SysConfig
db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
db := e.Orm.Model(&system.SysConfig{Model: common.Model{
Id: c.GetId().(int),
}}).Updates(c)
err = db.Error
if err != nil {
e.Log.Errorf("Service UpdateSysConfig error:%s", err)
return err
}
if db.RowsAffected == 0 {
@@ -89,11 +105,10 @@ func (e *SysConfig) RemoveSysConfig(d *dto.SysConfigById, c *system.SysConfig) e
var err error
var data system.SysConfig
db := e.Orm.Model(&data).
Where(d.GetId()).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.Ids)
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
e.Log.Errorf("Service RemoveSysConfig error:%s", err)
return err
}
if db.RowsAffected == 0 {
@@ -110,7 +125,7 @@ func (e *SysConfig) GetSysConfigByKEY(c *dto.SysConfigControl) error {
data.ConfigKey = c.ConfigKey
err = e.Orm.Table(data.TableName()).Where("config_key = ?", data.ConfigKey).First(c).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
e.Log.Errorf("Service GetSysConfigByKEY error:%s", err)
return err
}
+68 -72
View File
@@ -2,8 +2,8 @@ package service
import (
"errors"
log "github.com/go-admin-team/go-admin-core/logger"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
"go-admin/app/admin/models/system"
@@ -84,9 +84,9 @@ func (e *SysDept) InsertSysDept(model *system.SysDept) error {
// UpdateSysDept 修改SysDept对象
func (e *SysDept) UpdateSysDept(c *system.SysDept) error {
var err error
var data system.SysDept
db := e.Orm.Model(&data).
db := e.Orm.Model(&system.SysDept{
DeptId: c.GetId().(int),
}).
Where(c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
@@ -96,9 +96,6 @@ func (e *SysDept) UpdateSysDept(c *system.SysDept) error {
return errors.New("无权更新该数据")
}
//参数1:是要修改的数据
//参数2:是修改的数据
return nil
}
@@ -107,8 +104,7 @@ func (e *SysDept) RemoveSysDept(d *dto.SysDeptById) error {
var err error
var data system.SysDept
db := e.Orm.Model(&data).
Where(d.GetId()).Delete(&data)
db := e.Orm.Model(&data).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
@@ -220,66 +216,66 @@ func (e *SysDept) deptPageCall(deptlist *[]system.SysDept, menu system.SysDept)
return menu
}
//// GetRoleDeptId 获取角色的部门ID集合
//func (e *SysDept) GetRoleDeptId(roleId int) ([]int, error) {
// deptIds := make([]int, 0)
// deptList := make([]dto.DeptIdList, 0)
// if err := e.Orm.Table("sys_role_dept").
// Select("sys_role_dept.dept_id").
// Joins("LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id").
// Where("role_id = ? ", roleId).
// Where(" sys_role_dept.dept_id not in(select sys_dept.parent_id from sys_role_dept LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id where role_id =? )", roleId).
// Find(&deptList).Error; err != nil {
// return nil, err
// }
//
// for i := 0; i < len(deptList); i++ {
// deptIds = append(deptIds, deptList[i].DeptId)
// }
//
// return deptIds, nil
//}
//
//func (e *SysDept) SetDeptLabel() (m []dto.DeptLabel, err error) {
// list := make([]models.SysDept, 0)
// err = e.Orm.Find(&list).Error
// if err != nil {
// log.Error("find dept list error, %s", e.err)
// return
// }
//
// m = make([]dto.DeptLabel, 0)
// var item dto.DeptLabel
// for i := range list {
// if list[i].ParentId != 0 {
// continue
// }
// item = dto.DeptLabel{}
// item.Id = list[i].DeptId
// item.Label = list[i].DeptName
// deptInfo := digitDeptLabel(&list, item)
//
// m = append(m, deptInfo)
// }
// return
//}
//
//// digitDeptLabel
//func digitDeptLabel(deptList *[]models.SysDept, dept dto.DeptLabel) dto.DeptLabel {
// list := *deptList
//
// var mi dto.DeptLabel
// min := make([]dto.DeptLabel, 0)
// for j := 0; j < len(list); j++ {
//
// if dept.Id != list[j].ParentId {
// continue
// }
// mi = dto.DeptLabel{Id: list[j].DeptId, Label: list[j].DeptName, Children: []dto.DeptLabel{}}
// ms := digitDeptLabel(deptList, mi)
// min = append(min, ms)
//
// }
// dept.Children = min
// return dept
//}
// GetRoleDeptId 获取角色的部门ID集合
func (e *SysDept) GetRoleDeptId(roleId int) ([]int, error) {
deptIds := make([]int, 0)
deptList := make([]dto.DeptIdList, 0)
if err := e.Orm.Table("sys_role_dept").
Select("sys_role_dept.dept_id").
Joins("LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id").
Where("role_id = ? ", roleId).
Where(" sys_role_dept.dept_id not in(select sys_dept.parent_id from sys_role_dept LEFT JOIN sys_dept on sys_dept.dept_id=sys_role_dept.dept_id where role_id =? )", roleId).
Find(&deptList).Error; err != nil {
return nil, err
}
for i := 0; i < len(deptList); i++ {
deptIds = append(deptIds, deptList[i].DeptId)
}
return deptIds, nil
}
func (e *SysDept) SetDeptLabel() (m []dto.DeptLabel, err error) {
list := make([]system.SysDept, 0)
err = e.Orm.Find(&list).Error
if err != nil {
log.Error("find dept list error, %s", err.Error())
return
}
m = make([]dto.DeptLabel, 0)
var item dto.DeptLabel
for i := range list {
if list[i].ParentId != 0 {
continue
}
item = dto.DeptLabel{}
item.Id = list[i].DeptId
item.Label = list[i].DeptName
deptInfo := digitDeptLabel(&list, item)
m = append(m, deptInfo)
}
return
}
// digitDeptLabel
func digitDeptLabel(deptList *[]system.SysDept, dept dto.DeptLabel) dto.DeptLabel {
list := *deptList
var mi dto.DeptLabel
min := make([]dto.DeptLabel, 0)
for j := 0; j < len(list); j++ {
if dept.Id != list[j].ParentId {
continue
}
mi = dto.DeptLabel{Id: list[j].DeptId, Label: list[j].DeptName, Children: []dto.DeptLabel{}}
ms := digitDeptLabel(deptList, mi)
min = append(min, ms)
}
dept.Children = min
return dept
}
+4 -6
View File
@@ -71,10 +71,9 @@ func (e *SysDictData) Insert(model *system.SysDictData) error {
// Update 修改对象
func (e *SysDictData) Update(c *system.SysDictData) error {
var err error
var data system.SysDictData
db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
db := e.Orm.Model(&system.SysDictData{
DictCode: c.GetId().(int),
}).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
@@ -91,8 +90,7 @@ func (e *SysDictData) Remove(d *dto.SysDictDataById, c *system.SysDictData) erro
var err error
var data system.SysDictData
db := e.Orm.Model(&data).
Where(d.GetId()).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
+4 -6
View File
@@ -71,10 +71,9 @@ func (e *SysDictType) Insert(model *system.SysDictType) error {
// Update 修改对象
func (e *SysDictType) Update(c *system.SysDictType) error {
var err error
var data system.SysDictType
db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
db := e.Orm.Model(&system.SysDictType{
ID: c.GetId().(int),
}).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
@@ -91,8 +90,7 @@ func (e *SysDictType) Remove(d *dto.SysDictTypeById, c *system.SysDictType) erro
var err error
var data system.SysDictType
db := e.Orm.Model(&data).
Where(d.GetId()).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
+4 -3
View File
@@ -3,6 +3,7 @@ package service
import (
"errors"
"fmt"
"go-admin/app/admin/models/system"
"gorm.io/gorm"
@@ -91,10 +92,10 @@ func (e *SysFileDir) UpdateSysFileDir(c *dto.SysFileDirControl, p *actions.DataP
var err error
data, _ := c.GenerateM()
db := e.Orm.
db := e.Orm.Model(&system.SysRole{RoleId: c.GetId().(int)}).
Scopes(
actions.Permission(data.TableName(), p),
).Where(c.ID).Updates(data)
).Updates(data)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
@@ -113,7 +114,7 @@ func (e *SysFileDir) RemoveSysFileDir(d *dto.SysFileDirById, p *actions.DataPerm
db := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).Where(d.Id).Delete(&data)
).Delete(&data, d.Id)
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
+6 -3
View File
@@ -2,6 +2,7 @@ package service
import (
"errors"
common "go-admin/common/models"
"gorm.io/gorm"
@@ -89,10 +90,12 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *dto.SysFileInfoControl, p *actions.Da
e.Log.Errorf("db error: %s", err)
return err
}
err = e.Orm.Debug().Model(&data).
err = e.Orm.Debug().Model(&models.SysFileInfo{Model: common.Model{
Id: c.ID,
}}).
Scopes(
actions.Permission(data.TableName(), p),
).Where("id = ?", c.ID).Updates(&data).Error
).Updates(&data).Error
if err != nil {
e.Log.Errorf("db error: %s", err)
return err
@@ -112,7 +115,7 @@ func (e *SysFileInfo) RemoveSysFileInfo(d *dto.SysFileInfoById, p *actions.DataP
db := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).Where(d.GetId()).Delete(&data)
).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
+1 -2
View File
@@ -19,8 +19,7 @@ type SysJob struct {
func (e *SysJob) RemoveJob(c *dto.GeneralDelDto) error {
var err error
var data models.SysJob
data.JobId = c.Id
err = e.Orm.Table(data.TableName()).First(&data).Error
err = e.Orm.Table(data.TableName()).First(&data, c.Id).Error
if err != nil {
e.Log.Errorf("db error: %s", err)
return err
+2 -3
View File
@@ -75,7 +75,7 @@ func (e *SysLoginLog) UpdateSysLoginLog(c common.ActiveRecord) error {
var data system.SysLoginLog
db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
Where("id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
@@ -92,8 +92,7 @@ func (e *SysLoginLog) RemoveSysLoginLog(d *dto.SysLoginLogById, c common.ActiveR
var err error
var data system.SysLoginLog
db := e.Orm.Model(&data).
Where(d.Ids).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.Ids)
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
+2 -3
View File
@@ -107,7 +107,7 @@ func (e *SysMenu) UpdateSysMenu(c *system.SysMenu) error {
var data system.SysMenu
db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
Where("menu_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
@@ -124,8 +124,7 @@ func (e *SysMenu) RemoveSysMenu(d *dto.SysMenuById) error {
var err error
var data system.SysMenu
db := e.Orm.Model(&data).
Where(d.GetId()).Delete(&data)
db := e.Orm.Model(&data).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
+17 -20
View File
@@ -5,6 +5,7 @@ import (
"go-admin/app/admin/models/system"
"go-admin/app/admin/service/dto"
cDto "go-admin/common/dto"
common "go-admin/common/models"
"go-admin/common/service"
"gorm.io/gorm"
)
@@ -26,7 +27,7 @@ func (e *SysOperaLog) GetSysOperaLogPage(c *dto.SysOperaLogSearch, list *[]syste
Find(list).Limit(-1).Offset(-1).
Count(count).Error
if err != nil {
e.Log.Errorf(" db error:%s", err)
e.Log.Errorf("Service GetSysOperaLogPage error:%s", err.Error())
return err
}
return nil
@@ -34,19 +35,17 @@ func (e *SysOperaLog) GetSysOperaLogPage(c *dto.SysOperaLogSearch, list *[]syste
// GetSysOperaLog 获取SysOperaLog对象
func (e *SysOperaLog) GetSysOperaLog(d *dto.SysOperaLogById, model *system.SysOperaLog) error {
var err error
var data system.SysOperaLog
db := e.Orm.Model(&data).
First(model, d.GetId())
err = db.Error
err := e.Orm.Model(&data).
First(model, d.GetId()).Error
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
err = errors.New("查看对象不存在或无权查看")
e.Log.Errorf(" db error:%s", err)
e.Log.Errorf("Service GetSysOperaLog error:%s", err.Error())
return err
}
if db.Error != nil {
e.Log.Errorf(" db error:%s", err)
if err != nil {
e.Log.Errorf("Service GetSysOperaLog error:%s", err.Error())
return err
}
return nil
@@ -60,7 +59,7 @@ func (e *SysOperaLog) InsertSysOperaLog(model *system.SysOperaLog) error {
err = e.Orm.Model(&data).
Create(model).Error
if err != nil {
e.Log.Errorf(" db error:%s", err)
e.Log.Errorf("Service InsertSysOperaLog error:%s", err.Error())
return err
}
return nil
@@ -69,12 +68,12 @@ func (e *SysOperaLog) InsertSysOperaLog(model *system.SysOperaLog) error {
// UpdateSysOperaLog 修改SysOperaLog对象
func (e *SysOperaLog) UpdateSysOperaLog(c *system.SysOperaLog) error {
var err error
var data system.SysOperaLog
db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf(" db error:%s", err)
db := e.Orm.Model(&system.SysOperaLog{Model: common.Model{
Id: c.GetId().(int),
}}).Updates(c)
if err = db.Error; err != nil {
e.Log.Errorf("Service UpdateSysOperaLog error:%s", err.Error())
return err
}
if db.RowsAffected == 0 {
@@ -89,15 +88,13 @@ func (e *SysOperaLog) RemoveSysOperaLog(d *dto.SysOperaLogById) error {
var err error
var data system.SysOperaLog
db := e.Orm.Model(&data).Where(d.Ids).Delete(&data)
if db.Error != nil {
err = db.Error
e.Log.Errorf(" Delete error: %s", err)
db := e.Orm.Model(&data).Delete(&data, d.Ids)
if err = db.Error; err != nil {
e.Log.Errorf("Service RemoveSysOperaLog error:%s", err.Error())
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
return err
return errors.New("无权删除该数据")
}
return nil
}
+1 -1
View File
@@ -74,7 +74,7 @@ func (e *SysPost) UpdateSysPost(c *system.SysPost) error {
var data system.SysPost
db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
Where("post_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
+2 -2
View File
@@ -104,7 +104,7 @@ func (e *SysRole) UpdateSysRole(c *system.SysRole) error {
}
}()
db := tx.Model(&c).
Where(c.GetId()).Updates(c)
Where(" role_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
@@ -197,7 +197,7 @@ func (e *SysRole) UpdateDataScope(c *system.SysRole) (err error) {
tx.Commit()
}
}()
err = tx.Model(&system.SysRole{}).Where("role_id = ?", c.RoleId).Select("data_scope, update_by").Updates(c).Error
err = tx.Model(&system.SysRole{}).Where("role_id = ?", c.RoleId).Select("data_scope", "update_by").Updates(c).Error
if err != nil {
return err
}
+33 -14
View File
@@ -3,6 +3,8 @@ package service
import (
"errors"
log "github.com/go-admin-team/go-admin-core/logger"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
"go-admin/app/admin/models/system"
@@ -81,7 +83,7 @@ func (e *SysUser) UpdateSysUser(c common.ActiveRecord, p *actions.DataPermission
db := e.Orm.Model(c).
Scopes(
actions.Permission(c.TableName(), p),
).Where(c.GetId()).Updates(c)
).Where("user_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
@@ -101,7 +103,7 @@ func (e *SysUser) RemoveSysUser(d cDto.Control, c common.ActiveRecord, p *action
db := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).Where(d.GetId()).Delete(c)
).Delete(c, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
@@ -115,29 +117,46 @@ func (e *SysUser) RemoveSysUser(d cDto.Control, c common.ActiveRecord, p *action
}
// UpdateSysUserPwd 修改SysUser对象密码
func (e *SysUser) UpdateSysUserPwd(c *system.SysUser, p *actions.DataPermission) error {
func (e *SysUser) UpdateSysUserPwd(id int, oldPassword, newPassword string, p *actions.DataPermission) error {
var err error
if c.Password == "" {
if newPassword == "" {
return nil
}
c := &system.SysUser{}
err = c.Encrypt()
if err != nil {
return err
}
db := e.Orm.Model(c).
err = e.Orm.Model(c).
Scopes(
actions.Permission(c.TableName(), p),
).Where(c.GetId()).Updates(c)
if db.Error != nil {
).Where("user_id = ?", id).Select("UserId", "Password", "Salt").First(c).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.New("无权更新该数据")
}
e.Log.Errorf("db error: %s", err)
return err
}
var ok bool
ok, err = pkg.CompareHashAndPassword(c.Password, oldPassword)
if err != nil {
e.Log.Errorf("CompareHashAndPassword error, %s", err.Error())
return err
}
if !ok {
err = errors.New("incorrect Password")
e.Log.Warnf("user[%d] %s", id, err.Error())
return err
}
c.Password = newPassword
db := e.Orm.Model(c).Where("user_id = ?", id).Select("Password", "Salt").Updates(c)
if err = db.Error; err != nil {
e.Log.Errorf("db error: %s", err)
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
err = errors.New("set password error")
log.Warnf("db update error")
return err
}
return nil
}
+43 -5
View File
@@ -3,8 +3,6 @@ package api
import (
"context"
"fmt"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"log"
"net/http"
"os"
@@ -13,14 +11,19 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/config/source/file"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
"github.com/go-admin-team/go-admin-core/sdk/pkg/logger"
"github.com/spf13/cobra"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg/logger"
"go-admin/app/admin/models/system"
"go-admin/app/admin/router"
"go-admin/app/jobs"
"go-admin/common/database"
"go-admin/common/global"
ext "go-admin/config"
)
var (
@@ -49,7 +52,8 @@ func init() {
}
func setup() {
// 注入配置扩展项
config.ExtendConfig = &ext.ExtConfig
//1. 读取配置
config.Setup(file.NewSource, file.WithPath(configYml))
go config.Watch()
@@ -62,9 +66,43 @@ func setup() {
config.LoggerConfig.Stdout))
//3. 初始化数据库链接
database.Setup()
//4. 设置缓存
cacheAdapter, err := config.CacheConfig.Setup()
if err != nil {
log.Fatalf("cache setup error, %s\n", err.Error())
}
sdk.Runtime.SetCacheAdapter(cacheAdapter)
//5. 设置验证码store
captcha.SetStore(captcha.NewCacheStore(cacheAdapter, 600))
//6. 设置队列
if !config.QueueConfig.Empty() {
queueAdapter, err := config.QueueConfig.Setup()
if err != nil {
log.Fatalf("queue setup error, %s\n", err.Error())
}
sdk.Runtime.SetQueueAdapter(queueAdapter)
defer func() {
go queueAdapter.Run()
}()
}
//7. 设置分布式锁
if !config.LockerConfig.Empty() {
lockerAdapter, err := config.LockerConfig.Setup()
if err != nil {
log.Fatalf("locker setup error, %s\n", err.Error())
}
sdk.Runtime.SetLockerAdapter(lockerAdapter)
}
usageStr := `starting api server...`
log.Println(usageStr)
//注册监听函数
queue := sdk.Runtime.GetMemoryQueue("")
queue.Register(global.LoginLog, system.SaveLoginLog)
queue.Register(global.OperateLog, system.SaveOperaLog)
go queue.Run()
}
func run() error {
+22
View File
@@ -0,0 +1,22 @@
package models
import (
"time"
"gorm.io/gorm"
)
type ControlBy struct {
CreateBy int `json:"createBy" gorm:"index;comment:创建者"`
UpdateBy int `json:"updateBy" gorm:"index;comment:更新者"`
}
type Model struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"`
}
type ModelTime struct {
CreatedAt time.Time `json:"createdAt" gorm:"comment:创建时间"`
UpdatedAt time.Time `json:"updatedAt" gorm:"comment:最后更新时间"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:删除时间"`
}
@@ -0,0 +1,16 @@
package models
//sys_casbin_rule
type CasbinRule struct {
PType string `json:"p_type" gorm:"size:100;"`
V0 string `json:"v0" gorm:"size:100;"`
V1 string `json:"v1" gorm:"size:100;"`
V2 string `json:"v2" gorm:"size:100;"`
V3 string `json:"v3" gorm:"size:100;"`
V4 string `json:"v4" gorm:"size:100;"`
V5 string `json:"v5" gorm:"size:100;"`
}
func (CasbinRule) TableName() string {
return "sys_casbin_rule"
}
@@ -1,8 +1,4 @@
package version
import (
"go-admin/app/admin/models"
)
package models
type DictData struct {
DictCode int `gorm:"primaryKey;autoIncrement;" json:"dictCode" example:"1"` //字典编码
@@ -15,10 +11,9 @@ type DictData struct {
IsDefault string `gorm:"size:8;" json:"isDefault"` //
Status string `gorm:"size:4;" json:"status"` //状态
Default string `gorm:"size:8;" json:"default"` //
CreateBy string `gorm:"size:64;" json:"createBy"` //
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
Remark string `gorm:"size:255;" json:"remark"` //备注
models.BaseModel
ControlBy
ModelTime
}
func (DictData) TableName() string {
@@ -1,18 +1,13 @@
package version
import (
"go-admin/app/admin/models"
)
package models
type DictType struct {
DictId int `gorm:"primaryKey;autoIncrement;" json:"dictId"`
DictName string `gorm:"size:128;" json:"dictName"` //字典名称
DictType string `gorm:"size:128;" json:"dictType"` //字典类型
Status string `gorm:"size:4;" json:"status"` //状态
CreateBy string `gorm:"size:11;" json:"createBy"` //创建者
UpdateBy string `gorm:"size:11;" json:"updateBy"` //更新者
Remark string `gorm:"size:255;" json:"remark"` //备注
models.BaseModel
ControlBy
ModelTime
}
func (DictType) TableName() string {
+55
View File
@@ -0,0 +1,55 @@
package models
import (
"fmt"
"go-admin/common/global"
"gorm.io/gorm"
"io/ioutil"
"log"
"strings"
)
func InitDb(db *gorm.DB) (err error) {
filePath := "config/db.sql"
err = ExecSql(db, filePath)
if global.Driver == "postgres" {
filePath = "config/pg.sql"
err = ExecSql(db, filePath)
}
return err
}
func ExecSql(db *gorm.DB, filePath string) error {
sql, err := Ioutil(filePath)
if err != nil {
fmt.Println("数据库基础数据初始化脚本读取失败!原因:", err.Error())
return err
}
sqlList := strings.Split(sql, ";")
for i := 0; i < len(sqlList)-1; i++ {
if strings.Contains(sqlList[i], "--") {
fmt.Println(sqlList[i])
continue
}
sql := strings.Replace(sqlList[i]+";", "\n", "", 0)
sql = strings.TrimSpace(sql)
if err = db.Exec(sql).Error; err != nil {
log.Printf("error sql: %s", sql)
if !strings.Contains(err.Error(), "Query was empty") {
return err
}
}
}
return nil
}
func Ioutil(filePath string) (string, error) {
if contents, err := ioutil.ReadFile(filePath); err == nil {
//因为contents是[]byte类型,直接转换成string类型后会多一行空格,需要使用strings.Replace替换换行符
result := strings.Replace(string(contents), "\n", "", 1)
fmt.Println("Use ioutil.ReadFile to read a file:", result)
return result, nil
} else {
return "", err
}
}
+11
View File
@@ -0,0 +1,11 @@
package models
import (
"time"
)
type BaseModel struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
}
+16
View File
@@ -0,0 +1,16 @@
package models
type Post struct {
PostId int `gorm:"primaryKey;autoIncrement" json:"postId"` //岗位编号
PostName string `gorm:"size:128;" json:"postName"` //岗位名称
PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码
Sort int `gorm:"" json:"sort"` //岗位排序
Status string `gorm:"size:4;" json:"status"` //状态
Remark string `gorm:"size:255;" json:"remark"` //描述
ModelTime
ControlBy
}
func (Post) TableName() string {
return "sys_post"
}

Some files were not shown because too many files have changed in this diff Show More