作者 陈志颖

feat:共创申请增加游客处理

@@ -101,18 +101,31 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -101,18 +101,31 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
101 101
102 var newCooperationApplication *domain.CooperationApplication 102 var newCooperationApplication *domain.CooperationApplication
103 103
104 - if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 { // 游客操作  
105 - // TODO 获取申请人信息 104 + if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 && applyForCooperationCommand.UserBaseId != 0 { // 游客操作
  105 + // 获取申请人信息
  106 + var applicant *domain.User
  107 + if data, err := userService.VisitorFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserBaseId); err != nil {
  108 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
  109 + } else {
  110 + applicant = data
  111 + }
106 112
107 - // TODO 校验:同一个用户,不能多次申请同一个项目 113 + // 校验:同一个用户,不能多次申请同一个项目
  114 + applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
  115 + "visitorUserBaseId": applicant.UserBaseId,
  116 + "cooperationApplicationId": cooperationProject.CooperationProjectId,
  117 + })
  118 + if applicationExist {
  119 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "抱歉,您已经申请过该项目")
  120 + }
108 121
109 - // TODO 校验:判断用户类型是否属于承接对象  
110 - //if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {  
111 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")  
112 - //} 122 + // 校验:判断用户类型是否属于承接对象
  123 + if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
  124 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
  125 + }
113 126
114 newCooperationApplication = &domain.CooperationApplication{ 127 newCooperationApplication = &domain.CooperationApplication{
115 - CooperationApplicationApplicant: nil, // TODO 获取游客(申请人)信息 128 + CooperationApplicationApplicant: applicant,
116 CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment, 129 CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
117 CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription, 130 CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
118 CooperationApplicationStatus: 1, 131 CooperationApplicationStatus: 1,
@@ -157,6 +170,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -157,6 +170,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
157 applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{ 170 applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
158 "companyId": applyForCooperationCommand.CompanyId, 171 "companyId": applyForCooperationCommand.CompanyId,
159 "orgId": applyForCooperationCommand.OrgId, 172 "orgId": applyForCooperationCommand.OrgId,
  173 + "applicantId": applicant.UserId,
160 "cooperationApplicationId": cooperationProject.CooperationProjectId, 174 "cooperationApplicationId": cooperationProject.CooperationProjectId,
161 }) 175 })
162 if applicationExist { 176 if applicationExist {
@@ -30,7 +30,6 @@ type PayCreditAccountCommand struct { @@ -30,7 +30,6 @@ type PayCreditAccountCommand struct {
30 } 30 }
31 31
32 func (payCreditAccountCommand *PayCreditAccountCommand) Valid(validation *validation.Validation) { 32 func (payCreditAccountCommand *PayCreditAccountCommand) Valid(validation *validation.Validation) {
33 - //validation.SetError("CustomValid", "未实现的自定义认证")  
34 } 33 }
35 34
36 func (payCreditAccountCommand *PayCreditAccountCommand) ValidateCommand() error { 35 func (payCreditAccountCommand *PayCreditAccountCommand) ValidateCommand() error {
@@ -9,4 +9,5 @@ type UserService interface { @@ -9,4 +9,5 @@ type UserService interface {
9 RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) // 获取相关人 9 RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) // 获取相关人
10 SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) // 获取业务员 10 SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) // 获取业务员
11 OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) // 获取操作人 11 OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) // 获取操作人
  12 + VisitorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) // 获取游客
12 } 13 }
@@ -27,6 +27,9 @@ func (dao *CooperationApplicationDao) CheckApplicationExist(queryOptions map[str @@ -27,6 +27,9 @@ func (dao *CooperationApplicationDao) CheckApplicationExist(queryOptions map[str
27 if applicantId, ok := queryOptions["applicantId"]; ok && applicantId.(int64) != 0 { 27 if applicantId, ok := queryOptions["applicantId"]; ok && applicantId.(int64) != 0 {
28 query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userId":"?"}'`, applicantId) 28 query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userId":"?"}'`, applicantId)
29 } 29 }
  30 + if visitorUserBaseId, ok := queryOptions["visitorUserBaseId"]; ok && visitorUserBaseId.(int64) != 0 {
  31 + query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, visitorUserBaseId)
  32 + }
30 if applicantBaseId, ok := queryOptions["applicantBaseId"]; ok && applicantBaseId.(int64) != 0 { 33 if applicantBaseId, ok := queryOptions["applicantBaseId"]; ok && applicantBaseId.(int64) != 0 {
31 query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, applicantBaseId) 34 query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, applicantBaseId)
32 } 35 }
@@ -172,6 +172,33 @@ func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId in @@ -172,6 +172,33 @@ func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId in
172 } 172 }
173 } 173 }
174 174
  175 +// VisitorFrom 获取游客
  176 +func (service *UserService) VisitorFrom(companyId int64, orgId int64, userBaseId int64) (*domain.User, error) {
  177 + var returnData *domain.User
  178 + if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
  179 + return nil, err
  180 + } else {
  181 + if visitor, err := userAdaptor.ToParticipator(companyId, orgId, userBaseId, "Visitor"); err != nil {
  182 + return nil, err
  183 + } else {
  184 + if visitor != nil {
  185 + log.Logger.Debug("游客", map[string]interface{}{
  186 + "visitor interface": visitor,
  187 + })
  188 + visitorJson, err1 := json.Marshal(visitor)
  189 + if err1 != nil {
  190 + return nil, err
  191 + }
  192 + err2 := json.Unmarshal(visitorJson, &returnData)
  193 + if err2 != nil {
  194 + return nil, err2
  195 + }
  196 + }
  197 + return returnData, nil
  198 + }
  199 + }
  200 +}
  201 +
