zjxpcyc hace 6 años
padre
commit
d078297911

+ 6
- 0
models/constant.go Ver fichero

@@ -131,3 +131,9 @@ const (
131 131
 	SYS_RESOURCE_COURSE = "course"
132 132
 	SYS_RESOURCE_GOODS  = "goods"
133 133
 )
134
+
135
+// dashboard 配置的使用者类型
136
+const (
137
+	DASH_SETTING_FOR_USER     = "user"
138
+	DASH_SETTING_FOR_USERTYPE = "user-type"
139
+)

+ 10
- 0
models/model/ta_dashboard_setting.go Ver fichero

@@ -0,0 +1,10 @@
1
+package model
2
+
3
+type TaDashboardSetting struct {
4
+	SettingId   string `xorm:"not null pk VARCHAR(64)"`
5
+	SettingName string `xorm:"VARCHAR(255)"`
6
+	CompList    string `xorm:"TEXT"`
7
+	Owner       string `xorm:"VARCHAR(64)"`
8
+	ForType     string `xorm:"VARCHAR(100)"`
9
+	Status      int    `xorm:"SMALLINT(6)"`
10
+}

+ 45
- 0
models/statistics/other.go Ver fichero

@@ -0,0 +1,45 @@
1
+package statistics
2
+
3
+import (
4
+	"spaceofcheng/services/models"
5
+	"spaceofcheng/services/models/model"
6
+	"strings"
7
+)
8
+
9
+// GetUserTypes 获取人员类型
10
+func (m *StatisticsDAO) GetUserTypes(id string) ([]model.SysUserType, error) {
11
+	if id == "" {
12
+		return nil, nil
13
+	}
14
+
15
+	var tps []model.SysUserType
16
+	if err := m.db.Where("user_id=?", id).Find(&tps); err != nil {
17
+		return nil, err
18
+	}
19
+
20
+	return tps, nil
21
+}
22
+
23
+// GetDashboardSetting 获取人员 dashboard 设置
24
+func (m *StatisticsDAO) GetDashboardSetting(userID string, userTypes []string) ([]model.TaDashboardSetting, error) {
25
+	filters := make([]string, 0)
26
+	if userID != "" {
27
+		filters = append(filters, "(for_type='"+models.DASH_SETTING_FOR_USER+"' AND owner='"+userID+"')")
28
+	}
29
+
30
+	if userTypes != nil {
31
+		filters = append(filters, "(for_type='"+models.DASH_SETTING_FOR_USERTYPE+"' AND owner in ('"+strings.Join(userTypes, "','")+"'))")
32
+	}
33
+
34
+	if len(filters) == 0 {
35
+		return nil, nil
36
+	}
37
+
38
+	var settings []model.TaDashboardSetting
39
+	query := `select * from ta_dashboard_setting where (` + strings.Join(filters, " OR ") + ") AND status = ?"
40
+	if err := m.db.SQL(query, models.STATUS_NORMAL).Find(&settings); err != nil {
41
+		return nil, err
42
+	}
43
+
44
+	return settings, nil
45
+}

+ 37
- 0
service/statistics/dashboard.go Ver fichero

@@ -0,0 +1,37 @@
1
+package statistics
2
+
3
+// import (
4
+// 	"spaceofcheng/services/models/model"
5
+// 	"spaceofcheng/services/utils"
6
+// 	"strings"
7
+// )
8
+
9
+// // StaDashboard 控制板统计
10
+// func (s *StatisticsServ) StaDashboard() error {
11
+// 	user := s.ctx.Get("user").(model.SysUser)
12
+
13
+// }
14
+
15
+// // distinctDashSettings 去重 dashboard 配置
16
+// func (s *StatisticsServ) distinctDashSettings(settings []model.TaDashboardSetting) []string {
17
+// 	comps := make([]string, 0)
18
+
19
+// 	if settings == nil || len(settings) == 0 {
20
+// 		return comps
21
+// 	}
22
+
23
+// 	for _, s := range settings {
24
+// 		comps = append(comps, s.CompList)
25
+// 	}
26
+
27
+// 	allComps := strings.Split(strings.Join(comps, ","), ",")
28
+
29
+// 	res := make([]string, 0)
30
+// 	for _, cmp := range allComps {
31
+// 		if utils.StrSliceIndexOf(res, cmp) == -1 {
32
+// 			res = append(res, cmp)
33
+// 		}
34
+// 	}
35
+
36
+// 	return res
37
+// }

+ 6
- 0
service/statistics/setting.go Ver fichero

@@ -0,0 +1,6 @@
1
+package statistics
2
+
3
+// StaticMapFrontComponent 每种统计映射的前端组件名称
4
+var StaticMapFrontComponent = map[string]string{
5
+	"": "",
6
+}

+ 20
- 0
service/statistics/statistics.go Ver fichero

@@ -0,0 +1,20 @@
1
+package statistics
2
+
3
+import (
4
+	"spaceofcheng/services/models/statistics"
5
+	"spaceofcheng/services/utils"
6
+)
7
+
8
+// StatisticsServ 系统处理
9
+type StatisticsServ struct {
10
+	ctx *utils.Context
11
+	dao *statistics.StatisticsDAO
12
+}
13
+
14
+// NewStatisticsServ 初始化
15
+func NewStatisticsServ(ctx *utils.Context) *StatisticsServ {
16
+	return &StatisticsServ{
17
+		ctx: ctx,
18
+		dao: statistics.NewStatisticsDAO(ctx),
19
+	}
20
+}