作者 tangxuhui

更新

package command
type CompanySignUpCommand struct {
CompanyName string
Contacts string
IndustryCategory string
Password string
Phone string
Scale string
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
type CommonService struct {
... ... @@ -13,7 +16,7 @@ func NewCommonService(options map[string]interface{}) *CommonService {
}
//GetDictionaryByCode 根据code获取字典数据
func (dictionaryService *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDictionaryByCodeQuery) (interface{}, error) {
func (srv *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDictionaryByCodeQuery) (interface{}, error) {
creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic()
result, err := creationBasicGateway.GetDictionarysByCode(allied_creation_basic.ReqGetDictionaryByCode{
DictCode: getDictionaryQuery.DictCode,
... ... @@ -23,3 +26,20 @@ func (dictionaryService *CommonService) GetDictionaryByCode(getDictionaryQuery *
}
return result, nil
}
//CompanySignUp 公司注册
func (srv *CommonService) CompanySignUp(signUpCommand *command.CompanySignUpCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(0, 0, 0)
_, err := creationUserGateway.AuthCompanySignUp(allied_creation_user.ReqAuthCompanySignUp{
CompanyName: signUpCommand.CompanyName,
Contacts: signUpCommand.Contacts,
IndustryCategory: signUpCommand.IndustryCategory,
Password: signUpCommand.Password,
Phone: signUpCommand.Phone,
Scale: signUpCommand.Scale,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return signUpCommand, nil
}
... ...
... ... @@ -36,6 +36,7 @@ type UserRole struct {
RoleID string `json:"roleId"`
RoleName string `json:"roleName"`
OrgName string `json:"orgName"`
Descript string `json:"descript"`
}
type UserMenu struct {
... ...
package query
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type CompanyOrgSelectorQuery struct {
//操作人
Operator domain.Operator `json:"-"`
//
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
OrgName string `json:"orgName"`
}
... ...
package query
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
type CompanyRoleSelectorQuery struct {
//操作人
Operator domain.Operator `json:"-"`
//
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
RoleName string `json:"roleName"`
}
... ...
... ... @@ -16,6 +16,11 @@ import (
type UsersService struct {
}
func NewUsersService(options map[string]interface{}) *UsersService {
newUsersService := &UsersService{}
return newUsersService
}
// 获取公司用户信息
func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.CompanyUserGetQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
... ... @@ -258,7 +263,7 @@ func (usersService *UsersService) CooperationUserAdd(cooperationUserAddCommand *
Avatar: cooperationUserAddCommand.Avatar,
OrgId: cooperationUserAddCommand.Operator.OrgId,
Phone: cooperationUserAddCommand.Phone,
Password: "", //TODO 填充默认密码
Password: "123456", //TODO 填充默认密码
})
data := struct {
UserId string `json:"userId"`
... ... @@ -380,7 +385,61 @@ func (usersService *UsersService) CooperationUserUpdate(cooperationUserUpdateCom
return cooperationUserUpdateCommand, err
}
func NewUsersService(options map[string]interface{}) *UsersService {
newUsersService := &UsersService{}
return newUsersService
//CompanyOrgSelector 获取公司组织的下拉列表
func (usersService *UsersService) SelectorCompanyOrg(selectorQuery *query.CompanyOrgSelectorQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
selectorQuery.Operator.CompanyId,
selectorQuery.Operator.OrgId,
selectorQuery.Operator.UserId)
result, err := creationUserGateway.OrgSearch(allied_creation_user.ReqOrgSearch{
CompanyId: int(selectorQuery.Operator.CompanyId),
DepName: selectorQuery.OrgName,
IsOrg: 1,
Limit: selectorQuery.PageSize,
Offset: (selectorQuery.PageNumber - 1) * selectorQuery.PageSize,
OrgCode: "",
ParentId: 0,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var (
dataList []dto.UserOrg
item dto.UserOrg
)
for _, v := range result.Orgs {
item = dto.UserOrg{
OrgID: strconv.Itoa(v.OrgID),
OrgName: v.OrgName,
}
dataList = append(dataList, item)
}
return int64(result.Count), dataList, nil
}
//SelectorCompanyRole 获取公司角色的下拉列表
func (usersService *UsersService) SelectorCompanyRole(selectorQuery *query.CompanyRoleSelectorQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
selectorQuery.Operator.CompanyId,
selectorQuery.Operator.OrgId,
selectorQuery.Operator.UserId)
result, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{
Limit: selectorQuery.PageSize,
Offset: (selectorQuery.PageNumber - 1) * selectorQuery.PageSize,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var (
dataList []dto.UserOrg
// item dto.UserOrg
)
// for _, v := range result.Orgs {
// item = dto.UserOrg{
// OrgID: strconv.Itoa(v.OrgID),
// OrgName: v.OrgName,
// }
// dataList = append(dataList, item)
// }
return int64(result.Count), dataList, nil
}
... ...
package allied_creation_user
import (
"encoding/json"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
// AuthCompanySignUp 企业注册
func (gateway HttplibAlliedCreationUser) AuthCompanySignUp(param ReqAuthCompanySignUp) (*DataAuthCompanySignUp, error) {
url := gateway.baseUrL + "/auth/company-sign-up"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:企业注册。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求企业注册失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取企业注册失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:企业注册。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析企业注册:%w", err)
}
var data DataAuthCompanySignUp
err = gateway.GetResponseData(result, &data)
return &data, err
}
//AuthChangePassword 修改密码
func (gateway HttplibAlliedCreationUser) AuthChangePassword(param ReqAuthChangePassword) (*DataAuthChangePassword, error) {
url := gateway.baseUrL + "/auth/change-password"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:修改密码。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求修改密码失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取修改密码失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:修改密码。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析修改密码:%w", err)
}
var data DataAuthChangePassword
err = gateway.GetResponseData(result, &data)
return &data, err
}
// AuthCheckPassword 手机账号密码检查
func (gateway HttplibAlliedCreationUser) AuthCheckPassword(param ReqAuthCheckPassword) (*DataAuthCheckPassword, error) {
url := gateway.baseUrL + "/auth/check-password"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:手机账号密码检查。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求手机账号密码检查失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取手机账号密码检查失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:手机账号密码检查。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析手机账号密码检查:%w", err)
}
var data DataAuthCheckPassword
err = gateway.GetResponseData(result, &data)
return &data, err
}
// AuthDestroyAccount 注销账号 (添加用户时重新激活)
func (gateway HttplibAlliedCreationUser) AuthDestroyAccount(param ReqAuthDestroyAccount) (*DataAuthDestroyAccount, error) {
url := gateway.baseUrL + "/auth/destroy-account"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:注销账号 (添加用户时重新激活)。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求注销账号 (添加用户时重新激活)失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取注销账号 (添加用户时重新激活)失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:注销账号 (添加用户时重新激活)。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析注销账号 (添加用户时重新激活):%w", err)
}
var data DataAuthDestroyAccount
err = gateway.GetResponseData(result, &data)
return &data, err
}
// AuthResetPassword 重置密码(忘记密码)
func (gateway HttplibAlliedCreationUser) AuthResetPassword(param ReqAuthResetPassword) (*DataAuthResetPassword, error) {
url := gateway.baseUrL + "/auth/reset-password"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:重置密码(忘记密码)。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求重置密码(忘记密码)失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取重置密码(忘记密码)失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:重置密码(忘记密码)。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析重置密码(忘记密码):%w", err)
}
var data DataAuthResetPassword
err = gateway.GetResponseData(result, &data)
return &data, err
}
//AuthResetPhone 重置手机号
func (gateway HttplibAlliedCreationUser) AuthResetPhone(param ReqAuthResetPhone) (*DataAuthResetPhone, error) {
url := gateway.baseUrL + "/auth/reset-phone"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:重置手机号。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求重置手机号失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取重置手机号失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:重置手机号。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析重置手机号:%w", err)
}
var data DataAuthResetPhone
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package allied_creation_user
//企业注册
type (
ReqAuthCompanySignUp struct {
CompanyName string `json:"companyName"`
Contacts string `json:"contacts"`
IndustryCategory string `json:"industryCategory"`
Password string `json:"password"`
Phone string `json:"phone"`
Scale string `json:"scale"`
}
DataAuthCompanySignUp struct {
}
)
//修改密码
type (
ReqAuthChangePassword struct {
NewPassword string `json:"newPassword"`
OldPassword string `json:"oldPassword"`
UserId string `json:"userId"`
}
DataAuthChangePassword struct {
}
)
//手机账号密码检查
type (
ReqAuthCheckPassword struct {
}
DataAuthCheckPassword struct {
}
)
//注销账号 (添加用户时重新激活)
type (
ReqAuthDestroyAccount struct {
}
DataAuthDestroyAccount struct {
}
)
//重置手机号
type (
ReqAuthResetPhone struct{}
DataAuthResetPhone struct{}
)
//重置密码(忘记密码)
type (
ReqAuthResetPassword struct{}
DataAuthResetPassword struct{}
)
... ...
... ... @@ -88,7 +88,7 @@ type (
ReqOrgSearch struct {
CompanyId int `json:"companyId"`
DepName string `json:"depName"`
IsOrg int `json:"isOrg"`
IsOrg int `json:"isOrg"` //否是组织(是:1 不是:2)
Limit int `json:"limit"`
Offset int `json:"offset"`
OrgCode string `json:"orgCode"`
... ...
... ... @@ -13,6 +13,10 @@ type (
OrgName string `json:"orgName"`
//角色码名称
RoleName string `json:"roleName"`
InOrgIds []int `json:"inOrgIds"`
OrgId int
}
DataRoleSearch struct {
... ...
... ... @@ -11,9 +11,11 @@ type baseController struct {
func (controller *baseController) returnPageListData(count int64, data interface{}, err error, pageNumber int) {
dataMap := map[string]interface{}{
"totalRow": count,
"pageNumber": pageNumber,
"list": data,
"grid": map[string]interface{}{
"total": count,
"pageNumber": pageNumber,
"list": data,
},
}
controller.Response(dataMap, err)
}
... ...
... ... @@ -119,3 +119,13 @@ func (controller *UsersController) CooperationUserResetPassword() {
data, err := usersService.CooperationUserResetPassword(cooperationUserResetPasswordCommand)
controller.Response(data, err)
}
//CompanyOrgSelector 组织选择表
func (controller *UsersController) SelectorCompanyOrg() {
usersService := service.NewUsersService(nil)
selectorQuery := &query.CompanyOrgSelectorQuery{}
controller.Unmarshal(selectorQuery)
selectorQuery.Operator = controller.GetOperator()
cnt, data, err := usersService.SelectorCompanyOrg(selectorQuery)
controller.returnPageListData(cnt, data, err, selectorQuery.PageNumber)
}
... ...
... ... @@ -18,4 +18,6 @@ func init() {
web.Router("/v1/web/users/cooperation-user/:userId", &web_client.UsersController{}, "Get:CooperationUserGet")
web.Router("/v1/web/users/cooperation-user/enable", &web_client.UsersController{}, "Put:CooperationUserEnable")
web.Router("/v1/web/users/cooperation-user/reset-password", &web_client.UsersController{}, "Put:CooperationUserResetPassword")
web.Router("/v1/web/users/selector/org", &web_client.UsersController{}, "Post:SelectorCompanyOrg")
}
... ...