system.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package eta_forum
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models/system"
  5. "eta/eta_api/utils"
  6. "fmt"
  7. )
  8. type RoleSaveReq struct {
  9. RoleId int `description:"角色ID"`
  10. RoleName string `description:"角色名称"`
  11. RoleType string `description:"角色类型"`
  12. RoleTypeCode string `description:"角色类型编码"`
  13. RoleLevel int `description:"角色等级:0-表示一级角色,每个账号只能绑定一个一级角色 ,1-表示二级角色,每个账号可以绑定多个二级 角色"`
  14. CreateTime string `description:"创建时间"`
  15. ModifyTime string
  16. BusinessCode string `description:"商家编码"`
  17. }
  18. // 上传角色信息
  19. func RoleSave(roleId int) (err error) {
  20. if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
  21. return
  22. }
  23. //查询用户信息
  24. roleInfo, err := system.GetRoleInfoById(roleId)
  25. if err != nil {
  26. if err.Error() == utils.ErrNoRow() {
  27. err = fmt.Errorf("用户不存在")
  28. return
  29. }
  30. err = fmt.Errorf("获取用户信息失败,Err:" + err.Error())
  31. return
  32. }
  33. var req RoleSaveReq
  34. req.RoleId = roleInfo.RoleId
  35. req.RoleName = roleInfo.RoleName
  36. req.RoleTypeCode = roleInfo.RoleTypeCode
  37. req.RoleType = roleInfo.RoleType
  38. req.RoleLevel = roleInfo.RoleLevel
  39. req.CreateTime = roleInfo.CreateTime.Format(utils.FormatDateTime)
  40. req.ModifyTime = roleInfo.ModifyTime.Format(utils.FormatDateTime)
  41. reqJson, err := json.Marshal(req)
  42. if err != nil {
  43. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  44. return
  45. }
  46. respItem, err := RoleSaveLib(string(reqJson))
  47. if err != nil {
  48. err = fmt.Errorf("上传角色信息失败,Err:" + err.Error())
  49. return
  50. }
  51. if respItem.Ret != 200 {
  52. err = fmt.Errorf("上传角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
  53. return
  54. }
  55. return
  56. }
  57. type RoleDeleteReq struct {
  58. RoleId int
  59. BusinessCode string `description:"商家编码"`
  60. }
  61. // 删除角色信息
  62. func RoleDelete(roleId int) (err error) {
  63. if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
  64. return
  65. }
  66. var req RoleDeleteReq
  67. req.RoleId = roleId
  68. req.BusinessCode = utils.BusinessCode
  69. reqJson, err := json.Marshal(req)
  70. if err != nil {
  71. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  72. return
  73. }
  74. respItem, err := RoleDeleteLib(string(reqJson))
  75. if err != nil {
  76. err = fmt.Errorf("删除角色信息失败,Err:" + err.Error())
  77. return
  78. }
  79. if respItem.Ret != 200 {
  80. err = fmt.Errorf("删除角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
  81. return
  82. }
  83. return
  84. }
  85. type SysDepartmentAddReq struct {
  86. DepartmentId int `description:"部门Id"`
  87. DepartmentName string `description:"部门名称"`
  88. Sort int `description:"排序"`
  89. CreateTime string `description:"创建时间"`
  90. }
  91. // 上传部门信息
  92. func DepartmentSave(id int) (err error) {
  93. if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
  94. return
  95. }
  96. //查询用户信息
  97. info, err := system.GetSysDepartmentById(id)
  98. if err != nil {
  99. if err.Error() == utils.ErrNoRow() {
  100. err = fmt.Errorf("用户不存在")
  101. return
  102. }
  103. err = fmt.Errorf("获取用户信息失败,Err:" + err.Error())
  104. return
  105. }
  106. var req SysDepartmentAddReq
  107. req.DepartmentId = info.DepartmentId
  108. req.DepartmentName = info.DepartmentName
  109. req.Sort = info.Sort
  110. req.CreateTime = info.CreateTime.Format(utils.FormatDateTime)
  111. reqJson, err := json.Marshal(req)
  112. if err != nil {
  113. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  114. return
  115. }
  116. respItem, err := DepartmentSaveLib(string(reqJson))
  117. if err != nil {
  118. err = fmt.Errorf("上传角色信息失败,Err:" + err.Error())
  119. return
  120. }
  121. if respItem.Ret != 200 {
  122. err = fmt.Errorf("上传角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
  123. return
  124. }
  125. return
  126. }
  127. type DepartmentDeleteReq struct {
  128. DepartmentId int `description:"部门Id"`
  129. BusinessCode string `description:"商家编码"`
  130. }
  131. // 删除部门信息
  132. func DepartmentDelete(id int) (err error) {
  133. if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
  134. return
  135. }
  136. var req DepartmentDeleteReq
  137. req.DepartmentId = id
  138. req.BusinessCode = utils.BusinessCode
  139. reqJson, err := json.Marshal(req)
  140. if err != nil {
  141. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  142. return
  143. }
  144. respItem, err := DepartmentDeleteLib(string(reqJson))
  145. if err != nil {
  146. err = fmt.Errorf("删除角色信息失败,Err:" + err.Error())
  147. return
  148. }
  149. if respItem.Ret != 200 {
  150. err = fmt.Errorf("删除角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
  151. return
  152. }
  153. return
  154. }
  155. type SysGroupAddReq struct {
  156. List []*system.SysGroup
  157. }
  158. // 新增分组信息
  159. func GroupSave(ids []int) (err error) {
  160. if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
  161. return
  162. }
  163. //查询用户信息
  164. if len(ids) == 0 {
  165. return
  166. }
  167. list, err := system.GetSysGroupByGroupIds(ids)
  168. if err != nil {
  169. err = fmt.Errorf("获取分组信息失败,Err:" + err.Error())
  170. return
  171. }
  172. var req SysGroupAddReq
  173. req.List = list
  174. reqJson, err := json.Marshal(req)
  175. if err != nil {
  176. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  177. return
  178. }
  179. respItem, err := GroupSaveLib(string(reqJson))
  180. if err != nil {
  181. err = fmt.Errorf("上传角色信息失败,Err:" + err.Error())
  182. return
  183. }
  184. if respItem.Ret != 200 {
  185. err = fmt.Errorf("上传角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
  186. return
  187. }
  188. return
  189. }
  190. type GroupDeleteReq struct {
  191. GroupId int `description:"分组ID"`
  192. BusinessCode string `description:"商家编码"`
  193. }
  194. // 删除分组信息
  195. func GroupDelete(id int) (err error) {
  196. if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
  197. return
  198. }
  199. var req GroupDeleteReq
  200. req.GroupId = id
  201. req.BusinessCode = utils.BusinessCode
  202. reqJson, err := json.Marshal(req)
  203. if err != nil {
  204. err = fmt.Errorf("参数解析异常,Err:" + err.Error())
  205. return
  206. }
  207. respItem, err := GroupDeleteLib(string(reqJson))
  208. if err != nil {
  209. err = fmt.Errorf("删除角色信息失败,Err:" + err.Error())
  210. return
  211. }
  212. if respItem.Ret != 200 {
  213. err = fmt.Errorf("删除角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
  214. return
  215. }
  216. return
  217. }