作者 陈志颖

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

... ... @@ -101,18 +101,31 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
var newCooperationApplication *domain.CooperationApplication
if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 { // 游客操作
// TODO 获取申请人信息
if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 && applyForCooperationCommand.UserBaseId != 0 { // 游客操作
// 获取申请人信息
var applicant *domain.User
if data, err := userService.VisitorFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserBaseId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
} else {
applicant = data
}
// TODO 校验:同一个用户,不能多次申请同一个项目
// 校验:同一个用户,不能多次申请同一个项目
applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
"visitorUserBaseId": applicant.UserBaseId,
"cooperationApplicationId": cooperationProject.CooperationProjectId,
})
if applicationExist {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "抱歉,您已经申请过该项目")
}
// TODO 校验:判断用户类型是否属于承接对象
//if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
//}
// 校验:判断用户类型是否属于承接对象
if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
}
newCooperationApplication = &domain.CooperationApplication{
CooperationApplicationApplicant: nil, // TODO 获取游客(申请人)信息
CooperationApplicationApplicant: applicant,
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
CooperationApplicationStatus: 1,
... ... @@ -157,6 +170,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
"companyId": applyForCooperationCommand.CompanyId,
"orgId": applyForCooperationCommand.OrgId,
"applicantId": applicant.UserId,
"cooperationApplicationId": cooperationProject.CooperationProjectId,
})
if applicationExist {
... ...
... ... @@ -30,7 +30,6 @@ type PayCreditAccountCommand struct {
}
func (payCreditAccountCommand *PayCreditAccountCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (payCreditAccountCommand *PayCreditAccountCommand) ValidateCommand() error {
... ...
... ... @@ -9,4 +9,5 @@ type UserService interface {
RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) // 获取相关人
SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) // 获取业务员
OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) // 获取操作人
VisitorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) // 获取游客
}
... ...
... ... @@ -27,6 +27,9 @@ func (dao *CooperationApplicationDao) CheckApplicationExist(queryOptions map[str
if applicantId, ok := queryOptions["applicantId"]; ok && applicantId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userId":"?"}'`, applicantId)
}
if visitorUserBaseId, ok := queryOptions["visitorUserBaseId"]; ok && visitorUserBaseId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, visitorUserBaseId)
}
if applicantBaseId, ok := queryOptions["applicantBaseId"]; ok && applicantBaseId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, applicantBaseId)
}
... ...
... ... @@ -172,6 +172,33 @@ func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId in
}
}
// VisitorFrom 获取游客
func (service *UserService) VisitorFrom(companyId int64, orgId int64, userBaseId int64) (*domain.User, error) {
var returnData *domain.User
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if visitor, err := userAdaptor.ToParticipator(companyId, orgId, userBaseId, "Visitor"); err != nil {
return nil, err
} else {
if visitor != nil {
log.Logger.Debug("游客", map[string]interface{}{
"visitor interface": visitor,
})
visitorJson, err1 := json.Marshal(visitor)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(visitorJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
func NewUserService() (*UserService, error) {
return &UserService{}, nil
}
... ...
... ... @@ -54,6 +54,12 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId
return map[string]interface{}{}, nil
}
return user, nil
case "Visitor": // 游客
visitor, err := userTranslator.ToVisitorFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return visitor, nil
}
}
return map[string]interface{}{}, nil
... ...
... ... @@ -42,6 +42,33 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId
return &data, err
}
// GetUserInfo 获取用户信息
func (serviceGateway *HttplibUserServiceGateway) GetUserInfo(companyId int64, orgId int64, userBaseId int64) (*translator.UserDetail, error) {
url := serviceGateway.baseURL + "/auth/user-info"
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["userBaseId"] = userBaseId
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("获取获取用户信息失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:获取用户信息。", map[string]interface{}{
"result": string(byteResult),
})
var result GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析获取用户:%w", err)
}
var data translator.UserDetail
err = serviceGateway.getResponseData(result, &data)
return &data, err
}
// GetUsers 获取用户
func (serviceGateway *HttplibUserServiceGateway) GetUsers(companyId int64, orgId int64, uids []int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
... ...
... ... @@ -8,6 +8,20 @@ import (
type UserTranslator struct {
}
type UserInfoDetail struct {
UserBaseId int64 `json:"userBaseId"`
UserType int32 `json:"userType"`
UserInfo struct {
UserName string `json:"userName"`
Phone string `json:"phone"`
} `json:"userInfo,omitempty"`
Im struct {
Accid string `json:"accid"`
ImToken string `json:"imToken"`
CsAccountId string `json:"csAccountId"`
} `json:"im,omitempty"`
}
type UserDetail struct {
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId"`
... ... @@ -348,7 +362,7 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d
var roles []*domain.Role
for _, role := range user.UserRole {
roles = append(roles, &domain.Role{
RoleId: int64(role.RoleID),
RoleId: role.RoleID,
RoleName: role.RoleName,
})
}
... ... @@ -386,6 +400,19 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d
}, nil
}
func (translator *UserTranslator) ToVisitorFromRepresentation(user *UserDetail) (*domain.User, error) {
return &domain.User{
UserBaseId: user.UserBaseId,
UserInfo: &domain.UserInfo{
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
},
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
}, nil
}
func NewUserTranslator() (*UserTranslator, error) {
return &UserTranslator{}, nil
}
... ...