65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"github.com/jinzhu/copier"
|
|
"github.com/pkg/errors"
|
|
"qnc-server/common/xerr"
|
|
"qnc-server/pkg/lzkit/crypto"
|
|
"qnc-server/pkg/lzkit/lzUtils"
|
|
|
|
"qnc-server/app/user/cmd/api/internal/svc"
|
|
"qnc-server/app/user/cmd/api/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type QueryDetailLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewQueryDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryDetailLogic {
|
|
return &QueryDetailLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *QueryDetailLogic) QueryDetail(req *types.QueryDetailReq) (resp *types.QueryDetailResp, err error) {
|
|
queryModel, err := l.svcCtx.QueryModel.FindOne(l.ctx, req.Id)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %+v", err)
|
|
}
|
|
|
|
var query types.Query
|
|
query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
|
|
query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
|
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
|
key, decodeErr := hex.DecodeString(secretKey)
|
|
if decodeErr != nil {
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取AES解密解药失败, %+v", err)
|
|
}
|
|
if lzUtils.NullStringToString(queryModel.QueryData) != "" {
|
|
queryData, decryptErr := crypto.AesDecrypt(lzUtils.NullStringToString(queryModel.QueryData), key)
|
|
if decryptErr != nil {
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果解密失败, %+v", decryptErr)
|
|
}
|
|
unmarshalErr := json.Unmarshal(queryData, &query.QueryData)
|
|
if unmarshalErr != nil {
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体处理失败, %+v", unmarshalErr)
|
|
}
|
|
}
|
|
err = copier.Copy(&query, queryModel)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %+v", err)
|
|
}
|
|
return &types.QueryDetailResp{
|
|
Query: query,
|
|
}, nil
|
|
}
|