Skip to content

Commit 164a424

Browse files
committed
chore:update sth
1 parent c1c5880 commit 164a424

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

pkg/base/context/login_data.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ func ExtractIDFromLoginData(data *model.LoginData) string {
6565
// 研究生:id直接是stuId,以 00000 为前缀(可能是 9 或 10 位)
6666
// 本科生:identifier 末尾为学号,按入学年份判断是 9 位还是 10 位
6767
// 2026年开始本科生学号由9位变到10位
68-
// 本科生identifier规则:yyyymmdd + hhmmss + 学号,长度不定
69-
// 比如2026年8月5日,开头就是202685,12月17日就是20261217
70-
// 时间也是一样,24小时制,当日1时50分07秒就是1507,10时0分0秒就是1000,12时37分59秒就是123759
68+
// 本科生identifier规则:请求时间 yyyymmdd + hhmmss + 学号,长度不定
69+
// 比如请求时间在2026年8月5日,开头就是202685,12月17日就是20261217
70+
// 时间也是一样,24小时制,当日1时50分7秒就是1507,10时0分0秒就是1000,12时37分59秒就是123759
7171
func ExtractIDFromIdentifier(id string) string {
7272
if len(id) < constants.StudentIDLength {
7373
return ""

pkg/base/context/login_data_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func TestExtractIDFromIdentifier(t *testing.T) {
4343
},
4444
{
4545
name: "本科生-10位学号",
46-
id: "202685148141026012345",
47-
want: "1026012345",
46+
id: "202685148140102612345",
47+
want: "0102612345",
4848
},
4949
{
5050
name: "过短",

pkg/constants/jwch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ const (
2626
// 2026年(含)起入学的新生学号由9位变为10位。
2727
// 学号第3-4位为入学年份(如 22/25/26),年份 >= StudentIDYearThreshold 时为10位新学号。
2828
StudentIDLengthNew = 10
29-
StudentIDYearThreshold = "26"
29+
StudentIDYearThreshold = 26
3030
)

pkg/utils/id.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package utils
1818

1919
import (
20+
"strconv"
2021
"strings"
2122

2223
"github.com/west2-online/fzuhelper-server/pkg/constants"
@@ -47,7 +48,8 @@ func RemoveUndergraduatePrefix(id string) string {
4748
// 先取后9位,其第3-4位为入学年份
4849
last9 := id[len(id)-constants.StudentIDLength:]
4950
// 年份 >= 26(2026年起入学)为10位新学号,取后10位
50-
if len(id) >= constants.StudentIDLengthNew && last9[2:4] >= constants.StudentIDYearThreshold {
51+
year, err := strconv.Atoi(last9[2:4])
52+
if err == nil && len(id) >= constants.StudentIDLengthNew && year >= constants.StudentIDYearThreshold {
5153
return id[len(id)-constants.StudentIDLengthNew:]
5254
}
5355
return last9

0 commit comments

Comments
 (0)