作者 陈志颖

feat:增加部门REST集成

... ... @@ -138,6 +138,7 @@ func (dividendsEstimateService *DividendsEstimateService) ListMoneyIncentivesEst
if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(listMoneyIncentivesEstimateQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// TODO 判断承接人是否已分红
var moneyIncentivesEstimateDtos []*dto.MoneyIncentivesEstimateDto
for _, cooperationContract := range cooperationContracts {
moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{}
... ...
package domain_service
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/adaptor"
)
type DepartmentService struct {
}
func (service *DepartmentService) DepartmentFrom(companyId int64, departmentId int64) (*domain.Department, error) {
return nil, nil
if departmentAdaptor, err := adaptor.NewDepartmentAdaptor(); err != nil {
return nil, err
} else {
if department, err := departmentAdaptor.ToDepartment(companyId, departmentId); err != nil {
return nil, err
} else {
return department, nil
}
}
}
func NewDepartmentService() (*DepartmentService, error) {
... ...
... ... @@ -95,23 +95,30 @@ func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (*t
}
// GetDepartment 获取部门信息
func (serviceGateway *HttplibUserServiceGateway) GetDepartment(companyId int64, departmentId int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
url := strings.Join([]string{serviceGateway.baseURL, "companies/" + companyIdStr}, "/")
func (serviceGateway *HttplibUserServiceGateway) GetDepartment(companyId int64, departmentId int64) (*translator.DepartmentDetail, error) {
departmentIdStr := strconv.FormatInt(departmentId, 10)
url := serviceGateway.baseURL + "/org/" + departmentIdStr
request := serviceGateway.createRequest(url, "get")
options := make(map[string]interface{})
options["departmentId"] = departmentId
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
response := make(map[string]interface{})
err2 := request.ToJSON(&response)
if err2 != nil {
return nil, err2
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("获取返回组织失败:%w", err)
}
data, err := serviceGateway.responseHandle(response)
return data, 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.DepartmentDetail
err = serviceGateway.getResponseData(result, &data)
return &data, err
}
// GetOrganization 获取组织信息
... ...
... ... @@ -7,7 +7,7 @@ type UserServiceGateway interface {
GetUsers(companyId int64, orgId int64, uids []int64) (map[string]interface{}, error)
GetCompany(companyId int64) (*translator.CompanyDetail, error)
GetOrganization(companyId int64, organizationId int64) (*translator.OrganizationDetail, error)
GetDepartment(companyId int64, departmentId int64) (map[string]interface{}, error)
GetDepartment(companyId int64, departmentId int64) (*translator.DepartmentDetail, error)
UserInMenu(companyId int64, userId int64, menuCode string) (bool, error)
UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error)
}
... ...
package translator
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type DepartmentTranslator struct {
}
func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(data map[string]interface{}) (*domain.Department, error) {
type DepartmentDetail struct {
OrgId int64 `json:"orgId"`
CompanyId int64 `json:"companyId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
OrgCode string `json:"orgCode"`
OrgName string `json:"orgName"`
Ext struct {
} `json:"ext"`
IsOrg int `json:"isOrg"`
OrgStatus int `json:"orgStatus"`
}
func (translator *DepartmentTranslator) ToDepartmentFromRepresentation(department *DepartmentDetail) (*domain.Department, error) {
return &domain.Department{
DepartmentId: 0,
DepartmentName: "",
DepartmentNumber: "",
DepartmentId: department.OrgId,
DepartmentName: department.OrgName,
DepartmentNumber: department.OrgCode,
IsOrganization: false,
}, nil
}
... ...