79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package cmb
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
err2 "voucher/api/err"
|
|
v1 "voucher/api/v1"
|
|
"voucher/internal/biz/bo"
|
|
"voucher/internal/biz/vo"
|
|
)
|
|
|
|
func (v *Cmb) bizContent(_ context.Context, orderNotify *bo.OrderNotifyBo) (string, error) {
|
|
|
|
cmbStatus, err := orderNotify.Event.GetCmbStatusText()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
req := &v1.CmbNotifyRequest{
|
|
Ticket: orderNotify.OrderNo,
|
|
Status: cmbStatus.GetValue(),
|
|
TransDate: time.Now().Format("20060102150405"),
|
|
OrgNo: v.bc.Cmb.OrgNo,
|
|
Ext: "",
|
|
}
|
|
|
|
bizJsonBytes, err := json.Marshal(req)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(bizJsonBytes), nil
|
|
}
|
|
|
|
func (v *Cmb) notifyCreate(ctx context.Context, req *bo.OrderNotifyBo) (*v1.CmbRequest, *bo.OrderNotifyBo, error) {
|
|
|
|
bizContent, err := v.bizContent(ctx, req)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
request, err := v.CmbMixRepo.GetRequest(ctx, &bo.CmbRequestBo{
|
|
FuncName: vo.CmbNotifyFuncName,
|
|
BizContent: bizContent,
|
|
})
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
requestBytes, err := json.Marshal(request)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
req.Request = string(requestBytes)
|
|
|
|
orderNotify, err := v.OrderNotifyRepo.Create(ctx, req)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
return request, orderNotify, err
|
|
}
|
|
|
|
func (v *Cmb) notifySuccess(ctx context.Context, notifyId uint64, bizStr string) error {
|
|
|
|
return v.OrderNotifyRepo.Success(ctx, notifyId, bizStr)
|
|
}
|
|
|
|
func (v *Cmb) notifyFail(ctx context.Context, notifyId uint64, errMsg string) error {
|
|
|
|
if err := v.OrderNotifyRepo.Fail(ctx, notifyId, errMsg); err != nil {
|
|
return err
|
|
}
|
|
|
|
return err2.ErrorNeedRetryNotify(errMsg)
|
|
}
|