审查视图

pkg/infrastructure/service_gateway/translator/user_translator.go 11.8 KB
1
package translator
陈志颖 authored
2
3 4 5 6
import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
	"time"
)
陈志颖 authored
7 8 9 10

type UserTranslator struct {
}
11 12 13 14 15 16 17 18 19 20 21 22 23 24
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"`
}
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
type UserDetail struct {
	UserId          int64  `json:"userId"`
	UserBaseId      int64  `json:"userBaseId"`
	UserType        int32  `json:"userType"`
	UserCode        string `json:"userCode"`
	EnableStatus    int32  `json:"enableStatus"`
	CooperationInfo struct {
		CooperationCompany  string    `json:"cooperationCompany"`
		CooperationDeadline time.Time `json:"cooperationDeadline"`
	} `json:"cooperationInfo,omitempty"`
	UserInfo struct {
		Phone    string `json:"phone"`
		UserCode string `json:"userCode"`
		Email    string `json:"email"`
		UserName string `json:"userName"`
		Avatar   string `json:"avatar"`
	} `json:"userInfo,omitempty"`
yangfu authored
42
	Company struct {
43 44 45 46 47 48 49
		CompanyId        int64     `json:"companyId"`
		CompanyName      string    `json:"companyName"`
		Scale            string    `json:"scale"`
		IndustryCategory string    `json:"industryCategory"`
		RegisteredTime   time.Time `json:"registeredTime"`
		Status           int64     `json:"status"`
	} `json:"company,omitempty"`
yangfu authored
50
	Org struct {
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
		OrgId   int64  `json:"orgId"`
		OrgCode string `json:"orgCode"`
		OrgName string `json:"orgName"`
	} `json:"org,omitempty"`
	Department *struct {
		DepartmentId   int64  `json:"departmentId"`
		DepartmentName string `json:"departmentName"`
	} `json:"department,omitempty"`
	UserRole []struct {
		RoleID   int64  `json:"roleId"`
		RoleName string `json:"roleName"`
		Ext      struct {
			OrgName string `json:"orgName"`
		} `json:"ext,omitempty"`
	} `json:"userRole"`
	UserOrg []struct {
		OrgID     int64     `json:"orgId"`
		CreatedAt time.Time `json:"createdAt"`
		UpdatedAt time.Time `json:"updatedAt"`
		DeletedAt time.Time `json:"deletedAt"`
		OrgName   string    `json:"orgName"`
	} `json:"userOrg"`
73 74 75
	Favorite struct {
		OrgItems []int64 `json:"orgItems"`
	} `json:"favorite"`
76 77
	// 创建时间
	CreatedAt time.Time `json:"createdAt,omitempty"`
78 79
}
80 81 82 83 84 85 86 87 88 89 90
func (user *UserDetail) CheckOrgStarred(orgId int64) bool {
	var starred bool = false
	for i := range user.Favorite.OrgItems {
		if user.Favorite.OrgItems[i] == orgId {
			starred = true
			return starred
		}
	}
	return false
}
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail) (*domain.Relevant, error) {
	var orgs []*domain.Org
	for _, org := range user.UserOrg {
		orgs = append(orgs, &domain.Org{
			OrgId:   org.OrgID,
			OrgName: org.OrgName,
			Company: &domain.Company{
				CompanyId:   user.Company.CompanyId,
				CompanyLogo: "",
				CompanyName: user.Company.CompanyName,
			},
		})
	}
	var roles []*domain.Role
	for _, role := range user.UserRole {
		roles = append(roles, &domain.Role{
107
			RoleId:   role.RoleID,
108 109 110
			RoleName: role.RoleName,
		})
	}
111
	return &domain.Relevant{
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
		UserId:     user.UserId,
		UserBaseId: user.UserBaseId,
		Org: &domain.Org{
			OrgId:   user.Org.OrgId,
			OrgName: user.Org.OrgName,
			Company: &domain.Company{
				CompanyId:   user.Company.CompanyId,
				CompanyLogo: "",
				CompanyName: user.Company.CompanyName,
			},
		},
		Orgs: orgs,
		Department: &domain.Department{
			DepartmentId:     user.Department.DepartmentId,
			DepartmentName:   user.Department.DepartmentName,
			DepartmentNumber: "",
			IsOrganization:   false,
		},
		Roles: roles,
		UserInfo: &domain.UserInfo{
			UserAvatar:  user.UserInfo.Avatar,
			UserEmail:   user.UserInfo.Email,
			UserName:    user.UserInfo.UserName,
			UserPhone:   user.UserInfo.Phone,
			UserAccount: "",
137
			UserCode:    user.UserCode,
138
		},
139 140 141 142
		UserType:  user.UserType,
		UserName:  user.UserInfo.UserName,
		UserPhone: user.UserInfo.Phone,
		Status:    user.EnableStatus,
143 144 145 146 147
		Company: &domain.Company{
			CompanyId:   user.Company.CompanyId,
			CompanyLogo: "",
			CompanyName: user.Company.CompanyName,
		},
148
	}, nil
陈志颖 authored
149 150
}
151
func (translator *UserTranslator) ToReferrerFromRepresentation(user *UserDetail) (*domain.Referrer, error) {
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
	var orgs []*domain.Org
	for _, org := range user.UserOrg {
		orgs = append(orgs, &domain.Org{
			OrgId:   org.OrgID,
			OrgName: org.OrgName,
			Company: &domain.Company{
				CompanyId:   user.Company.CompanyId,
				CompanyLogo: "",
				CompanyName: user.Company.CompanyName,
			},
		})
	}
	var roles []*domain.Role
	for _, role := range user.UserRole {
		roles = append(roles, &domain.Role{
			RoleId:   int64(role.RoleID),
			RoleName: role.RoleName,
		})
	}
171
	return &domain.Referrer{
172 173
		UserId:     user.UserId,
		UserBaseId: user.UserBaseId,
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
		Roles:      roles,
		Orgs:       orgs,
		Org: &domain.Org{
			OrgId:   user.Org.OrgId,
			OrgName: user.Org.OrgName,
			Company: nil,
		},
		Department: &domain.Department{
			DepartmentId:     user.Department.DepartmentId,
			DepartmentName:   user.Department.DepartmentName,
			DepartmentNumber: "",
			IsOrganization:   false,
		},
		Company: &domain.Company{
			CompanyId:   user.Company.CompanyId,
			CompanyLogo: "",
			CompanyName: user.Company.CompanyName,
		},
192 193 194 195 196 197 198 199
		UserInfo: &domain.UserInfo{
			UserAvatar:  user.UserInfo.Avatar,
			UserEmail:   user.UserInfo.Email,
			UserName:    user.UserInfo.UserName,
			UserPhone:   user.UserInfo.Phone,
			UserAccount: "",
			UserCode:    user.UserCode,
		},
200 201 202
		UserType:  user.UserType,
		UserName:  user.UserInfo.UserName,
		UserPhone: user.UserInfo.Phone,
203
	}, nil
陈志颖 authored
204 205
}
206
func (translator *UserTranslator) ToUndertakerFromRepresentation(user *UserDetail) (*domain.Undertaker, error) {
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
	var orgs []*domain.Org
	for _, org := range user.UserOrg {
		orgs = append(orgs, &domain.Org{
			OrgId:   org.OrgID,
			OrgName: org.OrgName,
			Company: &domain.Company{
				CompanyId:   user.Company.CompanyId,
				CompanyLogo: "",
				CompanyName: user.Company.CompanyName,
			},
		})
	}
	var roles []*domain.Role
	for _, role := range user.UserRole {
		roles = append(roles, &domain.Role{
			RoleId:   int64(role.RoleID),
			RoleName: role.RoleName,
		})
	}
226
	return &domain.Undertaker{
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
		UserId:     user.UserId,
		UserBaseId: user.UserBaseId,
		Org: &domain.Org{
			OrgId:   user.Org.OrgId,
			OrgName: user.Org.OrgName,
			Company: nil,
		},
		Orgs: orgs,
		Department: &domain.Department{
			DepartmentId:     user.Department.DepartmentId,
			DepartmentName:   user.Department.DepartmentName,
			DepartmentNumber: "",
			IsOrganization:   false,
		},
		Roles: roles,
		UserInfo: &domain.UserInfo{
			UserAvatar:  user.UserInfo.Avatar,
			UserEmail:   user.UserInfo.Email,
			UserName:    user.UserInfo.UserName,
			UserPhone:   user.UserInfo.Phone,
			UserAccount: "",
248
			UserCode:    user.UserCode,
249 250 251 252 253 254 255 256 257 258
		},
		UserType:  user.UserType,
		UserName:  user.UserInfo.UserName,
		UserPhone: user.UserInfo.Phone,
		Status:    user.EnableStatus,
		Company: &domain.Company{
			CompanyId:   user.Company.CompanyId,
			CompanyLogo: "",
			CompanyName: user.Company.CompanyName,
		},
259 260
		ContractAttachment: nil,
	}, nil
陈志颖 authored
261 262
}
263
func (translator *UserTranslator) ToSalesmanFromRepresentation(user *UserDetail) (*domain.Salesman, error) {
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	var orgs []*domain.Org
	for _, org := range user.UserOrg {
		orgs = append(orgs, &domain.Org{
			OrgId:   org.OrgID,
			OrgName: org.OrgName,
			Company: &domain.Company{
				CompanyId:   user.Company.CompanyId,
				CompanyLogo: "",
				CompanyName: user.Company.CompanyName,
			},
		})
	}
	var roles []*domain.Role
	for _, role := range user.UserRole {
		roles = append(roles, &domain.Role{
			RoleId:   int64(role.RoleID),
			RoleName: role.RoleName,
		})
	}
283
	return &domain.Salesman{
284 285
		UserId:     user.UserId,
		UserBaseId: user.UserBaseId,
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
		Roles:      roles,
		Orgs:       orgs,
		Org: &domain.Org{
			OrgId:   user.Org.OrgId,
			OrgName: user.Org.OrgName,
			Company: nil,
		},
		Department: &domain.Department{
			DepartmentId:     user.Department.DepartmentId,
			DepartmentName:   user.Department.DepartmentName,
			DepartmentNumber: "",
			IsOrganization:   false,
		},
		Company: &domain.Company{
			CompanyId:   user.Company.CompanyId,
			CompanyLogo: "",
			CompanyName: user.Company.CompanyName,
		},
		UserInfo: &domain.UserInfo{
			UserAvatar:  user.UserInfo.Avatar,
			UserEmail:   user.UserInfo.Email,
			UserName:    user.UserInfo.UserName,
			UserPhone:   user.UserInfo.Phone,
			UserAccount: "",
310
			UserCode:    user.UserCode,
311 312 313 314
		},
		UserType:  user.UserType,
		UserName:  user.UserInfo.UserName,
		UserPhone: user.UserInfo.Phone,
315
	}, nil
陈志颖 authored
316 317
}
318
func (translator *UserTranslator) ToOperatorFromRepresentation(user *UserDetail) (*domain.User, error) {
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
	var orgs []*domain.Org
	for _, org := range user.UserOrg {
		orgs = append(orgs, &domain.Org{
			OrgId:   org.OrgID,
			OrgName: org.OrgName,
			Company: &domain.Company{
				CompanyId:   user.Company.CompanyId,
				CompanyLogo: "",
				CompanyName: user.Company.CompanyName,
			},
		})
	}
	var roles []*domain.Role
	for _, role := range user.UserRole {
		roles = append(roles, &domain.Role{
			RoleId:   int64(role.RoleID),
			RoleName: role.RoleName,
		})
	}
338
	return &domain.User{
339 340
		UserId:     user.UserId,
		UserBaseId: user.UserBaseId,
341 342 343 344 345 346 347 348 349 350 351 352 353
		Org: &domain.Org{
			OrgId:   user.Org.OrgId,
			OrgName: user.Org.OrgName,
			Company: nil,
		},
		Orgs: orgs,
		Department: &domain.Department{
			DepartmentId:     user.Department.DepartmentId,
			DepartmentName:   user.Department.DepartmentName,
			DepartmentNumber: "",
			IsOrganization:   false,
		},
		Roles: roles,
yangfu authored
354 355 356 357
		UserInfo: &domain.UserInfo{
			UserName:   user.UserInfo.UserName,
			UserPhone:  user.UserInfo.Phone,
			UserAvatar: user.UserInfo.Avatar,
358
			UserCode:   user.UserCode,
yangfu authored
359
		},
360
		UserType:  user.UserType,
yangfu authored
361 362
		UserName:  user.UserInfo.UserName,
		UserPhone: user.UserInfo.Phone,
363 364 365 366 367 368
		Status:    user.EnableStatus,
		Company: &domain.Company{
			CompanyId:   user.Company.CompanyId,
			CompanyLogo: "",
			CompanyName: user.Company.CompanyName,
		},
369
	}, nil
陈志颖 authored
370
}
371
372
func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*domain.User, error) {
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
	var orgs []*domain.Org
	for _, org := range user.UserOrg {
		orgs = append(orgs, &domain.Org{
			OrgId:   org.OrgID,
			OrgName: org.OrgName,
			Company: &domain.Company{
				CompanyId:   user.Company.CompanyId,
				CompanyLogo: "",
				CompanyName: user.Company.CompanyName,
			},
		})
	}
	var roles []*domain.Role
	for _, role := range user.UserRole {
		roles = append(roles, &domain.Role{
388
			RoleId:   role.RoleID,
389 390 391
			RoleName: role.RoleName,
		})
	}
392
	return &domain.User{
393 394
		UserId:     user.UserId,
		UserBaseId: user.UserBaseId,
395 396 397 398 399 400 401 402 403 404 405 406 407
		Org: &domain.Org{
			OrgId:   user.Org.OrgId,
			OrgName: user.Org.OrgName,
			Company: nil,
		},
		Orgs: orgs,
		Department: &domain.Department{
			DepartmentId:     user.Department.DepartmentId,
			DepartmentName:   user.Department.DepartmentName,
			DepartmentNumber: "",
			IsOrganization:   false,
		},
		Roles: roles,
yangfu authored
408 409 410 411
		UserInfo: &domain.UserInfo{
			UserName:   user.UserInfo.UserName,
			UserPhone:  user.UserInfo.Phone,
			UserAvatar: user.UserInfo.Avatar,
412
			UserCode:   user.UserCode,
yangfu authored
413
		},
414
		UserType:  user.UserType,
yangfu authored
415 416
		UserName:  user.UserInfo.UserName,
		UserPhone: user.UserInfo.Phone,
417 418 419 420 421 422
		Status:    user.EnableStatus,
		Company: &domain.Company{
			CompanyId:   user.Company.CompanyId,
			CompanyLogo: "",
			CompanyName: user.Company.CompanyName,
		},
423
		CreatedAt: user.CreatedAt,
424 425 426
	}, nil
}
427 428 429 430
func (translator *UserTranslator) ToVisitorFromRepresentation(user *UserDetail) (*domain.User, error) {
	return &domain.User{
		UserBaseId: user.UserBaseId,
		UserInfo: &domain.UserInfo{
431 432 433
			UserName:   user.UserInfo.UserName,
			UserPhone:  user.UserInfo.Phone,
			UserAvatar: user.UserInfo.Avatar,
434 435 436 437 438 439 440
		},
		UserType:  user.UserType,
		UserName:  user.UserInfo.UserName,
		UserPhone: user.UserInfo.Phone,
	}, nil
}
441 442 443
func NewUserTranslator() (*UserTranslator, error) {
	return &UserTranslator{}, nil
}