temp
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
syntax = "v1"
|
|
||||||
|
|
||||||
info (
|
|
||||||
title: "代理服务"
|
|
||||||
desc: "代理服务接口"
|
|
||||||
author: "Liangzai"
|
|
||||||
email: "2440983361@qq.com"
|
|
||||||
version: "v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
import (
|
|
||||||
"agent/agent.api"
|
|
||||||
)
|
|
||||||
|
|
||||||
@server (
|
|
||||||
prefix: api/v1/agent
|
|
||||||
group: agent
|
|
||||||
)
|
|
||||||
service main {
|
|
||||||
@handler GetAgentInfo
|
|
||||||
get /info returns (AgentInfoResp)
|
|
||||||
|
|
||||||
// 提交代理申请
|
|
||||||
@handler ApplyForAgent
|
|
||||||
post /apply (AgentApplyReq) returns (AgentApplyResp)
|
|
||||||
|
|
||||||
// 查询代理申请状态
|
|
||||||
@handler GetAgentAuditStatus
|
|
||||||
get /audit/status (AgentAuditStatusReq) returns (AgentAuditStatusResp)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
syntax = "v1"
|
|
||||||
|
|
||||||
info (
|
|
||||||
title: "代理服务"
|
|
||||||
desc: "代理服务接口"
|
|
||||||
author: "Liangzai"
|
|
||||||
email: "2440983361@qq.com"
|
|
||||||
version: "v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
AgentInfoResp {
|
|
||||||
isAgent bool `json:"is_agent"`
|
|
||||||
region string `json:"region"`
|
|
||||||
mobile string `json:"mobile"`
|
|
||||||
wechatID string `json:"wechat_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 代理申请请求参数
|
|
||||||
AgentApplyReq {
|
|
||||||
UserID int64 `json:"user_id"`
|
|
||||||
Region string `json:"region"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
WechatID string `json:"wechat_id"`
|
|
||||||
}
|
|
||||||
// 代理申请响应
|
|
||||||
AgentApplyResp {
|
|
||||||
Status string `json:"status"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
// 查询代理申请状态请求参数
|
|
||||||
AgentAuditStatusReq {
|
|
||||||
UserID int64 `json:"user_id"`
|
|
||||||
}
|
|
||||||
// 查询代理申请状态响应
|
|
||||||
AgentAuditStatusResp {
|
|
||||||
Status int `json:"status"` // 0=待审核,1=审核通过,2=审核未通过
|
|
||||||
AuditReason string `json:"audit_reason"`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -12,4 +12,3 @@ import "user.api"
|
|||||||
import "query.api"
|
import "query.api"
|
||||||
import "pay.api"
|
import "pay.api"
|
||||||
import "product.api"
|
import "product.api"
|
||||||
import "agent.api"
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Name: main
|
Name: main
|
||||||
Host: 0.0.0.0
|
Host: 0.0.0.0
|
||||||
Port: 8888
|
Port: 8888
|
||||||
DataSource: "qnc:5vg67b3UNHu8@tcp(127.0.0.1:20001)/qnc?charset=utf8mb4&parseTime=True&loc=Local"
|
DataSource: "tyc:5vg67b3UNHu8@tcp(127.0.0.1:20001)/tyc?charset=utf8mb4&parseTime=True&loc=Local"
|
||||||
CacheRedis:
|
CacheRedis:
|
||||||
- Host: "127.0.0.1:20002"
|
- Host: "127.0.0.1:20002"
|
||||||
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
|
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
Name: main
|
Name: main
|
||||||
Host: 0.0.0.0
|
Host: 0.0.0.0
|
||||||
Port: 8888
|
Port: 8888
|
||||||
DataSource: "qnc:5vg67b3UNHu8@tcp(qnc_mysql:3306)/qnc?charset=utf8mb4&parseTime=True&loc=Local"
|
DataSource: "tyc:5vg67b3UNHu8@tcp(tyc_mysql:3306)/tyc?charset=utf8mb4&parseTime=True&loc=Local"
|
||||||
CacheRedis:
|
CacheRedis:
|
||||||
- Host: "qnc_redis:6379"
|
- Host: "tyc_redis:6379"
|
||||||
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
|
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
|
||||||
Type: "node" # 单节点模式
|
Type: "node" # 单节点模式
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package agent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/agent"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ApplyForAgentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var req types.AgentApplyReq
|
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
|
||||||
result.ParamErrorResult(r, w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := validator.Validate(req); err != nil {
|
|
||||||
result.ParamValidateErrorResult(r, w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
l := agent.NewApplyForAgentLogic(r.Context(), svcCtx)
|
|
||||||
resp, err := l.ApplyForAgent(&req)
|
|
||||||
result.HttpResult(r, w, resp, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package agent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/agent"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetAgentAuditStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var req types.AgentAuditStatusReq
|
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
|
||||||
result.ParamErrorResult(r, w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := validator.Validate(req); err != nil {
|
|
||||||
result.ParamValidateErrorResult(r, w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
l := agent.NewGetAgentAuditStatusLogic(r.Context(), svcCtx)
|
|
||||||
resp, err := l.GetAgentAuditStatus(&req)
|
|
||||||
result.HttpResult(r, w, resp, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package agent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/agent"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetAgentInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
l := agent.NewGetAgentInfoLogic(r.Context(), svcCtx)
|
|
||||||
resp, err := l.GetAgentInfo()
|
|
||||||
result.HttpResult(r, w, resp, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,12 +3,13 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/auth"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/auth"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func SendSmsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func SendSmsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package notification
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/notification"
|
"tyc-server/app/user/cmd/api/internal/logic/notification"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/common/result"
|
"tyc-server/common/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetNotificationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetNotificationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/pay"
|
"tyc-server/app/user/cmd/api/internal/logic/pay"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/common/result"
|
"tyc-server/common/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AlipayCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func AlipayCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/pay"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/pay"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func IapCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func IapCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/pay"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/pay"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func PaymentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func PaymentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/pay"
|
"tyc-server/app/user/cmd/api/internal/logic/pay"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/common/result"
|
"tyc-server/common/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WechatPayCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func WechatPayCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/pay"
|
"tyc-server/app/user/cmd/api/internal/logic/pay"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/common/result"
|
"tyc-server/common/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WechatPayRefundCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func WechatPayRefundCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package product
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/product"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/product"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetProductByEnHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetProductByEnHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package product
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/product"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/product"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetProductByIDHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetProductByIDHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package product
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/product"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/product"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetProductRenderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetProductRenderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryDetailByOrderIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryDetailByOrderIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryDetailByOrderNoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryDetailByOrderNoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryExampleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryExampleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryProvisionalOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryProvisionalOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryRetryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryRetryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QueryServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QueryServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/query"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func QuerySingleTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func QuerySingleTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -4,40 +4,18 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
agent "qnc-server/app/user/cmd/api/internal/handler/agent"
|
auth "tyc-server/app/user/cmd/api/internal/handler/auth"
|
||||||
auth "qnc-server/app/user/cmd/api/internal/handler/auth"
|
notification "tyc-server/app/user/cmd/api/internal/handler/notification"
|
||||||
notification "qnc-server/app/user/cmd/api/internal/handler/notification"
|
pay "tyc-server/app/user/cmd/api/internal/handler/pay"
|
||||||
pay "qnc-server/app/user/cmd/api/internal/handler/pay"
|
product "tyc-server/app/user/cmd/api/internal/handler/product"
|
||||||
product "qnc-server/app/user/cmd/api/internal/handler/product"
|
query "tyc-server/app/user/cmd/api/internal/handler/query"
|
||||||
query "qnc-server/app/user/cmd/api/internal/handler/query"
|
user "tyc-server/app/user/cmd/api/internal/handler/user"
|
||||||
user "qnc-server/app/user/cmd/api/internal/handler/user"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
server.AddRoutes(
|
|
||||||
[]rest.Route{
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/apply",
|
|
||||||
Handler: agent.ApplyForAgentHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/audit/status",
|
|
||||||
Handler: agent.GetAgentAuditStatusHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/info",
|
|
||||||
Handler: agent.GetAgentInfoHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
rest.WithPrefix("/api/v1/agent"),
|
|
||||||
)
|
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/common/result"
|
"tyc-server/common/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DecryptMobileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func DecryptMobileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/common/result"
|
"tyc-server/common/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func DetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/common/result"
|
"tyc-server/common/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func MobileCodeLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func MobileCodeLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func MobileLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func MobileLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func WxH5AuthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func WxH5AuthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package user
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/logic/user"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/result"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"qnc-server/app/user/cmd/api/internal/logic/user"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/result"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func WxMiniAuthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func WxMiniAuthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package agent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ApplyForAgentLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewApplyForAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyForAgentLogic {
|
|
||||||
return &ApplyForAgentLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *types.AgentApplyResp, err error) {
|
|
||||||
var agentAudit model.AgentAudit
|
|
||||||
agentAudit.Mobile = req.Mobile
|
|
||||||
agentAudit.Region = req.Region
|
|
||||||
agentAudit.WechatId = lzUtils.StringToNullString(req.WechatID)
|
|
||||||
agentAudit.Status = 0
|
|
||||||
agentAuditInsert, err := l.svcCtx.AgentAuditModel.Insert(l.ctx, nil, &agentAudit)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "代理申请, 保存代理信息失败: %+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
// 延迟 10 秒
|
|
||||||
<-time.After(10 * time.Second)
|
|
||||||
// 查找刚刚插入的数据
|
|
||||||
agentAuditID, _ := agentAuditInsert.LastInsertId()
|
|
||||||
agentAuditRow, _ := l.svcCtx.AgentAuditModel.FindOne(l.ctx, agentAuditID)
|
|
||||||
|
|
||||||
l.svcCtx.AgentAuditModel.UpdateWithVersion(l.ctx, nil, agentAuditRow)
|
|
||||||
}()
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package agent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GetAgentAuditStatusLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGetAgentAuditStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentAuditStatusLogic {
|
|
||||||
return &GetAgentAuditStatusLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *GetAgentAuditStatusLogic) GetAgentAuditStatus(req *types.AgentAuditStatusReq) (resp *types.AgentAuditStatusResp, err error) {
|
|
||||||
// todo: add your logic here and delete this line
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package agent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"github.com/jinzhu/copier"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"qnc-server/common/ctxdata"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GetAgentInfoLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGetAgentInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentInfoLogic {
|
|
||||||
return &GetAgentInfoLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *GetAgentInfoLogic) GetAgentInfo() (resp *types.AgentInfoResp, err error) {
|
|
||||||
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理信息, %+v", err)
|
|
||||||
}
|
|
||||||
agent, err := l.svcCtx.AgentModel.FindOneByUserId(l.ctx, userID)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
|
||||||
return &types.AgentInfoResp{
|
|
||||||
IsAgent: false,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取代理信息, %+v", err)
|
|
||||||
}
|
|
||||||
copier.Copy(&resp, agent)
|
|
||||||
resp.IsAgent = true
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
@@ -3,13 +3,14 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
dysmsapi "github.com/alibabacloud-go/dysmsapi-20170525/v3/client"
|
dysmsapi "github.com/alibabacloud-go/dysmsapi-20170525/v3/client"
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package notification
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package pay
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/smartwalle/alipay/v3"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
|
"github.com/smartwalle/alipay/v3"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AlipayCallbackLogic struct {
|
type AlipayCallbackLogic struct {
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ package pay
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
"qnc-server/app/user/model"
|
"tyc-server/app/user/model"
|
||||||
"qnc-server/common/ctxdata"
|
"tyc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"tyc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/service"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type WechatPayCallbackLogic struct {
|
type WechatPayCallbackLogic struct {
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package pay
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"net/http"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type WechatPayRefundCallbackLogic struct {
|
type WechatPayRefundCallbackLogic struct {
|
||||||
|
|||||||
@@ -2,15 +2,16 @@ package product
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/mr"
|
"github.com/zeromicro/go-zero/core/mr"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package product
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ package product
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/mr"
|
"github.com/zeromicro/go-zero/core/mr"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,16 +5,17 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
|
"tyc-server/pkg/lzkit/delay"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
|
||||||
"qnc-server/pkg/lzkit/delay"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ package query
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"time"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
"tyc-server/pkg/lzkit/delay"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"qnc-server/pkg/lzkit/delay"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"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"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package query
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
"qnc-server/common/xerr"
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ package query
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/ctxdata"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/ctxdata"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type QueryListLogic struct {
|
type QueryListLogic struct {
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/ctxdata"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/ctxdata"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ package query
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/pkg/errors"
|
"tyc-server/common/xerr"
|
||||||
"qnc-server/common/xerr"
|
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,18 +5,18 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
|
||||||
"qnc-server/common/ctxdata"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
|
||||||
"qnc-server/pkg/lzkit/validator"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/service"
|
||||||
|
"tyc-server/common/ctxdata"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
|
"tyc-server/pkg/lzkit/validator"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ package query
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DecryptMobileLogic struct {
|
type DecryptMobileLogic struct {
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/common/ctxdata"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/common/ctxdata"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"qnc-server/common/ctxdata"
|
|
||||||
jwtx "qnc-server/common/jwt"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/common/ctxdata"
|
||||||
|
jwtx "tyc-server/common/jwt"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,15 +3,16 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
jwtx "tyc-server/common/jwt"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
jwtx "qnc-server/common/jwt"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,16 +2,17 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
jwtx "qnc-server/common/jwt"
|
|
||||||
"qnc-server/common/tool"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
jwtx "tyc-server/common/jwt"
|
||||||
|
"tyc-server/common/tool"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,17 +3,18 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
jwtx "tyc-server/common/jwt"
|
||||||
|
"tyc-server/common/tool"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
jwtx "qnc-server/common/jwt"
|
|
||||||
"qnc-server/common/tool"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,16 +4,17 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
jwtx "qnc-server/common/jwt"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
jwtx "tyc-server/common/jwt"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"github.com/pkg/errors"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,17 +4,18 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
jwtx "qnc-server/common/jwt"
|
|
||||||
"qnc-server/common/xerr"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
jwtx "tyc-server/common/jwt"
|
||||||
|
"tyc-server/common/xerr"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package queue
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package queue
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const TASKTIME = "0 2 * * *"
|
const TASKTIME = "0 2 * * *"
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/model"
|
"tyc-server/app/user/model"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package queue
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smartwalle/alipay/v3"
|
|
||||||
mathrand "math/rand"
|
mathrand "math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
|
"github.com/smartwalle/alipay/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AliPayService struct {
|
type AliPayService struct {
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/bytedance/sonic"
|
"github.com/bytedance/sonic"
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang-jwt/jwt/v4"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
|
||||||
|
"github.com/golang-jwt/jwt/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ApplePayService 是 Apple IAP 支付服务的结构体
|
// ApplePayService 是 Apple IAP 支付服务的结构体
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/types"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package service
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VerificationService struct {
|
type VerificationService struct {
|
||||||
|
|||||||
@@ -3,6 +3,14 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
"tyc-server/app/user/model"
|
||||||
|
"tyc-server/common/ctxdata"
|
||||||
|
"tyc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
|
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/core/downloader"
|
"github.com/wechatpay-apiv3/wechatpay-go/core/downloader"
|
||||||
@@ -14,13 +22,6 @@ import (
|
|||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"net/http"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
"tyc-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
"qnc-server/app/user/cmd/api/internal/middleware"
|
"tyc-server/app/user/cmd/api/internal/middleware"
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"tyc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/model"
|
"tyc-server/app/user/model"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
@@ -25,11 +25,6 @@ type ServiceContext struct {
|
|||||||
ProductRenderModel model.ProductRenderModel
|
ProductRenderModel model.ProductRenderModel
|
||||||
OrderModel model.OrderModel
|
OrderModel model.OrderModel
|
||||||
QueryModel model.QueryModel
|
QueryModel model.QueryModel
|
||||||
AgentModel model.AgentModel
|
|
||||||
AgentAuditModel model.AgentAuditModel
|
|
||||||
AgentClosureModel model.AgentClosureModel
|
|
||||||
AgentCommissionModel model.AgentCommissionModel
|
|
||||||
AgentWalletModel model.AgentWalletModel
|
|
||||||
GlobalNotificationsModel model.GlobalNotificationsModel
|
GlobalNotificationsModel model.GlobalNotificationsModel
|
||||||
ExampleModel model.ExampleModel
|
ExampleModel model.ExampleModel
|
||||||
AlipayService *service.AliPayService
|
AlipayService *service.AliPayService
|
||||||
@@ -89,11 +84,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
QueryModel: model.NewQueryModel(db, c.CacheRedis),
|
QueryModel: model.NewQueryModel(db, c.CacheRedis),
|
||||||
ExampleModel: model.NewExampleModel(db, c.CacheRedis),
|
ExampleModel: model.NewExampleModel(db, c.CacheRedis),
|
||||||
GlobalNotificationsModel: model.NewGlobalNotificationsModel(db, c.CacheRedis),
|
GlobalNotificationsModel: model.NewGlobalNotificationsModel(db, c.CacheRedis),
|
||||||
AgentModel: model.NewAgentModel(db, c.CacheRedis),
|
|
||||||
AgentAuditModel: model.NewAgentAuditModel(db, c.CacheRedis),
|
|
||||||
AgentCommissionModel: model.NewAgentCommissionModel(db, c.CacheRedis),
|
|
||||||
AgentWalletModel: model.NewAgentWalletModel(db, c.CacheRedis),
|
|
||||||
AgentClosureModel: model.NewAgentClosureModel(db, c.CacheRedis),
|
|
||||||
FeatureModel: featureModel,
|
FeatureModel: featureModel,
|
||||||
ProductFeatureModel: productFeatureModel,
|
ProductFeatureModel: productFeatureModel,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,6 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
package types
|
package types
|
||||||
|
|
||||||
type AgentApplyReq struct {
|
|
||||||
UserID int64 `json:"user_id"`
|
|
||||||
Region string `json:"region"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
WechatID string `json:"wechat_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AgentApplyResp struct {
|
|
||||||
Status string `json:"status"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AgentAuditStatusReq struct {
|
|
||||||
UserID int64 `json:"user_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AgentAuditStatusResp struct {
|
|
||||||
Status int `json:"status"` // 0=待审核,1=审核通过,2=审核未通过
|
|
||||||
AuditReason string `json:"audit_reason"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AgentInfoResp struct {
|
|
||||||
IsAgent bool `json:"is_agent"`
|
|
||||||
Region string `json:"region"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
WechatID string `json:"wechat_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Feature struct {
|
type Feature struct {
|
||||||
ID int64 `json:"id"` // 功能ID
|
ID int64 `json:"id"` // 功能ID
|
||||||
ApiID string `json:"api_id"` // API标识
|
ApiID string `json:"api_id"` // API标识
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
"tyc-server/app/user/cmd/api/internal/config"
|
||||||
"qnc-server/app/user/cmd/api/internal/handler"
|
"tyc-server/app/user/cmd/api/internal/handler"
|
||||||
"qnc-server/app/user/cmd/api/internal/queue"
|
"tyc-server/app/user/cmd/api/internal/queue"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"tyc-server/app/user/cmd/api/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AgentAuditModel = (*customAgentAuditModel)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// AgentAuditModel is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in customAgentAuditModel.
|
|
||||||
AgentAuditModel interface {
|
|
||||||
agentAuditModel
|
|
||||||
}
|
|
||||||
|
|
||||||
customAgentAuditModel struct {
|
|
||||||
*defaultAgentAuditModel
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewAgentAuditModel returns a model for the database table.
|
|
||||||
func NewAgentAuditModel(conn sqlx.SqlConn, c cache.CacheConf) AgentAuditModel {
|
|
||||||
return &customAgentAuditModel{
|
|
||||||
defaultAgentAuditModel: newAgentAuditModel(conn, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,374 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT!
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"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"
|
|
||||||
"qnc-server/common/globalkey"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
agentAuditFieldNames = builder.RawFieldNames(&AgentAudit{})
|
|
||||||
agentAuditRows = strings.Join(agentAuditFieldNames, ",")
|
|
||||||
agentAuditRowsExpectAutoSet = strings.Join(stringx.Remove(agentAuditFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
|
||||||
agentAuditRowsWithPlaceHolder = strings.Join(stringx.Remove(agentAuditFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
||||||
|
|
||||||
cacheQncAgentAuditIdPrefix = "cache:qnc:agentAudit:id:"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
agentAuditModel interface {
|
|
||||||
Insert(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error)
|
|
||||||
FindOne(ctx context.Context, id int64) (*AgentAudit, error)
|
|
||||||
Update(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error)
|
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentAudit) 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 *AgentAudit) 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) ([]*AgentAudit, error)
|
|
||||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, error)
|
|
||||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, int64, error)
|
|
||||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentAudit, error)
|
|
||||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentAudit, error)
|
|
||||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAgentAuditModel struct {
|
|
||||||
sqlc.CachedConn
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
AgentAudit struct {
|
|
||||||
Id int64 `db:"id"`
|
|
||||||
UserId int64 `db:"user_id"`
|
|
||||||
Region string `db:"region"`
|
|
||||||
Mobile string `db:"mobile"`
|
|
||||||
WechatId sql.NullString `db:"wechat_id"`
|
|
||||||
Status int64 `db:"status"`
|
|
||||||
AuditReason sql.NullString `db:"audit_reason"`
|
|
||||||
CreateTime time.Time `db:"create_time"`
|
|
||||||
AuditTime sql.NullTime `db:"audit_time"`
|
|
||||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
|
||||||
Version int64 `db:"version"` // 版本号
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func newAgentAuditModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentAuditModel {
|
|
||||||
return &defaultAgentAuditModel{
|
|
||||||
CachedConn: sqlc.NewConn(conn, c),
|
|
||||||
table: "`agent_audit`",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) Insert(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error) {
|
|
||||||
data.DelState = globalkey.DelStateNo
|
|
||||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, data.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, agentAuditRowsExpectAutoSet)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}, qncAgentAuditIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) FindOne(ctx context.Context, id int64) (*AgentAudit, error) {
|
|
||||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, id)
|
|
||||||
var resp AgentAudit
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncAgentAuditIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", agentAuditRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
|
||||||
})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, model.ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) Update(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error) {
|
|
||||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, 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, agentAuditRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id)
|
|
||||||
}, qncAgentAuditIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentAudit) error {
|
|
||||||
|
|
||||||
oldVersion := data.Version
|
|
||||||
data.Version += 1
|
|
||||||
|
|
||||||
var sqlResult sql.Result
|
|
||||||
var err error
|
|
||||||
|
|
||||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, 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, agentAuditRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
|
||||||
}, qncAgentAuditIdKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updateCount, err := sqlResult.RowsAffected()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if updateCount == 0 {
|
|
||||||
return model.ErrNoRowsUpdate
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentAudit) 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 "), "AgentAuditModel delete err : %+v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) 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 *defaultAgentAuditModel) 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 *defaultAgentAuditModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentAudit, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentAuditRows)
|
|
||||||
|
|
||||||
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 []*AgentAudit
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentAuditRows)
|
|
||||||
|
|
||||||
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 []*AgentAudit
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, int64, error) {
|
|
||||||
|
|
||||||
total, err := m.FindCount(ctx, builder, "id")
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns(agentAuditRows)
|
|
||||||
|
|
||||||
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, total, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AgentAudit
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, total, nil
|
|
||||||
default:
|
|
||||||
return nil, total, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentAudit, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentAuditRows)
|
|
||||||
|
|
||||||
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 []*AgentAudit
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentAudit, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentAuditRows)
|
|
||||||
|
|
||||||
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 []*AgentAudit
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) 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 *defaultAgentAuditModel) SelectBuilder() squirrel.SelectBuilder {
|
|
||||||
return squirrel.Select().From(m.table)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentAuditModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
|
||||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, 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)
|
|
||||||
}, qncAgentAuditIdKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (m *defaultAgentAuditModel) formatPrimary(primary interface{}) string {
|
|
||||||
return fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, primary)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentAuditModel) 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", agentAuditRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentAuditModel) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AgentClosureModel = (*customAgentClosureModel)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// AgentClosureModel is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in customAgentClosureModel.
|
|
||||||
AgentClosureModel interface {
|
|
||||||
agentClosureModel
|
|
||||||
}
|
|
||||||
|
|
||||||
customAgentClosureModel struct {
|
|
||||||
*defaultAgentClosureModel
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewAgentClosureModel returns a model for the database table.
|
|
||||||
func NewAgentClosureModel(conn sqlx.SqlConn, c cache.CacheConf) AgentClosureModel {
|
|
||||||
return &customAgentClosureModel{
|
|
||||||
defaultAgentClosureModel: newAgentClosureModel(conn, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,409 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT!
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"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"
|
|
||||||
"qnc-server/common/globalkey"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
agentClosureFieldNames = builder.RawFieldNames(&AgentClosure{})
|
|
||||||
agentClosureRows = strings.Join(agentClosureFieldNames, ",")
|
|
||||||
agentClosureRowsExpectAutoSet = strings.Join(stringx.Remove(agentClosureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
|
||||||
agentClosureRowsWithPlaceHolder = strings.Join(stringx.Remove(agentClosureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
||||||
|
|
||||||
cacheQncAgentClosureIdPrefix = "cache:qnc:agentClosure:id:"
|
|
||||||
cacheQncAgentClosureAncestorIdDescendantIdPrefix = "cache:qnc:agentClosure:ancestorId:descendantId:"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
agentClosureModel interface {
|
|
||||||
Insert(ctx context.Context, session sqlx.Session, data *AgentClosure) (sql.Result, error)
|
|
||||||
FindOne(ctx context.Context, id int64) (*AgentClosure, error)
|
|
||||||
FindOneByAncestorIdDescendantId(ctx context.Context, ancestorId int64, descendantId int64) (*AgentClosure, error)
|
|
||||||
Update(ctx context.Context, session sqlx.Session, data *AgentClosure) (sql.Result, error)
|
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentClosure) 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 *AgentClosure) 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) ([]*AgentClosure, error)
|
|
||||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, error)
|
|
||||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, int64, error)
|
|
||||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentClosure, error)
|
|
||||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentClosure, error)
|
|
||||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAgentClosureModel struct {
|
|
||||||
sqlc.CachedConn
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
AgentClosure struct {
|
|
||||||
Id int64 `db:"id"`
|
|
||||||
AncestorId int64 `db:"ancestor_id"`
|
|
||||||
DescendantId int64 `db:"descendant_id"`
|
|
||||||
Depth int64 `db:"depth"`
|
|
||||||
CreateTime time.Time `db:"create_time"`
|
|
||||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
|
||||||
Version int64 `db:"version"` // 版本号
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func newAgentClosureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentClosureModel {
|
|
||||||
return &defaultAgentClosureModel{
|
|
||||||
CachedConn: sqlc.NewConn(conn, c),
|
|
||||||
table: "`agent_closure`",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) Insert(ctx context.Context, session sqlx.Session, data *AgentClosure) (sql.Result, error) {
|
|
||||||
data.DelState = globalkey.DelStateNo
|
|
||||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
|
||||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, data.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, agentClosureRowsExpectAutoSet)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.AncestorId, data.DescendantId, data.Depth, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.AncestorId, data.DescendantId, data.Depth, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) FindOne(ctx context.Context, id int64) (*AgentClosure, error) {
|
|
||||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, id)
|
|
||||||
var resp AgentClosure
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncAgentClosureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", agentClosureRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
|
||||||
})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, model.ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) FindOneByAncestorIdDescendantId(ctx context.Context, ancestorId int64, descendantId int64) (*AgentClosure, error) {
|
|
||||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, ancestorId, descendantId)
|
|
||||||
var resp AgentClosure
|
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncAgentClosureAncestorIdDescendantIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `ancestor_id` = ? AND `descendant_id` = ? AND del_state = ? limit 1", agentClosureRows, m.table)
|
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, ancestorId, descendantId, globalkey.DelStateNo); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Id, nil
|
|
||||||
}, m.queryPrimary)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, model.ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) Update(ctx context.Context, session sqlx.Session, newData *AgentClosure) (sql.Result, error) {
|
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
|
||||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, 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, agentClosureRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
|
||||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *AgentClosure) error {
|
|
||||||
|
|
||||||
oldVersion := newData.Version
|
|
||||||
newData.Version += 1
|
|
||||||
|
|
||||||
var sqlResult sql.Result
|
|
||||||
var err error
|
|
||||||
|
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
|
||||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, 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, agentClosureRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
|
||||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updateCount, err := sqlResult.RowsAffected()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if updateCount == 0 {
|
|
||||||
return model.ErrNoRowsUpdate
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentClosure) 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 "), "AgentClosureModel delete err : %+v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) 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 *defaultAgentClosureModel) 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 *defaultAgentClosureModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentClosure, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentClosureRows)
|
|
||||||
|
|
||||||
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 []*AgentClosure
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentClosureRows)
|
|
||||||
|
|
||||||
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 []*AgentClosure
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, int64, error) {
|
|
||||||
|
|
||||||
total, err := m.FindCount(ctx, builder, "id")
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns(agentClosureRows)
|
|
||||||
|
|
||||||
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, total, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AgentClosure
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, total, nil
|
|
||||||
default:
|
|
||||||
return nil, total, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentClosure, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentClosureRows)
|
|
||||||
|
|
||||||
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 []*AgentClosure
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentClosure, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentClosureRows)
|
|
||||||
|
|
||||||
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 []*AgentClosure
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) 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 *defaultAgentClosureModel) SelectBuilder() squirrel.SelectBuilder {
|
|
||||||
return squirrel.Select().From(m.table)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentClosureModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
|
||||||
data, err := m.FindOne(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
|
||||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, 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)
|
|
||||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (m *defaultAgentClosureModel) formatPrimary(primary interface{}) string {
|
|
||||||
return fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, primary)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentClosureModel) 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", agentClosureRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentClosureModel) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AgentCommissionModel = (*customAgentCommissionModel)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// AgentCommissionModel is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in customAgentCommissionModel.
|
|
||||||
AgentCommissionModel interface {
|
|
||||||
agentCommissionModel
|
|
||||||
}
|
|
||||||
|
|
||||||
customAgentCommissionModel struct {
|
|
||||||
*defaultAgentCommissionModel
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewAgentCommissionModel returns a model for the database table.
|
|
||||||
func NewAgentCommissionModel(conn sqlx.SqlConn, c cache.CacheConf) AgentCommissionModel {
|
|
||||||
return &customAgentCommissionModel{
|
|
||||||
defaultAgentCommissionModel: newAgentCommissionModel(conn, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT!
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"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"
|
|
||||||
"qnc-server/common/globalkey"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
agentCommissionFieldNames = builder.RawFieldNames(&AgentCommission{})
|
|
||||||
agentCommissionRows = strings.Join(agentCommissionFieldNames, ",")
|
|
||||||
agentCommissionRowsExpectAutoSet = strings.Join(stringx.Remove(agentCommissionFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
|
||||||
agentCommissionRowsWithPlaceHolder = strings.Join(stringx.Remove(agentCommissionFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
||||||
|
|
||||||
cacheQncAgentCommissionIdPrefix = "cache:qnc:agentCommission:id:"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
agentCommissionModel interface {
|
|
||||||
Insert(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error)
|
|
||||||
FindOne(ctx context.Context, id int64) (*AgentCommission, error)
|
|
||||||
Update(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error)
|
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommission) 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 *AgentCommission) 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) ([]*AgentCommission, error)
|
|
||||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, error)
|
|
||||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, int64, error)
|
|
||||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentCommission, error)
|
|
||||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentCommission, error)
|
|
||||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAgentCommissionModel struct {
|
|
||||||
sqlc.CachedConn
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
AgentCommission struct {
|
|
||||||
Id int64 `db:"id"`
|
|
||||||
AgentId int64 `db:"agent_id"`
|
|
||||||
OrderId int64 `db:"order_id"`
|
|
||||||
CommissionAmount float64 `db:"commission_amount"`
|
|
||||||
Status int64 `db:"status"`
|
|
||||||
CreateTime time.Time `db:"create_time"`
|
|
||||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
|
||||||
Version int64 `db:"version"` // 版本号
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func newAgentCommissionModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentCommissionModel {
|
|
||||||
return &defaultAgentCommissionModel{
|
|
||||||
CachedConn: sqlc.NewConn(conn, c),
|
|
||||||
table: "`agent_commission`",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) Insert(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error) {
|
|
||||||
data.DelState = globalkey.DelStateNo
|
|
||||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, data.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, agentCommissionRowsExpectAutoSet)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}, qncAgentCommissionIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) FindOne(ctx context.Context, id int64) (*AgentCommission, error) {
|
|
||||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, id)
|
|
||||||
var resp AgentCommission
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncAgentCommissionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", agentCommissionRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
|
||||||
})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, model.ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) Update(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error) {
|
|
||||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, 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, agentCommissionRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
|
||||||
}, qncAgentCommissionIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommission) error {
|
|
||||||
|
|
||||||
oldVersion := data.Version
|
|
||||||
data.Version += 1
|
|
||||||
|
|
||||||
var sqlResult sql.Result
|
|
||||||
var err error
|
|
||||||
|
|
||||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, 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, agentCommissionRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
|
||||||
}, qncAgentCommissionIdKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updateCount, err := sqlResult.RowsAffected()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if updateCount == 0 {
|
|
||||||
return model.ErrNoRowsUpdate
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentCommission) 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 "), "AgentCommissionModel delete err : %+v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) 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 *defaultAgentCommissionModel) 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 *defaultAgentCommissionModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentCommission, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentCommissionRows)
|
|
||||||
|
|
||||||
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 []*AgentCommission
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentCommissionRows)
|
|
||||||
|
|
||||||
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 []*AgentCommission
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, int64, error) {
|
|
||||||
|
|
||||||
total, err := m.FindCount(ctx, builder, "id")
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns(agentCommissionRows)
|
|
||||||
|
|
||||||
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, total, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AgentCommission
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, total, nil
|
|
||||||
default:
|
|
||||||
return nil, total, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentCommission, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentCommissionRows)
|
|
||||||
|
|
||||||
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 []*AgentCommission
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentCommission, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentCommissionRows)
|
|
||||||
|
|
||||||
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 []*AgentCommission
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) 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 *defaultAgentCommissionModel) SelectBuilder() squirrel.SelectBuilder {
|
|
||||||
return squirrel.Select().From(m.table)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentCommissionModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
|
||||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, 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)
|
|
||||||
}, qncAgentCommissionIdKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (m *defaultAgentCommissionModel) formatPrimary(primary interface{}) string {
|
|
||||||
return fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, primary)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentCommissionModel) 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", agentCommissionRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentCommissionModel) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AgentModel = (*customAgentModel)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// AgentModel is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in customAgentModel.
|
|
||||||
AgentModel interface {
|
|
||||||
agentModel
|
|
||||||
}
|
|
||||||
|
|
||||||
customAgentModel struct {
|
|
||||||
*defaultAgentModel
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewAgentModel returns a model for the database table.
|
|
||||||
func NewAgentModel(conn sqlx.SqlConn, c cache.CacheConf) AgentModel {
|
|
||||||
return &customAgentModel{
|
|
||||||
defaultAgentModel: newAgentModel(conn, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,409 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT!
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"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"
|
|
||||||
"qnc-server/common/globalkey"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
agentFieldNames = builder.RawFieldNames(&Agent{})
|
|
||||||
agentRows = strings.Join(agentFieldNames, ",")
|
|
||||||
agentRowsExpectAutoSet = strings.Join(stringx.Remove(agentFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
|
||||||
agentRowsWithPlaceHolder = strings.Join(stringx.Remove(agentFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
||||||
|
|
||||||
cacheQncAgentIdPrefix = "cache:qnc:agent:id:"
|
|
||||||
cacheQncAgentUserIdPrefix = "cache:qnc:agent:userId:"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
agentModel interface {
|
|
||||||
Insert(ctx context.Context, session sqlx.Session, data *Agent) (sql.Result, error)
|
|
||||||
FindOne(ctx context.Context, id int64) (*Agent, error)
|
|
||||||
FindOneByUserId(ctx context.Context, userId int64) (*Agent, error)
|
|
||||||
Update(ctx context.Context, session sqlx.Session, data *Agent) (sql.Result, error)
|
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *Agent) 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 *Agent) 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) ([]*Agent, error)
|
|
||||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, error)
|
|
||||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, int64, error)
|
|
||||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*Agent, error)
|
|
||||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*Agent, error)
|
|
||||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAgentModel struct {
|
|
||||||
sqlc.CachedConn
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
Agent struct {
|
|
||||||
Id int64 `db:"id"`
|
|
||||||
UserId int64 `db:"user_id"`
|
|
||||||
Region string `db:"region"`
|
|
||||||
Mobile string `db:"mobile"`
|
|
||||||
WechatId sql.NullString `db:"wechat_id"`
|
|
||||||
CreateTime time.Time `db:"create_time"`
|
|
||||||
UpdateTime time.Time `db:"update_time"`
|
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
|
||||||
Version int64 `db:"version"` // 版本号
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func newAgentModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentModel {
|
|
||||||
return &defaultAgentModel{
|
|
||||||
CachedConn: sqlc.NewConn(conn, c),
|
|
||||||
table: "`agent`",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) Insert(ctx context.Context, session sqlx.Session, data *Agent) (sql.Result, error) {
|
|
||||||
data.DelState = globalkey.DelStateNo
|
|
||||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, data.Id)
|
|
||||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
|
||||||
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, agentRowsExpectAutoSet)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) FindOne(ctx context.Context, id int64) (*Agent, error) {
|
|
||||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, id)
|
|
||||||
var resp Agent
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncAgentIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentRows, 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 *defaultAgentModel) FindOneByUserId(ctx context.Context, userId int64) (*Agent, error) {
|
|
||||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, userId)
|
|
||||||
var resp Agent
|
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncAgentUserIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
|
||||||
query := fmt.Sprintf("select %s from %s where `user_id` = ? and del_state = ? limit 1", agentRows, m.table)
|
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, userId, globalkey.DelStateNo); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Id, nil
|
|
||||||
}, m.queryPrimary)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) Update(ctx context.Context, session sqlx.Session, newData *Agent) (sql.Result, error) {
|
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, data.Id)
|
|
||||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
|
||||||
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, agentRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
|
||||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Agent) error {
|
|
||||||
|
|
||||||
oldVersion := newData.Version
|
|
||||||
newData.Version += 1
|
|
||||||
|
|
||||||
var sqlResult sql.Result
|
|
||||||
var err error
|
|
||||||
|
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, data.Id)
|
|
||||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
|
||||||
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, agentRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
|
||||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updateCount, err := sqlResult.RowsAffected()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if updateCount == 0 {
|
|
||||||
return ErrNoRowsUpdate
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *Agent) 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 "), "AgentModel delete err : %+v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) 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 *defaultAgentModel) 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 *defaultAgentModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*Agent, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentRows)
|
|
||||||
|
|
||||||
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 []*Agent
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentRows)
|
|
||||||
|
|
||||||
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 []*Agent
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, int64, error) {
|
|
||||||
|
|
||||||
total, err := m.FindCount(ctx, builder, "id")
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns(agentRows)
|
|
||||||
|
|
||||||
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, total, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*Agent
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, total, nil
|
|
||||||
default:
|
|
||||||
return nil, total, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*Agent, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentRows)
|
|
||||||
|
|
||||||
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 []*Agent
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*Agent, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentRows)
|
|
||||||
|
|
||||||
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 []*Agent
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) 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 *defaultAgentModel) SelectBuilder() squirrel.SelectBuilder {
|
|
||||||
return squirrel.Select().From(m.table)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
|
||||||
data, err := m.FindOne(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, id)
|
|
||||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
|
||||||
_, 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)
|
|
||||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (m *defaultAgentModel) formatPrimary(primary interface{}) string {
|
|
||||||
return fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, primary)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentModel) 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", agentRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentModel) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AgentWalletModel = (*customAgentWalletModel)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// AgentWalletModel is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in customAgentWalletModel.
|
|
||||||
AgentWalletModel interface {
|
|
||||||
agentWalletModel
|
|
||||||
}
|
|
||||||
|
|
||||||
customAgentWalletModel struct {
|
|
||||||
*defaultAgentWalletModel
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewAgentWalletModel returns a model for the database table.
|
|
||||||
func NewAgentWalletModel(conn sqlx.SqlConn, c cache.CacheConf) AgentWalletModel {
|
|
||||||
return &customAgentWalletModel{
|
|
||||||
defaultAgentWalletModel: newAgentWalletModel(conn, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,372 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT!
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"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"
|
|
||||||
"qnc-server/common/globalkey"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
agentWalletFieldNames = builder.RawFieldNames(&AgentWallet{})
|
|
||||||
agentWalletRows = strings.Join(agentWalletFieldNames, ",")
|
|
||||||
agentWalletRowsExpectAutoSet = strings.Join(stringx.Remove(agentWalletFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
|
||||||
agentWalletRowsWithPlaceHolder = strings.Join(stringx.Remove(agentWalletFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
||||||
|
|
||||||
cacheQncAgentWalletIdPrefix = "cache:qnc:agentWallet:id:"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
agentWalletModel interface {
|
|
||||||
Insert(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error)
|
|
||||||
FindOne(ctx context.Context, id int64) (*AgentWallet, error)
|
|
||||||
Update(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error)
|
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentWallet) 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 *AgentWallet) 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) ([]*AgentWallet, error)
|
|
||||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, error)
|
|
||||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, int64, error)
|
|
||||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentWallet, error)
|
|
||||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentWallet, error)
|
|
||||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAgentWalletModel struct {
|
|
||||||
sqlc.CachedConn
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
AgentWallet struct {
|
|
||||||
Id int64 `db:"id"`
|
|
||||||
AgentId int64 `db:"agent_id"`
|
|
||||||
Balance float64 `db:"balance"`
|
|
||||||
FrozenBalance float64 `db:"frozen_balance"`
|
|
||||||
TotalEarnings float64 `db:"total_earnings"`
|
|
||||||
WithdrawnAmount float64 `db:"withdrawn_amount"`
|
|
||||||
CreateTime time.Time `db:"create_time"`
|
|
||||||
UpdateTime time.Time `db:"update_time"`
|
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
|
||||||
Version int64 `db:"version"` // 版本号
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func newAgentWalletModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentWalletModel {
|
|
||||||
return &defaultAgentWalletModel{
|
|
||||||
CachedConn: sqlc.NewConn(conn, c),
|
|
||||||
table: "`agent_wallet`",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) Insert(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error) {
|
|
||||||
data.DelState = globalkey.DelStateNo
|
|
||||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, data.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, agentWalletRowsExpectAutoSet)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version)
|
|
||||||
}, qncAgentWalletIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) FindOne(ctx context.Context, id int64) (*AgentWallet, error) {
|
|
||||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, id)
|
|
||||||
var resp AgentWallet
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncAgentWalletIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", agentWalletRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
|
||||||
})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, model.ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) Update(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error) {
|
|
||||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, 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, agentWalletRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id)
|
|
||||||
}, qncAgentWalletIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentWallet) error {
|
|
||||||
|
|
||||||
oldVersion := data.Version
|
|
||||||
data.Version += 1
|
|
||||||
|
|
||||||
var sqlResult sql.Result
|
|
||||||
var err error
|
|
||||||
|
|
||||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, 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, agentWalletRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
|
||||||
}, qncAgentWalletIdKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updateCount, err := sqlResult.RowsAffected()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if updateCount == 0 {
|
|
||||||
return model.ErrNoRowsUpdate
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentWallet) 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 "), "AgentWalletModel delete err : %+v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) 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 *defaultAgentWalletModel) 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 *defaultAgentWalletModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentWallet, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentWalletRows)
|
|
||||||
|
|
||||||
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 []*AgentWallet
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentWalletRows)
|
|
||||||
|
|
||||||
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 []*AgentWallet
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, int64, error) {
|
|
||||||
|
|
||||||
total, err := m.FindCount(ctx, builder, "id")
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns(agentWalletRows)
|
|
||||||
|
|
||||||
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, total, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AgentWallet
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, total, nil
|
|
||||||
default:
|
|
||||||
return nil, total, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentWallet, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentWalletRows)
|
|
||||||
|
|
||||||
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 []*AgentWallet
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentWallet, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(agentWalletRows)
|
|
||||||
|
|
||||||
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 []*AgentWallet
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) 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 *defaultAgentWalletModel) SelectBuilder() squirrel.SelectBuilder {
|
|
||||||
return squirrel.Select().From(m.table)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentWalletModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
|
||||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, 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)
|
|
||||||
}, qncAgentWalletIdKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (m *defaultAgentWalletModel) formatPrimary(primary interface{}) string {
|
|
||||||
return fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, primary)
|
|
||||||
}
|
|
||||||
func (m *defaultAgentWalletModel) 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", agentWalletRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAgentWalletModel) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -26,8 +26,8 @@ var (
|
|||||||
exampleRowsExpectAutoSet = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
exampleRowsExpectAutoSet = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
exampleRowsWithPlaceHolder = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
exampleRowsWithPlaceHolder = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncExampleIdPrefix = "cache:qnc:example:id:"
|
cacheTycExampleIdPrefix = "cache:tyc:example:id:"
|
||||||
cacheQncExampleProductIdPrefix = "cache:qnc:example:productId:"
|
cacheTycExampleProductIdPrefix = "cache:tyc:example:productId:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -77,21 +77,21 @@ func newExampleModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultExampleModel
|
|||||||
|
|
||||||
func (m *defaultExampleModel) Insert(ctx context.Context, session sqlx.Session, data *Example) (sql.Result, error) {
|
func (m *defaultExampleModel) Insert(ctx context.Context, session sqlx.Session, data *Example) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, exampleRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, exampleRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
return session.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
return conn.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
||||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultExampleModel) FindOne(ctx context.Context, id int64) (*Example, error) {
|
func (m *defaultExampleModel) FindOne(ctx context.Context, id int64) (*Example, error) {
|
||||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, id)
|
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, id)
|
||||||
var resp Example
|
var resp Example
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncExampleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycExampleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
@@ -106,9 +106,9 @@ func (m *defaultExampleModel) FindOne(ctx context.Context, id int64) (*Example,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultExampleModel) FindOneByProductId(ctx context.Context, productId int64) (*Example, error) {
|
func (m *defaultExampleModel) FindOneByProductId(ctx context.Context, productId int64) (*Example, error) {
|
||||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, productId)
|
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, productId)
|
||||||
var resp Example
|
var resp Example
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncExampleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
err := m.QueryRowIndexCtx(ctx, &resp, tycExampleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
query := fmt.Sprintf("select %s from %s where `product_id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `product_id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, globalkey.DelStateNo); err != nil {
|
if err := conn.QueryRowCtx(ctx, &resp, query, productId, globalkey.DelStateNo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -130,15 +130,15 @@ func (m *defaultExampleModel) Update(ctx context.Context, session sqlx.Session,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, exampleRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, exampleRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultExampleModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Example) error {
|
func (m *defaultExampleModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Example) error {
|
||||||
@@ -153,15 +153,15 @@ func (m *defaultExampleModel) UpdateWithVersion(ctx context.Context, session sql
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, exampleRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, exampleRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -384,19 +384,19 @@ func (m *defaultExampleModel) Delete(ctx context.Context, session sqlx.Session,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, id)
|
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, id)
|
||||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultExampleModel) formatPrimary(primary interface{}) string {
|
func (m *defaultExampleModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultExampleModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultExampleModel) 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", exampleRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
@@ -18,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -27,8 +26,8 @@ var (
|
|||||||
featureRowsExpectAutoSet = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
featureRowsExpectAutoSet = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
featureRowsWithPlaceHolder = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
featureRowsWithPlaceHolder = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncFeatureIdPrefix = "cache:qnc:feature:id:"
|
cacheTycFeatureIdPrefix = "cache:tyc:feature:id:"
|
||||||
cacheQncFeatureApiIdPrefix = "cache:qnc:feature:apiId:"
|
cacheTycFeatureApiIdPrefix = "cache:tyc:feature:apiId:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -77,39 +76,39 @@ func newFeatureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultFeatureModel
|
|||||||
|
|
||||||
func (m *defaultFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *Feature) (sql.Result, error) {
|
func (m *defaultFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *Feature) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, data.Id)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, featureRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, featureRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultFeatureModel) FindOne(ctx context.Context, id int64) (*Feature, error) {
|
func (m *defaultFeatureModel) FindOne(ctx context.Context, id int64) (*Feature, error) {
|
||||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id)
|
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, id)
|
||||||
var resp Feature
|
var resp Feature
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", featureRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string) (*Feature, error) {
|
func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string) (*Feature, error) {
|
||||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, apiId)
|
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, apiId)
|
||||||
var resp Feature
|
var resp Feature
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
err := m.QueryRowIndexCtx(ctx, &resp, tycFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `api_id` = ? AND del_state = ? limit 1", featureRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `api_id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, apiId, globalkey.DelStateNo); err != nil {
|
if err := conn.QueryRowCtx(ctx, &resp, query, apiId, globalkey.DelStateNo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -119,7 +118,7 @@ func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string)
|
|||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -130,15 +129,15 @@ func (m *defaultFeatureModel) Update(ctx context.Context, session sqlx.Session,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, data.Id)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, featureRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, featureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Feature) error {
|
func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Feature) error {
|
||||||
@@ -153,15 +152,15 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, data.Id)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, featureRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, featureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -170,7 +169,7 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if updateCount == 0 {
|
if updateCount == 0 {
|
||||||
return model.ErrNoRowsUpdate
|
return ErrNoRowsUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -384,22 +383,22 @@ func (m *defaultFeatureModel) Delete(ctx context.Context, session sqlx.Session,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id)
|
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, id)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultFeatureModel) formatPrimary(primary interface{}) string {
|
func (m *defaultFeatureModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultFeatureModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultFeatureModel) 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", featureRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
model2 "qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
@@ -18,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -27,7 +26,7 @@ var (
|
|||||||
globalNotificationsRowsExpectAutoSet = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
globalNotificationsRowsExpectAutoSet = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
globalNotificationsRowsWithPlaceHolder = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
globalNotificationsRowsWithPlaceHolder = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncGlobalNotificationsIdPrefix = "cache:qnc:globalNotifications:id:"
|
cacheTycGlobalNotificationsIdPrefix = "cache:tyc:globalNotifications:id:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -81,20 +80,20 @@ func newGlobalNotificationsModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultG
|
|||||||
|
|
||||||
func (m *defaultGlobalNotificationsModel) Insert(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
func (m *defaultGlobalNotificationsModel) Insert(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, data.Id)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, globalNotificationsRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, globalNotificationsRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||||
}, qncGlobalNotificationsIdKey)
|
}, tycGlobalNotificationsIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64) (*GlobalNotifications, error) {
|
func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64) (*GlobalNotifications, error) {
|
||||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, id)
|
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, id)
|
||||||
var resp GlobalNotifications
|
var resp GlobalNotifications
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", globalNotificationsRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", globalNotificationsRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
@@ -102,21 +101,21 @@ func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64)
|
|||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model2.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultGlobalNotificationsModel) Update(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
func (m *defaultGlobalNotificationsModel) Update(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
||||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, data.Id)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, globalNotificationsRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, globalNotificationsRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||||
}, qncGlobalNotificationsIdKey)
|
}, tycGlobalNotificationsIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *GlobalNotifications) error {
|
func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *GlobalNotifications) error {
|
||||||
@@ -127,14 +126,14 @@ func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context,
|
|||||||
var sqlResult sql.Result
|
var sqlResult sql.Result
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, data.Id)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, globalNotificationsRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, globalNotificationsRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||||
}, qncGlobalNotificationsIdKey)
|
}, tycGlobalNotificationsIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -143,7 +142,7 @@ func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if updateCount == 0 {
|
if updateCount == 0 {
|
||||||
return model2.ErrNoRowsUpdate
|
return ErrNoRowsUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -352,18 +351,18 @@ func (m *defaultGlobalNotificationsModel) SelectBuilder() squirrel.SelectBuilder
|
|||||||
return squirrel.Select().From(m.table)
|
return squirrel.Select().From(m.table)
|
||||||
}
|
}
|
||||||
func (m *defaultGlobalNotificationsModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
func (m *defaultGlobalNotificationsModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, id)
|
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, id)
|
||||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncGlobalNotificationsIdKey)
|
}, tycGlobalNotificationsIdKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultGlobalNotificationsModel) formatPrimary(primary interface{}) string {
|
func (m *defaultGlobalNotificationsModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultGlobalNotificationsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultGlobalNotificationsModel) 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", globalNotificationsRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", globalNotificationsRows, m.table)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
@@ -18,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -27,8 +26,8 @@ var (
|
|||||||
orderRowsExpectAutoSet = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
orderRowsExpectAutoSet = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
orderRowsWithPlaceHolder = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
orderRowsWithPlaceHolder = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncOrderIdPrefix = "cache:qnc:order:id:"
|
cacheTycOrderIdPrefix = "cache:tyc:order:id:"
|
||||||
cacheQncOrderOrderNoPrefix = "cache:qnc:order:orderNo:"
|
cacheTycOrderOrderNoPrefix = "cache:tyc:order:orderNo:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -61,8 +60,8 @@ type (
|
|||||||
OrderNo string `db:"order_no"` // 自生成的订单号
|
OrderNo string `db:"order_no"` // 自生成的订单号
|
||||||
UserId int64 `db:"user_id"` // 用户ID
|
UserId int64 `db:"user_id"` // 用户ID
|
||||||
ProductId int64 `db:"product_id"` // 产品ID(软关联到产品表)
|
ProductId int64 `db:"product_id"` // 产品ID(软关联到产品表)
|
||||||
PaymentPlatform string `db:"payment_platform"` // 支付平台(支付宝、微信、其他)
|
PaymentPlatform string `db:"payment_platform"` // 支付平台(支付宝、微信、苹果内购、其他)
|
||||||
PaymentScene string `db:"payment_scene"` // 支付场景(App、H5、微信小程序、公众号)
|
PaymentScene string `db:"payment_scene"` // 支付场景(App、H5、微信小程序、公众号、天远查)
|
||||||
PlatformOrderId sql.NullString `db:"platform_order_id"` // 支付平台订单号
|
PlatformOrderId sql.NullString `db:"platform_order_id"` // 支付平台订单号
|
||||||
Amount float64 `db:"amount"` // 支付金额
|
Amount float64 `db:"amount"` // 支付金额
|
||||||
Status string `db:"status"` // 支付状态
|
Status string `db:"status"` // 支付状态
|
||||||
@@ -86,39 +85,39 @@ func newOrderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultOrderModel {
|
|||||||
|
|
||||||
func (m *defaultOrderModel) Insert(ctx context.Context, session sqlx.Session, data *Order) (sql.Result, error) {
|
func (m *defaultOrderModel) Insert(ctx context.Context, session sqlx.Session, data *Order) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, data.Id)
|
||||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, orderRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, orderRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
return session.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
return conn.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultOrderModel) FindOne(ctx context.Context, id int64) (*Order, error) {
|
func (m *defaultOrderModel) FindOne(ctx context.Context, id int64) (*Order, error) {
|
||||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, id)
|
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, id)
|
||||||
var resp Order
|
var resp Order
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", orderRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string) (*Order, error) {
|
func (m *defaultOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string) (*Order, error) {
|
||||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, orderNo)
|
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, orderNo)
|
||||||
var resp Order
|
var resp Order
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncOrderOrderNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
err := m.QueryRowIndexCtx(ctx, &resp, tycOrderOrderNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `order_no` = ? AND del_state = ? limit 1", orderRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `order_no` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderNo, globalkey.DelStateNo); err != nil {
|
if err := conn.QueryRowCtx(ctx, &resp, query, orderNo, globalkey.DelStateNo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -128,7 +127,7 @@ func (m *defaultOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string
|
|||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -139,15 +138,15 @@ func (m *defaultOrderModel) Update(ctx context.Context, session sqlx.Session, ne
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, data.Id)
|
||||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, orderRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, orderRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Order) error {
|
func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Order) error {
|
||||||
@@ -162,15 +161,15 @@ func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, data.Id)
|
||||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, orderRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, orderRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -179,7 +178,7 @@ func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if updateCount == 0 {
|
if updateCount == 0 {
|
||||||
return model.ErrNoRowsUpdate
|
return ErrNoRowsUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -393,22 +392,22 @@ func (m *defaultOrderModel) Delete(ctx context.Context, session sqlx.Session, id
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, id)
|
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, id)
|
||||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultOrderModel) formatPrimary(primary interface{}) string {
|
func (m *defaultOrderModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultOrderModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultOrderModel) 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", orderRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
@@ -18,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -27,9 +26,8 @@ var (
|
|||||||
productFeatureRowsExpectAutoSet = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
productFeatureRowsExpectAutoSet = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
productFeatureRowsWithPlaceHolder = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
productFeatureRowsWithPlaceHolder = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncProductFeatureIdPrefix = "cache:qnc:productFeature:id:"
|
cacheTycProductFeatureIdPrefix = "cache:tyc:productFeature:id:"
|
||||||
cacheQncProductFeatureProductIdFeatureIdPrefix = "cache:qnc:productFeature:productId:featureId:"
|
cacheTycProductFeatureProductIdFeatureIdPrefix = "cache:tyc:productFeature:productId:featureId:"
|
||||||
cacheQncProductFeatureProductIdSortPrefix = "cache:qnc:productFeature:productId:sort:"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -37,7 +35,6 @@ type (
|
|||||||
Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
||||||
FindOne(ctx context.Context, id int64) (*ProductFeature, error)
|
FindOne(ctx context.Context, id int64) (*ProductFeature, error)
|
||||||
FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error)
|
FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error)
|
||||||
FindOneByProductIdSort(ctx context.Context, productId int64, sort int64) (*ProductFeature, error)
|
|
||||||
Update(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
Update(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ProductFeature) error
|
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ProductFeature) error
|
||||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||||
@@ -59,16 +56,17 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProductFeature struct {
|
ProductFeature struct {
|
||||||
Id int64 `db:"id"` // 主键ID
|
Id int64 `db:"id"` // 主键ID
|
||||||
ProductId int64 `db:"product_id"` // 产品ID
|
ProductId int64 `db:"product_id"` // 产品ID
|
||||||
FeatureId int64 `db:"feature_id"` // 功能ID
|
FeatureId int64 `db:"feature_id"` // 功能ID
|
||||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
DelState int64 `db:"del_state"` // 删除状态
|
||||||
Version int64 `db:"version"` // 版本号
|
Version int64 `db:"version"` // 版本号
|
||||||
Sort int64 `db:"sort"` // 排序字段
|
Sort int64 `db:"sort"`
|
||||||
IsImportant int64 `db:"is_important"` // 是否重要,1为重要,0为不重要
|
Enable int64 `db:"enable"`
|
||||||
|
IsImportant int64 `db:"is_important"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -81,40 +79,39 @@ func newProductFeatureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProduc
|
|||||||
|
|
||||||
func (m *defaultProductFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error) {
|
func (m *defaultProductFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, data.Id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productFeatureRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, productFeatureRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant)
|
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.Enable, data.IsImportant)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant)
|
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.Enable, data.IsImportant)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductFeatureModel) FindOne(ctx context.Context, id int64) (*ProductFeature, error) {
|
func (m *defaultProductFeatureModel) FindOne(ctx context.Context, id int64) (*ProductFeature, error) {
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, id)
|
||||||
var resp ProductFeature
|
var resp ProductFeature
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncProductFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycProductFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error) {
|
func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error) {
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, productId, featureId)
|
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, productId, featureId)
|
||||||
var resp ProductFeature
|
var resp ProductFeature
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductFeatureProductIdFeatureIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
err := m.QueryRowIndexCtx(ctx, &resp, tycProductFeatureProductIdFeatureIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_id` = ? AND `feature_id` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `product_id` = ? and `feature_id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, featureId, globalkey.DelStateNo); err != nil {
|
if err := conn.QueryRowCtx(ctx, &resp, query, productId, featureId, globalkey.DelStateNo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -124,27 +121,7 @@ func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Con
|
|||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultProductFeatureModel) FindOneByProductIdSort(ctx context.Context, productId int64, sort int64) (*ProductFeature, error) {
|
|
||||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, productId, sort)
|
|
||||||
var resp ProductFeature
|
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductFeatureProductIdSortKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_id` = ? AND `sort` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, sort, globalkey.DelStateNo); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Id, nil
|
|
||||||
}, m.queryPrimary)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, model.ErrNotFound
|
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -155,16 +132,15 @@ func (m *defaultProductFeatureModel) Update(ctx context.Context, session sqlx.Se
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, data.Id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productFeatureRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productFeatureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id)
|
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductFeature) error {
|
func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductFeature) error {
|
||||||
@@ -179,16 +155,15 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, data.Id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productFeatureRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productFeatureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id, oldVersion)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -197,7 +172,7 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if updateCount == 0 {
|
if updateCount == 0 {
|
||||||
return model.ErrNoRowsUpdate
|
return ErrNoRowsUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -411,23 +386,22 @@ func (m *defaultProductFeatureModel) Delete(ctx context.Context, session sqlx.Se
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultProductFeatureModel) formatPrimary(primary interface{}) string {
|
func (m *defaultProductFeatureModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultProductFeatureModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultProductFeatureModel) 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", productFeatureRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
@@ -18,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -27,8 +26,8 @@ var (
|
|||||||
productRowsExpectAutoSet = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
productRowsExpectAutoSet = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
productRowsWithPlaceHolder = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
productRowsWithPlaceHolder = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncProductIdPrefix = "cache:qnc:product:id:"
|
cacheTycProductIdPrefix = "cache:tyc:product:id:"
|
||||||
cacheQncProductProductEnPrefix = "cache:qnc:product:productEn:"
|
cacheTycProductProductEnPrefix = "cache:tyc:product:productEn:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -81,39 +80,39 @@ func newProductModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProductModel
|
|||||||
|
|
||||||
func (m *defaultProductModel) Insert(ctx context.Context, session sqlx.Session, data *Product) (sql.Result, error) {
|
func (m *defaultProductModel) Insert(ctx context.Context, session sqlx.Session, data *Product) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, data.Id)
|
||||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, productRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
||||||
}, qncProductIdKey, qncProductProductEnKey)
|
}, tycProductIdKey, tycProductProductEnKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductModel) FindOne(ctx context.Context, id int64) (*Product, error) {
|
func (m *defaultProductModel) FindOne(ctx context.Context, id int64) (*Product, error) {
|
||||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, id)
|
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, id)
|
||||||
var resp Product
|
var resp Product
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncProductIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycProductIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", productRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductModel) FindOneByProductEn(ctx context.Context, productEn string) (*Product, error) {
|
func (m *defaultProductModel) FindOneByProductEn(ctx context.Context, productEn string) (*Product, error) {
|
||||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, productEn)
|
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, productEn)
|
||||||
var resp Product
|
var resp Product
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductProductEnKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
err := m.QueryRowIndexCtx(ctx, &resp, tycProductProductEnKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_en` = ? AND del_state = ? limit 1", productRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `product_en` = ? and del_state = ? limit 1", productRows, m.table)
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, productEn, globalkey.DelStateNo); err != nil {
|
if err := conn.QueryRowCtx(ctx, &resp, query, productEn, globalkey.DelStateNo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -123,7 +122,7 @@ func (m *defaultProductModel) FindOneByProductEn(ctx context.Context, productEn
|
|||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -134,15 +133,15 @@ func (m *defaultProductModel) Update(ctx context.Context, session sqlx.Session,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, data.Id)
|
||||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
||||||
}, qncProductIdKey, qncProductProductEnKey)
|
}, tycProductIdKey, tycProductProductEnKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Product) error {
|
func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Product) error {
|
||||||
@@ -157,15 +156,15 @@ func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sql
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, data.Id)
|
||||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
||||||
}, qncProductIdKey, qncProductProductEnKey)
|
}, tycProductIdKey, tycProductProductEnKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -174,7 +173,7 @@ func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sql
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if updateCount == 0 {
|
if updateCount == 0 {
|
||||||
return model.ErrNoRowsUpdate
|
return ErrNoRowsUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -388,22 +387,22 @@ func (m *defaultProductModel) Delete(ctx context.Context, session sqlx.Session,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, id)
|
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, id)
|
||||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncProductIdKey, qncProductProductEnKey)
|
}, tycProductIdKey, tycProductProductEnKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultProductModel) formatPrimary(primary interface{}) string {
|
func (m *defaultProductModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncProductIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycProductIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultProductModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultProductModel) 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", productRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -26,8 +26,8 @@ var (
|
|||||||
productRenderRowsExpectAutoSet = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
productRenderRowsExpectAutoSet = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
productRenderRowsWithPlaceHolder = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
productRenderRowsWithPlaceHolder = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncProductRenderIdPrefix = "cache:qnc:productRender:id:"
|
cacheTycProductRenderIdPrefix = "cache:tyc:productRender:id:"
|
||||||
cacheQncProductRenderPlatformModuleProductIdPrefix = "cache:qnc:productRender:platform:module:productId:"
|
cacheTycProductRenderPlatformModuleProductIdPrefix = "cache:tyc:productRender:platform:module:productId:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -78,21 +78,21 @@ func newProductRenderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProduct
|
|||||||
|
|
||||||
func (m *defaultProductRenderModel) Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error) {
|
func (m *defaultProductRenderModel) Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productRenderRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, productRenderRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*ProductRender, error) {
|
func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*ProductRender, error) {
|
||||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, id)
|
||||||
var resp ProductRender
|
var resp ProductRender
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
@@ -107,9 +107,9 @@ func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*Pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductRenderModel) FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error) {
|
func (m *defaultProductRenderModel) FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error) {
|
||||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
||||||
var resp ProductRender
|
var resp ProductRender
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
err := m.QueryRowIndexCtx(ctx, &resp, tycProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
query := fmt.Sprintf("select %s from %s where `platform` = ? and `module` = ? and `product_id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `platform` = ? and `module` = ? and `product_id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, platform, module, productId, globalkey.DelStateNo); err != nil {
|
if err := conn.QueryRowCtx(ctx, &resp, query, platform, module, productId, globalkey.DelStateNo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -131,15 +131,15 @@ func (m *defaultProductRenderModel) Update(ctx context.Context, session sqlx.Ses
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productRenderRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productRenderRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductRender) error {
|
func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductRender) error {
|
||||||
@@ -154,15 +154,15 @@ func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, sessi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, productRenderRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productRenderRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -385,19 +385,19 @@ func (m *defaultProductRenderModel) Delete(ctx context.Context, session sqlx.Ses
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, id)
|
||||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultProductRenderModel) formatPrimary(primary interface{}) string {
|
func (m *defaultProductRenderModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultProductRenderModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultProductRenderModel) 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", productRenderRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"qnc-server/deploy/script/model"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
@@ -18,7 +17,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
"qnc-server/common/globalkey"
|
"tyc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -27,8 +26,8 @@ var (
|
|||||||
queryRowsExpectAutoSet = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
queryRowsExpectAutoSet = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
queryRowsWithPlaceHolder = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
queryRowsWithPlaceHolder = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheQncQueryIdPrefix = "cache:qnc:query:id:"
|
cacheTycQueryIdPrefix = "cache:tyc:query:id:"
|
||||||
cacheQncQueryOrderIdPrefix = "cache:qnc:query:orderId:"
|
cacheTycQueryOrderIdPrefix = "cache:tyc:query:orderId:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -81,39 +80,39 @@ func newQueryModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultQueryModel {
|
|||||||
|
|
||||||
func (m *defaultQueryModel) Insert(ctx context.Context, session sqlx.Session, data *Query) (sql.Result, error) {
|
func (m *defaultQueryModel) Insert(ctx context.Context, session sqlx.Session, data *Query) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, data.Id)
|
||||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, queryRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, queryRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
return session.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
return conn.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
||||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultQueryModel) FindOne(ctx context.Context, id int64) (*Query, error) {
|
func (m *defaultQueryModel) FindOne(ctx context.Context, id int64) (*Query, error) {
|
||||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, id)
|
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, id)
|
||||||
var resp Query
|
var resp Query
|
||||||
err := m.QueryRowCtx(ctx, &resp, qncQueryIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tycQueryIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", queryRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultQueryModel) FindOneByOrderId(ctx context.Context, orderId int64) (*Query, error) {
|
func (m *defaultQueryModel) FindOneByOrderId(ctx context.Context, orderId int64) (*Query, error) {
|
||||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, orderId)
|
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, orderId)
|
||||||
var resp Query
|
var resp Query
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, qncQueryOrderIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
err := m.QueryRowIndexCtx(ctx, &resp, tycQueryOrderIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `order_id` = ? AND del_state = ? limit 1", queryRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `order_id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderId, globalkey.DelStateNo); err != nil {
|
if err := conn.QueryRowCtx(ctx, &resp, query, orderId, globalkey.DelStateNo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -123,7 +122,7 @@ func (m *defaultQueryModel) FindOneByOrderId(ctx context.Context, orderId int64)
|
|||||||
case nil:
|
case nil:
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
case sqlc.ErrNotFound:
|
case sqlc.ErrNotFound:
|
||||||
return nil, model.ErrNotFound
|
return nil, ErrNotFound
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -134,15 +133,15 @@ func (m *defaultQueryModel) Update(ctx context.Context, session sqlx.Session, ne
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, data.Id)
|
||||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, queryRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, queryRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Query) error {
|
func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Query) error {
|
||||||
@@ -157,15 +156,15 @@ func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, data.Id)
|
||||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, queryRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, queryRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -174,7 +173,7 @@ func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if updateCount == 0 {
|
if updateCount == 0 {
|
||||||
return model.ErrNoRowsUpdate
|
return ErrNoRowsUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -388,22 +387,22 @@ func (m *defaultQueryModel) Delete(ctx context.Context, session sqlx.Session, id
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, id)
|
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, id)
|
||||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultQueryModel) formatPrimary(primary interface{}) string {
|
func (m *defaultQueryModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultQueryModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultQueryModel) 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", queryRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user