mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-01 09:31:28 +08:00
项目目录优化,任务模块后端代码
This commit is contained in:
89
apps/log/api/log_login.go
Normal file
89
apps/log/api/log_login.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/apps/log/services"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/utils"
|
||||
)
|
||||
|
||||
type LogLoginApi struct {
|
||||
LogLoginApp services.LogLoginModel
|
||||
}
|
||||
|
||||
// @Summary 登录日志列表
|
||||
// @Description 获取JSON
|
||||
// @Tags 登录日志
|
||||
// @Param status query string false "status"
|
||||
// @Param username query string false "username"
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageNum query int false "页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/list [get]
|
||||
// @Security
|
||||
func (l *LogLoginApi) GetLoginLogList(rc *ctx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
loginLocation := rc.GinCtx.Query("loginLocation")
|
||||
username := rc.GinCtx.Query("username")
|
||||
|
||||
list, total := l.LogLoginApp.FindListPage(pageNum, pageSize, entity.LogLogin{LoginLocation: loginLocation, Username: username})
|
||||
rc.ResData = map[string]interface{}{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
"pageSize": pageSize,
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 通过编码获取登录日志
|
||||
// @Description 获取JSON
|
||||
// @Tags 登录日志
|
||||
// @Param infoId path int true "infoId"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/logLogin/{infoId} [get]
|
||||
// @Security
|
||||
func (l *LogLoginApi) GetLoginLog(rc *ctx.ReqCtx) {
|
||||
infoId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("infoId"))
|
||||
rc.ResData = l.LogLoginApp.FindOne(int64(infoId))
|
||||
}
|
||||
|
||||
// @Summary 修改登录日志
|
||||
// @Description 获取JSON
|
||||
// @Tags 登录日志
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body entity.LogLogin true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /system/log/logLogin [put]
|
||||
// @Security X-TOKEN
|
||||
func (l *LogLoginApi) UpdateLoginLog(rc *ctx.ReqCtx) {
|
||||
var log entity.LogLogin
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &log)
|
||||
l.LogLoginApp.Update(log)
|
||||
}
|
||||
|
||||
// @Summary 批量删除登录日志
|
||||
// @Description 删除数据
|
||||
// @Tags 登录日志
|
||||
// @Param infoId path string true "以逗号(,)分割的infoId"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logLogin/{infoId} [delete]
|
||||
func (l *LogLoginApi) DeleteLoginLog(rc *ctx.ReqCtx) {
|
||||
infoIds := rc.GinCtx.Param("infoId")
|
||||
group := utils.IdsStrToIdsIntGroup(infoIds)
|
||||
l.LogLoginApp.Delete(group)
|
||||
}
|
||||
|
||||
// @Summary 清空登录日志
|
||||
// @Description 删除数据
|
||||
// @Tags 登录日志
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logLogin/all [delete]
|
||||
func (l *LogLoginApi) DeleteAll(rc *ctx.ReqCtx) {
|
||||
l.LogLoginApp.DeleteAll()
|
||||
}
|
||||
76
apps/log/api/log_oper.go
Normal file
76
apps/log/api/log_oper.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/apps/log/services"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/utils"
|
||||
)
|
||||
|
||||
type LogOperApi struct {
|
||||
LogOperApp services.LogOperModel
|
||||
}
|
||||
|
||||
// @Summary 操作日志列表
|
||||
// @Description 获取JSON
|
||||
// @Tags 操作日志
|
||||
// @Param status query string false "status"
|
||||
// @Param operName query string false "operName"
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageNum query int false "页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/list [get]
|
||||
// @Security
|
||||
func (l *LogOperApi) GetOperLogList(rc *ctx.ReqCtx) {
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
|
||||
businessType := rc.GinCtx.Query("businessType")
|
||||
operName := rc.GinCtx.Query("operName")
|
||||
title := rc.GinCtx.Query("title")
|
||||
list, total := l.LogOperApp.FindListPage(pageNum, pageSize, entity.LogOper{BusinessType: businessType, OperName: operName, Title: title})
|
||||
rc.ResData = map[string]interface{}{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
"pageSize": pageSize,
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 通过编码获取操作日志
|
||||
// @Description 获取JSON
|
||||
// @Tags 操作日志
|
||||
// @Param operId path int true "operId"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/log/logOper/{operId} [get]
|
||||
// @Security
|
||||
func (l *LogOperApi) GetOperLog(rc *ctx.ReqCtx) {
|
||||
operId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("operId"))
|
||||
rc.ResData = l.LogOperApp.FindOne(int64(operId))
|
||||
}
|
||||
|
||||
// @Summary 批量删除操作日志
|
||||
// @Description 删除数据
|
||||
// @Tags 操作日志
|
||||
// @Param operId path string true "以逗号(,)分割的operId"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logOper/{operId} [delete]
|
||||
func (l *LogOperApi) DeleteOperLog(rc *ctx.ReqCtx) {
|
||||
operIds := rc.GinCtx.Param("operId")
|
||||
group := utils.IdsStrToIdsIntGroup(operIds)
|
||||
log.Println("group", group)
|
||||
l.LogOperApp.Delete(group)
|
||||
}
|
||||
|
||||
// @Summary 清空操作日志
|
||||
// @Description 删除数据
|
||||
// @Tags 操作日志
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /system/log/logOper/all [delete]
|
||||
func (l *LogOperApi) DeleteAll(rc *ctx.ReqCtx) {
|
||||
l.LogOperApp.DeleteAll()
|
||||
}
|
||||
24
apps/log/entity/log_login.go
Normal file
24
apps/log/entity/log_login.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"pandax/base/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LogLogin struct {
|
||||
InfoId int64 `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键
|
||||
Username string `json:"username" gorm:"type:varchar(128);comment:用户名"`
|
||||
Status string `json:"status" gorm:"type:varchar(1);comment:状态"`
|
||||
Ipaddr string `json:"ipaddr" gorm:"type:varchar(255);comment:ip地址"`
|
||||
LoginLocation string `json:"loginLocation" gorm:"type:varchar(255);comment:归属地"`
|
||||
Browser string `json:"browser" gorm:"type:varchar(255);comment:浏览器"`
|
||||
Os string `json:"os" gorm:"type:varchar(255);comment:系统"`
|
||||
Platform string `json:"platform" gorm:"type:varchar(255);comment:固件"`
|
||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;comment:登录时间"`
|
||||
CreateBy string `json:"createBy" gorm:"type:varchar(128);comment:创建人"`
|
||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);comment:更新者"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
Remark string `json:"remark" gorm:"type:varchar(255);"` //备注
|
||||
Msg string `json:"msg" gorm:"type:varchar(255);"`
|
||||
model.BaseModel
|
||||
}
|
||||
19
apps/log/entity/log_oper.go
Normal file
19
apps/log/entity/log_oper.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"pandax/base/model"
|
||||
)
|
||||
|
||||
type LogOper struct {
|
||||
OperId int64 `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //主键
|
||||
Title string `json:"title" gorm:"type:varchar(128);comment:操作的模块"`
|
||||
BusinessType string `json:"businessType" gorm:"type:varchar(1);comment:0其它 1新增 2修改 3删除"`
|
||||
Method string `json:"method" gorm:"type:varchar(255);comment:请求方法"`
|
||||
OperName string `json:"operName" gorm:"type:varchar(255);comment:操作人员"`
|
||||
OperUrl string `json:"operUrl" gorm:"type:varchar(255);comment:操作url"`
|
||||
OperIp string `json:"operIp" gorm:"type:varchar(255);comment:操作IP"`
|
||||
OperLocation string `json:"operLocation" gorm:"type:varchar(255);comment:操作地点"`
|
||||
OperParam string `json:"operParam" gorm:"type:varchar(255);comment:请求参数"` //
|
||||
Status string `json:"status" gorm:"type:varchar(1);comment:0=正常,1=异常"`
|
||||
model.BaseModel
|
||||
}
|
||||
67
apps/log/router/log.go
Normal file
67
apps/log/router/log.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"pandax/apps/log/api"
|
||||
"pandax/apps/log/services"
|
||||
"pandax/base/ctx"
|
||||
)
|
||||
|
||||
func InitLogRouter(router *gin.RouterGroup) {
|
||||
// 登录日志
|
||||
login := &api.LogLoginApi{
|
||||
LogLoginApp: services.LogLoginModelDao,
|
||||
}
|
||||
logLogin := router.Group("logLogin")
|
||||
|
||||
logLoginListLog := ctx.NewLogInfo("获取登录日志列表")
|
||||
logLogin.GET("list", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(logLoginListLog).Handle(login.GetLoginLogList)
|
||||
})
|
||||
|
||||
getLogLoginLog := ctx.NewLogInfo("获取登录日志信息")
|
||||
logLogin.GET(":infoId", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(getLogLoginLog).Handle(login.GetLoginLog)
|
||||
})
|
||||
|
||||
updateLogLoginLog := ctx.NewLogInfo("修改登录日志信息")
|
||||
logLogin.PUT("", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(updateLogLoginLog).Handle(login.UpdateLoginLog)
|
||||
})
|
||||
|
||||
deleteLogLoginAllLog := ctx.NewLogInfo("删除登录日志信息")
|
||||
logLogin.DELETE("all", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogLoginAllLog).Handle(login.DeleteAll)
|
||||
})
|
||||
|
||||
deleteLogLoginLog := ctx.NewLogInfo("删除登录日志信息")
|
||||
logLogin.DELETE(":infoId", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogLoginLog).Handle(login.DeleteLoginLog)
|
||||
})
|
||||
|
||||
// 操作日志
|
||||
oper := &api.LogOperApi{
|
||||
LogOperApp: services.LogOperModelDao,
|
||||
}
|
||||
logOper := router.Group("logOper")
|
||||
|
||||
logOperListLog := ctx.NewLogInfo("获取操作日志列表")
|
||||
logOper.GET("list", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(logOperListLog).Handle(oper.GetOperLogList)
|
||||
})
|
||||
|
||||
getLogOperLog := ctx.NewLogInfo("获取操作日志信息")
|
||||
logOper.GET(":operId", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(getLogOperLog).Handle(oper.GetOperLog)
|
||||
})
|
||||
|
||||
deleteLogOperAllLog := ctx.NewLogInfo("删除操作日志信息")
|
||||
logOper.DELETE("all", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperAllLog).Handle(oper.DeleteAll)
|
||||
})
|
||||
|
||||
deleteLogOperLog := ctx.NewLogInfo("删除操作日志信息")
|
||||
logOper.DELETE(":operId", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperLog).Handle(oper.DeleteOperLog)
|
||||
})
|
||||
}
|
||||
78
apps/log/services/log_login.go
Normal file
78
apps/log/services/log_login.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
)
|
||||
|
||||
type (
|
||||
LogLoginModel interface {
|
||||
Insert(data entity.LogLogin) *entity.LogLogin
|
||||
FindOne(infoId int64) *entity.LogLogin
|
||||
FindListPage(page, pageSize int, data entity.LogLogin) (*[]entity.LogLogin, int64)
|
||||
Update(data entity.LogLogin) *entity.LogLogin
|
||||
Delete(infoId []int64)
|
||||
DeleteAll()
|
||||
}
|
||||
|
||||
logLoginModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var LogLoginModelDao LogLoginModel = &logLoginModelImpl{
|
||||
table: `log_logins`,
|
||||
}
|
||||
|
||||
func (m *logLoginModelImpl) Insert(data entity.LogLogin) *entity.LogLogin {
|
||||
data.CreateBy = "0"
|
||||
data.UpdateBy = "0"
|
||||
global.Db.Table(m.table).Create(&data)
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *logLoginModelImpl) FindOne(infoId int64) *entity.LogLogin {
|
||||
resData := new(entity.LogLogin)
|
||||
err := global.Db.Table(m.table).Where("`info_id` = ?", infoId).First(resData).Error
|
||||
biz.ErrIsNil(err, "查询登录日志信息失败")
|
||||
return resData
|
||||
}
|
||||
|
||||
func (m *logLoginModelImpl) FindListPage(page, pageSize int, data entity.LogLogin) (*[]entity.LogLogin, int64) {
|
||||
list := make([]entity.LogLogin, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
if data.LoginLocation != "" {
|
||||
db = db.Where("login_location like ?", "%"+data.LoginLocation+"%")
|
||||
}
|
||||
if data.Username != "" {
|
||||
db = db.Where("username like ?", "%"+data.Username+"%")
|
||||
}
|
||||
err := db.Where("`delete_time` IS NULL").Count(&total).Error
|
||||
err = db.Order("info_id desc").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
|
||||
biz.ErrIsNil(err, "查询登录分页日志信息失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *logLoginModelImpl) Update(data entity.LogLogin) *entity.LogLogin {
|
||||
err := global.Db.Table(m.table).Updates(&data).Error
|
||||
biz.ErrIsNil(err, "修改登录日志信息失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *logLoginModelImpl) Delete(infoIds []int64) {
|
||||
err := global.Db.Table(m.table).Delete(&entity.LogLogin{}, "`info_id` in (?)", infoIds).Error
|
||||
biz.ErrIsNil(err, "删除登录日志信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
func (m *logLoginModelImpl) DeleteAll() {
|
||||
global.Db.Exec("DELETE FROM log_logins")
|
||||
}
|
||||
72
apps/log/services/log_oper.go
Normal file
72
apps/log/services/log_oper.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
)
|
||||
|
||||
type (
|
||||
LogOperModel interface {
|
||||
Insert(data entity.LogOper) *entity.LogOper
|
||||
FindOne(infoId int64) *entity.LogOper
|
||||
FindListPage(page, pageSize int, data entity.LogOper) (*[]entity.LogOper, int64)
|
||||
Delete(infoId []int64)
|
||||
DeleteAll()
|
||||
}
|
||||
|
||||
logLogOperModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var LogOperModelDao LogOperModel = &logLogOperModelImpl{
|
||||
table: `log_opers`,
|
||||
}
|
||||
|
||||
func (m *logLogOperModelImpl) Insert(data entity.LogOper) *entity.LogOper {
|
||||
global.Db.Table(m.table).Create(&data)
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *logLogOperModelImpl) FindOne(operId int64) *entity.LogOper {
|
||||
resData := new(entity.LogOper)
|
||||
err := global.Db.Table(m.table).Where("`oper_id` = ?", operId).First(resData).Error
|
||||
biz.ErrIsNil(err, "查询操作日志信息失败")
|
||||
return resData
|
||||
}
|
||||
|
||||
func (m *logLogOperModelImpl) FindListPage(page, pageSize int, data entity.LogOper) (*[]entity.LogOper, int64) {
|
||||
list := make([]entity.LogOper, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.BusinessType != "" {
|
||||
db = db.Where("business_type = ?", data.BusinessType)
|
||||
}
|
||||
if data.OperLocation != "" {
|
||||
db = db.Where("oper_location like ?", "%"+data.OperLocation+"%")
|
||||
}
|
||||
if data.Title != "" {
|
||||
db = db.Where("title like ?", "%"+data.Title+"%")
|
||||
}
|
||||
if data.OperName != "" {
|
||||
db = db.Where("oper_name like ?", "%"+data.OperName+"%")
|
||||
}
|
||||
err := db.Where("`delete_time` IS NULL").Count(&total).Error
|
||||
err = db.Order("create_time desc").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
|
||||
biz.ErrIsNil(err, "查询操作分页日志信息失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *logLogOperModelImpl) Delete(operIds []int64) {
|
||||
err := global.Db.Table(m.table).Delete(&entity.LogOper{}, "`oper_id` in (?)", operIds).Error
|
||||
biz.ErrIsNil(err, "删除操作日志信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
func (m *logLogOperModelImpl) DeleteAll() {
|
||||
global.Db.Exec("DELETE FROM log_opers")
|
||||
}
|
||||
Reference in New Issue
Block a user