This commit is contained in:
XM-GO
2023-08-22 17:29:11 +08:00
parent 5be575e982
commit 3ac5ecc55a
20 changed files with 88 additions and 128 deletions

View File

@@ -16,7 +16,7 @@ type SystemApiApi struct {
func (s *SystemApiApi) CreateApi(rc *restfulx.ReqCtx) {
var api entity.SysApi
restfulx.BindQuery(rc, &api)
restfulx.BindJsonAndValid(rc, &api)
s.ApiApp.Insert(api)
}
@@ -50,7 +50,7 @@ func (s *SystemApiApi) GetApiById(rc *restfulx.ReqCtx) {
func (s *SystemApiApi) UpdateApi(rc *restfulx.ReqCtx) {
var api entity.SysApi
restfulx.BindQuery(rc, &api)
restfulx.BindJsonAndValid(rc, &api)
s.ApiApp.Update(api)
}

View File

@@ -43,14 +43,14 @@ func (p *ConfigApi) GetConfig(rc *restfulx.ReqCtx) {
func (p *ConfigApi) InsertConfig(rc *restfulx.ReqCtx) {
var config entity.SysConfig
restfulx.BindQuery(rc, &config)
restfulx.BindJsonAndValid(rc, &config)
p.ConfigApp.Insert(config)
}
func (p *ConfigApi) UpdateConfig(rc *restfulx.ReqCtx) {
var post entity.SysConfig
restfulx.BindQuery(rc, &post)
restfulx.BindJsonAndValid(rc, &post)
p.ConfigApp.Update(post)
}

View File

@@ -21,9 +21,6 @@ type DeptApi struct {
func (m *DeptApi) GetDeptTreeRoleSelect(rc *restfulx.ReqCtx) {
roleId := restfulx.PathParamInt(rc, "roleId")
var dept entity.SysDept
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
dept.TenantId = rc.LoginAccount.TenantId
}
result := m.DeptApp.SelectDeptLable(dept)
deptIds := make([]int64, 0)
@@ -43,9 +40,7 @@ func (a *DeptApi) GetDeptList(rc *restfulx.ReqCtx) {
status := restfulx.QueryParam(rc, "status")
deptId := restfulx.QueryInt(rc, "deptId", 0)
dept := entity.SysDept{DeptName: deptName, Status: status, DeptId: int64(deptId)}
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
dept.TenantId = rc.LoginAccount.TenantId
}
if dept.DeptName == "" {
rc.ResData = a.DeptApp.SelectDept(dept)
} else {
@@ -55,9 +50,6 @@ func (a *DeptApi) GetDeptList(rc *restfulx.ReqCtx) {
func (a *DeptApi) GetOrdinaryDeptList(rc *restfulx.ReqCtx) {
var dept entity.SysDept
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
dept.TenantId = rc.LoginAccount.TenantId
}
rc.ResData = a.DeptApp.FindList(dept)
}
@@ -67,9 +59,7 @@ func (a *DeptApi) GetDeptTree(rc *restfulx.ReqCtx) {
status := restfulx.QueryParam(rc, "status")
deptId := restfulx.QueryInt(rc, "deptId", 0)
dept := entity.SysDept{DeptName: deptName, Status: status, DeptId: int64(deptId)}
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
dept.TenantId = rc.LoginAccount.TenantId
}
rc.ResData = a.DeptApp.SelectDept(dept)
}
@@ -80,15 +70,14 @@ func (a *DeptApi) GetDept(rc *restfulx.ReqCtx) {
func (a *DeptApi) InsertDept(rc *restfulx.ReqCtx) {
var dept entity.SysDept
restfulx.BindQuery(rc, &dept)
dept.TenantId = rc.LoginAccount.TenantId
restfulx.BindJsonAndValid(rc, &dept)
dept.CreateBy = rc.LoginAccount.UserName
a.DeptApp.Insert(dept)
}
func (a *DeptApi) UpdateDept(rc *restfulx.ReqCtx) {
var dept entity.SysDept
restfulx.BindQuery(rc, &dept)
restfulx.BindJsonAndValid(rc, &dept)
dept.UpdateBy = rc.LoginAccount.UserName
a.DeptApp.Update(dept)

View File

@@ -39,7 +39,7 @@ func (p *DictApi) GetDictType(rc *restfulx.ReqCtx) {
func (p *DictApi) InsertDictType(rc *restfulx.ReqCtx) {
var dict entity.SysDictType
restfulx.BindQuery(rc, &dict)
restfulx.BindJsonAndValid(rc, &dict)
dict.CreateBy = rc.LoginAccount.UserName
p.DictType.Insert(dict)
@@ -47,7 +47,7 @@ func (p *DictApi) InsertDictType(rc *restfulx.ReqCtx) {
func (p *DictApi) UpdateDictType(rc *restfulx.ReqCtx) {
var dict entity.SysDictType
restfulx.BindQuery(rc, &dict)
restfulx.BindJsonAndValid(rc, &dict)
dict.CreateBy = rc.LoginAccount.UserName
p.DictType.Update(dict)
@@ -102,14 +102,14 @@ func (p *DictApi) GetDictData(rc *restfulx.ReqCtx) {
func (p *DictApi) InsertDictData(rc *restfulx.ReqCtx) {
var data entity.SysDictData
restfulx.BindQuery(rc, &data)
restfulx.BindJsonAndValid(rc, &data)
data.CreateBy = rc.LoginAccount.UserName
p.DictData.Insert(data)
}
func (p *DictApi) UpdateDictData(rc *restfulx.ReqCtx) {
var data entity.SysDictData
restfulx.BindQuery(rc, &data)
restfulx.BindJsonAndValid(rc, &data)
data.CreateBy = rc.LoginAccount.UserName
p.DictData.Update(data)

View File

@@ -11,7 +11,7 @@ type Register struct {
// User login structure
type Login struct {
Username string `json:"username"` // 用户名
Username string `json:"username" ` // 用户名
Password string `json:"password"` // 密码
Captcha string `json:"captcha"` // 验证码
CaptchaId string `json:"captchaId"` // 验证码ID

View File

@@ -68,7 +68,7 @@ func (m *MenuApi) GetMenu(rc *restfulx.ReqCtx) {
func (m *MenuApi) InsertMenu(rc *restfulx.ReqCtx) {
var menu entity.SysMenu
restfulx.BindQuery(rc, &menu)
restfulx.BindJsonAndValid(rc, &menu)
menu.CreateBy = rc.LoginAccount.UserName
m.MenuApp.Insert(menu)
permis := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)
@@ -81,7 +81,7 @@ func (m *MenuApi) InsertMenu(rc *restfulx.ReqCtx) {
func (m *MenuApi) UpdateMenu(rc *restfulx.ReqCtx) {
var menu entity.SysMenu
restfulx.BindQuery(rc, &menu)
restfulx.BindJsonAndValid(rc, &menu)
menu.UpdateBy = rc.LoginAccount.UserName
m.MenuApp.Update(menu)
permis := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)

View File

@@ -40,7 +40,7 @@ func (p *NoticeApi) GetNoticeList(rc *restfulx.ReqCtx) {
// InsertNotice 添加通知
func (p *NoticeApi) InsertNotice(rc *restfulx.ReqCtx) {
var notice entity.SysNotice
restfulx.BindQuery(rc, &notice)
restfulx.BindJsonAndValid(rc, &notice)
notice.UserName = rc.LoginAccount.UserName
p.NoticeApp.Insert(notice)
}
@@ -48,7 +48,7 @@ func (p *NoticeApi) InsertNotice(rc *restfulx.ReqCtx) {
// UpdateNotice 修改通知
func (p *NoticeApi) UpdateNotice(rc *restfulx.ReqCtx) {
var notice entity.SysNotice
restfulx.BindQuery(rc, &notice)
restfulx.BindJsonAndValid(rc, &notice)
p.NoticeApp.Update(notice)
}

View File

@@ -28,10 +28,6 @@ func (p *PostApi) GetPostList(rc *restfulx.ReqCtx) {
postCode := restfulx.QueryParam(rc, "postCode")
post := entity.SysPost{Status: status, PostName: postName, PostCode: postCode}
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
post.TenantId = rc.LoginAccount.TenantId
}
list, total := p.PostApp.FindListPage(pageNum, pageSize, post)
rc.ResData = model.ResultPage{
@@ -51,8 +47,7 @@ func (p *PostApi) GetPost(rc *restfulx.ReqCtx) {
// InsertPost 添加职位
func (p *PostApi) InsertPost(rc *restfulx.ReqCtx) {
var post entity.SysPost
restfulx.BindQuery(rc, &post)
post.TenantId = rc.LoginAccount.TenantId
restfulx.BindJsonAndValid(rc, &post)
post.CreateBy = rc.LoginAccount.UserName
p.PostApp.Insert(post)
}
@@ -60,7 +55,7 @@ func (p *PostApi) InsertPost(rc *restfulx.ReqCtx) {
// UpdatePost 修改职位
func (p *PostApi) UpdatePost(rc *restfulx.ReqCtx) {
var post entity.SysPost
restfulx.BindQuery(rc, &post)
restfulx.BindJsonAndValid(rc, &post)
post.CreateBy = rc.LoginAccount.UserName
p.PostApp.Update(post)

View File

@@ -28,11 +28,6 @@ func (r *RoleApi) GetRoleList(rc *restfulx.ReqCtx) {
roleName := restfulx.QueryParam(rc, "roleName")
roleKey := restfulx.QueryParam(rc, "roleKey")
role := entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
role.TenantId = rc.LoginAccount.TenantId
}
list, total := r.RoleApp.FindListPage(pageNum, pageSize, role)
rc.ResData = model.ResultPage{
@@ -55,9 +50,8 @@ func (r *RoleApi) GetRole(rc *restfulx.ReqCtx) {
// InsertRole 创建角色
func (r *RoleApi) InsertRole(rc *restfulx.ReqCtx) {
var role entity.SysRole
restfulx.BindQuery(rc, &role)
restfulx.BindJsonAndValid(rc, &role)
role.CreateBy = rc.LoginAccount.UserName
role.TenantId = rc.LoginAccount.TenantId
insert := r.RoleApp.Insert(role)
role.RoleId = insert.RoleId
r.RoleMenuApp.Insert(insert.RoleId, role.MenuIds)
@@ -69,7 +63,7 @@ func (r *RoleApi) InsertRole(rc *restfulx.ReqCtx) {
// UpdateRole 修改用户角色
func (r *RoleApi) UpdateRole(rc *restfulx.ReqCtx) {
var role entity.SysRole
restfulx.BindQuery(rc, &role)
restfulx.BindJsonAndValid(rc, &role)
role.UpdateBy = rc.LoginAccount.UserName
// 修改角色
r.RoleApp.Update(role)
@@ -85,7 +79,7 @@ func (r *RoleApi) UpdateRole(rc *restfulx.ReqCtx) {
// UpdateRoleStatus 修改用户角色状态
func (r *RoleApi) UpdateRoleStatus(rc *restfulx.ReqCtx) {
var role entity.SysRole
restfulx.BindQuery(rc, &role)
restfulx.BindJsonAndValid(rc, &role)
role.UpdateBy = rc.LoginAccount.UserName
// 修改角色
r.RoleApp.Update(role)
@@ -94,7 +88,7 @@ func (r *RoleApi) UpdateRoleStatus(rc *restfulx.ReqCtx) {
// UpdateRoleDataScope 修改用户角色部门
func (r *RoleApi) UpdateRoleDataScope(rc *restfulx.ReqCtx) {
var role entity.SysRole
restfulx.BindQuery(rc, &role)
restfulx.BindJsonAndValid(rc, &role)
role.UpdateBy = rc.LoginAccount.UserName
// 修改角色
update := r.RoleApp.Update(role)
@@ -141,9 +135,7 @@ func (p *RoleApi) ExportRole(rc *restfulx.ReqCtx) {
roleName := restfulx.QueryParam(rc, "roleName")
roleKey := restfulx.QueryParam(rc, "roleKey")
role := entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
role.TenantId = rc.LoginAccount.TenantId
}
list := p.RoleApp.FindList(role)
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)

View File

@@ -3,18 +3,21 @@ package api
import (
"fmt"
"github.com/XM-GO/PandaKit/biz"
"github.com/XM-GO/PandaKit/oss"
"github.com/XM-GO/PandaKit/restfulx"
"net/http"
"os"
"pandax/pkg/config"
"pandax/pkg/global"
"pandax/pkg/tool"
"path"
"time"
)
type UploadApi struct{}
const filePath = "uploads/file"
// UploadImage 图片上传
// UploadImage 图片上传
func (up *UploadApi) UploadImage(rc *restfulx.ReqCtx) {
_, fileHeader, err := rc.Request.Request.FormFile("file")
@@ -25,6 +28,19 @@ func (up *UploadApi) UploadImage(rc *restfulx.ReqCtx) {
rc.ResData = map[string]string{"fileName": fileName, "filePath": link}
}
// UplaodResOsses 上传文件ResOsses
func (p *UploadApi) UplaodToOss(rc *restfulx.ReqCtx) {
_, handler, _ := rc.Request.Request.FormFile("file")
yunFileTmpPath := "uploads/" + time.Now().Format("2006-01-02") + "/" + handler.Filename
// 读取本地文件。
f, openError := handler.Open()
biz.ErrIsNil(openError, "function file.Open() Failed")
config := global.Conf.Oss
biz.ErrIsNil(NewOss(*config).PutObj(yunFileTmpPath, f), "上传OSS失败")
rc.ResData = fmt.Sprintf("http://%s/%s/%s", config.Endpoint, config.BucketName, yunFileTmpPath)
}
func (up *UploadApi) GetImage(rc *restfulx.ReqCtx) {
actual := path.Join(filePath, restfulx.PathParam(rc, "subpath"))
http.ServeFile(
@@ -39,3 +55,14 @@ func (up *UploadApi) DeleteImage(rc *restfulx.ReqCtx) {
err := os.Remove(fmt.Sprintf("%s/%s", filePath, fileName))
biz.ErrIsNil(err, "文件删除失败")
}
func NewOss(ens config.Oss) oss.Driver {
return oss.NewMiniOss(oss.MiniOConfig{
BucketName: ens.BucketName,
Endpoint: ens.Endpoint,
AccessKeyID: ens.AccessKey,
SecretAccessKey: ens.SecretKey,
UseSSL: ens.UseSSL,
Location: "cn-north-1",
})
}

View File

@@ -58,7 +58,7 @@ func (u *UserApi) RefreshToken(rc *restfulx.ReqCtx) {
// Login 用户登录
func (u *UserApi) Login(rc *restfulx.ReqCtx) {
var l form.Login
restfulx.BindQuery(rc, &l)
restfulx.BindJsonAndValid(rc, &l)
log.Println(l)
biz.IsTrue(captcha.Verify(l.CaptchaId, l.Captcha), "验证码认证失败")
@@ -67,7 +67,6 @@ func (u *UserApi) Login(rc *restfulx.ReqCtx) {
j := token.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256)
token, err := j.CreateToken(token.Claims{
UserId: login.UserId,
TenantId: login.TenantId,
UserName: login.Username,
RoleId: login.RoleId,
RoleKey: role.RoleKey,
@@ -156,9 +155,6 @@ func (u *UserApi) GetSysUserList(rc *restfulx.ReqCtx) {
user.Phone = phone
user.DeptId = int64(deptId)
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
user.TenantId = rc.LoginAccount.TenantId
}
list, total := u.UserApp.FindListPage(pageNum, pageSize, user)
rc.ResData = model.ResultPage{
@@ -222,7 +218,7 @@ func (u *UserApi) InsetSysUserAvatar(rc *restfulx.ReqCtx) {
// SysUserUpdatePwd 修改密码
func (u *UserApi) SysUserUpdatePwd(rc *restfulx.ReqCtx) {
var pws entity.SysUserPwd
restfulx.BindQuery(rc, &pws)
restfulx.BindJsonAndValid(rc, &pws)
user := entity.SysUser{}
user.UserId = rc.LoginAccount.UserId
@@ -238,23 +234,16 @@ func (u *UserApi) GetSysUser(rc *restfulx.ReqCtx) {
result := u.UserApp.FindOne(user)
var role entity.SysRole
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
role.TenantId = rc.LoginAccount.TenantId
}
roles := u.RoleApp.FindList(role)
var post entity.SysPost
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
post.TenantId = rc.LoginAccount.TenantId
}
posts := u.PostApp.FindList(post)
var dept entity.SysDept
rc.ResData = vo.UserVo{
Data: result,
PostIds: result.PostIds,
RoleIds: result.RoleIds,
Roles: *roles,
Posts: *posts,
Roles: *u.RoleApp.FindList(role),
Posts: *u.PostApp.FindList(post),
Depts: u.DeptApp.SelectDept(dept),
}
}
@@ -262,14 +251,8 @@ func (u *UserApi) GetSysUser(rc *restfulx.ReqCtx) {
func (u *UserApi) GetSysUserInit(rc *restfulx.ReqCtx) {
var role entity.SysRole
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
role.TenantId = rc.LoginAccount.TenantId
}
roles := u.RoleApp.FindList(role)
var post entity.SysPost
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
post.TenantId = rc.LoginAccount.TenantId
}
posts := u.PostApp.FindList(post)
rc.ResData = vo.UserRolePost{
Roles: *roles,
@@ -303,7 +286,7 @@ func (u *UserApi) GetUserRolePost(rc *restfulx.ReqCtx) {
// InsertSysUser 创建用户
func (u *UserApi) InsertSysUser(rc *restfulx.ReqCtx) {
var sysUser entity.SysUser
restfulx.BindQuery(rc, &sysUser)
restfulx.BindJsonAndValid(rc, &sysUser)
sysUser.CreateBy = rc.LoginAccount.UserName
u.UserApp.Insert(sysUser)
}
@@ -311,7 +294,7 @@ func (u *UserApi) InsertSysUser(rc *restfulx.ReqCtx) {
// UpdateSysUser 修改用户数据
func (u *UserApi) UpdateSysUser(rc *restfulx.ReqCtx) {
var sysUser entity.SysUser
restfulx.BindQuery(rc, &sysUser)
restfulx.BindJsonAndValid(rc, &sysUser)
sysUser.CreateBy = rc.LoginAccount.UserName
u.UserApp.Update(sysUser)
}
@@ -319,7 +302,7 @@ func (u *UserApi) UpdateSysUser(rc *restfulx.ReqCtx) {
// UpdateSysUserStu 修改用户状态
func (u *UserApi) UpdateSysUserStu(rc *restfulx.ReqCtx) {
var sysUser entity.SysUser
restfulx.BindQuery(rc, &sysUser)
restfulx.BindJsonAndValid(rc, &sysUser)
sysUser.CreateBy = rc.LoginAccount.UserName
u.UserApp.Update(sysUser)
}
@@ -342,10 +325,6 @@ func (u *UserApi) ExportUser(rc *restfulx.ReqCtx) {
user.Username = username
user.Phone = phone
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
user.TenantId = rc.LoginAccount.TenantId
}
list := u.UserApp.FindList(user)
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
utils.InterfaceToExcel(*list, fileName)

View File

@@ -55,6 +55,7 @@ type UserVo struct {
RoleIds string `json:"roleIds"`
Roles []entity.SysRole `json:"roles"`
Posts []entity.SysPost `json:"posts"`
Depts []entity.SysDept `json:"depts"`
}
type UserRolePost struct {