From 88702f1d3db33a3ee166ba7615ae39b8a719143f Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 13 十月 2023 15:26:51 +0800 Subject: [PATCH] Merge branch 'feat-sso' --- service/user.go | 55 - proto/user/user.pb.go | 194 +++++ router/base.go | 32 go.mod | 5 api/v1/salesReturn.go | 10 api/v1/salesRefund.go | 10 proto/user.proto | 12 api/v1/salesLeads.go | 9 model/user.go | 2 model/subOrder.go | 3 model/salesReturn.go | 10 api/v1/masterOrder.go | 10 service/serviceFollowup.go | 3 model/followRecord.go | 6 constvar/const.go | 4 model/serviceOrder.go | 24 go.sum | 15 middleware/jwt.go | 20 service/salesRefund.go | 3 main.go | 5 model/request/jwt.go | 2 api/v1/serviceFollowup.go | 10 service/salesDetails.go | 3 api/v1/client.go | 10 utils/clamis.go | 24 model/contract.go | 3 service/serviceOrder.go | 3 api/v1/contact.go | 10 api/v1/contract.go | 10 model/contact.go | 7 api/v1/quotation.go | 10 proto/user/user_grpc.pb.go | 49 + router/user.go | 48 middleware/interceptor.go | 21 model/masterOrder.go | 3 model/serviceFollowup.go | 10 conf/aps-crm.json | 2 middleware/user.go | 78 ++ api/v1/salesDetails.go | 10 api/v1/user.go | 723 +++++++++++------------ model/client.go | 4 service/salesReturn.go | 3 router/image.go | 31 api/v1/subOrder.go | 10 model/saleChance.go | 3 model/quotation.go | 2 api/v1/serviceOrder.go | 10 model/serviceContract.go | 11 api/v1/saleChance.go | 10 model/salesDetails.go | 11 api/v1/captcha.go | 104 +- service/lru.go | 40 + api/v1/serviceContract.go | 10 model/salesRefund.go | 11 router/index.go | 25 api/v1/followRecord.go | 10 service/serviceContract.go | 3 57 files changed, 1,140 insertions(+), 626 deletions(-) diff --git a/api/v1/captcha.go b/api/v1/captcha.go index 4be71ca..124ed57 100644 --- a/api/v1/captcha.go +++ b/api/v1/captcha.go @@ -1,62 +1,50 @@ package v1 -import ( - "aps_crm/conf" - "aps_crm/constvar" - "aps_crm/model/response" - "aps_crm/pkg/contextx" - "aps_crm/pkg/convertx" - "aps_crm/pkg/ecode" - "aps_crm/pkg/logx" - "github.com/gin-gonic/gin" - "github.com/mojocn/base64Captcha" - "time" -) - type BaseApi struct{} -// Captcha -// @Tags Base -// @Summary 鑾峰彇楠岃瘉鐮� -// @Produce application/json -// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" -// @Router /api/base/captcha [post] -func (slf *BaseApi) Captcha(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) - if !ok { - return - } - - // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚� - openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁� - openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿 - key := c.ClientIP() - v, ok := constvar.BlackCache.Get(key) - if !ok { - constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut)) - } - - var oc bool - if openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha { // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟 - oc = true - } - // 瀛楃,鍏紡,楠岃瘉鐮侀厤缃� - // 鐢熸垚榛樿鏁板瓧鐨刣river - driver := base64Captcha.NewDriverDigit(conf.Conf.Captcha.ImgHeight, conf.Conf.Captcha.ImgWidth, conf.Conf.Captcha.KeyLong, 0.7, 80) - cp := base64Captcha.NewCaptcha(driver, store) - id, b64s, err := cp.Generate() - captcha := store.Get(id, false) - logx.Infof("Captcha Generate captchaId:%v captcha:%v", id, captcha) - if err != nil { - logx.Errorf("Captcha Generate err:%v", err) - ctx.Fail(ecode.CaptchaGenerateFailed) - return - } - - ctx.OkWithDetailed(response.CaptchaResponse{ - CaptchaId: id, - PicPath: b64s, - CaptchaLength: conf.Conf.Captcha.KeyLong, - OpenCaptcha: oc, - }) -} +// +//// Captcha +//// @Tags Base +//// @Summary 鑾峰彇楠岃瘉鐮� +//// @Produce application/json +//// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" +//// @Router /api/base/captcha [post] +//func (slf *BaseApi) Captcha(c *gin.Context) { +// ctx, ok := contextx.NewContext(c, nil) +// if !ok { +// return +// } +// +// // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚� +// openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁� +// openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿 +// key := c.ClientIP() +// v, ok := constvar.BlackCache.Get(key) +// if !ok { +// constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut)) +// } +// +// var oc bool +// if openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha { // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟 +// oc = true +// } +// // 瀛楃,鍏紡,楠岃瘉鐮侀厤缃� +// // 鐢熸垚榛樿鏁板瓧鐨刣river +// driver := base64Captcha.NewDriverDigit(conf.Conf.Captcha.ImgHeight, conf.Conf.Captcha.ImgWidth, conf.Conf.Captcha.KeyLong, 0.7, 80) +// cp := base64Captcha.NewCaptcha(driver, store) +// id, b64s, err := cp.Generate() +// captcha := store.Get(id, false) +// logx.Infof("Captcha Generate captchaId:%v captcha:%v", id, captcha) +// if err != nil { +// logx.Errorf("Captcha Generate err:%v", err) +// ctx.Fail(ecode.CaptchaGenerateFailed) +// return +// } +// +// ctx.OkWithDetailed(response.CaptchaResponse{ +// CaptchaId: id, +// PicPath: b64s, +// CaptchaLength: conf.Conf.Captcha.KeyLong, +// OpenCaptcha: oc, +// }) +//} diff --git a/api/v1/client.go b/api/v1/client.go index 839083a..40375c9 100644 --- a/api/v1/client.go +++ b/api/v1/client.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -206,6 +208,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + clients, total, errCode := clientService.GetClientList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/contact.go b/api/v1/contact.go index 0766523..534bd03 100644 --- a/api/v1/contact.go +++ b/api/v1/contact.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -167,6 +169,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/contract.go b/api/v1/contract.go index 98b4ee9..6e432b3 100644 --- a/api/v1/contract.go +++ b/api/v1/contract.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -142,6 +144,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/followRecord.go b/api/v1/followRecord.go index 6a4d6f8..0fe3939 100644 --- a/api/v1/followRecord.go +++ b/api/v1/followRecord.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "errors" "github.com/gin-gonic/gin" "time" @@ -229,6 +231,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/masterOrder.go b/api/v1/masterOrder.go index 1e7b005..246e9b8 100644 --- a/api/v1/masterOrder.go +++ b/api/v1/masterOrder.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -152,6 +154,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + masterOrders, total, errCode := masterOrderService.GetMasterOrderList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/quotation.go b/api/v1/quotation.go index a26d4e9..4fd996c 100644 --- a/api/v1/quotation.go +++ b/api/v1/quotation.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -169,6 +171,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + quotations, total, errCode := quotationService.GetQuotationList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/saleChance.go b/api/v1/saleChance.go index b7bedb5..bb4714f 100644 --- a/api/v1/saleChance.go +++ b/api/v1/saleChance.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -209,6 +211,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + saleChances, total, errCode := saleChanceService.GetSaleChanceList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/salesDetails.go b/api/v1/salesDetails.go index 22a0744..3a64ec5 100644 --- a/api/v1/salesDetails.go +++ b/api/v1/salesDetails.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" "strconv" ) @@ -166,7 +168,13 @@ return } - salesDetailss, total, errCode := salesDetailsService.GetSalesDetailsList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.SaleChanceId) + var memberIds []int + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + memberIds = []int{userInfo.CrmUserId} + } + + salesDetailss, total, errCode := salesDetailsService.GetSalesDetailsList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.SaleChanceId, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/api/v1/salesLeads.go b/api/v1/salesLeads.go index c1dc6e4..0812a5a 100644 --- a/api/v1/salesLeads.go +++ b/api/v1/salesLeads.go @@ -7,6 +7,7 @@ "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -160,6 +161,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + salesLeadss, total, errCode := salesLeadsService.GetSalesLeadsList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/salesRefund.go b/api/v1/salesRefund.go index 494f3b1..1d630b3 100644 --- a/api/v1/salesRefund.go +++ b/api/v1/salesRefund.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" "strconv" "strings" @@ -170,7 +172,13 @@ return } - salesRefunds, total, errCode := salesRefundService.GetSalesRefundList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.SourceId) + var memberIds []int + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + memberIds = []int{userInfo.CrmUserId} + } + + salesRefunds, total, errCode := salesRefundService.GetSalesRefundList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.SourceId, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/api/v1/salesReturn.go b/api/v1/salesReturn.go index ab99f0c..f53260f 100644 --- a/api/v1/salesReturn.go +++ b/api/v1/salesReturn.go @@ -1,12 +1,14 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" "aps_crm/pkg/structx" + "aps_crm/utils" "github.com/gin-gonic/gin" "strconv" "strings" @@ -165,7 +167,13 @@ return } - salesReturns, total, errCode := salesReturnService.GetSalesReturnList(params) + var memberIds []int + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + memberIds = []int{userInfo.CrmUserId} + } + + salesReturns, total, errCode := salesReturnService.GetSalesReturnList(params, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/api/v1/serviceContract.go b/api/v1/serviceContract.go index c50b29a..dd32f74 100644 --- a/api/v1/serviceContract.go +++ b/api/v1/serviceContract.go @@ -1,12 +1,14 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" "aps_crm/pkg/structx" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -144,7 +146,13 @@ return } - serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params) + var memberIds []int + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + memberIds = []int{userInfo.CrmUserId} + } + + serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/api/v1/serviceFollowup.go b/api/v1/serviceFollowup.go index 410de2d..116acf7 100644 --- a/api/v1/serviceFollowup.go +++ b/api/v1/serviceFollowup.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -151,7 +153,13 @@ return } - serviceFollowups, total, errCode := serviceFollowupService.GetServiceFollowupList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.ServiceOrderId) + var memberIds []int + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + memberIds = []int{userInfo.CrmUserId} + } + + serviceFollowups, total, errCode := serviceFollowupService.GetServiceFollowupList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.ServiceOrderId, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/api/v1/serviceOrder.go b/api/v1/serviceOrder.go index 2db3520..aef80c2 100644 --- a/api/v1/serviceOrder.go +++ b/api/v1/serviceOrder.go @@ -1,6 +1,7 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" @@ -8,6 +9,7 @@ "aps_crm/pkg/ecode" "aps_crm/pkg/structx" "aps_crm/service" + "aps_crm/utils" "github.com/gin-gonic/gin" "strconv" ) @@ -139,7 +141,13 @@ return } - serviceOrder, total, errCode := service.NewServiceOrderService().GetServiceOrderList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword, params.ServiceContractId, params.SalesDetailsId) + var memberIds []int + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + memberIds = []int{userInfo.CrmUserId} + } + + serviceOrder, total, errCode := service.NewServiceOrderService().GetServiceOrderList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword, params.ServiceContractId, params.SalesDetailsId, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/api/v1/subOrder.go b/api/v1/subOrder.go index 3d6a0a1..17372fc 100644 --- a/api/v1/subOrder.go +++ b/api/v1/subOrder.go @@ -1,11 +1,13 @@ package v1 import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" + "aps_crm/utils" "github.com/gin-gonic/gin" ) @@ -140,6 +142,14 @@ return } + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + subOrders, total, errCode := subOrderService.GetSubOrderList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) diff --git a/api/v1/user.go b/api/v1/user.go index 9cd713c..76fecfc 100644 --- a/api/v1/user.go +++ b/api/v1/user.go @@ -1,381 +1,364 @@ package v1 -import ( - "aps_crm/conf" - "aps_crm/constvar" - "aps_crm/model" - "aps_crm/model/request" - "aps_crm/model/response" - "aps_crm/pkg/contextx" - "aps_crm/pkg/ecode" - "aps_crm/pkg/encrypt" - "aps_crm/pkg/logx" - "aps_crm/pkg/snowflake" - "aps_crm/utils" - "fmt" - "github.com/gin-gonic/gin" - "github.com/go-redis/redis/v8" - "github.com/mojocn/base64Captcha" -) - -// 褰撳紑鍚鏈嶅姟鍣ㄩ儴缃叉椂锛屾浛鎹笅闈㈢殑閰嶇疆锛屼娇鐢╮edis鍏变韩瀛樺偍楠岃瘉鐮� -// var store = captcha.NewDefaultRedisStore() -var store = base64Captcha.DefaultMemStore - -// Login // -// @Tags Base -// @Summary 鐢ㄦ埛鐧诲綍 -// @Produce application/json -// @Param object body request.Login true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" -// @Router /api/base/login [post] -func (slf *BaseApi) Login(c *gin.Context) { - var params request.Login - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚� - key := c.ClientIP() - //openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鏆存鏁� - //openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿 - //v, ok := constvar.BlackCache.Get(key) - //if !ok { - // constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut)) - //} - - //var oc = openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃叉毚娆℃暟 - - //if !oc || store.Verify(params.CaptchaId, params.Captcha, true) { - u := &model.User{Username: params.Username, Password: params.Password} - user, errCode := userService.Login(u) - if errCode != ecode.OK { - logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛鍚嶄笉瀛樺湪鎴栬�呭瘑鐮侀敊璇�! errCode:%v", errCode) - // 楠岃瘉鐮佹鏁�+1 - _ = constvar.BlackCache.Increment(key, 1) - ctx.Fail(errCode) - return - } - // 璧嬪�艰彍鍗旾D鍒楄〃 - //user.MenuIds, _ = menuService.GetUserMenuIds(user.UUID, user.UserType) - slf.TokenNext(ctx, *user) - return - //} - - // 楠岃瘉鐮佹鏁�+1 - //_ = constvar.BlackCache.Increment(key, 1) - //ctx.Fail(ecode.CaptchaErr) -} - -// TokenNext 鐧诲綍浠ュ悗绛惧彂jwt -func (slf *BaseApi) TokenNext(ctx *contextx.Context, user model.User) { - logx.Infof("TokenNext user:%+v", user) - j := &utils.JWT{SigningKey: []byte(conf.Conf.JWT.SigningKey)} // 鍞竴绛惧悕 - claims := j.CreateClaims(request.BaseClaims{ - UserId: user.UUID, - Username: user.Username, - UserType: user.UserType, - AuthorityId: user.AuthorityId, - }) - token, err := j.CreateToken(claims) - if err != nil { - logx.Errorf("鍒涘缓token澶辫触! err:%v", err) - ctx.Fail(ecode.CreateTokenErr) - return - } - if !conf.Conf.System.UseMultipoint { // 涓嶅厑璁稿鐐圭櫥褰� - ctx.OkWithDetailed(response.LoginResponse{ - User: user, - Token: token, - //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, - }) - return - } - - if jwtStr, err := jwtService.GetRedisJWT(user.Username); err == redis.Nil { // redis鏃燡WT鏁版嵁 - if err := jwtService.SetRedisJWT(token, user.Username); err != nil { - logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err) - ctx.Fail(ecode.RedisErr) - return - } - ctx.OkWithDetailed(response.LoginResponse{ - User: user, - Token: token, - //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, - }) - } else if err != nil { // redis鑾峰彇JWT鎶ラ敊 - logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err) - ctx.Fail(ecode.RedisErr) - } else { // 鎴愬姛鑾峰彇redis鐨凧WT锛屾棫鐨勪綔搴� - var blackJWT model.JwtBlacklist - blackJWT.Jwt = jwtStr - if err := jwtService.JsonInBlacklist(blackJWT); err != nil { - ctx.Fail(ecode.DBErr) - return - } - if err := jwtService.SetRedisJWT(token, user.Username); err != nil { - ctx.Fail(ecode.RedisErr) - return - } - ctx.OkWithDetailed(response.LoginResponse{ - User: user, - Token: token, - //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, - }) - } -} - -// Register +//// 褰撳紑鍚鏈嶅姟鍣ㄩ儴缃叉椂锛屾浛鎹笅闈㈢殑閰嶇疆锛屼娇鐢╮edis鍏变韩瀛樺偍楠岃瘉鐮� +//// var store = captcha.NewDefaultRedisStore() +//var store = base64Captcha.DefaultMemStore // -// @Tags User -// @Summary 娉ㄥ唽璐﹀彿 -// @Produce application/json -// @Param object body request.Register true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{data=response.UserResponse} "鎴愬姛" -// @Router /api/user/register [post] -func (slf *BaseApi) Register(c *gin.Context) { - var params request.Register - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - userInfo := utils.GetUserInfo(c) - if len(userInfo.UserId) <= 0 { - ctx.Fail(ecode.UnknownErr) - return - } - - if len(params.Username) == 0 || len(params.Password) == 0 || len(params.NickName) == 0 || params.AuthorityId == 0 || len(params.RePassword) == 0 || params.DepartmentId == 0 { - ctx.Fail(ecode.ParamsErr) - return - } - - var userId = fmt.Sprintf("u%v", snowflake.GenerateId()) - var passWord = encrypt.BcryptHash(params.Password) - var userType constvar.UserType - - user := &model.User{UUID: userId, Username: params.Username, UserType: userType, NickName: params.NickName, Password: passWord, HeaderImg: params.HeaderImg, Phone: params.Phone, Email: params.Email, DepartmentId: params.DepartmentId, AuthorityId: params.AuthorityId} - userReturn, errCode := userService.Register(user) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - - //if user.UserType == constvar.UserTypePrimary { // 涓昏处鎴峰垱寤哄搴旂殑鏁版嵁搴撶敤鎴峰拰鎺掔▼鏁版嵁搴� - // err := model.NewMysql().CreateDatabase(user.Username) - // if err != nil { - // ctx.Fail(ecode.CreateDatabaseErr) - // return - // } - // - // defaultPwd := fmt.Sprintf("%v@Basic2023", user.Username) - // err = model.NewMysql().CreateUser(user.Username, defaultPwd, user.Username) - // if err != nil { - // ctx.Fail(ecode.CreateDatabaseUserErr) - // return - // } - //} - - ctx.OkWithDetailed(response.UserResponse{User: *userReturn}) -} - -// ChangePassword +//// Login +//// +//// @Tags Base +//// @Summary 鐢ㄦ埛鐧诲綍 +//// @Produce application/json +//// @Param object body request.Login true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" +//// @Router /api/base/login [post] +//func (slf *BaseApi) Login(c *gin.Context) { +// var params request.Login +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } // -// @Tags User -// @Summary 鐢ㄦ埛淇敼瀵嗙爜 -// @Produce application/json -// @Param object body request.ChangePasswordReq true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} "鎴愬姛" -// @Router /api/user/changePassword [post] -func (slf *BaseApi) ChangePassword(c *gin.Context) { - var params request.ChangePasswordReq - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - u := &model.User{UUID: utils.GetUserID(c), Password: params.Password} - _, errCode := userService.ChangePassword(u, params.NewPassword) - if errCode != ecode.OK { - ctx.Fail(errCode) - return - } - ctx.Ok() -} - -// GetUserList +// // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚� +// key := c.ClientIP() +// //openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鏆存鏁� +// //openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿 +// //v, ok := constvar.BlackCache.Get(key) +// //if !ok { +// // constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut)) +// //} // -// @Tags User -// @Summary 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�) -// @Produce application/json -// @Param object body request.GetUserList true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{data=response.PageResult} "鎴愬姛" -// @Router /api/user/getUserList [post] -func (slf *BaseApi) GetUserList(c *gin.Context) { - var params request.GetUserList - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - userInfo := utils.GetUserInfo(c) - if len(userInfo.UserId) <= 0 || len(userInfo.ParentId) == 0 { - ctx.Fail(ecode.UnknownErr) - return - } - - ctx.OkWithDetailed(response.PageResult{ - Page: params.Page, - PageSize: params.PageSize, - }) -} - -// DeleteUser +// //var oc = openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃叉毚娆℃暟 // -// @Tags User -// @Summary 鍒犻櫎鐢ㄦ埛 -// @Produce application/json -// @Param object body request.DeleteUserReq true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} "鎴愬姛" -// @Router /api/user/deleteUser [delete] -func (slf *BaseApi) DeleteUser(c *gin.Context) { - var params request.DeleteUserReq - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - if len(params.UserId) <= 0 { - ctx.Fail(ecode.ParamsErr) - return - } - - userInfo := utils.GetUserInfo(c) - if userInfo.UserType != constvar.UserTypePrimary || userInfo.UserId == params.UserId { - ctx.Fail(ecode.NoPowerErr) - return - } - - err := userService.DeleteUser(params.UserId) - if err != nil { - logx.Errorf("鍒犻櫎澶辫触! err:%v", err) - ctx.Fail(ecode.DBErr) - return - } - ctx.Ok() -} - -// SetUserInfo +// //if !oc || store.Verify(params.CaptchaId, params.Captcha, true) { +// u := &model.User{Username: params.Username, Password: params.Password} +// user, errCode := userService.Login(u) +// if errCode != ecode.OK { +// logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛鍚嶄笉瀛樺湪鎴栬�呭瘑鐮侀敊璇�! errCode:%v", errCode) +// // 楠岃瘉鐮佹鏁�+1 +// _ = constvar.BlackCache.Increment(key, 1) +// ctx.Fail(errCode) +// return +// } +// // 璧嬪�艰彍鍗旾D鍒楄〃 +// //user.MenuIds, _ = menuService.GetUserMenuIds(user.UUID, user.UserType) +// slf.TokenNext(ctx, *user) +// return +// //} // -// @Tags User -// @Summary 璁剧疆鐢ㄦ埛淇℃伅 -// @Produce application/json -// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} "鎴愬姛" -// @Router /api/user/setUserInfo [post] -func (slf *BaseApi) SetUserInfo(c *gin.Context) { - var params request.ChangeUserInfo - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - err := userService.SetUserInfo(model.User{ - UUID: params.ID, - NickName: params.NickName, - HeaderImg: params.HeaderImg, - Phone: params.Phone, - Email: params.Email, - Pos: params.Pos, - }) - if err != nil { - logx.Errorf("璁剧疆澶辫触! err:%v", err) - ctx.Fail(ecode.DBErr) - return - } - ctx.Ok() -} - -// SetSelfInfo +// // 楠岃瘉鐮佹鏁�+1 +// //_ = constvar.BlackCache.Increment(key, 1) +// //ctx.Fail(ecode.CaptchaErr) +//} // -// @Tags User -// @Summary 璁剧疆鐢ㄦ埛淇℃伅 -// @Produce application/json -// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} "鎴愬姛" -// @Router /api/user/setSelfInfo [post] -func (slf *BaseApi) SetSelfInfo(c *gin.Context) { - var params request.ChangeUserInfo - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - params.ID = utils.GetUserID(c) - err := userService.SetUserInfo(model.User{ - UUID: params.ID, - NickName: params.NickName, - HeaderImg: params.HeaderImg, - Phone: params.Phone, - Email: params.Email, - Pos: params.Pos, - }) - if err != nil { - logx.Errorf("璁剧疆澶辫触! err:%v", err) - ctx.Fail(ecode.DBErr) - return - } - ctx.Ok() -} - -// GetUserInfo +//// TokenNext 鐧诲綍浠ュ悗绛惧彂jwt +//func (slf *BaseApi) TokenNext(ctx *contextx.Context, user model.User) { +// logx.Infof("TokenNext user:%+v", user) +// j := &utils.JWT{SigningKey: []byte(conf.Conf.JWT.SigningKey)} // 鍞竴绛惧悕 +// claims := j.CreateClaims(request.BaseClaims{ +// UserId: user.UUID, +// Username: user.Username, +// UserType: user.UserType, +// AuthorityId: user.AuthorityId, +// }) +// token, err := j.CreateToken(claims) +// if err != nil { +// logx.Errorf("鍒涘缓token澶辫触! err:%v", err) +// ctx.Fail(ecode.CreateTokenErr) +// return +// } +// if !conf.Conf.System.UseMultipoint { // 涓嶅厑璁稿鐐圭櫥褰� +// ctx.OkWithDetailed(response.LoginResponse{ +// User: user, +// Token: token, +// //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, +// }) +// return +// } // -// @Tags User -// @Summary 鑾峰彇鑷韩淇℃伅 -// @Produce application/json -// @Success 200 {object} contextx.Response{} "鎴愬姛" -// @Router /api/user/getUserInfo [post] -func (slf *BaseApi) GetUserInfo(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) - if !ok { - return - } - - id := utils.GetUserID(c) - ReqUser, err := userService.GetUserInfo(id) - if err != nil { - logx.Errorf("鑾峰彇澶辫触! err:%v", err) - ctx.Fail(ecode.DBErr) - return - } - ctx.OkWithDetailed(response.UserResponse{ - User: *ReqUser, - }) -} - -// ResetPassword +// if jwtStr, err := jwtService.GetRedisJWT(user.Username); err == redis.Nil { // redis鏃燡WT鏁版嵁 +// if err := jwtService.SetRedisJWT(token, user.Username); err != nil { +// logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err) +// ctx.Fail(ecode.RedisErr) +// return +// } +// ctx.OkWithDetailed(response.LoginResponse{ +// User: user, +// Token: token, +// //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, +// }) +// } else if err != nil { // redis鑾峰彇JWT鎶ラ敊 +// logx.Errorf("璁剧疆鐧诲綍鐘舵�佸け璐�! err:%v", err) +// ctx.Fail(ecode.RedisErr) +// } else { // 鎴愬姛鑾峰彇redis鐨凧WT锛屾棫鐨勪綔搴� +// var blackJWT model.JwtBlacklist +// blackJWT.Jwt = jwtStr +// if err := jwtService.JsonInBlacklist(blackJWT); err != nil { +// ctx.Fail(ecode.DBErr) +// return +// } +// if err := jwtService.SetRedisJWT(token, user.Username); err != nil { +// ctx.Fail(ecode.RedisErr) +// return +// } +// ctx.OkWithDetailed(response.LoginResponse{ +// User: user, +// Token: token, +// //ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, +// }) +// } +//} // -// @Tags User -// @Summary 閲嶇疆鐢ㄦ埛瀵嗙爜 -// @Produce application/json -// @Param object body model.User true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{} "鎴愬姛" -// @Router /api/user/resetPassword [post] -func (slf *BaseApi) ResetPassword(c *gin.Context) { - var params model.User - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - err := userService.ResetPassword(params.UUID) - if err != nil { - logx.Errorf("閲嶇疆澶辫触! err:%v", err) - ctx.Fail(ecode.DBErr) - return - } - ctx.Ok() -} +//// Register +//// +//// @Tags User +//// @Summary 娉ㄥ唽璐﹀彿 +//// @Produce application/json +//// @Param object body request.Register true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{data=response.UserResponse} "鎴愬姛" +//// @Router /api/user/register [post] +//func (slf *BaseApi) Register(c *gin.Context) { +// var params request.Register +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } +// +// userInfo := utils.GetUserInfo(c) +// if len(userInfo.UserId) <= 0 { +// ctx.Fail(ecode.UnknownErr) +// return +// } +// +// if len(params.Username) == 0 || len(params.Password) == 0 || len(params.NickName) == 0 || params.AuthorityId == 0 || len(params.RePassword) == 0 || params.DepartmentId == 0 { +// ctx.Fail(ecode.ParamsErr) +// return +// } +// +// var userId = fmt.Sprintf("u%v", snowflake.GenerateId()) +// var passWord = encrypt.BcryptHash(params.Password) +// var userType constvar.UserType +// +// user := &model.User{UUID: userId, Username: params.Username, UserType: userType, NickName: params.NickName, Password: passWord, HeaderImg: params.HeaderImg, Phone: params.Phone, Email: params.Email, DepartmentId: params.DepartmentId, AuthorityId: params.AuthorityId} +// userReturn, errCode := userService.Register(user) +// if errCode != ecode.OK { +// ctx.Fail(errCode) +// return +// } +// +// //if user.UserType == constvar.UserTypePrimary { // 涓昏处鎴峰垱寤哄搴旂殑鏁版嵁搴撶敤鎴峰拰鎺掔▼鏁版嵁搴� +// // err := model.NewMysql().CreateDatabase(user.Username) +// // if err != nil { +// // ctx.Fail(ecode.CreateDatabaseErr) +// // return +// // } +// // +// // defaultPwd := fmt.Sprintf("%v@Basic2023", user.Username) +// // err = model.NewMysql().CreateUser(user.Username, defaultPwd, user.Username) +// // if err != nil { +// // ctx.Fail(ecode.CreateDatabaseUserErr) +// // return +// // } +// //} +// +// ctx.OkWithDetailed(response.UserResponse{User: *userReturn}) +//} +// +//// ChangePassword +//// +//// @Tags User +//// @Summary 鐢ㄦ埛淇敼瀵嗙爜 +//// @Produce application/json +//// @Param object body request.ChangePasswordReq true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{} "鎴愬姛" +//// @Router /api/user/changePassword [post] +//func (slf *BaseApi) ChangePassword(c *gin.Context) { +// var params request.ChangePasswordReq +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } +// +// u := &model.User{UUID: utils.GetUserID(c), Password: params.Password} +// _, errCode := userService.ChangePassword(u, params.NewPassword) +// if errCode != ecode.OK { +// ctx.Fail(errCode) +// return +// } +// ctx.Ok() +//} +// +//// GetUserList +//// +//// @Tags User +//// @Summary 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�) +//// @Produce application/json +//// @Param object body request.GetUserList true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{data=response.PageResult} "鎴愬姛" +//// @Router /api/user/getUserList [post] +//func (slf *BaseApi) GetUserList(c *gin.Context) { +// var params request.GetUserList +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } +// +// userInfo := utils.GetUserInfo(c) +// if len(userInfo.UserId) <= 0 || len(userInfo.ParentId) == 0 { +// ctx.Fail(ecode.UnknownErr) +// return +// } +// +// ctx.OkWithDetailed(response.PageResult{ +// Page: params.Page, +// PageSize: params.PageSize, +// }) +//} +// +//// DeleteUser +//// +//// @Tags User +//// @Summary 鍒犻櫎鐢ㄦ埛 +//// @Produce application/json +//// @Param object body request.DeleteUserReq true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{} "鎴愬姛" +//// @Router /api/user/deleteUser [delete] +//func (slf *BaseApi) DeleteUser(c *gin.Context) { +// var params request.DeleteUserReq +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } +// +// if len(params.UserId) <= 0 { +// ctx.Fail(ecode.ParamsErr) +// return +// } +// +// userInfo := utils.GetUserInfo(c) +// if userInfo.UserType != constvar.UserTypePrimary || userInfo.UserId == params.UserId { +// ctx.Fail(ecode.NoPowerErr) +// return +// } +// +// err := userService.DeleteUser(params.UserId) +// if err != nil { +// logx.Errorf("鍒犻櫎澶辫触! err:%v", err) +// ctx.Fail(ecode.DBErr) +// return +// } +// ctx.Ok() +//} +// +//// SetUserInfo +//// +//// @Tags User +//// @Summary 璁剧疆鐢ㄦ埛淇℃伅 +//// @Produce application/json +//// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{} "鎴愬姛" +//// @Router /api/user/setUserInfo [post] +//func (slf *BaseApi) SetUserInfo(c *gin.Context) { +// var params request.ChangeUserInfo +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } +// +// err := userService.SetUserInfo(model.User{ +// UUID: params.ID, +// NickName: params.NickName, +// HeaderImg: params.HeaderImg, +// Phone: params.Phone, +// Email: params.Email, +// Pos: params.Pos, +// }) +// if err != nil { +// logx.Errorf("璁剧疆澶辫触! err:%v", err) +// ctx.Fail(ecode.DBErr) +// return +// } +// ctx.Ok() +//} +// +//// SetSelfInfo +//// +//// @Tags User +//// @Summary 璁剧疆鐢ㄦ埛淇℃伅 +//// @Produce application/json +//// @Param object body request.ChangeUserInfo true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{} "鎴愬姛" +//// @Router /api/user/setSelfInfo [post] +//func (slf *BaseApi) SetSelfInfo(c *gin.Context) { +// var params request.ChangeUserInfo +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } +// +// params.ID = utils.GetUserID(c) +// err := userService.SetUserInfo(model.User{ +// UUID: params.ID, +// NickName: params.NickName, +// HeaderImg: params.HeaderImg, +// Phone: params.Phone, +// Email: params.Email, +// Pos: params.Pos, +// }) +// if err != nil { +// logx.Errorf("璁剧疆澶辫触! err:%v", err) +// ctx.Fail(ecode.DBErr) +// return +// } +// ctx.Ok() +//} +// +//// GetUserInfo +//// +//// @Tags User +//// @Summary 鑾峰彇鑷韩淇℃伅 +//// @Produce application/json +//// @Success 200 {object} contextx.Response{} "鎴愬姛" +//// @Router /api/user/getUserInfo [post] +//func (slf *BaseApi) GetUserInfo(c *gin.Context) { +// ctx, ok := contextx.NewContext(c, nil) +// if !ok { +// return +// } +// +// id := utils.GetUserID(c) +// ReqUser, err := userService.GetUserInfo(id) +// if err != nil { +// logx.Errorf("鑾峰彇澶辫触! err:%v", err) +// ctx.Fail(ecode.DBErr) +// return +// } +// ctx.OkWithDetailed(response.UserResponse{ +// User: *ReqUser, +// }) +//} +// +//// ResetPassword +//// +//// @Tags User +//// @Summary 閲嶇疆鐢ㄦ埛瀵嗙爜 +//// @Produce application/json +//// @Param object body model.User true "鏌ヨ鍙傛暟" +//// @Success 200 {object} contextx.Response{} "鎴愬姛" +//// @Router /api/user/resetPassword [post] +//func (slf *BaseApi) ResetPassword(c *gin.Context) { +// var params model.User +// ctx, ok := contextx.NewContext(c, ¶ms) +// if !ok { +// return +// } +// +// err := userService.ResetPassword(params.UUID) +// if err != nil { +// logx.Errorf("閲嶇疆澶辫触! err:%v", err) +// ctx.Fail(ecode.DBErr) +// return +// } +// ctx.Ok() +//} diff --git a/conf/aps-crm.json b/conf/aps-crm.json index 1277fbd..d8f9bfe 100644 --- a/conf/aps-crm.json +++ b/conf/aps-crm.json @@ -49,7 +49,7 @@ }, "GrpcServiceAddr": { "Aps": "192.168.20.120:9091", - "Admin": "192.168.20.119:50051" + "Admin": "192.168.20.120:50051" } } diff --git a/constvar/const.go b/constvar/const.go index 20784bc..98cfd24 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -204,3 +204,7 @@ } return true } + +const ( + SystemType = 2 +) diff --git a/go.mod b/go.mod index ac5dfee..6fb32ea 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,10 @@ moul.io/zapgorm2 v1.3.0 ) -require google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect +require ( + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect +) require ( github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect diff --git a/go.sum b/go.sum index da3bc7c..15a16ee 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,8 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= @@ -142,6 +144,7 @@ github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= @@ -229,18 +232,27 @@ github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.17.2/go.mod h1:lcxIZN44yMIrWI78a5CpucdD14hX0SBDbNRvjDBItsw= github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= @@ -279,6 +291,7 @@ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8= +github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -304,6 +317,7 @@ github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= @@ -770,6 +784,7 @@ gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index fc4488d..2b73602 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ v1 "aps_crm/api/v1" "aps_crm/conf" "aps_crm/initialize" + "aps_crm/middleware" "aps_crm/model" "aps_crm/pkg/logx" "aps_crm/router" @@ -47,7 +48,7 @@ } go v1.InitProductServiceConn() - go service.InitUserConn() + go middleware.InitUserConn() go v1.InitCodeServiceConn() //c := cron.New() @@ -63,8 +64,8 @@ <-quit v1.CloseProductServiceConn() - service.CloseUserConn() v1.CloseCodeServiceConn() + middleware.CloseUserConn() logx.Infof("aps-crm exited...") os.Exit(0) diff --git a/middleware/interceptor.go b/middleware/interceptor.go new file mode 100644 index 0000000..ca3a2fb --- /dev/null +++ b/middleware/interceptor.go @@ -0,0 +1,21 @@ +package middleware + +import ( + "context" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +// HeaderInterceptor 鎷︽埅鍣ㄥ嚱鏁� +func HeaderInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { + token := ctx.Value("token") + if token != nil { + // 鍒涘缓涓�涓嚜瀹氫箟鐨� metadata + md := metadata.Pairs("token", token.(string)) + // 灏� metadata 娣诲姞鍒� context 涓� + ctx = metadata.NewOutgoingContext(ctx, md) + } + // 璋冪敤瀹為檯鐨� gRPC 鏂规硶 + err := invoker(ctx, method, req, reply, cc, opts...) + return err +} diff --git a/middleware/jwt.go b/middleware/jwt.go index 673087c..ec143b0 100644 --- a/middleware/jwt.go +++ b/middleware/jwt.go @@ -82,10 +82,12 @@ func JWTAuth2() gin.HandlerFunc { return func(c *gin.Context) { + ctx := new(contextx.Context).SetCtx(c) // 鎴戜滑杩欓噷jwt閴存潈鍙栧ご閮ㄤ俊鎭� Authorization 鐧诲綍鏃跺洖杩斿洖token淇℃伅 杩欓噷鍓嶇闇�瑕佹妸token瀛樺偍鍒癱ookie鎴栬�呮湰鍦發ocalStorage涓� 涓嶈繃闇�瑕佽窡鍚庣鍗忓晢杩囨湡鏃堕棿 鍙互绾﹀畾鍒锋柊浠ょ墝鎴栬�呴噸鏂扮櫥褰� token := c.Request.Header.Get("Authorization") if token == "" { - c.Next() + ctx.Fail(ecode.JWTEmpty) + c.Abort() return } slices := strings.Split(token, " ") @@ -103,8 +105,20 @@ c.Next() return } - + userInfo := service.GetUserBaseCache(claims.UserId) + if userInfo == nil { + SyncUserInfo() + userInfo = service.GetUserBaseCache(claims.UserId) + } + claims.CrmUserId = userInfo.UserId + claims.NickName = userInfo.NickName c.Set("claims", claims) - c.Next() + if CheckAuth(c.Request.RequestURI, token) { + c.Next() + } else { + ctx.Fail(ecode.JWTDisabled) + c.Abort() + return + } } } diff --git a/middleware/user.go b/middleware/user.go new file mode 100644 index 0000000..c6df3f9 --- /dev/null +++ b/middleware/user.go @@ -0,0 +1,78 @@ +package middleware + +import ( + "aps_crm/conf" + "aps_crm/constvar" + "aps_crm/model" + "aps_crm/pkg/logx" + "aps_crm/proto/user" + "context" + "fmt" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "time" +) + +var ( + userConn *grpc.ClientConn +) + +func InitUserConn() { + var err error + userConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Admin, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(HeaderInterceptor)) + if err != nil { + logx.Errorf("grpc dial user service error: %v", err.Error()) + return + } +} + +func CloseUserConn() { + if userConn != nil { + userConn.Close() + } +} + +func CheckAuth(apiPath string, token string) bool { + cli := user.NewUserServiceClient(userConn) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + ctx = context.WithValue(ctx, "token", token) + rsp, err := cli.UserMenuCheck(ctx, &user.CheckRequest{ + ApiPath: apiPath, + SystemType: constvar.SystemType, + }) + if err != nil { + logx.Errorf("check auth err: %v", err) + return false + } + return rsp.Result +} + +func SyncUserInfo() { + cli := user.NewUserServiceClient(userConn) + + var users []*user.User + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := cli.SyncUser(ctx, &user.UserRequest{Users: users}) + if err != nil { + logx.Errorf("could not sync users: %v", err) + return + } + + fmt.Printf("Synced: %v, Message: %s", r.List, r.Message) + + for _, member := range r.List { + err = model.NewUserSearch(nil).FirstOrCreate(model.User{ + UUID: member.Uuid, + Username: member.Username, + UserType: constvar.UserType(member.Usertype), + NickName: member.Nickname, + }) + if err != nil { + logx.Errorf("sync user error: %v", err.Error()) + continue + } + } +} diff --git a/model/client.go b/model/client.go index 9e91558..28d4a52 100644 --- a/model/client.go +++ b/model/client.go @@ -113,9 +113,7 @@ db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%") } - case int: - case int64: - case float64: + case int, uint, int64, float64: if key == "id" || key == "client_type_id" || key == "client_status_id" || key == "member_id" { db = db.Where(key+" = ?", v) } diff --git a/model/contact.go b/model/contact.go index 9961a42..c7ecfea 100644 --- a/model/contact.go +++ b/model/contact.go @@ -93,9 +93,10 @@ db = db.Where("is_first = ?", false) } } - case int: - case int64: - case float64: + case int, uint, int64, float64: + if key == "id" || key == "client_type_id" || key == "client_status_id" || key == "member_id" { + db = db.Where(key+" = ?", v) + } if key == "client_id" { db = db.Where("client_id = ? and is_first = true", v) } diff --git a/model/contract.go b/model/contract.go index 35a23a7..e287473 100644 --- a/model/contract.go +++ b/model/contract.go @@ -71,6 +71,9 @@ db = db.Where(key+"= ?", v) } case int: + if key == "member_id" { + db = db.Where(key+"= ?", v) + } } } } diff --git a/model/followRecord.go b/model/followRecord.go index 6188d70..ffa3d10 100644 --- a/model/followRecord.go +++ b/model/followRecord.go @@ -98,10 +98,8 @@ if key == "client_status" { db = db.Joins("Client").Joins("Client.ClientStatus").Where("Client__ClientStatus.name LIKE ?", "%"+v+"%") } - case int: - case int64: - case float64: - if key == "client_id" || key == "contact_id" || key == "sales_leads_id" || key == "sale_chance_id" { + case int, int64, float64: + if key == "client_id" || key == "contact_id" || key == "sales_leads_id" || key == "sale_chance_id" || key == "member_id" { db = db.Where(key+" = ?", v) } } diff --git a/model/masterOrder.go b/model/masterOrder.go index 256b492..ac02f01 100644 --- a/model/masterOrder.go +++ b/model/masterOrder.go @@ -64,8 +64,7 @@ if key == "member_name" { db = db.Joins("Member").Where("Member.username = ?", v) } - case int: - case float64: + case int, float64: if key == "client_id" || key == "member_id" || key == "money" { db = db.Where(key+" = ?", v) } diff --git a/model/quotation.go b/model/quotation.go index 24257f4..956371b 100644 --- a/model/quotation.go +++ b/model/quotation.go @@ -80,7 +80,7 @@ } case int: - if key == "client_id" || key == "sale_chance_id" { + if key == "client_id" || key == "sale_chance_id" || key == "member_id" { db = db.Where(key+" = ?", v) } } diff --git a/model/request/jwt.go b/model/request/jwt.go index 1b2f444..e67ab55 100644 --- a/model/request/jwt.go +++ b/model/request/jwt.go @@ -10,6 +10,8 @@ BaseClaims BufferTime int64 jwt.StandardClaims + CrmUserId int + NickName string } type BaseClaims struct { diff --git a/model/saleChance.go b/model/saleChance.go index bc5ef40..61b4a1a 100644 --- a/model/saleChance.go +++ b/model/saleChance.go @@ -111,8 +111,7 @@ db = db.Where("expected_time LIKE ?", "%"+v+"%") } - case int: - case float64: + case int, float64: if key == "member_id" || key == "budget" || key == "projected_amount" { db = db.Where(key+" = ?", v) } diff --git a/model/salesDetails.go b/model/salesDetails.go index b0e58b3..3eb8372 100644 --- a/model/salesDetails.go +++ b/model/salesDetails.go @@ -52,6 +52,7 @@ PageNum int PageSize int Preload bool + MemberIds []int } ) @@ -88,6 +89,11 @@ db = db.Joins("left join sales_details_product sdp on sdp.sales_details_id = sales_details.id left join products on sdp.product_id = products.id").Where("products.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) } + + if len(slf.MemberIds) > 0 { + db = db.Where("member_id in ?", slf.MemberIds) + } + if slf.Preload { db = db.Preload("Products"). Preload("Member"). @@ -166,6 +172,11 @@ return slf } +func (slf *SalesDetailsSearch) SetMemberIds(memberIds []int) *SalesDetailsSearch { + slf.MemberIds = memberIds + return slf +} + func (slf *SalesDetailsSearch) SetPreload(preload bool) *SalesDetailsSearch { slf.Preload = preload return slf diff --git a/model/salesRefund.go b/model/salesRefund.go index 5218841..4a16620 100644 --- a/model/salesRefund.go +++ b/model/salesRefund.go @@ -43,6 +43,7 @@ PageSize int Preload bool Ids []int + MemberIds []int } ) @@ -108,6 +109,10 @@ db = db.Where("amount_total like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) } + } + + if len(slf.MemberIds) > 0 { + db = db.Where("member_id in ?", slf.MemberIds) } return db @@ -211,3 +216,9 @@ var db = slf.build() return db.Updates(data).Error } + + +func (slf *SalesRefundSearch) SetMemberIds(memberIds []int) *SalesRefundSearch { + slf.MemberIds = memberIds + return slf +} diff --git a/model/salesReturn.go b/model/salesReturn.go index 3f1d335..884e501 100644 --- a/model/salesReturn.go +++ b/model/salesReturn.go @@ -46,6 +46,7 @@ PageSize int Preload bool Ids []int + MemberIds []int } ) @@ -105,6 +106,10 @@ db = db.Where("amount_has_refund = ?", slf.Keyword) } + } + + if len(slf.MemberIds) > 0 { + db = db.Where("member_id in ?", slf.MemberIds) } return db @@ -207,3 +212,8 @@ var db = slf.build() return db.Updates(data).Error } + +func (slf *SalesReturnSearch) SetMemberIds(memberIds []int) *SalesReturnSearch { + slf.MemberIds = memberIds + return slf +} diff --git a/model/serviceContract.go b/model/serviceContract.go index 9939134..a8fd896 100644 --- a/model/serviceContract.go +++ b/model/serviceContract.go @@ -56,6 +56,7 @@ PageNum int PageSize int Preload bool + MemberIds []int } ) @@ -109,6 +110,11 @@ db = db.Where("amount_receivable = ?", slf.Keyword) } + + if len(slf.MemberIds) > 0 { + db = db.Where("member_id in ?", slf.MemberIds) + } + if slf.Preload { db = db. Preload("Client"). @@ -212,6 +218,11 @@ return slf } +func (slf *ServiceContractSearch) SetMemberIds(memberIds []int) *ServiceContractSearch { + slf.MemberIds = memberIds + return slf +} + func (slf *ServiceContractSearch) SetSalesDetailsId(salesDetailsId int) *ServiceContractSearch { slf.SalesDetailsId = salesDetailsId return slf diff --git a/model/serviceFollowup.go b/model/serviceFollowup.go index c69cd23..fa12b97 100644 --- a/model/serviceFollowup.go +++ b/model/serviceFollowup.go @@ -46,6 +46,7 @@ PageNum int PageSize int Preload bool + MemberIds []int } ) @@ -95,6 +96,10 @@ Preload("SolveRate"). Preload("IsVisit"). Preload("OldMember") + } + + if len(slf.MemberIds) > 0 { + db = db.Where("member_id in ?", slf.MemberIds) } return db @@ -176,6 +181,11 @@ return slf } +func (slf *ServiceFollowupSearch) SetMemberIds(memberIds []int) *ServiceFollowupSearch { + slf.MemberIds = memberIds + return slf +} + func (slf *ServiceFollowupSearch) UpdateByMap(data map[string]interface{}) error { var db = slf.build() return db.Updates(data).Error diff --git a/model/serviceOrder.go b/model/serviceOrder.go index 0b012b5..16291f8 100644 --- a/model/serviceOrder.go +++ b/model/serviceOrder.go @@ -61,13 +61,14 @@ // ServiceOrderSearch 鏈嶅姟鍗曟悳绱㈡潯浠� ServiceOrderSearch struct { ServiceOrder - Orm *gorm.DB - QueryClass constvar.ServiceOrderQueryClass - KeywordType constvar.ServiceOrderKeywordType - Keyword string - PageNum int - PageSize int - Preload bool + Orm *gorm.DB + QueryClass constvar.ServiceOrderQueryClass + KeywordType constvar.ServiceOrderKeywordType + Keyword string + PageNum int + PageSize int + Preload bool + ServiceManIds []int } ) @@ -124,6 +125,10 @@ db = db.Joins("ServiceType", clause.LeftJoin).Where("ServiceType.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) case constvar.ServiceOrderKeywordFaultType: db = db.Joins("FaultType", clause.LeftJoin).Where("FaultType.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + } + + if len(slf.ServiceManIds) > 0 { + db = db.Where("service_man_id in ?", slf.ServiceManIds) } return db @@ -192,6 +197,11 @@ return slf } +func (slf *ServiceOrderSearch) SetMemberIds(memberIds []int) *ServiceOrderSearch { + slf.ServiceManIds = memberIds + return slf +} + func (slf *ServiceOrderSearch) SetPreload(preload bool) *ServiceOrderSearch { slf.Preload = preload return slf diff --git a/model/subOrder.go b/model/subOrder.go index b7d5869..175a6b6 100644 --- a/model/subOrder.go +++ b/model/subOrder.go @@ -74,6 +74,9 @@ if key == "master_order_id" { db = db.Where("master_order_id = ?", v) } + if key == "member_id" { + db = db.Where("member_id = ?", v) + } } } } diff --git a/model/user.go b/model/user.go index 6cbf77f..925d6d7 100644 --- a/model/user.go +++ b/model/user.go @@ -89,7 +89,7 @@ var db = slf.Orm.Model(&User{}).Preload("Menus") if slf.UUID != "" { - db = db.Where("id = ?", slf.UUID) + db = db.Where("uuid = ?", slf.UUID) } if slf.Username != "" { diff --git a/proto/user.proto b/proto/user.proto index 42d1243..50e32f3 100644 --- a/proto/user.proto +++ b/proto/user.proto @@ -6,6 +6,7 @@ service UserService { rpc SyncUser(UserRequest) returns (UserResponse); + rpc UserMenuCheck(CheckRequest) returns (CheckResponse); } message User { @@ -13,7 +14,6 @@ string username = 2; int32 usertype = 3; string nickname = 4; - // ... other fields } @@ -26,5 +26,15 @@ string message = 2; repeated User List = 3; int64 total = 4; +} +message CheckRequest { + string apiPath = 1; //鎺ュ彛璺緞 + int32 SystemType = 2; //绯荤粺鍚嶇О +} + +message CheckResponse { + int32 code = 1; + string message = 2; + bool result = 3; } diff --git a/proto/user/user.pb.go b/proto/user/user.pb.go index 91bbfbf..399d3aa 100644 --- a/proto/user/user.pb.go +++ b/proto/user/user.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v4.24.0 +// protoc-gen-go v1.31.0 +// protoc v3.19.0 // source: user.proto package user @@ -28,7 +28,7 @@ Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"` Usertype int32 `protobuf:"varint,3,opt,name=usertype,proto3" json:"usertype,omitempty"` - Nickname string `protobuf:"bytes,4,opt,name=nickname,proto3" json:"nickname,omitempty"` + Nickname string `protobuf:"bytes,4,opt,name=nickname,proto3" json:"nickname,omitempty"` // ... other fields } func (x *User) Reset() { @@ -209,6 +209,124 @@ return 0 } +type CheckRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ApiPath string `protobuf:"bytes,1,opt,name=apiPath,proto3" json:"apiPath,omitempty"` //鎺ュ彛璺緞 + SystemType int32 `protobuf:"varint,2,opt,name=SystemType,proto3" json:"SystemType,omitempty"` //绯荤粺鍚嶇О +} + +func (x *CheckRequest) Reset() { + *x = CheckRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_user_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CheckRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CheckRequest) ProtoMessage() {} + +func (x *CheckRequest) ProtoReflect() protoreflect.Message { + mi := &file_user_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CheckRequest.ProtoReflect.Descriptor instead. +func (*CheckRequest) Descriptor() ([]byte, []int) { + return file_user_proto_rawDescGZIP(), []int{3} +} + +func (x *CheckRequest) GetApiPath() string { + if x != nil { + return x.ApiPath + } + return "" +} + +func (x *CheckRequest) GetSystemType() int32 { + if x != nil { + return x.SystemType + } + return 0 +} + +type CheckResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Result bool `protobuf:"varint,3,opt,name=result,proto3" json:"result,omitempty"` +} + +func (x *CheckResponse) Reset() { + *x = CheckResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_user_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CheckResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CheckResponse) ProtoMessage() {} + +func (x *CheckResponse) ProtoReflect() protoreflect.Message { + mi := &file_user_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CheckResponse.ProtoReflect.Descriptor instead. +func (*CheckResponse) Descriptor() ([]byte, []int) { + return file_user_proto_rawDescGZIP(), []int{4} +} + +func (x *CheckResponse) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *CheckResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *CheckResponse) GetResult() bool { + if x != nil { + return x.Result + } + return false +} + var File_user_proto protoreflect.FileDescriptor var file_user_proto_rawDesc = []byte{ @@ -230,12 +348,26 @@ 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x32, 0x40, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x08, 0x53, 0x79, 0x6e, 0x63, 0x55, 0x73, - 0x65, 0x72, 0x12, 0x11, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, - 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x75, - 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x22, 0x48, 0x0a, 0x0c, 0x43, 0x68, 0x65, 0x63, 0x6b, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x70, 0x69, 0x50, 0x61, + 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x70, 0x69, 0x50, 0x61, 0x74, + 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, + 0x65, 0x22, 0x55, 0x0a, 0x0d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0x7a, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x08, 0x53, 0x79, 0x6e, 0x63, 0x55, + 0x73, 0x65, 0x72, 0x12, 0x11, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, + 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x0d, 0x55, 0x73, + 0x65, 0x72, 0x4d, 0x65, 0x6e, 0x75, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x12, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -250,19 +382,23 @@ return file_user_proto_rawDescData } -var file_user_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_user_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_user_proto_goTypes = []interface{}{ - (*User)(nil), // 0: user.User - (*UserRequest)(nil), // 1: user.UserRequest - (*UserResponse)(nil), // 2: user.UserResponse + (*User)(nil), // 0: user.User + (*UserRequest)(nil), // 1: user.UserRequest + (*UserResponse)(nil), // 2: user.UserResponse + (*CheckRequest)(nil), // 3: user.CheckRequest + (*CheckResponse)(nil), // 4: user.CheckResponse } var file_user_proto_depIdxs = []int32{ 0, // 0: user.UserRequest.users:type_name -> user.User 0, // 1: user.UserResponse.List:type_name -> user.User 1, // 2: user.UserService.SyncUser:input_type -> user.UserRequest - 2, // 3: user.UserService.SyncUser:output_type -> user.UserResponse - 3, // [3:4] is the sub-list for method output_type - 2, // [2:3] is the sub-list for method input_type + 3, // 3: user.UserService.UserMenuCheck:input_type -> user.CheckRequest + 2, // 4: user.UserService.SyncUser:output_type -> user.UserResponse + 4, // 5: user.UserService.UserMenuCheck:output_type -> user.CheckResponse + 4, // [4:6] is the sub-list for method output_type + 2, // [2:4] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name @@ -310,6 +446,30 @@ return nil } } + file_user_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CheckRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CheckResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -317,7 +477,7 @@ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_user_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/user/user_grpc.pb.go b/proto/user/user_grpc.pb.go index 2825eb1..789f1b7 100644 --- a/proto/user/user_grpc.pb.go +++ b/proto/user/user_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v3.19.0 +// source: user.proto package user @@ -14,11 +18,17 @@ // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +const ( + UserService_SyncUser_FullMethodName = "/user.UserService/SyncUser" + UserService_UserMenuCheck_FullMethodName = "/user.UserService/UserMenuCheck" +) + // UserServiceClient is the client API for UserService service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type UserServiceClient interface { SyncUser(ctx context.Context, in *UserRequest, opts ...grpc.CallOption) (*UserResponse, error) + UserMenuCheck(ctx context.Context, in *CheckRequest, opts ...grpc.CallOption) (*CheckResponse, error) } type userServiceClient struct { @@ -31,7 +41,16 @@ func (c *userServiceClient) SyncUser(ctx context.Context, in *UserRequest, opts ...grpc.CallOption) (*UserResponse, error) { out := new(UserResponse) - err := c.cc.Invoke(ctx, "/user.UserService/SyncUser", in, out, opts...) + err := c.cc.Invoke(ctx, UserService_SyncUser_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userServiceClient) UserMenuCheck(ctx context.Context, in *CheckRequest, opts ...grpc.CallOption) (*CheckResponse, error) { + out := new(CheckResponse) + err := c.cc.Invoke(ctx, UserService_UserMenuCheck_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -43,6 +62,7 @@ // for forward compatibility type UserServiceServer interface { SyncUser(context.Context, *UserRequest) (*UserResponse, error) + UserMenuCheck(context.Context, *CheckRequest) (*CheckResponse, error) mustEmbedUnimplementedUserServiceServer() } @@ -52,6 +72,9 @@ func (UnimplementedUserServiceServer) SyncUser(context.Context, *UserRequest) (*UserResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SyncUser not implemented") +} +func (UnimplementedUserServiceServer) UserMenuCheck(context.Context, *CheckRequest) (*CheckResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UserMenuCheck not implemented") } func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {} @@ -76,10 +99,28 @@ } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/user.UserService/SyncUser", + FullMethod: UserService_SyncUser_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(UserServiceServer).SyncUser(ctx, req.(*UserRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _UserService_UserMenuCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CheckRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServiceServer).UserMenuCheck(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: UserService_UserMenuCheck_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServiceServer).UserMenuCheck(ctx, req.(*CheckRequest)) } return interceptor(ctx, in, info, handler) } @@ -95,6 +136,10 @@ MethodName: "SyncUser", Handler: _UserService_SyncUser_Handler, }, + { + MethodName: "UserMenuCheck", + Handler: _UserService_UserMenuCheck_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "user.proto", diff --git a/router/base.go b/router/base.go index 6b05fa6..32c786d 100644 --- a/router/base.go +++ b/router/base.go @@ -1,18 +1,18 @@ package router -import ( - "aps_crm/api/v1" - "github.com/gin-gonic/gin" -) - -type BaseRouter struct{} - -func (s *BaseRouter) InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) { - baseRouter := Router.Group("base") - baseApi := v1.ApiGroup.BaseApi - { - baseRouter.POST("login", baseApi.Login) // 鐢ㄦ埛鐧诲綍 - baseRouter.POST("captcha", baseApi.Captcha) // 鑾峰彇楠岃瘉鐮� - } - return baseRouter -} +//import ( +// "aps_crm/api/v1" +// "github.com/gin-gonic/gin" +//) +// +//type BaseRouter struct{} +// +//func (s *BaseRouter) InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) { +// baseRouter := Router.Group("base") +// baseApi := v1.ApiGroup.BaseApi +// { +// baseRouter.POST("login", baseApi.Login) // 鐢ㄦ埛鐧诲綍 +// baseRouter.POST("captcha", baseApi.Captcha) // 鑾峰彇楠岃瘉鐮� +// } +// return baseRouter +//} diff --git a/router/image.go b/router/image.go index af08f81..41b64c1 100644 --- a/router/image.go +++ b/router/image.go @@ -1,17 +1,18 @@ package router -import ( - "aps_crm/api/v1" - "github.com/gin-gonic/gin" -) - -type ImageRouter struct{} - -func (s *BaseRouter) InitImageRouter(Router *gin.RouterGroup) (R gin.IRoutes) { - imageRouter := Router.Group("image") - imageApi := v1.ApiGroup.ImageApi - { - imageRouter.POST("upload", imageApi.Upload) // 涓婁紶鍥惧儚 - } - return imageRouter -} +// +//import ( +// "aps_crm/api/v1" +// "github.com/gin-gonic/gin" +//) +// +//type ImageRouter struct{} +// +//func (s *BaseRouter) InitImageRouter(Router *gin.RouterGroup) (R gin.IRoutes) { +// imageRouter := Router.Group("image") +// imageApi := v1.ApiGroup.ImageApi +// { +// imageRouter.POST("upload", imageApi.Upload) // 涓婁紶鍥惧儚 +// } +// return imageRouter +//} diff --git a/router/index.go b/router/index.go index 2cbe48e..c9d55be 100644 --- a/router/index.go +++ b/router/index.go @@ -5,6 +5,7 @@ "aps_crm/conf" _ "aps_crm/docs" "aps_crm/middleware" + "fmt" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" @@ -27,8 +28,8 @@ IsVisitRouter SolveRateRouter TimelyRateRouter - BaseRouter - UserRouter + //BaseRouter + //UserRouter JwtRouter CountryRouter ProvinceRouter @@ -87,6 +88,14 @@ Router.Use(cors.Default()) Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + //鑾峰彇鎵�鏈夎矾鐢� //todo + Router.GET("getRouters", func(c *gin.Context) { + routers := Router.Routes() + for _, v := range routers { + fmt.Printf("\"%v\" : 1,\n", v.Path) + } + }) + routerGroup := new(Group) PublicGroup := Router.Group("api") @@ -96,18 +105,18 @@ c.JSON(http.StatusOK, "ok") }) } - { - routerGroup.InitBaseRouter(PublicGroup) // 娉ㄥ唽鍩虹鍔熻兘璺敱 涓嶅仛閴存潈 - routerGroup.InitImageRouter(PublicGroup) // 鍥惧儚鍔熻兘璺敱 - } + //{ + // routerGroup.InitBaseRouter(PublicGroup) // 娉ㄥ唽鍩虹鍔熻兘璺敱 涓嶅仛閴存潈 + // routerGroup.InitImageRouter(PublicGroup) // 鍥惧儚鍔熻兘璺敱 + //} PrivateGroup := Router.Group("api") //PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) PrivateGroup.Use(middleware.JWTAuth2()) //PrivateGroup.Use(middleware.CasbinHandler()) { - routerGroup.InitJwtRouter(PrivateGroup) // jwt鐩稿叧璺敱 - routerGroup.InitUserRouter(PrivateGroup) // 娉ㄥ唽鐢ㄦ埛璺敱 + routerGroup.InitJwtRouter(PrivateGroup) // jwt鐩稿叧璺敱 + //routerGroup.InitUserRouter(PrivateGroup) // 娉ㄥ唽鐢ㄦ埛璺敱 routerGroup.InitCountryRouter(PrivateGroup) // 娉ㄥ唽country璺敱 routerGroup.InitProvinceRouter(PrivateGroup) // 娉ㄥ唽province璺敱 routerGroup.InitCityRouter(PrivateGroup) // 娉ㄥ唽city璺敱 diff --git a/router/user.go b/router/user.go index 5e624ea..9bc3f81 100644 --- a/router/user.go +++ b/router/user.go @@ -1,26 +1,26 @@ package router -import ( - "aps_crm/api/v1" - "github.com/gin-gonic/gin" -) - -type UserRouter struct{} - -func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) { - userRouter := Router.Group("user") - userRouterWithoutRecord := Router.Group("user") - baseApi := v1.ApiGroup.BaseApi - { - userRouter.POST("register", baseApi.Register) // 娉ㄥ唽璐﹀彿 - //userRouter.POST("changePassword", baseApi.ChangePassword) // 鐢ㄦ埛淇敼瀵嗙爜 - //userRouter.POST("resetPassword", baseApi.ResetPassword) // 閲嶇疆鐢ㄦ埛瀵嗙爜 - userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 鍒犻櫎鐢ㄦ埛 - userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 璁剧疆鐢ㄦ埛淇℃伅 - //userRouter.PUT("setSelfInfo", baseApi.SetSelfInfo) // 璁剧疆鑷韩淇℃伅 - } - { - userRouterWithoutRecord.POST("getUserList", baseApi.GetUserList) // 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�) - userRouterWithoutRecord.GET("getUserInfo", baseApi.GetUserInfo) // 鑾峰彇鑷韩淇℃伅 - } -} +//import ( +// "aps_crm/api/v1" +// "github.com/gin-gonic/gin" +//) +// +//type UserRouter struct{} +// +//func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) { +// userRouter := Router.Group("user") +// userRouterWithoutRecord := Router.Group("user") +// baseApi := v1.ApiGroup.BaseApi +// { +// userRouter.POST("register", baseApi.Register) // 娉ㄥ唽璐﹀彿 +// //userRouter.POST("changePassword", baseApi.ChangePassword) // 鐢ㄦ埛淇敼瀵嗙爜 +// //userRouter.POST("resetPassword", baseApi.ResetPassword) // 閲嶇疆鐢ㄦ埛瀵嗙爜 +// userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 鍒犻櫎鐢ㄦ埛 +// userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 璁剧疆鐢ㄦ埛淇℃伅 +// //userRouter.PUT("setSelfInfo", baseApi.SetSelfInfo) // 璁剧疆鑷韩淇℃伅 +// } +// { +// userRouterWithoutRecord.POST("getUserList", baseApi.GetUserList) // 鍒嗛〉鑾峰彇鐢ㄦ埛鍒楄〃(涓嶄紶鍒嗛〉鍙傛暟锛岃幏鍙栧叏閮�) +// userRouterWithoutRecord.GET("getUserInfo", baseApi.GetUserInfo) // 鑾峰彇鑷韩淇℃伅 +// } +//} diff --git a/service/lru.go b/service/lru.go new file mode 100644 index 0000000..b212997 --- /dev/null +++ b/service/lru.go @@ -0,0 +1,40 @@ +package service + +import ( + "github.com/hashicorp/golang-lru/v2/expirable" + "time" +) + +type userBaseInfo struct { + UserId int + NickName string +} + +var userCache *expirable.LRU[string, *userBaseInfo] + +func init() { + //make cache with 5 minutes TTL and 100 max keys + userCache = expirable.NewLRU[string, *userBaseInfo](100, nil, time.Minute*5) +} + +func GetUserBaseCache(adminUserId string) *userBaseInfo { + userCache, ok := userCache.Get(adminUserId) + if !ok { + userService := UserService{} + userRecord, err := userService.GetUserInfo(adminUserId) + if err != nil { + return nil + } + baseInfo := &userBaseInfo{ + UserId: userRecord.ID, + NickName: userRecord.NickName, + } + SetUserBaseCache(adminUserId, baseInfo) + return baseInfo + } + return userCache +} + +func SetUserBaseCache(adminUserId string, user *userBaseInfo) { + _ = userCache.Add(adminUserId, user) +} diff --git a/service/salesDetails.go b/service/salesDetails.go index 1e15798..c529a75 100644 --- a/service/salesDetails.go +++ b/service/salesDetails.go @@ -114,12 +114,13 @@ return ecode.OK } -func (SalesDetailsService) GetSalesDetailsList(page, pageSize int, keywordType constvar.SalesDetailsKeywordType, keyword string, saleChanceId int) ([]*model.SalesDetails, int64, int) { +func (SalesDetailsService) GetSalesDetailsList(page, pageSize int, keywordType constvar.SalesDetailsKeywordType, keyword string, saleChanceId int, memberIds []int) ([]*model.SalesDetails, int64, int) { // get contact list contacts, total, err := model.NewSalesDetailsSearch(). SetPreload(true). SetKeywordType(keywordType). SetSaleChanceId(saleChanceId). + SetMemberIds(memberIds). SetKeyword(keyword).SetPage(page, pageSize).FindAll() if err != nil { return nil, 0, ecode.SalesDetailsListErr diff --git a/service/salesRefund.go b/service/salesRefund.go index 2632314..c9897a1 100644 --- a/service/salesRefund.go +++ b/service/salesRefund.go @@ -168,13 +168,14 @@ return ecode.OK } -func (SalesRefundService) GetSalesRefundList(page, pageSize int, keywordType constvar.SalesRefundKeywordType, keyword string, sourceId int) ([]*model.SalesRefund, int64, int) { +func (SalesRefundService) GetSalesRefundList(page, pageSize int, keywordType constvar.SalesRefundKeywordType, keyword string, sourceId int, memberIds []int) ([]*model.SalesRefund, int64, int) { // get contact list contacts, total, err := model.NewSalesRefundSearch(). SetKeywordType(keywordType). SetKeyword(keyword). SetSourceId(sourceId). SetPreload(true). + SetMemberIds(memberIds). SetPage(page, pageSize).FindAll() if err != nil { return nil, 0, ecode.SalesRefundListErr diff --git a/service/salesReturn.go b/service/salesReturn.go index 4363b78..41b94fe 100644 --- a/service/salesReturn.go +++ b/service/salesReturn.go @@ -124,7 +124,7 @@ return ecode.OK } -func (SalesReturnService) GetSalesReturnList(params request.GetSalesReturnList) ([]*model.SalesReturn, int64, int) { +func (SalesReturnService) GetSalesReturnList(params request.GetSalesReturnList, memberIds []int)) ([]*model.SalesReturn, int64, int) { // get contact list contacts, total, err := model.NewSalesReturnSearch(). SetKeywordType(params.KeywordType). @@ -133,6 +133,7 @@ SetSourceId(params.SourceId). SetSourceType(params.SourceType). SetPreload(true). + SetMemberIds(memberIds). FindAll() if err != nil { return nil, 0, ecode.SalesReturnListErr diff --git a/service/serviceContract.go b/service/serviceContract.go index 1ef53c8..c4fed1c 100644 --- a/service/serviceContract.go +++ b/service/serviceContract.go @@ -117,7 +117,7 @@ return ecode.OK } -func (SContractService) GetServiceContractList(params request.GetServiceContractList) ([]*model.ServiceContract, int64, int) { +func (SContractService) GetServiceContractList(params request.GetServiceContractList, memberIds []int) ([]*model.ServiceContract, int64, int) { // get contact list contacts, total, err := model.NewServiceContractSearch(). SetKeyword(params.Keyword). @@ -128,6 +128,7 @@ SetQuotationId(params.QuotationId). SetSaleChanceId(params.SaleChanceId). SetContactId(params.ContactId). + SetMemberIds(memberIds). SetPreload(true). Find() if err != nil { diff --git a/service/serviceFollowup.go b/service/serviceFollowup.go index 46c52c9..fede335 100644 --- a/service/serviceFollowup.go +++ b/service/serviceFollowup.go @@ -41,7 +41,7 @@ return ecode.OK } -func (FollowupService) GetServiceFollowupList(page, pageSize int, keywordType constvar.ServiceFollowupKeywordType, keyword string, serviceOrderId int) ([]*model.ServiceFollowup, int64, int) { +func (FollowupService) GetServiceFollowupList(page, pageSize int, keywordType constvar.ServiceFollowupKeywordType, keyword string, serviceOrderId int, memberIds []int) ([]*model.ServiceFollowup, int64, int) { // get contact list contacts, total, err := model.NewServiceFollowupSearch(). SetKeywordType(keywordType). @@ -49,6 +49,7 @@ SetPage(page, pageSize). SetPreload(true). SetServiceOrderId(serviceOrderId). + SetMemberIds(memberIds). FindAll() if err != nil { return nil, 0, ecode.ServiceFollowupListErr diff --git a/service/serviceOrder.go b/service/serviceOrder.go index 97c6df1..6598ad0 100644 --- a/service/serviceOrder.go +++ b/service/serviceOrder.go @@ -38,7 +38,7 @@ return ecode.OK } -func (ServiceOrderService) GetServiceOrderList(page, pageSize int, queryClass constvar.ServiceOrderQueryClass, keywordType constvar.ServiceOrderKeywordType, keyword string, serviceContractId, salesDetailsId int) ([]*model.ServiceOrder, int64, int) { +func (ServiceOrderService) GetServiceOrderList(page, pageSize int, queryClass constvar.ServiceOrderQueryClass, keywordType constvar.ServiceOrderKeywordType, keyword string, serviceContractId, salesDetailsId int, memberIds []int) ([]*model.ServiceOrder, int64, int) { list, total, err := model.NewServiceOrderSearch(). SetPage(page, pageSize). SetKeyword(keyword). @@ -47,6 +47,7 @@ SetPreload(true). SetServiceContractId(serviceContractId). SetSalesDetailsId(salesDetailsId). + SetMemberIds(memberIds). Find() if err != nil { return nil, 0, ecode.DBErr diff --git a/service/user.go b/service/user.go index c5a1c8e..3f40330 100644 --- a/service/user.go +++ b/service/user.go @@ -1,20 +1,12 @@ package service import ( - "aps_crm/conf" "aps_crm/constvar" "aps_crm/model" "aps_crm/pkg/ecode" "aps_crm/pkg/encrypt" - "aps_crm/pkg/logx" - "aps_crm/proto/user" - "context" "errors" - "fmt" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" "gorm.io/gorm" - "time" ) type UserService struct{} @@ -100,51 +92,4 @@ func (userService *UserService) GetUserList() (userList []*model.User, err error) { return model.NewUserSearch(nil).FindAll() -} - -var ( - userConn *grpc.ClientConn -) - -func InitUserConn() { - var err error - userConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Admin, grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - logx.Errorf("grpc dial user service error: %v", err.Error()) - return - } -} - -func CloseUserConn() { - if userConn != nil { - userConn.Close() - } -} - -func SyncUserInfo() { - cli := user.NewUserServiceClient(userConn) - - var users []*user.User - - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - r, err := cli.SyncUser(ctx, &user.UserRequest{Users: users}) - if err != nil { - logx.Fatalf("could not sync users: %v", err) - } - - fmt.Printf("Synced: %v, Message: %s", r.List, r.Message) - - for _, member := range r.List { - err = model.NewUserSearch(nil).FirstOrCreate(model.User{ - UUID: member.Uuid, - Username: member.Username, - UserType: constvar.UserType(member.Usertype), - NickName: member.Nickname, - }) - if err != nil { - logx.Errorf("sync user error: %v", err.Error()) - continue - } - } } diff --git a/utils/clamis.go b/utils/clamis.go index 1e10801..305d0ce 100644 --- a/utils/clamis.go +++ b/utils/clamis.go @@ -22,30 +22,18 @@ return claims, err } -// GetUserID 浠嶨in鐨凜ontext涓幏鍙栦粠jwt瑙f瀽鍑烘潵鐨勭敤鎴稩D -func GetUserID(c *gin.Context) string { - if claims, exists := c.Get("claims"); !exists { - if cl, err := GetClaims(c); err != nil { - return "" - } else { - return cl.UserId - } - } else { +func GetUserID(c *gin.Context) int { + if claims, exists := c.Get("claims"); exists { waitUse := claims.(*request.CustomClaims) - return waitUse.UserId + return waitUse.CrmUserId } + return 0 } -// GetUserInfo 浠嶨in鐨凜ontext涓幏鍙栦粠jwt瑙f瀽鍑烘潵鐨勭敤鎴蜂俊鎭� func GetUserInfo(c *gin.Context) *request.CustomClaims { - if claims, exists := c.Get("claims"); !exists { - if cl, err := GetClaims(c); err != nil { - return nil - } else { - return cl - } - } else { + if claims, exists := c.Get("claims"); exists { waitUse := claims.(*request.CustomClaims) return waitUse } + return nil } -- Gitblit v1.8.0