| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- package casbin
- import (
- "dashoo.cn/business2/module"
- . "dashoo.cn/backend/api/controllers"
- "encoding/json"
- "fmt"
- // "fmt"
- "dashoo.cn/utils"
- )
- // Operations about Users
- type ModuleController struct {
- BaseController
- }
- type ModuleModel struct {
- Parentid int `json:"parentid"`
- Fullname string `json:"fullname"`
- Description string `json:"description"`
- HaveChild int `json:"havechild"`
- Navigateurl string `json:"navigateurl"`
- Imageindex string `json:"imageindex"`
- }
- // @Title 菜单列表
- // @Description 菜单列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /list [get]
- func (this *ModuleController) List() {
- //page := this.GetPageInfoForm()
- svc := module.GetModuleService(utils.DBE)
- //permissionsvc := permission.GetPermissionService(utils.DBE)
- //ztreecurrentusernodesmodu := permissionsvc.GetModuleAll(this.User.Id, "30")
- where := " 1=1"
- keyword := this.GetString("keyword")
- parentid := this.GetString("parentid")
- if keyword != "" {
- where = where + " and FullName like '%" + keyword + "%'"
- }
- if parentid != "" && parentid != "-1" {
- ids := svc.GetChildByTopId(parentid)
- where = where + " and Id in ( " + ids + " )"
- }
- var list []module.Base_Module
- svc.GetEntities(&list, where)
- var datainfo DataInfo
- datainfo.Items = list
- //datainfo.CurrentItemCount = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 菜单列表带父级名称
- // @Description
- // @Success 200 {object} business.device.DeviceChannels
- // @router /listbandparentname [get]
- func (this *ModuleController) Listbandparentname() {
- page := this.GetPageInfoForm()
- svc := module.GetModuleService(utils.DBE)
- where := "1=1"
- keyword := this.GetString("keyword")
- parentid := this.GetString("parentid")
- if keyword != "" {
- where = where + " and a.Fullname like '%" + keyword + "%'"
- }
- if parentid != "" && parentid != "-1" {
- ids := svc.GetChildByTopId(parentid)
- where = where + " and a.Id in ( " + ids + " )"
- }
- total, list := svc.GetListbandparentname(page.CurrentPage, page.Size, "a.ParentId, a.CreateOn desc", where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 创建菜单
- // @Description 创建菜单
- // @Param body body business.device.DeviceChannels
- // @Success 200 {object} controllers.Request
- // @router / [post]
- func (this *ModuleController) AddOrganize() {
- var model ModuleModel
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var errinfo ErrorInfo
- var entity module.Base_Module
- svc := module.GetModuleService(utils.DBE)
- // 编辑后添加一条数据
- entity.Fullname = model.Fullname
- entity.Parentid = model.Parentid
- entity.Description = model.Description
- entity.Navigateurl = model.Navigateurl
- entity.Imageindex = model.Imageindex
- entity.Createuserid, _ = utils.StrTo(this.User.Id).Int()
- entity.Createby = this.User.Realname
- entity.Enabled = 1
- entity.Ismenu = 0000000001
- entity.Ispublic =1
- entity.Expand = 1
- entity.Allowdelete = 1
- entity.Allowedit =1
- _, err := svc.InsertEntity(&entity)
- if err == nil {
- errinfo.Message = "添加菜单成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- } else {
- errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- }
- // @Title 编辑菜单
- // @Description 编辑菜单
- // @Param id path string true
- // @Param body body business.device.DeviceChannels
- // @Success 200 {object} controllers.Request
- // @router /:id [put]
- func (this *ModuleController) EditOrganize() {
- id := this.Ctx.Input.Param(":id")
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model ModuleModel
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var entity module.Base_Module
- var entityempty module.Base_Module
- svc := module.GetModuleService(utils.DBE)
- has := svc.GetEntityById(id, &entity)
- if has {
- entity.Fullname = model.Fullname
- entity.Parentid = model.Parentid
- entity.Description = model.Description
- entity.Navigateurl = model.Navigateurl
- entity.Imageindex = model.Imageindex
- entity.Modifieduserid, _ = utils.StrTo(this.User.Id).Int()
- entity.Modifiedby = this.User.Realname
- var cols []string = []string{"FullName", "ParentId", "Description","NavigateUrl","ImageIndex", "ModifiedUserId", "ModifiedBy"}
- err := svc.UpdateEntityAndBackupByCols(id, &entity, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Realname)
- if err == nil {
- errinfo.Message = "保存成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- } else {
- errinfo.Message = "操作失败!操作数据不存在"
- errinfo.Code = -3
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- }
- // @Title 删除菜单
- // @Description 删除菜单
- // @Param id path string true
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /:id [delete]
- func (this *ModuleController) Delete() {
- id := this.Ctx.Input.Param(":id")
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- svc := module.GetModuleService(utils.DBE)
- var entity module.Base_Module
- var entityempty module.Base_Module
- err := svc.DeleteEntityAndBackup(id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取子集列表
- // @Description 获取子集列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /childlist/:id [get]
- func (this *ModuleController) ChildList() {
- id := this.Ctx.Input.Param(":id")
- svc := module.GetModuleService(utils.DBE)
- where := " Createuserid= " + this.User.Id
- where = where + " and ParentId = " + id + ""
- list := make([]module.Base_Module, 0)
- svc.GetDatasByCols(&list, where, "Sortcode, CreateOn desc", []string{"Id", "ParentId", "Fullname"})
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取父集列表
- // @Description 获取父集列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /parentlist/:id [get]
- func (this *ModuleController) ParentList() {
- id := this.Ctx.Input.Param(":id")
- svc := module.GetModuleService(utils.DBE)
- var errinfo ErrorInfo
- var url string
- idlist := svc.GetMenuTopItem(url, id)
- fmt.Println(idlist)
- errinfo.Message = "test"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
|