forked from free-lancers/electricity_bill_calc_service
new:新增withdraw请求,该暂无真实数据
This commit is contained in:
@@ -42,34 +42,35 @@ type _LoginForm struct {
|
||||
}
|
||||
|
||||
func doLogin(c *fiber.Ctx) error {
|
||||
result := response.NewResult(c)
|
||||
loginData := new(_LoginForm)
|
||||
if err := c.BodyParser(loginData); err != nil {
|
||||
result := response.NewResult(c) //创建一个相应结果对象
|
||||
loginData := new(_LoginForm) //创建一个解析登录表单数据的实体
|
||||
if err := c.BodyParser(loginData); err != nil { //解析请求体中的Json数据到loginData里,如果解析出错就返回错误
|
||||
userLog.Error("表单解析失败!", zap.Error(err))
|
||||
return result.Error(http.StatusInternalServerError, "表单解析失败。")
|
||||
return result.Error(http.StatusInternalServerError, "表单解析失败。") //返回一个内部服务器错误的相应结果
|
||||
}
|
||||
var (
|
||||
session *model.Session
|
||||
err error
|
||||
)
|
||||
userLog.Info("有用户请求登录。", zap.String("username", loginData.Username), zap.Int16("type", loginData.Type))
|
||||
if loginData.Type == model.USER_TYPE_ENT {
|
||||
session, err = service.UserService.ProcessEnterpriseUserLogin(loginData.Username, loginData.Password)
|
||||
userLog.Info("有用户请求登录。", zap.String("username", loginData.Username), zap.Int16("type", loginData.Type)) //记录日志相关信息
|
||||
if loginData.Type == model.USER_TYPE_ENT { //根据登录类型选择不同的处理方法
|
||||
session, err = service.UserService.ProcessEnterpriseUserLogin(loginData.Username, loginData.Password) //企业用户
|
||||
} else {
|
||||
session, err = service.UserService.ProcessManagementUserLogin(loginData.Username, loginData.Password)
|
||||
userLog.Info("该用户是管理用户")
|
||||
session, err = service.UserService.ProcessManagementUserLogin(loginData.Username, loginData.Password) //管理用户
|
||||
}
|
||||
if err != nil {
|
||||
if authError, ok := err.(*exceptions.AuthenticationError); ok {
|
||||
if authError.NeedReset {
|
||||
if authError, ok := err.(*exceptions.AuthenticationError); ok { //检查错误是否为身份验证错误
|
||||
if authError.NeedReset { //如果需要重置密码则返回对应结果
|
||||
return result.LoginNeedReset()
|
||||
}
|
||||
return result.Error(int(authError.Code), authError.Message)
|
||||
return result.Error(int(authError.Code), authError.Message) //返回身份验证错误相应
|
||||
} else {
|
||||
userLog.Error("用户登录请求处理失败!", zap.Error(err))
|
||||
return result.Error(http.StatusInternalServerError, err.Error())
|
||||
return result.Error(http.StatusInternalServerError, err.Error()) //返回内部服务器错误
|
||||
}
|
||||
}
|
||||
return result.LoginSuccess(session)
|
||||
return result.LoginSuccess(session) //返回登录成功相应结果,包含会话信息
|
||||
}
|
||||
|
||||
func doLogout(c *fiber.Ctx) error {
|
||||
|
74
controller/withdraw.go
Normal file
74
controller/withdraw.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/response"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var withdrawLog = logger.Named("Handler", "Withdraw")
|
||||
|
||||
func InitializeWithdrawHandlers(router *fiber.App) {
|
||||
router.Get("/withdraw", withdraw)
|
||||
}
|
||||
|
||||
//用于检索用户的核算报表
|
||||
func withdraw(c *fiber.Ctx) error {
|
||||
//记录日志
|
||||
withdrawLog.Info("带分页的待审核的核算撤回申请列表")
|
||||
//获取请求参数
|
||||
result := response.NewResult(c)
|
||||
keyword := c.Query("keyword", "")
|
||||
page := c.QueryInt("page", 1)
|
||||
withdrawLog.Info("参数为: ", zap.String("keyword", keyword), zap.Int("page", page))
|
||||
//中间数据库操作暂且省略。。。。
|
||||
//首先进行核算报表的分页查询
|
||||
|
||||
//TODO: 2023-07-18 此处的data需要经过上面数据库查询后进行数据返回,此处只是作于演示
|
||||
data := fiber.Map{
|
||||
"report": fiber.Map{
|
||||
"id": "string",
|
||||
"parkId": "string",
|
||||
"periodBegin": "string",
|
||||
"periodEnd": "string",
|
||||
"published": true,
|
||||
"publishedAt": "string",
|
||||
"withdraw": 0,
|
||||
"lastWithdrawAppliedAt": "string",
|
||||
"lastWithdrawAuditAt": "string",
|
||||
"status": 0,
|
||||
"message": "string",
|
||||
},
|
||||
"park": fiber.Map{
|
||||
"id": "string",
|
||||
"userId": "string",
|
||||
"name": "string",
|
||||
"tenement": "string",
|
||||
"area": "string",
|
||||
"capacity": "string",
|
||||
"category": 0,
|
||||
"meter04kvType": 0,
|
||||
"region": "string",
|
||||
"address": "string",
|
||||
"contact": "string",
|
||||
"phone": "string",
|
||||
},
|
||||
"user": fiber.Map{
|
||||
"id": "string",
|
||||
"name": "string",
|
||||
"contact": "string",
|
||||
"phone": "string",
|
||||
"region": "string",
|
||||
"address": "string",
|
||||
},
|
||||
}
|
||||
datas := make([]interface{}, 0)
|
||||
datas = append(datas, data)
|
||||
//TODO: 2023-07-18 此处返回值是个示例,具体返回值需要查询数据库
|
||||
return result.Success(
|
||||
"withdraw请求成功",
|
||||
response.NewPagedResponse(page, 20).ToMap(),
|
||||
fiber.Map{"records": datas},
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user