module.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. package casbin
  2. import (
  3. "dashoo.cn/business2/module"
  4. . "dashoo.cn/backend/api/controllers"
  5. "encoding/json"
  6. "fmt"
  7. // "fmt"
  8. "dashoo.cn/utils"
  9. )
  10. // Operations about Users
  11. type ModuleController struct {
  12. BaseController
  13. }
  14. type ModuleModel struct {
  15. Parentid int `json:"parentid"`
  16. Fullname string `json:"fullname"`
  17. Description string `json:"description"`
  18. HaveChild int `json:"havechild"`
  19. Navigateurl string `json:"navigateurl"`
  20. Imageindex string `json:"imageindex"`
  21. }
  22. // @Title 菜单列表
  23. // @Description 菜单列表
  24. // @Success 200 {object} business.device.DeviceChannels
  25. // @router /list [get]
  26. func (this *ModuleController) List() {
  27. //page := this.GetPageInfoForm()
  28. svc := module.GetModuleService(utils.DBE)
  29. //permissionsvc := permission.GetPermissionService(utils.DBE)
  30. //ztreecurrentusernodesmodu := permissionsvc.GetModuleAll(this.User.Id, "30")
  31. where := " 1=1"
  32. keyword := this.GetString("keyword")
  33. parentid := this.GetString("parentid")
  34. if keyword != "" {
  35. where = where + " and FullName like '%" + keyword + "%'"
  36. }
  37. if parentid != "" && parentid != "-1" {
  38. ids := svc.GetChildByTopId(parentid)
  39. where = where + " and Id in ( " + ids + " )"
  40. }
  41. var list []module.Base_Module
  42. svc.GetEntities(&list, where)
  43. var datainfo DataInfo
  44. datainfo.Items = list
  45. //datainfo.CurrentItemCount = total
  46. this.Data["json"] = &datainfo
  47. this.ServeJSON()
  48. }
  49. // @Title 菜单列表带父级名称
  50. // @Description
  51. // @Success 200 {object} business.device.DeviceChannels
  52. // @router /listbandparentname [get]
  53. func (this *ModuleController) Listbandparentname() {
  54. page := this.GetPageInfoForm()
  55. svc := module.GetModuleService(utils.DBE)
  56. where := "1=1"
  57. keyword := this.GetString("keyword")
  58. parentid := this.GetString("parentid")
  59. if keyword != "" {
  60. where = where + " and a.Fullname like '%" + keyword + "%'"
  61. }
  62. if parentid != "" && parentid != "-1" {
  63. ids := svc.GetChildByTopId(parentid)
  64. where = where + " and a.Id in ( " + ids + " )"
  65. }
  66. total, list := svc.GetListbandparentname(page.CurrentPage, page.Size, "a.ParentId, a.CreateOn desc", where)
  67. var datainfo DataInfo
  68. datainfo.Items = list
  69. datainfo.CurrentItemCount = total
  70. this.Data["json"] = &datainfo
  71. this.ServeJSON()
  72. }
  73. // @Title 创建菜单
  74. // @Description 创建菜单
  75. // @Param body body business.device.DeviceChannels
  76. // @Success 200 {object} controllers.Request
  77. // @router / [post]
  78. func (this *ModuleController) AddOrganize() {
  79. var model ModuleModel
  80. var jsonblob = this.Ctx.Input.RequestBody
  81. json.Unmarshal(jsonblob, &model)
  82. var errinfo ErrorInfo
  83. var entity module.Base_Module
  84. svc := module.GetModuleService(utils.DBE)
  85. // 编辑后添加一条数据
  86. entity.Fullname = model.Fullname
  87. entity.Parentid = model.Parentid
  88. entity.Description = model.Description
  89. entity.Navigateurl = model.Navigateurl
  90. entity.Imageindex = model.Imageindex
  91. entity.Createuserid, _ = utils.StrTo(this.User.Id).Int()
  92. entity.Createby = this.User.Realname
  93. entity.Enabled = 1
  94. entity.Ismenu = 0000000001
  95. entity.Ispublic =1
  96. entity.Expand = 1
  97. entity.Allowdelete = 1
  98. entity.Allowedit =1
  99. _, err := svc.InsertEntity(&entity)
  100. if err == nil {
  101. errinfo.Message = "添加菜单成功!"
  102. errinfo.Code = 0
  103. this.Data["json"] = &errinfo
  104. this.ServeJSON()
  105. return
  106. } else {
  107. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  108. errinfo.Code = -1
  109. this.Data["json"] = &errinfo
  110. this.ServeJSON()
  111. return
  112. }
  113. }
  114. // @Title 编辑菜单
  115. // @Description 编辑菜单
  116. // @Param id path string true
  117. // @Param body body business.device.DeviceChannels
  118. // @Success 200 {object} controllers.Request
  119. // @router /:id [put]
  120. func (this *ModuleController) EditOrganize() {
  121. id := this.Ctx.Input.Param(":id")
  122. var errinfo ErrorInfo
  123. if id == "" {
  124. errinfo.Message = "操作失败!请求信息不完整"
  125. errinfo.Code = -2
  126. this.Data["json"] = &errinfo
  127. this.ServeJSON()
  128. return
  129. }
  130. var model ModuleModel
  131. var jsonblob = this.Ctx.Input.RequestBody
  132. json.Unmarshal(jsonblob, &model)
  133. var entity module.Base_Module
  134. var entityempty module.Base_Module
  135. svc := module.GetModuleService(utils.DBE)
  136. has := svc.GetEntityById(id, &entity)
  137. if has {
  138. entity.Fullname = model.Fullname
  139. entity.Parentid = model.Parentid
  140. entity.Description = model.Description
  141. entity.Navigateurl = model.Navigateurl
  142. entity.Imageindex = model.Imageindex
  143. entity.Modifieduserid, _ = utils.StrTo(this.User.Id).Int()
  144. entity.Modifiedby = this.User.Realname
  145. var cols []string = []string{"FullName", "ParentId", "Description","NavigateUrl","ImageIndex", "ModifiedUserId", "ModifiedBy"}
  146. err := svc.UpdateEntityAndBackupByCols(id, &entity, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Realname)
  147. if err == nil {
  148. errinfo.Message = "保存成功!"
  149. errinfo.Code = 0
  150. this.Data["json"] = &errinfo
  151. this.ServeJSON()
  152. } else {
  153. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  154. errinfo.Code = -1
  155. this.Data["json"] = &errinfo
  156. this.ServeJSON()
  157. }
  158. } else {
  159. errinfo.Message = "操作失败!操作数据不存在"
  160. errinfo.Code = -3
  161. this.Data["json"] = &errinfo
  162. this.ServeJSON()
  163. return
  164. }
  165. }
  166. // @Title 删除菜单
  167. // @Description 删除菜单
  168. // @Param id path string true
  169. // @Success 200 {object} ErrorInfo
  170. // @Failure 403 :id 为空
  171. // @router /:id [delete]
  172. func (this *ModuleController) Delete() {
  173. id := this.Ctx.Input.Param(":id")
  174. var errinfo ErrorInfo
  175. if id == "" {
  176. errinfo.Message = "操作失败!请求信息不完整"
  177. errinfo.Code = -2
  178. this.Data["json"] = &errinfo
  179. this.ServeJSON()
  180. return
  181. }
  182. svc := module.GetModuleService(utils.DBE)
  183. var entity module.Base_Module
  184. var entityempty module.Base_Module
  185. err := svc.DeleteEntityAndBackup(id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username)
  186. if err == nil {
  187. errinfo.Message = "删除成功"
  188. errinfo.Code = 0
  189. this.Data["json"] = &errinfo
  190. this.ServeJSON()
  191. } else {
  192. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  193. errinfo.Code = -1
  194. this.Data["json"] = &errinfo
  195. this.ServeJSON()
  196. }
  197. }
  198. // @Title 获取子集列表
  199. // @Description 获取子集列表
  200. // @Success 200 {object} business.device.DeviceChannels
  201. // @router /childlist/:id [get]
  202. func (this *ModuleController) ChildList() {
  203. id := this.Ctx.Input.Param(":id")
  204. svc := module.GetModuleService(utils.DBE)
  205. where := " Createuserid= " + this.User.Id
  206. where = where + " and ParentId = " + id + ""
  207. list := make([]module.Base_Module, 0)
  208. svc.GetDatasByCols(&list, where, "Sortcode, CreateOn desc", []string{"Id", "ParentId", "Fullname"})
  209. var datainfo DataInfo
  210. datainfo.Items = list
  211. this.Data["json"] = &datainfo
  212. this.ServeJSON()
  213. }
  214. // @Title 获取父集列表
  215. // @Description 获取父集列表
  216. // @Success 200 {object} business.device.DeviceChannels
  217. // @router /parentlist/:id [get]
  218. func (this *ModuleController) ParentList() {
  219. id := this.Ctx.Input.Param(":id")
  220. svc := module.GetModuleService(utils.DBE)
  221. var errinfo ErrorInfo
  222. var url string
  223. idlist := svc.GetMenuTopItem(url, id)
  224. fmt.Println(idlist)
  225. errinfo.Message = "test"
  226. errinfo.Code = 0
  227. this.Data["json"] = &errinfo
  228. this.ServeJSON()
  229. }