128 lines
4.2 KiB
Go
128 lines
4.2 KiB
Go
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/sirupsen/logrus"
|
|
"net/http"
|
|
"psi/constant"
|
|
"psi/database"
|
|
systemReq "psi/models/request"
|
|
systemRes "psi/models/response"
|
|
"psi/service"
|
|
"psi/utils"
|
|
)
|
|
|
|
type SplitAccountDeductionLogApi struct{}
|
|
|
|
var splitAccountDeductionLogService = service.SplitAccountDeductionLogService{}
|
|
|
|
// GetSplitAccountDeductionLogList 获取分账扣钱日志列表
|
|
func (r *SplitAccountDeductionLogApi) GetSplitAccountDeductionLogList(c *gin.Context) {
|
|
var req systemReq.GetSplitAccountDeductionLogListRequest
|
|
|
|
if err := c.ShouldBindQuery(&req); err != nil {
|
|
ValidAndFail(constant.LoggerChannelRequest, "分账扣钱日志列表请求参数异常", "参数错误: "+err.Error(), c, err)
|
|
return
|
|
}
|
|
|
|
result, err := splitAccountDeductionLogService.GetSplitAccountDeductionLogList(req, database.GetDB(c))
|
|
if err != nil {
|
|
utils.FailWithRequestLog(constant.LoggerChannelWork, "分账扣钱日志列表异常", err, c, req)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 200,
|
|
"data": result,
|
|
})
|
|
}
|
|
|
|
// GetSplitAccountDeductionLogDetail 获取分账扣钱日志详情
|
|
func (r *SplitAccountDeductionLogApi) GetSplitAccountDeductionLogDetail(c *gin.Context) {
|
|
idStr := c.Param("id")
|
|
|
|
if idStr == "" {
|
|
utils.ErrorLog(constant.LoggerChannelRequest, logrus.Fields{
|
|
"source": "获取分账扣钱日志详情请求参数异常",
|
|
"err_msg": "ID参数不能为空",
|
|
})
|
|
systemRes.FailWithValidateMessage("参数错误: ID不能为空", c)
|
|
return
|
|
}
|
|
|
|
var id int64
|
|
if _, err := fmt.Sscanf(idStr, "%d", &id); err != nil || id <= 0 {
|
|
utils.ErrorLog(constant.LoggerChannelRequest, logrus.Fields{
|
|
"source": "获取分账扣钱日志详情请求参数异常",
|
|
"err_msg": "ID格式错误: " + idStr,
|
|
})
|
|
systemRes.FailWithValidateMessage("参数错误: ID格式不正确", c)
|
|
return
|
|
}
|
|
|
|
result, err := splitAccountDeductionLogService.GetSplitAccountDeductionLogDetail(id, database.GetDB(c))
|
|
if err != nil {
|
|
utils.FailWithRequestLog(constant.LoggerChannelWork, "分账扣钱日志详情异常", err, c, gin.H{"id": id})
|
|
return
|
|
}
|
|
|
|
systemRes.OkWithDetailed(result, "查询成功", c)
|
|
}
|
|
|
|
// CreateSplitAccountDeductionLog 创建分账扣钱日志
|
|
func (r *SplitAccountDeductionLogApi) CreateSplitAccountDeductionLog(c *gin.Context) {
|
|
var req systemReq.AddSplitAccountDeductionLogRequest
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
ValidAndFail(constant.LoggerChannelRequest, "创建分账扣钱日志请求参数异常", "参数错误: "+err.Error(), c, err)
|
|
return
|
|
}
|
|
|
|
userInfo := utils.GetUserInfo(c)
|
|
id, err := splitAccountDeductionLogService.CreateSplitAccountDeductionLog(req, userInfo.Username, database.GetDB(c))
|
|
if err != nil {
|
|
utils.FailWithRequestLog(constant.LoggerChannelWork, "创建分账扣钱日志异常", err, c, req)
|
|
return
|
|
}
|
|
systemRes.OkWithDetailed(gin.H{"id": id}, "创建成功", c)
|
|
}
|
|
|
|
// UpdateSplitAccountDeductionLog 更新分账扣钱日志
|
|
func (r *SplitAccountDeductionLogApi) UpdateSplitAccountDeductionLog(c *gin.Context) {
|
|
var req systemReq.UpdateSplitAccountDeductionLogRequest
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
ValidAndFail(constant.LoggerChannelRequest, "更新分账扣钱日志请求参数异常", "参数错误: "+err.Error(), c, err)
|
|
return
|
|
}
|
|
|
|
userInfo := utils.GetUserInfo(c)
|
|
err := splitAccountDeductionLogService.UpdateSplitAccountDeductionLog(req, userInfo.Username, database.GetDB(c))
|
|
if err != nil {
|
|
utils.FailWithRequestLog(constant.LoggerChannelWork, "更新分账扣钱日志异常", err, c, req)
|
|
return
|
|
}
|
|
|
|
systemRes.OkWithMessage("更新成功", c)
|
|
}
|
|
|
|
// DeleteSplitAccountDeductionLog 删除分账扣钱日志
|
|
func (r *SplitAccountDeductionLogApi) DeleteSplitAccountDeductionLog(c *gin.Context) {
|
|
var req systemReq.DeleteSplitAccountDeductionLogRequest
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
ValidAndFail(constant.LoggerChannelRequest, "删除分账扣钱日志请求参数异常", "参数错误: "+err.Error(), c, err)
|
|
return
|
|
}
|
|
|
|
userInfo := utils.GetUserInfo(c)
|
|
err := splitAccountDeductionLogService.DeleteSplitAccountDeductionLog(req, userInfo.Username, database.GetDB(c))
|
|
if err != nil {
|
|
utils.FailWithRequestLog(constant.LoggerChannelWork, "删除分账扣钱日志异常", err, c, req)
|
|
return
|
|
}
|
|
|
|
systemRes.OkWithMessage("删除成功", c)
|
|
}
|