Skip to content

Commit

Permalink
Merge pull request #94 from zjutjh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
XiMo-210 authored Mar 2, 2025
2 parents 248950d + 25182ed commit 3db4083
Show file tree
Hide file tree
Showing 48 changed files with 1,029 additions and 575 deletions.
5 changes: 2 additions & 3 deletions app/apiException/apiException.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ var (
PwdError = NewError(http.StatusInternalServerError, 200511, "密码长度必须在6~20位之间")
ReactiveError = NewError(http.StatusInternalServerError, 200512, "该通行证已经存在,请重新输入")
StudentIdError = NewError(http.StatusInternalServerError, 200513, "学号格式不正确,请重新输入")
YxySessionExpired = NewError(http.StatusInternalServerError, 200514, "一卡通登陆过期,请稍后再试")
YxyNeedCaptcha = NewError(http.StatusInternalServerError, 200515, "请输入验证码")
WrongCaptcha = NewError(http.StatusInternalServerError, 200516, "图形验证码错误")
YxySessionExpired = NewError(http.StatusInternalServerError, 200514, "一卡通登陆过期,请重新登陆")
WrongPhoneNum = NewError(http.StatusInternalServerError, 200517, "手机号格式不正确")
ImgTypeError = NewError(http.StatusInternalServerError, 200518, "图片类型有误")
PersonalInfoNotFill = NewError(http.StatusInternalServerError, 200519, "请先填写个人基本信息")
Expand All @@ -38,6 +36,7 @@ var (
SendVerificationCodeLimit = NewError(http.StatusInternalServerError, 200524, "短信发送超限,请1分钟后再试")
CampusMismatch = NewError(http.StatusInternalServerError, 200525, "暂无该校区绑定信息")
OAuthNotUpdate = NewError(http.StatusInternalServerError, 200526, "统一身份认证密码未更新")
NoApiAvailable = NewError(http.StatusInternalServerError, 200527, "正方相关服务暂不可用")
NotInit = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound))
NotFound = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound))
Unknown = NewError(http.StatusInternalServerError, 300500, "系统异常,请稍后重试!")
Expand Down
6 changes: 0 additions & 6 deletions app/config/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const fileUrlKey = "fileUrlKey"

const registerTipsKey = "registerTipsKey"

const defaultThemeKey = "defaultThemeKey"

