mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 02:04:09 +00:00
feat:update gen
This commit is contained in:
@@ -5,14 +5,25 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
imgType "github.com/shamsher31/goimgtype"
|
||||
|
||||
"go-admin/pkg/utils"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/app"
|
||||
)
|
||||
|
||||
type FileResponse struct {
|
||||
Size int64 `json:"size"`
|
||||
Path string `json:"path"`
|
||||
FullPath string `json:"full_path"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// @Summary 上传图片
|
||||
// @Description 获取JSON
|
||||
// @Tags 公共接口
|
||||
@@ -25,6 +36,7 @@ import (
|
||||
func UploadFile(c *gin.Context) {
|
||||
tag, _ := c.GetPostForm("type")
|
||||
urlPerfix := fmt.Sprintf("http://%s/", c.Request.Host)
|
||||
var fileResponse FileResponse
|
||||
if tag == "" {
|
||||
app.Error(c, 200, errors.New(""), "缺少标识")
|
||||
return
|
||||
@@ -41,25 +53,52 @@ func UploadFile(c *gin.Context) {
|
||||
|
||||
singleFile := "static/uploadfile/" + guid + utils.GetExt(files.Filename)
|
||||
_ = c.SaveUploadedFile(files, singleFile)
|
||||
app.OK(c, urlPerfix+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, "上传成功")
|
||||
return
|
||||
case "2": // 多图
|
||||
files := c.Request.MultipartForm.File["file"]
|
||||
multipartFile := make([]string, len(files))
|
||||
var multipartFile []FileResponse
|
||||
for _, f := range files {
|
||||
guid := uuid.New().String()
|
||||
multipartFileName := "static/uploadfile/" + guid + utils.GetExt(f.Filename)
|
||||
_ = c.SaveUploadedFile(f, multipartFileName)
|
||||
multipartFile = append(multipartFile, urlPerfix+multipartFileName)
|
||||
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, "上传成功")
|
||||
return
|
||||
case "3": // base64
|
||||
files, _ := c.GetPostForm("file")
|
||||
ddd, _ := base64.StdEncoding.DecodeString(files)
|
||||
file2list := strings.Split(files, ",")
|
||||
ddd, _ := base64.StdEncoding.DecodeString(file2list[1])
|
||||
guid := uuid.New().String()
|
||||
_ = ioutil.WriteFile("static/uploadfile/"+guid+".jpg", ddd, 0666)
|
||||
app.OK(c, urlPerfix+"static/uploadfile/"+guid+".jpg", "上传成功")
|
||||
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, "上传成功")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package student
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/app"
|
||||
"go-admin/tools/app/msg"
|
||||
)
|
||||
|
||||
func GetStudentList(c *gin.Context) {
|
||||
var data models.Student
|
||||
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)
|
||||
}
|
||||
|
||||
var v dto.StudentSearch
|
||||
err = c.Bind(&v)
|
||||
tools.HasError(err, "数据解析失败", 422)
|
||||
|
||||
data.DataScope = tools.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex, v)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.PageOK(c, result, count, pageIndex, pageSize, "")
|
||||
}
|
||||
|
||||
func GetStudent(c *gin.Context) {
|
||||
var data models.Student
|
||||
data.Id, _ = tools.StringToInt(c.Param("id"))
|
||||
result, err := data.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 添加Student
|
||||
// @Description 获取JSON
|
||||
// @Tags Student
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.Student true "data"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/student [post]
|
||||
func InsertStudent(c *gin.Context) {
|
||||
var data models.Student
|
||||
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 UpdateStudent(c *gin.Context) {
|
||||
var data models.Student
|
||||
err := c.ShouldBindJSON(&data)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.Id)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func DeleteStudent(c *gin.Context) {
|
||||
var data models.Student
|
||||
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)
|
||||
}
|
||||
@@ -12,5 +12,5 @@ type CasbinRule struct {
|
||||
}
|
||||
|
||||
func (CasbinRule) TableName() string {
|
||||
return "casbin_rule"
|
||||
return "sys_casbin_rule"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
orm "go-admin/common/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type SysFileInfo struct {
|
||||
@@ -63,12 +62,12 @@ func (e *SysFileInfo) GetPage(pageSize int, pageIndex int) ([]SysFileInfo, int,
|
||||
}
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table, err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
//dataPermission := new(DataPermission)
|
||||
//dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
//table, err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
//if err != nil {
|
||||
// return nil, 0, err
|
||||
//}
|
||||
var count int64
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user