Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev
正在显示
26 个修改的文件
包含
1849 行增加
和
0 行删除
cmd/discuss/doc/dsl/api/department.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: department/v1 | ||
14 | + group: department | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getDepartment | ||
19 | + post /department/:id (DepartmentGetRequest) returns (DepartmentGetResponse) | ||
20 | + @handler saveDepartment | ||
21 | + post /department (DepartmentSaveRequest) returns (DepartmentSaveResponse) | ||
22 | + @handler deleteDepartment | ||
23 | + delete /department/:id (DepartmentDeleteRequest) returns (DepartmentDeleteResponse) | ||
24 | + @handler updateDepartment | ||
25 | + put /department/:id (DepartmentUpdateRequest) returns (DepartmentUpdateResponse) | ||
26 | + @handler searchDepartment | ||
27 | + post /department/search (DepartmentSearchRequest) returns (DepartmentSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + DepartmentGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + DepartmentGetResponse struct{ | ||
35 | + Department DepartmentItem `json:"department"` | ||
36 | + } | ||
37 | + | ||
38 | + DepartmentSaveRequest struct{ | ||
39 | + Department DepartmentItem `json:"department"` | ||
40 | + } | ||
41 | + DepartmentSaveResponse struct{} | ||
42 | + | ||
43 | + DepartmentDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + DepartmentDeleteResponse struct{} | ||
47 | + | ||
48 | + DepartmentUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + Department DepartmentItem `json:"department"` | ||
51 | + } | ||
52 | + DepartmentUpdateResponse struct{} | ||
53 | + | ||
54 | + DepartmentSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + DepartmentSearchResponse{ | ||
59 | + List []DepartmentItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + DepartmentItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/api/message_business.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: message_business/v1 | ||
14 | + group: message_business | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getMessageBusiness | ||
19 | + post /message_business/:id (MessageBusinessGetRequest) returns (MessageBusinessGetResponse) | ||
20 | + @handler saveMessageBusiness | ||
21 | + post /message_business (MessageBusinessSaveRequest) returns (MessageBusinessSaveResponse) | ||
22 | + @handler deleteMessageBusiness | ||
23 | + delete /message_business/:id (MessageBusinessDeleteRequest) returns (MessageBusinessDeleteResponse) | ||
24 | + @handler updateMessageBusiness | ||
25 | + put /message_business/:id (MessageBusinessUpdateRequest) returns (MessageBusinessUpdateResponse) | ||
26 | + @handler searchMessageBusiness | ||
27 | + post /message_business/search (MessageBusinessSearchRequest) returns (MessageBusinessSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + MessageBusinessGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + MessageBusinessGetResponse struct{ | ||
35 | + MessageBusiness MessageBusinessItem `json:"message_business"` | ||
36 | + } | ||
37 | + | ||
38 | + MessageBusinessSaveRequest struct{ | ||
39 | + MessageBusiness MessageBusinessItem `json:"message_business"` | ||
40 | + } | ||
41 | + MessageBusinessSaveResponse struct{} | ||
42 | + | ||
43 | + MessageBusinessDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + MessageBusinessDeleteResponse struct{} | ||
47 | + | ||
48 | + MessageBusinessUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + MessageBusiness MessageBusinessItem `json:"message_business"` | ||
51 | + } | ||
52 | + MessageBusinessUpdateResponse struct{} | ||
53 | + | ||
54 | + MessageBusinessSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + MessageBusinessSearchResponse{ | ||
59 | + List []MessageBusinessItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + MessageBusinessItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/api/message_system.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: message_system/v1 | ||
14 | + group: message_system | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getMessageSystem | ||
19 | + post /message_system/:id (MessageSystemGetRequest) returns (MessageSystemGetResponse) | ||
20 | + @handler saveMessageSystem | ||
21 | + post /message_system (MessageSystemSaveRequest) returns (MessageSystemSaveResponse) | ||
22 | + @handler deleteMessageSystem | ||
23 | + delete /message_system/:id (MessageSystemDeleteRequest) returns (MessageSystemDeleteResponse) | ||
24 | + @handler updateMessageSystem | ||
25 | + put /message_system/:id (MessageSystemUpdateRequest) returns (MessageSystemUpdateResponse) | ||
26 | + @handler searchMessageSystem | ||
27 | + post /message_system/search (MessageSystemSearchRequest) returns (MessageSystemSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + MessageSystemGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + MessageSystemGetResponse struct{ | ||
35 | + MessageSystem MessageSystemItem `json:"message_system"` | ||
36 | + } | ||
37 | + | ||
38 | + MessageSystemSaveRequest struct{ | ||
39 | + MessageSystem MessageSystemItem `json:"message_system"` | ||
40 | + } | ||
41 | + MessageSystemSaveResponse struct{} | ||
42 | + | ||
43 | + MessageSystemDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + MessageSystemDeleteResponse struct{} | ||
47 | + | ||
48 | + MessageSystemUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + MessageSystem MessageSystemItem `json:"message_system"` | ||
51 | + } | ||
52 | + MessageSystemUpdateResponse struct{} | ||
53 | + | ||
54 | + MessageSystemSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + MessageSystemSearchResponse{ | ||
59 | + List []MessageSystemItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + MessageSystemItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/api/role.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: role/v1 | ||
14 | + group: role | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getRole | ||
19 | + post /role/:id (RoleGetRequest) returns (RoleGetResponse) | ||
20 | + @handler saveRole | ||
21 | + post /role (RoleSaveRequest) returns (RoleSaveResponse) | ||
22 | + @handler deleteRole | ||
23 | + delete /role/:id (RoleDeleteRequest) returns (RoleDeleteResponse) | ||
24 | + @handler updateRole | ||
25 | + put /role/:id (RoleUpdateRequest) returns (RoleUpdateResponse) | ||
26 | + @handler searchRole | ||
27 | + post /role/search (RoleSearchRequest) returns (RoleSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + RoleGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + RoleGetResponse struct{ | ||
35 | + Role RoleItem `json:"role"` | ||
36 | + } | ||
37 | + | ||
38 | + RoleSaveRequest struct{ | ||
39 | + Role RoleItem `json:"role"` | ||
40 | + } | ||
41 | + RoleSaveResponse struct{} | ||
42 | + | ||
43 | + RoleDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + RoleDeleteResponse struct{} | ||
47 | + | ||
48 | + RoleUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + Role RoleItem `json:"role"` | ||
51 | + } | ||
52 | + RoleUpdateResponse struct{} | ||
53 | + | ||
54 | + RoleSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + RoleSearchResponse{ | ||
59 | + List []RoleItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + RoleItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/api/user.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: user/v1 | ||
14 | + group: user | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getUser | ||
19 | + post /user/:id (UserGetRequest) returns (UserGetResponse) | ||
20 | + @handler saveUser | ||
21 | + post /user (UserSaveRequest) returns (UserSaveResponse) | ||
22 | + @handler deleteUser | ||
23 | + delete /user/:id (UserDeleteRequest) returns (UserDeleteResponse) | ||
24 | + @handler updateUser | ||
25 | + put /user/:id (UserUpdateRequest) returns (UserUpdateResponse) | ||
26 | + @handler searchUser | ||
27 | + post /user/search (UserSearchRequest) returns (UserSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + UserGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + UserGetResponse struct{ | ||
35 | + User UserItem `json:"user"` | ||
36 | + } | ||
37 | + | ||
38 | + UserSaveRequest struct{ | ||
39 | + User UserItem `json:"user"` | ||
40 | + } | ||
41 | + UserSaveResponse struct{} | ||
42 | + | ||
43 | + UserDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + UserDeleteResponse struct{} | ||
47 | + | ||
48 | + UserUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + User UserItem `json:"user"` | ||
51 | + } | ||
52 | + UserUpdateResponse struct{} | ||
53 | + | ||
54 | + UserSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + UserSearchResponse{ | ||
59 | + List []UserItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + UserItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/rpc/department.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message DepartmentGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message DepartmentGetResp{ | ||
12 | + DepartmentItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message DepartmentSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message DepartmentSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message DepartmentDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message DepartmentDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message DepartmentUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message DepartmentUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message DepartmentSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message DepartmentSearchResp{ | ||
41 | + repeated DepartmentItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message DepartmentItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service DepartmentService { | ||
49 | + rpc DepartmentGet(DepartmentGetReq) returns(DepartmentGetResp); | ||
50 | + rpc DepartmentSave(DepartmentSaveReq) returns(DepartmentSaveResp); | ||
51 | + rpc DepartmentDelete(DepartmentDeleteReq) returns(DepartmentDeleteResp); | ||
52 | + rpc DepartmentUpdate(DepartmentUpdateReq) returns(DepartmentUpdateResp); | ||
53 | + rpc DepartmentSearch(DepartmentSearchReq) returns(DepartmentSearchResp); | ||
54 | +} |
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message MessageBusinessGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message MessageBusinessGetResp{ | ||
12 | + MessageBusinessItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message MessageBusinessSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message MessageBusinessSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message MessageBusinessDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message MessageBusinessDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message MessageBusinessUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message MessageBusinessUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message MessageBusinessSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message MessageBusinessSearchResp{ | ||
41 | + repeated MessageBusinessItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message MessageBusinessItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service MessageBusinessService { | ||
49 | + rpc MessageBusinessGet(MessageBusinessGetReq) returns(MessageBusinessGetResp); | ||
50 | + rpc MessageBusinessSave(MessageBusinessSaveReq) returns(MessageBusinessSaveResp); | ||
51 | + rpc MessageBusinessDelete(MessageBusinessDeleteReq) returns(MessageBusinessDeleteResp); | ||
52 | + rpc MessageBusinessUpdate(MessageBusinessUpdateReq) returns(MessageBusinessUpdateResp); | ||
53 | + rpc MessageBusinessSearch(MessageBusinessSearchReq) returns(MessageBusinessSearchResp); | ||
54 | +} |
cmd/discuss/doc/dsl/rpc/message_system.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message MessageSystemGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message MessageSystemGetResp{ | ||
12 | + MessageSystemItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message MessageSystemSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message MessageSystemSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message MessageSystemDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message MessageSystemDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message MessageSystemUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message MessageSystemUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message MessageSystemSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message MessageSystemSearchResp{ | ||
41 | + repeated MessageSystemItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message MessageSystemItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service MessageSystemService { | ||
49 | + rpc MessageSystemGet(MessageSystemGetReq) returns(MessageSystemGetResp); | ||
50 | + rpc MessageSystemSave(MessageSystemSaveReq) returns(MessageSystemSaveResp); | ||
51 | + rpc MessageSystemDelete(MessageSystemDeleteReq) returns(MessageSystemDeleteResp); | ||
52 | + rpc MessageSystemUpdate(MessageSystemUpdateReq) returns(MessageSystemUpdateResp); | ||
53 | + rpc MessageSystemSearch(MessageSystemSearchReq) returns(MessageSystemSearchResp); | ||
54 | +} |
cmd/discuss/doc/dsl/rpc/role.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message RoleGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message RoleGetResp{ | ||
12 | + RoleItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message RoleSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message RoleSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message RoleDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message RoleDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message RoleUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message RoleUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message RoleSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message RoleSearchResp{ | ||
41 | + repeated RoleItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message RoleItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service RoleService { | ||
49 | + rpc RoleGet(RoleGetReq) returns(RoleGetResp); | ||
50 | + rpc RoleSave(RoleSaveReq) returns(RoleSaveResp); | ||
51 | + rpc RoleDelete(RoleDeleteReq) returns(RoleDeleteResp); | ||
52 | + rpc RoleUpdate(RoleUpdateReq) returns(RoleUpdateResp); | ||
53 | + rpc RoleSearch(RoleSearchReq) returns(RoleSearchResp); | ||
54 | +} |
cmd/discuss/doc/dsl/rpc/user.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message UserGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message UserGetResp{ | ||
12 | + UserItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message UserSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message UserSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message UserDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message UserDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message UserUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message UserUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message UserSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message UserSearchResp{ | ||
41 | + repeated UserItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message UserItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service UserService { | ||
49 | + rpc UserGet(UserGetReq) returns(UserGetResp); | ||
50 | + rpc UserSave(UserSaveReq) returns(UserSaveResp); | ||
51 | + rpc UserDelete(UserDeleteReq) returns(UserDeleteResp); | ||
52 | + rpc UserUpdate(UserUpdateReq) returns(UserUpdateResp); | ||
53 | + rpc UserSearch(UserSearchReq) returns(UserSearchResp); | ||
54 | +} |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | +) | ||
8 | + | ||
9 | +type Department struct { | ||
10 | + Id int64 // 唯一标识 | ||
11 | + | ||
12 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
13 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
14 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
15 | + Version int `json:"version,omitempty"` | ||
16 | +} | ||
17 | + | ||
18 | +func (m *Department) TableName() string { | ||
19 | + return "department" | ||
20 | +} | ||
21 | + | ||
22 | +func (m *Department) BeforeCreate(tx *gorm.DB) (err error) { | ||
23 | + // m.CreatedAt = time.Now().Unix() | ||
24 | + // m.UpdatedAt = time.Now().Unix() | ||
25 | + return | ||
26 | +} | ||
27 | + | ||
28 | +func (m *Department) BeforeUpdate(tx *gorm.DB) (err error) { | ||
29 | + // m.UpdatedAt = time.Now().Unix() | ||
30 | + return | ||
31 | +} | ||
32 | + | ||
33 | +func (m *Department) CacheKeyFunc() string { | ||
34 | + if m.Id == 0 { | ||
35 | + return "" | ||
36 | + } | ||
37 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
38 | +} | ||
39 | + | ||
40 | +func (m *Department) CacheKeyFuncByObject(obj interface{}) string { | ||
41 | + if v, ok := obj.(*Department); ok { | ||
42 | + return v.CacheKeyFunc() | ||
43 | + } | ||
44 | + return "" | ||
45 | +} | ||
46 | + | ||
47 | +func (m *Department) CachePrimaryKeyFunc() string { | ||
48 | + if len("") == 0 { | ||
49 | + return "" | ||
50 | + } | ||
51 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
52 | +} |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | + "gorm.io/plugin/soft_delete" | ||
8 | +) | ||
9 | + | ||
10 | +type MessageBusiness struct { | ||
11 | + Id int64 // 唯一标识 | ||
12 | + Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳) | ||
13 | + OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌) | ||
14 | + TriggerId int64 `json:"triggerId"` // 触发者ID | ||
15 | + RecipientId int64 `json:"recipientId"` // 接收者ID | ||
16 | + ArticleId int64 `json:"articleId"` // 文章ID | ||
17 | + CommentId int64 `json:"commentId"` // 评论ID | ||
18 | + DiscussionId int64 `json:"discussionId"` // 圆桌ID | ||
19 | + DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID | ||
20 | + Content string `json:"content"` // 消息内容 | ||
21 | + CreatedAt int64 `json:",omitempty"` | ||
22 | + UpdatedAt int64 `json:",omitempty"` | ||
23 | + DeletedAt int64 `json:",omitempty"` | ||
24 | + Version int `json:",omitempty"` | ||
25 | + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` | ||
26 | +} | ||
27 | + | ||
28 | +func (m *MessageBusiness) TableName() string { | ||
29 | + return "message_business" | ||
30 | +} | ||
31 | + | ||
32 | +func (m *MessageBusiness) BeforeCreate(tx *gorm.DB) (err error) { | ||
33 | + // m.CreatedAt = time.Now().Unix() | ||
34 | + // m.UpdatedAt = time.Now().Unix() | ||
35 | + return | ||
36 | +} | ||
37 | + | ||
38 | +func (m *MessageBusiness) BeforeUpdate(tx *gorm.DB) (err error) { | ||
39 | + // m.UpdatedAt = time.Now().Unix() | ||
40 | + return | ||
41 | +} | ||
42 | + | ||
43 | +func (m *MessageBusiness) CacheKeyFunc() string { | ||
44 | + if m.Id == 0 { | ||
45 | + return "" | ||
46 | + } | ||
47 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
48 | +} | ||
49 | + | ||
50 | +func (m *MessageBusiness) CacheKeyFuncByObject(obj interface{}) string { | ||
51 | + if v, ok := obj.(*MessageBusiness); ok { | ||
52 | + return v.CacheKeyFunc() | ||
53 | + } | ||
54 | + return "" | ||
55 | +} | ||
56 | + | ||
57 | +func (m *MessageBusiness) CachePrimaryKeyFunc() string { | ||
58 | + if len("") == 0 { | ||
59 | + return "" | ||
60 | + } | ||
61 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
62 | +} |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | + "gorm.io/plugin/soft_delete" | ||
8 | +) | ||
9 | + | ||
10 | +type MessageSystem struct { | ||
11 | + Id int64 // 唯一标识 | ||
12 | + RecipientId int64 `json:"recipientId"` // 接收者ID | ||
13 | + Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知) | ||
14 | + Title string `json:"title"` // 标题 | ||
15 | + Content string `json:"content"` // 内容 | ||
16 | + CreatedAt int64 `json:",omitempty"` | ||
17 | + UpdatedAt int64 `json:",omitempty"` | ||
18 | + DeletedAt int64 `json:",omitempty"` | ||
19 | + Version int `json:",omitempty"` | ||
20 | + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` | ||
21 | +} | ||
22 | + | ||
23 | +func (m *MessageSystem) TableName() string { | ||
24 | + return "message_system" | ||
25 | +} | ||
26 | + | ||
27 | +func (m *MessageSystem) BeforeCreate(tx *gorm.DB) (err error) { | ||
28 | + // m.CreatedAt = time.Now().Unix() | ||
29 | + // m.UpdatedAt = time.Now().Unix() | ||
30 | + return | ||
31 | +} | ||
32 | + | ||
33 | +func (m *MessageSystem) BeforeUpdate(tx *gorm.DB) (err error) { | ||
34 | + // m.UpdatedAt = time.Now().Unix() | ||
35 | + return | ||
36 | +} | ||
37 | + | ||
38 | +func (m *MessageSystem) CacheKeyFunc() string { | ||
39 | + if m.Id == 0 { | ||
40 | + return "" | ||
41 | + } | ||
42 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
43 | +} | ||
44 | + | ||
45 | +func (m *MessageSystem) CacheKeyFuncByObject(obj interface{}) string { | ||
46 | + if v, ok := obj.(*MessageSystem); ok { | ||
47 | + return v.CacheKeyFunc() | ||
48 | + } | ||
49 | + return "" | ||
50 | +} | ||
51 | + | ||
52 | +func (m *MessageSystem) CachePrimaryKeyFunc() string { | ||
53 | + if len("") == 0 { | ||
54 | + return "" | ||
55 | + } | ||
56 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
57 | +} |
cmd/discuss/interanl/pkg/db/models/role.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | + "time" | ||
8 | +) | ||
9 | + | ||
10 | +type Role struct { | ||
11 | + Id int64 // 唯一标识 | ||
12 | + | ||
13 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
14 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
15 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
16 | + Version int `json:"version,omitempty"` | ||
17 | +} | ||
18 | + | ||
19 | +func (m *Role) TableName() string { | ||
20 | + return "role" | ||
21 | +} | ||
22 | + | ||
23 | +func (m *Role) BeforeCreate(tx *gorm.DB) (err error) { | ||
24 | + m.CreatedAt = time.Now().Unix() | ||
25 | + m.UpdatedAt = time.Now().Unix() | ||
26 | + return | ||
27 | +} | ||
28 | + | ||
29 | +func (m *Role) BeforeUpdate(tx *gorm.DB) (err error) { | ||
30 | + m.UpdatedAt = time.Now().Unix() | ||
31 | + return | ||
32 | +} | ||
33 | + | ||
34 | +func (m *Role) CacheKeyFunc() string { | ||
35 | + if m.Id == 0 { | ||
36 | + return "" | ||
37 | + } | ||
38 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
39 | +} | ||
40 | + | ||
41 | +func (m *Role) CacheKeyFuncByObject(obj interface{}) string { | ||
42 | + if v, ok := obj.(*Role); ok { | ||
43 | + return v.CacheKeyFunc() | ||
44 | + } | ||
45 | + return "" | ||
46 | +} | ||
47 | + | ||
48 | +func (m *Role) CachePrimaryKeyFunc() string { | ||
49 | + if len("") == 0 { | ||
50 | + return "" | ||
51 | + } | ||
52 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
53 | +} |
cmd/discuss/interanl/pkg/db/models/user.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | + "time" | ||
8 | +) | ||
9 | + | ||
10 | +type User struct { | ||
11 | + Id int64 // 唯一标识 | ||
12 | + | ||
13 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
14 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
15 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
16 | + Version int `json:"version,omitempty"` | ||
17 | +} | ||
18 | + | ||
19 | +func (m *User) TableName() string { | ||
20 | + return "user" | ||
21 | +} | ||
22 | + | ||
23 | +func (m *User) BeforeCreate(tx *gorm.DB) (err error) { | ||
24 | + m.CreatedAt = time.Now().Unix() | ||
25 | + m.UpdatedAt = time.Now().Unix() | ||
26 | + return | ||
27 | +} | ||
28 | + | ||
29 | +func (m *User) BeforeUpdate(tx *gorm.DB) (err error) { | ||
30 | + m.UpdatedAt = time.Now().Unix() | ||
31 | + return | ||
32 | +} | ||
33 | + | ||
34 | +func (m *User) CacheKeyFunc() string { | ||
35 | + if m.Id == 0 { | ||
36 | + return "" | ||
37 | + } | ||
38 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
39 | +} | ||
40 | + | ||
41 | +func (m *User) CacheKeyFuncByObject(obj interface{}) string { | ||
42 | + if v, ok := obj.(*User); ok { | ||
43 | + return v.CacheKeyFunc() | ||
44 | + } | ||
45 | + return "" | ||
46 | +} | ||
47 | + | ||
48 | +func (m *User) CachePrimaryKeyFunc() string { | ||
49 | + if len("") == 0 { | ||
50 | + return "" | ||
51 | + } | ||
52 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
53 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | + "gorm.io/gorm" | ||
12 | +) | ||
13 | + | ||
14 | +type DepartmentRepository struct { | ||
15 | + *cache.CachedRepository | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *DepartmentRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
19 | + var ( | ||
20 | + err error | ||
21 | + m = &models.Department{} | ||
22 | + tx = conn.DB() | ||
23 | + ) | ||
24 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
28 | + return nil, tx.Error | ||
29 | + } | ||
30 | + dm.Id = m.Id | ||
31 | + return repository.ModelToDomainModel(m) | ||
32 | + | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *DepartmentRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
36 | + var ( | ||
37 | + err error | ||
38 | + m *models.Department | ||
39 | + tx = conn.DB() | ||
40 | + ) | ||
41 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + queryFunc := func() (interface{}, error) { | ||
45 | + tx = tx.Model(m).Updates(m) | ||
46 | + return nil, tx.Error | ||
47 | + } | ||
48 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return repository.ModelToDomainModel(m) | ||
52 | +} | ||
53 | + | ||
54 | +func (repository *DepartmentRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
55 | + var ( | ||
56 | + err error | ||
57 | + m *models.Department | ||
58 | + tx = transaction.DB() | ||
59 | + ) | ||
60 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
61 | + return nil, err | ||
62 | + } | ||
63 | + oldVersion := dm.Version | ||
64 | + m.Version += 1 | ||
65 | + queryFunc := func() (interface{}, error) { | ||
66 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
67 | + if tx.RowsAffected == 0 { | ||
68 | + return nil, domain.ErrUpdateFail | ||
69 | + } | ||
70 | + return nil, tx.Error | ||
71 | + } | ||
72 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + return repository.ModelToDomainModel(m) | ||
76 | +} | ||
77 | + | ||
78 | +func (repository *DepartmentRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
79 | + var ( | ||
80 | + tx = conn.DB() | ||
81 | + m = &models.Department{Id: dm.Identify().(int64)} | ||
82 | + ) | ||
83 | + queryFunc := func() (interface{}, error) { | ||
84 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
85 | + return m, tx.Error | ||
86 | + } | ||
87 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
88 | + return dm, err | ||
89 | + } | ||
90 | + return repository.ModelToDomainModel(m) | ||
91 | +} | ||
92 | + | ||
93 | +func (repository *DepartmentRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.Department, error) { | ||
94 | + var ( | ||
95 | + err error | ||
96 | + tx = conn.DB() | ||
97 | + m = new(models.Department) | ||
98 | + ) | ||
99 | + queryFunc := func() (interface{}, error) { | ||
100 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
101 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
102 | + return nil, domain.ErrNotFound | ||
103 | + } | ||
104 | + return m, tx.Error | ||
105 | + } | ||
106 | + cacheModel := new(models.Department) | ||
107 | + cacheModel.Id = id | ||
108 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + return repository.ModelToDomainModel(m) | ||
112 | +} | ||
113 | + | ||
114 | +func (repository *DepartmentRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Department, error) { | ||
115 | + var ( | ||
116 | + tx = conn.DB() | ||
117 | + ms []*models.Department | ||
118 | + dms = make([]*domain.Department, 0) | ||
119 | + total int64 | ||
120 | + ) | ||
121 | + queryFunc := func() (interface{}, error) { | ||
122 | + tx = tx.Model(&ms).Order("id desc") | ||
123 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
124 | + return dms, tx.Error | ||
125 | + } | ||
126 | + return dms, nil | ||
127 | + } | ||
128 | + | ||
129 | + if _, err := repository.Query(queryFunc); err != nil { | ||
130 | + return 0, nil, err | ||
131 | + } | ||
132 | + | ||
133 | + for _, item := range ms { | ||
134 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
135 | + return 0, dms, err | ||
136 | + } else { | ||
137 | + dms = append(dms, dm) | ||
138 | + } | ||
139 | + } | ||
140 | + return total, dms, nil | ||
141 | +} | ||
142 | + | ||
143 | +func (repository *DepartmentRepository) ModelToDomainModel(from *models.Department) (*domain.Department, error) { | ||
144 | + to := &domain.Department{} | ||
145 | + err := copier.Copy(to, from) | ||
146 | + return to, err | ||
147 | +} | ||
148 | + | ||
149 | +func (repository *DepartmentRepository) DomainModelToModel(from *domain.Department) (*models.Department, error) { | ||
150 | + to := &models.Department{} | ||
151 | + err := copier.Copy(to, from) | ||
152 | + return to, err | ||
153 | +} | ||
154 | + | ||
155 | +func NewDepartmentRepository(cache *cache.CachedRepository) domain.DepartmentRepository { | ||
156 | + return &DepartmentRepository{CachedRepository: cache} | ||
157 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gorm.io/gorm" | ||
9 | +) | ||
10 | + | ||
11 | +type MessageBusinessRepository struct { | ||
12 | + *cache.CachedRepository | ||
13 | +} | ||
14 | + | ||
15 | +func (repository *MessageBusinessRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.MessageBusiness) (*domain.MessageBusiness, error) { | ||
16 | + var ( | ||
17 | + err error | ||
18 | + m = &models.MessageBusiness{} | ||
19 | + tx = conn.DB() | ||
20 | + ) | ||
21 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
22 | + return nil, err | ||
23 | + } | ||
24 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
25 | + return nil, tx.Error | ||
26 | + } | ||
27 | + dm.Id = m.Id | ||
28 | + return repository.ModelToDomainModel(m) | ||
29 | + | ||
30 | +} | ||
31 | + | ||
32 | +func (repository *MessageBusinessRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.MessageBusiness) (*domain.MessageBusiness, error) { | ||
33 | + var ( | ||
34 | + err error | ||
35 | + m *models.MessageBusiness | ||
36 | + tx = conn.DB() | ||
37 | + ) | ||
38 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
39 | + return nil, err | ||
40 | + } | ||
41 | + queryFunc := func() (interface{}, error) { | ||
42 | + tx = tx.Model(m).Updates(m) | ||
43 | + return nil, tx.Error | ||
44 | + } | ||
45 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
46 | + return nil, err | ||
47 | + } | ||
48 | + return repository.ModelToDomainModel(m) | ||
49 | +} | ||
50 | + | ||
51 | +func (repository *MessageBusinessRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.MessageBusiness) (*domain.MessageBusiness, error) { | ||
52 | + var ( | ||
53 | + err error | ||
54 | + m *models.MessageBusiness | ||
55 | + tx = transaction.DB() | ||
56 | + ) | ||
57 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
58 | + return nil, err | ||
59 | + } | ||
60 | + oldVersion := dm.Version | ||
61 | + m.Version += 1 | ||
62 | + queryFunc := func() (interface{}, error) { | ||
63 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
64 | + if tx.RowsAffected == 0 { | ||
65 | + return nil, domain.ErrUpdateFail | ||
66 | + } | ||
67 | + return nil, tx.Error | ||
68 | + } | ||
69 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
70 | + return nil, err | ||
71 | + } | ||
72 | + return repository.ModelToDomainModel(m) | ||
73 | +} | ||
74 | + | ||
75 | +func (repository *MessageBusinessRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.MessageBusiness) (*domain.MessageBusiness, error) { | ||
76 | + var ( | ||
77 | + tx = conn.DB() | ||
78 | + m = &models.MessageBusiness{Id: dm.Identify().(int64)} | ||
79 | + ) | ||
80 | + queryFunc := func() (interface{}, error) { | ||
81 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
82 | + return m, tx.Error | ||
83 | + } | ||
84 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
85 | + return dm, err | ||
86 | + } | ||
87 | + return repository.ModelToDomainModel(m) | ||
88 | +} | ||
89 | + | ||
90 | +func (repository *MessageBusinessRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.MessageBusiness, error) { | ||
91 | + var ( | ||
92 | + err error | ||
93 | + tx = conn.DB() | ||
94 | + m = new(models.MessageBusiness) | ||
95 | + ) | ||
96 | + queryFunc := func() (interface{}, error) { | ||
97 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
98 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
99 | + return nil, domain.ErrNotFound | ||
100 | + } | ||
101 | + return m, tx.Error | ||
102 | + } | ||
103 | + cacheModel := new(models.MessageBusiness) | ||
104 | + cacheModel.Id = id | ||
105 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
106 | + return nil, err | ||
107 | + } | ||
108 | + return repository.ModelToDomainModel(m) | ||
109 | +} | ||
110 | + | ||
111 | +func (repository *MessageBusinessRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.MessageBusiness, error) { | ||
112 | + var ( | ||
113 | + tx = conn.DB() | ||
114 | + ms []*models.MessageBusiness | ||
115 | + dms = make([]*domain.MessageBusiness, 0) | ||
116 | + total int64 | ||
117 | + ) | ||
118 | + queryFunc := func() (interface{}, error) { | ||
119 | + tx = tx.Model(&ms).Order("id desc") | ||
120 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
121 | + return dms, tx.Error | ||
122 | + } | ||
123 | + return dms, nil | ||
124 | + } | ||
125 | + | ||
126 | + if _, err := repository.Query(queryFunc); err != nil { | ||
127 | + return 0, nil, err | ||
128 | + } | ||
129 | + | ||
130 | + for _, item := range ms { | ||
131 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
132 | + return 0, dms, err | ||
133 | + } else { | ||
134 | + dms = append(dms, dm) | ||
135 | + } | ||
136 | + } | ||
137 | + return total, dms, nil | ||
138 | +} | ||
139 | + | ||
140 | +func (repository *MessageBusinessRepository) ModelToDomainModel(from *models.MessageBusiness) (*domain.MessageBusiness, error) { | ||
141 | + to := &domain.MessageBusiness{} | ||
142 | + err := copier.Copy(to, from) | ||
143 | + return to, err | ||
144 | +} | ||
145 | + | ||
146 | +func (repository *MessageBusinessRepository) DomainModelToModel(from *domain.MessageBusiness) (*models.MessageBusiness, error) { | ||
147 | + to := &models.MessageBusiness{} | ||
148 | + err := copier.Copy(to, from) | ||
149 | + return to, err | ||
150 | +} | ||
151 | + | ||
152 | +func NewMessageBusinessRepository(cache *cache.CachedRepository) domain.MessageBusinessRepository { | ||
153 | + return &MessageBusinessRepository{CachedRepository: cache} | ||
154 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gorm.io/gorm" | ||
9 | +) | ||
10 | + | ||
11 | +type MessageSystemRepository struct { | ||
12 | + *cache.CachedRepository | ||
13 | +} | ||
14 | + | ||
15 | +func (repository *MessageSystemRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.MessageSystem) (*domain.MessageSystem, error) { | ||
16 | + var ( | ||
17 | + err error | ||
18 | + m = &models.MessageSystem{} | ||
19 | + tx = conn.DB() | ||
20 | + ) | ||
21 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
22 | + return nil, err | ||
23 | + } | ||
24 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
25 | + return nil, tx.Error | ||
26 | + } | ||
27 | + dm.Id = m.Id | ||
28 | + return repository.ModelToDomainModel(m) | ||
29 | + | ||
30 | +} | ||
31 | + | ||
32 | +func (repository *MessageSystemRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.MessageSystem) (*domain.MessageSystem, error) { | ||
33 | + var ( | ||
34 | + err error | ||
35 | + m *models.MessageSystem | ||
36 | + tx = conn.DB() | ||
37 | + ) | ||
38 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
39 | + return nil, err | ||
40 | + } | ||
41 | + queryFunc := func() (interface{}, error) { | ||
42 | + tx = tx.Model(m).Updates(m) | ||
43 | + return nil, tx.Error | ||
44 | + } | ||
45 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
46 | + return nil, err | ||
47 | + } | ||
48 | + return repository.ModelToDomainModel(m) | ||
49 | +} | ||
50 | + | ||
51 | +func (repository *MessageSystemRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.MessageSystem) (*domain.MessageSystem, error) { | ||
52 | + var ( | ||
53 | + err error | ||
54 | + m *models.MessageSystem | ||
55 | + tx = transaction.DB() | ||
56 | + ) | ||
57 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
58 | + return nil, err | ||
59 | + } | ||
60 | + oldVersion := dm.Version | ||
61 | + m.Version += 1 | ||
62 | + queryFunc := func() (interface{}, error) { | ||
63 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
64 | + if tx.RowsAffected == 0 { | ||
65 | + return nil, domain.ErrUpdateFail | ||
66 | + } | ||
67 | + return nil, tx.Error | ||
68 | + } | ||
69 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
70 | + return nil, err | ||
71 | + } | ||
72 | + return repository.ModelToDomainModel(m) | ||
73 | +} | ||
74 | + | ||
75 | +func (repository *MessageSystemRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.MessageSystem) (*domain.MessageSystem, error) { | ||
76 | + var ( | ||
77 | + tx = conn.DB() | ||
78 | + m = &models.MessageSystem{Id: dm.Identify().(int64)} | ||
79 | + ) | ||
80 | + queryFunc := func() (interface{}, error) { | ||
81 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
82 | + return m, tx.Error | ||
83 | + } | ||
84 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
85 | + return dm, err | ||
86 | + } | ||
87 | + return repository.ModelToDomainModel(m) | ||
88 | +} | ||
89 | + | ||
90 | +func (repository *MessageSystemRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.MessageSystem, error) { | ||
91 | + var ( | ||
92 | + err error | ||
93 | + tx = conn.DB() | ||
94 | + m = new(models.MessageSystem) | ||
95 | + ) | ||
96 | + queryFunc := func() (interface{}, error) { | ||
97 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
98 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
99 | + return nil, domain.ErrNotFound | ||
100 | + } | ||
101 | + return m, tx.Error | ||
102 | + } | ||
103 | + cacheModel := new(models.MessageSystem) | ||
104 | + cacheModel.Id = id | ||
105 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
106 | + return nil, err | ||
107 | + } | ||
108 | + return repository.ModelToDomainModel(m) | ||
109 | +} | ||
110 | + | ||
111 | +func (repository *MessageSystemRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.MessageSystem, error) { | ||
112 | + var ( | ||
113 | + tx = conn.DB() | ||
114 | + ms []*models.MessageSystem | ||
115 | + dms = make([]*domain.MessageSystem, 0) | ||
116 | + total int64 | ||
117 | + ) | ||
118 | + queryFunc := func() (interface{}, error) { | ||
119 | + tx = tx.Model(&ms).Order("id desc") | ||
120 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
121 | + return dms, tx.Error | ||
122 | + } | ||
123 | + return dms, nil | ||
124 | + } | ||
125 | + | ||
126 | + if _, err := repository.Query(queryFunc); err != nil { | ||
127 | + return 0, nil, err | ||
128 | + } | ||
129 | + | ||
130 | + for _, item := range ms { | ||
131 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
132 | + return 0, dms, err | ||
133 | + } else { | ||
134 | + dms = append(dms, dm) | ||
135 | + } | ||
136 | + } | ||
137 | + return total, dms, nil | ||
138 | +} | ||
139 | + | ||
140 | +func (repository *MessageSystemRepository) ModelToDomainModel(from *models.MessageSystem) (*domain.MessageSystem, error) { | ||
141 | + to := &domain.MessageSystem{} | ||
142 | + err := copier.Copy(to, from) | ||
143 | + return to, err | ||
144 | +} | ||
145 | + | ||
146 | +func (repository *MessageSystemRepository) DomainModelToModel(from *domain.MessageSystem) (*models.MessageSystem, error) { | ||
147 | + to := &models.MessageSystem{} | ||
148 | + err := copier.Copy(to, from) | ||
149 | + return to, err | ||
150 | +} | ||
151 | + | ||
152 | +func NewMessageSystemRepository(cache *cache.CachedRepository) domain.MessageSystemRepository { | ||
153 | + return &MessageSystemRepository{CachedRepository: cache} | ||
154 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | + "gorm.io/gorm" | ||
12 | +) | ||
13 | + | ||
14 | +type RoleRepository struct { | ||
15 | + *cache.CachedRepository | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *RoleRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
19 | + var ( | ||
20 | + err error | ||
21 | + m = &models.Role{} | ||
22 | + tx = conn.DB() | ||
23 | + ) | ||
24 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
28 | + return nil, tx.Error | ||
29 | + } | ||
30 | + dm.Id = m.Id | ||
31 | + return repository.ModelToDomainModel(m) | ||
32 | + | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *RoleRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
36 | + var ( | ||
37 | + err error | ||
38 | + m *models.Role | ||
39 | + tx = conn.DB() | ||
40 | + ) | ||
41 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + queryFunc := func() (interface{}, error) { | ||
45 | + tx = tx.Model(m).Updates(m) | ||
46 | + return nil, tx.Error | ||
47 | + } | ||
48 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return repository.ModelToDomainModel(m) | ||
52 | +} | ||
53 | + | ||
54 | +func (repository *RoleRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
55 | + var ( | ||
56 | + err error | ||
57 | + m *models.Role | ||
58 | + tx = transaction.DB() | ||
59 | + ) | ||
60 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
61 | + return nil, err | ||
62 | + } | ||
63 | + oldVersion := dm.Version | ||
64 | + m.Version += 1 | ||
65 | + queryFunc := func() (interface{}, error) { | ||
66 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
67 | + if tx.RowsAffected == 0 { | ||
68 | + return nil, domain.ErrUpdateFail | ||
69 | + } | ||
70 | + return nil, tx.Error | ||
71 | + } | ||
72 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + return repository.ModelToDomainModel(m) | ||
76 | +} | ||
77 | + | ||
78 | +func (repository *RoleRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
79 | + var ( | ||
80 | + tx = conn.DB() | ||
81 | + m = &models.Role{Id: dm.Identify().(int64)} | ||
82 | + ) | ||
83 | + queryFunc := func() (interface{}, error) { | ||
84 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
85 | + return m, tx.Error | ||
86 | + } | ||
87 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
88 | + return dm, err | ||
89 | + } | ||
90 | + return repository.ModelToDomainModel(m) | ||
91 | +} | ||
92 | + | ||
93 | +func (repository *RoleRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.Role, error) { | ||
94 | + var ( | ||
95 | + err error | ||
96 | + tx = conn.DB() | ||
97 | + m = new(models.Role) | ||
98 | + ) | ||
99 | + queryFunc := func() (interface{}, error) { | ||
100 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
101 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
102 | + return nil, domain.ErrNotFound | ||
103 | + } | ||
104 | + return m, tx.Error | ||
105 | + } | ||
106 | + cacheModel := new(models.Role) | ||
107 | + cacheModel.Id = id | ||
108 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + return repository.ModelToDomainModel(m) | ||
112 | +} | ||
113 | + | ||
114 | +func (repository *RoleRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Role, error) { | ||
115 | + var ( | ||
116 | + tx = conn.DB() | ||
117 | + ms []*models.Role | ||
118 | + dms = make([]*domain.Role, 0) | ||
119 | + total int64 | ||
120 | + ) | ||
121 | + queryFunc := func() (interface{}, error) { | ||
122 | + tx = tx.Model(&ms).Order("id desc") | ||
123 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
124 | + return dms, tx.Error | ||
125 | + } | ||
126 | + return dms, nil | ||
127 | + } | ||
128 | + | ||
129 | + if _, err := repository.Query(queryFunc); err != nil { | ||
130 | + return 0, nil, err | ||
131 | + } | ||
132 | + | ||
133 | + for _, item := range ms { | ||
134 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
135 | + return 0, dms, err | ||
136 | + } else { | ||
137 | + dms = append(dms, dm) | ||
138 | + } | ||
139 | + } | ||
140 | + return total, dms, nil | ||
141 | +} | ||
142 | + | ||
143 | +func (repository *RoleRepository) ModelToDomainModel(from *models.Role) (*domain.Role, error) { | ||
144 | + to := &domain.Role{} | ||
145 | + err := copier.Copy(to, from) | ||
146 | + return to, err | ||
147 | +} | ||
148 | + | ||
149 | +func (repository *RoleRepository) DomainModelToModel(from *domain.Role) (*models.Role, error) { | ||
150 | + to := &models.Role{} | ||
151 | + err := copier.Copy(to, from) | ||
152 | + return to, err | ||
153 | +} | ||
154 | + | ||
155 | +func NewRoleRepository(cache *cache.CachedRepository) domain.RoleRepository { | ||
156 | + return &RoleRepository{CachedRepository: cache} | ||
157 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | + "gorm.io/gorm" | ||
12 | +) | ||
13 | + | ||
14 | +type UserRepository struct { | ||
15 | + *cache.CachedRepository | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *UserRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
19 | + var ( | ||
20 | + err error | ||
21 | + m = &models.User{} | ||
22 | + tx = conn.DB() | ||
23 | + ) | ||
24 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
28 | + return nil, tx.Error | ||
29 | + } | ||
30 | + dm.Id = m.Id | ||
31 | + return repository.ModelToDomainModel(m) | ||
32 | + | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *UserRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
36 | + var ( | ||
37 | + err error | ||
38 | + m *models.User | ||
39 | + tx = conn.DB() | ||
40 | + ) | ||
41 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + queryFunc := func() (interface{}, error) { | ||
45 | + tx = tx.Model(m).Updates(m) | ||
46 | + return nil, tx.Error | ||
47 | + } | ||
48 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return repository.ModelToDomainModel(m) | ||
52 | +} | ||
53 | + | ||
54 | +func (repository *UserRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
55 | + var ( | ||
56 | + err error | ||
57 | + m *models.User | ||
58 | + tx = transaction.DB() | ||
59 | + ) | ||
60 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
61 | + return nil, err | ||
62 | + } | ||
63 | + oldVersion := dm.Version | ||
64 | + m.Version += 1 | ||
65 | + queryFunc := func() (interface{}, error) { | ||
66 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
67 | + if tx.RowsAffected == 0 { | ||
68 | + return nil, domain.ErrUpdateFail | ||
69 | + } | ||
70 | + return nil, tx.Error | ||
71 | + } | ||
72 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + return repository.ModelToDomainModel(m) | ||
76 | +} | ||
77 | + | ||
78 | +func (repository *UserRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
79 | + var ( | ||
80 | + tx = conn.DB() | ||
81 | + m = &models.User{Id: dm.Identify().(int64)} | ||
82 | + ) | ||
83 | + queryFunc := func() (interface{}, error) { | ||
84 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
85 | + return m, tx.Error | ||
86 | + } | ||
87 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
88 | + return dm, err | ||
89 | + } | ||
90 | + return repository.ModelToDomainModel(m) | ||
91 | +} | ||
92 | + | ||
93 | +func (repository *UserRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.User, error) { | ||
94 | + var ( | ||
95 | + err error | ||
96 | + tx = conn.DB() | ||
97 | + m = new(models.User) | ||
98 | + ) | ||
99 | + queryFunc := func() (interface{}, error) { | ||
100 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
101 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
102 | + return nil, domain.ErrNotFound | ||
103 | + } | ||
104 | + return m, tx.Error | ||
105 | + } | ||
106 | + cacheModel := new(models.User) | ||
107 | + cacheModel.Id = id | ||
108 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + return repository.ModelToDomainModel(m) | ||
112 | +} | ||
113 | + | ||
114 | +func (repository *UserRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.User, error) { | ||
115 | + var ( | ||
116 | + tx = conn.DB() | ||
117 | + ms []*models.User | ||
118 | + dms = make([]*domain.User, 0) | ||
119 | + total int64 | ||
120 | + ) | ||
121 | + queryFunc := func() (interface{}, error) { | ||
122 | + tx = tx.Model(&ms).Order("id desc") | ||
123 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
124 | + return dms, tx.Error | ||
125 | + } | ||
126 | + return dms, nil | ||
127 | + } | ||
128 | + | ||
129 | + if _, err := repository.Query(queryFunc); err != nil { | ||
130 | + return 0, nil, err | ||
131 | + } | ||
132 | + | ||
133 | + for _, item := range ms { | ||
134 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
135 | + return 0, dms, err | ||
136 | + } else { | ||
137 | + dms = append(dms, dm) | ||
138 | + } | ||
139 | + } | ||
140 | + return total, dms, nil | ||
141 | +} | ||
142 | + | ||
143 | +func (repository *UserRepository) ModelToDomainModel(from *models.User) (*domain.User, error) { | ||
144 | + to := &domain.User{} | ||
145 | + err := copier.Copy(to, from) | ||
146 | + return to, err | ||
147 | +} | ||
148 | + | ||
149 | +func (repository *UserRepository) DomainModelToModel(from *domain.User) (*models.User, error) { | ||
150 | + to := &models.User{} | ||
151 | + err := copier.Copy(to, from) | ||
152 | + return to, err | ||
153 | +} | ||
154 | + | ||
155 | +func NewUserRepository(cache *cache.CachedRepository) domain.UserRepository { | ||
156 | + return &UserRepository{CachedRepository: cache} | ||
157 | +} |
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type Department struct { | ||
9 | + Id int64 `json:"id,omitempty"` // 部门ID | ||
10 | + CompanyId int64 `json:"companyId,omitempty"` // 公司ID | ||
11 | + ParentId int64 `json:"parentId,omitempty"` // 父级ID | ||
12 | + Name string `json:"name,omitempty"` // 部门名称 | ||
13 | + | ||
14 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
15 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
16 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
17 | + Version int `json:"version,omitempty"` | ||
18 | +} | ||
19 | + | ||
20 | +type DepartmentRepository interface { | ||
21 | + Insert(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
22 | + Update(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
23 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
24 | + Delete(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
25 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Department, error) | ||
26 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Department, error) | ||
27 | +} | ||
28 | + | ||
29 | +func (m *Department) Identify() interface{} { | ||
30 | + if m.Id == 0 { | ||
31 | + return nil | ||
32 | + } | ||
33 | + return m.Id | ||
34 | +} |
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type MessageBusiness struct { | ||
9 | + Id int64 // 唯一标识 | ||
10 | + Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳) | ||
11 | + OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌) | ||
12 | + TriggerId int64 `json:"triggerId"` // 触发者ID | ||
13 | + RecipientId int64 `json:"recipientId"` // 接收者ID | ||
14 | + ArticleId int64 `json:"articleId"` // 文章ID | ||
15 | + CommentId int64 `json:"commentId"` // 评论ID | ||
16 | + DiscussionId int64 `json:"discussionId"` // 圆桌ID | ||
17 | + DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID | ||
18 | + Content string `json:"content"` // 消息内容 | ||
19 | + CreatedAt int64 `json:",omitempty"` | ||
20 | + UpdatedAt int64 `json:",omitempty"` | ||
21 | + DeletedAt int64 `json:",omitempty"` | ||
22 | + Version int `json:",omitempty"` | ||
23 | +} | ||
24 | + | ||
25 | +type MessageBusinessRepository interface { | ||
26 | + Insert(ctx context.Context, conn transaction.Conn, dm *MessageBusiness) (*MessageBusiness, error) | ||
27 | + Update(ctx context.Context, conn transaction.Conn, dm *MessageBusiness) (*MessageBusiness, error) | ||
28 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *MessageBusiness) (*MessageBusiness, error) | ||
29 | + Delete(ctx context.Context, conn transaction.Conn, dm *MessageBusiness) (*MessageBusiness, error) | ||
30 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*MessageBusiness, error) | ||
31 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*MessageBusiness, error) | ||
32 | +} | ||
33 | + | ||
34 | +func (m *MessageBusiness) Identify() interface{} { | ||
35 | + if m.Id == 0 { | ||
36 | + return nil | ||
37 | + } | ||
38 | + return m.Id | ||
39 | +} |
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type MessageSystem struct { | ||
9 | + Id int64 // 唯一标识 | ||
10 | + RecipientId int64 `json:"recipientId"` // 接收者ID | ||
11 | + Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知) | ||
12 | + Title string `json:"title"` // 标题 | ||
13 | + Content string `json:"content"` // 内容 | ||
14 | + CreatedAt int64 `json:",omitempty"` | ||
15 | + UpdatedAt int64 `json:",omitempty"` | ||
16 | + DeletedAt int64 `json:",omitempty"` | ||
17 | + Version int `json:",omitempty"` | ||
18 | +} | ||
19 | + | ||
20 | +type MessageSystemRepository interface { | ||
21 | + Insert(ctx context.Context, conn transaction.Conn, dm *MessageSystem) (*MessageSystem, error) | ||
22 | + Update(ctx context.Context, conn transaction.Conn, dm *MessageSystem) (*MessageSystem, error) | ||
23 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *MessageSystem) (*MessageSystem, error) | ||
24 | + Delete(ctx context.Context, conn transaction.Conn, dm *MessageSystem) (*MessageSystem, error) | ||
25 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*MessageSystem, error) | ||
26 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*MessageSystem, error) | ||
27 | +} | ||
28 | + | ||
29 | +func (m *MessageSystem) Identify() interface{} { | ||
30 | + if m.Id == 0 { | ||
31 | + return nil | ||
32 | + } | ||
33 | + return m.Id | ||
34 | +} |
cmd/discuss/interanl/pkg/domain/role.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type Role struct { | ||
9 | + Id int64 `json:"id"` // 角色ID | ||
10 | + Name string `json:"name"` // 角色名称 | ||
11 | + Auths []int64 `json:"auths"` // 角色权限列表 | ||
12 | + Remark string `json:"remark"` // 备注 | ||
13 | + Users []int64 `json:"users"` // 绑定的用户 | ||
14 | + | ||
15 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
16 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
17 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
18 | + Version int `json:"version,omitempty"` | ||
19 | +} | ||
20 | + | ||
21 | +type RoleRepository interface { | ||
22 | + Insert(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
23 | + Update(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
24 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
25 | + Delete(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
26 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Role, error) | ||
27 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Role, error) | ||
28 | +} | ||
29 | + | ||
30 | +func (m *Role) Identify() interface{} { | ||
31 | + if m.Id == 0 { | ||
32 | + return nil | ||
33 | + } | ||
34 | + return m.Id | ||
35 | +} |
cmd/discuss/interanl/pkg/domain/user.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type User struct { | ||
9 | + Id int64 `json:"id,omitempty"` // 用户ID | ||
10 | + CompanyId int64 `json:"companyId,omitempty"` // 公司ID | ||
11 | + DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID | ||
12 | + Roles []int64 `json:"roleId,omitempty"` // 角色 | ||
13 | + Flag int `json:"flag"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | ||
14 | + Name string `json:"name,omitempty"` // 名称 | ||
15 | + Avatar string `json:"avatar,omitempty"` // 头像 | ||
16 | + Phone string `json:"phone,omitempty"` // 手机号 唯一 | ||
17 | + Position string `json:"position,omitempty"` // 职位 | ||
18 | + Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 | ||
19 | + AuditStatus int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 | ||
20 | + | ||
21 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
22 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
23 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
24 | + Version int `json:"version,omitempty"` | ||
25 | +} | ||
26 | + | ||
27 | +type UserRepository interface { | ||
28 | + Insert(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
29 | + Update(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
30 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
31 | + Delete(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
32 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*User, error) | ||
33 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error) | ||
34 | +} | ||
35 | + | ||
36 | +func (m *User) Identify() interface{} { | ||
37 | + if m.Id == 0 { | ||
38 | + return nil | ||
39 | + } | ||
40 | + return m.Id | ||
41 | +} |
1 | CREATE TABLE `comment` ( | 1 | CREATE TABLE `comment` ( |
2 | `id` int(0) NOT NULL COMMENT '唯一标识', | 2 | `id` int(0) NOT NULL COMMENT '唯一标识', |
3 | PRIMARY KEY (`id`) USING BTREE | 3 | PRIMARY KEY (`id`) USING BTREE |
4 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
5 | + | ||
6 | +CREATE TABLE `department` ( | ||
7 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
8 | + PRIMARY KEY (`id`) USING BTREE | ||
9 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
10 | + | ||
11 | +CREATE TABLE `role` ( | ||
12 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
13 | + PRIMARY KEY (`id`) USING BTREE | ||
14 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
15 | + | ||
16 | +CREATE TABLE `user` ( | ||
17 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
18 | + PRIMARY KEY (`id`) USING BTREE | ||
4 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | 19 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; |
-
请 注册 或 登录 后发表评论