123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- package eta_forum
- import (
- "encoding/json"
- "eta/eta_api/models/system"
- "eta/eta_api/utils"
- "fmt"
- )
- type RoleSaveReq struct {
- RoleId int `description:"角色ID"`
- RoleName string `description:"角色名称"`
- RoleType string `description:"角色类型"`
- RoleTypeCode string `description:"角色类型编码"`
- RoleLevel int `description:"角色等级:0-表示一级角色,每个账号只能绑定一个一级角色 ,1-表示二级角色,每个账号可以绑定多个二级 角色"`
- CreateTime string `description:"创建时间"`
- ModifyTime string
- BusinessCode string `description:"商家编码"`
- }
- // 上传角色信息
- func RoleSave(roleId int) (err error) {
- if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
- return
- }
- //查询用户信息
- roleInfo, err := system.GetRoleInfoById(roleId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = fmt.Errorf("用户不存在")
- return
- }
- err = fmt.Errorf("获取用户信息失败,Err:" + err.Error())
- return
- }
- var req RoleSaveReq
- req.RoleId = roleInfo.RoleId
- req.RoleName = roleInfo.RoleName
- req.RoleTypeCode = roleInfo.RoleTypeCode
- req.RoleType = roleInfo.RoleType
- req.RoleLevel = roleInfo.RoleLevel
- req.CreateTime = roleInfo.CreateTime.Format(utils.FormatDateTime)
- req.ModifyTime = roleInfo.ModifyTime.Format(utils.FormatDateTime)
- reqJson, err := json.Marshal(req)
- if err != nil {
- err = fmt.Errorf("参数解析异常,Err:" + err.Error())
- return
- }
- respItem, err := RoleSaveLib(string(reqJson))
- if err != nil {
- err = fmt.Errorf("上传角色信息失败,Err:" + err.Error())
- return
- }
- if respItem.Ret != 200 {
- err = fmt.Errorf("上传角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
- return
- }
- return
- }
- type RoleDeleteReq struct {
- RoleId int
- BusinessCode string `description:"商家编码"`
- }
- // 删除角色信息
- func RoleDelete(roleId int) (err error) {
- if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
- return
- }
- var req RoleDeleteReq
- req.RoleId = roleId
- req.BusinessCode = utils.BusinessCode
- reqJson, err := json.Marshal(req)
- if err != nil {
- err = fmt.Errorf("参数解析异常,Err:" + err.Error())
- return
- }
- respItem, err := RoleDeleteLib(string(reqJson))
- if err != nil {
- err = fmt.Errorf("删除角色信息失败,Err:" + err.Error())
- return
- }
- if respItem.Ret != 200 {
- err = fmt.Errorf("删除角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
- return
- }
- return
- }
- type SysDepartmentAddReq struct {
- DepartmentId int `description:"部门Id"`
- DepartmentName string `description:"部门名称"`
- Sort int `description:"排序"`
- CreateTime string `description:"创建时间"`
- }
- // 上传部门信息
- func DepartmentSave(id int) (err error) {
- if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
- return
- }
- //查询用户信息
- info, err := system.GetSysDepartmentById(id)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = fmt.Errorf("用户不存在")
- return
- }
- err = fmt.Errorf("获取用户信息失败,Err:" + err.Error())
- return
- }
- var req SysDepartmentAddReq
- req.DepartmentId = info.DepartmentId
- req.DepartmentName = info.DepartmentName
- req.Sort = info.Sort
- req.CreateTime = info.CreateTime.Format(utils.FormatDateTime)
- reqJson, err := json.Marshal(req)
- if err != nil {
- err = fmt.Errorf("参数解析异常,Err:" + err.Error())
- return
- }
- respItem, err := DepartmentSaveLib(string(reqJson))
- if err != nil {
- err = fmt.Errorf("上传角色信息失败,Err:" + err.Error())
- return
- }
- if respItem.Ret != 200 {
- err = fmt.Errorf("上传角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
- return
- }
- return
- }
- type DepartmentDeleteReq struct {
- DepartmentId int `description:"部门Id"`
- BusinessCode string `description:"商家编码"`
- }
- // 删除部门信息
- func DepartmentDelete(id int) (err error) {
- if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
- return
- }
- var req DepartmentDeleteReq
- req.DepartmentId = id
- req.BusinessCode = utils.BusinessCode
- reqJson, err := json.Marshal(req)
- if err != nil {
- err = fmt.Errorf("参数解析异常,Err:" + err.Error())
- return
- }
- respItem, err := DepartmentDeleteLib(string(reqJson))
- if err != nil {
- err = fmt.Errorf("删除角色信息失败,Err:" + err.Error())
- return
- }
- if respItem.Ret != 200 {
- err = fmt.Errorf("删除角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
- return
- }
- return
- }
- type SysGroupAddReq struct {
- List []*system.SysGroup
- }
- // 新增分组信息
- func GroupSave(ids []int) (err error) {
- if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
- return
- }
- //查询用户信息
- if len(ids) == 0 {
- return
- }
- list, err := system.GetSysGroupByGroupIds(ids)
- if err != nil {
- err = fmt.Errorf("获取分组信息失败,Err:" + err.Error())
- return
- }
- var req SysGroupAddReq
- req.List = list
- reqJson, err := json.Marshal(req)
- if err != nil {
- err = fmt.Errorf("参数解析异常,Err:" + err.Error())
- return
- }
- respItem, err := GroupSaveLib(string(reqJson))
- if err != nil {
- err = fmt.Errorf("上传角色信息失败,Err:" + err.Error())
- return
- }
- if respItem.Ret != 200 {
- err = fmt.Errorf("上传角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
- return
- }
- return
- }
- type GroupDeleteReq struct {
- GroupId int `description:"分组ID"`
- BusinessCode string `description:"商家编码"`
- }
- // 删除分组信息
- func GroupDelete(id int) (err error) {
- if utils.BusinessCode == "" || (utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeDebug && utils.BusinessCode != utils.BusinessCodeSandbox) {
- return
- }
- var req GroupDeleteReq
- req.GroupId = id
- req.BusinessCode = utils.BusinessCode
- reqJson, err := json.Marshal(req)
- if err != nil {
- err = fmt.Errorf("参数解析异常,Err:" + err.Error())
- return
- }
- respItem, err := GroupDeleteLib(string(reqJson))
- if err != nil {
- err = fmt.Errorf("删除角色信息失败,Err:" + err.Error())
- return
- }
- if respItem.Ret != 200 {
- err = fmt.Errorf("删除角色信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg)
- return
- }
- return
- }
|