|
@@ -2,6 +2,8 @@ package admin_service
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"encoding/json"
|
|
5
|
+ "fmt"
|
|
6
|
+ "github.com/jinzhu/gorm"
|
5
|
7
|
"io/ioutil"
|
6
|
8
|
"net/http"
|
7
|
9
|
"net/url"
|
|
@@ -146,11 +148,11 @@ func processAdminUserInfo(data map[string]interface{}) *AdminUserInfo {
|
146
|
148
|
orgs := processOrgs(data)
|
147
|
149
|
orgAppIds := processOrgAppIds(data)
|
148
|
150
|
orgApps := processOrgApps(data)
|
149
|
|
- app2OrgIds := processApp2OrgIds(data)
|
|
151
|
+ //app2OrgIds := processApp2OrgIds(data)
|
150
|
152
|
appRoles := processAppRoles(data)
|
151
|
153
|
appPurviews := processPurviews(data)
|
152
|
154
|
appUrlfors := processPurviewUrlfors(data)
|
153
|
|
- orgSubscibes := processOrgSubscibes(data)
|
|
155
|
+ //orgSubscibes := processOrgSubscibes(data)
|
154
|
156
|
sessionAdminUserInfo := &AdminUserInfo{
|
155
|
157
|
AdminUser: adminUser,
|
156
|
158
|
CurrentOrgId: currentOrgId,
|
|
@@ -159,11 +161,11 @@ func processAdminUserInfo(data map[string]interface{}) *AdminUserInfo {
|
159
|
161
|
Orgs: orgs,
|
160
|
162
|
OrgAppIds: orgAppIds,
|
161
|
163
|
OrgApps: orgApps,
|
162
|
|
- App2OrgIds: app2OrgIds,
|
163
|
|
- AppRoles: appRoles,
|
164
|
|
- AppPurviews: appPurviews,
|
165
|
|
- AppUrlfors: appUrlfors,
|
166
|
|
- Subscibes: orgSubscibes,
|
|
164
|
+ //App2OrgIds: app2OrgIds,
|
|
165
|
+ AppRoles: appRoles,
|
|
166
|
+ AppPurviews: appPurviews,
|
|
167
|
+ AppUrlfors: appUrlfors,
|
|
168
|
+ //Subscibes: orgSubscibes,
|
167
|
169
|
}
|
168
|
170
|
return sessionAdminUserInfo
|
169
|
171
|
}
|
|
@@ -381,3 +383,86 @@ func ModifyPassword(adminID int64, password string) error {
|
381
|
383
|
err := service.UserWriteDB().Model(&models.AdminUser{}).Where("id = ? AND status = 1", adminID).Updates(map[string]interface{}{"password": password, "mtime": time.Now().Unix()}).Error
|
382
|
384
|
return err
|
383
|
385
|
}
|
|
386
|
+
|
|
387
|
+func GetPurviewById(ids string) ([]*models.Purview, error) {
|
|
388
|
+ var originPurviews []*models.Purview
|
|
389
|
+ getPurviewErr := service.UserReadDB().Model(&models.Purview{}).Where(fmt.Sprintf("id in (%v) and status = 1", ids)).Order("listorder asc").Order("id asc").Find(&originPurviews).Error
|
|
390
|
+ return originPurviews, getPurviewErr
|
|
391
|
+}
|
|
392
|
+
|
|
393
|
+func FindAdminUserIDA(id int64) (role models.App_Role, err error) {
|
|
394
|
+ err = service.UserReadDB().Model(&models.App_Role{}).Where("id = ?", id).First(&role).Error
|
|
395
|
+ return
|
|
396
|
+}
|
|
397
|
+
|
|
398
|
+func GetSuperAdminUsersPurviewTreeAndUrlfors(appType int) ([]string, []*models.Purview, error) {
|
|
399
|
+ originPurviews, getPurviewErr := getAllOriginPurviews(appType)
|
|
400
|
+ if getPurviewErr != nil {
|
|
401
|
+ return nil, nil, getPurviewErr
|
|
402
|
+ }
|
|
403
|
+ urlfors, processedPurviews := getUrlforsAndProcessPurviews2Tree(originPurviews)
|
|
404
|
+ return urlfors, processedPurviews, nil
|
|
405
|
+}
|
|
406
|
+
|
|
407
|
+// 加工这些规则:树形化;以及从中取出不为空的 urlfor
|
|
408
|
+// 正确结果的前提是 originPurviews 以 parentid asc 排好序了的
|
|
409
|
+func getUrlforsAndProcessPurviews2Tree(originPurviews []*models.Purview) ([]string, []*models.Purview) {
|
|
410
|
+ processedPurviews := make([]*models.Purview, 0)
|
|
411
|
+ pid_childs := make(map[int][]*models.Purview)
|
|
412
|
+ urlfors := make([]string, 0, len(originPurviews))
|
|
413
|
+ for _, purview := range originPurviews {
|
|
414
|
+ if len(purview.Urlfor) != 0 {
|
|
415
|
+ urlfors = append(urlfors, purview.Urlfor)
|
|
416
|
+ }
|
|
417
|
+
|
|
418
|
+ // warning:下面这个算法只适用最多两层树形结构的菜单,对于两层以上的会丢失掉第三层及其以下的节点
|
|
419
|
+ // 因为取出 originPurviews 的时候已经排过序了,所以顶级节点肯定最先处理,不需要担心子节点比父节点先处理
|
|
420
|
+ if purview.Parentid == 0 {
|
|
421
|
+ processedPurviews = append(processedPurviews, purview)
|
|
422
|
+ } else {
|
|
423
|
+ childs := pid_childs[int(purview.Parentid)]
|
|
424
|
+ if pid_childs[int(purview.Parentid)] == nil {
|
|
425
|
+ childs = make([]*models.Purview, 0)
|
|
426
|
+ }
|
|
427
|
+ childs = append(childs, purview)
|
|
428
|
+ pid_childs[int(purview.Parentid)] = childs
|
|
429
|
+ }
|
|
430
|
+ }
|
|
431
|
+
|
|
432
|
+ for _, proPurview := range processedPurviews {
|
|
433
|
+ proPurview.Childs = pid_childs[int(proPurview.Id)]
|
|
434
|
+ }
|
|
435
|
+
|
|
436
|
+ return urlfors, processedPurviews
|
|
437
|
+}
|
|
438
|
+
|
|
439
|
+func getAllOriginPurviews(appType int) ([]*models.Purview, error) {
|
|
440
|
+ var purviews []*models.Purview
|
|
441
|
+ getPurviewErr := service.UserReadDB().Model(models.Purview{}).Where("module = ? AND status = 1", appType).Order("listorder asc").Order("id asc").Find(&purviews).Error
|
|
442
|
+ if getPurviewErr != nil {
|
|
443
|
+ if getPurviewErr == gorm.ErrRecordNotFound {
|
|
444
|
+ return nil, nil
|
|
445
|
+ } else {
|
|
446
|
+ return nil, getPurviewErr
|
|
447
|
+ }
|
|
448
|
+ }
|
|
449
|
+ return purviews, nil
|
|
450
|
+}
|
|
451
|
+
|
|
452
|
+func GetRolePurviewIds(roleID int64) (string, error) {
|
|
453
|
+ var rolePurview models.RolePurview
|
|
454
|
+ err := service.UserReadDB().Where("role_id = ?", roleID).First(&rolePurview).Error
|
|
455
|
+ if err != nil {
|
|
456
|
+ if err == gorm.ErrRecordNotFound {
|
|
457
|
+ return "", nil
|
|
458
|
+ } else {
|
|
459
|
+ return "", err
|
|
460
|
+ }
|
|
461
|
+ }
|
|
462
|
+ return rolePurview.PurviewIds, nil
|
|
463
|
+}
|
|
464
|
+
|
|
465
|
+func GetOrgSubscibe(org_id int64) (subscibe models.ServeSubscibe, err error) {
|
|
466
|
+ err = service.UserReadDB().Model(&models.ServeSubscibe{}).Where("org_id = ? AND status = 1", org_id).First(&subscibe).Error
|
|
467
|
+ return
|
|
468
|
+}
|