diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..2e08b34c --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -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 diff --git a/.github/workflows/dev-lwx.yml b/.github/workflows/dev-lwx.yml new file mode 100644 index 00000000..b62a4c6b --- /dev/null +++ b/.github/workflows/dev-lwx.yml @@ -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' diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 91d18fff..64457815 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.14 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.14 id: go - name: Check out code into the Go module directory diff --git a/.gitignore b/.gitignore index d3f12f85..ce6fd6bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea .vscode +*/.DS_Store static/uploadfile main.exe go-admin @@ -14,4 +15,10 @@ config/settings.dev.*.yml.log temp/logs config/settings.dev.yml.log config/settings.b.dev.yml -cmd/migrate/migration/version_local/* +cmd/migrate/migration/version-local/* +!cmd/migrate/migration/version-local/doc.go +*/.DS_Store + +# go sum +go.sum +config/settings.deva.yml diff --git a/Dockerfile b/Dockerfile index 94dc8c03..71c81a82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ - FROM golang:alpine as builder -MAINTAINER xxx +MAINTAINER lwnmengjing ENV GOPROXY https://goproxy.cn/ @@ -9,7 +8,7 @@ WORKDIR /go/release RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk update && apk add tzdata -COPY ./go.mod ./go.mod +COPY go.mod ./go.mod RUN go mod download COPY . . RUN pwd && ls @@ -19,11 +18,9 @@ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o FROM alpine COPY --from=builder /go/release/go-admin / -COPY --from=builder /go/release/config/ /config/ 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"] \ No newline at end of file diff --git a/README.en.md b/README.en.md index 6e997ba0..196790d9 100644 --- a/README.en.md +++ b/README.en.md @@ -23,6 +23,10 @@ - GORM-based database storage that can expand many types of databases - Simple model mapping of configuration files to quickly get the desired configuration + +- Form builder + +- Multi command mode - TODO: unit test @@ -39,102 +43,90 @@ 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. +11. Multi command mode code generation: according to the data table structure to generate the corresponding business, all visual programming, basic business can be 0 code. +12. Form construction: Customize page style, drag and drop to achieve page layout. +13. Service monitoring: view the basic information of some servers. -## Configuration details +## 🗞 System architecture -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 -``` +
+
+
![]() |
+ ![]() |
+ ![]() |
+
| This QQ group is full | +![]() |
+
+
+
## 🤝 Open source projects used
@@ -169,20 +206,10 @@ Demo address:[http://www.zhangwj.com](http://www.zhangwj.com/#/login)
-## 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)
+2. [chengxiao](https://github.com/chengxiao)
+
## License
@@ -191,4 +218,4 @@ I saw a lot of friends who experience the wrong verification code, so I adjusted
Copyright (c) 2020 wenjianzhang
-[中文]qq technical exchange group: 74520518
+[中文]qq technical exchange group: 74520518
\ No newline at end of file
diff --git a/README.md b/README.md
index dd22d0fb..52190193 100644
--- a/README.md
+++ b/README.md
@@ -18,18 +18,20 @@ go-admin已经从wenjianzhang/go-admin 迁移到go-admin-team/go-admin,为了
- [English](https://github.com/wenjianzhang/go-admin/blob/master/README.en.md) | 简体中文
+ [English](https://github.com/go-admin-team/go-admin/blob/master/README.en.md) | 简体中文
##### 基于Gin + Vue + Element UI的前后端分离权限管理系统
系统初始化极度简单,只需要配置文件中,修改数据库连接,系统启动后会自动初始化数据库信息以及必须的基础数据
-[在线文档国际](https://wenjianzhang.github.io/go-admin-site)
+[在线文档](https://doc.go-admin.dev)
-[在线文档国内](http://mydearzwj.gitee.io/go-admin-site/)
+[github在线文档](https://wenjianzhang.github.io)
-[前端项目](https://github.com/wenjianzhang/go-admin-ui)
+[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)
@@ -130,10 +132,10 @@ cd goadmin
```bash
# 获取后端代码
-git clone https://github.com/wenjianzhang/go-admin.git
+git clone https://github.com/go-admin-team/go-admin.git
# 获取前端代码
-git clone https://github.com/wenjianzhang/go-admin-ui.git
+git clone https://github.com/go-admin-team/go-admin-ui.git
```
@@ -158,15 +160,44 @@ vi ./config/setting.yml
# 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
# 首次配置需要初始化数据库资源信息
-./go-admin migrate -c config/settings.yml -m dev
+# macOS or linux 下使用
+$ ./go-admin migrate -c=config/settings.dev.yml
+
+# ⚠️注意:windows 下使用
+$ go-admin.exe migrate -c=config/settings.dev.yml
# 启动项目,也可以用IDE进行调试
-./go-admin server -c config/settings.yml -p 8000 -m dev
+# macOS or linux 下使用
+$ ./go-admin server -c config/settings.yml
+
+# ⚠️注意:windows 下使用
+$ go-admin.exe server -c config/settings.yml
```
#### 使用docker 编译启动
@@ -176,7 +207,8 @@ vi ./config/setting.yml
docker build -t go-admin .
# 启动容器,第一个go-admin是容器名字,第二个go-admin是镜像名称
-docker run --name go-admin -p 8000:8000 -d go-admin
+# -v 映射配置文件 本地路径:容器路径
+docker run --name go-admin -p 8000:8000 -v /config/settings.yml:/config/settings.yml -d go-admin-server
```
@@ -184,18 +216,16 @@ docker run --name go-admin -p 8000:8000 -d go-admin
#### 文档生成
```bash
-swag init
-
-# 如果没有swag命令 go get安装一下即可
-go get -u github.com/swaggo/swag/cmd/swag
+go generate
```
#### 交叉编译
```bash
+# windows
env GOOS=windows GOARCH=amd64 go build main.go
# or
-
+# linux
env GOOS=linux GOARCH=amd64 go build main.go
```
@@ -215,7 +245,7 @@ npm run dev
## 🎬 在线体验
> admin / 123456
-演示地址:[http://www.zhangwj.com](http://www.zhangwj.com/#/login)
+演示地址:[http://www.go-admin.dev](http://www.go-admin.dev/#/login)
## 📨 互动
@@ -232,18 +262,33 @@ npm run dev

+
## 🤝 特别感谢
-[chengxiao](https://github.com/chengxiao)
-[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)
+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)
## 🤟 打赏
@@ -258,9 +303,11 @@ npm run dev
zhuqiyun LLL狐 星星之火 cjj770 Sam 唐*i 晓聪 aLong *渊 海马 魏镇坪 + 111 *哥 我的宇哥哥 *声 *节
+## 🤝 链接
+[Go开发者成长线路图](http://www.golangroadmap.com/)
+
## 🔑 License
-[MIT](https://github.com/wenjianzhang/go-admin/blob/master/LICENSE.md)
+[MIT](https://github.com/go-admin-team/go-admin/blob/master/LICENSE.md)
Copyright (c) 2020 wenjianzhang
-
diff --git a/app/admin/apis/log/loginlog.go b/app/admin/apis/log/loginlog.go
deleted file mode 100644
index 6f36f402..00000000
--- a/app/admin/apis/log/loginlog.go
+++ /dev/null
@@ -1,134 +0,0 @@
-package log
-
-import (
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
-)
-
-// @Summary 登录日志列表
-// @Description 获取JSON
-// @Tags 登录日志
-// @Param status query string false "status"
-// @Param dictCode query string false "dictCode"
-// @Param dictType query string false "dictType"
-// @Param pageSize query int false "页条数"
-// @Param pageIndex query int false "页码"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/loginloglist [get]
-// @Security Bearer
-func GetLoginLogList(c *gin.Context) {
- var data models.LoginLog
- var err error
- var pageSize = 10
- var pageIndex = 1
-
- size := c.Request.FormValue("pageSize")
- if size != "" {
- pageSize, err = tools.StringToInt(size)
- }
-
- index := c.Request.FormValue("pageIndex")
- if index != "" {
- pageIndex, err = tools.StringToInt(index)
- }
-
- data.Username = c.Request.FormValue("username")
- data.Status = c.Request.FormValue("status")
- data.Ipaddr = c.Request.FormValue("ipaddr")
- result, count, err := data.GetPage(pageSize, pageIndex)
- tools.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())
-}
-
-// @Summary 通过编码获取登录日志
-// @Description 获取JSON
-// @Tags 登录日志
-// @Param infoId path int true "infoId"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/loginlog/{infoId} [get]
-// @Security Bearer
-func GetLoginLog(c *gin.Context) {
- var LoginLog models.LoginLog
- LoginLog.InfoId, _ = tools.StringToInt(c.Param("infoId"))
- result, err := LoginLog.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
-
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 添加登录日志
-// @Description 获取JSON
-// @Tags 登录日志
-// @Accept application/json
-// @Product application/json
-// @Param data body models.LoginLog true "data"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/loginlog [post]
-// @Security Bearer
-func InsertLoginLog(c *gin.Context) {
- var data models.LoginLog
- err := c.BindWith(&data, binding.JSON)
- tools.HasError(err, "", 500)
- result, err := data.Create()
- tools.HasError(err, "", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 修改登录日志
-// @Description 获取JSON
-// @Tags 登录日志
-// @Accept application/json
-// @Product application/json
-// @Param data body models.LoginLog true "body"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/loginlog [put]
-// @Security Bearer
-func UpdateLoginLog(c *gin.Context) {
- var data models.LoginLog
- err := c.BindWith(&data, binding.JSON)
- tools.HasError(err, "", -1)
- result, err := data.Update(data.InfoId)
- tools.HasError(err, "", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 批量删除登录日志
-// @Description 删除数据
-// @Tags 登录日志
-// @Param infoId path string true "以逗号(,)分割的infoId"
-// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
-// @Router /api/v1/loginlog/{infoId} [delete]
-func DeleteLoginLog(c *gin.Context) {
- var data models.LoginLog
- data.UpdateBy = tools.GetUserIdStr(c)
- IDS := tools.IdsStrToIdsIntGroup("infoId", c)
- _, err := data.BatchDelete(IDS)
- tools.HasError(err, "修改失败", 500)
- var res app.Response
- res.Msg = "删除成功"
- c.JSON(http.StatusOK, res.ReturnOK())
-}
diff --git a/app/admin/apis/log/operlog.go b/app/admin/apis/log/operlog.go
deleted file mode 100644
index 2e5a8dd6..00000000
--- a/app/admin/apis/log/operlog.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package log
-
-import (
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
-)
-
-// @Summary 登录日志列表
-// @Description 获取JSON
-// @Tags 登录日志
-// @Param status query string false "status"
-// @Param dictCode query string false "dictCode"
-// @Param dictType query string false "dictType"
-// @Param pageSize query int false "页条数"
-// @Param pageIndex query int false "页码"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/operloglist [get]
-// @Security Bearer
-func GetOperLogList(c *gin.Context) {
- var data models.SysOperLog
- var err error
- var pageSize = 10
- var pageIndex = 1
-
- size := c.Request.FormValue("pageSize")
- if size != "" {
- pageSize, err = tools.StringToInt(size)
- }
-
- index := c.Request.FormValue("pageIndex")
- if index != "" {
- pageIndex, err = tools.StringToInt(index)
- }
-
- data.OperName = c.Request.FormValue("operName")
- data.Status = c.Request.FormValue("status")
- data.OperIp = c.Request.FormValue("operIp")
- result, count, err := data.GetPage(pageSize, pageIndex)
- tools.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())
-}
-
-// @Summary 通过编码获取登录日志
-// @Description 获取JSON
-// @Tags 登录日志
-// @Param infoId path int true "infoId"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/operlog/{infoId} [get]
-// @Security Bearer
-func GetOperLog(c *gin.Context) {
- var OperLog models.SysOperLog
- OperLog.OperId, _ = tools.StringToInt(c.Param("operId"))
- result, err := OperLog.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 添加操作日志
-// @Description 获取JSON
-// @Tags 操作日志
-// @Accept application/json
-// @Product application/json
-// @Param data body models.SysOperLog true "data"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/operlog [post]
-// @Security Bearer
-func InsertOperLog(c *gin.Context) {
- var data models.SysOperLog
- err := c.BindWith(&data, binding.JSON)
- tools.HasError(err, "", 500)
- result, err := data.Create()
- tools.HasError(err, "", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 批量删除操作日志
-// @Description 删除数据
-// @Tags 操作日志
-// @Param operId path string true "以逗号(,)分割的operId"
-// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
-// @Router /api/v1/operlog/{operId} [delete]
-func DeleteOperLog(c *gin.Context) {
- var data models.SysOperLog
- data.UpdateBy = tools.GetUserIdStr(c)
- IDS := tools.IdsStrToIdsIntGroup("operId", c)
- _, err := data.BatchDelete(IDS)
- tools.HasError(err, "删除失败", 500)
- var res app.Response
- res.Msg = "删除成功"
- c.JSON(http.StatusOK, res.ReturnOK())
-}
diff --git a/app/admin/apis/monitor/server.go b/app/admin/apis/monitor/server.go
index 48928fe2..9e5b2329 100644
--- a/app/admin/apis/monitor/server.go
+++ b/app/admin/apis/monitor/server.go
@@ -4,12 +4,13 @@ import (
"runtime"
"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/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
- "go-admin/tools"
- "go-admin/tools/app"
+ "go-admin/common/apis"
)
const (
@@ -19,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
@@ -33,8 +39,8 @@ func ServerInfo(c *gin.Context) {
osDic["compiler"] = runtime.Compiler
osDic["version"] = runtime.Version()
osDic["numGoroutine"] = runtime.NumGoroutine()
- osDic["ip"] = tools.GetLocaHonst()
- osDic["projectDir"] = tools.GetCurrentPath()
+ osDic["ip"] = pkg.GetLocaHonst()
+ osDic["projectDir"] = pkg.GetCurrentPath()
dis, _ := disk.Usage("/")
diskTotalGB := int(dis.Total) / GB
@@ -57,10 +63,10 @@ func ServerInfo(c *gin.Context) {
cpuDic := make(map[string]interface{}, 0)
cpuDic["cpuInfo"], _ = cpu.Info()
percent, _ := cpu.Percent(0, false)
- cpuDic["Percent"] = tools.Round(percent[0], 2)
+ 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,
diff --git a/app/admin/apis/public/file.go b/app/admin/apis/public/file.go
index 0068a50e..42a4aca7 100644
--- a/app/admin/apis/public/file.go
+++ b/app/admin/apis/public/file.go
@@ -8,12 +8,12 @@ import (
"strings"
"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/utils"
"github.com/google/uuid"
- imgType "github.com/shamsher31/goimgtype"
- "go-admin/pkg/utils"
- "go-admin/tools"
- "go-admin/tools/app"
+ "go-admin/common/apis"
+ "go-admin/common/file_store"
)
type FileResponse struct {
@@ -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,72 +39,161 @@ 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": // 单图
- files, err := c.FormFile("file")
- if err != nil {
- app.Error(c, 200, errors.New(""), "图片不能为空")
+ var done bool
+ fileResponse, done = e.singleFile(c, fileResponse, urlPerfix)
+ if done {
return
}
- // 上传文件至指定目录
- guid := uuid.New().String()
-
- singleFile := "static/uploadfile/" + guid + utils.GetExt(files.Filename)
- _ = c.SaveUploadedFile(files, singleFile)
- fileType, _ := imgType.Get(singleFile)
- fileResponse = FileResponse{
- Size: tools.GetFileSize(singleFile),
- Path: singleFile,
- FullPath: urlPerfix + singleFile,
- Name: files.Filename,
- Type: fileType,
- }
- app.OK(c, fileResponse, "上传成功")
+ e.OK(fileResponse, "上传成功")
return
case "2": // 多图
- files := c.Request.MultipartForm.File["file"]
- var multipartFile []FileResponse
- for _, f := range files {
- guid := uuid.New().String()
- multipartFileName := "static/uploadfile/" + guid + utils.GetExt(f.Filename)
- e := c.SaveUploadedFile(f, multipartFileName)
- fileType, _ := imgType.Get(multipartFileName)
- if e == nil {
- multipartFile = append(multipartFile, FileResponse{
- Size: tools.GetFileSize(multipartFileName),
- Path: multipartFileName,
- FullPath: urlPerfix + multipartFileName,
- Name: f.Filename,
- Type: fileType,
- })
- }
- }
- app.OK(c, multipartFile, "上传成功")
+ multipartFile := e.multipleFile(c, urlPerfix)
+ e.OK(multipartFile, "上传成功")
return
case "3": // base64
- files, _ := c.GetPostForm("file")
- file2list := strings.Split(files, ",")
- ddd, _ := base64.StdEncoding.DecodeString(file2list[1])
- guid := uuid.New().String()
- base64File := "static/uploadfile/" + guid + ".jpg"
- _ = ioutil.WriteFile(base64File, ddd, 0666)
- typeStr := strings.Replace(strings.Replace(file2list[0], "data:", "", -1), ";base64", "", -1)
- fileResponse = FileResponse{
- Size: tools.GetFileSize(base64File),
- Path: base64File,
- FullPath: urlPerfix + base64File,
- Name: "",
- Type: typeStr,
- }
- app.OK(c, fileResponse, "上传成功")
+ fileResponse = e.baseImg(c, fileResponse, urlPerfix)
+ e.OK(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"
+ 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{
+ Size: pkg.GetFileSize(base64File),
+ Path: base64File,
+ FullPath: urlPerfix + base64File,
+ Name: "",
+ Type: typeStr,
+ }
+ source, _ := c.GetPostForm("source")
+ err = thirdUpload(source, fileName, base64File)
+ if err != nil {
+ e.Error(200, errors.New(""), "上传第三方失败")
+ return fileResponse
+ }
+ if source != "1" {
+ fileResponse.Path = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
+ fileResponse.FullPath = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
+ }
+ return 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)
+
+ 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 err1 == nil {
+ err := thirdUpload(source, fileName, multipartFileName)
+ if err != nil {
+ e.Error(500, errors.New(""), "上传第三方失败")
+ } else {
+ fileResponse := FileResponse{
+ Size: pkg.GetFileSize(multipartFileName),
+ Path: multipartFileName,
+ FullPath: urlPerfix + multipartFileName,
+ Name: f.Filename,
+ Type: fileType,
+ }
+ if source != "1" {
+ fileResponse.Path = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
+ fileResponse.FullPath = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
+ }
+ multipartFile = append(multipartFile, fileResponse)
+ }
+ }
+ }
+ return multipartFile
+}
+
+func (e File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) {
+ files, err := c.FormFile("file")
+
+ if err != nil {
+ e.Error(200, errors.New(""), "图片不能为空")
+ return FileResponse{}, true
+ }
+ // 上传文件至指定目录
+ guid := uuid.New().String()
+
+ fileName := guid + utils.GetExt(files.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{
+ Size: pkg.GetFileSize(singleFile),
+ Path: singleFile,
+ FullPath: urlPerfix + singleFile,
+ Name: files.Filename,
+ Type: fileType,
+ }
+ source, _ := c.GetPostForm("source")
+ err = thirdUpload(source, fileName, singleFile)
+ if err != nil {
+ e.Error(200, errors.New(""), "上传第三方失败")
+ return FileResponse{}, true
+ }
+ fileResponse.Path = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
+ fileResponse.FullPath = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName
+ return fileResponse, false
+}
+
+func thirdUpload(source string, name string, path string) error {
+ switch source {
+ case "2":
+ return ossUpload("img/"+name, path)
+ case "3":
+ return qiniuUpload("img/"+name, path)
+ }
+ return nil
+}
+
+func ossUpload(name string, path string) error {
+ oss := file_store.ALiYunOSS{}
+ return oss.UpLoad(name, path)
+}
+
+func qiniuUpload(name string, path string) error {
+ oss := file_store.ALiYunOSS{}
+ return oss.UpLoad(name, path)
+}
diff --git a/app/admin/apis/sys_china_area_data/sys_china_area_data.go b/app/admin/apis/sys_china_area_data/sys_china_area_data.go
new file mode 100644
index 00000000..bdf82982
--- /dev/null
+++ b/app/admin/apis/sys_china_area_data/sys_china_area_data.go
@@ -0,0 +1,195 @@
+package sys_china_area_data
+
+import (
+ "net/http"
+
+ "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/service"
+ "go-admin/app/admin/service/dto"
+ "go-admin/common/actions"
+ "go-admin/common/apis"
+)
+
+type SysChinaAreaData struct {
+ apis.Api
+}
+
+func (e SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) {
+ e.SetContext(c)
+ log := e.GetLogger()
+ d := new(dto.SysChinaAreaDataSearch)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //查询列表
+ err = d.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ list := make([]models.SysChinaAreaData, 0)
+ var count int64
+ serviceStudent := service.SysChinaAreaData{}
+ serviceStudent.Log = log
+ serviceStudent.Orm = db
+ err = serviceStudent.GetSysChinaAreaDataPage(d, p, &list, &count)
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
+}
+
+func (e SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) {
+ e.SetContext(c)
+ log := e.GetLogger()
+ control := new(dto.SysChinaAreaDataById)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //查看详情
+ err = control.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object models.SysChinaAreaData
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysChinaAreaData := service.SysChinaAreaData{}
+ serviceSysChinaAreaData.Log = log
+ serviceSysChinaAreaData.Orm = db
+ err = serviceSysChinaAreaData.GetSysChinaAreaData(control, p, &object)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "查询失败")
+ return
+ }
+
+ e.OK(object, "查看成功")
+}
+
+func (e SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) {
+ e.SetContext(c)
+ log := e.GetLogger()
+ control := new(dto.SysChinaAreaDataControl)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //新增操作
+ err = control.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ object, err := control.Generate()
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "模型生成失败")
+ return
+ }
+ // 设置创建人
+ object.SetCreateBy(user.GetUserId(c))
+
+ serviceSysChinaAreaData := service.SysChinaAreaData{}
+ serviceSysChinaAreaData.Orm = db
+ serviceSysChinaAreaData.Log = log
+ err = serviceSysChinaAreaData.InsertSysChinaAreaData(object)
+ if err != nil {
+ log.Error(err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+
+ e.OK(object.GetId(), "创建成功")
+}
+
+func (e SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) {
+ e.SetContext(c)
+ log := e.GetLogger()
+ control := new(dto.SysChinaAreaDataControl)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //更新操作
+ err = control.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ object, err := control.Generate()
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "模型生成失败")
+ return
+ }
+ object.SetUpdateBy(user.GetUserId(c))
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysChinaAreaData := service.SysChinaAreaData{}
+ serviceSysChinaAreaData.Orm = db
+ serviceSysChinaAreaData.Log = log
+ err = serviceSysChinaAreaData.UpdateSysChinaAreaData(object, p)
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ e.OK(object.GetId(), "更新成功")
+}
+
+func (e SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) {
+ e.SetContext(c)
+ log := e.GetLogger()
+ control := new(dto.SysChinaAreaDataById)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //删除操作
+ err = control.Bind(c)
+ if err != nil {
+ log.Errorf("Bind error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ // 设置编辑人
+ control.SetUpdateBy(user.GetUserId(c))
+
+ // 数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysChinaAreaData := service.SysChinaAreaData{}
+ serviceSysChinaAreaData.Orm = db
+ serviceSysChinaAreaData.Log = log
+ err = serviceSysChinaAreaData.RemoveSysChinaAreaData(control, p)
+ if err != nil {
+ log.Errorf("RemoveSysChinaAreaData error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "删除失败")
+ return
+ }
+ e.OK(control.GetId(), "删除成功")
+}
\ No newline at end of file
diff --git a/app/admin/apis/sys_file/sys_file_dir.go b/app/admin/apis/sys_file/sys_file_dir.go
new file mode 100644
index 00000000..d275638c
--- /dev/null
+++ b/app/admin/apis/sys_file/sys_file_dir.go
@@ -0,0 +1,198 @@
+package sys_file
+
+import (
+ "net/http"
+
+ "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"
+
+ "go-admin/app/admin/models"
+ "go-admin/app/admin/service"
+ "go-admin/app/admin/service/dto"
+ "go-admin/common/actions"
+ "go-admin/common/apis"
+)
+
+type SysFileDir struct {
+ apis.Api
+}
+
+func (e SysFileDir) GetSysFileDirList(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ search := new(dto.SysFileDirSearch)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ err = c.ShouldBind(search)
+ if err != nil {
+ log.Debugf("ShouldBind error: %s", err.Error())
+ }
+
+ var list *[]models.SysFileDirL
+ serviceStudent := service.SysFileDir{}
+ serviceStudent.Log = log
+ serviceStudent.Orm = db
+ list, err = serviceStudent.SetSysFileDir(search)
+ if err != nil {
+ log.Errorf("SetSysFileDir error, %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "查询失败")
+ return
+ }
+
+ e.OK(list, "查询成功")
+}
+
+func (e SysFileDir) GetSysFileDir(c *gin.Context) {
+ control := new(dto.SysFileDirById)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //查看详情
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("ShouldBindUri error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ }
+
+ var object models.SysFileDir
+
+ serviceSysFileDir := service.SysFileDir{}
+ serviceSysFileDir.Log = log
+ serviceSysFileDir.Orm = db
+ err = serviceSysFileDir.GetSysFileDir(control, &object)
+ if err != nil {
+ log.Errorf("GetSysFileDir error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.OK(object, "查看成功")
+}
+
+func (e SysFileDir) InsertSysFileDir(c *gin.Context) {
+ control := new(dto.SysFileDirControl)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //新增操作
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("ShouldBindUri error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ err = c.ShouldBind(control)
+ if err != nil {
+ log.Warnf("ShouldBind error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ // 设置创建人
+ control.CreateBy = user.GetUserId(c)
+
+ serviceSysFileDir := service.SysFileDir{}
+ serviceSysFileDir.Orm = db
+ serviceSysFileDir.Log = log
+ err = serviceSysFileDir.InsertSysFileDir(control)
+ if err != nil {
+ log.Errorf("InsertSysFileDir error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+
+ e.OK(control.ID, "创建成功")
+}
+
+func (e SysFileDir) UpdateSysFileDir(c *gin.Context) {
+ control := new(dto.SysFileDirControl)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("ShouldBindUri error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ }
+ err = c.ShouldBind(control)
+ if err != nil {
+ log.Warnf("ShouldBind error: %#v", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ }
+ // 设置创建人
+ control.UpdateBy = user.GetUserId(c)
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysFileDir := service.SysFileDir{}
+ serviceSysFileDir.Orm = db
+ serviceSysFileDir.Log = log
+ err = serviceSysFileDir.UpdateSysFileDir(control, p)
+ if err != nil {
+ log.Errorf("UpdateSysFileDir error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "更新失败")
+ return
+ }
+ e.OK(control.ID, "更新成功")
+}
+
+func (e SysFileDir) DeleteSysFileDir(c *gin.Context) {
+ control := new(dto.SysFileDirById)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ msgID := pkg.GenerateMsgIDFromContext(c)
+ //删除操作
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ }
+ err = c.ShouldBind(control)
+ if err != nil {
+ log.Warnf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ }
+
+ // 设置编辑人
+ control.UpdateBy = user.GetUserId(c)
+
+ // 数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysFileDir := service.SysFileDir{}
+ serviceSysFileDir.Orm = db
+ serviceSysFileDir.MsgID = msgID
+ err = serviceSysFileDir.RemoveSysFileDir(control, p)
+ if err != nil {
+ log.Errorf("RemoveSysFileDir error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "删除失败")
+ return
+ }
+ e.OK(control.Id, "删除成功")
+}
diff --git a/app/admin/apis/sys_file/sys_file_info.go b/app/admin/apis/sys_file/sys_file_info.go
new file mode 100644
index 00000000..637743bf
--- /dev/null
+++ b/app/admin/apis/sys_file/sys_file_info.go
@@ -0,0 +1,209 @@
+package sys_file
+
+import (
+ "net/http"
+
+ "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/service"
+ "go-admin/app/admin/service/dto"
+ "go-admin/common/actions"
+ "go-admin/common/apis"
+)
+
+type SysFileInfo struct {
+ apis.Api
+}
+
+func (e SysFileInfo) GetSysFileInfoList(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ search := new(dto.SysFileInfoSearch)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ err = c.ShouldBind(search)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ list := make([]models.SysFileInfo, 0)
+ var count int64
+ serviceStudent := service.SysFileInfo{}
+ serviceStudent.Log = log
+ serviceStudent.Orm = db
+ err = serviceStudent.GetSysFileInfoPage(search, p, &list, &count)
+ if err != nil {
+ log.Errorf("GetSysFileInfoPage error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.PageOK(list, int(count), search.PageIndex, search.PageSize, "查询成功")
+}
+
+func (e SysFileInfo) GetSysFileInfo(c *gin.Context) {
+ control := new(dto.SysFileInfoById)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //查看详情
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("参数验证错误, error:%s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ var object models.SysFileInfo
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysFileInfo := service.SysFileInfo{}
+ serviceSysFileInfo.Log = log
+ serviceSysFileInfo.Orm = db
+ err = serviceSysFileInfo.GetSysFileInfo(control, p, &object)
+ if err != nil {
+ log.Errorf("GetSysFileInfo error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.OK(object, "查看成功")
+}
+
+func (e SysFileInfo) InsertSysFileInfo(c *gin.Context) {
+ control := new(dto.SysFileInfoControl)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //新增操作
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ err = c.ShouldBind(control)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ // 设置创建人
+ control.CreateBy = user.GetUserId(c)
+
+ serviceSysFileInfo := service.SysFileInfo{}
+ serviceSysFileInfo.Orm = db
+ serviceSysFileInfo.Log = log
+ err = serviceSysFileInfo.InsertSysFileInfo(control)
+ if err != nil {
+ log.Errorf("InsertSysFileInfo error: %s", err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+
+ e.OK(control.ID, "创建成功")
+}
+
+func (e SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
+ control := new(dto.SysFileInfoControl)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ err = c.ShouldBind(control)
+ if err != nil {
+ log.Warnf("参数验证错误, error:%s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ // 设置创建人
+ control.UpdateBy = user.GetUserId(c)
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysFileInfo := service.SysFileInfo{}
+ serviceSysFileInfo.Orm = db
+ serviceSysFileInfo.Log = log
+ err = serviceSysFileInfo.UpdateSysFileInfo(control, p)
+ if err != nil {
+ log.Errorf("UpdateSysFileInfo error: %s", err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+ e.OK(control.ID, "更新成功")
+}
+
+func (e SysFileInfo) DeleteSysFileInfo(c *gin.Context) {
+ control := new(dto.SysFileInfoById)
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //删除操作
+ err = c.ShouldBindUri(control)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(422, err, "参数验证失败")
+ return
+ }
+ err = c.ShouldBind(control)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(422, err, "参数验证失败")
+ return
+ }
+
+ // 设置编辑人
+ control.UpdateBy = user.GetUserId(c)
+
+ // 数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysFileInfo := service.SysFileInfo{}
+ serviceSysFileInfo.Orm = db
+ serviceSysFileInfo.Log = log
+ err = serviceSysFileInfo.RemoveSysFileInfo(control, p)
+ if err != nil {
+ log.Errorf("RemoveSysFileInfo error: %s", err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+ e.OK(control.Id, "删除成功")
+}
diff --git a/app/admin/apis/sys_job/sys_job.go b/app/admin/apis/sys_job/sys_job.go
new file mode 100644
index 00000000..c0667ddd
--- /dev/null
+++ b/app/admin/apis/sys_job/sys_job.go
@@ -0,0 +1,73 @@
+package sys_job
+
+import (
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+ "github.com/go-admin-team/go-admin-core/sdk"
+ "go-admin/app/admin/service"
+ "go-admin/common/apis"
+ "go-admin/common/dto"
+)
+
+type SysJob struct {
+ apis.Api
+}
+
+// RemoveJobForService 调用service实现
+func (e SysJob) RemoveJobForService(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ var v dto.GeneralDelDto
+ err = c.Bind(&v)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ s := service.SysJob{}
+ s.Log = log
+ s.Orm = db
+ s.Cron = sdk.Runtime.GetCrontabKey(c.Request.Host)
+ err = s.RemoveJob(&v)
+ if err != nil {
+ log.Errorf("RemoveJob error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "")
+ return
+ }
+ e.OK(nil, s.Msg)
+}
+
+// StartJobForService 启动job service实现
+func (e SysJob) StartJobForService(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ var v dto.GeneralGetDto
+ err = c.BindUri(&v)
+ if err != nil {
+ log.Warnf("参数验证错误, error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ s := service.SysJob{}
+ s.Orm = db
+ s.Log = log
+ s.Cron = sdk.Runtime.GetCrontabKey(c.Request.Host)
+ err = s.StartJob(&v)
+ if err != nil {
+ log.Errorf("GetCrontabKey error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "")
+ return
+ }
+ e.OK(nil, s.Msg)
+}
diff --git a/app/admin/apis/sys_user/sys_user.go b/app/admin/apis/sys_user/sys_user.go
new file mode 100644
index 00000000..3a04a1a7
--- /dev/null
+++ b/app/admin/apis/sys_user/sys_user.go
@@ -0,0 +1,472 @@
+package sys_user
+
+import (
+ "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"
+ "github.com/google/uuid"
+
+ "go-admin/app/admin/models/system"
+ "go-admin/app/admin/service"
+ "go-admin/app/admin/service/dto"
+ "go-admin/common/actions"
+ "go-admin/common/apis"
+ common "go-admin/common/models"
+)
+
+type SysUser struct {
+ apis.Api
+}
+
+// @Summary 列表用户信息数据
+// @Description 获取JSON
+// @Tags 用户
+// @Param username query string false "username"
+// @Success 200 {string} string "{"code": 200, "data": [...]}"
+// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
+// @Router /api/v1/sysUser [get]
+// @Security Bearer
+func (e SysUser) GetSysUserList(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ d := new(dto.SysUserSearch)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := d.Generate()
+
+ //查询列表
+ err = req.Bind(c)
+ if err != nil {
+ log.Warnf("Bind error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ list := make([]system.SysUser, 0)
+ var count int64
+ serviceStudent := service.SysUser{}
+ serviceStudent.Log = log
+ serviceStudent.Orm = db
+ err = serviceStudent.GetSysUserPage(req, p, &list, &count)
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+}
+
+// @Summary 获取用户
+// @Description 获取JSON
+// @Tags 用户
+// @Param userId path int true "用户编码"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/v1/sysUser/{userId} [get]
+// @Security Bearer
+func (e SysUser) GetSysUser(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ control := new(dto.SysUserById)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //查看详情
+ req := control.Generate()
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object system.SysUser
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Log = log
+ serviceSysUser.Orm = db
+ err = serviceSysUser.GetSysUser(req, p, &object)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "查询失败")
+ return
+ }
+
+ e.OK(object, "查看成功")
+}
+
+// @Summary 创建用户
+// @Description 获取JSON
+// @Tags 用户
+// @Accept application/json
+// @Product application/json
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ control := new(dto.SysUserControl)
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //新增操作
+ req := control.Generate()
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object common.ActiveRecord
+ object, err = req.GenerateM()
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "模型生成失败")
+ return
+ }
+ // 设置创建人
+ object.SetCreateBy(user.GetUserId(c))
+
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Orm = db
+ serviceSysUser.Log = log
+ err = serviceSysUser.InsertSysUser(object)
+ if err != nil {
+ log.Error(err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+
+ e.OK(object.GetId(), "创建成功")
+}
+
+// @Summary 修改用户数据
+// @Description 获取JSON
+// @Tags 用户
+// @Accept application/json
+// @Product application/json
+// @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) {
+ control := new(dto.SysUserControl)
+
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := control.Generate()
+ //更新操作
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object common.ActiveRecord
+ object, err = req.GenerateM()
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "模型生成失败")
+ return
+ }
+ object.SetUpdateBy(user.GetUserId(c))
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Orm = db
+ serviceSysUser.Log = log
+ err = serviceSysUser.UpdateSysUser(object, p)
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ e.OK(object.GetId(), "更新成功")
+}
+
+// @Summary 删除用户数据
+// @Description 删除数据
+// @Tags 用户
+// @Param userId path int true "userId"
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ control := new(dto.SysUserById)
+
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //删除操作
+ req := control.Generate()
+ err = req.Bind(c)
+ if err != nil {
+ log.Errorf("Bind error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object common.ActiveRecord
+ object, err = req.GenerateM()
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "模型生成失败")
+ return
+ }
+
+ // 设置编辑人
+ object.SetUpdateBy(user.GetUserId(c))
+
+ // 数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Orm = db
+ serviceSysUser.Log = log
+ err = serviceSysUser.RemoveSysUser(req, object, p)
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ e.OK(object.GetId(), "删除成功")
+}
+
+// @Summary 修改头像
+// @Description 获取JSON
+// @Tags 用户
+// @Accept multipart/form-data
+// @Param file formData file true "file"
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ // 数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ form, _ := c.MultipartForm()
+ files := form.File["upload[]"]
+ guid := uuid.New().String()
+ filPath := "static/uploadfile/" + guid + ".jpg"
+ for _, file := range files {
+ log.Debugf("upload avatar file: %s", file.Filename)
+ // 上传文件至指定目录
+ err = c.SaveUploadedFile(file, filPath)
+ if err != nil {
+ log.Errorf("save file error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "")
+ return
+ }
+ }
+
+ object := &system.SysUser{
+ UserId: p.UserId,
+ Avatar: "/" + filPath,
+ }
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Orm = db
+ serviceSysUser.Log = log
+ err = serviceSysUser.UpdateSysUser(object, p)
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ e.OK(filPath, "修改成功")
+}
+
+// @Summary 重置密码
+// @Description 获取JSON
+// @Tags 用户
+// @Accept application/json
+// @Product application/json
+// @Param data body dto.PassWord true "body"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/v1/user/pwd [post]
+// @Security Bearer
+func (e SysUser) SysUserUpdatePwd(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ var pwd dto.PassWord
+ err = c.Bind(&pwd)
+ if err != nil {
+ log.Errorf("Bind error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ // 数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Orm = db
+ serviceSysUser.Log = log
+ 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(nil, "密码修改成功")
+}
+
+// @Summary 获取个人中心用户
+// @Description 获取JSON
+// @Tags 个人中心
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/v1/user/profile [get]
+// @Security Bearer
+func (e SysUser) GetSysUserProfile(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ id := user.GetUserId(c)
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Log = log
+ serviceSysUser.Orm = db
+ user := new(system.SysUser)
+ roles := make([]system.SysRole, 0)
+ posts := make([]system.SysPost, 0)
+ err = serviceSysUser.GetSysUserProfile(id, user, &roles, &posts)
+ if err != nil {
+ log.Errorf("get user profile error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "获取用户信息失败")
+ return
+ }
+ e.OK(gin.H{
+ "user": user,
+ "roles": roles,
+ "posts": posts,
+ }, "查询成功")
+ //var SysUser models.SysUser
+ //userId := tools.GetUserIdStr(c)
+ //SysUser.UserId, _ = tools.StringToInt(userId)
+ //result, err := SysUser.Get()
+ //tools.HasError(err, "抱歉未找到相关信息", -1)
+ //var SysRole models.SysRole
+ //var Post models.Post
+ //var Dept models.SysDepts
+ ////获取角色列表
+ //roles, err := SysRole.GetList()
+ ////获取职位列表
+ //posts, err := Post.GetList()
+ ////获取部门列表
+ //Dept.DeptId = result.DeptId
+ //dept, err := Dept.Get()
+ //
+ //postIds := make([]int, 0)
+ //postIds = append(postIds, result.PostId)
+ //
+ //roleIds := make([]int, 0)
+ //roleIds = append(roleIds, result.RoleId)
+ //
+ //app.Custum(c, gin.H{
+ // "code": 200,
+ // "data": result,
+ // "postIds": postIds,
+ // "roleIds": roleIds,
+ // "roles": roles,
+ // "posts": posts,
+ // "dept": dept,
+ //})
+}
+
+func (e SysUser) GetInfo(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //数据权限检查
+ p := actions.GetPermissionFromContext(c)
+
+ var roles = make([]string, 1)
+ roles[0] = user.GetRoleName(c)
+
+ var permissions = make([]string, 1)
+ permissions[0] = "*:*:*"
+
+ var buttons = make([]string, 1)
+ buttons[0] = "*:*:*"
+
+ RoleMenu := system.RoleMenu{}
+ RoleMenu.RoleId = user.GetRoleId(c)
+
+ var mp = make(map[string]interface{})
+ mp["roles"] = roles
+ if user.GetRoleName(c) == "admin" || user.GetRoleName(c) == "系统管理员" {
+ mp["permissions"] = permissions
+ mp["buttons"] = buttons
+ } else {
+ list, _ := RoleMenu.GetPermis(db)
+ mp["permissions"] = list
+ mp["buttons"] = list
+ }
+
+ var sysUser system.SysUser
+ req := new(dto.SysUserById)
+ req.Id = user.GetUserId(c)
+ serviceSysUser := service.SysUser{}
+ serviceSysUser.Log = log
+ serviceSysUser.Orm = db
+ err = serviceSysUser.GetSysUser(req, p, &sysUser)
+ if err != nil {
+ e.Error(http.StatusUnauthorized, err, "登录失败")
+ return
+ }
+
+ mp["introduction"] = " am a super administrator"
+
+ mp["avatar"] = "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"
+ if sysUser.Avatar != "" {
+ mp["avatar"] = sysUser.Avatar
+ }
+ mp["userName"] = sysUser.NickName
+ mp["userId"] = sysUser.UserId
+ mp["deptId"] = sysUser.DeptId
+ mp["name"] = sysUser.NickName
+ e.OK(mp, "")
+}
diff --git a/app/admin/apis/syscategory/syscategory.go b/app/admin/apis/syscategory/syscategory.go
deleted file mode 100644
index 03181dea..00000000
--- a/app/admin/apis/syscategory/syscategory.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package syscategory
-
-import (
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/app/msg"
-)
-
-func GetSysCategoryList(c *gin.Context) {
- var data models.SysCategory
- 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.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 GetSysCategory(c *gin.Context) {
- var data models.SysCategory
- 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.SysCategory true "data"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/syscategory [post]
-func InsertSysCategory(c *gin.Context) {
- var data models.SysCategory
- 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 UpdateSysCategory(c *gin.Context) {
- var data models.SysCategory
- 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 DeleteSysCategory(c *gin.Context) {
- var data models.SysCategory
- 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)
-}
diff --git a/app/admin/apis/syscontent/syscontent.go b/app/admin/apis/syscontent/syscontent.go
deleted file mode 100644
index ceb851c3..00000000
--- a/app/admin/apis/syscontent/syscontent.go
+++ /dev/null
@@ -1,84 +0,0 @@
-package syscontent
-
-import (
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/app/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)
-}
diff --git a/app/admin/apis/sysfiledir/dir.go b/app/admin/apis/sysfiledir/dir.go
deleted file mode 100644
index fbf142be..00000000
--- a/app/admin/apis/sysfiledir/dir.go
+++ /dev/null
@@ -1,71 +0,0 @@
-package sysfiledir
-
-import (
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/app/msg"
-)
-
-func GetSysFileDirList(c *gin.Context) {
- var SysFileDir models.SysFileDir
- SysFileDir.Label = c.Request.FormValue("label")
- SysFileDir.PId, _ = tools.StringToInt(c.Request.FormValue("pid"))
- SysFileDir.Id, _ = tools.StringToInt(c.Request.FormValue("id"))
- SysFileDir.DataScope = tools.GetUserIdStr(c)
- result, err := SysFileDir.SetSysFileDir()
- tools.HasError(err, "抱歉未找到相关信息", -1)
- app.OK(c, result, "")
-}
-
-func GetSysFileDir(c *gin.Context) {
- var data models.SysFileDir
- data.Id, _ = tools.StringToInt(c.Param("id"))
- result, err := data.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
-
- app.OK(c, result, "")
-}
-
-// @Summary 添加SysFileDir
-// @Description 获取JSON
-// @Tags SysFileDir
-// @Accept application/json
-// @Product application/json
-// @Param data body models.SysFileDir true "data"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/sysfiledir [post]
-func InsertSysFileDir(c *gin.Context) {
- var data models.SysFileDir
- 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 UpdateSysFileDir(c *gin.Context) {
- var data models.SysFileDir
- 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 DeleteSysFileDir(c *gin.Context) {
- var data models.SysFileDir
- 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)
-}
diff --git a/app/admin/apis/sysfileinfo/sysfileinfo.go b/app/admin/apis/sysfileinfo/sysfileinfo.go
deleted file mode 100644
index 509c74a9..00000000
--- a/app/admin/apis/sysfileinfo/sysfileinfo.go
+++ /dev/null
@@ -1,77 +0,0 @@
-package sysfileinfo
-
-import (
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/app/msg"
-)
-
-func GetSysFileInfoList(c *gin.Context) {
- var data models.SysFileInfo
- var err error
- var pageSize = 10
- var pageIndex = 1
-
- if size := c.Request.FormValue("pageSize"); size != "" {
- pageSize, err = tools.StringToInt(size)
- }
- tools.HasError(err, "", -1)
- if index := c.Request.FormValue("pageIndex"); index != "" {
- pageIndex, err = tools.StringToInt(index)
- }
- tools.HasError(err, "", -1)
- if pid := c.Request.FormValue("pId"); pid != "" {
- data.PId, err = tools.StringToInt(pid)
- }
- tools.HasError(err, "", -1)
-
- data.DataScope = tools.GetUserIdStr(c)
- result, count, err := data.GetPage(pageSize, pageIndex)
- tools.HasError(err, "", -1)
-
- app.PageOK(c, result, count, pageIndex, pageSize, "")
-}
-
-func GetSysFileInfo(c *gin.Context) {
- var data models.SysFileInfo
- data.Id, _ = tools.StringToInt(c.Param("id"))
- result, err := data.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
-
- app.OK(c, result, "")
-}
-
-func InsertSysFileInfo(c *gin.Context) {
- var data models.SysFileInfo
- 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 UpdateSysFileInfo(c *gin.Context) {
- var data models.SysFileInfo
- 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 DeleteSysFileInfo(c *gin.Context) {
- var data models.SysFileInfo
- 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)
-}
diff --git a/app/admin/apis/sysjob/sysjob.go b/app/admin/apis/sysjob/sysjob.go
deleted file mode 100644
index c0067b49..00000000
--- a/app/admin/apis/sysjob/sysjob.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package sysjob
-
-import (
- "github.com/gin-gonic/gin"
-
- "go-admin/app/admin/service"
- "go-admin/common/apis"
- "go-admin/common/dto"
- "go-admin/common/log"
- "go-admin/tools"
- "go-admin/tools/app"
-)
-
-type SysJob struct {
- apis.Api
-}
-
-// RemoveJobForService 调用service实现
-func (e *SysJob) RemoveJobForService(c *gin.Context) {
- msgID := tools.GenerateMsgIDFromContext(c)
- db, err := e.GetOrm(c)
- if err != nil {
- log.Errorf("msgID[%s] error:%s", msgID, err)
- app.Error(c, 500, err, "")
- return
- }
- var v dto.GeneralDelDto
- err = c.BindUri(&v)
- if err != nil {
- log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
- app.Error(c, 422, err, "参数验证失败")
- return
- }
- s := service.SysJob{}
- s.MsgID = msgID
- s.Orm = db
- err = s.RemoveJob(&v)
- if err != nil {
- app.Error(c, 500, err, "")
- return
- }
- app.OK(c, nil, s.Msg)
-}
-
-// StartJobForService 启动job service实现
-func (e *SysJob) StartJobForService(c *gin.Context) {
- msgID := tools.GenerateMsgIDFromContext(c)
- db, err := e.GetOrm(c)
- if err != nil {
- log.Errorf("msgID[%s] error:%s", msgID, err)
- app.Error(c, 500, err, "")
- return
- }
- var v dto.GeneralGetDto
- err = c.BindUri(&v)
- if err != nil {
- log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
- app.Error(c, 422, err, "参数验证失败")
- return
- }
- s := service.SysJob{}
- s.Orm = db
- s.MsgID = msgID
- err = s.StartJob(&v)
- if err != nil {
- app.Error(c, 500, err, "")
- return
- }
- app.OK(c, nil, s.Msg)
-}
diff --git a/app/admin/apis/system/captcha.go b/app/admin/apis/system/captcha.go
index 26439a18..511fb784 100644
--- a/app/admin/apis/system/captcha.go
+++ b/app/admin/apis/system/captcha.go
@@ -2,16 +2,24 @@ package system
import (
"github.com/gin-gonic/gin"
-
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/captcha"
+ "github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
+ "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()
- tools.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,
diff --git a/app/admin/apis/system/config.go b/app/admin/apis/system/config.go
deleted file mode 100644
index 9a07a63b..00000000
--- a/app/admin/apis/system/config.go
+++ /dev/null
@@ -1,149 +0,0 @@
-package system
-
-import (
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/app/msg"
-)
-
-// @Summary 配置列表数据
-// @Description 获取JSON
-// @Tags 配置
-// @Param configKey query string false "configKey"
-// @Param configName query string false "configName"
-// @Param configType query string false "configType"
-// @Param pageSize query int false "页条数"
-// @Param pageIndex query int false "页码"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/configList [get]
-// @Security Bearer
-func GetConfigList(c *gin.Context) {
- var data models.SysConfig
- 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.ConfigKey = c.Request.FormValue("configKey")
- data.ConfigName = c.Request.FormValue("configName")
- data.ConfigType = c.Request.FormValue("configType")
- data.DataScope = tools.GetUserIdStr(c)
- result, count, err := data.GetPage(pageSize, pageIndex)
- tools.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())
-}
-
-// @Summary 获取配置
-// @Description 获取JSON
-// @Tags 配置
-// @Param configId path int true "配置编码"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/config/{configId} [get]
-// @Security Bearer
-func GetConfig(c *gin.Context) {
- var Config models.SysConfig
- Config.ConfigId, _ = tools.StringToInt(c.Param("configId"))
- result, err := Config.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
-
- var res app.Response
- res.Data = result
-
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 获取配置
-// @Description 获取JSON
-// @Tags 配置
-// @Param configKey path int true "configKey"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/configKey/{configKey} [get]
-// @Security Bearer
-func GetConfigByConfigKey(c *gin.Context) {
- var Config models.SysConfig
- Config.ConfigKey = c.Param("configKey")
- result, err := Config.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
-
- app.OK(c, result, result.ConfigValue)
-}
-
-// @Summary 添加配置
-// @Description 获取JSON
-// @Tags 配置
-// @Accept application/json
-// @Product application/json
-// @Param data body models.SysConfig 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 InsertConfig(c *gin.Context) {
- var data models.SysConfig
- err := c.BindWith(&data, binding.JSON)
- data.CreateBy = tools.GetUserIdStr(c)
- tools.HasError(err, "", 500)
- result, err := data.Create()
- tools.HasError(err, "", -1)
-
- app.OK(c, result, "")
-}
-
-// @Summary 修改配置
-// @Description 获取JSON
-// @Tags 配置
-// @Accept application/json
-// @Product application/json
-// @Param data body models.SysConfig true "body"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/config [put]
-// @Security Bearer
-func UpdateConfig(c *gin.Context) {
- var data models.SysConfig
- err := c.BindWith(&data, binding.JSON)
- tools.HasError(err, "数据解析失败", -1)
- data.UpdateBy = tools.GetUserIdStr(c)
- result, err := data.Update(data.ConfigId)
- tools.HasError(err, "", -1)
- app.OK(c, result, "")
-}
-
-// @Summary 删除配置
-// @Description 删除数据
-// @Tags 配置
-// @Param configId path int true "configId"
-// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
-// @Router /api/v1/config/{configId} [delete]
-func DeleteConfig(c *gin.Context) {
- var data models.SysConfig
- data.UpdateBy = tools.GetUserIdStr(c)
- IDS := tools.IdsStrToIdsIntGroup("configId", c)
- result, err := data.BatchDelete(IDS)
- tools.HasError(err, "修改失败", 500)
- app.OK(c, result, msg.DeletedSuccess)
-}
diff --git a/app/admin/apis/system/dept.go b/app/admin/apis/system/dept.go
deleted file mode 100644
index fb33bfae..00000000
--- a/app/admin/apis/system/dept.go
+++ /dev/null
@@ -1,133 +0,0 @@
-package system
-
-import (
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/app/msg"
-)
-
-// @Summary 分页部门列表数据
-// @Description 分页列表
-// @Tags 部门
-// @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": [...]}"
-// @Router /api/v1/deptList [get]
-// @Security Bearer
-func GetDeptList(c *gin.Context) {
- var Dept models.SysDept
- Dept.DeptName = c.Request.FormValue("deptName")
- Dept.Status = c.Request.FormValue("status")
- Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
- Dept.DataScope = tools.GetUserIdStr(c)
- result, err := Dept.SetDept(true)
- tools.HasError(err, "抱歉未找到相关信息", -1)
- app.OK(c, result, "")
-}
-
-func GetDeptTree(c *gin.Context) {
- var Dept models.SysDept
- Dept.DeptName = c.Request.FormValue("deptName")
- Dept.Status = c.Request.FormValue("status")
- Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
- result, err := Dept.SetDept(false)
- tools.HasError(err, "抱歉未找到相关信息", -1)
- app.OK(c, result, "")
-}
-
-// @Summary 部门列表数据
-// @Description 获取JSON
-// @Tags 部门
-// @Param deptId path string false "deptId"
-// @Param position query string false "position"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/dept/{deptId} [get]
-// @Security Bearer
-func GetDept(c *gin.Context) {
- var Dept models.SysDept
- Dept.DeptId, _ = tools.StringToInt(c.Param("deptId"))
- Dept.DataScope = tools.GetUserIdStr(c)
- result, err := Dept.Get()
- tools.HasError(err, msg.NotFound, 404)
- app.OK(c, result, msg.GetSuccess)
-}
-
-// @Summary 添加部门
-// @Description 获取JSON
-// @Tags 部门
-// @Accept application/json
-// @Product application/json
-// @Param data body models.SysDept true "data"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/dept [post]
-// @Security Bearer
-func InsertDept(c *gin.Context) {
- var data models.SysDept
- err := c.BindWith(&data, binding.JSON)
- tools.HasError(err, "", 500)
- data.CreateBy = tools.GetUserIdStr(c)
- result, err := data.Create()
- tools.HasError(err, "", -1)
- app.OK(c, result, msg.CreatedSuccess)
-}
-
-// @Summary 修改部门
-// @Description 获取JSON
-// @Tags 部门
-// @Accept application/json
-// @Product application/json
-// @Param id path int true "id"
-// @Param data body models.SysDept true "body"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/dept [put]
-// @Security Bearer
-func UpdateDept(c *gin.Context) {
- var data models.SysDept
- err := c.BindJSON(&data)
- tools.HasError(err, "", -1)
- data.UpdateBy = tools.GetUserIdStr(c)
- result, err := data.Update(data.DeptId)
- tools.HasError(err, "", -1)
- app.OK(c, result, msg.UpdatedSuccess)
-}
-
-// @Summary 删除部门
-// @Description 删除数据
-// @Tags 部门
-// @Param id path int true "id"
-// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
-// @Router /api/v1/dept/{id} [delete]
-func DeleteDept(c *gin.Context) {
- var data models.SysDept
- id, err := tools.StringToInt(c.Param("id"))
- _, err = data.Delete(id)
- tools.HasError(err, "删除失败", 500)
- app.OK(c, "", msg.DeletedSuccess)
-}
-
-func GetDeptTreeRoleselect(c *gin.Context) {
- var Dept models.SysDept
- var SysRole models.SysRole
- id, err := tools.StringToInt(c.Param("roleId"))
- SysRole.RoleId = id
- result, err := Dept.SetDeptLable()
- tools.HasError(err, msg.NotFound, -1)
- menuIds := make([]int, 0)
- if id != 0 {
- menuIds, err = SysRole.GetRoleDeptId()
- tools.HasError(err, "抱歉未找到相关信息", -1)
- }
- app.Custum(c, gin.H{
- "code": 200,
- "depts": result,
- "checkedKeys": menuIds,
- })
-}
diff --git a/app/admin/apis/system/dict/dictdata.go b/app/admin/apis/system/dict/dictdata.go
deleted file mode 100644
index bd58b907..00000000
--- a/app/admin/apis/system/dict/dictdata.go
+++ /dev/null
@@ -1,154 +0,0 @@
-package dict
-
-import (
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
-)
-
-// @Summary 字典数据列表
-// @Description 获取JSON
-// @Tags 字典数据
-// @Param status query string false "status"
-// @Param dictCode query string false "dictCode"
-// @Param dictType query string false "dictType"
-// @Param pageSize query int false "页条数"
-// @Param pageIndex query int false "页码"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/dict/data/list [get]
-// @Security Bearer
-func GetDictDataList(c *gin.Context) {
- var data models.DictData
- 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.DictLabel = c.Request.FormValue("dictLabel")
- data.Status = c.Request.FormValue("status")
- data.DictType = c.Request.FormValue("dictType")
- id := c.Request.FormValue("dictCode")
- data.DictCode, _ = tools.StringToInt(id)
- data.DataScope = tools.GetUserIdStr(c)
- result, count, err := data.GetPage(pageSize, pageIndex)
- tools.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())
-}
-
-// @Summary 通过编码获取字典数据
-// @Description 获取JSON
-// @Tags 字典数据
-// @Param dictCode path int true "字典编码"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/dict/data/{dictCode} [get]
-// @Security Bearer
-func GetDictData(c *gin.Context) {
- var DictData models.DictData
- DictData.DictLabel = c.Request.FormValue("dictLabel")
- DictData.DictCode, _ = tools.StringToInt(c.Param("dictCode"))
- result, err := DictData.GetByCode()
- tools.HasError(err, "抱歉未找到相关信息", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 通过字典类型获取字典数据
-// @Description 获取JSON
-// @Tags 字典数据
-// @Param dictType path int true "dictType"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/dict/databyType/{dictType} [get]
-// @Security Bearer
-func GetDictDataByDictType(c *gin.Context) {
- var DictData models.DictData
- DictData.DictType = c.Param("dictType")
- result, err := DictData.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
-
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 添加字典数据
-// @Description 获取JSON
-// @Tags 字典数据
-// @Accept application/json
-// @Product application/json
-// @Param data body models.DictType 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 InsertDictData(c *gin.Context) {
- var data models.DictData
- err := c.ShouldBindJSON(&data)
- data.CreateBy = tools.GetUserIdStr(c)
- tools.HasError(err, "", 500)
- result, err := data.Create()
- tools.HasError(err, "", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 修改字典数据
-// @Description 获取JSON
-// @Tags 字典数据
-// @Accept application/json
-// @Product application/json
-// @Param data body models.DictType true "body"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/dict/data [put]
-// @Security Bearer
-func UpdateDictData(c *gin.Context) {
- var data models.DictData
- err := c.BindWith(&data, binding.JSON)
- data.UpdateBy = tools.GetUserIdStr(c)
- tools.HasError(err, "", -1)
- result, err := data.Update(data.DictCode)
- tools.HasError(err, "", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 删除字典数据
-// @Description 删除数据
-// @Tags 字典数据
-// @Param dictCode path int true "dictCode"
-// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
-// @Router /api/v1/dict/data/{dictCode} [delete]
-func DeleteDictData(c *gin.Context) {
- var data models.DictData
- data.UpdateBy = tools.GetUserIdStr(c)
- IDS := tools.IdsStrToIdsIntGroup("dictCode", c)
- result, err := data.BatchDelete(IDS)
- tools.HasError(err, "修改失败", 500)
- app.OK(c, result, "删除成功")
-}
diff --git a/app/admin/apis/system/dict/dicttype.go b/app/admin/apis/system/dict/dicttype.go
deleted file mode 100644
index bf9fe500..00000000
--- a/app/admin/apis/system/dict/dicttype.go
+++ /dev/null
@@ -1,137 +0,0 @@
-package dict
-
-import (
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
-
- "go-admin/app/admin/models"
- "go-admin/tools"
- "go-admin/tools/app"
-)
-
-// @Summary 字典类型列表数据
-// @Description 获取JSON
-// @Tags 字典类型
-// @Param dictName query string false "dictName"
-// @Param dictId query string false "dictId"
-// @Param dictType query string false "dictType"
-// @Param pageSize query int false "页条数"
-// @Param pageIndex query int false "页码"
-// @Success 200 {object} app.PageResponse "{"code": 200, "data": [...]}"
-// @Router /api/v1/dict/type/list [get]
-// @Security Bearer
-func GetDictTypeList(c *gin.Context) {
- var data models.DictType
- 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.DictName = c.Request.FormValue("dictName")
- id := c.Request.FormValue("dictId")
- data.DictId, _ = tools.StringToInt(id)
- data.DictType = c.Request.FormValue("dictType")
- data.DataScope = tools.GetUserIdStr(c)
- result, count, err := data.GetPage(pageSize, pageIndex)
- tools.HasError(err, "", -1)
-
- app.PageOK(c, result, count, pageIndex, pageSize, "")
-}
-
-// @Summary 通过字典id获取字典类型
-// @Description 获取JSON
-// @Tags 字典类型
-// @Param dictId path int true "字典类型编码"
-// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
-// @Router /api/v1/dict/type/{dictId} [get]
-// @Security Bearer
-func GetDictType(c *gin.Context) {
- var DictType models.DictType
- DictType.DictName = c.Request.FormValue("dictName")
- DictType.DictId, _ = tools.StringToInt(c.Param("dictId"))
- result, err := DictType.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-func GetDictTypeOptionSelect(c *gin.Context) {
- var DictType models.DictType
- DictType.DictName = c.Request.FormValue("dictName")
- DictType.DictId, _ = tools.StringToInt(c.Param("dictId"))
- result, err := DictType.GetList()
- tools.HasError(err, "抱歉未找到相关信息", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 添加字典类型
-// @Description 获取JSON
-// @Tags 字典类型
-// @Accept application/json
-// @Product application/json
-// @Param data body models.DictType 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 InsertDictType(c *gin.Context) {
- var data models.DictType
- err := c.BindWith(&data, binding.JSON)
- data.CreateBy = tools.GetUserIdStr(c)
- tools.HasError(err, "", 500)
- result, err := data.Create()
- tools.HasError(err, "", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 修改字典类型
-// @Description 获取JSON
-// @Tags 字典类型
-// @Accept application/json
-// @Product application/json
-// @Param data body models.DictType true "body"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/dict/type [put]
-// @Security Bearer
-func UpdateDictType(c *gin.Context) {
- var data models.DictType
- err := c.BindWith(&data, binding.JSON)
- data.UpdateBy = tools.GetUserIdStr(c)
- tools.HasError(err, "", -1)
- result, err := data.Update(data.DictId)
- tools.HasError(err, "", -1)
- var res app.Response
- res.Data = result
- c.JSON(http.StatusOK, res.ReturnOK())
-}
-
-// @Summary 删除字典类型
-// @Description 删除数据
-// @Tags 字典类型
-// @Param dictId path int true "dictId"
-// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
-// @Router /api/v1/dict/type/{dictId} [delete]
-func DeleteDictType(c *gin.Context) {
- var data models.DictType
- data.UpdateBy = tools.GetUserIdStr(c)
- IDS := tools.IdsStrToIdsIntGroup("dictId", c)
- result, err := data.BatchDelete(IDS)
- tools.HasError(err, "修改失败", 500)
- app.OK(c, result, "删除成功")
-}
diff --git a/app/admin/apis/system/dict/sys_dict_data.go b/app/admin/apis/system/dict/sys_dict_data.go
new file mode 100644
index 00000000..94d16df7
--- /dev/null
+++ b/app/admin/apis/system/dict/sys_dict_data.go
@@ -0,0 +1,269 @@
+package dict
+
+import (
+ "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"
+ "go-admin/app/admin/service/dto"
+ "go-admin/common/apis"
+ common "go-admin/common/models"
+)
+
+type SysDictData struct {
+ apis.Api
+}
+
+// @Summary 字典数据列表
+// @Description 获取JSON
+// @Tags 字典数据
+// @Param status query string false "status"
+// @Param dictCode query string false "dictCode"
+// @Param dictType query string false "dictType"
+// @Param pageSize query int false "页条数"
+// @Param pageIndex query int false "页码"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/v1/dict/data [get]
+// @Security Bearer
+func (e SysDictData) GetSysDictDataList(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := &dto.SysDictDataSearch{}
+
+ //查询列表
+ err = req.Bind(c)
+ if err != nil {
+ log.Warnf("Bind error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ list := make([]system.SysDictData, 0)
+ var count int64
+ s := service.SysDictData{}
+ s.Log = log
+ s.Orm = db.Debug()
+ err = s.GetPage(req, &list, &count)
+ if err != nil {
+ log.Errorf("GetPage error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+}
+
+// @Summary 通过编码获取字典数据
+// @Description 获取JSON
+// @Tags 字典数据
+// @Param dictCode path int true "字典编码"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/v1/dict/data/{dictCode} [get]
+// @Security Bearer
+func (e SysDictData) GetSysDictData(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //查看详情
+ req := &dto.SysDictDataById{}
+ err = req.Bind(c)
+ if err != nil {
+ log.Warnf("Bind error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object system.SysDictData
+
+ s := service.SysDictData{}
+ s.Log = log
+ s.Orm = db
+ err = s.Get(req, &object)
+ if err != nil {
+ log.Warnf("Get error: %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.OK(object, "查看成功")
+}
+
+// @Summary 添加字典数据
+// @Description 获取JSON
+// @Tags 字典数据
+// @Accept application/json
+// @Product application/json
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //新增操作
+ req := &dto.SysDictDataControl{}
+ err = req.Bind(c)
+ if err != nil {
+ log.Warnf("Bind error: %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ object, _ := req.GenerateM()
+ // 设置创建人
+ object.SetCreateBy(user.GetUserId(c))
+
+ s := service.SysDictData{}
+ s.Orm = db
+ s.Log = log
+ err = s.Insert(object.(*system.SysDictData))
+ if err != nil {
+ log.Errorf("Insert error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+
+ e.OK(object.GetId(), "创建成功")
+}
+
+// @Summary 修改字典数据
+// @Description 获取JSON
+// @Tags 字典数据
+// @Accept application/json
+// @Product application/json
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := &dto.SysDictDataControl{}
+ //更新操作
+ err = req.Bind(c)
+ if err != nil {
+ log.Warnf("request validate error, %s", err.Error())
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ object, _ := req.GenerateM()
+ object.SetUpdateBy(user.GetUserId(c))
+
+ s := service.SysDictData{}
+ s.Orm = db
+ s.Log = log
+ err = s.Update(object.(*system.SysDictData))
+ if err != nil {
+ log.Errorf("Update error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "更新失败")
+ return
+ }
+ e.OK(object.GetId(), "更新成功")
+}
+
+// @Summary 删除字典数据
+// @Description 删除数据
+// @Tags 字典数据
+// @Param dictCode path int true "dictCode"
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //删除操作
+ req := new(dto.SysDictDataById)
+ err = req.Bind(c)
+ if err != nil {
+ log.Warnf("Bind error: %s", 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(http.StatusInternalServerError, err, "模型生成失败")
+ return
+ }
+
+ // 设置编辑人
+ object.SetUpdateBy(user.GetUserId(c))
+
+ s := service.SysDictData{}
+ s.Orm = db
+ s.Log = log
+ err = s.Remove(req, object.(*system.SysDictData))
+ if err != nil {
+ log.Errorf("Remove error, %s", err)
+ e.Error(http.StatusInternalServerError, err, "删除失败")
+ return
+ }
+ e.OK(object.GetId(), "删除成功")
+}
+
+func (e SysDictData) GetSysDictDataAll(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := &dto.SysDictDataSearch{}
+
+ //查询列表
+ err = req.Bind(c)
+ if err != nil {
+ log.Warnf("Bind error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ list := make([]system.SysDictData, 0)
+ s := service.SysDictData{}
+ s.Log = log
+ s.Orm = db
+ err = s.GetAll(req, &list)
+ if err != nil {
+ log.Errorf("GetAll error, %s", err.Error())
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.OK(list, "查询成功")
+}
diff --git a/app/admin/apis/system/dict/sys_dict_type.go b/app/admin/apis/system/dict/sys_dict_type.go
new file mode 100644
index 00000000..c2a05296
--- /dev/null
+++ b/app/admin/apis/system/dict/sys_dict_type.go
@@ -0,0 +1,267 @@
+package dict
+
+import (
+ "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"
+ "go-admin/app/admin/service/dto"
+ "go-admin/common/apis"
+ common "go-admin/common/models"
+)
+
+type SysDictType struct {
+ apis.Api
+}
+
+// @Summary 字典类型列表数据
+// @Description 获取JSON
+// @Tags 字典类型
+// @Param dictName query string false "dictName"
+// @Param dictId query string false "dictId"
+// @Param dictType query string false "dictType"
+// @Param pageSize query int false "页条数"
+// @Param pageIndex query int false "页码"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/v1/dict/type [get]
+// @Security Bearer
+func (e SysDictType) GetSysDictTypeList(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := &dto.SysDictTypeSearch{}
+
+ //查询列表
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ list := make([]system.SysDictType, 0)
+ var count int64
+ s := service.SysDictType{}
+ s.Log = log
+ s.Orm = db.Debug()
+ err = s.GetPage(req, &list, &count)
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "查询失败")
+ return
+ }
+
+ e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+}
+
+// @Summary 通过字典id获取字典类型
+// @Description 获取JSON
+// @Tags 字典类型
+// @Param dictId path int true "字典类型编码"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/v1/dict/type/{dictId} [get]
+// @Security Bearer
+func (e SysDictType) GetSysDictType(c *gin.Context) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //查看详情
+ req := &dto.SysDictTypeById{}
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object system.SysDictType
+
+ s := service.SysDictType{}
+ s.Log = log
+ s.Orm = db
+ err = s.Get(req, &object)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "查询失败")
+ return
+ }
+
+ e.OK(object, "查看成功")
+}
+
+// @Summary 添加字典类型
+// @Description 获取JSON
+// @Tags 字典类型
+// @Accept application/json
+// @Product application/json
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //新增操作
+ req := &dto.SysDictTypeControl{}
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ object, _ := req.GenerateM()
+ // 设置创建人
+ object.SetCreateBy(user.GetUserId(c))
+
+ s := service.SysDictType{}
+ s.Orm = db
+ s.Log = log
+ err = s.Insert(object.(*system.SysDictType))
+ if err != nil {
+ log.Error(err)
+ e.Error(http.StatusInternalServerError, err, "创建失败")
+ return
+ }
+
+ e.OK(object.GetId(), "创建成功")
+}
+
+// @Summary 修改字典类型
+// @Description 获取JSON
+// @Tags 字典类型
+// @Accept application/json
+// @Product application/json
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := &dto.SysDictTypeControl{}
+ //更新操作
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ object, _ := req.GenerateM()
+ object.SetUpdateBy(user.GetUserId(c))
+
+ s := service.SysDictType{}
+ s.Orm = db
+ s.Log = log
+ err = s.Update(object.(*system.SysDictType))
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ e.OK(object.GetId(), "更新成功")
+}
+
+// @Summary 删除字典类型
+// @Description 删除数据
+// @Tags 字典类型
+// @Param dictId path int true "dictId"
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ //删除操作
+ req := new(dto.SysDictTypeById)
+ err = req.Bind(c)
+ if err != nil {
+ log.Errorf("Bind error: %s", err)
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+ var object common.ActiveRecord
+ object, err = req.GenerateM()
+ if err != nil {
+ e.Error(http.StatusInternalServerError, err, "模型生成失败")
+ return
+ }
+
+ // 设置编辑人
+ object.SetUpdateBy(user.GetUserId(c))
+
+ s := service.SysDictType{}
+ s.Orm = db
+ s.Log = log
+ err = s.Remove(req, object.(*system.SysDictType))
+ if err != nil {
+ log.Error(err)
+ return
+ }
+ e.OK(object.GetId(), "删除成功")
+}
+
+// @Summary 字典类型全部数据
+// @Description 获取JSON
+// @Tags 字典类型
+// @Param dictName query string false "dictName"
+// @Param dictId query string false "dictId"
+// @Param dictType query string false "dictType"
+// @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) {
+ e.Context = c
+ log := e.GetLogger()
+ db, err := e.GetOrm()
+ if err != nil {
+ log.Error(err)
+ return
+ }
+
+ req := &dto.SysDictTypeSearch{}
+
+ //查询列表
+ err = req.Bind(c)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
+ return
+ }
+
+ list := make([]system.SysDictType, 0)
+ s := service.SysDictType{}
+ s.Log = log
+ s.Orm = db
+ err = s.GetAll(req, &list)
+ if err != nil {
+ e.Error(http.StatusUnprocessableEntity, err, "查询失败")
+ return
+ }
+
+ e.OK(list, "查询成功")
+}
diff --git a/app/admin/apis/system/index.go b/app/admin/apis/system/index.go
index 53327064..59997496 100644
--- a/app/admin/apis/system/index.go
+++ b/app/admin/apis/system/index.go
@@ -28,7 +28,7 @@ $(function(){
-
+