正在显示
28 个修改的文件
包含
1719 行增加
和
15 行删除
| @@ -13,3 +13,43 @@ func CreateMenuRepository(options map[string]interface{}) (domain.MenuRepository | @@ -13,3 +13,43 @@ func CreateMenuRepository(options map[string]interface{}) (domain.MenuRepository | ||
| 13 | } | 13 | } |
| 14 | return repository.NewMenuRepository(transactionContext) | 14 | return repository.NewMenuRepository(transactionContext) |
| 15 | } | 15 | } |
| 16 | + | ||
| 17 | +func CreateOrgRepository(options map[string]interface{}) (domain.OrgRepository, error) { | ||
| 18 | + var transactionContext *pg.TransactionContext | ||
| 19 | + if value, ok := options["transactionContext"]; ok { | ||
| 20 | + transactionContext = value.(*pg.TransactionContext) | ||
| 21 | + } | ||
| 22 | + return repository.NewOrgRepository(transactionContext) | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func CreateRoleRepository(options map[string]interface{}) (domain.RoleRepository, error) { | ||
| 26 | + var transactionContext *pg.TransactionContext | ||
| 27 | + if value, ok := options["transactionContext"]; ok { | ||
| 28 | + transactionContext = value.(*pg.TransactionContext) | ||
| 29 | + } | ||
| 30 | + return repository.NewRoleRepository(transactionContext) | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +func CreateUsersBaseRepository(options map[string]interface{}) (domain.UsersBaseRepository, error) { | ||
| 34 | + var transactionContext *pg.TransactionContext | ||
| 35 | + if value, ok := options["transactionContext"]; ok { | ||
| 36 | + transactionContext = value.(*pg.TransactionContext) | ||
| 37 | + } | ||
| 38 | + return repository.NewUsersBaseRepository(transactionContext) | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +func CreateUsersRepository(options map[string]interface{}) (domain.UsersRepository, error) { | ||
| 42 | + var transactionContext *pg.TransactionContext | ||
| 43 | + if value, ok := options["transactionContext"]; ok { | ||
| 44 | + transactionContext = value.(*pg.TransactionContext) | ||
| 45 | + } | ||
| 46 | + return repository.NewUsersRepository(transactionContext) | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +func CreateCompanyRepository(options map[string]interface{}) (domain.CompanyRepository, error) { | ||
| 50 | + var transactionContext *pg.TransactionContext | ||
| 51 | + if value, ok := options["transactionContext"]; ok { | ||
| 52 | + transactionContext = value.(*pg.TransactionContext) | ||
| 53 | + } | ||
| 54 | + return repository.NewCompanyRepository(transactionContext) | ||
| 55 | +} |
pkg/domain/company.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 公司状态状态 1:已注册 2:待认证 3:已认证 | ||
| 6 | +const ( | ||
| 7 | + CompanyRegistered = iota + 1 | ||
| 8 | + CompanyUnauthenticated | ||
| 9 | + CompanyAuthenticated | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +// 企业信息 (base) | ||
| 13 | +type Company struct { | ||
| 14 | + // 企业id | ||
| 15 | + CompanyId int64 `json:"companyId"` | ||
| 16 | + // 企业配置信息 | ||
| 17 | + CompanyConfig *CompanyConfig `json:"companyConfig"` | ||
| 18 | + // 企业基本信息 | ||
| 19 | + CompanyInfo *CompanyInfo `json:"companyInfo"` | ||
| 20 | + // 公司状态 | ||
| 21 | + Status int `json:"status"` | ||
| 22 | + // 创建时间 | ||
| 23 | + CreatedAt time.Time `json:"createdAt"` | ||
| 24 | + // 更新时间 | ||
| 25 | + UpdatedAt time.Time `json:"updatedAt"` | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +type CompanyRepository interface { | ||
| 29 | + Save(company *Company) (*Company, error) | ||
| 30 | + Remove(company *Company) (*Company, error) | ||
| 31 | + FindOne(queryOptions map[string]interface{}) (*Company, error) | ||
| 32 | + Find(queryOptions map[string]interface{}) (int64, []*Company, error) | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +func (company *Company) Identify() interface{} { | ||
| 36 | + if company.CompanyId == 0 { | ||
| 37 | + return nil | ||
| 38 | + } | ||
| 39 | + return company.CompanyId | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func (company *Company) Update(data map[string]interface{}) error { | ||
| 43 | + if systemName, ok := data["systemName"]; ok { | ||
| 44 | + company.CompanyConfig.SystemName = systemName.(string) | ||
| 45 | + } | ||
| 46 | + if theme, ok := data["theme"]; ok { | ||
| 47 | + company.CompanyConfig.Theme = theme.(string) | ||
| 48 | + } | ||
| 49 | + if companyName, ok := data["companyName"]; ok { | ||
| 50 | + company.CompanyInfo.CompanyName = companyName.(string) | ||
| 51 | + } | ||
| 52 | + if scale, ok := data["scale"]; ok { | ||
| 53 | + company.CompanyInfo.Scale = scale.(string) | ||
| 54 | + } | ||
| 55 | + if logo, ok := data["logo"]; ok { | ||
| 56 | + company.CompanyInfo.Logo = logo.(string) | ||
| 57 | + } | ||
| 58 | + if address, ok := data["address"]; ok { | ||
| 59 | + company.CompanyInfo.Address = address.(string) | ||
| 60 | + } | ||
| 61 | + if industryCategory, ok := data["industryCategory"]; ok { | ||
| 62 | + company.CompanyInfo.IndustryCategory = industryCategory.(string) | ||
| 63 | + } | ||
| 64 | + if contacts, ok := data["contacts"]; ok { | ||
| 65 | + company.CompanyInfo.Contacts = contacts.(string) | ||
| 66 | + } | ||
| 67 | + if registTime, ok := data["registTime"]; ok { | ||
| 68 | + company.CompanyInfo.RegisteredTime = registTime.(time.Time) | ||
| 69 | + } | ||
| 70 | + if registStatus, ok := data["registStatus"]; ok { | ||
| 71 | + company.CompanyInfo.status = registStatus.(int) | ||
| 72 | + } | ||
| 73 | + if status, ok := data["status"]; ok { | ||
| 74 | + company.Status = status.(int) | ||
| 75 | + } | ||
| 76 | + if createdAt, ok := data["createdAt"]; ok { | ||
| 77 | + company.CreatedAt = createdAt.(time.Time) | ||
| 78 | + } | ||
| 79 | + if updatedAt, ok := data["updatedAt"]; ok { | ||
| 80 | + company.UpdatedAt = updatedAt.(time.Time) | ||
| 81 | + } | ||
| 82 | + return nil | ||
| 83 | +} |
pkg/domain/company_config.go
0 → 100644
pkg/domain/company_info.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 公司信息 | ||
| 6 | +type CompanyInfo struct { | ||
| 7 | + // 企业名称 | ||
| 8 | + CompanyName string `json:"companyName"` | ||
| 9 | + // 规模 | ||
| 10 | + Scale string `json:"scale"` | ||
| 11 | + // 公司Logo地址 | ||
| 12 | + Logo string `json:"logo"` | ||
| 13 | + // 公司地址 | ||
| 14 | + Address string `json:"address"` | ||
| 15 | + // 所属行业 | ||
| 16 | + IndustryCategory string `json:"industryCategory"` | ||
| 17 | + // 联系人 | ||
| 18 | + Contacts string `json:"contacts"` | ||
| 19 | + // 注册时间 | ||
| 20 | + RegisteredTime time.Time `json:"registeredTime"` | ||
| 21 | + // 状态 1:已注册 2:待认证 3:已认证 | ||
| 22 | + status int `json:"status"` | ||
| 23 | +} |
pkg/domain/cooperation_info.go
0 → 100644
pkg/domain/ext.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +// 冗余附加数据 | ||
| 4 | +type Ext struct { | ||
| 5 | + // 用户姓名 | ||
| 6 | + UsersName string `json:"usersName,omitempty"` | ||
| 7 | + // 组织名称 | ||
| 8 | + OrgName string `json:"orgName,omitempty"` | ||
| 9 | + // 手机号码 | ||
| 10 | + Phone string `json:"phone,omitempty"` | ||
| 11 | + // 部门名称 | ||
| 12 | + DepName string `json:"depName,omitempty"` | ||
| 13 | + // 父级部门名称 | ||
| 14 | + ParentDepName string `json:"parentDepName,omitempty"` | ||
| 15 | +} |
| @@ -37,31 +37,31 @@ type MenuType string | @@ -37,31 +37,31 @@ type MenuType string | ||
| 37 | // 系统菜单 | 37 | // 系统菜单 |
| 38 | type Menu struct { | 38 | type Menu struct { |
| 39 | // 菜单编号 | 39 | // 菜单编号 |
| 40 | - MenuId int64 `json:"menuId"` | 40 | + MenuId int64 `json:"menuId,omitempty"` |
| 41 | // 父级id | 41 | // 父级id |
| 42 | - ParentId int64 `json:"parentId"` | 42 | + ParentId int64 `json:"parentId,omitempty"` |
| 43 | // 菜单名称 | 43 | // 菜单名称 |
| 44 | - MenuName string `json:"menuName"` | 44 | + MenuName string `json:"menuName,omitempty"` |
| 45 | // 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码) | 45 | // 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码) |
| 46 | - Code string `json:"code"` | 46 | + Code string `json:"code,omitempty"` |
| 47 | // 权限编码 users:edit | 47 | // 权限编码 users:edit |
| 48 | - AccessCode string `json:"accessCode"` | 48 | + AccessCode string `json:"accessCode,omitempty"` |
| 49 | // 菜单类型 (目录catalog、菜单menu、按钮button) | 49 | // 菜单类型 (目录catalog、菜单menu、按钮button) |
| 50 | - MenuType string `json:"menuType"` | 50 | + MenuType string `json:"menuType,omitempty"` |
| 51 | // 菜单图标 | 51 | // 菜单图标 |
| 52 | - Icon string `json:"icon"` | 52 | + Icon string `json:"icon,omitempty"` |
| 53 | // 排序 | 53 | // 排序 |
| 54 | - Sort int `json:"sort"` | 54 | + Sort int `json:"sort,omitempty"` |
| 55 | // 菜单说明 | 55 | // 菜单说明 |
| 56 | - Remark string `json:"remark"` | 56 | + Remark string `json:"remark,omitempty"` |
| 57 | // 菜单类别 (web:1、app:2) | 57 | // 菜单类别 (web:1、app:2) |
| 58 | - Category string `json:"category"` | 58 | + Category string `json:"category,omitempty"` |
| 59 | // 路径节点路径("0,11,12,") | 59 | // 路径节点路径("0,11,12,") |
| 60 | - ParentPath string `json:"parentPath"` | 60 | + ParentPath string `json:"parentPath,omitempty"` |
| 61 | // 菜单是否公开状态,[1:显示],[2:隐藏],默认显示 | 61 | // 菜单是否公开状态,[1:显示],[2:隐藏],默认显示 |
| 62 | - IsPublish int `json:"isPublish"` | 62 | + IsPublish int `json:"isPublish,omitempty"` |
| 63 | // 启用状态(启用:1 禁用:2),默认启用 | 63 | // 启用状态(启用:1 禁用:2),默认启用 |
| 64 | - EnableStatus int `json:"enableStatus"` | 64 | + EnableStatus int `json:"enableStatus,omitempty"` |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | type MenuRepository interface { | 67 | type MenuRepository interface { |
pkg/domain/org.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 组织 organization | ||
| 6 | +type Org struct { | ||
| 7 | + // 组织ID | ||
| 8 | + OrgId int64 `json:"orgId,omitempty"` | ||
| 9 | + // 企业id | ||
| 10 | + CompanyId int64 `json:"companyId,omitempty"` | ||
| 11 | + // 创建时间 | ||
| 12 | + CreatedAt time.Time `json:"createdAt,omitempty"` | ||
| 13 | + // 更新时间 | ||
| 14 | + UpdatedAt time.Time `json:"updatedAt,omitempty"` | ||
| 15 | + // 删除时间 | ||
| 16 | + DeletedAt time.Time `json:"deletedAt,omitempty"` | ||
| 17 | + // 组织编码 | ||
| 18 | + OrgCode string `json:"orgCode,omitempty"` | ||
| 19 | + // 组织名称 | ||
| 20 | + OrgName string `json:"orgName,omitempty"` | ||
| 21 | + // 扩展数据 | ||
| 22 | + Ext *Ext `json:"ext,omitempty"` | ||
| 23 | + // 是否是组织标识 1:是 2:不是 | ||
| 24 | + IsOrg int `json:"isOrg,omitempty"` | ||
| 25 | + // 组织状态 1:启用 2:禁用 3.删除 | ||
| 26 | + OrgStatus int `json:"orgStatus,omitempty"` | ||
| 27 | + // 父级ID | ||
| 28 | + ParentId int64 `json:"parentId,omitempty"` | ||
| 29 | + // 父级节点路径("0,11,12,") | ||
| 30 | + ParentPath string `json:"parentPath,omitempty"` | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +type OrgRepository interface { | ||
| 34 | + Save(org *Org) (*Org, error) | ||
| 35 | + Remove(org *Org) (*Org, error) | ||
| 36 | + FindOne(queryOptions map[string]interface{}) (*Org, error) | ||
| 37 | + Find(queryOptions map[string]interface{}) (int64, []*Org, error) | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +func (org *Org) Identify() interface{} { | ||
| 41 | + if org.OrgId == 0 { | ||
| 42 | + return nil | ||
| 43 | + } | ||
| 44 | + return org.OrgId | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +func (org *Org) Update(data map[string]interface{}) error { | ||
| 48 | + if createdAt, ok := data["createdAt"]; ok { | ||
| 49 | + org.CreatedAt = createdAt.(time.Time) | ||
| 50 | + } | ||
| 51 | + if updatedAt, ok := data["updatedAt"]; ok { | ||
| 52 | + org.UpdatedAt = updatedAt.(time.Time) | ||
| 53 | + } | ||
| 54 | + if deletedAt, ok := data["deletedAt"]; ok { | ||
| 55 | + org.DeletedAt = deletedAt.(time.Time) | ||
| 56 | + } | ||
| 57 | + if orgCode, ok := data["orgCode"]; ok { | ||
| 58 | + org.OrgCode = orgCode.(string) | ||
| 59 | + } | ||
| 60 | + if orgName, ok := data["orgName"]; ok { | ||
| 61 | + org.OrgName = orgName.(string) | ||
| 62 | + } | ||
| 63 | + if usersName, ok := data["usersName"]; ok { | ||
| 64 | + org.Ext.UsersName = usersName.(string) | ||
| 65 | + } | ||
| 66 | + if orgName, ok := data["orgName"]; ok { | ||
| 67 | + org.Ext.OrgName = orgName.(string) | ||
| 68 | + } | ||
| 69 | + if phone, ok := data["phone"]; ok { | ||
| 70 | + org.Ext.Phone = phone.(string) | ||
| 71 | + } | ||
| 72 | + if depName, ok := data["depName"]; ok { | ||
| 73 | + org.Ext.DepName = depName.(string) | ||
| 74 | + } | ||
| 75 | + if parentDepName, ok := data["parentDepName"]; ok { | ||
| 76 | + org.Ext.ParentDepName = parentDepName.(string) | ||
| 77 | + } | ||
| 78 | + if isOrg, ok := data["isOrg"]; ok { | ||
| 79 | + org.IsOrg = isOrg.(int) | ||
| 80 | + } | ||
| 81 | + if parentId, ok := data["parentId"]; ok { | ||
| 82 | + org.ParentId = parentId.(int64) | ||
| 83 | + } | ||
| 84 | + if parentPath, ok := data["parentPath"]; ok { | ||
| 85 | + org.ParentPath = parentPath.(string) | ||
| 86 | + } | ||
| 87 | + return nil | ||
| 88 | +} |
pkg/domain/role.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 角色类型 1.普通角色 1024:超级管理员 | ||
| 6 | +const ( | ||
| 7 | + RoleTypeNormal = 1 | ||
| 8 | + RoleTypeAdmin = 1024 | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +// 角色 (base) | ||
| 12 | +type Role struct { | ||
| 13 | + // 角色ID | ||
| 14 | + RoleId int64 `json:"roleId,omitempty"` | ||
| 15 | + // 企业id | ||
| 16 | + CompanyId int64 `json:"companyId,omitempty"` | ||
| 17 | + // 组织ID | ||
| 18 | + OrgId int64 `json:"orgId,omitempty"` | ||
| 19 | + // 角色类型 1.普通角色 1024:超级管理员 | ||
| 20 | + RoleType int `json:"roleType,omitempty"` | ||
| 21 | + // 角色名称 | ||
| 22 | + RoleName string `json:"roleName,omitempty"` | ||
| 23 | + // 有权限的菜单 | ||
| 24 | + AccessMenus []int64 `json:"accessMenus,omitempty"` | ||
| 25 | + // 描述 | ||
| 26 | + Desc int64 `json:"desc,omitempty"` | ||
| 27 | + // 扩展数据 | ||
| 28 | + Ext *Ext `json:"ext,omitempty"` | ||
| 29 | + // 创建时间 | ||
| 30 | + CreatedAt time.Time `json:"createdAt,omitempty"` | ||
| 31 | + // 更新时间 | ||
| 32 | + UpdatedAt time.Time `json:"updatedAt,omitempty"` | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +type RoleRepository interface { | ||
| 36 | + Save(role *Role) (*Role, error) | ||
| 37 | + Remove(role *Role) (*Role, error) | ||
| 38 | + FindOne(queryOptions map[string]interface{}) (*Role, error) | ||
| 39 | + Find(queryOptions map[string]interface{}) (int64, []*Role, error) | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func (role *Role) Identify() interface{} { | ||
| 43 | + if role.RoleId == 0 { | ||
| 44 | + return nil | ||
| 45 | + } | ||
| 46 | + return role.RoleId | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +func (role *Role) Update(data map[string]interface{}) error { | ||
| 50 | + if companyId, ok := data["companyId"]; ok { | ||
| 51 | + role.CompanyId = companyId.(int64) | ||
| 52 | + } | ||
| 53 | + if orgId, ok := data["orgId"]; ok { | ||
| 54 | + role.OrgId = orgId.(int64) | ||
| 55 | + } | ||
| 56 | + if roleType, ok := data["roleType"]; ok { | ||
| 57 | + role.RoleType = roleType.(int) | ||
| 58 | + } | ||
| 59 | + if roleName, ok := data["roleName"]; ok { | ||
| 60 | + role.RoleName = roleName.(string) | ||
| 61 | + } | ||
| 62 | + if accessMenus, ok := data["accessMenus"]; ok { | ||
| 63 | + role.AccessMenus = accessMenus.([]int64) | ||
| 64 | + } | ||
| 65 | + if desc, ok := data["desc"]; ok { | ||
| 66 | + role.Desc = desc.(int64) | ||
| 67 | + } | ||
| 68 | + if usersName, ok := data["usersName"]; ok { | ||
| 69 | + role.Ext.UsersName = usersName.(string) | ||
| 70 | + } | ||
| 71 | + if orgName, ok := data["orgName"]; ok { | ||
| 72 | + role.Ext.OrgName = orgName.(string) | ||
| 73 | + } | ||
| 74 | + if phone, ok := data["phone"]; ok { | ||
| 75 | + role.Ext.Phone = phone.(string) | ||
| 76 | + } | ||
| 77 | + if depName, ok := data["depName"]; ok { | ||
| 78 | + role.Ext.DepName = depName.(string) | ||
| 79 | + } | ||
| 80 | + if parentDepName, ok := data["parentDepName"]; ok { | ||
| 81 | + role.Ext.ParentDepName = parentDepName.(string) | ||
| 82 | + } | ||
| 83 | + if createdAt, ok := data["createdAt"]; ok { | ||
| 84 | + role.CreatedAt = createdAt.(time.Time) | ||
| 85 | + } | ||
| 86 | + if updatedAt, ok := data["updatedAt"]; ok { | ||
| 87 | + role.UpdatedAt = updatedAt.(time.Time) | ||
| 88 | + } | ||
| 89 | + return nil | ||
| 90 | +} |
pkg/domain/users.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 用户类型 | ||
| 6 | +const ( | ||
| 7 | + UsersTypeEmployee = 1 | ||
| 8 | + UsersTypeCooperation = 2 | ||
| 9 | + UsersTypeCompanyAdmin = 1024 | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +// 用户状态 | ||
| 13 | +const ( | ||
| 14 | + UserStatusEnable UsersStatus = 1 | ||
| 15 | + UserStatusDisable UsersStatus = 2 | ||
| 16 | + UserStatusDestroy UsersStatus = 3 | ||
| 17 | +) | ||
| 18 | + | ||
| 19 | +// 用户 | ||
| 20 | +type Users struct { | ||
| 21 | + // 用户Id 用户唯一标识 | ||
| 22 | + UsersId int64 `json:"usersId,omitempty"` | ||
| 23 | + // 企业id | ||
| 24 | + CompanyId int64 `json:"companyId,omitempty"` | ||
| 25 | + // 用户基础数据id | ||
| 26 | + UsersBaseId int64 `json:"usersBaseId,omitempty"` | ||
| 27 | + // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | ||
| 28 | + UsersType int `json:"usersType,omitempty"` | ||
| 29 | + // 用户编号 企业内标识 | ||
| 30 | + UsersCode string `json:"usersCode,omitempty"` | ||
| 31 | + // 组织机构 | ||
| 32 | + OrganizationId int64 `json:"organizationId,omitempty"` | ||
| 33 | + // 所属部门 | ||
| 34 | + DepartmentId int64 `json:"departmentId,omitempty"` | ||
| 35 | + // 用户信息 (冗余,数据存在usersBase里面) | ||
| 36 | + UsersInfo *UsersInfo `json:"usersInfo,omitempty"` | ||
| 37 | + // 用户关联的组织 | ||
| 38 | + UsersOrg []*Org `json:"usersOrg,omitempty"` | ||
| 39 | + // 用户关联的角色 | ||
| 40 | + UsersRole []*Role `json:"usersRole,omitempty"` | ||
| 41 | + // 收藏的菜单(工作台)(菜单编码列表) | ||
| 42 | + FavoriteMenus []string `json:"favoriteMenus,omitempty"` | ||
| 43 | + // 共创信息 (共创用户有效) | ||
| 44 | + CooperationInfo *CooperationInfo `json:"cooperationInfo,omitempty"` | ||
| 45 | + // 状态(1:启用 2:禁用 3:注销) | ||
| 46 | + EnableStatus int `json:"enableStatus,omitempty"` | ||
| 47 | + // 扩展数据 | ||
| 48 | + Ext *Ext `json:"ext,omitempty"` | ||
| 49 | + // 创建时间 | ||
| 50 | + CreatedAt time.Time `json:"createdAt,omitempty"` | ||
| 51 | + // 更新时间 | ||
| 52 | + UpdatedAt time.Time `json:"updatedAt,omitempty"` | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +type UsersRepository interface { | ||
| 56 | + Save(users *Users) (*Users, error) | ||
| 57 | + Remove(users *Users) (*Users, error) | ||
| 58 | + FindOne(queryOptions map[string]interface{}) (*Users, error) | ||
| 59 | + Find(queryOptions map[string]interface{}) (int64, []*Users, error) | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +func (users *Users) Identify() interface{} { | ||
| 63 | + if users.UsersId == 0 { | ||
| 64 | + return nil | ||
| 65 | + } | ||
| 66 | + return users.UsersId | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +func (users *Users) Update(data map[string]interface{}) error { | ||
| 70 | + if usersId, ok := data["usersId"]; ok { | ||
| 71 | + users.UsersId = usersId.(int64) | ||
| 72 | + } | ||
| 73 | + if companyId, ok := data["companyId"]; ok { | ||
| 74 | + users.CompanyId = companyId.(int64) | ||
| 75 | + } | ||
| 76 | + if usersBaseId, ok := data["usersBaseId"]; ok { | ||
| 77 | + users.UsersBaseId = usersBaseId.(int64) | ||
| 78 | + } | ||
| 79 | + if usersType, ok := data["usersType"]; ok { | ||
| 80 | + users.UsersType = usersType.(int) | ||
| 81 | + } | ||
| 82 | + if usersCode, ok := data["usersCode"]; ok { | ||
| 83 | + users.UsersCode = usersCode.(string) | ||
| 84 | + } | ||
| 85 | + if organizationId, ok := data["organizationId"]; ok { | ||
| 86 | + users.OrganizationId = organizationId.(int64) | ||
| 87 | + } | ||
| 88 | + if departmentId, ok := data["departmentId"]; ok { | ||
| 89 | + users.DepartmentId = departmentId.(int64) | ||
| 90 | + } | ||
| 91 | + if usersName, ok := data["usersName"]; ok { | ||
| 92 | + users.UsersInfo.UsersName = usersName.(string) | ||
| 93 | + } | ||
| 94 | + if phone, ok := data["phone"]; ok { | ||
| 95 | + users.UsersInfo.Phone = phone.(string) | ||
| 96 | + } | ||
| 97 | + if avatar, ok := data["avatar"]; ok { | ||
| 98 | + users.UsersInfo.Avatar = avatar.(string) | ||
| 99 | + } | ||
| 100 | + if email, ok := data["email"]; ok { | ||
| 101 | + users.UsersInfo.Email = email.(string) | ||
| 102 | + } | ||
| 103 | + if usersOrg, ok := data["usersOrg"]; ok { | ||
| 104 | + users.UsersOrg = usersOrg.([]*Org) | ||
| 105 | + } | ||
| 106 | + if usersRole, ok := data["usersRole"]; ok { | ||
| 107 | + users.UsersRole = usersRole.([]*Role) | ||
| 108 | + } | ||
| 109 | + if favoriteMenus, ok := data["favoriteMenus"]; ok { | ||
| 110 | + users.FavoriteMenus = favoriteMenus.([]string) | ||
| 111 | + } | ||
| 112 | + if cooperationCompany, ok := data["cooperationCompany"]; ok { | ||
| 113 | + users.CooperationInfo.CooperationCompany = cooperationCompany.(string) | ||
| 114 | + } | ||
| 115 | + if cooperationDeadline, ok := data["cooperationDeadline"]; ok { | ||
| 116 | + users.CooperationInfo.CooperationDeadline = cooperationDeadline.(time.Time) | ||
| 117 | + } | ||
| 118 | + if enableStatus, ok := data["enableStatus"]; ok { | ||
| 119 | + users.EnableStatus = enableStatus.(int) | ||
| 120 | + } | ||
| 121 | + if usersName, ok := data["usersName"]; ok { | ||
| 122 | + users.Ext.UsersName = usersName.(string) | ||
| 123 | + } | ||
| 124 | + if orgName, ok := data["orgName"]; ok { | ||
| 125 | + users.Ext.OrgName = orgName.(string) | ||
| 126 | + } | ||
| 127 | + if phone, ok := data["phone"]; ok { | ||
| 128 | + users.Ext.Phone = phone.(string) | ||
| 129 | + } | ||
| 130 | + if depName, ok := data["depName"]; ok { | ||
| 131 | + users.Ext.DepName = depName.(string) | ||
| 132 | + } | ||
| 133 | + if parentDepName, ok := data["parentDepName"]; ok { | ||
| 134 | + users.Ext.ParentDepName = parentDepName.(string) | ||
| 135 | + } | ||
| 136 | + if createdAt, ok := data["createdAt"]; ok { | ||
| 137 | + users.CreatedAt = createdAt.(time.Time) | ||
| 138 | + } | ||
| 139 | + if updatedAt, ok := data["updatedAt"]; ok { | ||
| 140 | + users.UpdatedAt = updatedAt.(time.Time) | ||
| 141 | + } | ||
| 142 | + return nil | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +type UsersStatus int |
pkg/domain/users_base.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +// 用户基础 | ||
| 6 | +type UsersBase struct { | ||
| 7 | + // 用户基础数据id | ||
| 8 | + UsersBaseId int64 `json:"usersBaseId,omitempty"` | ||
| 9 | + // 用户信息 | ||
| 10 | + UsersInfo *UsersInfo `json:"usersInfo,omitempty"` | ||
| 11 | + // 手机号码 | ||
| 12 | + Phone string `json:"phone,omitempty"` | ||
| 13 | + // 密码 | ||
| 14 | + Password string `json:"password,omitempty"` | ||
| 15 | + // IM信息 | ||
| 16 | + Im *Im `json:"im,omitempty"` | ||
| 17 | + // 关联的用户 (冗余) | ||
| 18 | + RelatedUsers []int64 `json:"relatedUsers,omitempty"` | ||
| 19 | + // 账号状态 1:正常 2.禁用 3:注销 | ||
| 20 | + Status int `json:"status,omitempty"` | ||
| 21 | + // 创建时间 | ||
| 22 | + CreatedAt time.Time `json:"createdAt,omitempty"` | ||
| 23 | + // 更新时间 | ||
| 24 | + UpdatedAt time.Time `json:"updatedAt,omitempty"` | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +type UsersBaseRepository interface { | ||
| 28 | + Save(usersBase *UsersBase) (*UsersBase, error) | ||
| 29 | + Remove(usersBase *UsersBase) (*UsersBase, error) | ||
| 30 | + FindOne(queryOptions map[string]interface{}) (*UsersBase, error) | ||
| 31 | + Find(queryOptions map[string]interface{}) (int64, []*UsersBase, error) | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +func (usersBase *UsersBase) Identify() interface{} { | ||
| 35 | + if usersBase.UsersBaseId == 0 { | ||
| 36 | + return nil | ||
| 37 | + } | ||
| 38 | + return usersBase.UsersBaseId | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +func (usersBase *UsersBase) Update(data map[string]interface{}) error { | ||
| 42 | + if usersName, ok := data["usersName"]; ok { | ||
| 43 | + usersBase.UsersInfo.UsersName = usersName.(string) | ||
| 44 | + } | ||
| 45 | + if phone, ok := data["phone"]; ok { | ||
| 46 | + usersBase.UsersInfo.Phone = phone.(string) | ||
| 47 | + } | ||
| 48 | + if avatar, ok := data["avatar"]; ok { | ||
| 49 | + usersBase.UsersInfo.Avatar = avatar.(string) | ||
| 50 | + } | ||
| 51 | + if email, ok := data["email"]; ok { | ||
| 52 | + usersBase.UsersInfo.Email = email.(string) | ||
| 53 | + } | ||
| 54 | + if phone, ok := data["phone"]; ok { | ||
| 55 | + usersBase.Phone = phone.(string) | ||
| 56 | + } | ||
| 57 | + if password, ok := data["password"]; ok { | ||
| 58 | + usersBase.Password = password.(string) | ||
| 59 | + } | ||
| 60 | + if accid, ok := data["accid"]; ok { | ||
| 61 | + usersBase.Im.Accid = accid.(string) | ||
| 62 | + } | ||
| 63 | + if imToken, ok := data["imToken"]; ok { | ||
| 64 | + usersBase.Im.ImToken = imToken.(string) | ||
| 65 | + } | ||
| 66 | + if csAccountId, ok := data["csAccountId"]; ok { | ||
| 67 | + usersBase.Im.CsAccountId = csAccountId.(string) | ||
| 68 | + } | ||
| 69 | + if relatedUsers, ok := data["relatedUsers"]; ok { | ||
| 70 | + usersBase.RelatedUsers = relatedUsers.([]int64) | ||
| 71 | + } | ||
| 72 | + if status, ok := data["status"]; ok { | ||
| 73 | + usersBase.Status = status.(int) | ||
| 74 | + } | ||
| 75 | + if createdAt, ok := data["createdAt"]; ok { | ||
| 76 | + usersBase.CreatedAt = createdAt.(time.Time) | ||
| 77 | + } | ||
| 78 | + if updatedAt, ok := data["updatedAt"]; ok { | ||
| 79 | + usersBase.UpdatedAt = updatedAt.(time.Time) | ||
| 80 | + } | ||
| 81 | + return nil | ||
| 82 | +} |
pkg/domain/users_info.go
0 → 100644
pkg/infrastructure/pg/models/company.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type Company struct { | ||
| 9 | + tableName string `pg:"users.company,alias:company"` | ||
| 10 | + // 企业id | ||
| 11 | + CompanyId int64 | ||
| 12 | + // 企业配置信息 | ||
| 13 | + CompanyConfig *domain.CompanyConfig | ||
| 14 | + // 企业基本信息 | ||
| 15 | + CompanyInfo *domain.CompanyInfo | ||
| 16 | + // 公司状态 | ||
| 17 | + Status int | ||
| 18 | + // 创建时间 | ||
| 19 | + CreatedAt time.Time | ||
| 20 | + // 更新时间 | ||
| 21 | + UpdatedAt time.Time | ||
| 22 | +} |
| @@ -24,8 +24,8 @@ type Menu struct { | @@ -24,8 +24,8 @@ type Menu struct { | ||
| 24 | Category string | 24 | Category string |
| 25 | // 父级节点路径("0,11,12,") | 25 | // 父级节点路径("0,11,12,") |
| 26 | ParentPath string | 26 | ParentPath string |
| 27 | - // 菜单是否公开状态,[0:隐藏],[1:显示],默认显示 | 27 | + // 菜单是否公开状态,[2:隐藏],[1:显示],默认显示 |
| 28 | IsPublish int | 28 | IsPublish int |
| 29 | - // 启用状态(启用:1 禁用:0),默认启用 | 29 | + // 启用状态(启用:1 禁用:2),默认启用 |
| 30 | EnableStatus int | 30 | EnableStatus int |
| 31 | } | 31 | } |
pkg/infrastructure/pg/models/org.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type Org struct { | ||
| 9 | + tableName string `pg:"users.org,alias:org"` | ||
| 10 | + // 组织ID | ||
| 11 | + OrgId int64 | ||
| 12 | + // 企业id | ||
| 13 | + CompanyId int64 | ||
| 14 | + // 创建时间 | ||
| 15 | + CreatedAt time.Time | ||
| 16 | + // 更新时间 | ||
| 17 | + UpdatedAt time.Time | ||
| 18 | + // 删除时间 | ||
| 19 | + DeletedAt time.Time | ||
| 20 | + // 组织编码 | ||
| 21 | + OrgCode string | ||
| 22 | + // 组织名称 | ||
| 23 | + OrgName string | ||
| 24 | + // 扩展数据 | ||
| 25 | + Ext *domain.Ext | ||
| 26 | + // 是否是组织标识 1:是 2:不是 | ||
| 27 | + IsOrg int | ||
| 28 | + // 组织状态 1:启用 2:禁用 3.删除 | ||
| 29 | + OrgStatus int `json:"orgStatus"` | ||
| 30 | + // 父级ID | ||
| 31 | + ParentId int64 | ||
| 32 | + // 父级节点路径("0,11,12,") | ||
| 33 | + ParentPath string | ||
| 34 | +} |
pkg/infrastructure/pg/models/role.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type Role struct { | ||
| 9 | + tableName string `pg:"users.role,alias:role"` | ||
| 10 | + // 角色ID | ||
| 11 | + RoleId int64 | ||
| 12 | + // 企业id | ||
| 13 | + CompanyId int64 | ||
| 14 | + // 组织ID | ||
| 15 | + OrgId int64 | ||
| 16 | + // 角色类型 1.普通角色 1024:超级管理员 | ||
| 17 | + RoleType int | ||
| 18 | + // 角色名称 | ||
| 19 | + RoleName string | ||
| 20 | + // 有权限的菜单 | ||
| 21 | + AccessMenus []int64 `pg:",array"` | ||
| 22 | + // 描述 | ||
| 23 | + Desc int64 | ||
| 24 | + // 扩展数据 | ||
| 25 | + Ext *domain.Ext | ||
| 26 | + // 创建时间 | ||
| 27 | + CreatedAt time.Time | ||
| 28 | + // 更新时间 | ||
| 29 | + UpdatedAt time.Time | ||
| 30 | +} |
pkg/infrastructure/pg/models/users.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type Users struct { | ||
| 9 | + tableName string `pg:"users.users,alias:users"` | ||
| 10 | + // 用户Id 用户唯一标识 | ||
| 11 | + UsersId int64 | ||
| 12 | + // 企业id | ||
| 13 | + CompanyId int64 | ||
| 14 | + // 用户基础数据id | ||
| 15 | + UsersBaseId int64 | ||
| 16 | + // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | ||
| 17 | + UsersType int | ||
| 18 | + // 用户编号 企业内标识 | ||
| 19 | + UsersCode string | ||
| 20 | + // 组织机构 | ||
| 21 | + OrganizationId int64 | ||
| 22 | + // 所属部门 | ||
| 23 | + DepartmentId int64 | ||
| 24 | + // 用户信息 (冗余,数据存在usersBase里面) | ||
| 25 | + //UsersInfo *domain.UsersInfo | ||
| 26 | + // 用户关联的组织 | ||
| 27 | + UsersOrg []*domain.Org `pg:",array"` | ||
| 28 | + // 用户关联的角色 | ||
| 29 | + UsersRole []*domain.Role `pg:",array"` | ||
| 30 | + // 收藏的菜单(工作台)(菜单编码列表) | ||
| 31 | + FavoriteMenus []string `pg:",array"` | ||
| 32 | + // 共创信息 (共创用户有效) | ||
| 33 | + CooperationInfo *domain.CooperationInfo | ||
| 34 | + // 状态(1:启用 2:禁用 3:注销) | ||
| 35 | + EnableStatus int | ||
| 36 | + // 扩展数据 | ||
| 37 | + Ext *domain.Ext | ||
| 38 | + // 创建时间 | ||
| 39 | + CreatedAt time.Time | ||
| 40 | + // 更新时间 | ||
| 41 | + UpdatedAt time.Time | ||
| 42 | +} |
pkg/infrastructure/pg/models/users_base.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type UsersBase struct { | ||
| 9 | + tableName string `pg:"users.users_base,alias:users_base"` | ||
| 10 | + // 用户基础数据id | ||
| 11 | + UsersBaseId int64 | ||
| 12 | + // 用户信息 | ||
| 13 | + UsersInfo *domain.UsersInfo | ||
| 14 | + // 手机号码 | ||
| 15 | + Phone string | ||
| 16 | + // 密码 | ||
| 17 | + Password string | ||
| 18 | + // IM信息 | ||
| 19 | + Im *domain.Im | ||
| 20 | + // 关联的用户 (冗余) | ||
| 21 | + RelatedUsers []int64 `pg:",array"` | ||
| 22 | + // 账号状态 1:正常 2.禁用 3:注销 | ||
| 23 | + Status int | ||
| 24 | + // 创建时间 | ||
| 25 | + CreatedAt time.Time | ||
| 26 | + // 更新时间 | ||
| 27 | + UpdatedAt time.Time | ||
| 28 | +} |
pkg/infrastructure/pg/transform/company.go
0 → 100644
| 1 | +package transform | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TransformToCompanyDomainModelFromPgModels(companyModel *models.Company) (*domain.Company, error) { | ||
| 9 | + return &domain.Company{ | ||
| 10 | + CompanyId: companyModel.CompanyId, | ||
| 11 | + CompanyConfig: companyModel.CompanyConfig, | ||
| 12 | + CompanyInfo: companyModel.CompanyInfo, | ||
| 13 | + Status: companyModel.Status, | ||
| 14 | + CreatedAt: companyModel.CreatedAt, | ||
| 15 | + UpdatedAt: companyModel.UpdatedAt, | ||
| 16 | + }, nil | ||
| 17 | +} |
pkg/infrastructure/pg/transform/org.go
0 → 100644
| 1 | +package transform | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TransformToOrgDomainModelFromPgModels(orgModel *models.Org) (*domain.Org, error) { | ||
| 9 | + return &domain.Org{ | ||
| 10 | + OrgId: orgModel.OrgId, | ||
| 11 | + CompanyId: orgModel.CompanyId, | ||
| 12 | + CreatedAt: orgModel.CreatedAt, | ||
| 13 | + UpdatedAt: orgModel.UpdatedAt, | ||
| 14 | + DeletedAt: orgModel.DeletedAt, | ||
| 15 | + OrgCode: orgModel.OrgCode, | ||
| 16 | + OrgName: orgModel.OrgName, | ||
| 17 | + Ext: orgModel.Ext, | ||
| 18 | + IsOrg: orgModel.IsOrg, | ||
| 19 | + ParentId: orgModel.ParentId, | ||
| 20 | + ParentPath: orgModel.ParentPath, | ||
| 21 | + }, nil | ||
| 22 | +} |
pkg/infrastructure/pg/transform/role.go
0 → 100644
| 1 | +package transform | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TransformToRoleDomainModelFromPgModels(roleModel *models.Role) (*domain.Role, error) { | ||
| 9 | + return &domain.Role{ | ||
| 10 | + RoleId: roleModel.RoleId, | ||
| 11 | + CompanyId: roleModel.CompanyId, | ||
| 12 | + OrgId: roleModel.OrgId, | ||
| 13 | + RoleType: roleModel.RoleType, | ||
| 14 | + RoleName: roleModel.RoleName, | ||
| 15 | + AccessMenus: roleModel.AccessMenus, | ||
| 16 | + Desc: roleModel.Desc, | ||
| 17 | + Ext: roleModel.Ext, | ||
| 18 | + CreatedAt: roleModel.CreatedAt, | ||
| 19 | + UpdatedAt: roleModel.UpdatedAt, | ||
| 20 | + }, nil | ||
| 21 | +} |
pkg/infrastructure/pg/transform/users.go
0 → 100644
| 1 | +package transform | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TransformToUsersDomainModelFromPgModels(usersModel *models.Users) (*domain.Users, error) { | ||
| 9 | + return &domain.Users{ | ||
| 10 | + UsersId: usersModel.UsersId, | ||
| 11 | + CompanyId: usersModel.CompanyId, | ||
| 12 | + UsersBaseId: usersModel.UsersBaseId, | ||
| 13 | + UsersType: usersModel.UsersType, | ||
| 14 | + UsersCode: usersModel.UsersCode, | ||
| 15 | + OrganizationId: usersModel.OrganizationId, | ||
| 16 | + DepartmentId: usersModel.DepartmentId, | ||
| 17 | + //UsersInfo: usersModel.UsersInfo, | ||
| 18 | + UsersOrg: usersModel.UsersOrg, | ||
| 19 | + UsersRole: usersModel.UsersRole, | ||
| 20 | + FavoriteMenus: usersModel.FavoriteMenus, | ||
| 21 | + CooperationInfo: usersModel.CooperationInfo, | ||
| 22 | + EnableStatus: usersModel.EnableStatus, | ||
| 23 | + Ext: usersModel.Ext, | ||
| 24 | + CreatedAt: usersModel.CreatedAt, | ||
| 25 | + UpdatedAt: usersModel.UpdatedAt, | ||
| 26 | + }, nil | ||
| 27 | +} |
| 1 | +package transform | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TransformToUsersBaseDomainModelFromPgModels(usersBaseModel *models.UsersBase) (*domain.UsersBase, error) { | ||
| 9 | + return &domain.UsersBase{ | ||
| 10 | + UsersBaseId: usersBaseModel.UsersBaseId, | ||
| 11 | + UsersInfo: usersBaseModel.UsersInfo, | ||
| 12 | + Phone: usersBaseModel.Phone, | ||
| 13 | + Password: usersBaseModel.Password, | ||
| 14 | + Im: usersBaseModel.Im, | ||
| 15 | + RelatedUsers: usersBaseModel.RelatedUsers, | ||
| 16 | + Status: usersBaseModel.Status, | ||
| 17 | + CreatedAt: usersBaseModel.CreatedAt, | ||
| 18 | + UpdatedAt: usersBaseModel.UpdatedAt, | ||
| 19 | + }, nil | ||
| 20 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + | ||
| 7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/transform" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type CompanyRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *CompanyRepository) nextIdentify() (int64, error) { | ||
| 20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | + if err != nil { | ||
| 22 | + return 0, err | ||
| 23 | + } | ||
| 24 | + id, err := IdWorker.NextId() | ||
| 25 | + return id, err | ||
| 26 | +} | ||
| 27 | +func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Company, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "company_id", | ||
| 30 | + "company_config", | ||
| 31 | + "company_info", | ||
| 32 | + "status", | ||
| 33 | + "created_at", | ||
| 34 | + "updated_at", | ||
| 35 | + } | ||
| 36 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 37 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
| 38 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 39 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "company_id") | ||
| 40 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 41 | + tx := repository.transactionContext.PgTx | ||
| 42 | + if company.Identify() == nil { | ||
| 43 | + companyId, err := repository.nextIdentify() | ||
| 44 | + if err != nil { | ||
| 45 | + return company, err | ||
| 46 | + } else { | ||
| 47 | + company.CompanyId = companyId | ||
| 48 | + } | ||
| 49 | + if _, err := tx.QueryOne( | ||
| 50 | + pg.Scan( | ||
| 51 | + &company.CompanyId, | ||
| 52 | + &company.CompanyConfig, | ||
| 53 | + &company.CompanyInfo, | ||
| 54 | + &company.Status, | ||
| 55 | + &company.CreatedAt, | ||
| 56 | + &company.UpdatedAt, | ||
| 57 | + ), | ||
| 58 | + fmt.Sprintf("INSERT INTO companys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 59 | + company.CompanyId, | ||
| 60 | + company.CompanyConfig, | ||
| 61 | + company.CompanyInfo, | ||
| 62 | + company.Status, | ||
| 63 | + company.CreatedAt, | ||
| 64 | + company.UpdatedAt, | ||
| 65 | + ); err != nil { | ||
| 66 | + return company, err | ||
| 67 | + } | ||
| 68 | + } else { | ||
| 69 | + if _, err := tx.QueryOne( | ||
| 70 | + pg.Scan( | ||
| 71 | + &company.CompanyConfig, | ||
| 72 | + &company.CompanyInfo, | ||
| 73 | + &company.Status, | ||
| 74 | + &company.CreatedAt, | ||
| 75 | + &company.UpdatedAt, | ||
| 76 | + ), | ||
| 77 | + fmt.Sprintf("UPDATE companys SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 78 | + company.CompanyConfig, | ||
| 79 | + company.CompanyInfo, | ||
| 80 | + company.Status, | ||
| 81 | + company.CreatedAt, | ||
| 82 | + company.UpdatedAt, | ||
| 83 | + company.Identify(), | ||
| 84 | + ); err != nil { | ||
| 85 | + return company, err | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + return company, nil | ||
| 89 | +} | ||
| 90 | +func (repository *CompanyRepository) Remove(company *domain.Company) (*domain.Company, error) { | ||
| 91 | + tx := repository.transactionContext.PgTx | ||
| 92 | + companyModel := new(models.Company) | ||
| 93 | + companyModel.CompanyId = company.Identify().(int64) | ||
| 94 | + if _, err := tx.Model(companyModel).WherePK().Delete(); err != nil { | ||
| 95 | + return company, err | ||
| 96 | + } | ||
| 97 | + return company, nil | ||
| 98 | +} | ||
| 99 | +func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}) (*domain.Company, error) { | ||
| 100 | + tx := repository.transactionContext.PgTx | ||
| 101 | + companyModel := new(models.Company) | ||
| 102 | + query := sqlbuilder.BuildQuery(tx.Model(companyModel), queryOptions) | ||
| 103 | + query.SetWhereByQueryOption("company.company_id = ?", "companyId") | ||
| 104 | + if err := query.First(); err != nil { | ||
| 105 | + if err.Error() == "pg: no rows in result set" { | ||
| 106 | + return nil, fmt.Errorf("没有此资源") | ||
| 107 | + } else { | ||
| 108 | + return nil, err | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + if companyModel.CompanyId == 0 { | ||
| 112 | + return nil, nil | ||
| 113 | + } else { | ||
| 114 | + return transform.TransformToCompanyDomainModelFromPgModels(companyModel) | ||
| 115 | + } | ||
| 116 | +} | ||
| 117 | +func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) { | ||
| 118 | + tx := repository.transactionContext.PgTx | ||
| 119 | + var companyModels []*models.Company | ||
| 120 | + companys := make([]*domain.Company, 0) | ||
| 121 | + query := sqlbuilder.BuildQuery(tx.Model(&companyModels), queryOptions) | ||
| 122 | + query.SetOffsetAndLimit(20) | ||
| 123 | + query.SetOrderDirect("company_id", "DESC") | ||
| 124 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 125 | + return 0, companys, err | ||
| 126 | + } else { | ||
| 127 | + for _, companyModel := range companyModels { | ||
| 128 | + if company, err := transform.TransformToCompanyDomainModelFromPgModels(companyModel); err != nil { | ||
| 129 | + return 0, companys, err | ||
| 130 | + } else { | ||
| 131 | + companys = append(companys, company) | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + return int64(count), companys, nil | ||
| 135 | + } | ||
| 136 | +} | ||
| 137 | +func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext) (*CompanyRepository, error) { | ||
| 138 | + if transactionContext == nil { | ||
| 139 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 140 | + } else { | ||
| 141 | + return &CompanyRepository{ | ||
| 142 | + transactionContext: transactionContext, | ||
| 143 | + }, nil | ||
| 144 | + } | ||
| 145 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + | ||
| 7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/transform" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type OrgRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *OrgRepository) nextIdentify() (int64, error) { | ||
| 20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | + if err != nil { | ||
| 22 | + return 0, err | ||
| 23 | + } | ||
| 24 | + id, err := IdWorker.NextId() | ||
| 25 | + return id, err | ||
| 26 | +} | ||
| 27 | +func (repository *OrgRepository) Save(org *domain.Org) (*domain.Org, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "org_id", | ||
| 30 | + "company_id", | ||
| 31 | + "created_at", | ||
| 32 | + "updated_at", | ||
| 33 | + "deleted_at", | ||
| 34 | + "org_code", | ||
| 35 | + "org_name", | ||
| 36 | + "ext", | ||
| 37 | + "org_status", | ||
| 38 | + "is_org", | ||
| 39 | + "parent_id", | ||
| 40 | + "parent_path", | ||
| 41 | + } | ||
| 42 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 43 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
| 44 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 45 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "org_id") | ||
| 46 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 47 | + tx := repository.transactionContext.PgTx | ||
| 48 | + if org.Identify() == nil { | ||
| 49 | + orgId, err := repository.nextIdentify() | ||
| 50 | + if err != nil { | ||
| 51 | + return org, err | ||
| 52 | + } else { | ||
| 53 | + org.OrgId = orgId | ||
| 54 | + } | ||
| 55 | + if _, err := tx.QueryOne( | ||
| 56 | + pg.Scan( | ||
| 57 | + &org.OrgId, | ||
| 58 | + &org.CompanyId, | ||
| 59 | + &org.CreatedAt, | ||
| 60 | + &org.UpdatedAt, | ||
| 61 | + &org.DeletedAt, | ||
| 62 | + &org.OrgCode, | ||
| 63 | + &org.OrgName, | ||
| 64 | + &org.Ext, | ||
| 65 | + &org.OrgStatus, | ||
| 66 | + &org.IsOrg, | ||
| 67 | + &org.ParentId, | ||
| 68 | + &org.ParentPath, | ||
| 69 | + ), | ||
| 70 | + fmt.Sprintf("INSERT INTO orgs (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 71 | + org.OrgId, | ||
| 72 | + org.CompanyId, | ||
| 73 | + org.CreatedAt, | ||
| 74 | + org.UpdatedAt, | ||
| 75 | + org.DeletedAt, | ||
| 76 | + org.OrgCode, | ||
| 77 | + org.OrgName, | ||
| 78 | + org.Ext, | ||
| 79 | + &org.OrgStatus, | ||
| 80 | + org.IsOrg, | ||
| 81 | + org.ParentId, | ||
| 82 | + org.ParentPath, | ||
| 83 | + ); err != nil { | ||
| 84 | + return org, err | ||
| 85 | + } | ||
| 86 | + } else { | ||
| 87 | + if _, err := tx.QueryOne( | ||
| 88 | + pg.Scan( | ||
| 89 | + &org.OrgId, | ||
| 90 | + &org.CompanyId, | ||
| 91 | + &org.CreatedAt, | ||
| 92 | + &org.UpdatedAt, | ||
| 93 | + &org.DeletedAt, | ||
| 94 | + &org.OrgCode, | ||
| 95 | + &org.OrgName, | ||
| 96 | + &org.Ext, | ||
| 97 | + &org.IsOrg, | ||
| 98 | + &org.ParentId, | ||
| 99 | + &org.ParentPath, | ||
| 100 | + ), | ||
| 101 | + fmt.Sprintf("UPDATE orgs SET %s WHERE org_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 102 | + org.CompanyId, | ||
| 103 | + org.CreatedAt, | ||
| 104 | + org.UpdatedAt, | ||
| 105 | + org.DeletedAt, | ||
| 106 | + org.OrgCode, | ||
| 107 | + org.OrgName, | ||
| 108 | + org.Ext, | ||
| 109 | + org.IsOrg, | ||
| 110 | + org.ParentId, | ||
| 111 | + org.ParentPath, | ||
| 112 | + org.Identify(), | ||
| 113 | + ); err != nil { | ||
| 114 | + return org, err | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + return org, nil | ||
| 118 | +} | ||
| 119 | +func (repository *OrgRepository) Remove(org *domain.Org) (*domain.Org, error) { | ||
| 120 | + tx := repository.transactionContext.PgTx | ||
| 121 | + orgModel := new(models.Org) | ||
| 122 | + orgModel.OrgId = org.Identify().(int64) | ||
| 123 | + if _, err := tx.Model(orgModel).WherePK().Delete(); err != nil { | ||
| 124 | + return org, err | ||
| 125 | + } | ||
| 126 | + return org, nil | ||
| 127 | +} | ||
| 128 | +func (repository *OrgRepository) FindOne(queryOptions map[string]interface{}) (*domain.Org, error) { | ||
| 129 | + tx := repository.transactionContext.PgTx | ||
| 130 | + orgModel := new(models.Org) | ||
| 131 | + query := sqlbuilder.BuildQuery(tx.Model(orgModel), queryOptions) | ||
| 132 | + query.SetWhereByQueryOption("org.org_id = ?", "orgId") | ||
| 133 | + if err := query.First(); err != nil { | ||
| 134 | + if err.Error() == "pg: no rows in result set" { | ||
| 135 | + return nil, fmt.Errorf("没有此资源") | ||
| 136 | + } else { | ||
| 137 | + return nil, err | ||
| 138 | + } | ||
| 139 | + } | ||
| 140 | + if orgModel.OrgId == 0 { | ||
| 141 | + return nil, nil | ||
| 142 | + } else { | ||
| 143 | + return transform.TransformToOrgDomainModelFromPgModels(orgModel) | ||
| 144 | + } | ||
| 145 | +} | ||
| 146 | +func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Org, error) { | ||
| 147 | + tx := repository.transactionContext.PgTx | ||
| 148 | + var orgModels []*models.Org | ||
| 149 | + orgs := make([]*domain.Org, 0) | ||
| 150 | + query := sqlbuilder.BuildQuery(tx.Model(&orgModels), queryOptions) | ||
| 151 | + query.SetOffsetAndLimit(20) | ||
| 152 | + query.SetOrderDirect("org_id", "DESC") | ||
| 153 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 154 | + return 0, orgs, err | ||
| 155 | + } else { | ||
| 156 | + for _, orgModel := range orgModels { | ||
| 157 | + if org, err := transform.TransformToOrgDomainModelFromPgModels(orgModel); err != nil { | ||
| 158 | + return 0, orgs, err | ||
| 159 | + } else { | ||
| 160 | + orgs = append(orgs, org) | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + return int64(count), orgs, nil | ||
| 164 | + } | ||
| 165 | +} | ||
| 166 | +func NewOrgRepository(transactionContext *pgTransaction.TransactionContext) (*OrgRepository, error) { | ||
| 167 | + if transactionContext == nil { | ||
| 168 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 169 | + } else { | ||
| 170 | + return &OrgRepository{ | ||
| 171 | + transactionContext: transactionContext, | ||
| 172 | + }, nil | ||
| 173 | + } | ||
| 174 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + | ||
| 7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/transform" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type RoleRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *RoleRepository) nextIdentify() (int64, error) { | ||
| 20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | + if err != nil { | ||
| 22 | + return 0, err | ||
| 23 | + } | ||
| 24 | + id, err := IdWorker.NextId() | ||
| 25 | + return id, err | ||
| 26 | +} | ||
| 27 | +func (repository *RoleRepository) Save(role *domain.Role) (*domain.Role, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "role_id", | ||
| 30 | + "company_id", | ||
| 31 | + "org_id", | ||
| 32 | + "role_type", | ||
| 33 | + "role_name", | ||
| 34 | + "access_menus", | ||
| 35 | + "desc", | ||
| 36 | + "ext", | ||
| 37 | + "created_at", | ||
| 38 | + "updated_at", | ||
| 39 | + } | ||
| 40 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 41 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
| 42 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 43 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "role_id") | ||
| 44 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 45 | + tx := repository.transactionContext.PgTx | ||
| 46 | + if role.Identify() == nil { | ||
| 47 | + roleId, err := repository.nextIdentify() | ||
| 48 | + if err != nil { | ||
| 49 | + return role, err | ||
| 50 | + } else { | ||
| 51 | + role.RoleId = roleId | ||
| 52 | + } | ||
| 53 | + if _, err := tx.QueryOne( | ||
| 54 | + pg.Scan( | ||
| 55 | + &role.RoleId, | ||
| 56 | + &role.CompanyId, | ||
| 57 | + &role.OrgId, | ||
| 58 | + &role.RoleType, | ||
| 59 | + &role.RoleName, | ||
| 60 | + pg.Array(&role.AccessMenus), | ||
| 61 | + &role.Desc, | ||
| 62 | + &role.Ext, | ||
| 63 | + &role.CreatedAt, | ||
| 64 | + &role.UpdatedAt, | ||
| 65 | + ), | ||
| 66 | + fmt.Sprintf("INSERT INTO roles (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 67 | + role.RoleId, | ||
| 68 | + role.CompanyId, | ||
| 69 | + role.OrgId, | ||
| 70 | + role.RoleType, | ||
| 71 | + role.RoleName, | ||
| 72 | + pg.Array(role.AccessMenus), | ||
| 73 | + role.Desc, | ||
| 74 | + role.Ext, | ||
| 75 | + role.CreatedAt, | ||
| 76 | + role.UpdatedAt, | ||
| 77 | + ); err != nil { | ||
| 78 | + return role, err | ||
| 79 | + } | ||
| 80 | + } else { | ||
| 81 | + if _, err := tx.QueryOne( | ||
| 82 | + pg.Scan( | ||
| 83 | + &role.RoleId, | ||
| 84 | + &role.CompanyId, | ||
| 85 | + &role.OrgId, | ||
| 86 | + &role.RoleType, | ||
| 87 | + &role.RoleName, | ||
| 88 | + pg.Array(&role.AccessMenus), | ||
| 89 | + &role.Desc, | ||
| 90 | + &role.Ext, | ||
| 91 | + &role.CreatedAt, | ||
| 92 | + &role.UpdatedAt, | ||
| 93 | + ), | ||
| 94 | + fmt.Sprintf("UPDATE roles SET %s WHERE role_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 95 | + role.CompanyId, | ||
| 96 | + role.OrgId, | ||
| 97 | + role.RoleType, | ||
| 98 | + role.RoleName, | ||
| 99 | + pg.Array(role.AccessMenus), | ||
| 100 | + role.Desc, | ||
| 101 | + role.Ext, | ||
| 102 | + role.CreatedAt, | ||
| 103 | + role.UpdatedAt, | ||
| 104 | + role.Identify(), | ||
| 105 | + ); err != nil { | ||
| 106 | + return role, err | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + return role, nil | ||
| 110 | +} | ||
| 111 | +func (repository *RoleRepository) Remove(role *domain.Role) (*domain.Role, error) { | ||
| 112 | + tx := repository.transactionContext.PgTx | ||
| 113 | + roleModel := new(models.Role) | ||
| 114 | + roleModel.RoleId = role.Identify().(int64) | ||
| 115 | + if _, err := tx.Model(roleModel).WherePK().Delete(); err != nil { | ||
| 116 | + return role, err | ||
| 117 | + } | ||
| 118 | + return role, nil | ||
| 119 | +} | ||
| 120 | +func (repository *RoleRepository) FindOne(queryOptions map[string]interface{}) (*domain.Role, error) { | ||
| 121 | + tx := repository.transactionContext.PgTx | ||
| 122 | + roleModel := new(models.Role) | ||
| 123 | + query := sqlbuilder.BuildQuery(tx.Model(roleModel), queryOptions) | ||
| 124 | + query.SetWhereByQueryOption("role.role_id = ?", "roleId") | ||
| 125 | + if err := query.First(); err != nil { | ||
| 126 | + if err.Error() == "pg: no rows in result set" { | ||
| 127 | + return nil, fmt.Errorf("没有此资源") | ||
| 128 | + } else { | ||
| 129 | + return nil, err | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + if roleModel.RoleId == 0 { | ||
| 133 | + return nil, nil | ||
| 134 | + } else { | ||
| 135 | + return transform.TransformToRoleDomainModelFromPgModels(roleModel) | ||
| 136 | + } | ||
| 137 | +} | ||
| 138 | +func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Role, error) { | ||
| 139 | + tx := repository.transactionContext.PgTx | ||
| 140 | + var roleModels []*models.Role | ||
| 141 | + roles := make([]*domain.Role, 0) | ||
| 142 | + query := sqlbuilder.BuildQuery(tx.Model(&roleModels), queryOptions) | ||
| 143 | + query.SetOffsetAndLimit(20) | ||
| 144 | + query.SetOrderDirect("role_id", "DESC") | ||
| 145 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 146 | + return 0, roles, err | ||
| 147 | + } else { | ||
| 148 | + for _, roleModel := range roleModels { | ||
| 149 | + if role, err := transform.TransformToRoleDomainModelFromPgModels(roleModel); err != nil { | ||
| 150 | + return 0, roles, err | ||
| 151 | + } else { | ||
| 152 | + roles = append(roles, role) | ||
| 153 | + } | ||
| 154 | + } | ||
| 155 | + return int64(count), roles, nil | ||
| 156 | + } | ||
| 157 | +} | ||
| 158 | +func NewRoleRepository(transactionContext *pgTransaction.TransactionContext) (*RoleRepository, error) { | ||
| 159 | + if transactionContext == nil { | ||
| 160 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 161 | + } else { | ||
| 162 | + return &RoleRepository{ | ||
| 163 | + transactionContext: transactionContext, | ||
| 164 | + }, nil | ||
| 165 | + } | ||
| 166 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + | ||
| 7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/transform" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type UsersBaseRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *UsersBaseRepository) nextIdentify() (int64, error) { | ||
| 20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | + if err != nil { | ||
| 22 | + return 0, err | ||
| 23 | + } | ||
| 24 | + id, err := IdWorker.NextId() | ||
| 25 | + return id, err | ||
| 26 | +} | ||
| 27 | +func (repository *UsersBaseRepository) Save(usersBase *domain.UsersBase) (*domain.UsersBase, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "users_base_id", | ||
| 30 | + "users_info", | ||
| 31 | + "phone", | ||
| 32 | + "password", | ||
| 33 | + "im", | ||
| 34 | + "related_users", | ||
| 35 | + "status", | ||
| 36 | + "created_at", | ||
| 37 | + "updated_at", | ||
| 38 | + } | ||
| 39 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 40 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
| 41 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 42 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "usersBase_id") | ||
| 43 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 44 | + tx := repository.transactionContext.PgTx | ||
| 45 | + if usersBase.Identify() == nil { | ||
| 46 | + usersBaseId, err := repository.nextIdentify() | ||
| 47 | + if err != nil { | ||
| 48 | + return usersBase, err | ||
| 49 | + } else { | ||
| 50 | + usersBase.UsersBaseId = usersBaseId | ||
| 51 | + } | ||
| 52 | + if _, err := tx.QueryOne( | ||
| 53 | + pg.Scan( | ||
| 54 | + &usersBase.UsersBaseId, | ||
| 55 | + &usersBase.UsersInfo, | ||
| 56 | + &usersBase.Phone, | ||
| 57 | + &usersBase.Password, | ||
| 58 | + &usersBase.Im, | ||
| 59 | + pg.Array(&usersBase.RelatedUsers), | ||
| 60 | + &usersBase.Status, | ||
| 61 | + &usersBase.CreatedAt, | ||
| 62 | + &usersBase.UpdatedAt, | ||
| 63 | + ), | ||
| 64 | + fmt.Sprintf("INSERT INTO users_bases (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 65 | + usersBase.UsersBaseId, | ||
| 66 | + usersBase.UsersInfo, | ||
| 67 | + usersBase.Phone, | ||
| 68 | + usersBase.Password, | ||
| 69 | + usersBase.Im, | ||
| 70 | + pg.Array(usersBase.RelatedUsers), | ||
| 71 | + usersBase.Status, | ||
| 72 | + usersBase.CreatedAt, | ||
| 73 | + usersBase.UpdatedAt, | ||
| 74 | + ); err != nil { | ||
| 75 | + return usersBase, err | ||
| 76 | + } | ||
| 77 | + } else { | ||
| 78 | + if _, err := tx.QueryOne( | ||
| 79 | + pg.Scan( | ||
| 80 | + &usersBase.UsersBaseId, | ||
| 81 | + &usersBase.UsersInfo, | ||
| 82 | + &usersBase.Phone, | ||
| 83 | + &usersBase.Password, | ||
| 84 | + &usersBase.Im, | ||
| 85 | + pg.Array(&usersBase.RelatedUsers), | ||
| 86 | + &usersBase.Status, | ||
| 87 | + &usersBase.CreatedAt, | ||
| 88 | + &usersBase.UpdatedAt, | ||
| 89 | + ), | ||
| 90 | + fmt.Sprintf("UPDATE users_bases SET %s WHERE users_base_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 91 | + usersBase.UsersInfo, | ||
| 92 | + usersBase.Phone, | ||
| 93 | + usersBase.Password, | ||
| 94 | + usersBase.Im, | ||
| 95 | + pg.Array(usersBase.RelatedUsers), | ||
| 96 | + usersBase.Status, | ||
| 97 | + usersBase.CreatedAt, | ||
| 98 | + usersBase.UpdatedAt, | ||
| 99 | + usersBase.Identify(), | ||
| 100 | + ); err != nil { | ||
| 101 | + return usersBase, err | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + return usersBase, nil | ||
| 105 | +} | ||
| 106 | +func (repository *UsersBaseRepository) Remove(usersBase *domain.UsersBase) (*domain.UsersBase, error) { | ||
| 107 | + tx := repository.transactionContext.PgTx | ||
| 108 | + usersBaseModel := new(models.UsersBase) | ||
| 109 | + usersBaseModel.UsersBaseId = usersBase.Identify().(int64) | ||
| 110 | + if _, err := tx.Model(usersBaseModel).WherePK().Delete(); err != nil { | ||
| 111 | + return usersBase, err | ||
| 112 | + } | ||
| 113 | + return usersBase, nil | ||
| 114 | +} | ||
| 115 | +func (repository *UsersBaseRepository) FindOne(queryOptions map[string]interface{}) (*domain.UsersBase, error) { | ||
| 116 | + tx := repository.transactionContext.PgTx | ||
| 117 | + usersBaseModel := new(models.UsersBase) | ||
| 118 | + query := sqlbuilder.BuildQuery(tx.Model(usersBaseModel), queryOptions) | ||
| 119 | + query.SetWhereByQueryOption("users_base.users_base_id = ?", "usersBaseId") | ||
| 120 | + if err := query.First(); err != nil { | ||
| 121 | + if err.Error() == "pg: no rows in result set" { | ||
| 122 | + return nil, fmt.Errorf("没有此资源") | ||
| 123 | + } else { | ||
| 124 | + return nil, err | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + if usersBaseModel.UsersBaseId == 0 { | ||
| 128 | + return nil, nil | ||
| 129 | + } else { | ||
| 130 | + return transform.TransformToUsersBaseDomainModelFromPgModels(usersBaseModel) | ||
| 131 | + } | ||
| 132 | +} | ||
| 133 | +func (repository *UsersBaseRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.UsersBase, error) { | ||
| 134 | + tx := repository.transactionContext.PgTx | ||
| 135 | + var usersBaseModels []*models.UsersBase | ||
| 136 | + usersBases := make([]*domain.UsersBase, 0) | ||
| 137 | + query := sqlbuilder.BuildQuery(tx.Model(&usersBaseModels), queryOptions) | ||
| 138 | + query.SetOffsetAndLimit(20) | ||
| 139 | + query.SetOrderDirect("users_base_id", "DESC") | ||
| 140 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 141 | + return 0, usersBases, err | ||
| 142 | + } else { | ||
| 143 | + for _, usersBaseModel := range usersBaseModels { | ||
| 144 | + if usersBase, err := transform.TransformToUsersBaseDomainModelFromPgModels(usersBaseModel); err != nil { | ||
| 145 | + return 0, usersBases, err | ||
| 146 | + } else { | ||
| 147 | + usersBases = append(usersBases, usersBase) | ||
| 148 | + } | ||
| 149 | + } | ||
| 150 | + return int64(count), usersBases, nil | ||
| 151 | + } | ||
| 152 | +} | ||
| 153 | +func NewUsersBaseRepository(transactionContext *pgTransaction.TransactionContext) (*UsersBaseRepository, error) { | ||
| 154 | + if transactionContext == nil { | ||
| 155 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 156 | + } else { | ||
| 157 | + return &UsersBaseRepository{ | ||
| 158 | + transactionContext: transactionContext, | ||
| 159 | + }, nil | ||
| 160 | + } | ||
| 161 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + | ||
| 7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/models" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg/transform" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type UsersRepository struct { | ||
| 16 | + transactionContext *pgTransaction.TransactionContext | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (repository *UsersRepository) nextIdentify() (int64, error) { | ||
| 20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
| 21 | + if err != nil { | ||
| 22 | + return 0, err | ||
| 23 | + } | ||
| 24 | + id, err := IdWorker.NextId() | ||
| 25 | + return id, err | ||
| 26 | +} | ||
| 27 | +func (repository *UsersRepository) Save(users *domain.Users) (*domain.Users, error) { | ||
| 28 | + sqlBuildFields := []string{ | ||
| 29 | + "users_id", | ||
| 30 | + "company_id", | ||
| 31 | + "users_base_id", | ||
| 32 | + "users_type", | ||
| 33 | + "users_code", | ||
| 34 | + "organization_id", | ||
| 35 | + "department_id", | ||
| 36 | + "users_info", | ||
| 37 | + "users_org", | ||
| 38 | + "users_role", | ||
| 39 | + "favorite_menus", | ||
| 40 | + "cooperation_info", | ||
| 41 | + "enable_status", | ||
| 42 | + "ext", | ||
| 43 | + "created_at", | ||
| 44 | + "updated_at", | ||
| 45 | + } | ||
| 46 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 47 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
| 48 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
| 49 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "users_id") | ||
| 50 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
| 51 | + tx := repository.transactionContext.PgTx | ||
| 52 | + if users.Identify() == nil { | ||
| 53 | + usersId, err := repository.nextIdentify() | ||
| 54 | + if err != nil { | ||
| 55 | + return users, err | ||
| 56 | + } else { | ||
| 57 | + users.UsersId = usersId | ||
| 58 | + } | ||
| 59 | + if _, err := tx.QueryOne( | ||
| 60 | + pg.Scan( | ||
| 61 | + &users.UsersId, | ||
| 62 | + &users.CompanyId, | ||
| 63 | + &users.UsersBaseId, | ||
| 64 | + &users.UsersType, | ||
| 65 | + &users.UsersCode, | ||
| 66 | + &users.OrganizationId, | ||
| 67 | + &users.DepartmentId, | ||
| 68 | + pg.Array(&users.UsersInfo), | ||
| 69 | + pg.Array(&users.UsersOrg), | ||
| 70 | + pg.Array(&users.UsersRole), | ||
| 71 | + pg.Array(&users.FavoriteMenus), | ||
| 72 | + &users.CooperationInfo, | ||
| 73 | + &users.EnableStatus, | ||
| 74 | + &users.Ext, | ||
| 75 | + &users.CreatedAt, | ||
| 76 | + &users.UpdatedAt, | ||
| 77 | + ), | ||
| 78 | + fmt.Sprintf("INSERT INTO userss (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
| 79 | + users.UsersId, | ||
| 80 | + users.CompanyId, | ||
| 81 | + users.UsersBaseId, | ||
| 82 | + users.UsersType, | ||
| 83 | + users.UsersCode, | ||
| 84 | + users.OrganizationId, | ||
| 85 | + users.DepartmentId, | ||
| 86 | + pg.Array(users.UsersInfo), | ||
| 87 | + pg.Array(users.UsersOrg), | ||
| 88 | + pg.Array(users.UsersRole), | ||
| 89 | + pg.Array(users.FavoriteMenus), | ||
| 90 | + users.CooperationInfo, | ||
| 91 | + users.EnableStatus, | ||
| 92 | + users.Ext, | ||
| 93 | + users.CreatedAt, | ||
| 94 | + users.UpdatedAt, | ||
| 95 | + ); err != nil { | ||
| 96 | + return users, err | ||
| 97 | + } | ||
| 98 | + } else { | ||
| 99 | + if _, err := tx.QueryOne( | ||
| 100 | + pg.Scan( | ||
| 101 | + &users.UsersId, | ||
| 102 | + &users.CompanyId, | ||
| 103 | + &users.UsersBaseId, | ||
| 104 | + &users.UsersType, | ||
| 105 | + &users.UsersCode, | ||
| 106 | + &users.OrganizationId, | ||
| 107 | + &users.DepartmentId, | ||
| 108 | + pg.Array(&users.UsersInfo), | ||
| 109 | + pg.Array(&users.UsersOrg), | ||
| 110 | + pg.Array(&users.UsersRole), | ||
| 111 | + pg.Array(&users.FavoriteMenus), | ||
| 112 | + &users.CooperationInfo, | ||
| 113 | + &users.EnableStatus, | ||
| 114 | + &users.Ext, | ||
| 115 | + &users.CreatedAt, | ||
| 116 | + &users.UpdatedAt, | ||
| 117 | + ), | ||
| 118 | + fmt.Sprintf("UPDATE userss SET %s WHERE users_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
| 119 | + users.CompanyId, | ||
| 120 | + users.UsersBaseId, | ||
| 121 | + users.UsersType, | ||
| 122 | + users.UsersCode, | ||
| 123 | + users.OrganizationId, | ||
| 124 | + users.DepartmentId, | ||
| 125 | + pg.Array(users.UsersInfo), | ||
| 126 | + pg.Array(users.UsersOrg), | ||
| 127 | + pg.Array(users.UsersRole), | ||
| 128 | + pg.Array(users.FavoriteMenus), | ||
| 129 | + users.CooperationInfo, | ||
| 130 | + users.EnableStatus, | ||
| 131 | + users.Ext, | ||
| 132 | + users.CreatedAt, | ||
| 133 | + users.UpdatedAt, | ||
| 134 | + users.Identify(), | ||
| 135 | + ); err != nil { | ||
| 136 | + return users, err | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | + return users, nil | ||
| 140 | +} | ||
| 141 | +func (repository *UsersRepository) Remove(users *domain.Users) (*domain.Users, error) { | ||
| 142 | + tx := repository.transactionContext.PgTx | ||
| 143 | + usersModel := new(models.Users) | ||
| 144 | + usersModel.UsersId = users.Identify().(int64) | ||
| 145 | + if _, err := tx.Model(usersModel).WherePK().Delete(); err != nil { | ||
| 146 | + return users, err | ||
| 147 | + } | ||
| 148 | + return users, nil | ||
| 149 | +} | ||
| 150 | +func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) (*domain.Users, error) { | ||
| 151 | + tx := repository.transactionContext.PgTx | ||
| 152 | + usersModel := new(models.Users) | ||
| 153 | + query := sqlbuilder.BuildQuery(tx.Model(usersModel), queryOptions) | ||
| 154 | + query.SetWhereByQueryOption("users.users_id = ?", "usersId") | ||
| 155 | + if err := query.First(); err != nil { | ||
| 156 | + if err.Error() == "pg: no rows in result set" { | ||
| 157 | + return nil, fmt.Errorf("没有此资源") | ||
| 158 | + } else { | ||
| 159 | + return nil, err | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + if usersModel.UsersId == 0 { | ||
| 163 | + return nil, nil | ||
| 164 | + } else { | ||
| 165 | + return transform.TransformToUsersDomainModelFromPgModels(usersModel) | ||
| 166 | + } | ||
| 167 | +} | ||
| 168 | +func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Users, error) { | ||
| 169 | + tx := repository.transactionContext.PgTx | ||
| 170 | + var usersModels []*models.Users | ||
| 171 | + userss := make([]*domain.Users, 0) | ||
| 172 | + query := sqlbuilder.BuildQuery(tx.Model(&usersModels), queryOptions) | ||
| 173 | + query.SetOffsetAndLimit(20) | ||
| 174 | + query.SetOrderDirect("users_id", "DESC") | ||
| 175 | + if count, err := query.SelectAndCount(); err != nil { | ||
| 176 | + return 0, userss, err | ||
| 177 | + } else { | ||
| 178 | + for _, usersModel := range usersModels { | ||
| 179 | + if users, err := transform.TransformToUsersDomainModelFromPgModels(usersModel); err != nil { | ||
| 180 | + return 0, userss, err | ||
| 181 | + } else { | ||
| 182 | + userss = append(userss, users) | ||
| 183 | + } | ||
| 184 | + } | ||
| 185 | + return int64(count), userss, nil | ||
| 186 | + } | ||
| 187 | +} | ||
| 188 | +func NewUsersRepository(transactionContext *pgTransaction.TransactionContext) (*UsersRepository, error) { | ||
| 189 | + if transactionContext == nil { | ||
| 190 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 191 | + } else { | ||
| 192 | + return &UsersRepository{ | ||
| 193 | + transactionContext: transactionContext, | ||
| 194 | + }, nil | ||
| 195 | + } | ||
| 196 | +} |
-
请 注册 或 登录 后发表评论