84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
package unsub
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/dao"
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/entity"
|
|
)
|
|
|
|
type Repository struct{}
|
|
|
|
func NewRepository() *Repository {
|
|
return &Repository{}
|
|
}
|
|
|
|
func (r *Repository) GetSourceBatch(ctx context.Context, batchNo string) (*entity.BatchMain, error) {
|
|
batch := &entity.BatchMain{}
|
|
columns := dao.BatchMain.Columns()
|
|
err := dao.BatchMain.Ctx(ctx).
|
|
Fields(
|
|
columns.Id,
|
|
columns.BatchNo,
|
|
columns.BatchType,
|
|
columns.BatchStatus,
|
|
columns.RunResult,
|
|
columns.TenantId,
|
|
columns.DeptId,
|
|
columns.CreatedDept,
|
|
columns.CreatedBy,
|
|
).
|
|
Where(columns.BatchNo, strings.TrimSpace(batchNo)).
|
|
Scan(batch)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if batch.Id == 0 {
|
|
return nil, nil
|
|
}
|
|
return batch, nil
|
|
}
|
|
|
|
func (r *Repository) GetSourceBatchRows(ctx context.Context, batchNo string) ([]*Row, error) {
|
|
var details []*entity.BatchDetail
|
|
columns := dao.BatchDetail.Columns()
|
|
err := dao.BatchDetail.Ctx(ctx).
|
|
Fields(columns.RowNo, columns.ItemId, columns.Snapshot).
|
|
Where(columns.BatchNo, strings.TrimSpace(batchNo)).
|
|
Where(columns.BatchType, consts.BatchTypeOutbound).
|
|
WhereIn(columns.DetailStatus, []int{consts.BatchDetailStatusSuccess, consts.BatchAsyncStatusSuccess}).
|
|
OrderAsc(columns.RowNo).
|
|
Scan(&details)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
rows := make([]*Row, 0, len(details))
|
|
for _, detail := range details {
|
|
if detail == nil {
|
|
continue
|
|
}
|
|
row := &Row{RowNo: detail.RowNo, Iccid: strings.TrimSpace(detail.ItemId)}
|
|
if detail.Snapshot != nil {
|
|
if row.Iccid == "" {
|
|
row.Iccid = strings.TrimSpace(detail.Snapshot.Get("iccid").String())
|
|
}
|
|
if row.Iccid == "" {
|
|
row.Iccid = strings.TrimSpace(detail.Snapshot.Get("ICCID").String())
|
|
}
|
|
row.Msisdn = strings.TrimSpace(detail.Snapshot.Get("msisdn").String())
|
|
if row.Msisdn == "" {
|
|
row.Msisdn = strings.TrimSpace(detail.Snapshot.Get("MSISDN").String())
|
|
}
|
|
row.Imsi = strings.TrimSpace(detail.Snapshot.Get("imsi").String())
|
|
if row.Imsi == "" {
|
|
row.Imsi = strings.TrimSpace(detail.Snapshot.Get("IMSI").String())
|
|
}
|
|
}
|
|
rows = append(rows, row)
|
|
}
|
|
return rows, nil
|
|
}
|