From 8cb0ab6819c60b84e770e80a4393752d37118100 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 23 Feb 2024 16:04:54 +0800 Subject: [PATCH 01/10] by Robin at 20240223; fix --- app/mix/service/apiservice.go | 2 +- app/mix/service/service.go | 2 +- app/mix/service/utilservice.go | 3 ++- dbstruct/account.go | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 2924ab88..6851a288 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -126,7 +126,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB // 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息 if ec == errcode.ErrCodeLoginNotExist { - login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter) + login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter, req.BaseRequest.DevType) if ec != errcode.ErrCodeLoginSrvOk { logger.Error("utilRegisterUser failed") ec = errcode.ErrCodeLoginRegisterUserFail diff --git a/app/mix/service/service.go b/app/mix/service/service.go index ff5ec41d..a8f45a54 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -536,7 +536,7 @@ func (s *Service) OpLoginByVeriCode(ctx *gin.Context, req *loginproto.OpLoginByV // 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息 if ec == errcode.ErrCodeLoginNotExist { - login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter) + login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter, req.BaseRequest.DevType) if ec != errcode.ErrCodeLoginSrvOk { logger.Error("utilRegisterUser failed") ec = errcode.ErrCodeLoginRegisterUserFail diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 8745295e..0814ab7e 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -25,7 +25,7 @@ import ( // 不向外暴露的辅助公共函数 // 注册账户 -func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhoneInfoComponent, inviter *int64) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) { +func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhoneInfoComponent, inviter *int64, devType int32) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) { var err error inviterUserId := int64(0) @@ -66,6 +66,7 @@ func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhone account.RegionCode = goproto.String(req.RegionCode) account.PhoneHash = goproto.String(req.PhoneHash) account.IsAMember = goproto.Int64(0) + account.DevType = goproto.Int32(devType) if inviterUserId != 0 { account.Inviter = goproto.Int64(inviterUserId) } diff --git a/dbstruct/account.go b/dbstruct/account.go index 9c365ff0..971f6c88 100644 --- a/dbstruct/account.go +++ b/dbstruct/account.go @@ -22,6 +22,7 @@ type Account struct { DiamondNum *int64 `json:"diamond_num" bson:"diamond_num"` // 钻石数量 Inviter *int64 `json:"inviter" bson:"inviter"` // 邀请人user_id IsAMember *int64 `json:"is_a_member" bson:"is_a_member"` // 是否是会员,0-否,1-是 + DevType *int32 `bson:"dev_type"` // 注册来源 Latitude *float64 `bson:"latitude"` // 纬度 Longitude *float64 `bson:"longitude"` // 经度 Ct *int64 `json:"ct" bson:"ct"` // 创建时间 From 9b9b84c89f46d3d3eea40bf01b18eadac1ef1ed0 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Sat, 24 Feb 2024 23:20:27 +0800 Subject: [PATCH 02/10] alipay change myts --- library/payclients/alipaycli/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/payclients/alipaycli/client.go b/library/payclients/alipaycli/client.go index 878e1ab0..0503976c 100644 --- a/library/payclients/alipaycli/client.go +++ b/library/payclients/alipaycli/client.go @@ -25,7 +25,7 @@ const ( var allAlipayClients = map[string]*AlipayClient{} func GetDefaultAlipayClient() *AlipayClient { - return allAlipayClients[AppIdXinYiDaoLe] + return allAlipayClients[AppIdMiYuanTianShi] } func GetAlipayClientByAppId(appId string) *AlipayClient { From 8b3d5b5ec6dbfc248c7879d9cc2ff958a2daacaf Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Sun, 25 Feb 2024 23:17:17 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BD=93=E7=8E=B0=E7=94=A8=20=E5=BF=83?= =?UTF-8?q?=E6=84=8F=E5=88=B0=E4=BA=86=E8=B4=A6=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mix/service/logic/vas.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 69af201f..6aa13439 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -1947,6 +1947,8 @@ func (v *Vas) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq) (t // 2000元以下直接操作 if money <= 200000 { + alipayCli := alipaycli.GetAlipayClientByAppId(alipaycli.AppIdXinYiDaoLe) + // 更改状态 err = v.store.UpdateWithdrawOrderStatus(ctx, tx, orderId, dbstruct.VasWithdrawOrderStatusInit, dbstruct.VasWithdrawOrderStatusAuto) if err != nil { @@ -1981,7 +1983,7 @@ func (v *Vas) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq) (t AlipayLoginId: alipayId, AlipayName: alipayName, } - transferResp, err = alipaycli.GetDefaultAlipayClient().UniTransfer(ctx, transferParam) + transferResp, err = alipayCli.UniTransfer(ctx, transferParam) if err != nil { logger.Error("UniTransfer fail, param: %v, err: %v", util.ToJson(transferParam), err) return From 0b1a71a343eb233407a5a7e00a5bc47fd1fb4f3a Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Mon, 26 Feb 2024 00:50:56 +0800 Subject: [PATCH 04/10] fix --- app/mix/service/logic/vas.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 6aa13439..377bd49e 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -1383,7 +1383,7 @@ func (v *Vas) GetAddWechatCoinOrders(ctx *gin.Context, mid int64, offset, limit statusList := make([]int32, 0) switch tab { case vasproto.AddWechatListTabWait: - statusList = []int32{dbstruct.VasCoinOrderStatusNotFill, dbstruct.VasCoinOrderStatusWaitDeal, dbstruct.VasCoinOrderStatusRefund} + statusList = []int32{dbstruct.VasCoinOrderStatusNotFill, dbstruct.VasCoinOrderStatusWaitDeal} case vasproto.AddWechatListTabFinish: statusList = []int32{dbstruct.VasCoinOrderStatusDeal, dbstruct.VasCoinOrderStatusFinish, dbstruct.VasCoinOrderStatusRefund} } From e570d4385d2c34d3ae7cf82e14d101b4d6ddbade Mon Sep 17 00:00:00 2001 From: Leufolium Date: Mon, 26 Feb 2024 09:27:21 +0800 Subject: [PATCH 05/10] by Robin at 20240226; prod xxl-job config info --- etc/mix/mix-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/mix/mix-prod.yaml b/etc/mix/mix-prod.yaml index 4540a5d0..10795151 100644 --- a/etc/mix/mix-prod.yaml +++ b/etc/mix/mix-prod.yaml @@ -112,7 +112,7 @@ server_info: file_server_domain_name: "https://file.tiefen.fun/" xxl_job: - server_addr: "http://127.0.0.1:9800/xxl-job-admin" + server_addr: "http://172.16.0.174:9800/xxl-job-admin" access_token: "default_token" executor_ip: "127.0.0.1" executor_port: "9801" From 48d058610d5e18b15ea9b7c5cd7a2a902fdcaa14 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Mon, 26 Feb 2024 19:28:03 +0800 Subject: [PATCH 06/10] add wxpayh5 --- api/proto/vas/proto/pay.go | 5 ++- app/mix/service/logic/vas.go | 21 +++++++++++ bizcommon/util/util.go | 7 ++++ library/payclients/wxpaycli/client.go | 44 ++++++++++++++++++++++ library/payclients/wxpaycli/client_test.go | 39 +++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-) diff --git a/api/proto/vas/proto/pay.go b/api/proto/vas/proto/pay.go index 5435d4a0..5eef2fee 100644 --- a/api/proto/vas/proto/pay.go +++ b/api/proto/vas/proto/pay.go @@ -31,6 +31,7 @@ const ( PayTypeAlipayH5 = "alipay_h5" // 支付宝 h5 PayTypeWxpayNative = "wxpay_native" // 微信 native PayTypeWxpayJsapi = "wxpay_jsapi" // 微信 jsapi + PayTypeWxpayH5 = "wxpay_h5" // 微信支付 h5 ) const ( @@ -66,7 +67,8 @@ type CreateOrderData struct { AlipayParamStr string `json:"alipay_param_str"` // 支付宝 app支付参数 AlipayH5ParamStr string `json:"alipay_h5_param_str"` // 支付宝 h5支付参数 WxpayNativeParamStr string `json:"wxpay_native_param_str"` // 微信支付 native支付参数 - WxpayJsapiParamObj wxpaycli.JsapiPayResp `json:"wxpay_jsapi_param_obj"` // 微信支付 native + WxpayJsapiParamObj wxpaycli.JsapiPayResp `json:"wxpay_jsapi_param_obj"` // 微信支付 jsapi支付参数 + WxpayH5ParamStr string `json:"wxpay_h5_param_str"` // 微信支付 h5支付参数 } // 预解锁联系方式 @@ -150,6 +152,7 @@ type H5DirectUnlockWechatData struct { AlipayH5ParamStr string `json:"alipay_h5_param_str"` // 支付宝 h5支付参数 WxpayNativeParamStr string `json:"wxpay_native_param_str"` // 微信支付 native支付参数 WxpayJsapiParamObj wxpaycli.JsapiPayResp `json:"wxpay_jsapi_param_obj"` // 微信支付 native + WxpayH5ParamStr string `json:"wxpay_h5_param_str"` // 微信支付 h5支付参数 } // 支付宝回调参数 diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 377bd49e..fd959788 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -98,6 +98,7 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data alipayH5ParamStr string wxpayNativeParamStr string wxpayJsapiParamObj wxpaycli.JsapiPayResp + wxpayH5ParamStr string ) defer func() { @@ -241,6 +242,24 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data return } req.Oid3 = wxpayCli.AppId + case vasproto.PayTypeWxpayH5: + wxpayCli := wxpaycli.GetDefaultWxpayClient() + h5PayParam := &wxpaycli.H5PayParam{ + Description: product.Subject, + OutTradeNo: orderId, + TotalAmount: product.RealPrice, + TimeOutSeconds: 900, + Cip: ctx.ClientIP(), + } + if len(h5PayParam.Cip) <= 0 { + h5PayParam.Cip = "112.124.18.6" + } + wxpayH5ParamStr, err = wxpayCli.H5Pay(ctx, h5PayParam) + if err != nil { + logger.Error("wxpay H5Pay fail, req: %v, h5PayParam: %v, err: %v", util.ToJson(req), util.ToJson(h5PayParam), err) + return + } + req.Oid3 = wxpayCli.AppId } // 添加订单 @@ -284,6 +303,7 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data AlipayH5ParamStr: alipayH5ParamStr, WxpayNativeParamStr: wxpayNativeParamStr, WxpayJsapiParamObj: wxpayJsapiParamObj, + WxpayH5ParamStr: wxpayH5ParamStr, } return } @@ -1554,6 +1574,7 @@ func (v *Vas) H5DirectUnlockWechat(ctx *gin.Context, req *vasproto.H5DirectUnloc AlipayH5ParamStr: cData.AlipayH5ParamStr, WxpayNativeParamStr: cData.WxpayNativeParamStr, WxpayJsapiParamObj: cData.WxpayJsapiParamObj, + WxpayH5ParamStr: cData.WxpayH5ParamStr, } return } diff --git a/bizcommon/util/util.go b/bizcommon/util/util.go index 410368fb..545be135 100644 --- a/bizcommon/util/util.go +++ b/bizcommon/util/util.go @@ -106,3 +106,10 @@ func BytesToString(b []byte) (s string) { _sptr.Len = _bptr.Len return s } + +func UnescapeJsonStr(s string) string { + s = strings.ReplaceAll(s, "\\u003c", "<") + s = strings.ReplaceAll(s, "\\u003e", ">") + s = strings.ReplaceAll(s, "\\u0026", "&") + return s +} diff --git a/library/payclients/wxpaycli/client.go b/library/payclients/wxpaycli/client.go index 1e6e7d89..ebe1eed1 100644 --- a/library/payclients/wxpaycli/client.go +++ b/library/payclients/wxpaycli/client.go @@ -242,3 +242,47 @@ func rsaSign(prvkey []byte, hash crypto.Hash, data []byte) ([]byte, error) { } return rsa.SignPKCS1v15(cryptorand.Reader, privateKey.(*rsa.PrivateKey), hash, hashed) } + +// 微信支付 h5支付 +type H5PayParam struct { + Description string + OutTradeNo string // 商家订单id,我们自己的订单id + TotalAmount int64 // 金额,单位:分 + TimeOutSeconds int // 订单有效时间,单位:秒 + Cip string // 客户端ip +} + +func (c *WxpayClient) H5Pay(ctx context.Context, param *H5PayParam) (wxpayH5ParamStr string, err error) { + if param.TimeOutSeconds <= 0 { + param.TimeOutSeconds = DefaultOrderTimeoutSeconds + } + bm := gopay.BodyMap{ + "appid": c.AppId, + "description": param.Description, + "out_trade_no": param.OutTradeNo, + "time_expire": time.Now().Add(time.Second * time.Duration(param.TimeOutSeconds)).Format(time.RFC3339), + "notify_url": c.NotifyUrl, + "amount": gopay.BodyMap{ + "total": param.TotalAmount, + "currency": "CNY", + }, + "scene_info": gopay.BodyMap{ + "payer_client_ip": param.Cip, + "h5_info": gopay.BodyMap{ + "type": "Wap", + }, + }, + } + resp, err := c.clientV3.V3TransactionH5(ctx, bm) + if err != nil { + return + } + if resp.Code != wxpayv3.Success { + logger.Info("wxpayv3 NativePay fail, code: %v, error: %v, response: %v", resp.Code, resp.Error, util.ToJson(resp.Response)) + return + } + + wxpayH5ParamStr = resp.Response.H5Url + logger.Info("wxpayv3 H5 success, code: %v, error: %v, response: %v", resp.Code, resp.Error, util.ToJson(resp.Response)) + return +} diff --git a/library/payclients/wxpaycli/client_test.go b/library/payclients/wxpaycli/client_test.go index 06af3218..28cba7e5 100644 --- a/library/payclients/wxpaycli/client_test.go +++ b/library/payclients/wxpaycli/client_test.go @@ -1,7 +1,9 @@ package wxpaycli import ( + "bytes" "context" + "encoding/json" "fmt" "os" "service/app/mix/conf" @@ -74,3 +76,40 @@ func TestWxpayClient_JsapiPay(t *testing.T) { } t.Log(util.ToJson(r)) } + +type Track struct { + XmlRequest string `json:"xmlRequest"` +} + +func (t *Track) JSON() ([]byte, error) { + buffer := &bytes.Buffer{} + encoder := json.NewEncoder(buffer) + // encoder.SetEscapeHTML(false) + err := encoder.Encode(t) + return buffer.Bytes(), err +} + +func AT() { + message := Track{} + message.XmlRequest = "XML" + fmt.Println("Before Marshal", message) + messageJSON, _ := message.JSON() + fmt.Println("After marshal", string(messageJSON)) +} + +func TestWxpayClient_H5Pay(t *testing.T) { + cli := GetDefaultWxpayClient() + + resp, err := cli.H5Pay(context.Background(), &H5PayParam{ + Description: "hello", + OutTradeNo: idgenerator.GenOrderId(), + TotalAmount: 1, + TimeOutSeconds: 3600 * 24, + Cip: "223.104.41.0", + }) + if err != nil { + t.Log(err.Error()) + return + } + t.Log(resp) +} From a0cb8555ce7ac2375ddbaaae13e9d65e186033e8 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Mon, 26 Feb 2024 19:29:59 +0800 Subject: [PATCH 07/10] add wxpayh5 --- app/mix/service/logic/vas.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index fd959788..bafbec39 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -251,6 +251,7 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data TimeOutSeconds: 900, Cip: ctx.ClientIP(), } + // 给个默认ip if len(h5PayParam.Cip) <= 0 { h5PayParam.Cip = "112.124.18.6" } From c3db97077bf73e95013d37886bd23e098dc43958 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 27 Feb 2024 01:05:14 +0800 Subject: [PATCH 08/10] by Robin at 20240227;fix --- etc/mix/mix-prod.yaml | 2 +- library/contentaudit/imageaudit/imageaudit.go | 14 +++++++++----- .../contentaudit/imageaudit/taskscheduler.go | 17 +---------------- library/contentaudit/textaudit/taskscheduler.go | 17 +---------------- library/contentaudit/textaudit/textaudit.go | 5 ----- 5 files changed, 12 insertions(+), 43 deletions(-) diff --git a/etc/mix/mix-prod.yaml b/etc/mix/mix-prod.yaml index 10795151..3f6d1813 100644 --- a/etc/mix/mix-prod.yaml +++ b/etc/mix/mix-prod.yaml @@ -114,7 +114,7 @@ server_info: xxl_job: server_addr: "http://172.16.0.174:9800/xxl-job-admin" access_token: "default_token" - executor_ip: "127.0.0.1" + executor_ip: "172.16.0.177" executor_port: "9801" registry_key: "golang-jobs-executor" log_path: "/app/ironfan/log/xxl_job/" \ No newline at end of file diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index f350f95f..1bfa5caa 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -42,9 +42,6 @@ func Run(batchId string) (successNum int, failNum int, err error) { return 0, 0, nil } - // 上锁 - defaultImageAuditTaskScheduler.lock() - logger.Info("Image audit batch started, batchId : %v, task number : %v", batchId, len(imageaudittasks)) // 1.构建批量任务控制块,初始化必要的actionMap、填充送审image等信息 ctrlBlock := NewImageAuditTaskBatchControlBlock(imageaudittasks, batchId) @@ -64,6 +61,7 @@ func Run(batchId string) (successNum int, failNum int, err error) { ConnectTimeout: tea.Int(30000), } _result, err := defaultImageAuditClient.ScanImageAdvance(req, runtime) + logger.Info("Receive the response from ScanImageAdvance: %v", _result.String()) if err != nil { if _t, ok := err.(*tea.SDKError); ok { logger.Error("ScanImageAdvance fail, errinfo : %v", util.DerefString(_t.Data)) @@ -76,8 +74,6 @@ func Run(batchId string) (successNum int, failNum int, err error) { // 4.处理应答 err = handleScanImageResponse(ctrlBlock, _result) - // 解锁 - defaultImageAuditTaskScheduler.unLock() successNum = len(imageaudittasks) return } @@ -119,37 +115,45 @@ func handleScanImageResponse(ctrlBlock *ImageAuditTaskBatchControlBlock, resp *i img2taskIndexMap := ctrlBlock.Img2taskIndexMap actionMap := ctrlBlock.ActionMap for i, result := range results { + logger.Info("Handling %vs result...", i) isTaskCompleted := false isActionCompleted := false action := &ImageAuditAction{} // 1.dataId是imageaudit表主键Id, 唯一标识一次对单张图片的图像审核 + logger.Info("Getting dataId...") dataId := util.DerefString(result.DataId) // 2.立即在imageaudit-imageaudit中更新该次审核结果 + logger.Info("Handling its audit record...") pass, err := handleImageAudit(dataId, result) if err != nil { logger.Error("handleImageAudit fail: %v", err) } // 3.取出task + logger.Info("Retriving its audit task...") taskIndex := img2taskIndexMap[i] task := taskCtrlBlocks[taskIndex] // 4.在task中记录本分片结果,并累积已到达的分片数,直到所有分片到达,决定该任务是否成功(非分片任务分片数为1) + logger.Info("Recording it to task...") isTaskCompleted = handleTask(task, pass) // 5.通过task的actionId,去actionId-[]*task的map查出本批次对该字段的动作链,更新其中关于自己的状态 + logger.Info("Recording the task result...") if isTaskCompleted { isActionCompleted, action = handleTaskAction(task, actionMap) } // 6.等待所有动作链元素均已抵达,判定本批次对该字段的操作是否成功 + logger.Info("Recording the action result...") if isActionCompleted { if err = finalizeTask(action); err != nil { logger.Error("finalizeTask fail: %v", err) } } + logger.Info("%vs result handled...", i) } return } diff --git a/library/contentaudit/imageaudit/taskscheduler.go b/library/contentaudit/imageaudit/taskscheduler.go index b88320cf..7ee484ee 100644 --- a/library/contentaudit/imageaudit/taskscheduler.go +++ b/library/contentaudit/imageaudit/taskscheduler.go @@ -10,29 +10,14 @@ var defaultImageAuditTaskScheduler *ImageAuditTaskScheduler // 图像审核任务调度器 type ImageAuditTaskScheduler struct { - // 同步标志 - batchFlag chan bool // 批处理同步标志 - // 状态记录 batchId string // 当前批次号 } func initScheduler(cfg *configcenter.ImageAuditConfig) { defaultImageAuditTaskScheduler = &ImageAuditTaskScheduler{ - batchFlag: make(chan bool, 1), - batchId: genereteBatchId(), + batchId: genereteBatchId(), } - defaultImageAuditTaskScheduler.batchFlag <- true -} - -// 批处理上锁 -func (s *ImageAuditTaskScheduler) lock() { - <-s.batchFlag -} - -// 批处理解锁 -func (s *ImageAuditTaskScheduler) unLock() { - s.batchFlag <- true } // 生成批次号 diff --git a/library/contentaudit/textaudit/taskscheduler.go b/library/contentaudit/textaudit/taskscheduler.go index 1902b3d7..eb7c92e1 100644 --- a/library/contentaudit/textaudit/taskscheduler.go +++ b/library/contentaudit/textaudit/taskscheduler.go @@ -10,29 +10,14 @@ var defaultTextAuditTaskScheduler *TextAuditTaskScheduler // 文字审核任务调度器 type TextAuditTaskScheduler struct { - // 缓冲池、同步标志 - batchFlag chan bool // 批处理同步标志 - // 状态记录 batchId string // 当前批次号 } func initScheduler(cfg *configcenter.TextAuditConfig) { defaultTextAuditTaskScheduler = &TextAuditTaskScheduler{ - batchFlag: make(chan bool, 1), - batchId: genereteBatchId(), + batchId: genereteBatchId(), } - defaultTextAuditTaskScheduler.batchFlag <- true -} - -// 批处理上锁 -func (s *TextAuditTaskScheduler) lock() { - <-s.batchFlag -} - -// 批处理解锁 -func (s *TextAuditTaskScheduler) unLock() { - s.batchFlag <- true } // 生成批次号 diff --git a/library/contentaudit/textaudit/textaudit.go b/library/contentaudit/textaudit/textaudit.go index 8653b016..3f55a23c 100644 --- a/library/contentaudit/textaudit/textaudit.go +++ b/library/contentaudit/textaudit/textaudit.go @@ -39,9 +39,6 @@ func Run(batchId string) (successNum int, failNum int, err error) { return 0, 0, nil } - // 上锁 - defaultTextAuditTaskScheduler.lock() - logger.Info("Text audit batch started, batchId : %v, task number : %v", batchId, len(textaudittasks)) // 1.构建批量任务控制块,初始化必要的actionMap、填充送审text等信息 ctrlBlock := NewTextAuditTaskBatchControlBlock(textaudittasks, batchId) @@ -68,8 +65,6 @@ func Run(batchId string) (successNum int, failNum int, err error) { // 4.处理应答 err = handleScanTextResponse(ctrlBlock, _result) - // 解锁 - defaultTextAuditTaskScheduler.unLock() successNum = len(textaudittasks) return } From 14e8ae6cd7e8dbf56fdac1323009828777984da3 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 27 Feb 2024 01:28:27 +0800 Subject: [PATCH 09/10] by Robin at 20240227; --- app/mix/service/apiservice.go | 6 +++++- app/mix/service/logic/account.go | 4 ++++ dbstruct/daily_statement.go | 23 +++++++++++++---------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index aa2d6f76..0edc0d25 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -25,6 +25,7 @@ import ( vericodeproto "service/api/proto/vericode/proto" "service/apollostruct" businessvalidator "service/app/mix/service/business_validator" + "service/bizcommon/common" "service/bizcommon/util" "service/dbstruct" "service/library/apollo" @@ -127,8 +128,11 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB login, account, vericode, ec = s.ApiLoginByVeriCodeBusinessValidate(ctx, req) // 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息 + if req.Channel == "h5" { + req.DevType = common.DeviceTypeH5 + } if ec == errcode.ErrCodeLoginNotExist { - login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter, req.BaseRequest.DevType) + login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter, req.DevType) if ec != errcode.ErrCodeLoginSrvOk { logger.Error("utilRegisterUser failed") ec = errcode.ErrCodeLoginRegisterUserFail diff --git a/app/mix/service/logic/account.go b/app/mix/service/logic/account.go index 8ecb4816..54bce23d 100644 --- a/app/mix/service/logic/account.go +++ b/app/mix/service/logic/account.go @@ -163,6 +163,10 @@ func (p *Account) OpCount(ctx *gin.Context, req *accountproto.OpCountReq) (int64 return count, err } +func (p *Account) OpCountRegisterSource(ctx *gin.Context, req *accountproto.OpCountReq) (int64, int64, int64, error) { + +} + func (p *Account) GetInviterMid(ctx *gin.Context, mid int64) (int64, error) { inviterMid := int64(0) userAcct, err := p.OpListByMid(ctx, &accountproto.OpListByMidReq{ diff --git a/dbstruct/daily_statement.go b/dbstruct/daily_statement.go index 3d224005..1244d006 100644 --- a/dbstruct/daily_statement.go +++ b/dbstruct/daily_statement.go @@ -1,15 +1,18 @@ package dbstruct type DailyStatement struct { - Id *int64 `json:"id" bson:"_id"` // 每日报表id - H5CallCount *int64 `json:"h5_call_count" bson:"h5_call_count"` // H5接口调用总量 - RegisteredUserCount *int64 `json:"registered_user_count" bson:"registered_user_count"` // 注册用户总量 - OrderCreatedCount *int64 `json:"order_created_count" bson:"order_created_count"` // 订单创建总量 - OrderFinishedCount *int64 `json:"order_finished_count" bson:"order_finished_count"` // 订单完成总量 - StartTime *int64 `json:"start_time" bson:"start_time"` // 起始时间 - EndTime *int64 `json:"end_time" bson:"end_time"` // 结束时间 - Ct *int64 `json:"ct" bson:"ct"` // 创建时间 - Ut *int64 `json:"ut" bson:"ut"` // 更新时间 - DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 + Id *int64 `json:"id" bson:"_id"` // 每日报表id + H5CallCount *int64 `json:"h5_call_count" bson:"h5_call_count"` // H5接口调用总量 + RegisteredUserCount *int64 `json:"registered_user_count" bson:"registered_user_count"` // 注册用户总量 + OrderCreatedCount *int64 `json:"order_created_count" bson:"order_created_count"` // 订单创建总量 + OrderFinishedCount *int64 `json:"order_finished_count" bson:"order_finished_count"` // 订单完成总量 + AndroidRegisteredUserCount *int64 `json:"android_registered_user_count" bson:"android_registered_user_count"` // 安卓注册总量 + IosRegisteredUserCount *int64 `json:"ios_registered_user_count" bson:"ios_registered_user_count"` // ios注册总量 + H5RegisteredUserCount *int64 `json:"h5_registered_user_count" bson:"h5_registered_user_count"` // h5注册总量 + StartTime *int64 `json:"start_time" bson:"start_time"` // 起始时间 + EndTime *int64 `json:"end_time" bson:"end_time"` // 结束时间 + Ct *int64 `json:"ct" bson:"ct"` // 创建时间 + Ut *int64 `json:"ut" bson:"ut"` // 更新时间 + DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 } From 2decbe9c678b7beb8bfb2c5c1530dc15a390a8b5 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 27 Feb 2024 01:50:47 +0800 Subject: [PATCH 10/10] by Robin at 20240227; register source statistics --- app/mix/dao/mongo.go | 97 ++++++++++++++++++++++++++++++++ app/mix/service/logic/account.go | 19 ++++++- app/mix/service/xxljob_tasks.go | 21 +++++-- dbstruct/daily_statement.go | 26 ++++----- 4 files changed, 142 insertions(+), 21 deletions(-) diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index f94155eb..edf130f0 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -5,6 +5,7 @@ import ( "service/api/consts" bannerproto "service/api/proto/banner/proto" catalogproto "service/api/proto/catalog/proto" + "service/bizcommon/common" "service/bizcommon/util" "strconv" "time" @@ -1058,6 +1059,102 @@ func (m *Mongo) GetAccountCount(ctx *gin.Context, req *accountproto.OpCountReq) return count, err } +func (m *Mongo) GetLastHourNewUserFromAndroidCount(ctx *gin.Context, req *accountproto.OpCountReq) (int64, error) { + col := m.getColAccount() + + filterInClause := []qmgo.M{} + if req.CtLowerBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "ct": qmgo.M{ + "$gte": util.DerefInt64(req.CtLowerBound), + }, + }) + } + if req.CtUpperBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "ct": qmgo.M{ + "$lte": util.DerefInt64(req.CtUpperBound), + }, + }) + } + + if len(filterInClause) == 0 { + return 0, nil + } + + filter := qmgo.M{ + "$and": filterInClause, + "dev_type": common.DeviceTypeAndroid, + } + + count, err := col.Find(ctx, filter).Count() + return count, err +} + +func (m *Mongo) GetLastHourNewUserFromIosCount(ctx *gin.Context, req *accountproto.OpCountReq) (int64, error) { + col := m.getColAccount() + + filterInClause := []qmgo.M{} + if req.CtLowerBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "ct": qmgo.M{ + "$gte": util.DerefInt64(req.CtLowerBound), + }, + }) + } + if req.CtUpperBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "ct": qmgo.M{ + "$lte": util.DerefInt64(req.CtUpperBound), + }, + }) + } + + if len(filterInClause) == 0 { + return 0, nil + } + + filter := qmgo.M{ + "$and": filterInClause, + "dev_type": common.DeviceTypeIos, + } + + count, err := col.Find(ctx, filter).Count() + return count, err +} + +func (m *Mongo) GetLastHourNewUserFromH5Count(ctx *gin.Context, req *accountproto.OpCountReq) (int64, error) { + col := m.getColAccount() + + filterInClause := []qmgo.M{} + if req.CtLowerBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "ct": qmgo.M{ + "$gte": util.DerefInt64(req.CtLowerBound), + }, + }) + } + if req.CtUpperBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "ct": qmgo.M{ + "$lte": util.DerefInt64(req.CtUpperBound), + }, + }) + } + + if len(filterInClause) == 0 { + return 0, nil + } + + filter := qmgo.M{ + "$and": filterInClause, + "dev_type": common.DeviceTypeH5, + } + + count, err := col.Find(ctx, filter).Count() + return count, err +} + // vericode相关 func (m *Mongo) CreateVeriCode(ctx *gin.Context, vericode *dbstruct.VeriCode) error { col := m.getColVeriCode() diff --git a/app/mix/service/logic/account.go b/app/mix/service/logic/account.go index 54bce23d..e2ff8e31 100644 --- a/app/mix/service/logic/account.go +++ b/app/mix/service/logic/account.go @@ -163,8 +163,23 @@ func (p *Account) OpCount(ctx *gin.Context, req *accountproto.OpCountReq) (int64 return count, err } -func (p *Account) OpCountRegisterSource(ctx *gin.Context, req *accountproto.OpCountReq) (int64, int64, int64, error) { - +func (p *Account) OpCountLastHourNewUserSource(ctx *gin.Context, req *accountproto.OpCountReq) (int64, int64, int64, error) { + androidCount, err := p.store.GetLastHourNewUserFromAndroidCount(ctx, req) + if err != nil { + logger.Error("GetLastHourNewUserSourceCount fail, err: %v", err) + return 0, 0, 0, err + } + iosCount, err := p.store.GetLastHourNewUserFromIosCount(ctx, req) + if err != nil { + logger.Error("GetLastHourNewUserFromIosCount fail, err: %v", err) + return 0, 0, 0, err + } + h5Count, err := p.store.GetLastHourNewUserFromH5Count(ctx, req) + if err != nil { + logger.Error("GetLastHourNewUserFromH5Count fail, err: %v", err) + return 0, 0, 0, err + } + return androidCount, iosCount, h5Count, err } func (p *Account) GetInviterMid(ctx *gin.Context, mid int64) (int64, error) { diff --git a/app/mix/service/xxljob_tasks.go b/app/mix/service/xxljob_tasks.go index d5aedafd..d052e318 100644 --- a/app/mix/service/xxljob_tasks.go +++ b/app/mix/service/xxljob_tasks.go @@ -107,6 +107,12 @@ func (s *CronService) CreateDailyStatement(ctx context.Context, param *xxl.RunRe return fmt.Sprintf("_DefaultVas GetOrderCountByStatus fail : %v", err) } + //获取用户注册来源 + androidCount, iosCount, h5Count, err := _DefaultAccount.OpCountLastHourNewUserSource(&gin.Context{}, &accountproto.OpCountReq{ + CtLowerBound: goproto.Int64(startTimeStamp), + CtUpperBound: goproto.Int64(endTimeStamp), + }) + finishedOrderCount := int32(0) allOrderCount := int32(0) for _, orderCount := range orderCounts { @@ -117,12 +123,15 @@ func (s *CronService) CreateDailyStatement(ctx context.Context, param *xxl.RunRe } dailyStatement := &dbstruct.DailyStatement{ - H5CallCount: goproto.Int64(int64(count)), - RegisteredUserCount: goproto.Int64(accountCount), - OrderCreatedCount: goproto.Int64(int64(allOrderCount)), - OrderFinishedCount: goproto.Int64(int64(finishedOrderCount)), - StartTime: goproto.Int64(startTimeStamp), - EndTime: goproto.Int64(endTimeStamp), + H5CallCount: goproto.Int64(int64(count)), + RegisteredUserCount: goproto.Int64(accountCount), + OrderCreatedCount: goproto.Int64(int64(allOrderCount)), + OrderFinishedCount: goproto.Int64(int64(finishedOrderCount)), + LastHourNewUserCountFromAndroid: goproto.Int64(androidCount), + LastHourNewUserCountFromIos: goproto.Int64(iosCount), + LastHourNewUserCountFromH5: goproto.Int64(h5Count), + StartTime: goproto.Int64(startTimeStamp), + EndTime: goproto.Int64(endTimeStamp), } err = _DefaultDailyStatement.OpCreate(&gin.Context{}, &daily_statementproto.OpCreateReq{ DailyStatement: dailyStatement, diff --git a/dbstruct/daily_statement.go b/dbstruct/daily_statement.go index 1244d006..bcba203e 100644 --- a/dbstruct/daily_statement.go +++ b/dbstruct/daily_statement.go @@ -1,18 +1,18 @@ package dbstruct type DailyStatement struct { - Id *int64 `json:"id" bson:"_id"` // 每日报表id - H5CallCount *int64 `json:"h5_call_count" bson:"h5_call_count"` // H5接口调用总量 - RegisteredUserCount *int64 `json:"registered_user_count" bson:"registered_user_count"` // 注册用户总量 - OrderCreatedCount *int64 `json:"order_created_count" bson:"order_created_count"` // 订单创建总量 - OrderFinishedCount *int64 `json:"order_finished_count" bson:"order_finished_count"` // 订单完成总量 - AndroidRegisteredUserCount *int64 `json:"android_registered_user_count" bson:"android_registered_user_count"` // 安卓注册总量 - IosRegisteredUserCount *int64 `json:"ios_registered_user_count" bson:"ios_registered_user_count"` // ios注册总量 - H5RegisteredUserCount *int64 `json:"h5_registered_user_count" bson:"h5_registered_user_count"` // h5注册总量 - StartTime *int64 `json:"start_time" bson:"start_time"` // 起始时间 - EndTime *int64 `json:"end_time" bson:"end_time"` // 结束时间 - Ct *int64 `json:"ct" bson:"ct"` // 创建时间 - Ut *int64 `json:"ut" bson:"ut"` // 更新时间 - DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 + Id *int64 `json:"id" bson:"_id"` // 每日报表id + H5CallCount *int64 `json:"h5_call_count" bson:"h5_call_count"` // H5接口调用总量 + RegisteredUserCount *int64 `json:"registered_user_count" bson:"registered_user_count"` // 注册用户总量 + OrderCreatedCount *int64 `json:"order_created_count" bson:"order_created_count"` // 订单创建总量 + OrderFinishedCount *int64 `json:"order_finished_count" bson:"order_finished_count"` // 订单完成总量 + LastHourNewUserCountFromAndroid *int64 `json:"last_hour_new_user_count_from_android" bson:"last_hour_new_user_count_from_android"` // 安卓注册总量 + LastHourNewUserCountFromIos *int64 `json:"last_hour_new_user_count_from_ios" bson:"last_hour_new_user_count_from_ios"` // ios注册总量 + LastHourNewUserCountFromH5 *int64 `json:"last_hour_new_user_count_from_h5" bson:"last_hour_new_user_count_from_h5"` // h5注册总量 + StartTime *int64 `json:"start_time" bson:"start_time"` // 起始时间 + EndTime *int64 `json:"end_time" bson:"end_time"` // 结束时间 + Ct *int64 `json:"ct" bson:"ct"` // 创建时间 + Ut *int64 `json:"ut" bson:"ut"` // 更新时间 + DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 }