addf
This commit is contained in:
@@ -2,10 +2,17 @@ package admin_query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/ctxdata"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -27,7 +34,6 @@ func NewAdminDeleteQueryFeatureDataLogic(ctx context.Context, svcCtx *svc.Servic
|
||||
}
|
||||
|
||||
func (l *AdminDeleteQueryFeatureDataLogic) AdminDeleteQueryFeatureData(req *types.AdminDeleteQueryFeatureDataReq) (resp *types.AdminDeleteQueryFeatureDataResp, err error) {
|
||||
// 基本参数校验
|
||||
if req.QueryId == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("QueryId 不能为空"), "")
|
||||
}
|
||||
@@ -35,8 +41,56 @@ func (l *AdminDeleteQueryFeatureDataLogic) AdminDeleteQueryFeatureData(req *type
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("feature_api_id 不能为空"), "")
|
||||
}
|
||||
|
||||
// 使用事务调用 WhitelistService.DeleteFeatureFromQueryData,保持与其它删除逻辑一致
|
||||
queryModel, err := l.svcCtx.QueryModel.FindOne(l.ctx, req.QueryId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("查询记录不存在"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询报告记录失败, %v", err)
|
||||
}
|
||||
|
||||
queryParams, err := decryptQueryParams(l.svcCtx, queryModel)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取查询参数失败, %v", err)
|
||||
}
|
||||
|
||||
idCard, _ := queryParams["id_card"].(string)
|
||||
if idCard == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("查询参数中缺少身份证号,无法添加白名单"), "")
|
||||
}
|
||||
|
||||
name, _ := queryParams["name"].(string)
|
||||
if strings.TrimSpace(name) == "" {
|
||||
name = "*"
|
||||
}
|
||||
|
||||
adminUserID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取管理员信息失败, %v", err)
|
||||
}
|
||||
|
||||
mainApiId := extractMainApiId(req.FeatureApiId)
|
||||
feature, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, mainApiId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("模块不存在"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询模块信息失败, %v", err)
|
||||
}
|
||||
|
||||
remark := fmt.Sprintf("后台删除报告模块自动同步 query_id=%s feature=%s", req.QueryId, feature.ApiId)
|
||||
l.svcCtx.QueryWhitelistSyncService.TrySync(
|
||||
l.ctx,
|
||||
name,
|
||||
idCard,
|
||||
[]string{feature.ApiId},
|
||||
remark,
|
||||
)
|
||||
|
||||
err = l.svcCtx.QueryModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
if wlErr := l.svcCtx.WhitelistService.EnsureFreeWhitelist(ctx, session, idCard, feature, adminUserID, req.QueryId); wlErr != nil {
|
||||
return wlErr
|
||||
}
|
||||
return l.svcCtx.WhitelistService.DeleteFeatureFromQueryData(ctx, session, req.QueryId, req.FeatureApiId)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -46,6 +100,37 @@ func (l *AdminDeleteQueryFeatureDataLogic) AdminDeleteQueryFeatureData(req *type
|
||||
|
||||
return &types.AdminDeleteQueryFeatureDataResp{
|
||||
Success: true,
|
||||
Message: "删除成功(如果原本不存在该模块数据,则视为已删除)",
|
||||
Message: "删除成功,已同步本地白名单并尽力同步天远查询白名单(若原本不存在该模块数据,则视为已删除)",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func extractMainApiId(featureApiId string) string {
|
||||
if idx := strings.Index(featureApiId, "_"); idx > 0 {
|
||||
return featureApiId[:idx]
|
||||
}
|
||||
return featureApiId
|
||||
}
|
||||
|
||||
func decryptQueryParams(svcCtx *svc.ServiceContext, queryModel *model.Query) (map[string]interface{}, error) {
|
||||
if queryModel.QueryParams == "" {
|
||||
return nil, errors.New("查询参数为空")
|
||||
}
|
||||
|
||||
secretKey := svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return nil, errors.Wrap(decodeErr, "获取AES密钥失败")
|
||||
}
|
||||
|
||||
decryptedParams, decryptErr := crypto.AesDecrypt(queryModel.QueryParams, key)
|
||||
if decryptErr != nil {
|
||||
return nil, errors.Wrap(decryptErr, "解密查询参数失败")
|
||||
}
|
||||
|
||||
var params map[string]interface{}
|
||||
if unmarshalErr := json.Unmarshal(decryptedParams, ¶ms); unmarshalErr != nil {
|
||||
return nil, errors.Wrap(unmarshalErr, "解析查询参数失败")
|
||||
}
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user