1、更新
This commit is contained in:
232
app/admin/apis/mm_app_version.go
Normal file
232
app/admin/apis/mm_app_version.go
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
package apis
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||||
|
"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"
|
||||||
|
"go-admin/app/admin/service"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmAppVersion struct {
|
||||||
|
api.Api
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPage 获取MmAppVersion列表
|
||||||
|
// @Summary 获取MmAppVersion列表
|
||||||
|
// @Description 获取MmAppVersion列表
|
||||||
|
// @Tags MmAppVersion
|
||||||
|
// @Param version query string false "版本号 1.0.0.1"
|
||||||
|
// @Param default query int64 false "是否默认 1-是 2-否"
|
||||||
|
// @Param pageSize query int false "页条数"
|
||||||
|
// @Param pageIndex query int false "页码"
|
||||||
|
// @Success 200 {object} response.Response{data=response.Page{list=[]models.MmAppVersion}} "{"code": 200, "data": [...]}"
|
||||||
|
// @Router /api/v1/mm-app-version [get]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmAppVersion) GetPage(c *gin.Context) {
|
||||||
|
req := dto.MmAppVersionGetPageReq{}
|
||||||
|
s := service.MmAppVersion{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
list := make([]models.MmAppVersion, 0)
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
err = s.GetPage(&req, p, &list, &count)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("获取MmAppVersion失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 获取MmAppVersion
|
||||||
|
// @Summary 获取MmAppVersion
|
||||||
|
// @Description 获取MmAppVersion
|
||||||
|
// @Tags MmAppVersion
|
||||||
|
// @Param id path int false "id"
|
||||||
|
// @Success 200 {object} response.Response{data=models.MmAppVersion} "{"code": 200, "data": [...]}"
|
||||||
|
// @Router /api/v1/mm-app-version/{id} [get]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmAppVersion) Get(c *gin.Context) {
|
||||||
|
req := dto.MmAppVersionGetReq{}
|
||||||
|
s := service.MmAppVersion{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object models.MmAppVersion
|
||||||
|
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
err = s.Get(&req, p, &object)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("获取MmAppVersion失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(object, "查询成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert 创建MmAppVersion
|
||||||
|
// @Summary 创建MmAppVersion
|
||||||
|
// @Description 创建MmAppVersion
|
||||||
|
// @Tags MmAppVersion
|
||||||
|
// @Accept application/json
|
||||||
|
// @Product application/json
|
||||||
|
// @Param data body dto.MmAppVersionInsertReq true "data"
|
||||||
|
// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
|
||||||
|
// @Router /api/v1/mm-app-version [post]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmAppVersion) Insert(c *gin.Context) {
|
||||||
|
req := dto.MmAppVersionInsertReq{}
|
||||||
|
s := service.MmAppVersion{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := req.Valid(); err != nil {
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置创建人
|
||||||
|
req.SetCreateBy(user.GetUserId(c))
|
||||||
|
|
||||||
|
err = s.Insert(&req)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("创建MmAppVersion失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(req.GetId(), "创建成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update 修改MmAppVersion
|
||||||
|
// @Summary 修改MmAppVersion
|
||||||
|
// @Description 修改MmAppVersion
|
||||||
|
// @Tags MmAppVersion
|
||||||
|
// @Accept application/json
|
||||||
|
// @Product application/json
|
||||||
|
// @Param id path int true "id"
|
||||||
|
// @Param data body dto.MmAppVersionUpdateReq true "body"
|
||||||
|
// @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
|
||||||
|
// @Router /api/v1/mm-app-version/{id} [put]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmAppVersion) Update(c *gin.Context) {
|
||||||
|
req := dto.MmAppVersionUpdateReq{}
|
||||||
|
s := service.MmAppVersion{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := req.Valid(); err != nil {
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req.SetUpdateBy(user.GetUserId(c))
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
err = s.Update(&req, p)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("修改MmAppVersion失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(req.GetId(), "修改成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除MmAppVersion
|
||||||
|
// @Summary 删除MmAppVersion
|
||||||
|
// @Description 删除MmAppVersion
|
||||||
|
// @Tags MmAppVersion
|
||||||
|
// @Param data body dto.MmAppVersionDeleteReq true "body"
|
||||||
|
// @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
|
||||||
|
// @Router /api/v1/mm-app-version [delete]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmAppVersion) Delete(c *gin.Context) {
|
||||||
|
s := service.MmAppVersion{}
|
||||||
|
req := dto.MmAppVersionDeleteReq{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// req.SetUpdateBy(user.GetUserId(c))
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
err = s.Remove(&req, p)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("删除MmAppVersion失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(req.GetId(), "删除成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLastVersion 获取最新版本号
|
||||||
|
func (e MmAppVersion) GetLastVersion(c *gin.Context) {
|
||||||
|
s := service.MmAppVersion{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := s.GetLastVersion()
|
||||||
|
if err != nil {
|
||||||
|
c.String(500, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, _ := json.Marshal(data)
|
||||||
|
|
||||||
|
c.String(http.StatusOK, string(resp))
|
||||||
|
}
|
||||||
@ -203,7 +203,10 @@ func (e MmGroup) GetOptions(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
list := make([]dto.MmGroupOption, 0)
|
list := make([]dto.MmGroupOption, 0)
|
||||||
err = s.GetOptions(&list)
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
p.RoleId = user.GetRoleId(c)
|
||||||
|
p.UserId = user.GetUserId(c)
|
||||||
|
err = s.GetOptions(&list, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Error(500, err, fmt.Sprintf("获取设备分组管理失败,\r\n失败信息 %s", err.Error()))
|
e.Error(500, err, fmt.Sprintf("获取设备分组管理失败,\r\n失败信息 %s", err.Error()))
|
||||||
return
|
return
|
||||||
|
|||||||
@ -375,7 +375,10 @@ func (e MmMachine) GetMachineList(c *gin.Context) {
|
|||||||
e.Logger.Error(err)
|
e.Logger.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
machineList, err := s.GetMachineList()
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
p.RoleId = user.GetRoleId(c)
|
||||||
|
p.UserId = user.GetUserId(c)
|
||||||
|
machineList, err := s.GetMachineList(p)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Error(500, err, fmt.Sprintf("获取设备白名单配置失败,\r\n失败信息 %s", err.Error()))
|
e.Error(500, err, fmt.Sprintf("获取设备白名单配置失败,\r\n失败信息 %s", err.Error()))
|
||||||
@ -508,11 +511,34 @@ func (e MmMachine) QueryIntervalAccount(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
intervalAccount, err := s.QueryIntervalAccount()
|
err = s.QueryIntervalAccount(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Error(500, err, fmt.Sprintf("查询设备间隔账号失败,\r\n失败信息 %s", err.Error()))
|
e.Error(500, err, fmt.Sprintf("查询设备间隔账号失败,\r\n失败信息 %s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
e.OK(intervalAccount, "查询成功")
|
|
||||||
|
// 重启设备
|
||||||
|
func (e MmMachine) RebootMachine(c *gin.Context) {
|
||||||
|
s := service.MmMachine{}
|
||||||
|
req := dto.MmMachineRebootReq{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req, binding.JSON).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.RebootMachine(&req)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("重启设备失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(nil, "重启成功")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ func (e MmMachineLog) GetPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p := actions.GetPermissionFromContext(c)
|
p := actions.GetPermissionFromContext(c)
|
||||||
list := make([]models.MmMachineLog, 0)
|
list := make([]dto.MmMachinePageResp, 0)
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
err = s.GetPage(&req, p, &list, &count)
|
err = s.GetPage(&req, p, &list, &count)
|
||||||
|
|||||||
@ -43,7 +43,7 @@ func (e MmRiskLog) GetPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p := actions.GetPermissionFromContext(c)
|
p := actions.GetPermissionFromContext(c)
|
||||||
list := make([]models.MmRiskLog, 0)
|
list := make([]dto.MmRiskLogPageResp, 0)
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
err = s.GetPage(&req, p, &list, &count)
|
err = s.GetPage(&req, p, &list, &count)
|
||||||
|
|||||||
192
app/admin/apis/mm_user_group.go
Normal file
192
app/admin/apis/mm_user_group.go
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
package apis
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/gin-gonic/gin/binding"
|
||||||
|
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||||
|
"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"
|
||||||
|
"go-admin/app/admin/service"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmUserGroup struct {
|
||||||
|
api.Api
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPage 获取用户分组权限列表
|
||||||
|
// @Summary 获取用户分组权限列表
|
||||||
|
// @Description 获取用户分组权限列表
|
||||||
|
// @Tags 用户分组权限
|
||||||
|
// @Param pageSize query int false "页条数"
|
||||||
|
// @Param pageIndex query int false "页码"
|
||||||
|
// @Success 200 {object} response.Response{data=response.Page{list=[]models.MmUserGroup}} "{"code": 200, "data": [...]}"
|
||||||
|
// @Router /api/v1/mm-user-group [get]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmUserGroup) GetPage(c *gin.Context) {
|
||||||
|
req := dto.MmUserGroupGetPageReq{}
|
||||||
|
s := service.MmUserGroup{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req, binding.Form, binding.Query).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
list := make([]models.MmUserGroup, 0)
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
err = s.GetPage(&req, p, &list, &count)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("获取用户分组权限失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 获取用户分组权限
|
||||||
|
// @Summary 获取用户分组权限
|
||||||
|
// @Description 获取用户分组权限
|
||||||
|
// @Tags 用户分组权限
|
||||||
|
// @Param id path int false "id"
|
||||||
|
// @Success 200 {object} response.Response{data=models.MmUserGroup} "{"code": 200, "data": [...]}"
|
||||||
|
// @Router /api/v1/mm-user-group/{id} [get]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmUserGroup) Get(c *gin.Context) {
|
||||||
|
req := dto.MmUserGroupGetReq{}
|
||||||
|
s := service.MmUserGroup{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object models.MmUserGroup
|
||||||
|
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
err = s.Get(&req, p, &object)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("获取用户分组权限失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(object, "查询成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert 创建用户分组权限
|
||||||
|
// @Summary 创建用户分组权限
|
||||||
|
// @Description 创建用户分组权限
|
||||||
|
// @Tags 用户分组权限
|
||||||
|
// @Accept application/json
|
||||||
|
// @Product application/json
|
||||||
|
// @Param data body dto.MmUserGroupInsertReq true "data"
|
||||||
|
// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
|
||||||
|
// @Router /api/v1/mm-user-group [post]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmUserGroup) Insert(c *gin.Context) {
|
||||||
|
req := dto.MmUserGroupInsertReq{}
|
||||||
|
s := service.MmUserGroup{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 设置创建人
|
||||||
|
req.SetCreateBy(user.GetUserId(c))
|
||||||
|
|
||||||
|
err = s.Insert(&req)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("创建用户分组权限失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(req.GetId(), "创建成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update 修改用户分组权限
|
||||||
|
// @Summary 修改用户分组权限
|
||||||
|
// @Description 修改用户分组权限
|
||||||
|
// @Tags 用户分组权限
|
||||||
|
// @Accept application/json
|
||||||
|
// @Product application/json
|
||||||
|
// @Param id path int true "id"
|
||||||
|
// @Param data body dto.MmUserGroupUpdateReq true "body"
|
||||||
|
// @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
|
||||||
|
// @Router /api/v1/mm-user-group/{id} [put]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmUserGroup) Update(c *gin.Context) {
|
||||||
|
req := dto.MmUserGroupUpdateReq{}
|
||||||
|
s := service.MmUserGroup{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.SetUpdateBy(user.GetUserId(c))
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
err = s.Update(&req, p)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("修改用户分组权限失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(req.GetId(), "修改成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete 删除用户分组权限
|
||||||
|
// @Summary 删除用户分组权限
|
||||||
|
// @Description 删除用户分组权限
|
||||||
|
// @Tags 用户分组权限
|
||||||
|
// @Param data body dto.MmUserGroupDeleteReq true "body"
|
||||||
|
// @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
|
||||||
|
// @Router /api/v1/mm-user-group [delete]
|
||||||
|
// @Security Bearer
|
||||||
|
func (e MmUserGroup) Delete(c *gin.Context) {
|
||||||
|
s := service.MmUserGroup{}
|
||||||
|
req := dto.MmUserGroupDeleteReq{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
Bind(&req).
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// req.SetUpdateBy(user.GetUserId(c))
|
||||||
|
p := actions.GetPermissionFromContext(c)
|
||||||
|
|
||||||
|
err = s.Remove(&req, p)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(500, err, fmt.Sprintf("删除用户分组权限失败,\r\n失败信息 %s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(req.GetId(), "删除成功")
|
||||||
|
}
|
||||||
@ -1,11 +1,12 @@
|
|||||||
package apis
|
package apis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin/binding"
|
|
||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin/binding"
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||||
@ -457,3 +458,26 @@ func (e SysUser) GetInfo(c *gin.Context) {
|
|||||||
mp["code"] = 200
|
mp["code"] = 200
|
||||||
e.OK(mp, "")
|
e.OK(mp, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户列表
|
||||||
|
func (e SysUser) GetList(c *gin.Context) {
|
||||||
|
s := service.SysUser{}
|
||||||
|
err := e.MakeContext(c).
|
||||||
|
MakeOrm().
|
||||||
|
MakeService(&s.Service).
|
||||||
|
Errors
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
datas := make([]dto.SysUserOptions, 0)
|
||||||
|
err = s.GetList(&datas)
|
||||||
|
if err != nil {
|
||||||
|
e.Logger.Error(err)
|
||||||
|
e.Error(500, err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(datas, "查询成功")
|
||||||
|
}
|
||||||
|
|||||||
29
app/admin/models/mm_app_version.go
Normal file
29
app/admin/models/mm_app_version.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-admin/common/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmAppVersion struct {
|
||||||
|
models.Model
|
||||||
|
|
||||||
|
Version string `json:"version" gorm:"type:varchar(20);comment:版本号 1.0.0.1"`
|
||||||
|
Default int `json:"default" gorm:"type:tinyint;column:default;comment:是否默认 1-是 2-否"`
|
||||||
|
Path string `json:"path" gorm:"type:varchar(500);comment:文件地址"`
|
||||||
|
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注信息"`
|
||||||
|
models.ModelTime
|
||||||
|
models.ControlBy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (MmAppVersion) TableName() string {
|
||||||
|
return "mm_app_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MmAppVersion) Generate() models.ActiveRecord {
|
||||||
|
o := *e
|
||||||
|
return &o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MmAppVersion) GetId() interface{} {
|
||||||
|
return e.Id
|
||||||
|
}
|
||||||
@ -1,9 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
"go-admin/common/models"
|
"go-admin/common/models"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MmMachineLog struct {
|
type MmMachineLog struct {
|
||||||
|
|||||||
30
app/admin/models/mm_user_group.go
Normal file
30
app/admin/models/mm_user_group.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-admin/common/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmUserGroup struct {
|
||||||
|
models.Model
|
||||||
|
|
||||||
|
UserId int `json:"userId" gorm:"type:int;comment:用户id"`
|
||||||
|
GroupIds string `json:"groupIds" gorm:"type:varchar(500);comment:设备分组ids (逗号分隔)"`
|
||||||
|
GroupIdList []int `json:"groupIdList" gorm:"-"`
|
||||||
|
GroupNames string `json:"groupNames" gorm:"-"`
|
||||||
|
UserName string `json:"userName" gorm:"-"`
|
||||||
|
models.ModelTime
|
||||||
|
models.ControlBy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (MmUserGroup) TableName() string {
|
||||||
|
return "mm_user_group"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MmUserGroup) Generate() models.ActiveRecord {
|
||||||
|
o := *e
|
||||||
|
return &o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MmUserGroup) GetId() interface{} {
|
||||||
|
return e.Id
|
||||||
|
}
|
||||||
36
app/admin/router/mm_app_version.go
Normal file
36
app/admin/router/mm_app_version.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
|
||||||
|
|
||||||
|
"go-admin/app/admin/apis"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
"go-admin/common/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
routerCheckRole = append(routerCheckRole, registerMmAppVersionRouter)
|
||||||
|
routerNoCheckRole = append(routerNoCheckRole, registerNoCheckRoleMmAppVersionRouter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// registerMmAppVersionRouter
|
||||||
|
func registerMmAppVersionRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
|
api := apis.MmAppVersion{}
|
||||||
|
r := v1.Group("/mm-app-version").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||||
|
{
|
||||||
|
r.GET("", actions.PermissionAction(), api.GetPage)
|
||||||
|
r.GET("/:id", actions.PermissionAction(), api.Get)
|
||||||
|
r.POST("", api.Insert)
|
||||||
|
r.PUT("/:id", actions.PermissionAction(), api.Update)
|
||||||
|
r.DELETE("", api.Delete)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerNoCheckRoleMmAppVersionRouter(v1 *gin.RouterGroup) {
|
||||||
|
api := apis.MmAppVersion{}
|
||||||
|
r := v1.Group("/mm-app-version")
|
||||||
|
{
|
||||||
|
r.GET("last", api.GetLastVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,5 +25,5 @@ func registerMmGroupRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
|||||||
r.DELETE("", api.Delete)
|
r.DELETE("", api.Delete)
|
||||||
}
|
}
|
||||||
|
|
||||||
v1.Group("/mm-group").GET("options", api.GetOptions)
|
v1.Group("/mm-group").Use(authMiddleware.MiddlewareFunc()).GET("options", actions.PermissionAction(), api.GetOptions)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,12 @@ func registerMmMachineRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMidd
|
|||||||
r.PUT("descriptionBatch", actions.PermissionAction(), api.UpdateDescriptionBatch)
|
r.PUT("descriptionBatch", actions.PermissionAction(), api.UpdateDescriptionBatch)
|
||||||
r.DELETE("uninstall", actions.PermissionAction(), api.Uninstall)
|
r.DELETE("uninstall", actions.PermissionAction(), api.Uninstall)
|
||||||
r.GET("intervalAccount", actions.PermissionAction(), api.QueryIntervalAccount)
|
r.GET("intervalAccount", actions.PermissionAction(), api.QueryIntervalAccount)
|
||||||
|
r.POST("reboot", actions.PermissionAction(), api.RebootMachine)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r2 := v1.Group("/mm-machine").Use(authMiddleware.MiddlewareFunc())
|
||||||
|
|
||||||
|
r2.GET("list", api.GetMachineList) //设备列表
|
||||||
}
|
}
|
||||||
|
|
||||||
// 未校验权限的
|
// 未校验权限的
|
||||||
@ -42,7 +47,6 @@ func registerMmMachineRouterNoRole(v1 *gin.RouterGroup) {
|
|||||||
|
|
||||||
r := v1.Group("/mm-machine")
|
r := v1.Group("/mm-machine")
|
||||||
{
|
{
|
||||||
r.GET("list", api.GetMachineList) //设备列表
|
|
||||||
r.GET("getPassword", api.GetPassword) //获取密码
|
r.GET("getPassword", api.GetPassword) //获取密码
|
||||||
r.GET("whiteProcess", api.GetWhiteProcess) //获取白名单进程
|
r.GET("whiteProcess", api.GetWhiteProcess) //获取白名单进程
|
||||||
r.POST("machineWhite", api.UpdateMachineWhite) //修改机器白名单
|
r.POST("machineWhite", api.UpdateMachineWhite) //修改机器白名单
|
||||||
|
|||||||
27
app/admin/router/mm_user_group.go
Normal file
27
app/admin/router/mm_user_group.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
|
||||||
|
|
||||||
|
"go-admin/app/admin/apis"
|
||||||
|
"go-admin/common/middleware"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
routerCheckRole = append(routerCheckRole, registerMmUserGroupRouter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// registerMmUserGroupRouter
|
||||||
|
func registerMmUserGroupRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
|
api := apis.MmUserGroup{}
|
||||||
|
r := v1.Group("/mm-user-group").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||||
|
{
|
||||||
|
r.GET("", actions.PermissionAction(), api.GetPage)
|
||||||
|
r.GET("/:id", actions.PermissionAction(), api.Get)
|
||||||
|
r.POST("", api.Insert)
|
||||||
|
r.PUT("/:id", actions.PermissionAction(), api.Update)
|
||||||
|
r.DELETE("", api.Delete)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,11 +1,12 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
|
|
||||||
"go-admin/app/admin/apis"
|
"go-admin/app/admin/apis"
|
||||||
"go-admin/common/actions"
|
"go-admin/common/actions"
|
||||||
"go-admin/common/middleware"
|
"go-admin/common/middleware"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -35,5 +36,6 @@ func registerSysUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
|||||||
v1auth := v1.Group("").Use(authMiddleware.MiddlewareFunc())
|
v1auth := v1.Group("").Use(authMiddleware.MiddlewareFunc())
|
||||||
{
|
{
|
||||||
v1auth.GET("/getinfo", api.GetInfo)
|
v1auth.GET("/getinfo", api.GetInfo)
|
||||||
|
v1auth.GET("/sys-user/options", api.GetList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
130
app/admin/service/dto/mm_app_version.go
Normal file
130
app/admin/service/dto/mm_app_version.go
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
"go-admin/common/dto"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmAppVersionGetPageReq struct {
|
||||||
|
dto.Pagination `search:"-"`
|
||||||
|
Version string `form:"version" search:"type:contains;column:version;table:mm_app_version" comment:"版本号 1.0.0.1"`
|
||||||
|
Default int64 `form:"default" search:"type:exact;column:default;table:mm_app_version" comment:"是否默认 1-是 2-否"`
|
||||||
|
MmAppVersionOrder
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmAppVersionOrder struct {
|
||||||
|
Id string `form:"idOrder" search:"type:order;column:id;table:mm_app_version"`
|
||||||
|
Version string `form:"versionOrder" search:"type:order;column:version;table:mm_app_version"`
|
||||||
|
Default string `form:"defaultOrder" search:"type:order;column:default;table:mm_app_version"`
|
||||||
|
Path string `form:"pathOrder" search:"type:order;column:path;table:mm_app_version"`
|
||||||
|
Remark string `form:"remarkOrder" search:"type:order;column:remark;table:mm_app_version"`
|
||||||
|
CreatedAt string `form:"createdAtOrder" search:"type:order;column:created_at;table:mm_app_version"`
|
||||||
|
UpdatedAt string `form:"updatedAtOrder" search:"type:order;column:updated_at;table:mm_app_version"`
|
||||||
|
DeletedAt string `form:"deletedAtOrder" search:"type:order;column:deleted_at;table:mm_app_version"`
|
||||||
|
CreateBy string `form:"createByOrder" search:"type:order;column:create_by;table:mm_app_version"`
|
||||||
|
UpdateBy string `form:"updateByOrder" search:"type:order;column:update_by;table:mm_app_version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MmAppVersionGetPageReq) GetNeedSearch() interface{} {
|
||||||
|
return *m
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmAppVersionInsertReq struct {
|
||||||
|
Id int `json:"-" comment:"主键"` // 主键
|
||||||
|
Version string `json:"version" comment:"版本号 1.0.0.1"`
|
||||||
|
Default int `json:"default" comment:"是否默认 1-是 2-否"`
|
||||||
|
Path string `json:"path" comment:"文件地址"`
|
||||||
|
Remark string `json:"remark" comment:"备注信息"`
|
||||||
|
common.ControlBy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MmAppVersionInsertReq) Valid() error {
|
||||||
|
if e.Version == "" {
|
||||||
|
return errors.New("版本号不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.Path == "" {
|
||||||
|
return errors.New("文件不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmAppVersionInsertReq) Generate(model *models.MmAppVersion) {
|
||||||
|
if s.Id == 0 {
|
||||||
|
model.Model = common.Model{Id: s.Id}
|
||||||
|
}
|
||||||
|
model.Version = strings.Trim(s.Version, " ")
|
||||||
|
model.Default = s.Default
|
||||||
|
model.Path = s.Path
|
||||||
|
model.Remark = s.Remark
|
||||||
|
model.CreateBy = s.CreateBy // 添加这而,需要记录是被谁创建的
|
||||||
|
model.Default = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmAppVersionInsertReq) GetId() interface{} {
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmAppVersionUpdateReq struct {
|
||||||
|
Id int `uri:"id" comment:"主键"` // 主键
|
||||||
|
Version string `json:"version" comment:"版本号 1.0.0.1"`
|
||||||
|
Default int `json:"default" comment:"是否默认 1-是 2-否"`
|
||||||
|
Path string `json:"path" comment:"文件地址"`
|
||||||
|
Remark string `json:"remark" comment:"备注信息"`
|
||||||
|
common.ControlBy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MmAppVersionUpdateReq) Valid() error {
|
||||||
|
if e.Version == "" {
|
||||||
|
return errors.New("版本号不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.Path == "" {
|
||||||
|
return errors.New("文件不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmAppVersionUpdateReq) Generate(model *models.MmAppVersion) {
|
||||||
|
if s.Id == 0 {
|
||||||
|
model.Model = common.Model{Id: s.Id}
|
||||||
|
}
|
||||||
|
model.Version = strings.Trim(s.Version, " ")
|
||||||
|
model.Default = s.Default
|
||||||
|
model.Path = s.Path
|
||||||
|
model.Remark = s.Remark
|
||||||
|
model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmAppVersionUpdateReq) GetId() interface{} {
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
// MmAppVersionGetReq 功能获取请求参数
|
||||||
|
type MmAppVersionGetReq struct {
|
||||||
|
Id int `uri:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmAppVersionGetReq) GetId() interface{} {
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
// MmAppVersionDeleteReq 功能删除请求参数
|
||||||
|
type MmAppVersionDeleteReq struct {
|
||||||
|
Ids []int `json:"ids"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmAppVersionDeleteReq) GetId() interface{} {
|
||||||
|
return s.Ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// MmAppVersionResp 功能返回响应
|
||||||
|
type MmAppVersionResp struct {
|
||||||
|
Version string `json:"version" comment:"版本号 1.0.0.1"`
|
||||||
|
Path string `json:"path" comment:"文件地址"`
|
||||||
|
}
|
||||||
@ -14,6 +14,7 @@ type MmMachineGetPageReq struct {
|
|||||||
Status string `form:"status" search:"type:exact;column:status;table:mm_machine" comment:"状态 0-掉线 1-在线"`
|
Status string `form:"status" search:"type:exact;column:status;table:mm_machine" comment:"状态 0-掉线 1-在线"`
|
||||||
GroupId int `form:"groupId" search:"-" comment:"分组id"`
|
GroupId int `form:"groupId" search:"-" comment:"分组id"`
|
||||||
ShowBind int `form:"showBind" search:"-" comment:"是否显示绑定 1-已绑定 2-未绑定"`
|
ShowBind int `form:"showBind" search:"-" comment:"是否显示绑定 1-已绑定 2-未绑定"`
|
||||||
|
MachineId string `form:"machineId" search:"type:contains;column:machine_id;table:mm_machine" comment:"设备id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MmMachineOrder struct {
|
type MmMachineOrder struct {
|
||||||
@ -199,3 +200,11 @@ type MmMachineDeleteReq struct {
|
|||||||
func (s *MmMachineDeleteReq) GetId() interface{} {
|
func (s *MmMachineDeleteReq) GetId() interface{} {
|
||||||
return s.Ids
|
return s.Ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MmMachineRebootReq struct {
|
||||||
|
MachineIds []string `json:"machineIds"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmMachineExportResp struct {
|
||||||
|
MachineId string `json:"machineId" excel:"设备id"`
|
||||||
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ type MmMachineLogGetPageReq struct {
|
|||||||
BiosId string `form:"biosId" search:"type:exact;column:bios_id;table:mm_machine_log" comment:"客户端唯一码"`
|
BiosId string `form:"biosId" search:"type:exact;column:bios_id;table:mm_machine_log" comment:"客户端唯一码"`
|
||||||
Type string `form:"type" search:"type:exact;column:type;table:mm_machine_log" comment:"日志类型(1-软件运行,2-软件安装,3-软件卸载,4-退出软件,5-修改机器号,6-进程拦截,7-心跳请求"`
|
Type string `form:"type" search:"type:exact;column:type;table:mm_machine_log" comment:"日志类型(1-软件运行,2-软件安装,3-软件卸载,4-退出软件,5-修改机器号,6-进程拦截,7-心跳请求"`
|
||||||
Remark string `form:"remark" search:"type:contains;column:remark;table:mm_machine_log" comment:"备注"`
|
Remark string `form:"remark" search:"type:contains;column:remark;table:mm_machine_log" comment:"备注"`
|
||||||
|
GroupId int `form:"groupId" search:"-" comment:"分组id"`
|
||||||
MmMachineLogOrder
|
MmMachineLogOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ type MmMachineHeartResp struct {
|
|||||||
HeartInterval int `json:"hi" comment:"心跳间隔(秒)"`
|
HeartInterval int `json:"hi" comment:"心跳间隔(秒)"`
|
||||||
KeywordsInterval int `json:"ki" comment:"关键字间隔(秒)"`
|
KeywordsInterval int `json:"ki" comment:"关键字间隔(秒)"`
|
||||||
InterceptInterval float64 `json:"ii" comment:"拦截间隔(小时)"`
|
InterceptInterval float64 `json:"ii" comment:"拦截间隔(小时)"`
|
||||||
|
Reboot bool `json:"rb" comment:"是否重启"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MmMachineLogInsertReq struct {
|
type MmMachineLogInsertReq struct {
|
||||||
@ -110,3 +112,18 @@ type MmMachineLogDeleteReq struct {
|
|||||||
func (s *MmMachineLogDeleteReq) GetId() interface{} {
|
func (s *MmMachineLogDeleteReq) GetId() interface{} {
|
||||||
return s.Ids
|
return s.Ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MachineGroupResp struct {
|
||||||
|
MachineId string `json:"machineId" comment:"机器编号"`
|
||||||
|
GroupName string `json:"groupName" comment:"分组名称"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmMachinePageResp struct {
|
||||||
|
Id int `json:"id" comment:"主键id"`
|
||||||
|
GroupId int `json:"groupId" comment:"分组id"`
|
||||||
|
MachineId string `json:"machineId" comment:"机器编号"`
|
||||||
|
BiosId string `json:"biosId" comment:"客户端唯一码"`
|
||||||
|
Type string `json:"type" comment:"日志类型(1-软件运行,2-软件安装,3-软件卸载,4-退出软件,5-修改机器号,6-进程拦截,7-心跳请求"`
|
||||||
|
Remark string `json:"remark" comment:"备注"`
|
||||||
|
CreatedAt string `json:"createdAt" comment:"创建时间"`
|
||||||
|
}
|
||||||
|
|||||||
@ -5,11 +5,13 @@ import (
|
|||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MmRiskLogGetPageReq struct {
|
type MmRiskLogGetPageReq struct {
|
||||||
dto.Pagination `search:"-"`
|
dto.Pagination `search:"-"`
|
||||||
Content string `form:"content" search:"type:contains;column:content;table:mm_risk_log" comment:"关键字"`
|
Content string `form:"content" search:"type:contains;column:content;table:mm_risk_log" comment:"关键字"`
|
||||||
|
GroupId int `form:"groupId" search:"-"`
|
||||||
MmRiskLogOrder
|
MmRiskLogOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,3 +121,13 @@ type MmRiskLogDeleteReq struct {
|
|||||||
func (s *MmRiskLogDeleteReq) GetId() interface{} {
|
func (s *MmRiskLogDeleteReq) GetId() interface{} {
|
||||||
return s.Ids
|
return s.Ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MmRiskLogPageResp struct {
|
||||||
|
Id int `json:"id" comment:"主键id"` // 主键id
|
||||||
|
GroupId int `json:"groupId" comment:"组id"`
|
||||||
|
MachineId string `json:"machineId" comment:"机器id"`
|
||||||
|
BiosId string `json:"biosId" comment:"bios id"`
|
||||||
|
Type int `json:"type" comment:"类型 0-关键字 1-长度限制"`
|
||||||
|
Content string `json:"content" comment:"内容"`
|
||||||
|
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
|
||||||
|
}
|
||||||
|
|||||||
99
app/admin/service/dto/mm_user_group.go
Normal file
99
app/admin/service/dto/mm_user_group.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
"go-admin/common/dto"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmUserGroupGetPageReq struct {
|
||||||
|
dto.Pagination `search:"-"`
|
||||||
|
MmUserGroupOrder
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmUserGroupOrder struct {
|
||||||
|
Id string `form:"idOrder" search:"type:order;column:id;table:mm_user_group"`
|
||||||
|
UserId string `form:"userIdOrder" search:"type:order;column:user_id;table:mm_user_group"`
|
||||||
|
GroupIds string `form:"groupIdsOrder" search:"type:order;column:group_ids;table:mm_user_group"`
|
||||||
|
CreatedAt string `form:"createdAtOrder" search:"type:order;column:created_at;table:mm_user_group"`
|
||||||
|
UpdatedAt string `form:"updatedAtOrder" search:"type:order;column:updated_at;table:mm_user_group"`
|
||||||
|
DeletedAt string `form:"deletedAtOrder" search:"type:order;column:deleted_at;table:mm_user_group"`
|
||||||
|
CreateBy string `form:"createByOrder" search:"type:order;column:create_by;table:mm_user_group"`
|
||||||
|
UpdateBy string `form:"updateByOrder" search:"type:order;column:update_by;table:mm_user_group"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MmUserGroupGetPageReq) GetNeedSearch() interface{} {
|
||||||
|
return *m
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmUserGroupInsertReq struct {
|
||||||
|
Id int `json:"-" comment:"主键id"` // 主键id
|
||||||
|
UserId int `json:"userId" comment:"用户id"`
|
||||||
|
GroupIds string `json:"groupIds" comment:"设备分组ids"`
|
||||||
|
GroupIdList []int `json:"groupIdList" comment:"设备分组id列表"`
|
||||||
|
common.ControlBy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmUserGroupInsertReq) Generate(model *models.MmUserGroup) {
|
||||||
|
if s.Id == 0 {
|
||||||
|
model.Model = common.Model{Id: s.Id}
|
||||||
|
}
|
||||||
|
idArray := make([]string, 0)
|
||||||
|
model.UserId = s.UserId
|
||||||
|
|
||||||
|
for _, id := range s.GroupIdList {
|
||||||
|
idArray = append(idArray, strconv.Itoa(id))
|
||||||
|
}
|
||||||
|
model.GroupIds = strings.Join(idArray, ",")
|
||||||
|
model.CreateBy = s.CreateBy // 添加这而,需要记录是被谁创建的
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmUserGroupInsertReq) GetId() interface{} {
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
type MmUserGroupUpdateReq struct {
|
||||||
|
Id int `uri:"id" comment:"主键id"` // 主键id
|
||||||
|
UserId int `json:"userId" comment:"用户id"`
|
||||||
|
GroupIds string `json:"groupIds" comment:"设备分组ids"`
|
||||||
|
GroupIdList []int `json:"groupIdList" comment:"设备分组id列表"`
|
||||||
|
common.ControlBy
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmUserGroupUpdateReq) Generate(model *models.MmUserGroup) {
|
||||||
|
if s.Id == 0 {
|
||||||
|
model.Model = common.Model{Id: s.Id}
|
||||||
|
}
|
||||||
|
idArray := make([]string, 0)
|
||||||
|
model.UserId = s.UserId
|
||||||
|
|
||||||
|
for _, id := range s.GroupIdList {
|
||||||
|
idArray = append(idArray, strconv.Itoa(id))
|
||||||
|
}
|
||||||
|
model.GroupIds = strings.Join(idArray, ",")
|
||||||
|
model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmUserGroupUpdateReq) GetId() interface{} {
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
// MmUserGroupGetReq 功能获取请求参数
|
||||||
|
type MmUserGroupGetReq struct {
|
||||||
|
Id int `uri:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmUserGroupGetReq) GetId() interface{} {
|
||||||
|
return s.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
// MmUserGroupDeleteReq 功能删除请求参数
|
||||||
|
type MmUserGroupDeleteReq struct {
|
||||||
|
Ids []int `json:"ids"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MmUserGroupDeleteReq) GetId() interface{} {
|
||||||
|
return s.Ids
|
||||||
|
}
|
||||||
@ -93,11 +93,11 @@ type SysUserInsertReq struct {
|
|||||||
Username string `json:"username" comment:"用户名" vd:"len($)>0"`
|
Username string `json:"username" comment:"用户名" vd:"len($)>0"`
|
||||||
Password string `json:"password" comment:"密码"`
|
Password string `json:"password" comment:"密码"`
|
||||||
NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
|
NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
|
||||||
Phone string `json:"phone" comment:"手机号" vd:"len($)>0"`
|
Phone string `json:"phone" comment:"手机号"`
|
||||||
RoleId int `json:"roleId" comment:"角色ID"`
|
RoleId int `json:"roleId" comment:"角色ID"`
|
||||||
Avatar string `json:"avatar" comment:"头像"`
|
Avatar string `json:"avatar" comment:"头像"`
|
||||||
Sex string `json:"sex" comment:"性别"`
|
Sex string `json:"sex" comment:"性别"`
|
||||||
Email string `json:"email" comment:"邮箱" vd:"len($)>0,email"`
|
Email string `json:"email" comment:"邮箱" `
|
||||||
DeptId int `json:"deptId" comment:"部门" vd:"$>0"`
|
DeptId int `json:"deptId" comment:"部门" vd:"$>0"`
|
||||||
PostId int `json:"postId" comment:"岗位"`
|
PostId int `json:"postId" comment:"岗位"`
|
||||||
Remark string `json:"remark" comment:"备注"`
|
Remark string `json:"remark" comment:"备注"`
|
||||||
@ -132,11 +132,11 @@ type SysUserUpdateReq struct {
|
|||||||
UserId int `json:"userId" comment:"用户ID"` // 用户ID
|
UserId int `json:"userId" comment:"用户ID"` // 用户ID
|
||||||
Username string `json:"username" comment:"用户名" vd:"len($)>0"`
|
Username string `json:"username" comment:"用户名" vd:"len($)>0"`
|
||||||
NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
|
NickName string `json:"nickName" comment:"昵称" vd:"len($)>0"`
|
||||||
Phone string `json:"phone" comment:"手机号" vd:"len($)>0"`
|
Phone string `json:"phone" comment:"手机号"`
|
||||||
RoleId int `json:"roleId" comment:"角色ID"`
|
RoleId int `json:"roleId" comment:"角色ID"`
|
||||||
Avatar string `json:"avatar" comment:"头像"`
|
Avatar string `json:"avatar" comment:"头像"`
|
||||||
Sex string `json:"sex" comment:"性别"`
|
Sex string `json:"sex" comment:"性别"`
|
||||||
Email string `json:"email" comment:"邮箱" vd:"len($)>0,email"`
|
Email string `json:"email" comment:"邮箱"`
|
||||||
DeptId int `json:"deptId" comment:"部门" vd:"$>0"`
|
DeptId int `json:"deptId" comment:"部门" vd:"$>0"`
|
||||||
PostId int `json:"postId" comment:"岗位"`
|
PostId int `json:"postId" comment:"岗位"`
|
||||||
Remark string `json:"remark" comment:"备注"`
|
Remark string `json:"remark" comment:"备注"`
|
||||||
@ -187,3 +187,8 @@ type PassWord struct {
|
|||||||
NewPassword string `json:"newPassword" vd:"len($)>0"`
|
NewPassword string `json:"newPassword" vd:"len($)>0"`
|
||||||
OldPassword string `json:"oldPassword" vd:"len($)>0"`
|
OldPassword string `json:"oldPassword" vd:"len($)>0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SysUserOptions struct {
|
||||||
|
UserId int `json:"userId"`
|
||||||
|
NickName string `json:"nickName"`
|
||||||
|
}
|
||||||
|
|||||||
167
app/admin/service/mm_app_version.go
Normal file
167
app/admin/service/mm_app_version.go
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/go-admin-team/go-admin-core/sdk/service"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
cDto "go-admin/common/dto"
|
||||||
|
"go-admin/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmAppVersion struct {
|
||||||
|
service.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPage 获取MmAppVersion列表
|
||||||
|
func (e *MmAppVersion) GetPage(c *dto.MmAppVersionGetPageReq, p *actions.DataPermission, list *[]models.MmAppVersion, count *int64) error {
|
||||||
|
var err error
|
||||||
|
var data models.MmAppVersion
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).
|
||||||
|
Find(list).Limit(-1).Offset(-1).
|
||||||
|
Count(count).Error
|
||||||
|
if err != nil {
|
||||||
|
e.Log.Errorf("MmAppVersionService GetPage error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 获取MmAppVersion对象
|
||||||
|
func (e *MmAppVersion) Get(d *dto.MmAppVersionGetReq, p *actions.DataPermission, model *models.MmAppVersion) error {
|
||||||
|
var data models.MmAppVersion
|
||||||
|
|
||||||
|
err := e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).
|
||||||
|
First(model, d.GetId()).Error
|
||||||
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
err = errors.New("查看对象不存在或无权查看")
|
||||||
|
e.Log.Errorf("Service GetMmAppVersion error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
e.Log.Errorf("db error:%s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert 创建MmAppVersion对象
|
||||||
|
func (e *MmAppVersion) Insert(c *dto.MmAppVersionInsertReq) error {
|
||||||
|
var err error
|
||||||
|
var data models.MmAppVersion
|
||||||
|
var count int64
|
||||||
|
|
||||||
|
c.Generate(&data)
|
||||||
|
err = e.Orm.Transaction(func(tx *gorm.DB) error {
|
||||||
|
tx.Model(&models.MmAppVersion{}).Where("version = ? ", c.Version).Count(&count)
|
||||||
|
|
||||||
|
if count > 0 {
|
||||||
|
return errors.New("版本号已存在,请重新输入")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err1 := tx.Model(&models.MmAppVersion{}).Where("`default` =1").Update("default", 2).Error; err1 != nil {
|
||||||
|
return err1
|
||||||
|
}
|
||||||
|
|
||||||
|
db := tx.Create(&data)
|
||||||
|
if err1 := db.Error; err1 != nil {
|
||||||
|
e.Log.Errorf("MmAppVersionService Save error:%s \r\n", err1)
|
||||||
|
return err1
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权创建该数据")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update 修改MmAppVersion对象
|
||||||
|
func (e *MmAppVersion) Update(c *dto.MmAppVersionUpdateReq, p *actions.DataPermission) error {
|
||||||
|
var err error
|
||||||
|
var data = models.MmAppVersion{}
|
||||||
|
var count int64
|
||||||
|
e.Orm.Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).First(&data, c.GetId())
|
||||||
|
c.Generate(&data)
|
||||||
|
|
||||||
|
err = e.Orm.Transaction(func(tx *gorm.DB) error {
|
||||||
|
tx.Model(&models.MmAppVersion{}).Where("version = ? and id <> ?", c.Version, c.GetId()).Count(&count)
|
||||||
|
|
||||||
|
if count > 0 {
|
||||||
|
return errors.New("版本号已存在,请重新输入")
|
||||||
|
}
|
||||||
|
|
||||||
|
//为默认时需要 修改其他的默认项
|
||||||
|
if c.Default == 1 {
|
||||||
|
if err1 := tx.Model(&models.MmAppVersion{}).Where("`default` =1").Update("default", 2).Error; err1 != nil {
|
||||||
|
return err1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
db := tx.Save(&data)
|
||||||
|
if err1 := db.Error; err1 != nil {
|
||||||
|
e.Log.Errorf("MmAppVersionService Save error:%s \r\n", err1)
|
||||||
|
return err1
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权更新该数据")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove 删除MmAppVersion
|
||||||
|
func (e *MmAppVersion) Remove(d *dto.MmAppVersionDeleteReq, p *actions.DataPermission) error {
|
||||||
|
var data models.MmAppVersion
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).Delete(&data, d.GetId())
|
||||||
|
if err := db.Error; err != nil {
|
||||||
|
e.Log.Errorf("Service RemoveMmAppVersion error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权删除该数据")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLastVersion 获取最新版本号
|
||||||
|
func (e *MmAppVersion) GetLastVersion() (dto.MmAppVersionResp, error) {
|
||||||
|
result := dto.MmAppVersionResp{}
|
||||||
|
var data models.MmAppVersion
|
||||||
|
e.Orm.Model(&data).
|
||||||
|
Where("`default` = 1").
|
||||||
|
Order("id desc").
|
||||||
|
First(&data)
|
||||||
|
|
||||||
|
if data.Id > 0 {
|
||||||
|
result.Version = data.Version
|
||||||
|
result.Path = fmt.Sprintf("%s%s", config.ExtConfig.FileEndPoint, data.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/service"
|
"github.com/go-admin-team/go-admin-core/sdk/service"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -126,9 +127,32 @@ func (e *MmGroup) Remove(d *dto.MmGroupDeleteReq, p *actions.DataPermission) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetOptions 获取MmGroup选项
|
// GetOptions 获取MmGroup选项
|
||||||
func (e *MmGroup) GetOptions(list *[]dto.MmGroupOption) error {
|
func (e *MmGroup) GetOptions(list *[]dto.MmGroupOption, p *actions.DataPermission) error {
|
||||||
var datas []models.MmGroup
|
var datas []models.MmGroup
|
||||||
if err := e.Orm.Model(models.MmGroup{}).Find(&datas).Error; err != nil {
|
var role models.SysRole
|
||||||
|
|
||||||
|
e.Orm.Model(role).Where("role_id =?", p.RoleId).Find(&role)
|
||||||
|
query := e.Orm.Model(models.MmGroup{})
|
||||||
|
|
||||||
|
if role.RoleKey != "admin" {
|
||||||
|
groups := ""
|
||||||
|
e.Orm.Model(models.MmUserGroup{}).Where("user_id = ?", p.UserId).Pluck("group_ids", &groups)
|
||||||
|
ids := strings.Split(groups, ",")
|
||||||
|
groupIds := make([]string, 0)
|
||||||
|
for _, item := range ids {
|
||||||
|
if item != "" {
|
||||||
|
groupIds = append(groupIds, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(groupIds) > 0 {
|
||||||
|
query.Where("id in ?", groupIds)
|
||||||
|
} else {
|
||||||
|
query.Where("1=0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Find(&datas).Error; err != nil {
|
||||||
e.Log.Errorf("Service GetMmGroupOptions error:%s \r\n", err)
|
e.Log.Errorf("Service GetMmGroupOptions error:%s \r\n", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -128,7 +128,7 @@ func (e *MmKeyword) ReloadMachineCache(isAll bool) {
|
|||||||
for _, machineId := range machineIds {
|
for _, machineId := range machineIds {
|
||||||
key := fmt.Sprintf(enums.MachineKeywords, machineId)
|
key := fmt.Sprintf(enums.MachineKeywords, machineId)
|
||||||
|
|
||||||
helper.DefaultRedis.SetStringExpire(key, string(bytes), time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, string(bytes), time.Hour*24)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/service"
|
"github.com/go-admin-team/go-admin-core/sdk/service"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
@ -26,8 +27,29 @@ type MmMachine struct {
|
|||||||
func (e *MmMachine) GetPage(c *dto.MmMachineGetPageReq, p *actions.DataPermission, list *[]models.MmMachine, count *int64) error {
|
func (e *MmMachine) GetPage(c *dto.MmMachineGetPageReq, p *actions.DataPermission, list *[]models.MmMachine, count *int64) error {
|
||||||
var err error
|
var err error
|
||||||
var data models.MmMachine
|
var data models.MmMachine
|
||||||
|
var role models.SysRole
|
||||||
|
query := e.Orm.Model(&data)
|
||||||
|
e.Orm.Model(role).Where("role_id =?", p.RoleId).Find(&role)
|
||||||
|
|
||||||
query := e.Orm.Model(&data).
|
if role.RoleKey != "admin" {
|
||||||
|
groups := ""
|
||||||
|
e.Orm.Model(models.MmUserGroup{}).Where("user_id = ?", p.UserId).Pluck("group_ids", &groups)
|
||||||
|
ids := strings.Split(groups, ",")
|
||||||
|
groupIds := make([]string, 0)
|
||||||
|
for _, item := range ids {
|
||||||
|
if item != "" {
|
||||||
|
groupIds = append(groupIds, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(groupIds) > 0 {
|
||||||
|
query.Where("group_id in ?", groupIds)
|
||||||
|
} else {
|
||||||
|
query.Where("1=0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query.
|
||||||
Order(" LENGTH(machine_id) asc, machine_id asc").
|
Order(" LENGTH(machine_id) asc, machine_id asc").
|
||||||
Scopes(
|
Scopes(
|
||||||
cDto.MakeCondition(c.GetNeedSearch()),
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
@ -130,8 +152,8 @@ func (e *MmMachine) Insert(c *dto.MmMachineInsertReq) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*24)
|
||||||
helper.DefaultRedis.SetStringExpire(key2, groupItems, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key2, groupItems, time.Hour*24)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -195,8 +217,8 @@ func (e *MmMachine) Update(c *dto.MmMachineUpdateReq, p *actions.DataPermission)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*24)
|
||||||
helper.DefaultRedis.SetStringExpire(key2, groupItems, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key2, groupItems, time.Hour*24)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -264,9 +286,9 @@ func (e *MmMachine) UpdateBatch(req *dto.MmMachineUpdateBatchReq, p *actions.Dat
|
|||||||
for _, item := range machineIds {
|
for _, item := range machineIds {
|
||||||
key := fmt.Sprintf(enums.MachineContentKey, item)
|
key := fmt.Sprintf(enums.MachineContentKey, item)
|
||||||
if content != "" {
|
if content != "" {
|
||||||
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*24)
|
||||||
} else {
|
} else {
|
||||||
helper.DefaultRedis.SetStringExpire(key, req.Content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, req.Content, time.Hour*24)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case req.Type == 1:
|
case req.Type == 1:
|
||||||
@ -281,9 +303,9 @@ func (e *MmMachine) UpdateBatch(req *dto.MmMachineUpdateBatchReq, p *actions.Dat
|
|||||||
key := fmt.Sprintf(enums.MachineContentKey, item)
|
key := fmt.Sprintf(enums.MachineContentKey, item)
|
||||||
|
|
||||||
if content != "" {
|
if content != "" {
|
||||||
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, content, time.Hour*24)
|
||||||
} else {
|
} else {
|
||||||
helper.DefaultRedis.SetStringExpire(key, req.Content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, req.Content, time.Hour*24)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,6 +446,13 @@ func (e *MmMachine) GetHeartResp(machineId string, cache bool) dto.MmMachineHear
|
|||||||
result.KeywordLimit = 2
|
result.KeywordLimit = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reboot, _ := helper.DefaultRedis.GetString(fmt.Sprintf(enums.RebootMachine, machineId))
|
||||||
|
|
||||||
|
if reboot == "1" {
|
||||||
|
result.Reboot = true
|
||||||
|
helper.DefaultRedis.DeleteString(fmt.Sprintf(enums.RebootMachine, machineId))
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,11 +607,32 @@ func (e *MmMachine) ChangeStatus() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取设备列表
|
// 获取设备列表
|
||||||
func (e *MmMachine) GetMachineList() ([]dto.Option, error) {
|
func (e *MmMachine) GetMachineList(p *actions.DataPermission) ([]dto.Option, error) {
|
||||||
var machines []models.MmMachine
|
var machines []models.MmMachine
|
||||||
result := make([]dto.Option, 0)
|
result := make([]dto.Option, 0)
|
||||||
|
var role models.SysRole
|
||||||
|
query := e.Orm.Model(&models.MmMachine{})
|
||||||
|
e.Orm.Model(role).Where("role_id =?", p.RoleId).Find(&role)
|
||||||
|
|
||||||
if err := e.Orm.Model(models.MmMachine{}).Order("LENGTH(machine_id) asc, machine_id asc").Find(&machines).Error; err != nil {
|
if role.RoleKey != "admin" {
|
||||||
|
groups := ""
|
||||||
|
e.Orm.Model(models.MmUserGroup{}).Where("user_id = ?", p.UserId).Pluck("group_ids", &groups)
|
||||||
|
ids := strings.Split(groups, ",")
|
||||||
|
groupIds := make([]string, 0)
|
||||||
|
for _, item := range ids {
|
||||||
|
if item != "" {
|
||||||
|
groupIds = append(groupIds, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(groupIds) > 0 {
|
||||||
|
query.Where("group_id in ?", groupIds)
|
||||||
|
} else {
|
||||||
|
query.Where("1=0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Order("LENGTH(machine_id) asc, machine_id asc").Find(&machines).Error; err != nil {
|
||||||
e.Log.Errorf("Service GetMachineList error:%s \r\n", err)
|
e.Log.Errorf("Service GetMachineList error:%s \r\n", err)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@ -638,17 +688,16 @@ func (e *MmMachine) UpdateDescriptionBatch(req *dto.MmMachineUpdateDescriptionBa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 查询设备间隔账号
|
// 查询设备间隔账号
|
||||||
func (e *MmMachine) QueryIntervalAccount() (string, error) {
|
func (e *MmMachine) QueryIntervalAccount(c *gin.Context) error {
|
||||||
machineIds := make([]string, 0)
|
machineIds := make([]string, 0)
|
||||||
result := ""
|
|
||||||
lastMachineId := 0
|
lastMachineId := 0
|
||||||
errMachineIds := make([]string, 0)
|
errMachineIds := make([]dto.MmMachineExportResp, 0)
|
||||||
|
|
||||||
if err := e.Orm.Model(models.MmMachine{}).
|
if err := e.Orm.Model(models.MmMachine{}).
|
||||||
Order(" LENGTH(machine_id) asc, machine_id asc").
|
Order(" LENGTH(machine_id) asc, machine_id asc").
|
||||||
Pluck("machine_id", &machineIds).Error; err != nil {
|
Pluck("machine_id", &machineIds).Error; err != nil {
|
||||||
e.Log.Errorf("Service QueryIntervalAccount error:%s \r\n", err)
|
e.Log.Errorf("Service QueryIntervalAccount error:%s \r\n", err)
|
||||||
return result, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, machineId := range machineIds {
|
for _, machineId := range machineIds {
|
||||||
@ -658,23 +707,43 @@ func (e *MmMachine) QueryIntervalAccount() (string, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if lastMachineId == 0 {
|
for i := lastMachineId + 1; i < newId; i++ {
|
||||||
lastMachineId = newId
|
errMachineIds = append(errMachineIds, dto.MmMachineExportResp{
|
||||||
continue
|
MachineId: strconv.Itoa(i),
|
||||||
}
|
})
|
||||||
|
|
||||||
//间隔超过1就不正常
|
|
||||||
if newId-lastMachineId > 1 {
|
|
||||||
errMachineIds = append(errMachineIds, fmt.Sprintf("%v-%v", lastMachineId, newId))
|
|
||||||
}
|
}
|
||||||
lastMachineId = newId
|
lastMachineId = newId
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errMachineIds) > 0 {
|
helper.ExportExcel(c, "导出设备号", errMachineIds, []string{})
|
||||||
result = fmt.Sprintf("设备编号%s中有设备编号未记录,请检查", strings.Join(errMachineIds, ","))
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重启机器
|
||||||
|
func (e *MmMachine) RebootMachine(req *dto.MmMachineRebootReq) error {
|
||||||
|
//重启所有设备
|
||||||
|
if len(req.MachineIds) == 0 {
|
||||||
|
var machineIds []string
|
||||||
|
if err := e.Orm.Model(models.MmMachine{}).Pluck("machine_id", &machineIds).Error; err != nil {
|
||||||
|
e.Log.Errorf("Service RebootMachine error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, machineId := range machineIds {
|
||||||
|
key := fmt.Sprintf(enums.RebootMachine, machineId)
|
||||||
|
if err := helper.DefaultRedis.SetStringExpire(key, "1", time.Hour*24); err != nil {
|
||||||
|
e.Log.Errorf("Service RebootMachine error:%s \r\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result = "设备编号正常"
|
for _, machineId := range req.MachineIds {
|
||||||
|
key := fmt.Sprintf(enums.RebootMachine, machineId)
|
||||||
|
if err := helper.DefaultRedis.SetStringExpire(key, "1", time.Hour*24); err != nil {
|
||||||
|
e.Log.Errorf("Service RebootMachine error:%s \r\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/service"
|
"github.com/go-admin-team/go-admin-core/sdk/service"
|
||||||
@ -18,22 +19,51 @@ type MmMachineLog struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPage 获取MmMachineLog列表
|
// GetPage 获取MmMachineLog列表
|
||||||
func (e *MmMachineLog) GetPage(c *dto.MmMachineLogGetPageReq, p *actions.DataPermission, list *[]models.MmMachineLog, count *int64) error {
|
func (e *MmMachineLog) GetPage(c *dto.MmMachineLogGetPageReq, p *actions.DataPermission, list *[]dto.MmMachinePageResp, count *int64) error {
|
||||||
var err error
|
var err error
|
||||||
var data models.MmMachineLog
|
var data models.MmMachineLog
|
||||||
|
var role models.SysRole
|
||||||
|
query := e.Orm.Model(&data).
|
||||||
|
Joins("left join mm_machine on mm_machine.machine_id = mm_machine_log.machine_id and mm_machine.deleted_at is null")
|
||||||
|
e.Orm.Model(role).Where("role_id =?", p.RoleId).Find(&role)
|
||||||
|
|
||||||
err = e.Orm.Model(&data).
|
if c.GroupId > 0 {
|
||||||
|
query.Where("mm_machine.group_id = ?", c.GroupId)
|
||||||
|
} else if c.GroupId == -1 {
|
||||||
|
query.Where("mm_machine.group_id = 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
if role.RoleKey != "admin" {
|
||||||
|
groups := ""
|
||||||
|
e.Orm.Model(models.MmUserGroup{}).Where("user_id = ?", p.UserId).Pluck("group_ids", &groups)
|
||||||
|
ids := strings.Split(groups, ",")
|
||||||
|
groupIds := make([]string, 0)
|
||||||
|
for _, item := range ids {
|
||||||
|
if item != "" {
|
||||||
|
groupIds = append(groupIds, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(groupIds) > 0 {
|
||||||
|
query.Where("mm_machine.group_id in ?", groupIds)
|
||||||
|
} else {
|
||||||
|
query.Where("1=0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = query.
|
||||||
Scopes(
|
Scopes(
|
||||||
cDto.MakeCondition(c.GetNeedSearch()),
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
actions.Permission(data.TableName(), p),
|
|
||||||
).
|
).
|
||||||
|
Select("mm_machine_log.*,mm_machine.group_id").
|
||||||
Find(list).Limit(-1).Offset(-1).
|
Find(list).Limit(-1).Offset(-1).
|
||||||
Count(count).Error
|
Count(count).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Log.Errorf("MmMachineLogService GetPage error:%s \r\n", err)
|
e.Log.Errorf("MmMachineLogService GetPage error:%s \r\n", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/go-admin-team/go-admin-core/logger"
|
"github.com/go-admin-team/go-admin-core/logger"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/service"
|
"github.com/go-admin-team/go-admin-core/sdk/service"
|
||||||
@ -18,16 +19,44 @@ type MmRiskLog struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPage 获取MmRiskLog列表
|
// GetPage 获取MmRiskLog列表
|
||||||
func (e *MmRiskLog) GetPage(c *dto.MmRiskLogGetPageReq, p *actions.DataPermission, list *[]models.MmRiskLog, count *int64) error {
|
func (e *MmRiskLog) GetPage(c *dto.MmRiskLogGetPageReq, p *actions.DataPermission, list *[]dto.MmRiskLogPageResp, count *int64) error {
|
||||||
var err error
|
var err error
|
||||||
var data models.MmRiskLog
|
var data models.MmRiskLog
|
||||||
|
var role models.SysRole
|
||||||
|
query := e.Orm.Model(&data).
|
||||||
|
Joins("left join mm_machine on mm_machine.machine_id = mm_risk_log.machine_id and mm_machine.deleted_at is null")
|
||||||
|
e.Orm.Model(role).Where("role_id =?", p.RoleId).Find(&role)
|
||||||
|
|
||||||
err = e.Orm.Model(&data).
|
if c.GroupId == -1 {
|
||||||
|
query.Where("mm_machine.group_id = 0")
|
||||||
|
} else if c.GroupId > 0 {
|
||||||
|
query.Where("mm_machine.group_id = ?", c.GroupId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if role.RoleKey != "admin" {
|
||||||
|
groups := ""
|
||||||
|
e.Orm.Model(models.MmUserGroup{}).Where("user_id = ?", p.UserId).Pluck("group_ids", &groups)
|
||||||
|
ids := strings.Split(groups, ",")
|
||||||
|
groupIds := make([]string, 0)
|
||||||
|
for _, item := range ids {
|
||||||
|
if item != "" {
|
||||||
|
groupIds = append(groupIds, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(groupIds) > 0 {
|
||||||
|
query.Where("mm_machine.group_id in ?", groupIds)
|
||||||
|
} else {
|
||||||
|
query.Where("1=0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = query.
|
||||||
Scopes(
|
Scopes(
|
||||||
cDto.MakeCondition(c.GetNeedSearch()),
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
actions.Permission(data.TableName(), p),
|
|
||||||
).
|
).
|
||||||
|
Select("mm_risk_log.*,mm_machine.group_id").
|
||||||
Find(list).Limit(-1).Offset(-1).
|
Find(list).Limit(-1).Offset(-1).
|
||||||
Count(count).Error
|
Count(count).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
198
app/admin/service/mm_user_group.go
Normal file
198
app/admin/service/mm_user_group.go
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-admin-team/go-admin-core/sdk/service"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/actions"
|
||||||
|
cDto "go-admin/common/dto"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MmUserGroup struct {
|
||||||
|
service.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPage 获取MmUserGroup列表
|
||||||
|
func (e *MmUserGroup) GetPage(c *dto.MmUserGroupGetPageReq, p *actions.DataPermission, list *[]models.MmUserGroup, count *int64) error {
|
||||||
|
var err error
|
||||||
|
var data models.MmUserGroup
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).
|
||||||
|
Find(list).Limit(-1).Offset(-1).
|
||||||
|
Count(count).Error
|
||||||
|
if err != nil {
|
||||||
|
e.Log.Errorf("MmUserGroupService GetPage error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
userIds := make([]int, 0)
|
||||||
|
userName := make(map[int]string)
|
||||||
|
groupIds := make([]int, 0)
|
||||||
|
groupNames := make(map[int]string)
|
||||||
|
|
||||||
|
for index := range *list {
|
||||||
|
userIds = append(userIds, (*list)[index].UserId)
|
||||||
|
if (*list)[index].GroupIds != "" {
|
||||||
|
groups := strings.Split((*list)[index].GroupIds, ",")
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
groupId, err := strconv.Atoi(group)
|
||||||
|
if err == nil && groupId > 0 {
|
||||||
|
groupIds = append(groupIds, groupId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(userIds) > 0 {
|
||||||
|
users := make([]models.SysUser, 0)
|
||||||
|
err = e.Orm.Model(models.SysUser{}).Select("user_id,nick_name").Where("user_id in (?)", userIds).Find(&users).Error
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, item := range users {
|
||||||
|
userName[item.UserId] = item.NickName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(groupIds) > 0 {
|
||||||
|
groups := make([]models.MmGroup, 0)
|
||||||
|
err = e.Orm.Model(models.MmGroup{}).Select("id,group_name").Where("id in (?)", groupIds).Find(&groups).Error
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, item := range groups {
|
||||||
|
groupNames[item.Id] = item.GroupName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for index := range *list {
|
||||||
|
if len(userName) > 0 {
|
||||||
|
(*list)[index].UserName = userName[(*list)[index].UserId]
|
||||||
|
}
|
||||||
|
if len(groupNames) > 0 {
|
||||||
|
groupIds := strings.Split((*list)[index].GroupIds, ",")
|
||||||
|
groupNamesStr := make([]string, 0)
|
||||||
|
for _, groupId := range groupIds {
|
||||||
|
groupId, _ := strconv.Atoi(groupId)
|
||||||
|
if groupId > 0 {
|
||||||
|
groupNamesStr = append(groupNamesStr, groupNames[groupId])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*list)[index].GroupNames = strings.Join(groupNamesStr, ",")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 获取MmUserGroup对象
|
||||||
|
func (e *MmUserGroup) Get(d *dto.MmUserGroupGetReq, p *actions.DataPermission, model *models.MmUserGroup) error {
|
||||||
|
var data models.MmUserGroup
|
||||||
|
|
||||||
|
err := e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).
|
||||||
|
First(model, d.GetId()).Error
|
||||||
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
err = errors.New("查看对象不存在或无权查看")
|
||||||
|
e.Log.Errorf("Service GetMmUserGroup error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
e.Log.Errorf("db error:%s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if model.GroupIds != "" {
|
||||||
|
groups := strings.Split(model.GroupIds, ",")
|
||||||
|
groupIdList := make([]int, 0)
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
groupId, err := strconv.Atoi(group)
|
||||||
|
if err == nil {
|
||||||
|
groupIdList = append(groupIdList, groupId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
model.GroupIdList = groupIdList
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert 创建MmUserGroup对象
|
||||||
|
func (e *MmUserGroup) Insert(c *dto.MmUserGroupInsertReq) error {
|
||||||
|
var err error
|
||||||
|
var data models.MmUserGroup
|
||||||
|
var count int64
|
||||||
|
c.Generate(&data)
|
||||||
|
|
||||||
|
e.Orm.Model(&data).Where("user_id =?", c.UserId).Count(&count)
|
||||||
|
|
||||||
|
if count > 0 {
|
||||||
|
return errors.New("该用户已存在")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = e.Orm.Create(&data).Error
|
||||||
|
if err != nil {
|
||||||
|
e.Log.Errorf("MmUserGroupService Insert error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update 修改MmUserGroup对象
|
||||||
|
func (e *MmUserGroup) Update(c *dto.MmUserGroupUpdateReq, p *actions.DataPermission) error {
|
||||||
|
var err error
|
||||||
|
var data = models.MmUserGroup{}
|
||||||
|
var count int64
|
||||||
|
e.Orm.Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).First(&data, c.GetId())
|
||||||
|
c.Generate(&data)
|
||||||
|
|
||||||
|
e.Orm.Model(&data).Where("user_id =? and id <>?", c.UserId, c.Id).Count(&count)
|
||||||
|
|
||||||
|
if count > 0 {
|
||||||
|
return errors.New("该用户已存在")
|
||||||
|
}
|
||||||
|
|
||||||
|
db := e.Orm.Save(&data)
|
||||||
|
if err = db.Error; err != nil {
|
||||||
|
e.Log.Errorf("MmUserGroupService Save error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权更新该数据")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove 删除MmUserGroup
|
||||||
|
func (e *MmUserGroup) Remove(d *dto.MmUserGroupDeleteReq, p *actions.DataPermission) error {
|
||||||
|
var data models.MmUserGroup
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
actions.Permission(data.TableName(), p),
|
||||||
|
).Delete(&data, d.GetId())
|
||||||
|
if err := db.Error; err != nil {
|
||||||
|
e.Log.Errorf("Service RemoveMmUserGroup error:%s \r\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权删除该数据")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -101,14 +101,14 @@ func (e *MmWhiteTemplate) Update(c *dto.MmWhiteTemplateUpdateReq, p *actions.Dat
|
|||||||
|
|
||||||
for _, machineId := range machineIds {
|
for _, machineId := range machineIds {
|
||||||
key := fmt.Sprintf(enums.MachineContentKey, machineId)
|
key := fmt.Sprintf(enums.MachineContentKey, machineId)
|
||||||
helper.DefaultRedis.SetStringExpire(key, c.Content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, c.Content, time.Hour*24)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
e.Orm.Model(models.MmMachine{}).Where(" group_items='' and bios_id!=''").Select("machine_id").Find(&machineIds)
|
e.Orm.Model(models.MmMachine{}).Where(" group_items='' and bios_id!=''").Select("machine_id").Find(&machineIds)
|
||||||
|
|
||||||
for _, machineId := range machineIds {
|
for _, machineId := range machineIds {
|
||||||
key := fmt.Sprintf(enums.MachineGroupKey, machineId)
|
key := fmt.Sprintf(enums.MachineGroupKey, machineId)
|
||||||
helper.DefaultRedis.SetStringExpire(key, c.Content, time.Hour*3)
|
helper.DefaultRedis.SetStringExpire(key, c.Content, time.Hour*24)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -264,3 +264,21 @@ func (e *SysUser) GetProfile(c *dto.SysUserById, user *models.SysUser, roles *[]
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户列表
|
||||||
|
func (e *SysUser) GetList(datas *[]dto.SysUserOptions) error {
|
||||||
|
var list []models.SysUser
|
||||||
|
|
||||||
|
if err := e.Orm.Model(&models.SysUser{}).Where("username <> 'admin'").Find(&list).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range list {
|
||||||
|
*datas = append(*datas, dto.SysUserOptions{
|
||||||
|
UserId: item.UserId,
|
||||||
|
NickName: item.NickName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ func InitJob() {
|
|||||||
jobList = map[string]JobExec{
|
jobList = map[string]JobExec{
|
||||||
"ExamplesOne": ExamplesOne{},
|
"ExamplesOne": ExamplesOne{},
|
||||||
"LockControl": LockJob{},
|
"LockControl": LockJob{},
|
||||||
|
"ClearLogJob": ClearLogJob{},
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,11 @@ const (
|
|||||||
MachineKeywords = "m_keywords:%s"
|
MachineKeywords = "m_keywords:%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
//设备重启缓存 {machineId}
|
||||||
|
RebootMachine = "reboot_machine:%s"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
//系统配置缓存
|
//系统配置缓存
|
||||||
Config = "config:%s"
|
Config = "config:%s"
|
||||||
|
|||||||
168
common/helper/excel_helper.go
Normal file
168
common/helper/excel_helper.go
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/xuri/excelize/v2"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
导出csv文件
|
||||||
|
|
||||||
|
- @fileName 文件名 不带拓展名
|
||||||
|
- @header 文件头
|
||||||
|
- @records 内容
|
||||||
|
*/
|
||||||
|
func ExportCSV(c *gin.Context, fileName string, header []string, records [][]string) error {
|
||||||
|
disposition := fmt.Sprintf("attachment; filename=%s.csv", fileName)
|
||||||
|
|
||||||
|
// Set headers
|
||||||
|
c.Header("Content-Description", "File Transfer")
|
||||||
|
c.Header("Content-Disposition", disposition)
|
||||||
|
c.Header("Content-Type", "text/csv")
|
||||||
|
|
||||||
|
// Create a CSV writer using the response writer
|
||||||
|
writer := csv.NewWriter(c.Writer)
|
||||||
|
defer writer.Flush()
|
||||||
|
|
||||||
|
// Write CSV header
|
||||||
|
writer.Write(header)
|
||||||
|
|
||||||
|
for _, record := range records {
|
||||||
|
writer.Write(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
导出excel
|
||||||
|
|
||||||
|
- @fileName 文件名称
|
||||||
|
- @data 数据源
|
||||||
|
- @ingore 忽略header
|
||||||
|
*/
|
||||||
|
func ExportExcel[T any](c *gin.Context, fileName string, data []T, ingore []string) error {
|
||||||
|
if len(data) == 0 {
|
||||||
|
return errors.New("无导出记录")
|
||||||
|
}
|
||||||
|
// Create a new Excel file
|
||||||
|
f := excelize.NewFile()
|
||||||
|
// Use reflection to get the header from struct tags
|
||||||
|
t := reflect.TypeOf(data[0])
|
||||||
|
headers := []string{}
|
||||||
|
for i := 0; i < t.NumField(); i++ {
|
||||||
|
field := t.Field(i)
|
||||||
|
excelTag := field.Tag.Get("excel")
|
||||||
|
if excelTag != "" && !ArrayAny(ingore, excelTag) {
|
||||||
|
headers = append(headers, excelTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Set headers
|
||||||
|
for i, header := range headers {
|
||||||
|
col := string('A' + i)
|
||||||
|
cell := fmt.Sprintf("%s1", col)
|
||||||
|
f.SetCellValue("Sheet1", cell, header)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill rows with data
|
||||||
|
for rowIndex, item := range data {
|
||||||
|
rowValue := reflect.ValueOf(item)
|
||||||
|
rowType := rowValue.Type()
|
||||||
|
for colIndex, header := range headers {
|
||||||
|
col := string('A' + colIndex)
|
||||||
|
cell := fmt.Sprintf("%s%d", col, rowIndex+2)
|
||||||
|
var fieldValue reflect.Value
|
||||||
|
|
||||||
|
for i := 0; i < rowType.NumField(); i++ {
|
||||||
|
field := rowType.Field(i)
|
||||||
|
if strings.EqualFold(field.Tag.Get("excel"), header) {
|
||||||
|
fieldValue = rowValue.Field(i)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the fieldValue is valid before accessing it
|
||||||
|
if fieldValue.IsValid() && fieldValue.CanInterface() {
|
||||||
|
//f.SetCellValue("Sheet1", cell, fieldValue.Interface())
|
||||||
|
value := fieldValue.Interface()
|
||||||
|
|
||||||
|
// Ensure the value is a string, convert it if necessary
|
||||||
|
var stringValue string
|
||||||
|
if v, ok := value.(string); ok {
|
||||||
|
stringValue = v // If it's a string, use it directly
|
||||||
|
} else {
|
||||||
|
stringValue = fmt.Sprintf("%v", value) // Otherwise, convert to string
|
||||||
|
}
|
||||||
|
f.SetCellValue("Sheet1", cell, stringValue)
|
||||||
|
} else {
|
||||||
|
// Handle the case where fieldValue is invalid or nil
|
||||||
|
f.SetCellValue("Sheet1", cell, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Set response headers and send the file to the client
|
||||||
|
|
||||||
|
// c.Writer.Header().Set("Content-Disposition", "attachment; filename=test.xlsx")
|
||||||
|
// c.Writer.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=binary")
|
||||||
|
// c.Writer.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
|
// c.Writer.Header().Set("Expires", "0")
|
||||||
|
// c.Writer.Header().Set("Cache-Control", "must-revalidate")
|
||||||
|
// c.Writer.Header().Set("Pragma", "public")
|
||||||
|
c.Header("Content-Description", "File Transfer")
|
||||||
|
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s.xlsx", fileName))
|
||||||
|
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||||
|
c.Header("Content-Transfer-Encoding", "binary")
|
||||||
|
c.Header("Expires", "0")
|
||||||
|
c.Header("Cache-Control", "must-revalidate")
|
||||||
|
c.Header("Pragma", "public")
|
||||||
|
c.Header("Content-Encoding", "")
|
||||||
|
//fmt.Println("c.Writer.Header():", c.Writer.Header())
|
||||||
|
if _, err := f.WriteTo(c.Writer); err != nil {
|
||||||
|
log.Println("Error writing file:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
//return f.WriteTo(c.Writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MapExcelToStruct[T any](rows [][]string, headers []string) ([]T, error) {
|
||||||
|
var results []T
|
||||||
|
if len(rows) == 0 {
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, row := range rows {
|
||||||
|
var result T
|
||||||
|
v := reflect.ValueOf(&result).Elem()
|
||||||
|
|
||||||
|
for i, header := range headers {
|
||||||
|
fieldName := ""
|
||||||
|
for j := 0; j < v.NumField(); j++ {
|
||||||
|
field := v.Type().Field(j)
|
||||||
|
tag := field.Tag.Get("excel")
|
||||||
|
if strings.EqualFold(tag, header) {
|
||||||
|
fieldName = field.Name
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if fieldName != "" && i < len(row) {
|
||||||
|
field := v.FieldByName(fieldName)
|
||||||
|
if field.IsValid() && field.CanSet() {
|
||||||
|
field.Set(reflect.ValueOf(row[i]).Convert(field.Type()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results = append(results, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
52
common/helper/extension_helper.go
Normal file
52
common/helper/extension_helper.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
/*
|
||||||
|
判断是否存在
|
||||||
|
|
||||||
|
- @arr 数组
|
||||||
|
- @value 值
|
||||||
|
*/
|
||||||
|
func ArrayAny[T comparable](arr []T, value T) bool {
|
||||||
|
for _, v := range arr {
|
||||||
|
if v == value {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义一个条件函数类型
|
||||||
|
type ConditionFunc[T any] func(T) bool
|
||||||
|
|
||||||
|
/*
|
||||||
|
判断是否存在
|
||||||
|
|
||||||
|
- @arr 数组
|
||||||
|
|
||||||
|
- @condition 判断函数
|
||||||
|
|
||||||
|
@return 对象指针
|
||||||
|
*/
|
||||||
|
func ArrayAnyExtension[T any](arr *[]T, condition ConditionFunc[T]) *T {
|
||||||
|
for _, v := range *arr {
|
||||||
|
if condition(v) {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveDuplicates(nums []int64) []int64 {
|
||||||
|
m := make(map[int64]bool)
|
||||||
|
result := []int64{}
|
||||||
|
|
||||||
|
for _, num := range nums {
|
||||||
|
if !m[num] {
|
||||||
|
m[num] = true
|
||||||
|
result = append(result, num)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
@ -12,6 +12,7 @@ var ExtConfig Extend
|
|||||||
type Extend struct {
|
type Extend struct {
|
||||||
AMap AMap // 这里配置对应配置文件的结构即可
|
AMap AMap // 这里配置对应配置文件的结构即可
|
||||||
Redis RedisConfig `mapstructure:"redis"`
|
Redis RedisConfig `mapstructure:"redis"`
|
||||||
|
FileEndPoint string `mapstructure:"fileEndPoint"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AMap struct {
|
type AMap struct {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ settings:
|
|||||||
readtimeout: 1
|
readtimeout: 1
|
||||||
writertimeout: 2
|
writertimeout: 2
|
||||||
# 数据权限功能开关
|
# 数据权限功能开关
|
||||||
enabledp: false
|
enabledp: true
|
||||||
logger:
|
logger:
|
||||||
# 日志存放路径
|
# 日志存放路径
|
||||||
path: temp/logs
|
path: temp/logs
|
||||||
@ -53,6 +53,7 @@ settings:
|
|||||||
addr: "127.0.0.1:6379"
|
addr: "127.0.0.1:6379"
|
||||||
password: ""
|
password: ""
|
||||||
db: 3
|
db: 3
|
||||||
|
fileEndPoint: http://192.168.2.102:8000
|
||||||
cache:
|
cache:
|
||||||
# redis:
|
# redis:
|
||||||
# addr: 127.0.0.1:6379
|
# addr: 127.0.0.1:6379
|
||||||
|
|||||||
6
go.mod
6
go.mod
@ -102,6 +102,7 @@ require (
|
|||||||
github.com/microsoft/go-mssqldb v1.8.0 // indirect
|
github.com/microsoft/go-mssqldb v1.8.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||||
github.com/mojocn/base64Captcha v1.3.8 // indirect
|
github.com/mojocn/base64Captcha v1.3.8 // indirect
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||||
@ -112,6 +113,8 @@ require (
|
|||||||
github.com/prometheus/common v0.62.0 // indirect
|
github.com/prometheus/common v0.62.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
|
github.com/richardlehane/mscfb v1.0.4 // indirect
|
||||||
|
github.com/richardlehane/msoleps v1.0.4 // indirect
|
||||||
github.com/shamsher31/goimgext v1.0.0 // indirect
|
github.com/shamsher31/goimgext v1.0.0 // indirect
|
||||||
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
||||||
github.com/spf13/cast v1.7.1 // indirect
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
@ -120,6 +123,9 @@ require (
|
|||||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
|
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d // indirect
|
||||||
|
github.com/xuri/excelize/v2 v2.9.0 // indirect
|
||||||
|
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
go.uber.org/zap v1.27.0 // indirect
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
|
|||||||
Reference in New Issue
Block a user