Merge branch 'master' of http://192.168.5.5:10010/r/aps/crm
# Conflicts:
# api/v1/contact.go
# api/v1/salesDetails.go
# model/quotation.go
# model/saleChance.go
# service/salesDetails.go
| | |
| | | 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 |
| | | } |
| | | // 字符,公式,验证码配置 |
| | | // 生成默认数字的driver |
| | | 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 |
| | | // } |
| | | // // 字符,公式,验证码配置 |
| | | // // 生成默认数字的driver |
| | | // 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, |
| | | // }) |
| | | //} |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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) |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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, params.ClientId) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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) |
| | |
| | | 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" |
| | |
| | | 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) |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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) |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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) |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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) |
| | |
| | | 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" |
| | | ) |
| | |
| | | return |
| | | } |
| | | |
| | | var memberIds []int |
| | | userInfo := utils.GetUserInfo(c) |
| | | if userInfo.UserType == constvar.UserTypeSub { |
| | | memberIds = []int{userInfo.CrmUserId} |
| | | } |
| | | |
| | | salesDetailss, total, errCode := salesDetailsService.GetSalesDetailsList(params) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/utils" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | |
| | | 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) |
| | |
| | | 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" |
| | |
| | | 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 |
| | |
| | | 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" |
| | |
| | | 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 |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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 |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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 |
| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/structx" |
| | | "aps_crm/service" |
| | | "aps_crm/utils" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | |
| | | 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 |
| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | 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) |
| | |
| | | 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" |
| | | ) |
| | | |
| | | // 当开启多服务器部署时,替换下面的配置,使用redis共享存储验证码 |
| | | // 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 |
| | | } |
| | | // 赋值菜单ID列表 |
| | | //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无JWT数据 |
| | | 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的JWT,旧的作废 |
| | | 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 |
| | | //// 当开启多服务器部署时,替换下面的配置,使用redis共享存储验证码 |
| | | //// 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 |
| | | // } |
| | | // // 赋值菜单ID列表 |
| | | // //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无JWT数据 |
| | | // 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的JWT,旧的作废 |
| | | // 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() |
| | | //} |
| | |
| | | }, |
| | | "GrpcServiceAddr": { |
| | | "Aps": "192.168.20.120:9091", |
| | | "Admin": "192.168.20.119:50051" |
| | | "Admin": "192.168.20.120:50051" |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | return true |
| | | } |
| | | |
| | | const ( |
| | | SystemType = 2 |
| | | ) |
| | |
| | | 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 |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | v1 "aps_crm/api/v1" |
| | | "aps_crm/conf" |
| | | "aps_crm/initialize" |
| | | "aps_crm/middleware" |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/logx" |
| | | "aps_crm/router" |
| | | "aps_crm/service" |
| | | "fmt" |
| | | "net/http" |
| | | "os" |
| | |
| | | } |
| | | |
| | | go v1.InitProductServiceConn() |
| | | go service.InitUserConn() |
| | | go middleware.InitUserConn() |
| | | go v1.InitCodeServiceConn() |
| | | |
| | | //c := cron.New() |
| | |
| | | <-quit |
| | | |
| | | v1.CloseProductServiceConn() |
| | | service.CloseUserConn() |
| | | v1.CloseCodeServiceConn() |
| | | middleware.CloseUserConn() |
| | | |
| | | logx.Infof("aps-crm exited...") |
| | | os.Exit(0) |
New file |
| | |
| | | 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 |
| | | } |
| | |
| | | |
| | | func JWTAuth2() gin.HandlerFunc { |
| | | return func(c *gin.Context) { |
| | | ctx := new(contextx.Context).SetCtx(c) |
| | | // 我们这里jwt鉴权取头部信息 Authorization 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localStorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录 |
| | | token := c.Request.Header.Get("Authorization") |
| | | if token == "" { |
| | | c.Next() |
| | | ctx.Fail(ecode.JWTEmpty) |
| | | c.Abort() |
| | | return |
| | | } |
| | | slices := strings.Split(token, " ") |
| | |
| | | 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 |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | 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 |
| | | } |
| | | } |
| | | } |
| | |
| | | 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) |
| | | } |
| | |
| | | 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) |
| | | } |
| | |
| | | db = db.Where(key+"= ?", v) |
| | | } |
| | | case int: |
| | | if key == "member_id" { |
| | | db = db.Where(key+"= ?", v) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | 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) |
| | | } |
| | | } |
| | |
| | | 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) |
| | | } |
| | |
| | | } |
| | | |
| | | case float64: |
| | | if key == "client_id" || key == "sale_chance_id" { |
| | | if key == "client_id" || key == "sale_chance_id" || key == "member_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | } |
| | |
| | | BaseClaims |
| | | BufferTime int64 |
| | | jwt.StandardClaims |
| | | CrmUserId int |
| | | NickName string |
| | | } |
| | | |
| | | type BaseClaims struct { |
| | |
| | | db = db.Where("expected_time LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | case int: |
| | | case float64: |
| | | case int, float64: |
| | | if key == "member_id" || key == "budget" || key == "projected_amount" || key == "client_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | |
| | | PageNum int |
| | | PageSize int |
| | | Preload bool |
| | | MemberIds []int |
| | | } |
| | | ) |
| | | |
| | |
| | | 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"). |
| | |
| | | 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 |
| | |
| | | PageSize int |
| | | Preload bool |
| | | Ids []int |
| | | MemberIds []int |
| | | } |
| | | ) |
| | | |
| | |
| | | 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 |
| | |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
| | | |
| | | |
| | | func (slf *SalesRefundSearch) SetMemberIds(memberIds []int) *SalesRefundSearch { |
| | | slf.MemberIds = memberIds |
| | | return slf |
| | | } |
| | |
| | | PageSize int |
| | | Preload bool |
| | | Ids []int |
| | | MemberIds []int |
| | | } |
| | | ) |
| | | |
| | |
| | | db = db.Where("amount_has_refund = ?", slf.Keyword) |
| | | |
| | | } |
| | | } |
| | | |
| | | if len(slf.MemberIds) > 0 { |
| | | db = db.Where("member_id in ?", slf.MemberIds) |
| | | } |
| | | |
| | | return db |
| | |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) SetMemberIds(memberIds []int) *SalesReturnSearch { |
| | | slf.MemberIds = memberIds |
| | | return slf |
| | | } |
| | |
| | | PageNum int |
| | | PageSize int |
| | | Preload bool |
| | | MemberIds []int |
| | | } |
| | | ) |
| | | |
| | |
| | | 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"). |
| | |
| | | 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 |
| | |
| | | PageNum int |
| | | PageSize int |
| | | Preload bool |
| | | MemberIds []int |
| | | } |
| | | ) |
| | | |
| | |
| | | Preload("SolveRate"). |
| | | Preload("IsVisit"). |
| | | Preload("OldMember") |
| | | } |
| | | |
| | | if len(slf.MemberIds) > 0 { |
| | | db = db.Where("member_id in ?", slf.MemberIds) |
| | | } |
| | | |
| | | return db |
| | |
| | | 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 |
| | |
| | | // 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 |
| | | } |
| | | ) |
| | | |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | if key == "client_id" || key == "master_order_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | if key == "member_id" { |
| | | db = db.Where("member_id = ?", v) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | 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 != "" { |
| | |
| | | |
| | | service UserService { |
| | | rpc SyncUser(UserRequest) returns (UserResponse); |
| | | rpc UserMenuCheck(CheckRequest) returns (CheckResponse); |
| | | } |
| | | |
| | | message User { |
| | |
| | | string username = 2; |
| | | int32 usertype = 3; |
| | | string nickname = 4; |
| | | |
| | | // ... other fields |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | // 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 |
| | |
| | | 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() { |
| | |
| | | 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{ |
| | |
| | | 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 ( |
| | |
| | | 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 |
| | |
| | | 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{ |
| | |
| | | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), |
| | | RawDescriptor: file_user_proto_rawDesc, |
| | | NumEnums: 0, |
| | | NumMessages: 3, |
| | | NumMessages: 5, |
| | | NumExtensions: 0, |
| | | NumServices: 1, |
| | | }, |
| | |
| | | // 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 |
| | | |
| | |
| | | // 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 { |
| | |
| | | |
| | | 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 |
| | | } |
| | |
| | | // for forward compatibility |
| | | type UserServiceServer interface { |
| | | SyncUser(context.Context, *UserRequest) (*UserResponse, error) |
| | | UserMenuCheck(context.Context, *CheckRequest) (*CheckResponse, error) |
| | | mustEmbedUnimplementedUserServiceServer() |
| | | } |
| | | |
| | |
| | | |
| | | 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() {} |
| | | |
| | |
| | | } |
| | | 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) |
| | | } |
| | |
| | | MethodName: "SyncUser", |
| | | Handler: _UserService_SyncUser_Handler, |
| | | }, |
| | | { |
| | | MethodName: "UserMenuCheck", |
| | | Handler: _UserService_UserMenuCheck_Handler, |
| | | }, |
| | | }, |
| | | Streams: []grpc.StreamDesc{}, |
| | | Metadata: "user.proto", |
| | |
| | | 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 |
| | | //} |
| | |
| | | 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 |
| | | //} |
| | |
| | | "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" |
| | |
| | | IsVisitRouter |
| | | SolveRateRouter |
| | | TimelyRateRouter |
| | | BaseRouter |
| | | UserRouter |
| | | //BaseRouter |
| | | //UserRouter |
| | | JwtRouter |
| | | CountryRouter |
| | | ProvinceRouter |
| | |
| | | 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") |
| | | |
| | |
| | | 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路由 |
| | |
| | | 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) // 获取自身信息 |
| | | // } |
| | | //} |
New file |
| | |
| | | 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) |
| | | } |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SalesDetailsService) GetSalesDetailsList(params request.GetSalesDetailsList) ([]*model.SalesDetails, int64, int) { |
| | | func (SalesDetailsService) GetSalesDetailsList(params request.GetSalesDetailsList, memberIds []int) ([]*model.SalesDetails, int64, int) { |
| | | // get contact list |
| | | contacts, total, err := model.NewSalesDetailsSearch(). |
| | | SetPreload(true). |
| | | SetMemberIds(memberIds). |
| | | SetKeywordType(params.KeywordType). |
| | | SetSaleChanceId(params.SaleChanceId). |
| | | SetClientId(params.ClientId). |
| | |
| | | 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 |
| | |
| | | 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). |
| | |
| | | SetSourceType(params.SourceType). |
| | | SetClientId(params.ClientId). |
| | | SetPreload(true). |
| | | SetMemberIds(memberIds). |
| | | FindAll() |
| | | if err != nil { |
| | | return nil, 0, ecode.SalesReturnListErr |
| | |
| | | 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). |
| | |
| | | SetQuotationId(params.QuotationId). |
| | | SetSaleChanceId(params.SaleChanceId). |
| | | SetContactId(params.ContactId). |
| | | SetMemberIds(memberIds). |
| | | SetPreload(true). |
| | | Find() |
| | | if err != nil { |
| | |
| | | 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). |
| | |
| | | SetPage(page, pageSize). |
| | | SetPreload(true). |
| | | SetServiceOrderId(serviceOrderId). |
| | | SetMemberIds(memberIds). |
| | | FindAll() |
| | | if err != nil { |
| | | return nil, 0, ecode.ServiceFollowupListErr |
| | |
| | | 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). |
| | |
| | | SetPreload(true). |
| | | SetServiceContractId(serviceContractId). |
| | | SetSalesDetailsId(salesDetailsId). |
| | | SetMemberIds(memberIds). |
| | | Find() |
| | | if err != nil { |
| | | return nil, 0, ecode.DBErr |
| | |
| | | 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{} |
| | |
| | | |
| | | 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 |
| | | } |
| | | } |
| | | } |
| | |
| | | return claims, err |
| | | } |
| | | |
| | | // GetUserID 从Gin的Context中获取从jwt解析出来的用户ID |
| | | 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 从Gin的Context中获取从jwt解析出来的用户信息 |
| | | 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 |
| | | } |