2023-12-20 15:39:25 +00:00
|
|
|
package mysqlkindbox
|
2024-01-23 07:39:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-03 04:56:27 +00:00
|
|
|
|
2024-01-23 07:39:58 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
2024-01-23 10:21:56 +00:00
|
|
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
2024-01-23 07:39:58 +00:00
|
|
|
)
|
|
|
|
|
2024-01-27 07:05:56 +00:00
|
|
|
func (d DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error {
|
2024-01-23 11:15:36 +00:00
|
|
|
const op = "mysqlkindbox.AddBatchKindBoxConcurrentlyRollback"
|
2024-01-27 07:05:56 +00:00
|
|
|
|
2024-02-03 05:03:58 +00:00
|
|
|
queryStr := "INSERT INTO kind_boxes (kind_box_req_id, benefactor_id, type, serial_number, status) VALUES "
|
|
|
|
values := []any{}
|
2024-01-23 10:21:56 +00:00
|
|
|
|
2024-02-03 05:03:58 +00:00
|
|
|
for _, kb := range kindBoxes {
|
|
|
|
queryStr += "(?, ?, ?, ?, ?),"
|
|
|
|
values = append(values, kb.KindBoxReqID, kb.BenefactorID, kb.Type, kb.SerialNumber, kb.Status.String())
|
2024-01-23 10:21:56 +00:00
|
|
|
}
|
2024-01-23 11:15:36 +00:00
|
|
|
|
2024-02-03 05:03:58 +00:00
|
|
|
// trim the last ,
|
|
|
|
queryStr = queryStr[0 : len(queryStr)-1]
|
2024-01-23 11:15:36 +00:00
|
|
|
|
2024-02-03 05:03:58 +00:00
|
|
|
if _, err := d.conn.Conn().ExecContext(ctx, queryStr, values...); err != nil {
|
2024-01-27 07:05:56 +00:00
|
|
|
return richerror.New(op).WithErr(err).
|
2024-01-23 10:21:56 +00:00
|
|
|
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
2024-01-23 11:15:36 +00:00
|
|
|
|
2024-01-27 07:05:56 +00:00
|
|
|
return nil
|
2024-01-23 07:39:58 +00:00
|
|
|
}
|