123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- package controllers
-
- import (
- "fmt"
- "strconv"
- "strings"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- )
-
- type BaseAPIController struct {
- BaseController
- }
-
-
-
-
-
-
-
-
-
-
-
-
- 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()
- }
-
- func (this *BaseAPIController) ServeDynamicFailJsonSend(msg string) {
- this.Data["json"] = enums.MakeDynamicFailResponseJSON(msg)
- this.ServeJSON()
- }
-
- type BaseAuthAPIController struct {
- BaseAPIController
- }
-
- func (this *BaseAuthAPIController) Prepare() {
- this.BaseAPIController.Prepare()
- if this.GetAdminUserInfo() == nil {
- var userAdmin models.AdminUser
- userAdmin.Id = 1448
- userAdmin.Mobile = "13318599895"
-
- userAdmin.Id = 1
- userAdmin.Mobile = "12222222222"
- userAdmin.IsSuperAdmin = true
- userAdmin.Status = 1
- userAdmin.CreateTime = 1530786071
- userAdmin.ModifyTime = 1530786071
- var subscibe models.ServeSubscibe
- subscibe.ID = 11
- subscibe.OrgId = 10644
- subscibe.PeriodStart = 1547447814
- subscibe.PeriodEnd = 1550039814
- 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 = 10644
- adminUserInfo.CurrentAppId = 17634
- adminUserInfo.AdminUser = &userAdmin
- adminUserInfo.Subscibes = subscibes
- this.SetSession("admin_user_info", &adminUserInfo)
-
-
-
-
- }
-
- adminUserInfo := this.GetAdminUserInfo()
-
- if this.Ctx.Request.Header.Get("Permission") == "2" {
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- if adminUserInfo.AdminUser.Id != org.Creator {
-
- isPermission := false
- adminUserInfo := this.GetAdminUserInfo()
-
- role, _ := service.GetUserAllRole(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.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 {
-
-
-
-
-
-
- if strings.Split(item.Urlfor, ",")[1] == strings.Split(this.Ctx.Request.RequestURI, "?")[0]+"?"+"mode="+this.GetString("mode") {
-
-
- for _, items := range userRolePurviewsArr {
- id, _ := strconv.ParseInt(items, 10, 64)
- if id == item.ID {
- isPermission = true
- }
- }
- if !isPermission {
- msg, _ := service.FindErrorMsgByStr(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
- json := make(map[string]interface{})
- json["msg"] = msg
- json["code"] = 0
- json["state"] = 0
- this.Data["json"] = json
- this.ServeJSON()
- this.StopRun()
- }
- }
- }
- }
- }
-
- if this.Ctx.Request.Header.Get("Permission") == "3" {
- org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
- if adminUserInfo.AdminUser.Id != org.Creator {
-
- isPermission := false
- adminUserInfo := this.GetAdminUserInfo()
-
- role, _ := service.GetUserAllRole(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.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 {
-
-
-
-
- if strings.Split(item.Urlfor, ",")[2] == strings.Split(this.Ctx.Request.RequestURI, "?")[0]+"?"+"mode="+this.GetString("mode") {
-
-
- for _, items := range userRolePurviewsArr {
- id, _ := strconv.ParseInt(items, 10, 64)
- if id == item.ID {
- isPermission = true
- }
- }
- if !isPermission {
- msg, _ := service.FindErrorMsgByStr(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
- 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 {
- var userAdmin models.AdminUser
- userAdmin.Id = 1448
- userAdmin.Mobile = "13318599895"
-
- userAdmin.Id = 1
- userAdmin.Mobile = "12222222222"
- userAdmin.IsSuperAdmin = false
- userAdmin.Status = 1
- userAdmin.CreateTime = 1530786071
- userAdmin.ModifyTime = 1530786071
- var subscibe models.ServeSubscibe
- subscibe.ID = 11
- subscibe.OrgId = 10644
- 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 = 10644
- adminUserInfo.CurrentAppId = 17634
- adminUserInfo.AdminUser = &userAdmin
- adminUserInfo.Subscibes = subscibes
- this.SetSession("admin_user_info", &adminUserInfo)
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- 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
- }
|