@@ -24,11 +24,26 @@ import (
2424 "github.com/west2-online/jwch"
2525)
2626
27+ // CreditDetail 用于表示学分的详细数据项
28+ type CreditDetail struct {
29+ Key string `json:"key"`
30+ Value string `json:"value"`
31+ }
32+
33+ // CreditCategory 用于表示学分分类
34+ type CreditCategory struct {
35+ Type string `json:"type"`
36+ Data []* CreditDetail `json:"data"`
37+ }
38+
39+ // CreditResponse 用于学分响应
40+ type CreditResponse []* CreditCategory
41+
2742// BuildCreditCategory 格式化处理学分统计
28- func BuildCreditCategory (categoryType string , credits []* jwch.CreditStatistics ) * jwch. CreditCategory {
29- category := & jwch. CreditCategory {
43+ func BuildCreditCategory (categoryType string , credits []* jwch.CreditStatistics ) * CreditCategory {
44+ category := & CreditCategory {
3045 Type : categoryType ,
31- Data : make ([]* jwch. CreditDetail , 0 , len (credits )),
46+ Data : make ([]* CreditDetail , 0 , len (credits )),
3247 }
3348
3449 // 用于计算"总计"栏的还需学分总和
@@ -52,12 +67,12 @@ func BuildCreditCategory(categoryType string, credits []*jwch.CreditStatistics)
5267 total , _ := strconv .ParseFloat (credit .Total , 64 )
5368 value := fmt .Sprintf ("%g / %g (还需 %g 分)" , gain , total , totalNeed )
5469
55- category .Data = append (category .Data , & jwch. CreditDetail {
70+ category .Data = append (category .Data , & CreditDetail {
5671 Key : credit .Type ,
5772 Value : value ,
5873 })
5974 case isSpecial :
60- category .Data = append (category .Data , & jwch. CreditDetail {
75+ category .Data = append (category .Data , & CreditDetail {
6176 Key : credit .Type ,
6277 Value : credit .Gain ,
6378 })
@@ -75,11 +90,11 @@ func BuildCreditCategory(categoryType string, credits []*jwch.CreditStatistics)
7590 totalNeed += need
7691 }
7792
78- category .Data = append (category .Data , & jwch. CreditDetail {
93+ category .Data = append (category .Data , & CreditDetail {
7994 Key : credit .Type ,
8095 Value : value ,
8196 })
8297 }
8398 }
8499 return category
85- }
100+ }
0 commit comments