175 func NewUserService() (*UserService, error) { 202 func NewUserService() (*UserService, error) {
176 return &UserService{}, nil 203 return &UserService{}, nil
177 } 204 }
@@ -54,6 +54,12 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId @@ -54,6 +54,12 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId
54 return map[string]interface{}{}, nil 54 return map[string]interface{}{}, nil
55 } 55 }
56 return user, nil 56 return user, nil
  57 + case "Visitor": // 游客
  58 + visitor, err := userTranslator.ToVisitorFromRepresentation(response)
  59 + if err != nil {
  60 + return map[string]interface{}{}, nil
  61 + }
  62 + return visitor, nil
57 } 63 }
58 } 64 }
59 return map[string]interface{}{}, nil 65 return map[string]interface{}{}, nil
@@ -42,6 +42,33 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId @@ -42,6 +42,33 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId
42 return &data, err 42 return &data, err
43 } 43 }
44 44
  45 +// GetUserInfo 获取用户信息
  46 +func (serviceGateway *HttplibUserServiceGateway) GetUserInfo(companyId int64, orgId int64, userBaseId int64) (*translator.UserDetail, error) {
  47 + url := serviceGateway.baseURL + "/auth/user-info"
  48 + request := serviceGateway.createRequest(url, "post")
  49 + options := make(map[string]interface{})
  50 + options["userBaseId"] = userBaseId
  51 + _, err1 := request.JSONBody(options)
  52 + if err1 != nil {
  53 + return nil, err1
  54 + }
  55 + byteResult, err := request.Bytes()
  56 + if err != nil {
  57 + return nil, fmt.Errorf("获取获取用户信息失败:%w", err)
  58 + }
  59 + log.Logger.Debug("获取用户模块请求数据:获取用户信息。", map[string]interface{}{
  60 + "result": string(byteResult),
  61 + })
  62 + var result GatewayResponse
  63 + err = json.Unmarshal(byteResult, &result)
  64 + if err != nil {
  65 + return nil, fmt.Errorf("解析获取用户:%w", err)
  66 + }
  67 + var data translator.UserDetail
  68 + err = serviceGateway.getResponseData(result, &data)
  69 + return &data, err
  70 +}
  71 +
45 // GetUsers 获取用户 72 // GetUsers 获取用户
46 func (serviceGateway *HttplibUserServiceGateway) GetUsers(companyId int64, orgId int64, uids []int64) (map[string]interface{}, error) { 73 func (serviceGateway *HttplibUserServiceGateway) GetUsers(companyId int64, orgId int64, uids []int64) (map[string]interface{}, error) {
47 companyIdStr := strconv.FormatInt(companyId, 10) 74 companyIdStr := strconv.FormatInt(companyId, 10)
@@ -8,6 +8,20 @@ import ( @@ -8,6 +8,20 @@ import (
8 type UserTranslator struct { 8 type UserTranslator struct {
9 } 9 }
10 10
  11 +type UserInfoDetail struct {
  12 + UserBaseId int64 `json:"userBaseId"`
  13 + UserType int32 `json:"userType"`
  14 + UserInfo struct {
  15 + UserName string `json:"userName"`
  16 + Phone string `json:"phone"`
  17 + } `json:"userInfo,omitempty"`
  18 + Im struct {
  19 + Accid string `json:"accid"`
  20 + ImToken string `json:"imToken"`
  21 + CsAccountId string `json:"csAccountId"`
  22 + } `json:"im,omitempty"`
  23 +}
  24 +
11 type UserDetail struct { 25 type UserDetail struct {
12 UserId int64 `json:"userId"` 26 UserId int64 `json:"userId"`
13 UserBaseId int64 `json:"userBaseId"` 27 UserBaseId int64 `json:"userBaseId"`
@@ -348,7 +362,7 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d @@ -348,7 +362,7 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d
348 var roles []*domain.Role 362 var roles []*domain.Role
349 for _, role := range user.UserRole { 363 for _, role := range user.UserRole {
350 roles = append(roles, &domain.Role{ 364 roles = append(roles, &domain.Role{
351 - RoleId: int64(role.RoleID), 365 + RoleId: role.RoleID,
352 RoleName: role.RoleName, 366 RoleName: role.RoleName,
353 }) 367 })
354 } 368 }
@@ -386,6 +400,19 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d @@ -386,6 +400,19 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d
386 }, nil 400 }, nil
387 } 401 }
388 402
  403 +func (translator *UserTranslator) ToVisitorFromRepresentation(user *UserDetail) (*domain.User, error) {
  404 + return &domain.User{
  405 + UserBaseId: user.UserBaseId,
  406 + UserInfo: &domain.UserInfo{
  407 + UserName: user.UserInfo.UserName,
  408 + UserPhone: user.UserInfo.Phone,
  409 + },
  410 + UserType: user.UserType,
  411 + UserName: user.UserInfo.UserName,
  412 + UserPhone: user.UserInfo.Phone,
  413 + }, nil
  414 +}
  415 +
389 func NewUserTranslator() (*UserTranslator, error) { 416 func NewUserTranslator() (*UserTranslator, error) {
390 return &UserTranslator{}, nil 417 return &UserTranslator{}, nil
391 } 418 }