正在显示
45 个修改的文件
包含
316 行增加
和
121 行删除
| @@ -62,3 +62,11 @@ func CreatePgCreateRoleService(options map[string]interface{}) (service.PgCreate | @@ -62,3 +62,11 @@ func CreatePgCreateRoleService(options map[string]interface{}) (service.PgCreate | ||
| 62 | } | 62 | } |
| 63 | return domainService.NewPgCreateRoleService(transactionContext) | 63 | return domainService.NewPgCreateRoleService(transactionContext) |
| 64 | } | 64 | } |
| 65 | + | ||
| 66 | +func CreatePgCreateOrgService(options map[string]interface{}) (service.PgCreateOrgService, error) { | ||
| 67 | + var transactionContext *pgTransaction.TransactionContext | ||
| 68 | + if value, ok := options["transactionContext"]; ok { | ||
| 69 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
| 70 | + } | ||
| 71 | + return domainService.NewPgCreateOrgService(transactionContext) | ||
| 72 | +} |
| @@ -101,7 +101,7 @@ func FastPgOrg(transactionContext application.TransactionContext, orgId int64) ( | @@ -101,7 +101,7 @@ func FastPgOrg(transactionContext application.TransactionContext, orgId int64) ( | ||
| 101 | if orgId > 0 { | 101 | if orgId > 0 { |
| 102 | if mod, err = rep.FindOne(map[string]interface{}{"orgId": orgId}); err != nil { | 102 | if mod, err = rep.FindOne(map[string]interface{}{"orgId": orgId}); err != nil { |
| 103 | if err == domain.ErrorNotFound { | 103 | if err == domain.ErrorNotFound { |
| 104 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该角色不存在") | 104 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该组织不存在") |
| 105 | } | 105 | } |
| 106 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 106 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 107 | } | 107 | } |
| @@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
| 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/menu/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/menu/command" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/menu/query" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/menu/query" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
| 11 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/common" | 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils" |
| 12 | "strconv" | 12 | "strconv" |
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| @@ -139,7 +139,7 @@ func (menuService *MenuService) ListMenu(listMenuQuery *query.ListMenuQuery) (in | @@ -139,7 +139,7 @@ func (menuService *MenuService) ListMenu(listMenuQuery *query.ListMenuQuery) (in | ||
| 139 | } else { | 139 | } else { |
| 140 | menuRepository = value | 140 | menuRepository = value |
| 141 | } | 141 | } |
| 142 | - queryOptions := common.SimpleStructToMap(listMenuQuery) | 142 | + queryOptions := utils.ObjectToMap(listMenuQuery) |
| 143 | if len(listMenuQuery.MenuCategory) > 0 { | 143 | if len(listMenuQuery.MenuCategory) > 0 { |
| 144 | queryOptions["code"] = "" | 144 | queryOptions["code"] = "" |
| 145 | if m, e := menuRepository.FindOne(map[string]interface{}{"code": listMenuQuery.MenuCategory}); e == nil && m != nil { | 145 | if m, e := menuRepository.FindOne(map[string]interface{}{"code": listMenuQuery.MenuCategory}); e == nil && m != nil { |
| @@ -10,7 +10,7 @@ import ( | @@ -10,7 +10,7 @@ import ( | ||
| 10 | 10 | ||
| 11 | type CreateOrgCommand struct { | 11 | type CreateOrgCommand struct { |
| 12 | // 企业id | 12 | // 企业id |
| 13 | - CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | 13 | + CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"` |
| 14 | // 组织编码 | 14 | // 组织编码 |
| 15 | OrgCode string `cname:"组织编码" json:"orgCode" valid:"Required"` | 15 | OrgCode string `cname:"组织编码" json:"orgCode" valid:"Required"` |
| 16 | // 组织名称 | 16 | // 组织名称 |
| @@ -18,7 +18,7 @@ type CreateOrgCommand struct { | @@ -18,7 +18,7 @@ type CreateOrgCommand struct { | ||
| 18 | // 是否是组织(是:1 不是:2) | 18 | // 是否是组织(是:1 不是:2) |
| 19 | IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg" valid:"Required"` | 19 | IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg" valid:"Required"` |
| 20 | // 父级ID | 20 | // 父级ID |
| 21 | - ParentId int64 `cname:"父级ID" json:"parentId,string" valid:"Required"` | 21 | + ParentId int64 `cname:"父级ID" json:"parentId" valid:"Required"` |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | func (createOrgCommand *CreateOrgCommand) Valid(validation *validation.Validation) { | 24 | func (createOrgCommand *CreateOrgCommand) Valid(validation *validation.Validation) { |
| @@ -10,7 +10,7 @@ import ( | @@ -10,7 +10,7 @@ import ( | ||
| 10 | 10 | ||
| 11 | type EnableOrgCommand struct { | 11 | type EnableOrgCommand struct { |
| 12 | // 组织ID | 12 | // 组织ID |
| 13 | - OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"` | 13 | + OrgId int64 `cname:"组织ID" json:"orgId" valid:"Required"` |
| 14 | // 组织状态 1:启用 2:禁用 3.删除 | 14 | // 组织状态 1:启用 2:禁用 3.删除 |
| 15 | OrgStatus int `cname:"组织状态 1:启用 2:禁用 3.删除" json:"orgStatus" valid:"Required"` | 15 | OrgStatus int `cname:"组织状态 1:启用 2:禁用 3.删除" json:"orgStatus" valid:"Required"` |
| 16 | } | 16 | } |
| @@ -14,7 +14,7 @@ type RemoveOrgCommand struct { | @@ -14,7 +14,7 @@ type RemoveOrgCommand struct { | ||
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | func (removeOrgCommand *RemoveOrgCommand) Valid(validation *validation.Validation) { | 16 | func (removeOrgCommand *RemoveOrgCommand) Valid(validation *validation.Validation) { |
| 17 | - //validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + validation.SetError("CustomValid", "未实现的自定义认证") |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | func (removeOrgCommand *RemoveOrgCommand) ValidateCommand() error { | 20 | func (removeOrgCommand *RemoveOrgCommand) ValidateCommand() error { |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,20 +10,38 @@ import ( | @@ -9,20 +10,38 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type UpdateOrgCommand struct { | 12 | type UpdateOrgCommand struct { |
| 13 | + // 用户ID | ||
| 14 | + UserId int64 `cname:"用户ID" json:"userId" valid:"Required"` | ||
| 12 | // 组织ID | 15 | // 组织ID |
| 13 | - OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"` | 16 | + OrgId int64 `cname:"组织ID" json:"orgId,string"` |
| 14 | // 组织编码 | 17 | // 组织编码 |
| 15 | - OrgCode string `cname:"组织编码" json:"orgCode" valid:"Required"` | 18 | + OrgCode string `cname:"组织编码" json:"orgCode"` |
| 16 | // 组织名称 | 19 | // 组织名称 |
| 17 | - OrgName string `cname:"组织名称" json:"orgName" valid:"Required"` | 20 | + OrgName string `cname:"组织名称" json:"orgName"` |
| 18 | // 是否是组织(是:1 不是:2) | 21 | // 是否是组织(是:1 不是:2) |
| 19 | - IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg" valid:"Required"` | 22 | + IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg"` |
| 20 | // 父级ID | 23 | // 父级ID |
| 21 | - ParentId int64 `cname:"父级ID" json:"parentId,string" valid:"Required"` | 24 | + ParentId int64 `cname:"父级ID" json:"parentId" valid:"Required"` |
| 22 | } | 25 | } |
| 23 | 26 | ||
| 24 | func (updateOrgCommand *UpdateOrgCommand) Valid(validation *validation.Validation) { | 27 | func (updateOrgCommand *UpdateOrgCommand) Valid(validation *validation.Validation) { |
| 25 | //validation.SetError("CustomValid", "未实现的自定义认证") | 28 | //validation.SetError("CustomValid", "未实现的自定义认证") |
| 29 | + if len(updateOrgCommand.OrgCode) == 0 { | ||
| 30 | + validation.SetError("CustomValid", "部门编码不能为空") | ||
| 31 | + return | ||
| 32 | + } | ||
| 33 | + if len(updateOrgCommand.OrgName) == 0 { | ||
| 34 | + validation.SetError("CustomValid", "部门名称不能为空") | ||
| 35 | + return | ||
| 36 | + } | ||
| 37 | + if updateOrgCommand.ParentId == 0 { | ||
| 38 | + validation.SetError("CustomValid", "上级部门不能为空") | ||
| 39 | + return | ||
| 40 | + } | ||
| 41 | + if !(updateOrgCommand.IsOrg == domain.IsOrgFlag || updateOrgCommand.IsOrg == domain.IsNotOrgFlag) { | ||
| 42 | + validation.SetError("CustomValid", "启用状体有误") | ||
| 43 | + return | ||
| 44 | + } | ||
| 26 | } | 45 | } |
| 27 | 46 | ||
| 28 | func (updateOrgCommand *UpdateOrgCommand) ValidateCommand() error { | 47 | func (updateOrgCommand *UpdateOrgCommand) ValidateCommand() error { |
| @@ -10,7 +10,7 @@ import ( | @@ -10,7 +10,7 @@ import ( | ||
| 10 | 10 | ||
| 11 | type GetOrgQuery struct { | 11 | type GetOrgQuery struct { |
| 12 | // 组织ID | 12 | // 组织ID |
| 13 | - OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"` | 13 | + OrgId int64 `cname:"组织ID" json:"orgId" valid:"Required"` |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | func (getOrgQuery *GetOrgQuery) Valid(validation *validation.Validation) { | 16 | func (getOrgQuery *GetOrgQuery) Valid(validation *validation.Validation) { |
| @@ -14,13 +14,13 @@ type ListOrgQuery struct { | @@ -14,13 +14,13 @@ type ListOrgQuery struct { | ||
| 14 | // 查询限制 | 14 | // 查询限制 |
| 15 | Limit int `cname:"查询限制" json:"limit,omitempty"` | 15 | Limit int `cname:"查询限制" json:"limit,omitempty"` |
| 16 | // 企业id | 16 | // 企业id |
| 17 | - CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | 17 | + CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"` |
| 18 | // 组织编码 | 18 | // 组织编码 |
| 19 | OrgCode string `cname:"组织编码" json:"orgCode,omitempty"` | 19 | OrgCode string `cname:"组织编码" json:"orgCode,omitempty"` |
| 20 | // 部门名称 | 20 | // 部门名称 |
| 21 | DepName string `cname:"部门名称" json:"depName,omitempty"` | 21 | DepName string `cname:"部门名称" json:"depName,omitempty"` |
| 22 | // 父级ID | 22 | // 父级ID |
| 23 | - ParentId int64 `cname:"父级ID" json:"parentId,string,omitempty"` | 23 | + ParentId int64 `cname:"父级ID" json:"parentId,omitempty"` |
| 24 | // 是否是组织(是:1 不是:2) | 24 | // 是否是组织(是:1 不是:2) |
| 25 | IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg,omitempty"` | 25 | IsOrg int `cname:"是否是组织(是:1 不是:2)" json:"isOrg,omitempty"` |
| 26 | } | 26 | } |
| @@ -8,6 +8,8 @@ import ( | @@ -8,6 +8,8 @@ import ( | ||
| 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/org/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/org/command" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/org/query" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/org/query" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils" | ||
| 12 | + "time" | ||
| 11 | ) | 13 | ) |
| 12 | 14 | ||
| 13 | // 组织管理 | 15 | // 组织管理 |
| @@ -35,23 +37,25 @@ func (orgService *OrgService) CreateOrg(createOrgCommand *command.CreateOrgComma | @@ -35,23 +37,25 @@ func (orgService *OrgService) CreateOrg(createOrgCommand *command.CreateOrgComma | ||
| 35 | OrgName: createOrgCommand.OrgName, | 37 | OrgName: createOrgCommand.OrgName, |
| 36 | IsOrg: createOrgCommand.IsOrg, | 38 | IsOrg: createOrgCommand.IsOrg, |
| 37 | ParentId: createOrgCommand.ParentId, | 39 | ParentId: createOrgCommand.ParentId, |
| 40 | + OrgStatus: domain.OrgStatusEnable, | ||
| 41 | + CreatedAt: time.Now(), | ||
| 42 | + UpdatedAt: time.Now(), | ||
| 43 | + Ext: &domain.Ext{}, | ||
| 38 | } | 44 | } |
| 39 | - var orgRepository domain.OrgRepository | ||
| 40 | - if value, err := factory.CreateOrgRepository(map[string]interface{}{ | 45 | + var org *domain.Org |
| 46 | + if createOrgService, err := factory.CreatePgCreateOrgService(map[string]interface{}{ | ||
| 41 | "transactionContext": transactionContext, | 47 | "transactionContext": transactionContext, |
| 42 | }); err != nil { | 48 | }); err != nil { |
| 43 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 49 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 44 | } else { | 50 | } else { |
| 45 | - orgRepository = value | ||
| 46 | - } | ||
| 47 | - if org, err := orgRepository.Save(newOrg); err != nil { | ||
| 48 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 49 | - } else { | ||
| 50 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 51 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 51 | + if org, err = createOrgService.CreateOrg(nil, newOrg); err != nil { |
| 52 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 52 | } | 53 | } |
| 53 | - return org, nil | ||
| 54 | } | 54 | } |
| 55 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 56 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 57 | + } | ||
| 58 | + return org, nil | ||
| 55 | } | 59 | } |
| 56 | 60 | ||
| 57 | // 设置组织启用状态 | 61 | // 设置组织启用状态 |
| @@ -156,7 +160,7 @@ func (orgService *OrgService) ListOrg(listOrgQuery *query.ListOrgQuery) (interfa | @@ -156,7 +160,7 @@ func (orgService *OrgService) ListOrg(listOrgQuery *query.ListOrgQuery) (interfa | ||
| 156 | } else { | 160 | } else { |
| 157 | orgRepository = value | 161 | orgRepository = value |
| 158 | } | 162 | } |
| 159 | - if count, orgs, err := orgRepository.Find(tool_funs.SimpleStructToMap(listOrgQuery)); err != nil { | 163 | + if count, orgs, err := orgRepository.Find(utils.ObjectToMap(listOrgQuery)); err != nil { |
| 160 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 164 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 161 | } else { | 165 | } else { |
| 162 | if err := transactionContext.CommitTransaction(); err != nil { | 166 | if err := transactionContext.CommitTransaction(); err != nil { |
| @@ -224,32 +228,37 @@ func (orgService *OrgService) UpdateOrg(updateOrgCommand *command.UpdateOrgComma | @@ -224,32 +228,37 @@ func (orgService *OrgService) UpdateOrg(updateOrgCommand *command.UpdateOrgComma | ||
| 224 | defer func() { | 228 | defer func() { |
| 225 | transactionContext.RollbackTransaction() | 229 | transactionContext.RollbackTransaction() |
| 226 | }() | 230 | }() |
| 227 | - var orgRepository domain.OrgRepository | ||
| 228 | - if value, err := factory.CreateOrgRepository(map[string]interface{}{ | ||
| 229 | - "transactionContext": transactionContext, | ||
| 230 | - }); err != nil { | ||
| 231 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 232 | - } else { | ||
| 233 | - orgRepository = value | ||
| 234 | - } | ||
| 235 | - org, err := orgRepository.FindOne(map[string]interface{}{"orgId": updateOrgCommand.OrgId}) | 231 | + orgRepository, org, err := factory.FastPgOrg(transactionContext, updateOrgCommand.OrgId) |
| 236 | if err != nil { | 232 | if err != nil { |
| 237 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 233 | + return nil, err |
| 238 | } | 234 | } |
| 239 | - if org == nil { | ||
| 240 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateOrgCommand.OrgId))) | 235 | + |
| 236 | + //判断当前组织内是否唯一 组织编码、组织名称 | ||
| 237 | + if findOne, err := orgRepository.FindOne(map[string]interface{}{"companyId": org.CompanyId, "parentId": updateOrgCommand.ParentId, "orgName": updateOrgCommand.OrgName, "notEqualOrgId": org.OrgId}); err == nil || findOne != nil { | ||
| 238 | + return nil, fmt.Errorf("部门名称重复") | ||
| 241 | } | 239 | } |
| 240 | + if findOne, err := orgRepository.FindOne(map[string]interface{}{"companyId": org.CompanyId, "parentId": updateOrgCommand.ParentId, "orgCode": updateOrgCommand.OrgCode, "notEqualOrgId": org.OrgId}); err == nil || findOne != nil { | ||
| 241 | + return nil, fmt.Errorf("部门编码重复") | ||
| 242 | + } | ||
| 243 | + | ||
| 242 | if err := org.Update(tool_funs.SimpleStructToMap(updateOrgCommand)); err != nil { | 244 | if err := org.Update(tool_funs.SimpleStructToMap(updateOrgCommand)); err != nil { |
| 243 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 245 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| 244 | } | 246 | } |
| 245 | - if org, err := orgRepository.Save(org); err != nil { | ||
| 246 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 247 | - } else { | ||
| 248 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 249 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 247 | + //上继组织 |
| 248 | + if updateOrgCommand.ParentId != 0 { | ||
| 249 | + _, parentOrg, err := factory.FastPgOrg(transactionContext, updateOrgCommand.ParentId) | ||
| 250 | + if err != nil { | ||
| 251 | + return nil, err | ||
| 250 | } | 252 | } |
| 251 | - return org, nil | 253 | + org.Ext.ParentDepName = parentOrg.OrgName |
| 254 | + } | ||
| 255 | + if org, err = orgRepository.Save(org); err != nil { | ||
| 256 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 257 | + } | ||
| 258 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 259 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 252 | } | 260 | } |
| 261 | + return org, nil | ||
| 253 | } | 262 | } |
| 254 | 263 | ||
| 255 | func NewOrgService(options map[string]interface{}) *OrgService { | 264 | func NewOrgService(options map[string]interface{}) *OrgService { |
| @@ -19,6 +19,8 @@ type ListRoleQuery struct { | @@ -19,6 +19,8 @@ type ListRoleQuery struct { | ||
| 19 | RoleName string `cname:"角色名称" json:"roleName,omitempty"` | 19 | RoleName string `cname:"角色名称" json:"roleName,omitempty"` |
| 20 | // 组织名称 | 20 | // 组织名称 |
| 21 | OrgName string `cname:"组织名称" json:"orgName,omitempty"` | 21 | OrgName string `cname:"组织名称" json:"orgName,omitempty"` |
| 22 | + // 企业id | ||
| 23 | + CompanyId int64 `cname:"企业id" json:"companyId" valid:"Required"` | ||
| 22 | // 组织ID | 24 | // 组织ID |
| 23 | OrgId int64 `cname:"组织ID" json:"orgId,omitempty"` | 25 | OrgId int64 `cname:"组织ID" json:"orgId,omitempty"` |
| 24 | // 匹配多个组织 | 26 | // 匹配多个组织 |
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/role/command" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/role/command" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/role/query" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/role/query" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils" | ||
| 11 | "time" | 12 | "time" |
| 12 | ) | 13 | ) |
| 13 | 14 | ||
| @@ -56,6 +57,11 @@ func (roleService *RoleService) CreateRole(createRoleCommand *command.CreateRole | @@ -56,6 +57,11 @@ func (roleService *RoleService) CreateRole(createRoleCommand *command.CreateRole | ||
| 56 | if err != nil { | 57 | if err != nil { |
| 57 | return nil, err | 58 | return nil, err |
| 58 | } | 59 | } |
| 60 | + roleRepository, _, err := factory.FastPgRole(transactionContext, 0) | ||
| 61 | + if existsRole, e := roleRepository.FindOne(map[string]interface{}{"companyId": org.CompanyId, "orgId": org.OrgId, "roleName": createRoleCommand.RoleName}); e == nil && existsRole != nil { | ||
| 62 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "该角色在当前组织机构已经存在") | ||
| 63 | + } | ||
| 64 | + | ||
| 59 | createRoleService, err := factory.CreatePgCreateRoleService(map[string]interface{}{ | 65 | createRoleService, err := factory.CreatePgCreateRoleService(map[string]interface{}{ |
| 60 | "transactionContext": transactionContext, | 66 | "transactionContext": transactionContext, |
| 61 | }) | 67 | }) |
| @@ -79,6 +85,9 @@ func (roleService *RoleService) CreateRole(createRoleCommand *command.CreateRole | @@ -79,6 +85,9 @@ func (roleService *RoleService) CreateRole(createRoleCommand *command.CreateRole | ||
| 79 | if err != nil { | 85 | if err != nil { |
| 80 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 86 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 81 | } | 87 | } |
| 88 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 89 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 90 | + } | ||
| 82 | return role, nil | 91 | return role, nil |
| 83 | } | 92 | } |
| 84 | 93 | ||
| @@ -105,7 +114,7 @@ func (roleService *RoleService) GetRole(getRoleQuery *query.GetRoleQuery) (inter | @@ -105,7 +114,7 @@ func (roleService *RoleService) GetRole(getRoleQuery *query.GetRoleQuery) (inter | ||
| 105 | } else { | 114 | } else { |
| 106 | roleRepository = value | 115 | roleRepository = value |
| 107 | } | 116 | } |
| 108 | - role, err := roleRepository.FindOne(map[string]interface{}{"roleId": getRoleQuery.RoleId}) | 117 | + role, err := roleRepository.FindOne(map[string]interface{}{"roleId": getRoleQuery.RoleId, "includeDeleted": true}) |
| 109 | if err != nil { | 118 | if err != nil { |
| 110 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 119 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 111 | } | 120 | } |
| @@ -184,7 +193,7 @@ func (roleService *RoleService) ListRole(listRoleQuery *query.ListRoleQuery) (in | @@ -184,7 +193,7 @@ func (roleService *RoleService) ListRole(listRoleQuery *query.ListRoleQuery) (in | ||
| 184 | } else { | 193 | } else { |
| 185 | roleRepository = value | 194 | roleRepository = value |
| 186 | } | 195 | } |
| 187 | - queryOptions := tool_funs.SimpleStructToMap(listRoleQuery) | 196 | + queryOptions := utils.ObjectToMap(listRoleQuery) |
| 188 | queryOptions["includeDeleted"] = false | 197 | queryOptions["includeDeleted"] = false |
| 189 | if count, roles, err := roleRepository.Find(queryOptions); err != nil { | 198 | if count, roles, err := roleRepository.Find(queryOptions); err != nil { |
| 190 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 199 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -229,6 +238,7 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole | @@ -229,6 +238,7 @@ func (roleService *RoleService) RemoveRole(removeRoleCommand *command.RemoveRole | ||
| 229 | if role == nil { | 238 | if role == nil { |
| 230 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeRoleCommand.RoleId))) | 239 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeRoleCommand.RoleId))) |
| 231 | } | 240 | } |
| 241 | + role.DeletedAt = time.Now() | ||
| 232 | if role, err := roleRepository.Remove(role); err != nil { | 242 | if role, err := roleRepository.Remove(role); err != nil { |
| 233 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 243 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 234 | } else { | 244 | } else { |
| @@ -275,24 +285,21 @@ func (roleService *RoleService) UpdateRole(updateRoleCommand *command.UpdateRole | @@ -275,24 +285,21 @@ func (roleService *RoleService) UpdateRole(updateRoleCommand *command.UpdateRole | ||
| 275 | defer func() { | 285 | defer func() { |
| 276 | transactionContext.RollbackTransaction() | 286 | transactionContext.RollbackTransaction() |
| 277 | }() | 287 | }() |
| 278 | - var roleRepository domain.RoleRepository | ||
| 279 | - if value, err := factory.CreateRoleRepository(map[string]interface{}{ | ||
| 280 | - "transactionContext": transactionContext, | ||
| 281 | - }); err != nil { | ||
| 282 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 283 | - } else { | ||
| 284 | - roleRepository = value | ||
| 285 | - } | ||
| 286 | - role, err := roleRepository.FindOne(map[string]interface{}{"roleId": updateRoleCommand.RoleId}) | 288 | + |
| 289 | + roleRepository, role, err := factory.FastPgRole(transactionContext, updateRoleCommand.RoleId) | ||
| 287 | if err != nil { | 290 | if err != nil { |
| 288 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 291 | + return nil, err |
| 289 | } | 292 | } |
| 290 | - if role == nil { | ||
| 291 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateRoleCommand.RoleId))) | 293 | + if existsRole, e := roleRepository.FindOne(map[string]interface{}{"companyId": role.CompanyId, "orgId": role.OrgId, "roleName": updateRoleCommand.RoleName}); e == nil && existsRole != nil && existsRole.RoleId != role.RoleId { |
| 294 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "该角色在当前组织机构已经存在") | ||
| 292 | } | 295 | } |
| 296 | + | ||
| 293 | if err := role.Update(tool_funs.SimpleStructToMap(updateRoleCommand)); err != nil { | 297 | if err := role.Update(tool_funs.SimpleStructToMap(updateRoleCommand)); err != nil { |
| 294 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 298 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| 295 | } | 299 | } |
| 300 | + if _, org, _ := factory.FastPgOrg(transactionContext, role.OrgId); org != nil { | ||
| 301 | + role.Ext.OrgName = org.OrgName | ||
| 302 | + } | ||
| 296 | if role, err := roleRepository.Save(role); err != nil { | 303 | if role, err := roleRepository.Save(role); err != nil { |
| 297 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 304 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 298 | } else { | 305 | } else { |
| @@ -3,7 +3,6 @@ package command | @@ -3,7 +3,6 @@ package command | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "github.com/beego/beego/v2/core/validation" | 5 | "github.com/beego/beego/v2/core/validation" |
| 6 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 7 | "reflect" | 6 | "reflect" |
| 8 | "strings" | 7 | "strings" |
| 9 | "time" | 8 | "time" |
| @@ -21,9 +20,9 @@ type CreateUserCommand struct { | @@ -21,9 +20,9 @@ type CreateUserCommand struct { | ||
| 21 | // 所属部门 | 20 | // 所属部门 |
| 22 | DepartmentId int64 `cname:"所属部门" json:"departmentId,omitempty" valid:"Required"` | 21 | DepartmentId int64 `cname:"所属部门" json:"departmentId,omitempty" valid:"Required"` |
| 23 | // 用户关联的组织 | 22 | // 用户关联的组织 |
| 24 | - UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"` | 23 | + UserOrg []int64 `cname:"用户关联的组织" json:"userOrg,omitempty"` |
| 25 | // 用户关联的角色 | 24 | // 用户关联的角色 |
| 26 | - UserRole []*domain.Role `cname:"用户关联的角色" json:"userRole,omitempty"` | 25 | + UserRole []int64 `cname:"用户关联的角色" json:"userRole,omitempty"` |
| 27 | // 共创公司 | 26 | // 共创公司 |
| 28 | CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"` | 27 | CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"` |
| 29 | // 共创到期时间 (yyyy-MM-dd) | 28 | // 共创到期时间 (yyyy-MM-dd) |
pkg/application/user/dto/user_dto.go
0 → 100644
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 5 | +) | ||
| 6 | + | ||
| 7 | +type UserDto struct { | ||
| 8 | + // 用户Id 用户唯一标识 | ||
| 9 | + UserId int64 `json:"userId,omitempty"` | ||
| 10 | + // 用户基础数据id | ||
| 11 | + UserBaseId int64 `json:"userBaseId,omitempty"` | ||
| 12 | + // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | ||
| 13 | + UserType int `json:"userType,omitempty"` | ||
| 14 | + // 用户编号 企业内标识 | ||
| 15 | + UserCode string `json:"userCode,omitempty"` | ||
| 16 | + // 用户关联的组织 | ||
| 17 | + UserOrg []*domain.Org `json:"userOrg,omitempty"` | ||
| 18 | + // 用户关联的角色 | ||
| 19 | + UserRole []*domain.Role `json:"userRole,omitempty"` | ||
| 20 | + // 收藏的菜单(工作台)(菜单编码列表) | ||
| 21 | + FavoriteMenus []string `json:"favoriteMenus,omitempty"` | ||
| 22 | + // 共创信息 (共创用户有效) | ||
| 23 | + CooperationInfo *domain.CooperationInfo `json:"cooperationInfo,omitempty"` | ||
| 24 | + // 状态(1:启用 2:禁用 3:注销) | ||
| 25 | + EnableStatus int `json:"enableStatus,omitempty"` | ||
| 26 | + // 用户信息 (冗余,数据存在userBase里面) | ||
| 27 | + UserInfo *domain.UserInfo `json:"userInfo,omitempty"` | ||
| 28 | + // 企业id | ||
| 29 | + Company *Company `json:"company,omitempty"` | ||
| 30 | + // 组织机构 | ||
| 31 | + Organization *domain.Org `json:"org,omitempty"` | ||
| 32 | + // 部门 | ||
| 33 | + Department *domain.Department `json:"department,omitempty"` | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +type Company struct { | ||
| 37 | + // 企业id | ||
| 38 | + CompanyId int64 `json:"companyId"` | ||
| 39 | + // 企业基本信息 | ||
| 40 | + domain.CompanyInfo | ||
| 41 | + Status int `json:"status"` | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error { | ||
| 45 | + dto.UserId = user.UserId | ||
| 46 | + dto.UserBaseId = user.UserBaseId | ||
| 47 | + dto.UserType = user.UserType | ||
| 48 | + dto.UserCode = user.UserCode | ||
| 49 | + dto.UserOrg = user.UserOrg | ||
| 50 | + dto.UserRole = user.UserRole | ||
| 51 | + dto.FavoriteMenus = user.FavoriteMenus | ||
| 52 | + dto.CooperationInfo = user.CooperationInfo | ||
| 53 | + dto.EnableStatus = user.EnableStatus | ||
| 54 | + dto.UserInfo = user.UserInfo | ||
| 55 | + dto.Company = &Company{ | ||
| 56 | + CompanyId: company.CompanyId, | ||
| 57 | + CompanyInfo: *company.CompanyInfo, | ||
| 58 | + Status: company.Status, | ||
| 59 | + } | ||
| 60 | + dto.Organization = user.Organization | ||
| 61 | + dto.Department = user.Department | ||
| 62 | + return nil | ||
| 63 | +} |
| @@ -3,11 +3,12 @@ package service | @@ -3,11 +3,12 @@ package service | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "github.com/linmadan/egglib-go/core/application" | 5 | "github.com/linmadan/egglib-go/core/application" |
| 6 | - "github.com/linmadan/egglib-go/utils/tool_funs" | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" |
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/dto" | ||
| 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils" | ||
| 11 | "time" | 12 | "time" |
| 12 | ) | 13 | ) |
| 13 | 14 | ||
| @@ -191,11 +192,21 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser | @@ -191,11 +192,21 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser | ||
| 191 | } | 192 | } |
| 192 | var sampleUserOrg = make([]*domain.Org, 0) | 193 | var sampleUserOrg = make([]*domain.Org, 0) |
| 193 | var sampleUserRole = make([]*domain.Role, 0) | 194 | var sampleUserRole = make([]*domain.Role, 0) |
| 195 | + orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0) | ||
| 196 | + roleRepository, _, _ := factory.FastPgRole(transactionContext, 0) | ||
| 194 | for i := range createUserCommand.UserOrg { | 197 | for i := range createUserCommand.UserOrg { |
| 195 | - sampleUserOrg = append(sampleUserOrg, createUserCommand.UserOrg[i].CloneSample()) | 198 | + if org, err := orgRepository.FindOne(map[string]interface{}{"orgId": createUserCommand.UserOrg[i]}); err != nil { |
| 199 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, "关联的组织不存在") | ||
| 200 | + } else { | ||
| 201 | + sampleUserOrg = append(sampleUserOrg, org.CloneSample()) | ||
| 202 | + } | ||
| 196 | } | 203 | } |
| 197 | for i := range createUserCommand.UserRole { | 204 | for i := range createUserCommand.UserRole { |
| 198 | - sampleUserRole = append(sampleUserRole, createUserCommand.UserRole[i].CloneSample()) | 205 | + if role, err := roleRepository.FindOne(map[string]interface{}{"roleId": createUserCommand.UserRole[i]}); err != nil { |
| 206 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, "关联的角色不存在") | ||
| 207 | + } else { | ||
| 208 | + sampleUserRole = append(sampleUserRole, role.CloneSample()) | ||
| 209 | + } | ||
| 199 | } | 210 | } |
| 200 | newUser := &domain.User{ | 211 | newUser := &domain.User{ |
| 201 | CompanyId: createUserCommand.CompanyId, | 212 | CompanyId: createUserCommand.CompanyId, |
| @@ -220,7 +231,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser | @@ -220,7 +231,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser | ||
| 220 | "transactionContext": transactionContext, | 231 | "transactionContext": transactionContext, |
| 221 | }) | 232 | }) |
| 222 | if user, err = createUserService.CreateUser(nil, newUser, createUserCommand.Password); err != nil { | 233 | if user, err = createUserService.CreateUser(nil, newUser, createUserCommand.Password); err != nil { |
| 223 | - return nil, err | 234 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 224 | } | 235 | } |
| 225 | if err := transactionContext.CommitTransaction(); err != nil { | 236 | if err := transactionContext.CommitTransaction(); err != nil { |
| 226 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 237 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -305,11 +316,14 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter | @@ -305,11 +316,14 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter | ||
| 305 | user.Company = company.CloneSample() | 316 | user.Company = company.CloneSample() |
| 306 | user.UserInfo = userBase.UserInfo | 317 | user.UserInfo = userBase.UserInfo |
| 307 | } | 318 | } |
| 308 | - | 319 | + userDto := &dto.UserDto{} |
| 320 | + if err := userDto.LoadDto(user, company); err != nil { | ||
| 321 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 322 | + } | ||
| 309 | if err := transactionContext.CommitTransaction(); err != nil { | 323 | if err := transactionContext.CommitTransaction(); err != nil { |
| 310 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 324 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 311 | } | 325 | } |
| 312 | - return user, nil | 326 | + return userDto, nil |
| 313 | } | 327 | } |
| 314 | 328 | ||
| 315 | // 返回用户有权限的菜单 | 329 | // 返回用户有权限的菜单 |
| @@ -377,7 +391,7 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | @@ -377,7 +391,7 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | ||
| 377 | } else { | 391 | } else { |
| 378 | userRepository = value | 392 | userRepository = value |
| 379 | } | 393 | } |
| 380 | - if count, users, err := userRepository.Find(tool_funs.SimpleStructToMap(listUserQuery)); err != nil { | 394 | + if count, users, err := userRepository.Find(utils.ObjectToMap(listUserQuery)); err != nil { |
| 381 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 395 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 382 | } else { | 396 | } else { |
| 383 | if err := transactionContext.CommitTransaction(); err != nil { | 397 | if err := transactionContext.CommitTransaction(); err != nil { |
| @@ -77,18 +77,21 @@ func (org *Org) Update(data map[string]interface{}) error { | @@ -77,18 +77,21 @@ func (org *Org) Update(data map[string]interface{}) error { | ||
| 77 | if orgName, ok := data["orgName"]; ok { | 77 | if orgName, ok := data["orgName"]; ok { |
| 78 | org.OrgName = orgName.(string) | 78 | org.OrgName = orgName.(string) |
| 79 | } | 79 | } |
| 80 | - if userName, ok := data["userName"]; ok { | ||
| 81 | - org.Ext.UserName = userName.(string) | ||
| 82 | - } | ||
| 83 | - if orgName, ok := data["orgName"]; ok { | ||
| 84 | - org.Ext.OrgName = orgName.(string) | ||
| 85 | - } | ||
| 86 | - if phone, ok := data["phone"]; ok { | ||
| 87 | - org.Ext.Phone = phone.(string) | ||
| 88 | - } | ||
| 89 | - if depName, ok := data["depName"]; ok { | ||
| 90 | - org.Ext.DepName = depName.(string) | ||
| 91 | - } | 80 | + if org.Ext == nil { |
| 81 | + org.Ext = &Ext{} | ||
| 82 | + } | ||
| 83 | + //if userName, ok := data["userName"]; ok { | ||
| 84 | + // org.Ext.UserName = userName.(string) | ||
| 85 | + //} | ||
| 86 | + //if orgName, ok := data["orgName"]; ok { | ||
| 87 | + // org.Ext.OrgName = orgName.(string) | ||
| 88 | + //} | ||
| 89 | + //if phone, ok := data["phone"]; ok { | ||
| 90 | + // org.Ext.Phone = phone.(string) | ||
| 91 | + //} | ||
| 92 | + //if depName, ok := data["depName"]; ok { | ||
| 93 | + // org.Ext.DepName = depName.(string) | ||
| 94 | + //} | ||
| 92 | if parentDepName, ok := data["parentDepName"]; ok { | 95 | if parentDepName, ok := data["parentDepName"]; ok { |
| 93 | org.Ext.ParentDepName = parentDepName.(string) | 96 | org.Ext.ParentDepName = parentDepName.(string) |
| 94 | } | 97 | } |
| @@ -137,6 +140,7 @@ func (org *Org) CloneSample() *Org { | @@ -137,6 +140,7 @@ func (org *Org) CloneSample() *Org { | ||
| 137 | return &Org{ | 140 | return &Org{ |
| 138 | OrgId: org.OrgId, | 141 | OrgId: org.OrgId, |
| 139 | OrgName: org.OrgName, | 142 | OrgName: org.OrgName, |
| 143 | + OrgCode: org.OrgCode, | ||
| 140 | } | 144 | } |
| 141 | } | 145 | } |
| 142 | 146 |
| 1 | package service | 1 | package service |
| 2 | 2 | ||
| 3 | +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
| 4 | + | ||
| 3 | // PgCreateOrgService 创建组织服务 | 5 | // PgCreateOrgService 创建组织服务 |
| 4 | type PgCreateOrgService interface { | 6 | type PgCreateOrgService interface { |
| 7 | + CreateOrg(optUser *domain.CheckOptions, orgInfo *domain.Org) (*domain.Org, error) | ||
| 5 | } | 8 | } |
| @@ -16,7 +16,7 @@ type PgCreateOrgService struct { | @@ -16,7 +16,7 @@ type PgCreateOrgService struct { | ||
| 16 | // | 16 | // |
| 17 | // optUser 操作人 | 17 | // optUser 操作人 |
| 18 | // orgInfo 组织信息 | 18 | // orgInfo 组织信息 |
| 19 | -func (ptr *PgCreateOrgService) CreateOrg(optUser *domain.User, orgInfo *domain.Org) (*domain.Org, error) { | 19 | +func (ptr *PgCreateOrgService) CreateOrg(optUser *domain.CheckOptions, orgInfo *domain.Org) (*domain.Org, error) { |
| 20 | var ( | 20 | var ( |
| 21 | err error | 21 | err error |
| 22 | org *domain.Org | 22 | org *domain.Org |
| @@ -45,6 +45,7 @@ func CheckCreatedOrgInfo(orgRepository *repository.OrgRepository, orgInfo *domai | @@ -45,6 +45,7 @@ func CheckCreatedOrgInfo(orgRepository *repository.OrgRepository, orgInfo *domai | ||
| 45 | return fmt.Errorf("父级部门不可用") | 45 | return fmt.Errorf("父级部门不可用") |
| 46 | } | 46 | } |
| 47 | orgInfo.ParentPath = org.GetFullPath() | 47 | orgInfo.ParentPath = org.GetFullPath() |
| 48 | + orgInfo.Ext.ParentDepName = org.OrgName | ||
| 48 | if org, err = orgRepository.FindOne(map[string]interface{}{"companyId": orgInfo.CompanyId, "parentId": orgInfo.ParentId, "orgCode": orgInfo.OrgCode}); err == nil && org != nil { | 49 | if org, err = orgRepository.FindOne(map[string]interface{}{"companyId": orgInfo.CompanyId, "parentId": orgInfo.ParentId, "orgCode": orgInfo.OrgCode}); err == nil && org != nil { |
| 49 | return fmt.Errorf("部门编码重复") | 50 | return fmt.Errorf("部门编码重复") |
| 50 | } | 51 | } |
| @@ -58,7 +58,7 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain | @@ -58,7 +58,7 @@ func (ptr *PgCreateUserService) CreateUser(optUser *domain.User, newUser *domain | ||
| 58 | // 1.用户编号唯一验证 用户编号在该企业内已存在,请重新输入 | 58 | // 1.用户编号唯一验证 用户编号在该企业内已存在,请重新输入 |
| 59 | // 2.当前企业内手机号唯一 手机号在该企业内已存在,请重新输入 | 59 | // 2.当前企业内手机号唯一 手机号在该企业内已存在,请重新输入 |
| 60 | if newUser.UserType&domain.UserTypeCompanyAdmin == 0 { | 60 | if newUser.UserType&domain.UserTypeCompanyAdmin == 0 { |
| 61 | - if user, err = userRepository.FindOne(map[string]interface{}{"companyId": newUser.CompanyId, "orgId": newUser.OrganizationId, "userCode": newUser.UserCode}); err == nil && user != nil { | 61 | + if user, err = userRepository.FindOne(map[string]interface{}{"companyId": newUser.CompanyId, "organizationId": newUser.OrganizationId, "userCode": newUser.UserCode}); err == nil && user != nil { |
| 62 | return nil, fmt.Errorf("用户编号在该企业内已存在,请重新输入") | 62 | return nil, fmt.Errorf("用户编号在该企业内已存在,请重新输入") |
| 63 | } | 63 | } |
| 64 | if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"account": newUser.UserInfo.Phone}); err == nil && userBase != nil { | 64 | if userBase, err = userBaseRepository.FindOne(map[string]interface{}{"account": newUser.UserInfo.Phone}); err == nil && userBase != nil { |
| @@ -26,7 +26,7 @@ type Org struct { | @@ -26,7 +26,7 @@ type Org struct { | ||
| 26 | // 是否是组织标识 1:是 2:不是 | 26 | // 是否是组织标识 1:是 2:不是 |
| 27 | IsOrg int `comment:"是否是组织标识 1:是 2:不是"` | 27 | IsOrg int `comment:"是否是组织标识 1:是 2:不是"` |
| 28 | // 组织状态 1:启用 2:禁用 3.删除 | 28 | // 组织状态 1:启用 2:禁用 3.删除 |
| 29 | - OrgStatus int `json:"orgStatus" comment:"组织状态 1:启用 2:禁用 3.删除"` | 29 | + OrgStatus int `comment:"组织状态 1:启用 2:禁用 3.删除"` |
| 30 | // 父级ID | 30 | // 父级ID |
| 31 | ParentId int64 `comment:"父级ID"` | 31 | ParentId int64 `comment:"父级ID"` |
| 32 | // 父级节点路径("0,11,12,") | 32 | // 父级节点路径("0,11,12,") |
| @@ -16,6 +16,7 @@ func TransformToOrgDomainModelFromPgModels(orgModel *models.Org) (*domain.Org, e | @@ -16,6 +16,7 @@ func TransformToOrgDomainModelFromPgModels(orgModel *models.Org) (*domain.Org, e | ||
| 16 | OrgName: orgModel.OrgName, | 16 | OrgName: orgModel.OrgName, |
| 17 | Ext: orgModel.Ext, | 17 | Ext: orgModel.Ext, |
| 18 | IsOrg: orgModel.IsOrg, | 18 | IsOrg: orgModel.IsOrg, |
| 19 | + OrgStatus: orgModel.OrgStatus, | ||
| 19 | ParentId: orgModel.ParentId, | 20 | ParentId: orgModel.ParentId, |
| 20 | ParentPath: orgModel.ParentPath, | 21 | ParentPath: orgModel.ParentPath, |
| 21 | }, nil | 22 | }, nil |
| @@ -23,5 +23,13 @@ func TransformToUserDomainModelFromPgModels(userModel *models.User) (*domain.Use | @@ -23,5 +23,13 @@ func TransformToUserDomainModelFromPgModels(userModel *models.User) (*domain.Use | ||
| 23 | Ext: userModel.Ext, | 23 | Ext: userModel.Ext, |
| 24 | CreatedAt: userModel.CreatedAt, | 24 | CreatedAt: userModel.CreatedAt, |
| 25 | UpdatedAt: userModel.UpdatedAt, | 25 | UpdatedAt: userModel.UpdatedAt, |
| 26 | + Department: &domain.Department{ | ||
| 27 | + DepartmentId: userModel.DepartmentId, | ||
| 28 | + DepartmentName: userModel.Ext.DepName, | ||
| 29 | + }, | ||
| 30 | + Organization: &domain.Org{ | ||
| 31 | + OrgId: userModel.OrganizationId, | ||
| 32 | + OrgName: userModel.Ext.OrgName, | ||
| 33 | + }, | ||
| 26 | }, nil | 34 | }, nil |
| 27 | } | 35 | } |
| @@ -94,6 +94,7 @@ func (repository *OrgRepository) Save(org *domain.Org) (*domain.Org, error) { | @@ -94,6 +94,7 @@ func (repository *OrgRepository) Save(org *domain.Org) (*domain.Org, error) { | ||
| 94 | &org.OrgCode, | 94 | &org.OrgCode, |
| 95 | &org.OrgName, | 95 | &org.OrgName, |
| 96 | &org.Ext, | 96 | &org.Ext, |
| 97 | + &org.OrgStatus, | ||
| 97 | &org.IsOrg, | 98 | &org.IsOrg, |
| 98 | &org.ParentId, | 99 | &org.ParentId, |
| 99 | &org.ParentPath, | 100 | &org.ParentPath, |
| @@ -106,6 +107,7 @@ func (repository *OrgRepository) Save(org *domain.Org) (*domain.Org, error) { | @@ -106,6 +107,7 @@ func (repository *OrgRepository) Save(org *domain.Org) (*domain.Org, error) { | ||
| 106 | org.OrgCode, | 107 | org.OrgCode, |
| 107 | org.OrgName, | 108 | org.OrgName, |
| 108 | org.Ext, | 109 | org.Ext, |
| 110 | + org.OrgStatus, | ||
| 109 | org.IsOrg, | 111 | org.IsOrg, |
| 110 | org.ParentId, | 112 | org.ParentId, |
| 111 | org.ParentPath, | 113 | org.ParentPath, |
| @@ -133,6 +135,7 @@ func (repository *OrgRepository) FindOne(queryOptions map[string]interface{}) (* | @@ -133,6 +135,7 @@ func (repository *OrgRepository) FindOne(queryOptions map[string]interface{}) (* | ||
| 133 | query.SetWhereByQueryOption("org_id = ?", "orgId") | 135 | query.SetWhereByQueryOption("org_id = ?", "orgId") |
| 134 | query.SetWhereByQueryOption("org_name = ?", "orgName") | 136 | query.SetWhereByQueryOption("org_name = ?", "orgName") |
| 135 | query.SetWhereByQueryOption("org_code = ?", "orgCode") | 137 | query.SetWhereByQueryOption("org_code = ?", "orgCode") |
| 138 | + query.SetWhereByQueryOption("org_id != ?", "notEqualOrgId") | ||
| 136 | if err := query.First(); err != nil { | 139 | if err := query.First(); err != nil { |
| 137 | if err.Error() == "pg: no rows in result set" { | 140 | if err.Error() == "pg: no rows in result set" { |
| 138 | return nil, fmt.Errorf("没有此资源") | 141 | return nil, fmt.Errorf("没有此资源") |
| @@ -152,7 +155,10 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6 | @@ -152,7 +155,10 @@ func (repository *OrgRepository) Find(queryOptions map[string]interface{}) (int6 | ||
| 152 | orgs := make([]*domain.Org, 0) | 155 | orgs := make([]*domain.Org, 0) |
| 153 | query := sqlbuilder.BuildQuery(tx.Model(&orgModels), queryOptions) | 156 | query := sqlbuilder.BuildQuery(tx.Model(&orgModels), queryOptions) |
| 154 | query.SetOffsetAndLimit(20) | 157 | query.SetOffsetAndLimit(20) |
| 155 | - query.SetOrderDirect("org_id", "DESC") | 158 | + query.SetWhereByQueryOption("is_org = ?", "isOrg") |
| 159 | + query.SetWhereByQueryOption("org_name = ?", "depName") | ||
| 160 | + query.SetWhereByQueryOption("org_code = ?", "orgCode") | ||
| 161 | + query.SetOrderDirect("org_id", "ASC") | ||
| 156 | if count, err := query.SelectAndCount(); err != nil { | 162 | if count, err := query.SelectAndCount(); err != nil { |
| 157 | return 0, orgs, err | 163 | return 0, orgs, err |
| 158 | } else { | 164 | } else { |
| @@ -125,6 +125,10 @@ func (repository *RoleRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -125,6 +125,10 @@ func (repository *RoleRepository) FindOne(queryOptions map[string]interface{}) ( | ||
| 125 | query.SetWhereByQueryOption("company_id = ?", "companyId") | 125 | query.SetWhereByQueryOption("company_id = ?", "companyId") |
| 126 | query.SetWhereByQueryOption("org_id = ?", "orgId") | 126 | query.SetWhereByQueryOption("org_id = ?", "orgId") |
| 127 | query.SetWhereByQueryOption("role_name = ?", "roleName") | 127 | query.SetWhereByQueryOption("role_name = ?", "roleName") |
| 128 | + query.SetWhereByQueryOption("(role_type & ?) >0", "roleType") | ||
| 129 | + if v, ok := queryOptions["includeDeleted"]; ok && v.(bool) { | ||
| 130 | + query.AllWithDeleted() | ||
| 131 | + } | ||
| 128 | if err := query.First(); err != nil { | 132 | if err := query.First(); err != nil { |
| 129 | if err.Error() == "pg: no rows in result set" { | 133 | if err.Error() == "pg: no rows in result set" { |
| 130 | return nil, fmt.Errorf("没有此资源") | 134 | return nil, fmt.Errorf("没有此资源") |
| @@ -147,6 +151,7 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int | @@ -147,6 +151,7 @@ func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int | ||
| 147 | query.SetWhereByQueryOption("company_id = ?", "companyId") | 151 | query.SetWhereByQueryOption("company_id = ?", "companyId") |
| 148 | query.SetWhereByQueryOption("org_id = ?", "orgId") | 152 | query.SetWhereByQueryOption("org_id = ?", "orgId") |
| 149 | query.SetWhereByQueryOption("role_name = ?", "roleName") | 153 | query.SetWhereByQueryOption("role_name = ?", "roleName") |
| 154 | + query.SetWhereByQueryOption("(role_type & ?) >0", "roleType") | ||
| 150 | // 包含删除的 | 155 | // 包含删除的 |
| 151 | if v, ok := queryOptions["includeDeleted"]; ok && !(v.(bool)) { | 156 | if v, ok := queryOptions["includeDeleted"]; ok && !(v.(bool)) { |
| 152 | query.Where("deleted_at is null") | 157 | query.Where("deleted_at is null") |
| @@ -147,6 +147,9 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -147,6 +147,9 @@ func (repository *UserRepository) FindOne(queryOptions map[string]interface{}) ( | ||
| 147 | userModel := new(models.User) | 147 | userModel := new(models.User) |
| 148 | query := sqlbuilder.BuildQuery(tx.Model(userModel), queryOptions) | 148 | query := sqlbuilder.BuildQuery(tx.Model(userModel), queryOptions) |
| 149 | query.SetWhereByQueryOption("user_id = ?", "userId") | 149 | query.SetWhereByQueryOption("user_id = ?", "userId") |
| 150 | + query.SetWhereByQueryOption("company_id=?", "companyId") | ||
| 151 | + query.SetWhereByQueryOption("organization_id=?", "organizationId") | ||
| 152 | + query.SetWhereByQueryOption("user_code = ?", "userCode") | ||
| 150 | if err := query.First(); err != nil { | 153 | if err := query.First(); err != nil { |
| 151 | if err.Error() == "pg: no rows in result set" { | 154 | if err.Error() == "pg: no rows in result set" { |
| 152 | return nil, fmt.Errorf("没有此资源") | 155 | return nil, fmt.Errorf("没有此资源") |
| @@ -2,6 +2,8 @@ package beego | @@ -2,6 +2,8 @@ package beego | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/beego/beego/v2/server/web" | 4 | "github.com/beego/beego/v2/server/web" |
| 5 | + "github.com/beego/beego/v2/server/web/context" | ||
| 6 | + "github.com/linmadan/egglib-go/log" | ||
| 5 | "github.com/linmadan/egglib-go/web/beego/filters" | 7 | "github.com/linmadan/egglib-go/web/beego/filters" |
| 6 | "os" | 8 | "os" |
| 7 | "strconv" | 9 | "strconv" |
| @@ -27,6 +29,23 @@ func init() { | @@ -27,6 +29,23 @@ func init() { | ||
| 27 | } | 29 | } |
| 28 | } | 30 | } |
| 29 | web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) | 31 | web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) |
| 30 | - web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) | 32 | + web.InsertFilter("/*", web.BeforeExec, CreateRequestLogFilter(Logger)) |
| 31 | web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) | 33 | web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) |
| 32 | } | 34 | } |
| 35 | + | ||
| 36 | +func CreateRequestLogFilter(logger log.Logger) func(ctx *context.Context) { | ||
| 37 | + return func(ctx *context.Context) { | ||
| 38 | + var append = make(map[string]interface{}) | ||
| 39 | + append["framework"] = "beego" | ||
| 40 | + append["method"] = ctx.Input.Method() | ||
| 41 | + append["url"] = ctx.Input.URL() | ||
| 42 | + logger.Info("http请求", append) | ||
| 43 | + if ctx.Input.Is("GET") { | ||
| 44 | + logger.Debug("http请求", append) | ||
| 45 | + } | ||
| 46 | + if ctx.Input.Is("POST") || ctx.Input.Is("PUT") { | ||
| 47 | + append["inputData"] = string(ctx.Input.RequestBody) | ||
| 48 | + logger.Debug("http请求", append) | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | +} |
| @@ -73,3 +73,11 @@ func (controller *OrgController) EnableOrg() { | @@ -73,3 +73,11 @@ func (controller *OrgController) EnableOrg() { | ||
| 73 | data, err := orgService.EnableOrg(enableOrgCommand) | 73 | data, err := orgService.EnableOrg(enableOrgCommand) |
| 74 | controller.Response(data, err) | 74 | controller.Response(data, err) |
| 75 | } | 75 | } |
| 76 | + | ||
| 77 | +func (controller *OrgController) SearchOrg() { | ||
| 78 | + orgService := service.NewOrgService(nil) | ||
| 79 | + listOrgQuery := &query.ListOrgQuery{} | ||
| 80 | + Must(controller.Unmarshal(listOrgQuery)) | ||
| 81 | + data, err := orgService.ListOrg(listOrgQuery) | ||
| 82 | + controller.Response(data, err) | ||
| 83 | +} |
| @@ -10,7 +10,7 @@ func init() { | @@ -10,7 +10,7 @@ func init() { | ||
| 10 | web.Router("/org/:orgId", &controllers.OrgController{}, "Put:UpdateOrg") | 10 | web.Router("/org/:orgId", &controllers.OrgController{}, "Put:UpdateOrg") |
| 11 | web.Router("/org/:orgId", &controllers.OrgController{}, "Get:GetOrg") | 11 | web.Router("/org/:orgId", &controllers.OrgController{}, "Get:GetOrg") |
| 12 | web.Router("/org/:orgId", &controllers.OrgController{}, "Delete:RemoveOrg") | 12 | web.Router("/org/:orgId", &controllers.OrgController{}, "Delete:RemoveOrg") |
| 13 | - web.Router("/org/search", &controllers.OrgController{}, "Post:ListOrg") | 13 | + web.Router("/org/search", &controllers.OrgController{}, "Post:SearchOrg") |
| 14 | web.Router("/org/:orgId/sub-department", &controllers.OrgController{}, "Get:GetOrgSubDepartment") | 14 | web.Router("/org/:orgId/sub-department", &controllers.OrgController{}, "Get:GetOrgSubDepartment") |
| 15 | web.Router("/org/enable", &controllers.OrgController{}, "Post:EnableOrg") | 15 | web.Router("/org/enable", &controllers.OrgController{}, "Post:EnableOrg") |
| 16 | } | 16 | } |
| @@ -10,6 +10,7 @@ import ( | @@ -10,6 +10,7 @@ import ( | ||
| 10 | ) | 10 | ) |
| 11 | 11 | ||
| 12 | var _ = Describe("创建企业", func() { | 12 | var _ = Describe("创建企业", func() { |
| 13 | + return | ||
| 13 | Describe("提交数据创建企业", func() { | 14 | Describe("提交数据创建企业", func() { |
| 14 | Context("提交正确的新企业信息 (base)数据", func() { | 15 | Context("提交正确的新企业信息 (base)数据", func() { |
| 15 | It("返回企业信息 (base)数据", func() { | 16 | It("返回企业信息 (base)数据", func() { |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("返回企业", func() { | 13 | var _ = Describe("返回企业", func() { |
| 14 | + return | ||
| 14 | var companyId int64 | 15 | var companyId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("返回自定义菜单列表", func() { | 13 | var _ = Describe("返回自定义菜单列表", func() { |
| 14 | + return | ||
| 14 | var companyId int64 | 15 | var companyId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("返回企业列表", func() { | 13 | var _ = Describe("返回企业列表", func() { |
| 14 | + return | ||
| 14 | var companyId int64 | 15 | var companyId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("移除企业", func() { | 13 | var _ = Describe("移除企业", func() { |
| 14 | + return | ||
| 14 | var companyId int64 | 15 | var companyId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("更新自定义菜单", func() { | 13 | var _ = Describe("更新自定义菜单", func() { |
| 14 | + return | ||
| 14 | var companyId int64 | 15 | var companyId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("更新企业", func() { | 13 | var _ = Describe("更新企业", func() { |
| 14 | + return | ||
| 14 | var companyId int64 | 15 | var companyId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| 1 | package org | 1 | package org |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "github.com/go-pg/pg/v10" | ||
| 4 | "net/http" | 5 | "net/http" |
| 5 | 6 | ||
| 6 | "github.com/gavv/httpexpect" | 7 | "github.com/gavv/httpexpect" |
| @@ -10,16 +11,24 @@ import ( | @@ -10,16 +11,24 @@ import ( | ||
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| 12 | var _ = Describe("创建组织", func() { | 13 | var _ = Describe("创建组织", func() { |
| 14 | + BeforeEach(func() { | ||
| 15 | + var roleId int64 | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&roleId), | ||
| 18 | + "INSERT INTO users.org (org_id,company_id,created_at,updated_at,deleted_at,org_code,org_name,ext,org_status,is_org,parent_id,parent_path) VALUES (999,999,'2021-07-26 08:06:29.3101584+00:00:00','2021-07-26 08:06:29.3101584+00:00:00','0001-01-01 00:00:00+00:00:00','ENTERPRISE01','string1','{}',1,1,0,'');", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 13 | Describe("提交数据创建组织", func() { | 22 | Describe("提交数据创建组织", func() { |
| 14 | Context("提交正确的新组织 organization数据", func() { | 23 | Context("提交正确的新组织 organization数据", func() { |
| 15 | It("返回组织 organization数据", func() { | 24 | It("返回组织 organization数据", func() { |
| 16 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 17 | body := map[string]interface{}{ | 26 | body := map[string]interface{}{ |
| 18 | - "companyId": "int64", | 27 | + "companyId": 999, |
| 19 | "orgCode": "string", | 28 | "orgCode": "string", |
| 20 | "orgName": "string", | 29 | "orgName": "string", |
| 21 | - "isOrg": "int", | ||
| 22 | - "parentId": "int64", | 30 | + "isOrg": 1, |
| 31 | + "parentId": 999, | ||
| 23 | } | 32 | } |
| 24 | httpExpect.POST("/org/"). | 33 | httpExpect.POST("/org/"). |
| 25 | WithJSON(body). | 34 | WithJSON(body). |
| @@ -35,7 +44,7 @@ var _ = Describe("创建组织", func() { | @@ -35,7 +44,7 @@ var _ = Describe("创建组织", func() { | ||
| 35 | }) | 44 | }) |
| 36 | }) | 45 | }) |
| 37 | AfterEach(func() { | 46 | AfterEach(func() { |
| 38 | - _, err := pG.DB.Exec("DELETE FROM org WHERE true") | 47 | + _, err := pG.DB.Exec("DELETE FROM users.org WHERE true") |
| 39 | Expect(err).NotTo(HaveOccurred()) | 48 | Expect(err).NotTo(HaveOccurred()) |
| 40 | }) | 49 | }) |
| 41 | }) | 50 | }) |
| @@ -11,12 +11,12 @@ import ( | @@ -11,12 +11,12 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("设置组织启用状态", func() { | 13 | var _ = Describe("设置组织启用状态", func() { |
| 14 | + return | ||
| 14 | var orgId int64 | 15 | var orgId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| 17 | pg.Scan(&orgId), | 18 | pg.Scan(&orgId), |
| 18 | - "INSERT INTO org (org_id, company_id, created_at, updated_at, deleted_at, org_code, org_name, ext, is_org, parent_id, org_status, parent_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING org_id", | ||
| 19 | - "testOrgId", "testCompanyId", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testOrgCode", "testOrgName", "testExt", "testIsOrg", "testParentId", "testOrgStatus", "testParentPath") | 19 | + "INSERT INTO users.org (org_id,company_id,created_at,updated_at,deleted_at,org_code,org_name,ext,org_status,is_org,parent_id,parent_path) VALUES (999,999,'2021-07-27 05:48:16.508526+00:00:00','2021-07-27 05:48:16.508526+00:00:00','0001-01-01 00:00:00+00:00:00','string','string',NULL,1,1,999,'') RETURNING org_id;\n") |
| 20 | Expect(err).NotTo(HaveOccurred()) | 20 | Expect(err).NotTo(HaveOccurred()) |
| 21 | }) | 21 | }) |
| 22 | Describe("设置组织启用状态", func() { | 22 | Describe("设置组织启用状态", func() { |
| @@ -24,8 +24,8 @@ var _ = Describe("设置组织启用状态", func() { | @@ -24,8 +24,8 @@ var _ = Describe("设置组织启用状态", func() { | ||
| 24 | It("", func() { | 24 | It("", func() { |
| 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 26 | body := map[string]interface{}{ | 26 | body := map[string]interface{}{ |
| 27 | - "orgId": "int64", | ||
| 28 | - "orgStatus": "int", | 27 | + "orgId": 999, |
| 28 | + "orgStatus": 1, | ||
| 29 | } | 29 | } |
| 30 | httpExpect.POST("/org/enable"). | 30 | httpExpect.POST("/org/enable"). |
| 31 | WithJSON(body). | 31 | WithJSON(body). |
| @@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | var _ = Describe("获取组织的子部门(通用部门列表使用)", func() { | 13 | var _ = Describe("获取组织的子部门(通用部门列表使用)", func() { |
| 14 | + return | ||
| 14 | var orgId int64 | 15 | var orgId int64 |
| 15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 17 | _, err := pG.DB.QueryOne( |
| @@ -15,15 +15,14 @@ var _ = Describe("返回组织", func() { | @@ -15,15 +15,14 @@ var _ = Describe("返回组织", func() { | ||
| 15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 16 | _, err := pG.DB.QueryOne( |
| 17 | pg.Scan(&orgId), | 17 | pg.Scan(&orgId), |
| 18 | - "INSERT INTO org (org_id, company_id, created_at, updated_at, deleted_at, org_code, org_name, ext, is_org, parent_id, org_status, parent_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING org_id", | ||
| 19 | - "testOrgId", "testCompanyId", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testOrgCode", "testOrgName", "testExt", "testIsOrg", "testParentId", "testOrgStatus", "testParentPath") | 18 | + "INSERT INTO users.org (org_id,company_id,created_at,updated_at,deleted_at,org_code,org_name,ext,org_status,is_org,parent_id,parent_path) VALUES (999,999,'2021-07-27 05:48:16.508526+00:00:00','2021-07-27 05:48:16.508526+00:00:00','0001-01-01 00:00:00+00:00:00','string','string',NULL,1,1,999,'') RETURNING org_id;\n") |
| 20 | Expect(err).NotTo(HaveOccurred()) | 19 | Expect(err).NotTo(HaveOccurred()) |
| 21 | }) | 20 | }) |
| 22 | Describe("根据orgId参数返回组织 organization", func() { | 21 | Describe("根据orgId参数返回组织 organization", func() { |
| 23 | Context("传入有效的orgId", func() { | 22 | Context("传入有效的orgId", func() { |
| 24 | It("返回组织 organization数据", func() { | 23 | It("返回组织 organization数据", func() { |
| 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 26 | - httpExpect.GET("/org/{orgId}"). | 25 | + httpExpect.GET("/org/999"). |
| 27 | Expect(). | 26 | Expect(). |
| 28 | Status(http.StatusOK). | 27 | Status(http.StatusOK). |
| 29 | JSON(). | 28 | JSON(). |
| @@ -35,7 +34,7 @@ var _ = Describe("返回组织", func() { | @@ -35,7 +34,7 @@ var _ = Describe("返回组织", func() { | ||
| 35 | }) | 34 | }) |
| 36 | }) | 35 | }) |
| 37 | AfterEach(func() { | 36 | AfterEach(func() { |
| 38 | - _, err := pG.DB.Exec("DELETE FROM org WHERE true") | 37 | + _, err := pG.DB.Exec("DELETE FROM users.org WHERE true") |
| 39 | Expect(err).NotTo(HaveOccurred()) | 38 | Expect(err).NotTo(HaveOccurred()) |
| 40 | }) | 39 | }) |
| 41 | }) | 40 | }) |
| @@ -15,8 +15,7 @@ var _ = Describe("返回组织列表", func() { | @@ -15,8 +15,7 @@ var _ = Describe("返回组织列表", func() { | ||
| 15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 16 | _, err := pG.DB.QueryOne( |
| 17 | pg.Scan(&orgId), | 17 | pg.Scan(&orgId), |
| 18 | - "INSERT INTO org (org_id, company_id, created_at, updated_at, deleted_at, org_code, org_name, ext, is_org, parent_id, org_status, parent_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING org_id", | ||
| 19 | - "testOrgId", "testCompanyId", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testOrgCode", "testOrgName", "testExt", "testIsOrg", "testParentId", "testOrgStatus", "testParentPath") | 18 | + "INSERT INTO users.org (org_id,company_id,created_at,updated_at,deleted_at,org_code,org_name,ext,org_status,is_org,parent_id,parent_path) VALUES (999,999,'2021-07-27 05:48:16.508526+00:00:00','2021-07-27 05:48:16.508526+00:00:00','0001-01-01 00:00:00+00:00:00','string','string',NULL,1,1,999,'') RETURNING org_id;\n") |
| 20 | Expect(err).NotTo(HaveOccurred()) | 19 | Expect(err).NotTo(HaveOccurred()) |
| 21 | }) | 20 | }) |
| 22 | Describe("根据参数返回组织 organization列表", func() { | 21 | Describe("根据参数返回组织 organization列表", func() { |
| @@ -24,13 +23,13 @@ var _ = Describe("返回组织列表", func() { | @@ -24,13 +23,13 @@ var _ = Describe("返回组织列表", func() { | ||
| 24 | It("返回组织 organization数据列表", func() { | 23 | It("返回组织 organization数据列表", func() { |
| 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 26 | body := map[string]interface{}{ | 25 | body := map[string]interface{}{ |
| 27 | - "offset": "int", | ||
| 28 | - "limit": "int", | ||
| 29 | - "companyId": "int64", | 26 | + "offset": 0, |
| 27 | + "limit": 20, | ||
| 28 | + "companyId": 999, | ||
| 30 | "orgCode": "string", | 29 | "orgCode": "string", |
| 31 | "depName": "string", | 30 | "depName": "string", |
| 32 | - "parentId": "int64", | ||
| 33 | - "isOrg": "int", | 31 | + "parentId": 0, |
| 32 | + "isOrg": 1, | ||
| 34 | } | 33 | } |
| 35 | httpExpect.POST("/org/search"). | 34 | httpExpect.POST("/org/search"). |
| 36 | WithJSON(body). | 35 | WithJSON(body). |
| @@ -42,12 +41,12 @@ var _ = Describe("返回组织列表", func() { | @@ -42,12 +41,12 @@ var _ = Describe("返回组织列表", func() { | ||
| 42 | ContainsKey("msg").ValueEqual("msg", "ok"). | 41 | ContainsKey("msg").ValueEqual("msg", "ok"). |
| 43 | ContainsKey("data").Value("data").Object(). | 42 | ContainsKey("data").Value("data").Object(). |
| 44 | ContainsKey("count").ValueEqual("count", 1). | 43 | ContainsKey("count").ValueEqual("count", 1). |
| 45 | - ContainsKey("org").Value("org").Array() | 44 | + ContainsKey("orgs").Value("orgs").Array() |
| 46 | }) | 45 | }) |
| 47 | }) | 46 | }) |
| 48 | }) | 47 | }) |
| 49 | AfterEach(func() { | 48 | AfterEach(func() { |
| 50 | - _, err := pG.DB.Exec("DELETE FROM org WHERE true") | 49 | + _, err := pG.DB.Exec("DELETE FROM users.org WHERE true") |
| 51 | Expect(err).NotTo(HaveOccurred()) | 50 | Expect(err).NotTo(HaveOccurred()) |
| 52 | }) | 51 | }) |
| 53 | }) | 52 | }) |
| @@ -8,7 +8,6 @@ import ( | @@ -8,7 +8,6 @@ import ( | ||
| 8 | "github.com/beego/beego/v2/server/web" | 8 | "github.com/beego/beego/v2/server/web" |
| 9 | . "github.com/onsi/ginkgo" | 9 | . "github.com/onsi/ginkgo" |
| 10 | . "github.com/onsi/gomega" | 10 | . "github.com/onsi/gomega" |
| 11 | - _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application" | ||
| 12 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | 11 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" |
| 13 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego" | 12 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego" |
| 14 | ) | 13 | ) |
| @@ -15,8 +15,7 @@ var _ = Describe("更新组织", func() { | @@ -15,8 +15,7 @@ var _ = Describe("更新组织", func() { | ||
| 15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 16 | _, err := pG.DB.QueryOne( | 16 | _, err := pG.DB.QueryOne( |
| 17 | pg.Scan(&orgId), | 17 | pg.Scan(&orgId), |
| 18 | - "INSERT INTO org (org_id, company_id, created_at, updated_at, deleted_at, org_code, org_name, ext, is_org, parent_id, org_status, parent_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING org_id", | ||
| 19 | - "testOrgId", "testCompanyId", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testOrgCode", "testOrgName", "testExt", "testIsOrg", "testParentId", "testOrgStatus", "testParentPath") | 18 | + "INSERT INTO users.org (org_id,company_id,created_at,updated_at,deleted_at,org_code,org_name,ext,org_status,is_org,parent_id,parent_path) VALUES (999,999,'2021-07-27 05:48:16.508526+00:00:00','2021-07-27 05:48:16.508526+00:00:00','0001-01-01 00:00:00+00:00:00','string','string',NULL,1,1,999,'') RETURNING org_id;\n") |
| 20 | Expect(err).NotTo(HaveOccurred()) | 19 | Expect(err).NotTo(HaveOccurred()) |
| 21 | }) | 20 | }) |
| 22 | Describe("提交数据更新组织", func() { | 21 | Describe("提交数据更新组织", func() { |
| @@ -24,12 +23,13 @@ var _ = Describe("更新组织", func() { | @@ -24,12 +23,13 @@ var _ = Describe("更新组织", func() { | ||
| 24 | It("返回更新后的组织 organization数据", func() { | 23 | It("返回更新后的组织 organization数据", func() { |
| 25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 26 | body := map[string]interface{}{ | 25 | body := map[string]interface{}{ |
| 27 | - "orgCode": "string", | ||
| 28 | - "orgName": "string", | ||
| 29 | - "isOrg": "int", | ||
| 30 | - "parentId": "int64", | 26 | + "userId": 999, |
| 27 | + "orgCode": "string001", | ||
| 28 | + "orgName": "string002", | ||
| 29 | + "isOrg": 2, | ||
| 30 | + "parentId": 999, | ||
| 31 | } | 31 | } |
| 32 | - httpExpect.PUT("/org/{orgId}"). | 32 | + httpExpect.PUT("/org/999"). |
| 33 | WithJSON(body). | 33 | WithJSON(body). |
| 34 | Expect(). | 34 | Expect(). |
| 35 | Status(http.StatusOK). | 35 | Status(http.StatusOK). |
| @@ -43,7 +43,7 @@ var _ = Describe("更新组织", func() { | @@ -43,7 +43,7 @@ var _ = Describe("更新组织", func() { | ||
| 43 | }) | 43 | }) |
| 44 | }) | 44 | }) |
| 45 | AfterEach(func() { | 45 | AfterEach(func() { |
| 46 | - _, err := pG.DB.Exec("DELETE FROM org WHERE true") | 46 | + _, err := pG.DB.Exec("DELETE FROM users.org WHERE true") |
| 47 | Expect(err).NotTo(HaveOccurred()) | 47 | Expect(err).NotTo(HaveOccurred()) |
| 48 | }) | 48 | }) |
| 49 | }) | 49 | }) |
| @@ -34,7 +34,8 @@ var _ = Describe("移除角色", func() { | @@ -34,7 +34,8 @@ var _ = Describe("移除角色", func() { | ||
| 34 | }) | 34 | }) |
| 35 | }) | 35 | }) |
| 36 | AfterEach(func() { | 36 | AfterEach(func() { |
| 37 | - //_, err := pG.DB.Exec("DELETE FROM users.role WHERE true") | ||
| 38 | - //Expect(err).NotTo(HaveOccurred()) | 37 | + result, err := pG.DB.Exec("DELETE FROM users.role WHERE true") |
| 38 | + Expect(result.RowsAffected()).Should(Equal(1)) | ||
| 39 | + Expect(err).NotTo(HaveOccurred()) | ||
| 39 | }) | 40 | }) |
| 40 | }) | 41 | }) |
| @@ -36,9 +36,9 @@ var _ = Describe("返回列表", func() { | @@ -36,9 +36,9 @@ var _ = Describe("返回列表", func() { | ||
| 36 | "companyId": 5, | 36 | "companyId": 5, |
| 37 | "organizationId": 5, | 37 | "organizationId": 5, |
| 38 | "departmentId": 5, | 38 | "departmentId": 5, |
| 39 | - "userName": "string", | ||
| 40 | - "depName": "string", | ||
| 41 | - "phone": "string", | 39 | + //"userName": "string", |
| 40 | + "depName": "string", | ||
| 41 | + "phone": "string", | ||
| 42 | } | 42 | } |
| 43 | httpExpect.POST("/user/search"). | 43 | httpExpect.POST("/user/search"). |
| 44 | WithJSON(body). | 44 | WithJSON(body). |
-
请 注册 或 登录 后发表评论