refactor(user):用户控制器基本完成迁移。

This commit is contained in:
徐涛 2022-09-18 08:18:31 +08:00
parent cea90c5b29
commit 3f60376061
2 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,7 @@
package controller
import (
"database/sql"
"electricity_bill_calc/excel"
"electricity_bill_calc/global"
"electricity_bill_calc/response"
@ -202,13 +203,14 @@ func modifyEndUserRegisterRecord(c *gin.Context) {
result.NotAccept("抄表数据合法性验证失败。")
return
}
tx := global.DBConn.NewSession()
if err = tx.Begin(); err != nil {
ctx, cancel := global.TimeoutContext()
defer cancel()
tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{})
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
defer tx.Close()
err = service.EndUserService.UpdateEndUserRegisterRecord(tx, *meter)
err = service.EndUserService.UpdateEndUserRegisterRecord(&tx, &ctx, *meter)
if err != nil {
tx.Rollback()
result.Error(http.StatusInternalServerError, err.Error())

View File

@ -324,6 +324,7 @@ func modifyAccountDetail(c *gin.Context) {
return
}
newUserInfo := new(model.UserDetail)
newUserInfo.Id = targetUserId
newUserInfo.Name = &modForm.Name
newUserInfo.Region = modForm.Region
newUserInfo.Address = modForm.Address
@ -334,13 +335,15 @@ func modifyAccountDetail(c *gin.Context) {
result.BadRequest("用户月服务费无法解析。")
return
}
_, err = global.DBConn.ID(targetUserId).Update(newUserInfo)
_, err = global.DB.NewUpdate().Model(newUserInfo).
WherePK().
Column("name", "region", "address", "contact", "phone", "unit_service_fee").
Exec(c)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
cache.AbolishRelation("user")
cache.AbolishRelation(fmt.Sprintf("user_%s", targetUserId))
cache.AbolishRelation(fmt.Sprintf("user:%s", targetUserId))
result.Updated("指定用户的信息已经更新。")
}