Skip to content

Commit

Permalink
feat:完成正装(物资)借用功能的开发
Browse files Browse the repository at this point in the history
  • Loading branch information
XiMo-210 committed Feb 25, 2024
1 parent 3048c11 commit fffbbcb
Show file tree
Hide file tree
Showing 20 changed files with 2,251 additions and 18 deletions.
6 changes: 5 additions & 1 deletion app/apiException/apiException.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ var (
ReactiveError = NewError(http.StatusInternalServerError, 200512, "该通行证已经存在,请重新输入")
StudentIdError = NewError(http.StatusInternalServerError, 200513, "学号格式不正确,请重新输入")
YxySessionExpired = NewError(http.StatusInternalServerError, 200514, "一卡通登陆过期,请稍后再试")
YxyNeedCaptcha = NewError(http.StatusInternalServerError, 500515, "请输入验证码")
YxyNeedCaptcha = NewError(http.StatusInternalServerError, 200515, "请输入验证码")
WrongCaptcha = NewError(http.StatusInternalServerError, 200516, "图形验证码错误")
WrongPhoneNum = NewError(http.StatusInternalServerError, 200517, "手机号格式不正确")
ImgTypeError = NewError(http.StatusInternalServerError, 200518, "图片类型有误")
PersonalInfoNotFill = NewError(http.StatusInternalServerError, 200519, "请先填写个人基本信息")
StockNotEnough = NewError(http.StatusInternalServerError, 200520, "物资库存不足")
RecordAlreadyExisted = NewError(http.StatusInternalServerError, 200521, "该用户已经申请过该物资")
RecordRejected = NewError(http.StatusInternalServerError, 200522, "该申请已经被驳回")
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
10 changes: 10 additions & 0 deletions app/config/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const schoolBusUrlKey = "schoolBusUrlKey"

const webpUrlKey = "jpgUrlKey"

const fileUrlKey = "fileUrlKey"

func GetSchoolBusUrl() string {
return getConfig(schoolBusUrlKey)
}
Expand All @@ -19,3 +21,11 @@ func GetWebpUrlKey() string {
func SetWebpUrlKey(url string) error {
return setConfig(webpUrlKey, url)
}

func GetFileUrlKey() string {
return getConfig(fileUrlKey)
}

func SetFileUrlKey(url string) error {
return setConfig(fileUrlKey, url)
}
185 changes: 185 additions & 0 deletions app/controllers/funcControllers/suppliesController/QA.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package suppliesController

import (
"time"
"wejh-go/app/apiException"
"wejh-go/app/models"
"wejh-go/app/services/sessionServices"
"wejh-go/app/services/suppliesServices"
"wejh-go/app/utils"

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

type CreateQAData struct {
Title string `json:"title" binding:"required"`
Content string `json:"content" binding:"required"`
}

// 创建 QA
func CreateQA(c *gin.Context) {
var data CreateQAData
err := c.ShouldBindJSON(&data)
if err != nil {
_ = c.AbortWithError(200, apiException.ParamError)
return
}

publisher := getIdentity(c)
err = suppliesServices.CreateQA(models.QA{
Title: data.Title,
Content: data.Content,
PublishTime: time.Now(),
Publisher: *publisher,
})

if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

utils.JsonSuccessResponse(c, nil)
}

type GetQAListData struct {
Publisher string `form:"publisher" binding:"required"`
}

// 用户获取对应发布方的 QA
func GetQAList(c *gin.Context) {
var data GetQAListData
err := c.ShouldBindQuery(&data)
if err != nil {
_ = c.AbortWithError(200, apiException.ParamError)
return
}

var QAList []models.QA
QAList, err = suppliesServices.GetQAListByPublisher(data.Publisher)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

utils.JsonSuccessResponse(c, QAList)
}

// 管理员获取自己发布的 QA
func GetQAListByAdmin(c *gin.Context) {
admin := getIdentity(c)

var QAList []models.QA
var err error
if *admin == "Admin" {
QAList, err = suppliesServices.GetQAListBySuperAdmin()
} else {
QAList, err = suppliesServices.GetQAListByPublisher(*admin)
}

if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

utils.JsonSuccessResponse(c, QAList)
}

type UpdateQAData struct {
ID int `json:"id" binding:"required"`
Title string `json:"title" binding:"required"`
Content string `json:"content" binding:"required"`
}

// 更新 QA
func UpdateQA(c *gin.Context) {
var data UpdateQAData
err := c.ShouldBindJSON(&data)
if err != nil {
_ = c.AbortWithError(200, apiException.ParamError)
return
}

pubisher := getIdentity(c)

var QA *models.QA
QA, err = suppliesServices.GetQAbyID(data.ID)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

if QA.Publisher != *pubisher && *pubisher != "Admin" {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

err = suppliesServices.UpdateQA(models.QA{
ID: data.ID,
Title: data.Title,
Content: data.Content,
PublishTime: time.Now(),
})
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

utils.JsonSuccessResponse(c, nil)
}

type DeleteQAData struct {
ID int `form:"id" binding:"required"`
}

// 删除 QA
func DeleteQA(c *gin.Context) {
var data DeleteQAData
err := c.ShouldBindQuery(&data)
if err != nil {
_ = c.AbortWithError(200, apiException.ParamError)
return
}

pubisher := getIdentity(c)

var QA *models.QA
QA, err = suppliesServices.GetQAbyID(data.ID)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

if QA.Publisher != *pubisher && *pubisher != "Admin" {
c.AbortWithError(200, apiException.ServerError)
return
}

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

utils.JsonSuccessResponse(c, nil)
}

// 获取身份
func getIdentity(c *gin.Context) *string {
user, err := sessionServices.GetUserSession(c)
if err != nil {
_ = c.AbortWithError(200, apiException.NotLogin)
return nil
}

var identity string
if user.Type == models.StudentAffairsCenter {
identity = "学生事务大厅"
} else if user.Type == models.Admin {
identity = "Admin"
} else {
_ = c.AbortWithError(200, apiException.ServerError)
return nil
}

return &identity
}
Loading

0 comments on commit fffbbcb

Please sign in to comment.