sync: 对齐小程序 v1.0.2 生产代码并脱敏
This commit is contained in:
@@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/batchmetadata"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/dao"
|
||||
@@ -126,7 +127,10 @@ func (s *sAppCard) LifecycleBatchSubmit(ctx context.Context, param *model.AppCar
|
||||
if err = appEnsureFeatureAccess(ctx, "card:"+operation.Code); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cardValues := appNormalizeLifecycleCardValues(param.CardValue, param.CardValues)
|
||||
cardValues, mode, err := appNormalizeLifecycleCardValues(param.CardValue, param.CardValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(cardValues) == 0 {
|
||||
return nil, gerror.New("请选择需要操作的卡")
|
||||
}
|
||||
@@ -153,7 +157,7 @@ func (s *sAppCard) LifecycleBatchSubmit(ctx context.Context, param *model.AppCar
|
||||
seen[item.Card.Iccid] = struct{}{}
|
||||
items = append(items, item)
|
||||
}
|
||||
return s.insertPendingLifecycleBatch(ctx, tx, user, items, operation, batchNo, strings.TrimSpace(param.Remark), now)
|
||||
return s.insertPendingLifecycleBatch(ctx, tx, user, items, operation, batchNo, strings.TrimSpace(param.Remark), mode, now)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -246,19 +250,52 @@ func (s *sAppCard) LifecycleBatchStatus(ctx context.Context, param *model.AppCar
|
||||
if err = appEnsureFeatureAccess(ctx, "card:"+operation.Code); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
status := appLifecycleBatchStatus(batch.BatchStatus, batch.BatchAsyncStatus)
|
||||
return &model.AppCardLifecycleModel{
|
||||
BatchNo: batch.BatchNo,
|
||||
BatchType: batch.BatchType,
|
||||
Operation: operation.Code,
|
||||
Status: appLifecycleBatchStatus(batch.BatchStatus, batch.BatchAsyncStatus),
|
||||
Status: status,
|
||||
Quantity: batch.TotalCount,
|
||||
SuccessCount: batch.SuccessCount,
|
||||
FailCount: batch.FailCount,
|
||||
FailReason: strings.TrimSpace(batch.FailReason),
|
||||
FailReason: appLifecycleFailReasonForResponse(status, batch.FailReason),
|
||||
Cards: []*model.AppCardModel{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func appLifecycleFailReasonForResponse(status string, reason string) string {
|
||||
reason = strings.TrimSpace(reason)
|
||||
if reason == "" {
|
||||
return ""
|
||||
}
|
||||
lower := strings.ToLower(reason)
|
||||
internalMarkers := []string{
|
||||
"save data service detail",
|
||||
"save lifecycle detail",
|
||||
"update `",
|
||||
"insert into",
|
||||
"delete from",
|
||||
"select ",
|
||||
"error 10",
|
||||
"sqlstate",
|
||||
"column '",
|
||||
"stack:",
|
||||
}
|
||||
for _, marker := range internalMarkers {
|
||||
if strings.Contains(lower, marker) {
|
||||
return "后台执行失败,请稍后重试;如持续失败,请联系管理员并提供批次号"
|
||||
}
|
||||
}
|
||||
if len([]rune(reason)) > 160 {
|
||||
return "后台执行失败,请稍后重试;如持续失败,请联系管理员并提供批次号"
|
||||
}
|
||||
if status == "failed" && (reason == "1 SIM cards failed" || reason == "1 SIM card failed") {
|
||||
return "卡片操作执行失败,请稍后重试"
|
||||
}
|
||||
return reason
|
||||
}
|
||||
|
||||
func (s *sAppCard) prepareLifecycleCard(ctx context.Context, user *entity.SysUser, cardValue string, rowNo int) (*appCardLifecycleItem, error) {
|
||||
card, err := s.findVisibleCard(ctx, user, cardValue)
|
||||
if err != nil {
|
||||
@@ -288,6 +325,13 @@ func (s *sAppCard) lockLifecycleCard(ctx context.Context, tx gdb.TX, user *entit
|
||||
if err = s.ensureOperateCard(ctx, user, card, operation.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channelInfo, err := s.resolveLifecycleCardChannelInfo(ctx, user.TenantId, card.Iccid, card.ChanKey)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrapf(err, "解析卡%s通道失败", appFirstNotEmpty(card.Iccid, cardValue))
|
||||
}
|
||||
if !appCardChannelAvailable(channelInfo) {
|
||||
return nil, gerror.Newf("此卡暂未收录,暂不能%s:%s", operation.Name, appFirstNotEmpty(card.Iccid, cardValue))
|
||||
}
|
||||
|
||||
var locked *entity.TSimCardInfo
|
||||
err = dao.TSimCardInfo.Ctx(ctx).TX(tx).
|
||||
@@ -306,6 +350,10 @@ func (s *sAppCard) lockLifecycleCard(ctx context.Context, tx gdb.TX, user *entit
|
||||
return nil, gerror.Newf("卡%s归属已变化,请刷新后重试", card.Iccid)
|
||||
}
|
||||
card.TSimCardInfo = *locked
|
||||
card.ChanKey = channelInfo.ChanKey
|
||||
card.ChanName = channelInfo.ChanName
|
||||
card.ChanAlias = channelInfo.ChanAlias
|
||||
card.TempKey = channelInfo.TempKey
|
||||
if err = s.ensureLifecycleCardStatus(card, operation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -382,7 +430,7 @@ func (s *sAppCard) applyMockLifecycleCards(ctx context.Context, tx gdb.TX, user
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sAppCard) insertPendingLifecycleBatch(ctx context.Context, tx gdb.TX, user *entity.SysUser, items []*appCardLifecycleItem, operation appCardLifecycleOperation, batchNo string, remark string, now *gtime.Time) error {
|
||||
func (s *sAppCard) insertPendingLifecycleBatch(ctx context.Context, tx gdb.TX, user *entity.SysUser, items []*appCardLifecycleItem, operation appCardLifecycleOperation, batchNo string, remark string, executionMode int, now *gtime.Time) error {
|
||||
quantity := len(items)
|
||||
_, err := dao.BatchMain.Ctx(ctx).TX(tx).Data(do.BatchMain{
|
||||
BatchNo: batchNo,
|
||||
@@ -390,7 +438,8 @@ func (s *sAppCard) insertPendingLifecycleBatch(ctx context.Context, tx gdb.TX, u
|
||||
BatchStatus: consts.BatchAsyncStatusPending,
|
||||
BatchAsyncStatus: consts.BatchAsyncStatusPending,
|
||||
SourceType: consts.BatchSourceTypeBatchSelect,
|
||||
SourceBatchNo: batchNo,
|
||||
SourceChannel: batchmetadata.MiniProgram,
|
||||
ExecutionMode: batchmetadata.NormalizeMode(executionMode),
|
||||
DeptId: user.DeptId,
|
||||
TotalCount: quantity,
|
||||
ValidCount: 0,
|
||||
@@ -962,13 +1011,21 @@ func appLifecycleOperType(operation appCardLifecycleOperation) string {
|
||||
}
|
||||
}
|
||||
|
||||
func appNormalizeLifecycleCardValues(cardValue string, cardValues []string) []string {
|
||||
func appNormalizeLifecycleCardValues(cardValue string, cardValues []string) ([]string, int, error) {
|
||||
values := make([]string, 0, len(cardValues)+1)
|
||||
if strings.TrimSpace(cardValue) != "" {
|
||||
values = append(values, cardValue)
|
||||
}
|
||||
values = append(values, cardValues...)
|
||||
return appNormalizeRenewCardValues(values)
|
||||
normalized := appNormalizeRenewCardValues(values)
|
||||
mode := batchmetadata.Bulk
|
||||
if strings.TrimSpace(cardValue) != "" && len(cardValues) == 0 {
|
||||
mode = batchmetadata.Single
|
||||
if len(normalized) != 1 {
|
||||
return nil, mode, gerror.New("单卡操作只能指定一张卡,请使用批量操作")
|
||||
}
|
||||
}
|
||||
return normalized, mode, nil
|
||||
}
|
||||
|
||||
func appLifecycleBatchInfo(operation appCardLifecycleOperation, items []*appCardLifecycleItem, batchNo string, remark string, now *gtime.Time) *gjson.Json {
|
||||
|
||||
Reference in New Issue
Block a user