f
This commit is contained in:
@@ -22,8 +22,31 @@ service main {
|
|||||||
|
|
||||||
@handler getAppConfig
|
@handler getAppConfig
|
||||||
get /app/config returns (getAppConfigResp)
|
get /app/config returns (getAppConfigResp)
|
||||||
|
|
||||||
|
@handler getHomeDynamicData
|
||||||
|
get /app/home/dynamic (getHomeDynamicDataReq) returns (getHomeDynamicDataResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
getHomeDynamicDataReq {
|
||||||
|
LastId int64 `json:"lastId,optional"`
|
||||||
|
}
|
||||||
|
InquiryRecordItem {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
Vin string `json:"vin"`
|
||||||
|
Model string `json:"model"`
|
||||||
|
}
|
||||||
|
ReviewItem {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
getHomeDynamicDataResp {
|
||||||
|
Cases []InquiryRecordItem `json:"cases"`
|
||||||
|
Reviews []ReviewItem `json:"reviews"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// 心跳检测响应
|
// 心跳检测响应
|
||||||
HealthCheckResp {
|
HealthCheckResp {
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"qnc-server/app/main/api/internal/logic/app"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetHomeDynamicDataHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetHomeDynamicDataReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := app.NewGetHomeDynamicDataLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetHomeDynamicData(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -842,6 +842,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/app/version",
|
Path: "/app/version",
|
||||||
Handler: app.GetAppVersionHandler(serverCtx),
|
Handler: app.GetAppVersionHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/app/home/dynamic",
|
||||||
|
Handler: app.GetHomeDynamicDataHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// 心跳检测接口
|
// 心跳检测接口
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
|
|||||||
64
app/main/api/internal/logic/app/gethomedynamicdatalogic.go
Normal file
64
app/main/api/internal/logic/app/gethomedynamicdatalogic.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetHomeDynamicDataLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetHomeDynamicDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetHomeDynamicDataLogic {
|
||||||
|
return &GetHomeDynamicDataLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetHomeDynamicDataLogic) GetHomeDynamicData(req *types.GetHomeDynamicDataReq) (resp *types.GetHomeDynamicDataResp, err error) {
|
||||||
|
// 1. 获取真实查询案例 (支持增量查询)
|
||||||
|
builder := l.svcCtx.InquiryRecordModel.SelectBuilder().Where("status = ?", 1)
|
||||||
|
|
||||||
|
var records []*model.InquiryRecord
|
||||||
|
if req.LastId > 0 {
|
||||||
|
// 增量获取大于 lastId 的记录
|
||||||
|
records, err = l.svcCtx.InquiryRecordModel.FindPageListByIdASC(l.ctx, builder, req.LastId, 50)
|
||||||
|
} else {
|
||||||
|
// 首次加载获取最新的 10 条
|
||||||
|
records, err = l.svcCtx.InquiryRecordModel.FindPageListByPage(l.ctx, builder, 1, 10, "id DESC")
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := make([]types.InquiryRecordItem, 0)
|
||||||
|
if err == nil {
|
||||||
|
for _, r := range records {
|
||||||
|
cases = append(cases, types.InquiryRecordItem{
|
||||||
|
Id: r.Id,
|
||||||
|
Tag: r.InquiryTag,
|
||||||
|
Vin: r.VinMasked,
|
||||||
|
Model: r.CarModel,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 硬编码返回一些初始评价
|
||||||
|
reviews := []types.ReviewItem{
|
||||||
|
{Name: "王先生", Content: "查询速度非常快,报告里关于出险的描述非常详细,避坑神器!"},
|
||||||
|
{Name: "李女士", Content: "买二手车之前查一下真的有必要,帮我发现了一台调表车。"},
|
||||||
|
{Name: "张先生", Content: "数据更新很及时,4S店的维保记录全都能查到。"},
|
||||||
|
{Name: "赵先生", Content: "操作简单,手机号绑定后报告一直保存着,随时可以查看。"},
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.GetHomeDynamicDataResp{
|
||||||
|
Cases: cases,
|
||||||
|
Reviews: reviews,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -5,10 +5,12 @@ import (
|
|||||||
|
|
||||||
"qnc-server/app/main/api/internal/svc"
|
"qnc-server/app/main/api/internal/svc"
|
||||||
"qnc-server/app/main/api/internal/types"
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/threading"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ToolboxQueryLogic struct {
|
type ToolboxQueryLogic struct {
|
||||||
@@ -40,8 +42,54 @@ func (l *ToolboxQueryLogic) ToolboxQuery(req *types.ToolboxQueryReq) (*types.Too
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录免费工具查询到动态展示表
|
||||||
|
l.recordFreeToolInquiry(req.ToolKey)
|
||||||
|
|
||||||
return &types.ToolboxQueryResp{
|
return &types.ToolboxQueryResp{
|
||||||
ToolKey: req.ToolKey,
|
ToolKey: req.ToolKey,
|
||||||
Result: result,
|
Result: result,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recordFreeToolInquiry 记录免费工具查询
|
||||||
|
func (l *ToolboxQueryLogic) recordFreeToolInquiry(toolKey string) {
|
||||||
|
// 异步记录,不影响主流程
|
||||||
|
threading.GoSafe(func() {
|
||||||
|
ctx := context.Background()
|
||||||
|
// 1. 获取工具名称 (这里可以建立一个简单的映射,或者从前端传过来,或者查询配置)
|
||||||
|
// 为了简单和解耦,我们这里仅记录 ToolKey,前端展示时再映射名称,或者在这里硬编码一些常用名称
|
||||||
|
toolName := toolKey
|
||||||
|
// 如果能访问到 toolboxRegistry 的逻辑最好,但后端通常不包含前端配置
|
||||||
|
// 我们可以通过一个简单的 Switch 处理一些核心工具名
|
||||||
|
switch toolKey {
|
||||||
|
case "ip-location":
|
||||||
|
toolName = "IP地址查询"
|
||||||
|
case "idcard-info":
|
||||||
|
toolName = "身份证归属地"
|
||||||
|
case "oilprice":
|
||||||
|
toolName = "实时油价"
|
||||||
|
case "joke":
|
||||||
|
toolName = "趣味笑话"
|
||||||
|
case "dream":
|
||||||
|
toolName = "周公解梦"
|
||||||
|
case "constellation":
|
||||||
|
toolName = "星座运势"
|
||||||
|
case "garbage":
|
||||||
|
toolName = "垃圾分类"
|
||||||
|
default:
|
||||||
|
// 其他的就直接用 key 或保持原样
|
||||||
|
}
|
||||||
|
|
||||||
|
record := &model.InquiryRecord{
|
||||||
|
UserPhoneTail: "系统",
|
||||||
|
DisplayName: "游客用户",
|
||||||
|
VinMasked: "******",
|
||||||
|
CarModel: "免费工具查询",
|
||||||
|
InquiryTag: toolName,
|
||||||
|
Status: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = l.svcCtx.InquiryRecordModel.Insert(ctx, nil, record)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"qnc-server/app/main/api/internal/svc"
|
"qnc-server/app/main/api/internal/svc"
|
||||||
"qnc-server/app/main/api/internal/types"
|
"qnc-server/app/main/api/internal/types"
|
||||||
"qnc-server/app/main/model"
|
"qnc-server/app/main/model"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
"qnc-server/pkg/lzkit/lzUtils"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
@@ -186,6 +186,9 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
|
|||||||
return l.handleError(ctx, updateQueryErr, order, query)
|
return l.handleError(ctx, updateQueryErr, order, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录动态查询记录 (真实案例展示)
|
||||||
|
go l.recordInquiryRecord(context.Background(), decryptData, product, encryptData)
|
||||||
|
|
||||||
// 报告生成成功后,发送代理处理异步任务(不阻塞报告流程)
|
// 报告生成成功后,发送代理处理异步任务(不阻塞报告流程)
|
||||||
if asyncErr := l.svcCtx.AsynqService.SendAgentProcessTask(order.Id); asyncErr != nil {
|
if asyncErr := l.svcCtx.AsynqService.SendAgentProcessTask(order.Id); asyncErr != nil {
|
||||||
// 代理处理任务发送失败,只记录日志,不影响报告流程
|
// 代理处理任务发送失败,只记录日志,不影响报告流程
|
||||||
@@ -377,6 +380,84 @@ func maskPhone(phone string) string {
|
|||||||
return phone[:3] + strings.Repeat("*", length-7) + phone[length-4:]
|
return phone[:3] + strings.Repeat("*", length-7) + phone[length-4:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recordInquiryRecord 记录成功的查询到动态展示表
|
||||||
|
func (l *PaySuccessNotifyUserHandler) recordInquiryRecord(ctx context.Context, decryptParams []byte, product *model.Product, encryptedResp string) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
logx.Errorf("记录查询记录异常: %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||||
|
key, _ := hex.DecodeString(secretKey)
|
||||||
|
|
||||||
|
// 1. 解析参数获取手机号和VIN
|
||||||
|
var params map[string]interface{}
|
||||||
|
_ = json.Unmarshal(decryptParams, ¶ms)
|
||||||
|
|
||||||
|
mobile, _ := params["mobile"].(string)
|
||||||
|
vin, _ := params["vin_code"].(string)
|
||||||
|
if vin == "" {
|
||||||
|
vin, _ = params["vin"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if mobile == "" || vin == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 解密响应数据获取车型
|
||||||
|
decryptResp, err := crypto.AesDecrypt(encryptedResp, key)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试从响应中寻找车型信息 (这里根据实际响应结构寻找)
|
||||||
|
// 通常在车辆信息接口的 data 字段中
|
||||||
|
carModel := "未知车型"
|
||||||
|
respStr := string(decryptResp)
|
||||||
|
|
||||||
|
// 简单的规则寻找车型字段
|
||||||
|
if strings.Contains(respStr, "model_name") {
|
||||||
|
re := regexp.MustCompile(`"model_name"\s*:\s*"([^"]+)"`)
|
||||||
|
match := re.FindStringSubmatch(respStr)
|
||||||
|
if len(match) > 1 {
|
||||||
|
carModel = match[1]
|
||||||
|
}
|
||||||
|
} else if strings.Contains(respStr, "brand_name") {
|
||||||
|
re := regexp.MustCompile(`"brand_name"\s*:\s*"([^"]+)"`)
|
||||||
|
match := re.FindStringSubmatch(respStr)
|
||||||
|
if len(match) > 1 {
|
||||||
|
carModel = match[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 脱敏处理
|
||||||
|
phoneTail := ""
|
||||||
|
if len(mobile) >= 4 {
|
||||||
|
phoneTail = mobile[len(mobile)-4:]
|
||||||
|
}
|
||||||
|
displayName := "用户*" + phoneTail
|
||||||
|
|
||||||
|
maskedVin := ""
|
||||||
|
if len(vin) >= 8 {
|
||||||
|
maskedVin = vin[:4] + "********" + vin[len(vin)-4:]
|
||||||
|
} else {
|
||||||
|
maskedVin = vin
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 保存记录
|
||||||
|
record := &model.InquiryRecord{
|
||||||
|
UserPhoneTail: phoneTail,
|
||||||
|
DisplayName: displayName,
|
||||||
|
VinMasked: maskedVin,
|
||||||
|
CarModel: carModel,
|
||||||
|
InquiryTag: product.ProductName,
|
||||||
|
Status: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = l.svcCtx.InquiryRecordModel.Insert(ctx, nil, record)
|
||||||
|
}
|
||||||
|
|
||||||
// 通用敏感信息脱敏 - 根据字符串长度比例进行脱敏
|
// 通用敏感信息脱敏 - 根据字符串长度比例进行脱敏
|
||||||
func maskGeneral(value string) string {
|
func maskGeneral(value string) string {
|
||||||
length := len(value)
|
length := len(value)
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ type ServiceContext struct {
|
|||||||
ExampleModel model.ExampleModel
|
ExampleModel model.ExampleModel
|
||||||
GlobalNotificationsModel model.GlobalNotificationsModel
|
GlobalNotificationsModel model.GlobalNotificationsModel
|
||||||
AuthorizationDocumentModel model.AuthorizationDocumentModel
|
AuthorizationDocumentModel model.AuthorizationDocumentModel
|
||||||
|
InquiryRecordModel model.InquiryRecordModel
|
||||||
|
|
||||||
// 第三方服务
|
// 第三方服务
|
||||||
TianyuanapiCallLogService *service.TianyuanapiCallLogService
|
TianyuanapiCallLogService *service.TianyuanapiCallLogService
|
||||||
@@ -172,6 +173,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
exampleModel := model.NewExampleModel(db, cacheConf)
|
exampleModel := model.NewExampleModel(db, cacheConf)
|
||||||
globalNotificationsModel := model.NewGlobalNotificationsModel(db, cacheConf)
|
globalNotificationsModel := model.NewGlobalNotificationsModel(db, cacheConf)
|
||||||
authorizationDocumentModel := model.NewAuthorizationDocumentModel(db, cacheConf)
|
authorizationDocumentModel := model.NewAuthorizationDocumentModel(db, cacheConf)
|
||||||
|
inquiryRecordModel := model.NewInquiryRecordModel(db, cacheConf)
|
||||||
tianyuanapiCallLogModel := model.NewTianyuanapiCallLogModel(db, cacheConf)
|
tianyuanapiCallLogModel := model.NewTianyuanapiCallLogModel(db, cacheConf)
|
||||||
|
|
||||||
// ============================== 第三方服务初始化 ==============================
|
// ============================== 第三方服务初始化 ==============================
|
||||||
@@ -297,6 +299,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
ExampleModel: exampleModel,
|
ExampleModel: exampleModel,
|
||||||
GlobalNotificationsModel: globalNotificationsModel,
|
GlobalNotificationsModel: globalNotificationsModel,
|
||||||
AuthorizationDocumentModel: authorizationDocumentModel,
|
AuthorizationDocumentModel: authorizationDocumentModel,
|
||||||
|
InquiryRecordModel: inquiryRecordModel,
|
||||||
|
|
||||||
// 第三方服务
|
// 第三方服务
|
||||||
TianyuanapiCallLogService: tianyuanapiCallLogService,
|
TianyuanapiCallLogService: tianyuanapiCallLogService,
|
||||||
|
|||||||
@@ -2436,3 +2436,24 @@ type SendSmsReq struct {
|
|||||||
ActionType string `json:"actionType" validate:"required,oneof=login register query agentApply realName bindMobile"`
|
ActionType string `json:"actionType" validate:"required,oneof=login register query agentApply realName bindMobile"`
|
||||||
CaptchaVerifyParam string `json:"captchaVerifyParam,optional"`
|
CaptchaVerifyParam string `json:"captchaVerifyParam,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetHomeDynamicDataReq struct {
|
||||||
|
LastId int64 `json:"lastId,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type InquiryRecordItem struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
Vin string `json:"vin"`
|
||||||
|
Model string `json:"model"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReviewItem struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetHomeDynamicDataResp struct {
|
||||||
|
Cases []InquiryRecordItem `json:"cases"`
|
||||||
|
Reviews []ReviewItem `json:"reviews"`
|
||||||
|
}
|
||||||
|
|||||||
27
app/main/model/inquiryRecordModel.go
Normal file
27
app/main/model/inquiryRecordModel.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ InquiryRecordModel = (*customInquiryRecordModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// InquiryRecordModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customInquiryRecordModel.
|
||||||
|
InquiryRecordModel interface {
|
||||||
|
inquiryRecordModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customInquiryRecordModel struct {
|
||||||
|
*defaultInquiryRecordModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewInquiryRecordModel returns a model for the database table.
|
||||||
|
func NewInquiryRecordModel(conn sqlx.SqlConn, c cache.CacheConf) InquiryRecordModel {
|
||||||
|
return &customInquiryRecordModel{
|
||||||
|
defaultInquiryRecordModel: newInquiryRecordModel(conn, c),
|
||||||
|
}
|
||||||
|
}
|
||||||
384
app/main/model/inquiryRecordModel_gen.go
Normal file
384
app/main/model/inquiryRecordModel_gen.go
Normal file
@@ -0,0 +1,384 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT!
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
inquiryRecordFieldNames = builder.RawFieldNames(&InquiryRecord{})
|
||||||
|
inquiryRecordRows = strings.Join(inquiryRecordFieldNames, ",")
|
||||||
|
inquiryRecordRowsExpectAutoSet = strings.Join(stringx.Remove(inquiryRecordFieldNames, "`create_time`", "`update_time`"), ",")
|
||||||
|
inquiryRecordRowsWithPlaceHolder = strings.Join(stringx.Remove(inquiryRecordFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheQncInquiryRecordIdPrefix = "cache:qnc:inquiryRecord:id:"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
inquiryRecordModel interface {
|
||||||
|
Insert(ctx context.Context, session sqlx.Session, data *InquiryRecord) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*InquiryRecord, error)
|
||||||
|
Update(ctx context.Context, session sqlx.Session, data *InquiryRecord) (sql.Result, error)
|
||||||
|
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *InquiryRecord) error
|
||||||
|
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||||
|
SelectBuilder() squirrel.SelectBuilder
|
||||||
|
DeleteSoft(ctx context.Context, session sqlx.Session, data *InquiryRecord) error
|
||||||
|
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||||
|
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||||
|
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*InquiryRecord, error)
|
||||||
|
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*InquiryRecord, error)
|
||||||
|
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*InquiryRecord, int64, error)
|
||||||
|
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*InquiryRecord, error)
|
||||||
|
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*InquiryRecord, error)
|
||||||
|
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultInquiryRecordModel struct {
|
||||||
|
sqlc.CachedConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
InquiryRecord struct {
|
||||||
|
Id int64 `db:"id"`
|
||||||
|
UserPhoneTail string `db:"user_phone_tail"` // 用户手机尾号
|
||||||
|
DisplayName string `db:"display_name"` // 展示名称
|
||||||
|
VinMasked string `db:"vin_masked"` // 脱敏VIN
|
||||||
|
CarModel string `db:"car_model"` // 车型
|
||||||
|
InquiryTag string `db:"inquiry_tag"` // 查询标签
|
||||||
|
Status int64 `db:"status"` // 状态 1:显示 0:隐藏
|
||||||
|
DelState int64 `db:"del_state"` // 删除状态 0:未删除 1:已删除
|
||||||
|
Version int64 `db:"version"` // 版本号
|
||||||
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||||
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||||
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newInquiryRecordModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultInquiryRecordModel {
|
||||||
|
return &defaultInquiryRecordModel{
|
||||||
|
CachedConn: sqlc.NewConn(conn, c),
|
||||||
|
table: "`inquiry_record`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) Insert(ctx context.Context, session sqlx.Session, data *InquiryRecord) (sql.Result, error) {
|
||||||
|
data.DelState = globalkey.DelStateNo
|
||||||
|
// 移除 insertUUID,使用数据库自增 ID
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, strings.Join(stringx.Remove(inquiryRecordFieldNames, "`id`", "`create_time`", "`update_time`"), ","))
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.UserPhoneTail, data.DisplayName, data.VinMasked, data.CarModel, data.InquiryTag, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.UserPhoneTail, data.DisplayName, data.VinMasked, data.CarModel, data.InquiryTag, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindOne(ctx context.Context, id int64) (*InquiryRecord, error) {
|
||||||
|
qncInquiryRecordIdKey := fmt.Sprintf("%s%v", cacheQncInquiryRecordIdPrefix, id)
|
||||||
|
var resp InquiryRecord
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, qncInquiryRecordIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", inquiryRecordRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
|
})
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) Update(ctx context.Context, session sqlx.Session, data *InquiryRecord) (sql.Result, error) {
|
||||||
|
qncInquiryRecordIdKey := fmt.Sprintf("%s%v", cacheQncInquiryRecordIdPrefix, data.Id)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, inquiryRecordRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.UserPhoneTail, data.DisplayName, data.VinMasked, data.CarModel, data.InquiryTag, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.UserPhoneTail, data.DisplayName, data.VinMasked, data.CarModel, data.InquiryTag, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||||
|
}, qncInquiryRecordIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *InquiryRecord) error {
|
||||||
|
|
||||||
|
oldVersion := data.Version
|
||||||
|
data.Version += 1
|
||||||
|
|
||||||
|
var sqlResult sql.Result
|
||||||
|
var err error
|
||||||
|
|
||||||
|
qncInquiryRecordIdKey := fmt.Sprintf("%s%v", cacheQncInquiryRecordIdPrefix, data.Id)
|
||||||
|
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, inquiryRecordRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.UserPhoneTail, data.DisplayName, data.VinMasked, data.CarModel, data.InquiryTag, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.UserPhoneTail, data.DisplayName, data.VinMasked, data.CarModel, data.InquiryTag, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||||
|
}, qncInquiryRecordIdKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateCount, err := sqlResult.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if updateCount == 0 {
|
||||||
|
return ErrNoRowsUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *InquiryRecord) error {
|
||||||
|
data.DelState = globalkey.DelStateYes
|
||||||
|
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||||
|
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||||
|
return errors.Wrapf(errors.New("delete soft failed "), "InquiryRecordModel delete err : %+v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp float64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("COUNT(" + field + ")")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp int64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*InquiryRecord, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(inquiryRecordRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*InquiryRecord
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*InquiryRecord, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(inquiryRecordRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*InquiryRecord
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*InquiryRecord, int64, error) {
|
||||||
|
|
||||||
|
totalBuilder := builder.Columns("COUNT(*)")
|
||||||
|
query, values, err := totalBuilder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &total, query, values...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if total == 0 {
|
||||||
|
return []*InquiryRecord{}, 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns(inquiryRecordRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err = builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*InquiryRecord
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, total, nil
|
||||||
|
default:
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*InquiryRecord, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(inquiryRecordRows)
|
||||||
|
|
||||||
|
if preMinId != 0 {
|
||||||
|
builder = builder.Where("id < ?", preMinId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*InquiryRecord
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*InquiryRecord, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(inquiryRecordRows)
|
||||||
|
|
||||||
|
if preMaxId != 0 {
|
||||||
|
builder = builder.Where("id > ?", preMaxId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*InquiryRecord
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||||
|
|
||||||
|
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
return fn(ctx, session)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) SelectBuilder() squirrel.SelectBuilder {
|
||||||
|
return squirrel.Select().From(m.table)
|
||||||
|
}
|
||||||
|
func (m *defaultInquiryRecordModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||||
|
qncInquiryRecordIdKey := fmt.Sprintf("%s%v", cacheQncInquiryRecordIdPrefix, id)
|
||||||
|
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, id)
|
||||||
|
}, qncInquiryRecordIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultInquiryRecordModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheQncInquiryRecordIdPrefix, primary)
|
||||||
|
}
|
||||||
|
func (m *defaultInquiryRecordModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", inquiryRecordRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultInquiryRecordModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
||||||
@@ -13,11 +13,11 @@ $tables = @(
|
|||||||
# ============================================
|
# ============================================
|
||||||
# 统计/白名单/成本价 同步用(执行 sync_whitelist_cost_tables.sql 后再生成)
|
# 统计/白名单/成本价 同步用(执行 sync_whitelist_cost_tables.sql 后再生成)
|
||||||
# ============================================
|
# ============================================
|
||||||
"feature",
|
# "feature",
|
||||||
"tianyuanapi_call_log",
|
# "tianyuanapi_call_log",
|
||||||
"user_feature_whitelist",
|
# "user_feature_whitelist",
|
||||||
"whitelist_order",
|
# "whitelist_order",
|
||||||
"whitelist_order_item"
|
# "whitelist_order_item"
|
||||||
# ============================================
|
# ============================================
|
||||||
# 新代理系统表
|
# 新代理系统表
|
||||||
# ============================================
|
# ============================================
|
||||||
@@ -49,8 +49,9 @@ $tables = @(
|
|||||||
# "agent_short_link",
|
# "agent_short_link",
|
||||||
# "agent_upgrade",
|
# "agent_upgrade",
|
||||||
# "agent_wallet",
|
# "agent_wallet",
|
||||||
"agent_withdrawal",
|
# "agent_withdrawal",
|
||||||
"agent_withdrawal_tax"
|
# "agent_withdrawal_tax"
|
||||||
|
"inquiry_record"
|
||||||
# "authorization_document",
|
# "authorization_document",
|
||||||
# "example",
|
# "example",
|
||||||
# "feature",
|
# "feature",
|
||||||
|
|||||||
Reference in New Issue
Block a user