mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-29 02:43:23 +08:00
tt
This commit is contained in:
95
hotgo-server/app/controller/apiController/base_controller.go
Normal file
95
hotgo-server/app/controller/apiController/base_controller.go
Normal file
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package apiController
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/bufanyun/hotgo/app/com"
|
||||
"github.com/bufanyun/hotgo/app/consts"
|
||||
"github.com/bufanyun/hotgo/app/form/apiForm"
|
||||
"github.com/bufanyun/hotgo/app/model"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Base = base{}
|
||||
|
||||
type base struct{}
|
||||
|
||||
//
|
||||
// @Title 获取lang信息
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *base) Lang(ctx context.Context, req *apiForm.BaseLangReq) (res *apiForm.BaseLangRes, err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
// @Title 获取IP归属地信息
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *base) IpLocation(ctx context.Context, req *apiForm.IpLocationReq) (res *apiForm.IpLocationRes, err error) {
|
||||
|
||||
panic("测试panic...")
|
||||
data := com.Ip.GetLocation(ctx, req.Ip)
|
||||
res = &apiForm.IpLocationRes{data}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (controller *base) Excel(ctx context.Context, req *apiForm.ExportReq) (res *apiForm.ExportRes, err error) {
|
||||
w := com.Context.Get(ctx).Request.Response
|
||||
|
||||
// 文件名
|
||||
fileName := "demo.xlsx"
|
||||
// 创建excel文件 (第三方excel包)
|
||||
file := excelize.NewFile()
|
||||
// 填充数据
|
||||
index := file.NewSheet("Sheet1")
|
||||
err = file.SetCellValue("Sheet1", "A1", "Hello world.")
|
||||
if err != nil {
|
||||
g.Log().Print(ctx, "SetCellValue:", err)
|
||||
return nil, err
|
||||
}
|
||||
err = file.SetCellValue("Sheet1", "B1", 100)
|
||||
if err != nil {
|
||||
g.Log().Print(ctx, "SetCellValue2:", err)
|
||||
return nil, err
|
||||
}
|
||||
file.SetActiveSheet(index)
|
||||
// 设置header头
|
||||
w.Header().Add("Content-Disposition", "attachment; filename="+fileName)
|
||||
w.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
// 写入字节数据
|
||||
err = file.Write(w.Writer)
|
||||
if err != nil {
|
||||
g.Log().Print(ctx, "Write:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 加入到上下文
|
||||
com.Context.SetResponse(ctx, &model.Response{
|
||||
Code: consts.CodeOK,
|
||||
Message: "",
|
||||
Timestamp: time.Now().Unix(),
|
||||
ReqId: com.Context.Get(ctx).ReqId,
|
||||
})
|
||||
//com.Context.Get(ctx).Request.Exit()
|
||||
return
|
||||
}
|
29
hotgo-server/app/controller/apiController/dict_controller.go
Normal file
29
hotgo-server/app/controller/apiController/dict_controller.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package apiController
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/bufanyun/hotgo/app/form/adminForm"
|
||||
"github.com/bufanyun/hotgo/app/service/sysService"
|
||||
)
|
||||
|
||||
var Dict = dict{}
|
||||
|
||||
type dict struct{}
|
||||
|
||||
//
|
||||
// @Title 获取指定字典类型的属性数据
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *dict) Attribute(ctx context.Context, req *adminForm.DictAttributeReq) (res *adminForm.DictAttributeRes, err error) {
|
||||
|
||||
res, err = sysService.Dict.Attribute(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
95
hotgo-server/app/controller/apiController/log_controller.go
Normal file
95
hotgo-server/app/controller/apiController/log_controller.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package apiController
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/bufanyun/hotgo/app/form/apiForm"
|
||||
"github.com/bufanyun/hotgo/app/form/input"
|
||||
"github.com/bufanyun/hotgo/app/service/sysService"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var Log = log{}
|
||||
|
||||
type log struct{}
|
||||
|
||||
//
|
||||
// @Title 清空日志
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *log) Clear(ctx context.Context, req *apiForm.LogClearReq) (res *apiForm.LogClearRes, err error) {
|
||||
err = gerror.New("考虑安全,请到数据库清空")
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
// @Title 导出
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *log) Export(ctx context.Context, req *apiForm.LogExportReq) (res *apiForm.LogExportRes, err error) {
|
||||
|
||||
err = sysService.Log.Export(ctx, input.LogListInp{
|
||||
Page: req.Page,
|
||||
Limit: req.Limit,
|
||||
Module: req.Module,
|
||||
Method: req.Method,
|
||||
Url: req.Url,
|
||||
Ip: req.Ip,
|
||||
ErrorCode: req.ErrorCode,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
MemberId: req.MemberId,
|
||||
TakeUpTime: req.TakeUpTime,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
// @Title 获取全局日志列表
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *log) List(ctx context.Context, req *apiForm.LogListReq) (*apiForm.LogListRes, error) {
|
||||
|
||||
list, totalCount, err := sysService.Log.List(ctx, input.LogListInp{
|
||||
Page: req.Page,
|
||||
Limit: req.Limit,
|
||||
Module: req.Module,
|
||||
Method: req.Method,
|
||||
Url: req.Url,
|
||||
Ip: req.Ip,
|
||||
ErrorCode: req.ErrorCode,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
MemberId: req.MemberId,
|
||||
TakeUpTime: req.TakeUpTime,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res apiForm.LogListRes
|
||||
res.List = list
|
||||
res.TotalCount = totalCount
|
||||
res.Limit = req.Page
|
||||
res.Limit = req.Limit
|
||||
|
||||
return &res, nil
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
package apiController
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/bufanyun/hotgo/app/com"
|
||||
"github.com/bufanyun/hotgo/app/consts"
|
||||
"github.com/bufanyun/hotgo/app/form/apiForm"
|
||||
"github.com/bufanyun/hotgo/app/form/input"
|
||||
"github.com/bufanyun/hotgo/app/service/adminService"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Login = login{}
|
||||
|
||||
type login struct{}
|
||||
|
||||
//
|
||||
// @Title 检查登录
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *login) Check(ctx context.Context, req *apiForm.LoginCheckReq) (*apiForm.LoginCheckRes, error) {
|
||||
|
||||
var res apiForm.LoginCheckRes
|
||||
res.IsValidCodeLogin = false
|
||||
res.Result = "login"
|
||||
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
//
|
||||
// @Title 提交登录
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *login) Sign(ctx context.Context, req *apiForm.LoginReq) (res *apiForm.LoginRes, err error) {
|
||||
|
||||
//// 校验 验证码
|
||||
//if !com.Captcha.VerifyString(req.Cid, req.Code) {
|
||||
// err = gerror.New("验证码错误")
|
||||
// return
|
||||
//}
|
||||
|
||||
var in input.AdminMemberLoginSignInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model, err := adminService.Member.Login(ctx, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = gconv.Scan(model, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
// @Title 注销登录
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *login) Logout(ctx context.Context, req *apiForm.LoginLogoutReq) (res *apiForm.LoginLogoutRes, err error) {
|
||||
|
||||
var authorization = com.Jwt.GetAuthorization(com.Context.Get(ctx).Request)
|
||||
|
||||
// TODO 获取jwtToken
|
||||
jwtToken := consts.RedisJwtToken + gmd5.MustEncryptString(authorization)
|
||||
if len(jwtToken) == 0 {
|
||||
err = gerror.New("当前用户未登录!")
|
||||
return res, err
|
||||
}
|
||||
|
||||
// TODO 删除登录token
|
||||
cache := com.Cache.New()
|
||||
_, err = cache.Remove(ctx, jwtToken)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
package apiController
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/bufanyun/hotgo/app/com"
|
||||
"github.com/bufanyun/hotgo/app/form/apiForm"
|
||||
"github.com/bufanyun/hotgo/app/form/input"
|
||||
"github.com/bufanyun/hotgo/app/service/adminService"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var Member = member{}
|
||||
|
||||
type member struct{}
|
||||
|
||||
//
|
||||
// @Title 获取登录用户的基本信息
|
||||
// @Description
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @Param ctx
|
||||
// @Param req
|
||||
// @Return res
|
||||
// @Return err
|
||||
//
|
||||
func (controller *member) Profile(ctx context.Context, req *apiForm.MemberProfileReq) (*apiForm.MemberProfileRes, error) {
|
||||
|
||||
var res apiForm.MemberProfileRes
|
||||
|
||||
memberId := com.Context.Get(ctx).User.Id
|
||||
if memberId <= 0 {
|
||||
err := gerror.New("获取用户信息失败!")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 用户基本信息
|
||||
memberInfo, err := adminService.Member.View(ctx, input.AdminMemberViewInp{Id: memberId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.User = memberInfo
|
||||
|
||||
// TODO 所在部门
|
||||
sysDept, err := adminService.Dept.View(ctx, input.AdminDeptViewInp{Id: memberInfo.DeptId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.SysDept = sysDept
|
||||
|
||||
// TODO 角色列表
|
||||
sysRoles, err := adminService.Role.GetMemberList(ctx, memberInfo.Role)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.SysRoles = sysRoles
|
||||
|
||||
// TODO 获取角色名称
|
||||
roleGroup, err := adminService.Role.GetName(ctx, memberInfo.Role)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.RoleGroup = roleGroup
|
||||
|
||||
// TODO 获取第一岗位名称
|
||||
postGroup, err := adminService.Post.GetMemberByStartName(ctx, memberInfo.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.PostGroup = postGroup
|
||||
|
||||
return &res, nil
|
||||
}
|
Reference in New Issue
Block a user