正在显示
3 个修改的文件
包含
164 行增加
和
0 行删除
pkg/pushdata/api.go
0 → 100644
1 | +package pushdata | ||
2 | + | ||
3 | +type FieldName struct { | ||
4 | + Name string `json:"name"` | ||
5 | +} | ||
6 | + | ||
7 | +type RespData struct { | ||
8 | + Code int `json:"code"` | ||
9 | +} | ||
10 | + | ||
11 | +func (resp *RespData) IsOk() bool { | ||
12 | + return resp.Code == 0 | ||
13 | +} | ||
14 | + | ||
15 | +type ReqCreateTable struct { | ||
16 | + Name string `json:"name"` | ||
17 | + Fields []FieldName `json:"fields"` | ||
18 | + Data []map[string]string `json:"data"` | ||
19 | +} | ||
20 | + | ||
21 | +type ReqAppendData struct { | ||
22 | + Name string `json:"name"` | ||
23 | + Fields []FieldName `json:"fields"` | ||
24 | + Data []map[string]string `json:"data"` | ||
25 | +} | ||
26 | + | ||
27 | +type AppTable interface { | ||
28 | + AppTableName() string // 应用表名称 | ||
29 | + AppTableField() []FieldName // 应用字段 | ||
30 | +} | ||
31 | + | ||
32 | +type GenData interface { | ||
33 | + DataForAppend() (ReqAppendData, error) //生成需要追加的数据 | ||
34 | +} | ||
35 | + | ||
36 | +type AppTableFile interface { | ||
37 | + AppTable | ||
38 | + GenData | ||
39 | +} | ||
40 | + | ||
41 | +type Client struct { | ||
42 | + entry []AppTableFile | ||
43 | + host string | ||
44 | +} | ||
45 | + | ||
46 | +// RegistEntry 注册数据推送项 | ||
47 | +func (c *Client) RegistEntry(item AppTableFile) { | ||
48 | + c.entry = append(c.entry, item) | ||
49 | +} | ||
50 | + | ||
51 | +// CreateTable 创建应用表 | ||
52 | +func (c *Client) CreateTable() { | ||
53 | + | ||
54 | +} | ||
55 | + | ||
56 | +// AppendData 追加应用表数据 | ||
57 | +func (c *Client) AppendData() { | ||
58 | + | ||
59 | +} |
pkg/pushdata/common.go
0 → 100644
pkg/pushdata/staff_assess.go
0 → 100644
1 | +package pushdata | ||
2 | + | ||
3 | +import ( | ||
4 | + "time" | ||
5 | +) | ||
6 | + | ||
7 | +type StaffAssessItem struct { | ||
8 | + TargetUser string `pg:"target_user"` //评估的目标人员 | ||
9 | + TargetUserAccount string `pg:"target_user_account"` //目标人员账号 | ||
10 | + ItemCategory string `pg:"item_category"` //分类 | ||
11 | + ItemName string `pg:"item_name"` //名称 | ||
12 | + ItemValue string `pg:"item_value"` //评分填写的值 | ||
13 | + ItemWeight string `pg:"item_weight"` //评分权重 | ||
14 | + BeginDay string `pg:"begin_day"` //日期 | ||
15 | + ProjectName string `pg:"project_name"` //项目名称 | ||
16 | + ProjectId string `pg:"project_id"` //项目id | ||
17 | + CycleId string `pg:"cycle_id"` //周期id | ||
18 | + CycleName string `pg:"cycle_name"` //周期名称 | ||
19 | +} | ||
20 | + | ||
21 | +func (t *StaffAssessItem) AppTableName() string { | ||
22 | + return "每日绩效评估" | ||
23 | +} | ||
24 | + | ||
25 | +func (t *StaffAssessItem) AppTableField() []FieldName { | ||
26 | + return []FieldName{ | ||
27 | + {Name: "用户姓名"}, | ||
28 | + {Name: "手机号"}, | ||
29 | + {Name: "分类"}, | ||
30 | + {Name: "名称"}, | ||
31 | + {Name: "评分"}, | ||
32 | + {Name: "权重"}, | ||
33 | + {Name: "评估日期"}, | ||
34 | + {Name: "项目ID"}, | ||
35 | + {Name: "项目名称"}, | ||
36 | + {Name: "周期ID"}, | ||
37 | + {Name: "周期"}, | ||
38 | + } | ||
39 | +} | ||
40 | + | ||
41 | +func (t *StaffAssessItem) MapData() (data map[string]string) { | ||
42 | + data = map[string]string{ | ||
43 | + "用户姓名": t.TargetUser, | ||
44 | + "手机号": t.TargetUserAccount, | ||
45 | + "分类": t.ItemCategory, | ||
46 | + "名称": t.ItemName, | ||
47 | + "评分": t.ItemValue, | ||
48 | + "权重": t.ItemWeight, | ||
49 | + "评估日期": t.BeginDay, | ||
50 | + "项目ID": t.ProjectId, | ||
51 | + "项目名称": t.ProjectName, | ||
52 | + "周期ID": t.CycleId, | ||
53 | + "周期名称": t.CycleName, | ||
54 | + } | ||
55 | + return | ||
56 | +} | ||
57 | + | ||
58 | +func (t *StaffAssessItem) DataForAppend() (data ReqAppendData, err error) { | ||
59 | + sqlStr := `select | ||
60 | + staff_assess.target_user ->>'account' as target_user_account, | ||
61 | + staff_assess.target_user ->>'userName' as target_user, | ||
62 | + to_char(staff_assess.begin_time at time zone 'PRC','YYYY-MM-DD') as begin_day, | ||
63 | + staff_assess.evaluation_project_id as project_id, | ||
64 | + staff_assess.evaluation_project_name as project_name, | ||
65 | + staff_assess.cycle_id , | ||
66 | + staff_assess.cycle_name , | ||
67 | + staff_assess_content.category item_category , | ||
68 | + staff_assess_content.value as item_value, | ||
69 | + staff_assess_content."name" as item_name, | ||
70 | + staff_assess_content.weight as item_weight | ||
71 | + from staff_assess | ||
72 | + join staff_assess_content on staff_assess.id =staff_assess_content.staff_assess_id | ||
73 | + where 1=1 | ||
74 | + and staff_assess.end_time between to_timestamp(?) and to_timestamp(?) ` | ||
75 | + nowTime := time.Now() | ||
76 | + yesterday := nowTime.AddDate(0, 0, -1) | ||
77 | + y, m, d := yesterday.Local().Date() | ||
78 | + yesterdayZero := time.Date(y, m, d, 0, 0, 0, 0, time.Local) | ||
79 | + yesterdayEnd := time.Date(y, m, d, 23, 59, 59, 0, time.Local) | ||
80 | + db := getDB() | ||
81 | + dataList := []StaffAssessItem{} | ||
82 | + _, err = db.Query(&dataList, sqlStr, yesterdayZero.Unix(), yesterdayEnd.Unix()) | ||
83 | + if len(dataList) == 0 { | ||
84 | + return | ||
85 | + } | ||
86 | + data = ReqAppendData{ | ||
87 | + Name: dataList[0].AppTableName(), | ||
88 | + Fields: dataList[0].AppTableField(), | ||
89 | + Data: make([]map[string]string, len(dataList)), | ||
90 | + } | ||
91 | + for i := range dataList { | ||
92 | + data.Data = append(data.Data, dataList[i].MapData()) | ||
93 | + } | ||
94 | + return | ||
95 | +} |
-
请 注册 或 登录 后发表评论