func GetSchoolBusUrl() string {
return getConfig(schoolBusUrlKey)
}
Expand Down Expand Up @@ -37,7 +35,3 @@ func SetFileUrlKey(url string) error {
func GetRegisterTipsKey() string { return getConfig(registerTipsKey) }

func SetRegisterTipsKey(url string) error { return setConfig(registerTipsKey, url) }

func GetDefaultThemeKey() string { return getConfig(defaultThemeKey) }

func SetDefaultThemeKey(url string) error { return setConfig(defaultThemeKey, url) }
6 changes: 1 addition & 5 deletions app/config/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const termStartDate = "termStartDate"
const scoreTermYearKey = "scoreTermYearKey"
const scoreTermKey = "scoreTermKey"

func SetSystemInfo(yearValue, termValue, termStartDateValue, scoreYearValue, scoreTermValue, jpgUrlValue, fileUrlValue, registerTipsValue, schoolBusUrlValue, defaultThemeValue string) error {
func SetSystemInfo(yearValue, termValue, termStartDateValue, scoreYearValue, scoreTermValue, jpgUrlValue, fileUrlValue, registerTipsValue, schoolBusUrlValue string) error {
err := setConfig(termYearKey, yearValue)
if err != nil {
return err
Expand Down Expand Up @@ -43,10 +43,6 @@ func SetSystemInfo(yearValue, termValue, termStartDateValue, scoreYearValue, sco
if err != nil {
return err
}
err = setConfig(defaultThemeKey, defaultThemeValue)
if err != nil {
return err
}
return err
}

Expand Down
3 changes: 1 addition & 2 deletions app/controllers/adminController/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type SystemInfoForm struct {
JpgUrlValue string `json:"jpgUrlValue"`
FileUrlValue string `json:"fileUrlValue"`
RegisterTips string `json:"registerTips"`
DefaultThemeValue string `json:"defaultThemeValue"`
}

type encryptForm struct {
Expand Down Expand Up @@ -72,7 +71,7 @@ func SetSystemInfo(c *gin.Context) {
return
}

err = config.SetSystemInfo(postForm.YearValue, postForm.TermValue, postForm.TermStartDateValue, postForm.ScoreYearValue, postForm.ScoreTermValue, postForm.JpgUrlValue, postForm.FileUrlValue, postForm.RegisterTips, postForm.SchoolBusUrlValue, postForm.DefaultThemeValue)
err = config.SetSystemInfo(postForm.YearValue, postForm.TermValue, postForm.TermStartDateValue, postForm.ScoreYearValue, postForm.ScoreTermValue, postForm.JpgUrlValue, postForm.FileUrlValue, postForm.RegisterTips, postForm.SchoolBusUrlValue)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand Down
44 changes: 16 additions & 28 deletions app/controllers/adminController/theme.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package adminController

import (
"github.com/gin-gonic/gin"
"wejh-go/app/apiException"
"wejh-go/app/models"
"wejh-go/app/services/themeServices"
"wejh-go/app/utils"

"github.com/gin-gonic/gin"
)

type CreateThemeData struct {
Name string `json:"name" binding:"required"`
Type string `json:"type" binding:"required"`
ThemeConfig string `json:"theme_config"`
ThemeName string `json:"theme_name" binding:"required"`
ThemeType string `json:"theme_type" binding:"required"`
IsDarkMode bool `json:"is_dark_mode"`
ThemeConfig models.ThemeConfig `json:"theme_config" binding:"required"`
}

// 管理员创建主题色
Expand All @@ -23,12 +25,7 @@ func CreateTheme(c *gin.Context) {
return
}

record := models.Theme{
Name: data.Name,
Type: data.Type,
ThemeConfig: data.ThemeConfig,
}
err = themeServices.CreateTheme(record)
err = themeServices.CreateTheme(data.ThemeName, data.ThemeType, data.IsDarkMode, data.ThemeConfig)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand All @@ -38,9 +35,10 @@ func CreateTheme(c *gin.Context) {
}

type UpdateThemeData struct {
ID int `json:"id" binding:"required"`
Name string `json:"name" binding:"required"`
ThemeConfig string `json:"theme_config" binding:"required"`
ThemeID int `json:"theme_id" binding:"required"`
ThemeName string `json:"theme_name" binding:"required"`
IsDarkMode bool `json:"is_dark_mode"`
ThemeConfig models.ThemeConfig `json:"theme_config" binding:"required"`
}

// 管理员更新主题色
Expand All @@ -52,11 +50,7 @@ func UpdateTheme(c *gin.Context) {
return
}

record := models.Theme{
Name: data.Name,
ThemeConfig: data.ThemeConfig,
}
err = themeServices.UpdateTheme(data.ID, record)
err = themeServices.UpdateTheme(data.ThemeID, data.ThemeName, data.IsDarkMode, data.ThemeConfig)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand All @@ -66,8 +60,8 @@ func UpdateTheme(c *gin.Context) {
}

// 管理员获取主题色列表
func GetThemes(c *gin.Context) {
themes, err := themeServices.GetThemes()
func GetAllTheme(c *gin.Context) {
themes, err := themeServices.GetAllTheme()
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand Down Expand Up @@ -103,7 +97,7 @@ func DeleteTheme(c *gin.Context) {
return
}

err = themeServices.DeleteTheme(data.ID, theme.Type)
err = themeServices.DeleteTheme(data.ID, theme.Type, theme.IsDarkMode)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand Down Expand Up @@ -161,13 +155,7 @@ func GetThemePermission(c *gin.Context) {
return
}

themePermission, err := themeServices.GetThemePermissionByStudentID(data.StudentID)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

themeNames, err := themeServices.GetThemeNameByID(themePermission)
themeNames, err := themeServices.GetPermittedThemeNames(data.StudentID)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand Down

This file was deleted.

17 changes: 10 additions & 7 deletions app/controllers/funcControllers/themeController/themeController.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package themeController

import (
"github.com/gin-gonic/gin"
"wejh-go/app/apiException"
"wejh-go/app/services/sessionServices"
"wejh-go/app/services/themeServices"
"wejh-go/app/utils"

"github.com/gin-gonic/gin"
)

func GetThemeList(c *gin.Context) {
Expand All @@ -21,20 +22,22 @@ func GetThemeList(c *gin.Context) {
return
}

themes, err := themeServices.GetThemesByID(themePermission)
themes, err := themeServices.GetPermittedThemeNames(user.StudentID)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

utils.JsonSuccessResponse(c, gin.H{
"theme_list": themes,
"current_theme_id": themePermission.CurrentThemeID,
"theme_list": themes,
"current_theme_id": themePermission.CurrentThemeID,
"current_theme_dark_id": themePermission.CurrentThemeDarkID,
})
}

type ChooseCurrentThemeData struct {
ID int `json:"id" binding:"required"`
ID int `json:"id"`
DarkID int `json:"dark_id"`
}

func ChooseCurrentTheme(c *gin.Context) {
Expand All @@ -51,13 +54,13 @@ func ChooseCurrentTheme(c *gin.Context) {
return
}

err = themeServices.CheckThemeExist(data.ID)
err = themeServices.CheckThemeExist(data.ID, data.DarkID)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

err = themeServices.UpdateCurrentTheme(data.ID, user.StudentID)
err = themeServices.UpdateCurrentTheme(data.ID, data.DarkID, user.StudentID)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand Down
56 changes: 16 additions & 40 deletions app/controllers/funcControllers/zfController/zfController.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"math/rand"
"time"
"wejh-go/app/apiException"
"wejh-go/app/models"
"wejh-go/app/services/funnelServices"
"wejh-go/app/services/sessionServices"
"wejh-go/app/services/userServices"
"wejh-go/app/utils"
"wejh-go/app/utils/circuitBreaker"
"wejh-go/config/redis"
)

Expand All @@ -34,15 +33,15 @@ func GetClassTable(c *gin.Context) {
return
}

loginType, err := genLoginType(user)
api, loginType, err := circuitBreaker.CB.GetApi(user.ZFPassword != "", user.OauthPassword != "")
if err != nil {
_ = c.AbortWithError(200, err)
return
}

result, err := funnelServices.GetClassTable(user, postForm.Year, postForm.Term, loginType)
result, err := funnelServices.GetClassTable(user, postForm.Year, postForm.Term, api, loginType)
if err != nil {
userServices.DelPassword(err, user, loginType)
userServices.DelPassword(err, user, string(loginType))
_ = c.AbortWithError(200, err)
return
}
Expand All @@ -63,15 +62,15 @@ func GetScore(c *gin.Context) {
return
}

loginType, err := genLoginType(user)
api, loginType, err := circuitBreaker.CB.GetApi(user.ZFPassword != "", user.OauthPassword != "")
if err != nil {
_ = c.AbortWithError(200, err)
return
}

result, err := funnelServices.GetScore(user, postForm.Year, postForm.Term, loginType)
result, err := funnelServices.GetScore(user, postForm.Year, postForm.Term, api, loginType)
if err != nil {
userServices.DelPassword(err, user, loginType)
userServices.DelPassword(err, user, string(loginType))
_ = c.AbortWithError(200, err)
return
}
Expand All @@ -92,15 +91,15 @@ func GetMidTermScore(c *gin.Context) {
return
}

loginType, err := genLoginType(user)
api, loginType, err := circuitBreaker.CB.GetApi(user.ZFPassword != "", user.OauthPassword != "")
if err != nil {
_ = c.AbortWithError(200, err)
return
}

result, err := funnelServices.GetMidTermScore(user, postForm.Year, postForm.Term, loginType)
result, err := funnelServices.GetMidTermScore(user, postForm.Year, postForm.Term, api, loginType)
if err != nil {
userServices.DelPassword(err, user, loginType)
userServices.DelPassword(err, user, string(loginType))
_ = c.AbortWithError(200, err)
return
}
Expand All @@ -121,15 +120,15 @@ func GetExam(c *gin.Context) {
return
}

loginType, err := genLoginType(user)
api, loginType, err := circuitBreaker.CB.GetApi(user.ZFPassword != "", user.OauthPassword != "")
if err != nil {
_ = c.AbortWithError(200, err)
return
}

result, err := funnelServices.GetExam(user, postForm.Year, postForm.Term, loginType)
result, err := funnelServices.GetExam(user, postForm.Year, postForm.Term, api, loginType)
if err != nil {
userServices.DelPassword(err, user, loginType)
userServices.DelPassword(err, user, string(loginType))
_ = c.AbortWithError(200, err)
return
}
Expand Down Expand Up @@ -159,7 +158,7 @@ func GetRoom(c *gin.Context) {
return
}

loginType, err := genLoginType(user)
api, loginType, err := circuitBreaker.CB.GetApi(user.ZFPassword != "", user.OauthPassword != "")
if err != nil {
_ = c.AbortWithError(200, err)
return
Expand All @@ -181,9 +180,9 @@ func GetRoom(c *gin.Context) {
}
}

result, err := funnelServices.GetRoom(user, postForm.Year, postForm.Term, postForm.Campus, postForm.Weekday, postForm.Week, postForm.Sections, loginType)
result, err := funnelServices.GetRoom(user, postForm.Year, postForm.Term, postForm.Campus, postForm.Weekday, postForm.Week, postForm.Sections, api, loginType)
if err != nil {
userServices.DelPassword(err, user, loginType)
userServices.DelPassword(err, user, string(loginType))
_ = c.AbortWithError(200, err)
return
}
Expand All @@ -198,26 +197,3 @@ func GetRoom(c *gin.Context) {
}
utils.JsonSuccessResponse(c, result)
}

func genLoginType(u *models.User) (string, error) {
var loginType string
rand.Seed(time.Now().UnixNano())
oauthVal := rand.Intn(40)
zfVal := rand.Intn(60)

if u.OauthPassword != "" && u.ZFPassword != "" {
if oauthVal > zfVal {
loginType = "OAUTH"
} else {
loginType = "ZF"
}
} else if u.OauthPassword != "" {
loginType = "OAUTH"
} else if u.ZFPassword != "" {
loginType = "ZF"
} else {
return "", apiException.NoThatPasswordOrWrong
}

return loginType, nil
}
Loading

0 comments on commit 3db4083

Please sign in to comment.