单元测试dao_account_log_test的时候报下面的错,如何解决?
来源:5-8 资金账户模块-账户流水表数据库访问层和测试用例编码实践
潇洒哥gogo
2020-05-14
no unique column for db tag. example: db:"order_id,unique"
: struct
2回答
-
潇洒哥gogo
提问者
2020-05-21
package accounts
import (
"github.com/shopspring/decimal"
"imooc.com/resk1/services"
"time"
)
type AccountLog struct {
Id int64 `db:"id,omitempty"` //
LogNo string `db:"log_no,unique"` //流水编号 全局不重复字符或数字,唯一性标识
TradeNo string `db:"trade_no"` //交易单号 全局不重复字符或数字,唯一性标识
AccountNo string `db:"account_no"` //账户编号 账户ID
UserId string `db:"user_id"` //用户编号
Username string `db:"username"` //用户名称
TargetAccountNo string `db:"target_account_no"` //账户编号 账户ID
TargetUserId string `db:"target_user_id"` //目标用户编号
TargetUsername string `db:"target_username"` //目标用户名称
Amount decimal.Decimal `db:"amount"` //交易金额,该交易涉及的金额
Balance decimal.Decimal `db:"balance"` //交易后余额,该交易后的余额
ChangeType services.ChangeType `db:"change_type"` //流水交易类型,0 创建账户,>0 为收入类型,<0 为支出类型,自定义
ChangeFlag services.ChangeFlag `db:"change_flag"` //交易变化标识:-1 出账 1为进账,枚举
Status int `db:"status"` //交易状态:
Decs string `db:"decs"` //交易描述
CreatedAt time.Time `db:"created_at,omitempty"` //创建时间
}
func (po *AccountLog) FromTransferDTO(dto *services.AccountTransferDTO) {
po.TradeNo = dto.TradeNo
po.AccountNo = dto.TradeBody.AccountNo
po.TargetAccountNo = dto.TradeTarget.AccountNo
po.UserId = dto.TradeBody.UserId
po.Username = dto.TradeBody.Username
po.TargetUserId = dto.TradeTarget.UserId
po.TargetUsername = dto.TradeTarget.Username
po.Amount = dto.Amount
po.ChangeType = dto.ChangeType
po.ChangeFlag = dto.ChangeFlag
po.Decs = dto.Decs
}
func (po *AccountLog) ToDTO() *services.AccountLogDTO {
dto := &services.AccountLogDTO{
TradeNo: po.TradeNo,
LogNo: po.LogNo,
AccountNo: po.AccountNo,
TargetAccountNo: po.TargetAccountNo,
UserId: po.UserId,
Username: po.Username,
TargetUserId: po.TargetUserId,
TargetUsername: po.TargetUsername,
Amount: po.Amount,
Balance: po.Balance,
ChangeType: po.ChangeType,
ChangeFlag: po.ChangeFlag,
Status: po.Status,
Decs: po.Decs,
CreatedAt: po.CreatedAt,
}
return dto
}
func (po *AccountLog) FromDTO(dto *services.AccountLogDTO) {
po.TradeNo = dto.TradeNo
po.LogNo = dto.LogNo
po.AccountNo = dto.AccountNo
po.TargetAccountNo = dto.TargetAccountNo
po.UserId = dto.UserId
po.Username = dto.Username
po.TargetUserId = dto.TargetUserId
po.TargetUsername = dto.TargetUsername
po.Amount = dto.Amount
po.Balance = dto.Balance
po.ChangeType = dto.ChangeType
po.ChangeFlag = dto.ChangeFlag
po.Status = dto.Status
po.Decs = dto.Decs
po.CreatedAt = dto.CreatedAt
}00 -
枫荇
2020-05-15
同学,您好!这个问题应该是映射关系不明确造成的,请附上你的po看一下。
012020-05-21
相似问题