Skip to content

Commit

Permalink
refactor: 重构图书馆登陆接口, 当前/历史借书记录接口, 将续借接口标记为未上架
Browse files Browse the repository at this point in the history
refactor: 重构图书馆登陆接口, 当前/历史借书记录接口, 将续借接口标记为未上架

refactor: 重构图书馆登陆接口, 当前/历史借书记录接口, 将续借接口标记为未上架

refactor: 重构图书馆登陆接口, 当前/历史借书记录接口, 将续借接口标记为未上架
  • Loading branch information
MangoGovo committed Nov 15, 2024
1 parent 4047b10 commit 4fa9b24
Show file tree
Hide file tree
Showing 17 changed files with 557 additions and 537 deletions.
20 changes: 15 additions & 5 deletions app/apis/library/libraryApi.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package library

import "funnel/app/apis"
// OAuth
const (
OAuthChaoXingInit = "https://tyrzfw.chaoxing.com/auth3/zjut/cas/init?isLogout=0&refer=https://opac.lib.zjut.edu.cn:8013/find/sso/login/zjut/0"
OAuthBaseUrl = "https://oauth.zjut.edu.cn/cas"
OAuthPublicKey = OAuthBaseUrl + "/v2/getPubKey"
OAuthLogin = OAuthBaseUrl + "/login"
)

var LibraryLogin = apis.LIBRARY_URL + "login.aspx"
// Library
const (
LoginFromOAuth = OAuthLogin + "?service=http://tyrzfw.chaoxing.com/auth3/zjut/cas/index"

var LibraryBorrowHistory = apis.LIBRARY_URL + "BorrowHistory.aspx"

var LibraryBorrowing = apis.LIBRARY_URL + "Borrowing.aspx"
BaseUrl = "https://opac.lib.zjut.edu.cn:8013"
CurrentLoanList = BaseUrl + "/find/loanInfo/loanList"
BorrowHistoryList = BaseUrl + "/find/loanInfo/loanHistoryList"
UserInfo = BaseUrl + "/oga/userinfo"
)
2 changes: 1 addition & 1 deletion app/apis/rootUrls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
//
//var CANTEEN_URL = os.Getenv("CANTEEN_URL")

var LIBRARY_URL string = config.Config.GetString("library")
//var LIBRARY_URL string = config.Config.GetString("library")

var CAPTCHA_BREAKER_URL string = config.Config.GetString("captcha.breaker_url")
var CAPTCHA_NEW_BREAKER_URL string = config.Config.GetString("captcha.new_breaker_url")
Expand Down
29 changes: 29 additions & 0 deletions app/controller/libraryController/borrowHistory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package libraryController

import (
"funnel/app/controller"
"funnel/app/service/libraryService"
"funnel/app/utils"
"github.com/gin-gonic/gin"
)

type borrowHistoryData struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Page int `json:"page" default:"1"`
}

// LibraryBorrowHistory 图书馆历史借书记录
func LibraryBorrowHistory(c *gin.Context) {
var data borrowHistoryData
if err := c.ShouldBind(&data); err != nil {
controller.ErrorHandle(c, err)
return
}
currentBorrow, err := libraryService.GetBorrowHistory(data.Username, data.Password, data.Page)
if err != nil {
controller.ErrorHandle(c, err)
return
}
utils.ContextDataResponseJson(c, utils.SuccessResponseJson(currentBorrow))
}
29 changes: 29 additions & 0 deletions app/controller/libraryController/currentBorrow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package libraryController

import (
"funnel/app/controller"
"funnel/app/service/libraryService"
"funnel/app/utils"
"github.com/gin-gonic/gin"
)

type currentBorrowData struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Page int `json:"page" default:"1"`
}

// LibraryCurrentBorrow 图书馆当前借书记录
func LibraryCurrentBorrow(c *gin.Context) {
var data currentBorrowData
if err := c.ShouldBind(&data); err != nil {
controller.ErrorHandle(c, err)
return
}
currentBorrow, err := libraryService.GetCurrentBorrow(data.Username, data.Password, data.Page)
if err != nil {
controller.ErrorHandle(c, err)
return
}
utils.ContextDataResponseJson(c, utils.SuccessResponseJson(currentBorrow))
}
115 changes: 0 additions & 115 deletions app/controller/libraryController/libraryController.go

This file was deleted.

14 changes: 14 additions & 0 deletions app/controller/libraryController/reBorrow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package libraryController

import (
"funnel/app/utils"
"github.com/gin-gonic/gin"
)

func LibraryReBorrow(c *gin.Context) {
utils.ContextDataResponseJson(c, utils.ResponseJsonMessage{
Code: 500,
Message: "功能仍未上架,敬请期待",
Data: interface{}(nil),
})
}
29 changes: 29 additions & 0 deletions app/service/libraryService/borrowHistory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package libraryService

import (
"funnel/app/apis/library"
"github.com/go-resty/resty/v2"
)

// GetBorrowHistory 获取图书馆当前借书记录
func GetBorrowHistory(username string, password string, page int) (interface{}, error) {
var ret Result
cookies, err := OAuthLogin(username, password)
if err != nil {
return nil, err
}
client := resty.New()
_, err = client.R().
SetBody(map[string]interface{}{
"page": page,
"rows": 10,
"searchType": 1,
"searchContent": "",
"sortType": 0,
"startDate": nil,
"endDate": nil}).
SetCookies(cookies).
SetResult(&ret).
Post(library.BorrowHistoryList)
return ret.Data, nil
}
29 changes: 29 additions & 0 deletions app/service/libraryService/currentBorrow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package libraryService

import (
"funnel/app/apis/library"
"github.com/go-resty/resty/v2"
)

// GetCurrentBorrow 获取图书馆当前借书记录
func GetCurrentBorrow(username string, password string, page int) (interface{}, error) {
var ret Result
cookies, err := OAuthLogin(username, password)
if err != nil {
return nil, err
}
client := resty.New()
_, err = client.R().
SetBody(map[string]interface{}{
"page": page,
"rows": 10,
"searchType": 1,
"searchContent": "",
"sortType": 0,
"startDate": nil,
"endDate": nil}).
SetCookies(cookies).
SetResult(&ret).
Post(library.CurrentLoanList)
return ret.Data, nil
}
Loading

0 comments on commit 4fa9b24

Please sign in to comment.