mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
大屏
This commit is contained in:
@@ -75,3 +75,10 @@ func (p *RuleChainApi) DeleteVisualRuleChain(rc *restfulx.ReqCtx) {
|
||||
ids := strings.Split(id, ",")
|
||||
p.VisualRuleChainApp.Delete(ids)
|
||||
}
|
||||
|
||||
// UpdateRuleStatus 修改状态
|
||||
func (p *RuleChainApi) UpdateRuleStatus(rc *restfulx.ReqCtx) {
|
||||
var rule entity.VisualRuleChain
|
||||
restfulx.BindQuery(rc, &rule)
|
||||
p.VisualRuleChainApp.Update(rule)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package api
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/model"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/kakuilan/kgo"
|
||||
"strings"
|
||||
|
||||
"pandax/apps/visual/entity"
|
||||
@@ -26,6 +27,8 @@ func (p *VisualScreenApi) GetVisualScreenList(rc *restfulx.ReqCtx) {
|
||||
data.ScreenName = restfulx.QueryParam(rc, "screenName")
|
||||
data.Status = restfulx.QueryParam(rc, "status")
|
||||
|
||||
data.GroupId = int64(restfulx.QueryInt(rc, "groupId", 0))
|
||||
|
||||
list, total := p.VisualScreenApp.FindListPage(pageNum, pageSize, data)
|
||||
|
||||
rc.ResData = model.ResultPage{
|
||||
@@ -46,7 +49,9 @@ func (p *VisualScreenApi) GetVisualScreen(rc *restfulx.ReqCtx) {
|
||||
func (p *VisualScreenApi) InsertVisualScreen(rc *restfulx.ReqCtx) {
|
||||
var data entity.VisualScreen
|
||||
restfulx.BindQuery(rc, &data)
|
||||
|
||||
data.UserId = rc.LoginAccount.UserId
|
||||
data.ScreenId = kgo.KStr.Uniqid("px")
|
||||
data.Creator = rc.LoginAccount.UserName
|
||||
p.VisualScreenApp.Insert(data)
|
||||
}
|
||||
|
||||
@@ -64,3 +69,10 @@ func (p *VisualScreenApi) DeleteVisualScreen(rc *restfulx.ReqCtx) {
|
||||
screenIds := strings.Split(screenId, ",")
|
||||
p.VisualScreenApp.Delete(screenIds)
|
||||
}
|
||||
|
||||
// UpdateScreenStatus 修改状态
|
||||
func (p *VisualScreenApi) UpdateScreenStatus(rc *restfulx.ReqCtx) {
|
||||
var screen entity.VisualScreen
|
||||
restfulx.BindQuery(rc, &screen)
|
||||
p.VisualScreenApp.Update(screen)
|
||||
}
|
||||
|
||||
@@ -6,10 +6,8 @@ package api
|
||||
// 生成人:panda
|
||||
// ==========================================================================
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/model"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"strings"
|
||||
|
||||
"github.com/XM-GO/PandaKit/utils"
|
||||
"pandax/apps/visual/entity"
|
||||
"pandax/apps/visual/services"
|
||||
)
|
||||
@@ -18,30 +16,41 @@ type VisualScreenGroupApi struct {
|
||||
VisualScreenGroupApp services.VisualScreenGroupModel
|
||||
}
|
||||
|
||||
// GetVisualScreenGroupList DataSetGroup列表数据
|
||||
func (p *VisualScreenGroupApi) GetVisualScreenGroupList(rc *restfulx.ReqCtx) {
|
||||
data := entity.VisualScreenGroup{}
|
||||
pageNum := restfulx.QueryInt(rc, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc, "pageSize", 10)
|
||||
data.Name = restfulx.QueryParam(rc, "name")
|
||||
// GetScreenGroupTree ScreenGroup 树
|
||||
func (p *VisualScreenGroupApi) GetScreenGroupTree(rc *restfulx.ReqCtx) {
|
||||
name := restfulx.QueryParam(rc, "name")
|
||||
status := restfulx.QueryParam(rc, "status")
|
||||
id := restfulx.QueryInt(rc, "id", 0)
|
||||
sg := entity.VisualScreenGroup{Name: name, Status: status, Id: int64(id)}
|
||||
rc.ResData = p.VisualScreenGroupApp.SelectScreenGroup(sg)
|
||||
}
|
||||
|
||||
list, total := p.VisualScreenGroupApp.FindListPage(pageNum, pageSize, data)
|
||||
func (p *VisualScreenGroupApi) GetScreenGroupList(rc *restfulx.ReqCtx) {
|
||||
name := restfulx.QueryParam(rc, "name")
|
||||
status := restfulx.QueryParam(rc, "status")
|
||||
id := restfulx.QueryInt(rc, "id", 0)
|
||||
sg := entity.VisualScreenGroup{Name: name, Status: status, Id: int64(id)}
|
||||
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
PageSize: int64(pageNum),
|
||||
Data: list,
|
||||
if sg.Name == "" {
|
||||
rc.ResData = p.VisualScreenGroupApp.SelectScreenGroup(sg)
|
||||
} else {
|
||||
rc.ResData = p.VisualScreenGroupApp.FindList(sg)
|
||||
}
|
||||
}
|
||||
|
||||
// GetVisualScreenGroup 获取DataSetGroup
|
||||
func (p *VisualScreenGroupApi) GetVisualScreenGroup(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParam(rc, "id")
|
||||
rc.ResData = p.VisualScreenGroupApp.FindOne(id)
|
||||
// GetScreenGroupAllList 查询所有
|
||||
func (p *VisualScreenGroupApi) GetScreenGroupAllList(rc *restfulx.ReqCtx) {
|
||||
var vsg entity.VisualScreenGroup
|
||||
rc.ResData = p.VisualScreenGroupApp.FindList(vsg)
|
||||
}
|
||||
|
||||
// InsertVisualScreenGroup 添加DataSetGroup
|
||||
// GetVisualScreenGroup 获取ScreenGroup
|
||||
func (p *VisualScreenGroupApi) GetVisualScreenGroup(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParamInt(rc, "id")
|
||||
rc.ResData = p.VisualScreenGroupApp.FindOne(int64(id))
|
||||
}
|
||||
|
||||
// InsertVisualScreenGroup 添加ScreenGroup
|
||||
func (p *VisualScreenGroupApi) InsertVisualScreenGroup(rc *restfulx.ReqCtx) {
|
||||
var data entity.VisualScreenGroup
|
||||
restfulx.BindQuery(rc, &data)
|
||||
@@ -49,7 +58,7 @@ func (p *VisualScreenGroupApi) InsertVisualScreenGroup(rc *restfulx.ReqCtx) {
|
||||
p.VisualScreenGroupApp.Insert(data)
|
||||
}
|
||||
|
||||
// UpdateVisualScreenGroup 修改DataSetGroup
|
||||
// UpdateVisualScreenGroup 修改ScreenGroup
|
||||
func (p *VisualScreenGroupApi) UpdateVisualScreenGroup(rc *restfulx.ReqCtx) {
|
||||
var data entity.VisualScreenGroup
|
||||
restfulx.BindQuery(rc, &data)
|
||||
@@ -57,9 +66,9 @@ func (p *VisualScreenGroupApi) UpdateVisualScreenGroup(rc *restfulx.ReqCtx) {
|
||||
p.VisualScreenGroupApp.Update(data)
|
||||
}
|
||||
|
||||
// DeleteVisualScreenGroup 删除DataSetGroup
|
||||
// DeleteVisualScreenGroup 删除ScreenGroup
|
||||
func (p *VisualScreenGroupApi) DeleteVisualScreenGroup(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParam(rc, "id")
|
||||
ids := strings.Split(id, ",")
|
||||
ids := utils.IdsStrToIdsIntGroup(id)
|
||||
p.VisualScreenGroupApp.Delete(ids)
|
||||
}
|
||||
|
||||
@@ -3,10 +3,19 @@ package entity
|
||||
import "github.com/XM-GO/PandaKit/model"
|
||||
|
||||
type VisualScreenGroup struct {
|
||||
Id string `gorm:"id;primary_key;type:varchar(64);comment:Id" json:"id"`
|
||||
Name string `gorm:"name;type:varchar(64);comment:分组名称" json:"name"`
|
||||
Pid string `gorm:"pid;type:varchar(64);comment:父Id" json:"pid"`
|
||||
Level int64 `gorm:"level;type:int;comment:等级" json:"level"`
|
||||
Id int64 `gorm:"id;primary_key;type:varchar(64);comment:Id" json:"id"`
|
||||
Name string `gorm:"name;type:varchar(64);comment:分组名称" json:"name"`
|
||||
Pid int64 `gorm:"pid;type:varchar(64);comment:父Id" json:"pid"`
|
||||
Path string `gorm:"path;type:varchar(64);comment:路径" json:"path"`
|
||||
Sort int64 `gorm:"sort;type:int;comment:排序" json:"sort"`
|
||||
Status string `gorm:"status;type:varchar(1);comment:状态" json:"status"`
|
||||
Children []VisualScreenGroup `json:"children" gorm:"-"`
|
||||
}
|
||||
|
||||
type ScreenGroupLabel struct {
|
||||
Id int64 `gorm:"-" json:"id"`
|
||||
Name string `gorm:"-" json:"name"`
|
||||
Children []ScreenGroupLabel `gorm:"-" json:"children"`
|
||||
}
|
||||
|
||||
func (VisualScreenGroup) TableName() string {
|
||||
@@ -14,13 +23,14 @@ func (VisualScreenGroup) TableName() string {
|
||||
}
|
||||
|
||||
type VisualScreen struct {
|
||||
UserId string `gorm:"userId;type:varchar(64);comment:用户Id" json:"userId"`
|
||||
UserId int64 `gorm:"userId;type:int;comment:用户Id" json:"userId"`
|
||||
ScreenId string `gorm:"primary_key;" json:"screenId"`
|
||||
GroupId int64 `gorm:"screenGroup;type:int;comment:分组Id" json:"groupId"`
|
||||
ScreenName string `gorm:"screenName;type:varchar(50);comment:名称" json:"screenName"`
|
||||
ScreenDataJson string `gorm:"screenDataJson;type:varchar(50);comment:Json数据" json:"screenDataJson"`
|
||||
ScreenBase64 string `gorm:"screenBase64;type:varchar(50);comment:Base64缩略图" json:"screenBase64"` //缩略图 base64
|
||||
ScreenRemark string `gorm:"screenRemark;type:varchar(50);comment:说明" json:"screenRemark"`
|
||||
Status string `gorm:"status;type:varchar(50);comment:状态" json:"status"`
|
||||
Status string `gorm:"status;type:varchar(1);comment:状态" json:"status"`
|
||||
Creator string `json:"creator"` //创建者
|
||||
model.BaseModel
|
||||
}
|
||||
|
||||
@@ -77,6 +77,13 @@ func InitRuleChainRouter(container *restful.Container) {
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Param(ws.PathParameter("id", "多id 1,2,3").DataType("string")))
|
||||
|
||||
ws.Route(ws.PUT("/changeStatus").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("修改状态").Handle(s.UpdateRuleStatus)
|
||||
}).
|
||||
Doc("修改状态").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Reads(entity.VisualScreen{}))
|
||||
|
||||
container.Add(ws)
|
||||
|
||||
}
|
||||
|
||||
@@ -66,5 +66,12 @@ func InitVisualScreenRouter(container *restful.Container) {
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Param(ws.PathParameter("screenId", "多id 1,2,3").DataType("string")))
|
||||
|
||||
ws.Route(ws.PUT("/changeStatus").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("修改状态").Handle(s.UpdateScreenStatus)
|
||||
}).
|
||||
Doc("修改状态").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Reads(entity.VisualScreen{}))
|
||||
|
||||
container.Add(ws)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/model"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"pandax/apps/visual/api"
|
||||
"pandax/apps/visual/entity"
|
||||
@@ -26,14 +25,29 @@ func InitVisualScreenGroupRouter(container *restful.Container) {
|
||||
tags := []string{"datasetgroup"}
|
||||
|
||||
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取ScreenGroup分页列表").Handle(s.GetVisualScreenGroupList)
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取ScreenGroup列表").Handle(s.GetScreenGroupList)
|
||||
}).
|
||||
Doc("获取ScreenGroup列表").
|
||||
Param(ws.QueryParameter("name", "名称").Required(false).DataType("string")).
|
||||
Param(ws.QueryParameter("status", "状态").Required(false).DataType("string")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Returns(200, "OK", []entity.VisualScreenGroup{}))
|
||||
|
||||
ws.Route(ws.GET("/list/all").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取ScreenGroup所有列表").Handle(s.GetScreenGroupAllList)
|
||||
}).
|
||||
Doc("获取ScreenGroup分页列表").
|
||||
Param(ws.QueryParameter("pageNum", "页数").Required(true).DataType("int")).
|
||||
Param(ws.QueryParameter("pageSize", "每页条数").Required(true).DataType("int")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(model.ResultPage{}).
|
||||
Returns(200, "OK", model.ResultPage{}))
|
||||
Returns(200, "OK", []entity.VisualScreenGroup{}))
|
||||
|
||||
ws.Route(ws.GET("/list/tree").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取ScreenGroup树").Handle(s.GetScreenGroupTree)
|
||||
}).
|
||||
Doc("获取ScreenGroup树").
|
||||
Param(ws.QueryParameter("name", "名称").Required(false).DataType("string")).
|
||||
Param(ws.QueryParameter("status", "状态").Required(false).DataType("string")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Returns(200, "OK", []entity.ScreenGroupLabel{}))
|
||||
|
||||
ws.Route(ws.GET("/{id}").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取ScreenGroup信息").Handle(s.GetVisualScreenGroup)
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
// ==========================================================================
|
||||
// 生成日期:2023-04-10 02:51:27 +0000 UTC
|
||||
// 生成路径: apps/visual/services/visual_data_set_group.go
|
||||
// 生成人:panda
|
||||
// ==========================================================================
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"pandax/apps/visual/entity"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
VisualScreenGroupModel interface {
|
||||
Insert(data entity.VisualScreenGroup) *entity.VisualScreenGroup
|
||||
FindOne(id string) *entity.VisualScreenGroup
|
||||
FindListPage(page, pageSize int, data entity.VisualScreenGroup) (*[]entity.VisualScreenGroup, int64)
|
||||
FindList(data entity.VisualScreenGroup) *[]entity.VisualScreenGroup
|
||||
Update(data entity.VisualScreenGroup) *entity.VisualScreenGroup
|
||||
Delete(ids []string)
|
||||
}
|
||||
|
||||
screenGroupModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var VisualScreenGroupModelDao VisualScreenGroupModel = &screenGroupModelImpl{
|
||||
table: `visual_screen_group`,
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) Insert(data entity.VisualScreenGroup) *entity.VisualScreenGroup {
|
||||
err := global.Db.Table(m.table).Create(&data).Error
|
||||
biz.ErrIsNil(err, "添加数据集分组失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) FindOne(id string) *entity.VisualScreenGroup {
|
||||
resData := new(entity.VisualScreenGroup)
|
||||
db := global.Db.Table(m.table).Where("id = ?", id)
|
||||
err := db.First(resData).Error
|
||||
biz.ErrIsNil(err, "查询数据集分组失败")
|
||||
return resData
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) FindListPage(page, pageSize int, data entity.VisualScreenGroup) (*[]entity.VisualScreenGroup, int64) {
|
||||
list := make([]entity.VisualScreenGroup, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.Pid != "" {
|
||||
db = db.Where("pid = ?", data.Pid)
|
||||
}
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("create_time").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询数据集分组分页列表失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) FindList(data entity.VisualScreenGroup) *[]entity.VisualScreenGroup {
|
||||
list := make([]entity.VisualScreenGroup, 0)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.Pid != "" {
|
||||
db = db.Where("pid = ?", data.Pid)
|
||||
}
|
||||
biz.ErrIsNil(db.Order("create_time").Find(&list).Error, "查询数据集分组列表失败")
|
||||
return &list
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) Update(data entity.VisualScreenGroup) *entity.VisualScreenGroup {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Updates(&data).Error, "修改数据集分组失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) Delete(s []string) {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Delete(&entity.VisualScreenGroup{}, "id in (?)", s).Error, "删除数据集分组失败")
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (m *screenModelImpl) FindListPage(page, pageSize int, data entity.VisualScr
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.UserId != "" {
|
||||
if data.UserId != 0 {
|
||||
db = db.Where("user_id = ?", data.UserId)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
@@ -61,12 +61,16 @@ func (m *screenModelImpl) FindListPage(page, pageSize int, data entity.VisualScr
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
if data.GroupId != 0 {
|
||||
db = db.Where("group_id = ?", data.GroupId)
|
||||
}
|
||||
if data.ScreenRemark != "" {
|
||||
db = db.Where("screen_remark like ?", "%"+data.ScreenRemark+"%")
|
||||
}
|
||||
if data.Creator != "" {
|
||||
db = db.Where("creator = ?", data.Creator)
|
||||
}
|
||||
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("create_time").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询bi大屏分页列表失败")
|
||||
@@ -77,7 +81,7 @@ func (m *screenModelImpl) FindList(data entity.VisualScreen) *[]entity.VisualScr
|
||||
list := make([]entity.VisualScreen, 0)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.UserId != "" {
|
||||
if data.UserId != 0 {
|
||||
db = db.Where("user_id = ?", data.UserId)
|
||||
}
|
||||
db.Where("delete_time IS NULL")
|
||||
|
||||
196
apps/visual/services/visual_screen_group.go
Normal file
196
apps/visual/services/visual_screen_group.go
Normal file
@@ -0,0 +1,196 @@
|
||||
// ==========================================================================
|
||||
// 生成日期:2023-04-10 02:51:27 +0000 UTC
|
||||
// 生成路径: apps/visual/services/visual_data_set_group.go
|
||||
// 生成人:panda
|
||||
// ==========================================================================
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/XM-GO/PandaKit/biz"
|
||||
"github.com/kakuilan/kgo"
|
||||
"pandax/apps/visual/entity"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
VisualScreenGroupModel interface {
|
||||
Insert(data entity.VisualScreenGroup) *entity.VisualScreenGroup
|
||||
FindOne(id int64) *entity.VisualScreenGroup
|
||||
FindListPage(page, pageSize int, data entity.VisualScreenGroup) (*[]entity.VisualScreenGroup, int64)
|
||||
FindList(data entity.VisualScreenGroup) *[]entity.VisualScreenGroup
|
||||
Update(data entity.VisualScreenGroup) *entity.VisualScreenGroup
|
||||
Delete(ids []int64)
|
||||
SelectScreenGroup(data entity.VisualScreenGroup) []entity.VisualScreenGroup
|
||||
SelectScreenGroupLabel(data entity.VisualScreenGroup) []entity.ScreenGroupLabel
|
||||
}
|
||||
|
||||
screenGroupModelImpl struct {
|
||||
table string
|
||||
}
|
||||
)
|
||||
|
||||
var VisualScreenGroupModelDao VisualScreenGroupModel = &screenGroupModelImpl{
|
||||
table: `visual_screen_group`,
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) Insert(data entity.VisualScreenGroup) *entity.VisualScreenGroup {
|
||||
err := global.Db.Table(m.table).Create(&data).Error
|
||||
biz.ErrIsNil(err, "添加数据集分组失败")
|
||||
|
||||
path := "/" + kgo.KConv.Int2Str(data.Id)
|
||||
if int(data.Pid) != 0 {
|
||||
vsg := m.FindOne(data.Pid)
|
||||
path = vsg.Path + path
|
||||
} else {
|
||||
path = "/0" + path
|
||||
}
|
||||
data.Path = path
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Model(&data).Updates(&data).Error, "修改分组信息失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) FindOne(id int64) *entity.VisualScreenGroup {
|
||||
resData := new(entity.VisualScreenGroup)
|
||||
db := global.Db.Table(m.table).Where("id = ?", id)
|
||||
err := db.First(resData).Error
|
||||
biz.ErrIsNil(err, "查询数据集分组失败")
|
||||
return resData
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) FindListPage(page, pageSize int, data entity.VisualScreenGroup) (*[]entity.VisualScreenGroup, int64) {
|
||||
list := make([]entity.VisualScreenGroup, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.Path != "" {
|
||||
db = db.Where("path like %?%", "%"+data.Path+"%")
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("sort").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询数据集分组分页列表失败")
|
||||
return &list, total
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) FindList(data entity.VisualScreenGroup) *[]entity.VisualScreenGroup {
|
||||
list := make([]entity.VisualScreenGroup, 0)
|
||||
db := global.Db.Table(m.table)
|
||||
// 此处填写 where参数判断
|
||||
if data.Name != "" {
|
||||
db = db.Where("name like ?", "%"+data.Name+"%")
|
||||
}
|
||||
if data.Path != "" {
|
||||
db = db.Where("path like %?%", "%"+data.Path+"%")
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
biz.ErrIsNil(db.Order("sort").Find(&list).Error, "查询数据集分组列表失败")
|
||||
return &list
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) Update(data entity.VisualScreenGroup) *entity.VisualScreenGroup {
|
||||
one := m.FindOne(data.Id)
|
||||
|
||||
path := "/" + kgo.KConv.Int2Str(data.Id)
|
||||
if int(data.Pid) != 0 {
|
||||
vsg := m.FindOne(data.Pid)
|
||||
path = vsg.Path + path
|
||||
} else {
|
||||
path = "/0" + path
|
||||
}
|
||||
data.Path = path
|
||||
|
||||
if data.Path != "" && data.Path != one.Path {
|
||||
biz.ErrIsNil(errors.New("上级分组不允许修改!"), "上级分组不允许修改")
|
||||
}
|
||||
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Updates(&data).Error, "修改数据集分组失败")
|
||||
return &data
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) Delete(s []int64) {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Delete(&entity.VisualScreenGroup{}, "id in (?)", s).Error, "删除数据集分组失败")
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) SelectScreenGroup(data entity.VisualScreenGroup) []entity.VisualScreenGroup {
|
||||
list := m.FindList(data)
|
||||
sd := make([]entity.VisualScreenGroup, 0)
|
||||
li := *list
|
||||
for i := 0; i < len(li); i++ {
|
||||
if li[i].Pid != 0 {
|
||||
continue
|
||||
}
|
||||
info := Digui(list, li[i])
|
||||
|
||||
sd = append(sd, info)
|
||||
}
|
||||
return sd
|
||||
}
|
||||
|
||||
func (m *screenGroupModelImpl) SelectScreenGroupLabel(data entity.VisualScreenGroup) []entity.ScreenGroupLabel {
|
||||
deptlist := m.FindList(data)
|
||||
|
||||
dl := make([]entity.ScreenGroupLabel, 0)
|
||||
deptl := *deptlist
|
||||
for i := 0; i < len(deptl); i++ {
|
||||
if deptl[i].Pid != 0 {
|
||||
continue
|
||||
}
|
||||
e := entity.ScreenGroupLabel{}
|
||||
e.Id = deptl[i].Id
|
||||
e.Name = deptl[i].Name
|
||||
deptsInfo := DiguiDeptLable(deptlist, e)
|
||||
|
||||
dl = append(dl, deptsInfo)
|
||||
}
|
||||
return dl
|
||||
}
|
||||
|
||||
func Digui(sglist *[]entity.VisualScreenGroup, menu entity.VisualScreenGroup) entity.VisualScreenGroup {
|
||||
list := *sglist
|
||||
|
||||
min := make([]entity.VisualScreenGroup, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if menu.Id != list[j].Pid {
|
||||
continue
|
||||
}
|
||||
mi := entity.VisualScreenGroup{}
|
||||
mi.Id = list[j].Id
|
||||
mi.Pid = list[j].Pid
|
||||
mi.Path = list[j].Path
|
||||
mi.Name = list[j].Name
|
||||
mi.Sort = list[j].Sort
|
||||
mi.Status = list[j].Status
|
||||
ms := Digui(sglist, mi)
|
||||
min = append(min, ms)
|
||||
}
|
||||
menu.Children = min
|
||||
return menu
|
||||
}
|
||||
func DiguiDeptLable(sglist *[]entity.VisualScreenGroup, dept entity.ScreenGroupLabel) entity.ScreenGroupLabel {
|
||||
list := *sglist
|
||||
|
||||
min := make([]entity.ScreenGroupLabel, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if dept.Id != list[j].Id {
|
||||
continue
|
||||
}
|
||||
sg := entity.ScreenGroupLabel{list[j].Id, list[j].Name, []entity.ScreenGroupLabel{}}
|
||||
ms := DiguiDeptLable(sglist, sg)
|
||||
min = append(min, ms)
|
||||
|
||||
}
|
||||
dept.Children = min
|
||||
return dept
|
||||
}
|
||||
@@ -54,6 +54,8 @@ func InitRouter() *transport.HttpServer {
|
||||
// 可视化
|
||||
{
|
||||
visualRouter.InitRuleChainRouter(container)
|
||||
visualRouter.InitVisualScreenGroupRouter(container)
|
||||
visualRouter.InitVisualScreenRouter(container)
|
||||
}
|
||||
// 任务
|
||||
{
|
||||
|
||||
85
pkg/utils/local.go
Normal file
85
pkg/utils/local.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"pandax/pkg/global"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Local struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
//@object: *Local
|
||||
//@function: UploadFile
|
||||
//@description: 上传文件
|
||||
//@param: file *multipart.FileHeader
|
||||
//@return: string, string, error
|
||||
|
||||
func (local *Local) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||
// 读取文件后缀
|
||||
ext := path.Ext(file.Filename)
|
||||
// 读取文件名并加密
|
||||
name := strings.TrimSuffix(file.Filename, ext)
|
||||
name = MD5V([]byte(name))
|
||||
// 拼接新文件名
|
||||
filename := name + "_" + time.Now().Format("20060102150405") + ext
|
||||
// 尝试创建此路径
|
||||
mkdirErr := os.MkdirAll(local.Path, os.ModePerm)
|
||||
if mkdirErr != nil {
|
||||
global.Log.Error("function os.MkdirAll() Filed", mkdirErr.Error())
|
||||
return "", "", errors.New("function os.MkdirAll() Filed, err:" + mkdirErr.Error())
|
||||
}
|
||||
// 拼接路径和文件名
|
||||
p := local.Path + "/" + filename
|
||||
|
||||
f, openError := file.Open() // 读取文件
|
||||
if openError != nil {
|
||||
global.Log.Error("function file.Open() Filed", openError.Error())
|
||||
return "", "", errors.New("function file.Open() Filed, err:" + openError.Error())
|
||||
}
|
||||
defer f.Close() // 创建文件 defer 关闭
|
||||
|
||||
out, createErr := os.Create(p)
|
||||
if createErr != nil {
|
||||
global.Log.Error("function os.Create() Filed", createErr.Error())
|
||||
return "", "", errors.New("function os.Create() Filed, err:" + createErr.Error())
|
||||
}
|
||||
defer out.Close() // 创建文件 defer 关闭
|
||||
|
||||
_, copyErr := io.Copy(out, f) // 传输(拷贝)文件
|
||||
if copyErr != nil {
|
||||
global.Log.Error("function io.Copy() Filed", copyErr.Error())
|
||||
return "", "", errors.New("function io.Copy() Filed, err:" + copyErr.Error())
|
||||
}
|
||||
return p, filename, nil
|
||||
}
|
||||
|
||||
//@object: *Local
|
||||
//@function: DeleteFile
|
||||
//@description: 删除文件
|
||||
//@param: key string
|
||||
//@return: error
|
||||
|
||||
func (local *Local) DeleteFile(key string) error {
|
||||
p := local.Path + "/" + key
|
||||
if strings.Contains(p, local.Path) {
|
||||
if err := os.Remove(p); err != nil {
|
||||
return errors.New("本地文件删除失败, err:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func MD5V(str []byte) string {
|
||||
h := md5.New()
|
||||
h.Write(str)
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
Reference in New Issue
Block a user