123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- package controllers
-
- import (
- "gdyb/enums"
- "gdyb/models"
- "github.com/astaxie/beego"
- //"XT_New/models"
-
- //"XT_New/models"
- "gdyb/service"
- )
-
- type BaseAPIController struct {
- BaseController
- }
-
- // func (this *BaseAPIController) Prepare() {
- // this.BaseController.Prepare()
- // beego.Trace("============================================================")
- // beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID"))
- // beego.Trace("session : %v", this.GetSession("info"))
- // this.SetSession("info", time.Now().Format("2006/01/02 15:04:05"))
- // beego.Trace("============================================================")
- // }
-
- // 输出数据格式化
- /*
- success json:
- {
- "state": 1,
- "code": 0,
- "data": json,
- }
-
- fail json:
- {
- "state": 0,
- "code": int,
- "msg": string,
- }
- */
- func (this *BaseAPIController) ServeSuccessJSON(data map[string]interface{}) {
- this.Data["json"] = enums.MakeSuccessResponseJSON(data)
- this.ServeJSON()
- }
-
- func (this *BaseAPIController) ServeFailJSONWithSGJErrorCode(code int) {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(code)
- this.ServeJSON()
- }
-
- func (this *BaseAPIController) ServeFailJSONWithSGJError(err *enums.SGJError) {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJError(err)
- this.ServeJSON()
- }
-
- func (this *BaseAPIController) ServeFailJsonSend(code int, msg string) {
- this.Data["json"] = enums.MakeFailResponseJSON(msg, code)
- this.ServeJSON()
- }
-
- type BaseAuthAPIController struct {
- BaseAPIController
- }
-
- func (this *BaseAuthAPIController) Prepare() {
- this.BaseAPIController.Prepare()
- if this.GetAdminUserInfo() == nil {
-
- //org_id, _ := beego.AppConfig.Int64("org_id")
- org_id, _ := beego.AppConfig.Int64("org_id")
-
- var userAdmin models.AdminUser
- userAdmin.Id = 1448
- userAdmin.Mobile = "13318599895"
- //userAdmin.Id = 597
- //userAdmin.Mobile = "19874122664"
- userAdmin.IsSuperAdmin = false
- userAdmin.Status = 1
- userAdmin.CreateTime = 1530786071
- userAdmin.ModifyTime = 1530786071
- var subscibe models.ServeSubscibe
- subscibe.ID = 1
- subscibe.OrgId = org_id
- subscibe.PeriodStart = 1538035409
- subscibe.PeriodEnd = 1569571409
- subscibe.State = 1
- subscibe.Status = 1
- subscibe.CreatedTime = 1538035409
- subscibe.UpdatedTime = 1538035409
- subscibes := make(map[int64]*models.ServeSubscibe, 0)
- subscibes[4] = &subscibe
- var adminUserInfo service.AdminUserInfo
- adminUserInfo.CurrentOrgId = org_id
- adminUserInfo.CurrentAppId = 8642
- adminUserInfo.AdminUser = &userAdmin
- this.SetSession("admin_user_info", &adminUserInfo)
- }
-
- //if this.Ctx.Request.Header.Get("Permission") == "5" { //医保相关权限
- // org_id, _ := beego.AppConfig.Int64("org_id")
- // org, _ := service.GetOrgById(org_id)
- // admin_user_id, _ := this.GetInt64("admin_user_id")
- // if admin_user_id != org.Creator { //超级管理员不受此限制
- // isPermission := false
- // //该机构下该用户有多少个
- // role, _ := service.GetUserAllRole(org_id, admin_user_id)
- // var roles []string
- // if len(role.RoleIds) <= 0 { //该用户没有设置角色
- //
- // } else {
- // roles = strings.Split(role.RoleIds, ",")
- // }
- // fmt.Println(roles)
- //
- // //获取该用户下所有角色的权限总集
- // var userRolePurviews string
- // var userRolePurviewsArr []string
- // for _, item := range roles {
- // role_id, _ := strconv.ParseInt(item, 10, 64)
- // purviews, _ := service.GetRoleFuncPurviewIds(role_id)
- // if len(userRolePurviews) == 0 {
- // userRolePurviews = purviews
- // } else {
- // userRolePurviews = userRolePurviews + "," + purviews
- // }
- // }
- // //该用户所拥有角色的权限的总集
- // userRolePurviewsArr = RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
- // fmt.Println(userRolePurviewsArr)
- // //系统所记录的权限列表
- // allPermission, _ := service.GetAllFunctionPurview()
- //
- // for _, item := range allPermission {
- // //获取该角色的所有权限
- // for _, items := range userRolePurviewsArr {
- // id, _ := strconv.ParseInt(items, 10, 64)
- // if id == item.ID {
- // isPermission = true
- // }
- // }
- // if !isPermission {
- // msg, _ := service.FindErrorMsgByStr(item.ID)
- // json := make(map[string]interface{})
- // json["msg"] = msg
- // json["code"] = 0
- // json["state"] = 0
- // this.Data["json"] = json
- // this.ServeJSON()
- // this.StopRun()
- // }
- //
- // }
- // }
- //}
-
- }
-
- type BaseServeAPIController struct {
- BaseAPIController
- }
-
- func (this *BaseServeAPIController) Prepare() {
- this.BaseAPIController.Prepare()
- if this.GetAdminUserInfo() == nil {
- org_id, _ := beego.AppConfig.Int64("org_id")
- var userAdmin models.AdminUser
- userAdmin.Id = 1448
- userAdmin.Mobile = "13318599895"
- userAdmin.IsSuperAdmin = false
- userAdmin.Status = 1
- userAdmin.CreateTime = 1530786071
- userAdmin.ModifyTime = 1530786071
- var subscibe models.ServeSubscibe
- subscibe.ID = 1
- subscibe.OrgId = org_id
- subscibe.PeriodStart = 1538035409
- subscibe.PeriodEnd = 1569571409
- subscibe.State = 1
- subscibe.Status = 1
- subscibe.CreatedTime = 1538035409
- subscibe.UpdatedTime = 1538035409
- subscibes := make(map[int64]*models.ServeSubscibe, 0)
- subscibes[4] = &subscibe
- var adminUserInfo service.AdminUserInfo
- adminUserInfo.CurrentOrgId = org_id
- adminUserInfo.AdminUser = &userAdmin
- this.SetSession("admin_user_info", &adminUserInfo)
- }
-
- //if this.Ctx.Request.Header.Get("Permission") == "5" { //医保相关权限
- // org_id, _ := beego.AppConfig.Int64("org_id")
- // org, _ := service.GetOrgById(org_id)
- // admin_user_id, _ := this.GetInt64("admin_user_id")
- // if admin_user_id != org.Creator { //超级管理员不受此限制
- // isPermission := false
- // //该机构下该用户有多少个
- // role, _ := service.GetUserAllRole(org_id, admin_user_id)
- // var roles []string
- // if len(role.RoleIds) <= 0 { //该用户没有设置角色
- //
- // } else {
- // roles = strings.Split(role.RoleIds, ",")
- // }
- // fmt.Println(roles)
- //
- // //获取该用户下所有角色的权限总集
- // var userRolePurviews string
- // var userRolePurviewsArr []string
- // for _, item := range roles {
- // role_id, _ := strconv.ParseInt(item, 10, 64)
- // purviews, _ := service.GetRoleFuncPurviewIds(role_id)
- // if len(userRolePurviews) == 0 {
- // userRolePurviews = purviews
- // } else {
- // userRolePurviews = userRolePurviews + "," + purviews
- // }
- // }
- // //该用户所拥有角色的权限的总集
- // userRolePurviewsArr = RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
- // fmt.Println(userRolePurviewsArr)
- // //系统所记录的权限列表
- // allPermission, _ := service.GetAllFunctionPurview()
- //
- // for _, item := range allPermission {
- // //获取该角色的所有权限
- // for _, items := range userRolePurviewsArr {
- // id, _ := strconv.ParseInt(items, 10, 64)
- // if id == item.ID {
- // isPermission = true
- // }
- // }
- // if !isPermission {
- // msg, _ := service.FindErrorMsgByStr(item.ID)
- // json := make(map[string]interface{})
- // json["msg"] = msg
- // json["code"] = 0
- // json["state"] = 0
- // this.Data["json"] = json
- // this.ServeJSON()
- // this.StopRun()
- // }
- //
- // }
- // }
- //}
-
- }
-
- func RemoveRepeatedPurviewElement2(arr []string) (newArr []string) {
- newArr = make([]string, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i] == arr[j] {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
|