作者 tangxuhui
... ... @@ -23,6 +23,13 @@ func (srv AuthService) AuthLogin(loginCommand *command.LoginCommand) (interface{
result interface{}
err error
)
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err = creationUserGateway.AuthRefreshIM(allied_creation_user.ReqAuthRefreshIM{
Phone: loginCommand.Phone,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "系统错误")
}
switch loginCommand.GrantType {
case "signInPassword":
result, err = srv.SignInPassword(loginCommand.Phone, loginCommand.Password)
... ... @@ -88,7 +95,7 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
if err := accessTokenCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
ltoken := domain.LoginToken{}
ltoken := &domain.LoginToken{}
err := ltoken.ParseToken(accessTokenCommand.AuthCode)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -96,7 +103,8 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
phone := ltoken.Account
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
userSeachResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
Phone: phone,
CompanyId: ltoken.CompanyId,
Phone: phone,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -133,11 +141,11 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
currentAccess.UpdatedTime = time.Now()
} else {
currentAccess = &domain.LoginAccess{
UserBaseId: int64(userSeachResult.Users[0].UserBaseId),
UserId: int64(userSeachResult.Users[0].UserId),
Account: userSeachResult.Users[0].UserInfo.Phone,
Platform: domain.LoginPlatformApp,
CompanyId: int64(userSeachResult.Users[0].Company.CompanyId),
UserBaseId: int64(userSeachResult.Users[0].UserBaseId),
UserId: int64(userSeachResult.Users[0].UserId),
Account: userSeachResult.Users[0].UserInfo.Phone,
Platform: domain.LoginPlatformApp,
//CompanyId: int64(userSeachResult.Users[0].Company.CompanyId),
OrganizationId: int64(userSeachResult.Users[0].Org.OrgId),
AccessToken: "",
RefreshToken: "",
... ... @@ -146,6 +154,9 @@ func (srv AuthService) GetAuthAccessToken(accessTokenCommand *command.AccessToke
CreatedTime: time.Now(),
UpdatedTime: time.Now(),
}
if userSeachResult.Users[0].Company != nil {
currentAccess.CompanyId = int64(userSeachResult.Users[0].Company.CompanyId)
}
}
//判定当前凭证的companyId,OrganizationId 是否在用户列表中
var currentOrgIsOK bool
... ... @@ -343,6 +354,8 @@ func (srv AuthService) GetUserInfo(userInfoCommand *command.UserInfoCommand) (in
"userName": resultUser.UserInfo.UserName,
"userPhone": resultUser.UserInfo.Phone,
"userAvatar": resultUser.UserInfo.Avatar,
//"userCode": resultUser.UserInfo.UserCode,
"email": resultUser.UserInfo.Email,
},
"department": resultUser.Department,
"company": map[string]interface{}{
... ...
... ... @@ -3,7 +3,9 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
"strconv"
)
// CooperationProjectService 共创项目服务
... ... @@ -11,18 +13,31 @@ type CooperationProjectService struct {
}
// CreateCooperationProject TODO:创建共创项目
func (srv CooperationProjectService) CreateCooperationProject(userMenusCommand *command.CreateCooperationProjectCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
userMenusCommand.Operator)
resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{
UserId: int(userMenusCommand.Operator.UserId),
func (srv CooperationProjectService) CreateCooperationProject(createCooperationProjectCommand *command.CreateCooperationProjectCommand) (interface{}, error) {
if err := createCooperationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(createCooperationProjectCommand.Operator)
result, err := creationCooperationGateway.CooperationProjectAdd(allied_creation_cooperation.ReqCooperationProjectAdd{
CooperationProjectDescription: createCooperationProjectCommand.CooperationProjectDescription,
CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
PublisherUid: strconv.Itoa(int(createCooperationProjectCommand.Operator.UserId)),
SponsorUid: createCooperationProjectCommand.CooperationProjectSponsor,
CooperationProjectUndertakerType: createCooperationProjectCommand.CooperationProjectUndertakerType,
Images: createCooperationProjectCommand.Images,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"accessMenus": resultMenu.Menus,
}, nil
data := struct {
CooperationProjectId int `json:"cooperationProjectId"`
command.CreateCooperationProjectCommand
}{
CooperationProjectId: result.CooperationProjectId,
CreateCooperationProjectCommand: *createCooperationProjectCommand,
}
return data, nil
}
// GetCooperationProject TODO:返回共创项目明细
... ...
... ... @@ -12,8 +12,8 @@ type Department struct {
Users []User `json:"users"`
}
type User struct {
UserID int `json:"userId"`
UserName string `json:"userName"`
UserID int `json:"userId"`
UserInfo map[string]interface{} `json:"userInfo"`
}
func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error {
... ... @@ -37,8 +37,10 @@ func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataO
}
if v, ok := mapDepartment[int64(user.Department.DepartmentId)]; ok {
v.Users = append(v.Users, User{
UserID: user.UserId,
UserName: user.UserInfo.UserName,
UserID: user.UserId,
UserInfo: map[string]interface{}{
"userName": user.UserInfo.UserName,
},
})
}
}
... ...
... ... @@ -25,9 +25,9 @@ type CompanyUserAddCommand struct {
// 邮箱
Email string `json:"email" valid:"Required"`
// 关联的组织机构
UsersOrg []string `json:"userOrg"`
// 关联的用户
UsersRole []string `json:"userRole"`
UserOrg []Org `json:"userOrg,omitempty"`
// 关联的组织结构
UserRole []Role `json:"userRole,omitempty"`
// 头像
Avatar string `json:"avatar" valid:"Required"`
}
... ...
... ... @@ -102,14 +102,14 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.
orgId, _ := strconv.Atoi(companyUserAddCommand.OrgId)
userOrg := []int64{}
userRole := []int64{}
for _, v := range companyUserAddCommand.UsersOrg {
id, err := strconv.Atoi(v)
for _, v := range companyUserAddCommand.UserOrg {
id, err := strconv.Atoi(v.OrgId)
if err == nil {
userOrg = append(userOrg, int64(id))
}
}
for _, v := range companyUserAddCommand.UsersRole {
id, err := strconv.Atoi(v)
for _, v := range companyUserAddCommand.UserRole {
id, err := strconv.Atoi(v.RoleId)
if err == nil {
userRole = append(userRole, int64(id))
}
... ... @@ -128,7 +128,7 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.
UserName: companyUserAddCommand.UsersName,
Phone: companyUserAddCommand.Phone,
Avatar: companyUserAddCommand.Avatar,
Email: companyUserAddCommand.Avatar,
Email: companyUserAddCommand.Email,
Password: "123456", //TODO 填充密码
})
if err != nil {
... ...
... ... @@ -13,7 +13,7 @@ var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080"
var ALLIED_CREATION_USER_HOST = "http://localhost:8081"
//天联共创业务模块
var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8081"
var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082"
//通用模块短信服务
var SMS_SERVE_HOST = "http://localhost:8081"
... ...
... ... @@ -53,24 +53,23 @@ func (t *LoginToken) GenerateRefreshToken() (string, error) {
func (t *LoginToken) GenerateAuthCode() (string, error) {
nowTime := time.Now().Unix()
claims := LoginToken{
StandardClaims: jwt.StandardClaims{
NotBefore: nowTime,
IssuedAt: nowTime,
ExpiresAt: nowTime + authCodeExpire,
Issuer: "allied_creation_gateway",
},
t.StandardClaims = jwt.StandardClaims{
NotBefore: nowTime,
IssuedAt: nowTime,
ExpiresAt: nowTime + authCodeExpire,
Issuer: "allied_creation_gateway",
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
token := jwt.NewWithClaims(jwt.SigningMethodHS256, *t)
return token.SignedString([]byte(loginTokenSecret))
}
func (t *LoginToken) ParseToken(str string) error {
tokenClaims, err := jwt.ParseWithClaims(
str,
&LoginToken{},
t,
func(token *jwt.Token) (interface{}, error) {
return loginTokenSecret, nil
return []byte(loginTokenSecret), nil
})
if err != nil {
return err
... ...
... ... @@ -3,7 +3,7 @@ package models
import "time"
type LoginAccess struct {
tableName string `pg:"login_accesss,alias:login_access"`
tableName string `pg:"login_access,alias:login_access"`
LoginAccessId int64 `pg:",pk"`
// 账号
... ...
... ... @@ -138,8 +138,8 @@ func (repository *LoginAccessRepository) Find(queryOptions map[string]interface{
query := sqlbuilder.BuildQuery(tx.Model(&loginAccessModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("login_access_id", "DESC")
query.SetWhereByQueryOption("account", "account")
query.SetWhereByQueryOption("platform", "platform")
query.SetWhereByQueryOption("account = ?", "account")
query.SetWhereByQueryOption("platform = ?", "platform")
if count, err := query.SelectAndCount(); err != nil {
return 0, loginAccesss, err
} else {
... ...
... ... @@ -23,6 +23,6 @@ func NewHttplibAlliedCreationCooperation(operator domain.Operator) *HttplibAllie
UserId: operator.UserId,
UserBaseId: operator.UserBaseId,
},
baseUrL: constant.ALLIED_CREATION_USER_HOST,
baseUrL: constant.ALLIED_CREATION_COOPERATION_HOST,
}
}
... ...
... ... @@ -193,3 +193,34 @@ func (gateway HttplibAlliedCreationUser) AuthResetPhone(param ReqAuthResetPhone)
err = gateway.GetResponseData(result, &data)
return &data, err
}
//RefreshIM 刷新IM信息
func (gateway HttplibAlliedCreationUser) AuthRefreshIM(param ReqAuthRefreshIM) (*DataAuthRefreshIM, error) {
url := gateway.baseUrL + "/auth/refresh-im"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:刷新IM信息。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求刷新IM信息失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取刷新IM信息失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:刷新IM信息。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析刷新IM信息:%w", err)
}
var data DataAuthRefreshIM
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -59,3 +59,21 @@ type (
ReqAuthResetPassword struct{}
DataAuthResetPassword struct{}
)
//重置手机号
type (
ReqAuthRefreshIM struct {
// 手机号码
Phone string `cname:"手机号码" json:"phone" valid:"Required"`
// 刷新标识 0:刷新IM信息,并返回 1:使用旧的im信息
RefreshFlag int `cname:"刷新标识" json:"refreshFlag"`
}
DataAuthRefreshIM struct {
// 网易云信ID
Accid string `json:"accid"`
// 网易云信Token
ImToken string `json:"imToken"`
// 系统分配客服ID
CsAccountId string `json:"csAccountId"`
}
)
... ...
... ... @@ -41,6 +41,6 @@ func (controller *baseController) GetOperator() domain.Operator {
UserId: 9,
CompanyId: 23,
OrgId: 45,
UserBaseId: 1,
UserBaseId: 5,
}
}
... ...
... ... @@ -153,6 +153,8 @@ func (controller *CooperationController) GetCooperationProject() {
return
}
cmd.Operator = controller.GetOperator()
projectId, _ := controller.GetInt(":projectId")
cmd.CooperationProjectId = projectId
data, err := svr.GetCooperationProject(cmd)
controller.Response(data, err)
}
... ...
... ... @@ -18,6 +18,7 @@ func (controller *CooperationProjectController) CreateCooperationProject() {
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
createCooperationProjectCommand.Operator = controller.GetOperator()
data, err := cooperationProjectService.CreateCooperationProject(createCooperationProjectCommand)
controller.Response(data, err)
}
... ... @@ -31,6 +32,7 @@ func (controller *CooperationProjectController) UpdateCooperationProject() {
}
projectId := controller.GetString(":projectId")
updateCooperationProjectCommand.CooperationProjectId = projectId
updateCooperationProjectCommand.Operator = controller.GetOperator()
data, err := cooperationProjectService.UpdateCooperationProject(updateCooperationProjectCommand)
controller.Response(data, err)
}
... ... @@ -40,6 +42,7 @@ func (controller *CooperationProjectController) GetCooperationProject() {
getCooperationProjectQuery := &query.GetCooperationProjectQuery{}
projectId, _ := controller.GetInt(":projectId")
getCooperationProjectQuery.CooperationProjectId = projectId
getCooperationProjectQuery.Operator = controller.GetOperator()
data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery)
controller.Response(data, err)
}
... ... @@ -51,6 +54,7 @@ func (controller *CooperationProjectController) ListCooperationProject() {
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
listCooperationProjectQuery.Operator = controller.GetOperator()
cnt, data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery)
controller.returnPageListData(cnt, data, err, listCooperationProjectQuery.PageNumber)
}
... ... @@ -60,6 +64,7 @@ func (controller *CooperationProjectController) EndCooperationProject() {
endCooperationProjectCommand := &command.EndCooperationProjectCommand{}
controller.Unmarshal(endCooperationProjectCommand)
//TODO
endCooperationProjectCommand.Operator = controller.GetOperator()
data, err := cooperationProjectService.EndCooperationProject(endCooperationProjectCommand)
controller.Response(data, err)
}
... ...
... ... @@ -12,7 +12,7 @@ func init() {
web.Router("/v1/app/auth/access-token", &mobile_client.AuthController{}, "Post:GetAuthAccessToken")
web.Router("/v1/app/auth/refresh-token", &mobile_client.AuthController{}, "Post:RefreshAuthAccessToken")
web.Router("/v1/app/auth/user-info", &mobile_client.AuthController{}, "Post:GetUserInfo")
web.Router("/v1/app/auth/user-menu", &mobile_client.AuthController{}, "Post:GetUserMenus")
web.Router("/v1/app/auth/user-orgs", &mobile_client.AuthController{}, "Post:GetUserOrg")
web.Router("/v1/app/user/user-info", &mobile_client.AuthController{}, "Post:GetUserInfo")
web.Router("/v1/app/user/user-menu", &mobile_client.AuthController{}, "Post:GetUserMenus")
web.Router("/v1/app/user/user-orgs", &mobile_client.AuthController{}, "Post:GetUserOrg")
}
... ...
... ... @@ -11,4 +11,13 @@ func init() {
web.Router("/v1/web/cooperation-projects/:projectId", &web_client.CooperationProjectController{}, "Get:GetCooperationProject")
web.Router("/v1/web/cooperation-projects/search", &web_client.CooperationProjectController{}, "Post:ListCooperationProject")
web.Router("/v1/web/cooperation-projects/end", &web_client.CooperationProjectController{}, "Put:EndCooperationProject")
/***** 1.共创模式 *****/
web.Router("/v1/web/cooperation-modes/", &web_client.CooperationModeController{}, "Post:CreateCooperationMode")
web.Router("/v1/web/cooperation-modes/:cooperationModeId", &web_client.CooperationModeController{}, "Put:UpdateCooperationMode")
web.Router("/v1/web/cooperation-modes/:cooperationModeId", &web_client.CooperationModeController{}, "Get:GetCooperationMode")
web.Router("/v1/web/cooperation-modes/:cooperationModeId", &web_client.CooperationModeController{}, "Delete:RemoveCooperationMode")
web.Router("/v1/web/cooperation-modes/search", &web_client.CooperationModeController{}, "Post:SearchCooperationMode")
web.Router("/v1/web/cooperation-modes/", &web_client.CooperationModeController{}, "Get:ListCooperationMode")
}
... ...
... ... @@ -2,6 +2,7 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
)
... ... @@ -12,4 +13,5 @@ func init() {
web.Router("/v1/web/orgs/:orgId", &web_client.OrgsController{}, "Get:OrgGet")
web.Router("/v1/web/orgs/enable", &web_client.OrgsController{}, "Post:OrgEnable")
web.Router("/v1/web/orgs/departments", &web_client.OrgsController{}, "Post:OrgGetSubDepartment")
web.Router("/v1/web/orgs/department-users", &mobile_client.OrgController{}, "Post:DepartmentUsers")
}
... ...