正在显示
16 个修改的文件
包含
681 行增加
和
14 行删除
@@ -3,7 +3,26 @@ module gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic | @@ -3,7 +3,26 @@ module gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic | ||
3 | go 1.16 | 3 | go 1.16 |
4 | 4 | ||
5 | require ( | 5 | require ( |
6 | + github.com/ajg/form v1.5.1 // indirect | ||
6 | github.com/beego/beego/v2 v2.0.1 | 7 | github.com/beego/beego/v2 v2.0.1 |
8 | + github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | ||
9 | + github.com/fatih/structs v1.1.0 // indirect | ||
10 | + github.com/gavv/httpexpect v2.0.0+incompatible | ||
7 | github.com/go-pg/pg/v10 v10.10.2 | 11 | github.com/go-pg/pg/v10 v10.10.2 |
12 | + github.com/google/go-querystring v1.1.0 // indirect | ||
13 | + github.com/gorilla/websocket v1.4.2 // indirect | ||
14 | + github.com/imkira/go-interpol v1.1.0 // indirect | ||
8 | github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6 | 15 | github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6 |
16 | + github.com/mattn/go-colorable v0.1.8 // indirect | ||
17 | + github.com/moul/http2curl v1.0.0 // indirect | ||
18 | + github.com/onsi/ginkgo v1.14.2 | ||
19 | + github.com/onsi/gomega v1.10.3 | ||
20 | + github.com/sergi/go-diff v1.2.0 // indirect | ||
21 | + github.com/smartystreets/goconvey v1.6.4 // indirect | ||
22 | + github.com/valyala/fasthttp v1.28.0 // indirect | ||
23 | + github.com/xeipuuv/gojsonschema v1.2.0 // indirect | ||
24 | + github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect | ||
25 | + github.com/yudai/gojsondiff v1.0.0 // indirect | ||
26 | + github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect | ||
27 | + github.com/yudai/pp v2.0.1+incompatible // indirect | ||
9 | ) | 28 | ) |
@@ -29,3 +29,11 @@ func CreateNoticePersonalRepository(options map[string]interface{}) (domain.Noti | @@ -29,3 +29,11 @@ func CreateNoticePersonalRepository(options map[string]interface{}) (domain.Noti | ||
29 | } | 29 | } |
30 | return repository.NewNoticePersonalRepository(transactionContext) | 30 | return repository.NewNoticePersonalRepository(transactionContext) |
31 | } | 31 | } |
32 | + | ||
33 | +func CreateSystemSettingRepository(options map[string]interface{}) (domain.SystemSettingRepository, error) { | ||
34 | + var transactionContext *pg.TransactionContext | ||
35 | + if value, ok := options["transactionContext"]; ok { | ||
36 | + transactionContext = value.(*pg.TransactionContext) | ||
37 | + } | ||
38 | + return repository.NewSystemSettingRepository(transactionContext) | ||
39 | +} |
@@ -15,6 +15,9 @@ type GetNoticePersonalListQuery struct { | @@ -15,6 +15,9 @@ type GetNoticePersonalListQuery struct { | ||
15 | PageIndex int64 `json:"pageIndex"` | 15 | PageIndex int64 `json:"pageIndex"` |
16 | // 是否是已读 | 16 | // 是否是已读 |
17 | IsRead int64 `json:"isRead"` | 17 | IsRead int64 `json:"isRead"` |
18 | + | ||
19 | + CompanyId int64 `json:"companyId"` | ||
20 | + OrgId int64 `json:"orgId"` | ||
18 | } | 21 | } |
19 | 22 | ||
20 | func (getNoticePersonalListQuery *GetNoticePersonalListQuery) Valid(validation *validation.Validation) { | 23 | func (getNoticePersonalListQuery *GetNoticePersonalListQuery) Valid(validation *validation.Validation) { |
@@ -106,26 +106,55 @@ func (noticePersonalService *NoticePersonalService) AgreeJoinCreationProject(agr | @@ -106,26 +106,55 @@ func (noticePersonalService *NoticePersonalService) AgreeJoinCreationProject(agr | ||
106 | } | 106 | } |
107 | 107 | ||
108 | // 获取消息列表 | 108 | // 获取消息列表 |
109 | -func (noticePersonalService *NoticePersonalService) GetNoticePersonalList(getNoticePersonalListQuery *query.GetNoticePersonalListQuery) (interface{}, error) { | 109 | +func (noticePersonalService *NoticePersonalService) GetNoticePersonalList(getNoticePersonalListQuery *query.GetNoticePersonalListQuery) (int64, interface{}, error) { |
110 | if err := getNoticePersonalListQuery.ValidateQuery(); err != nil { | 110 | if err := getNoticePersonalListQuery.ValidateQuery(); err != nil { |
111 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 111 | + return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
112 | } | 112 | } |
113 | transactionContext, err := factory.CreateTransactionContext(nil) | 113 | transactionContext, err := factory.CreateTransactionContext(nil) |
114 | if err != nil { | 114 | if err != nil { |
115 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 115 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
116 | } | 116 | } |
117 | if err := transactionContext.StartTransaction(); err != nil { | 117 | if err := transactionContext.StartTransaction(); err != nil { |
118 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 118 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
119 | } | 119 | } |
120 | defer func() { | 120 | defer func() { |
121 | transactionContext.RollbackTransaction() | 121 | transactionContext.RollbackTransaction() |
122 | }() | 122 | }() |
123 | 123 | ||
124 | - //TODO | 124 | + var noticePersonalRepository domain.NoticePersonalRepository |
125 | + if value, err := factory.CreateNoticePersonalRepository(map[string]interface{}{ | ||
126 | + "transactionContext": transactionContext, | ||
127 | + }); err != nil { | ||
128 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
129 | + } else { | ||
130 | + noticePersonalRepository = value | ||
131 | + } | ||
132 | + | ||
133 | + queryOption := map[string]interface{}{ | ||
134 | + "limit": getNoticePersonalListQuery.PageSize, | ||
135 | + "offset": (getNoticePersonalListQuery.PageIndex - 1) * getNoticePersonalListQuery.PageSize, | ||
136 | + } | ||
137 | + if getNoticePersonalListQuery.UserId > 0 { | ||
138 | + queryOption["userId"] = getNoticePersonalListQuery.UserId | ||
139 | + } | ||
140 | + if getNoticePersonalListQuery.OrgId > 0 { | ||
141 | + queryOption["orgId"] = getNoticePersonalListQuery.OrgId | ||
142 | + } | ||
143 | + | ||
144 | + if getNoticePersonalListQuery.CompanyId > 0 { | ||
145 | + queryOption["companyId"] = getNoticePersonalListQuery.CompanyId | ||
146 | + } | ||
147 | + if getNoticePersonalListQuery.IsRead > 0 { | ||
148 | + queryOption["isRead"] = getNoticePersonalListQuery.IsRead | ||
149 | + } | ||
150 | + cnt, noticeList, err := noticePersonalRepository.Find(queryOption) | ||
151 | + if err != nil { | ||
152 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
153 | + } | ||
125 | if err := transactionContext.CommitTransaction(); err != nil { | 154 | if err := transactionContext.CommitTransaction(); err != nil { |
126 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 155 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
127 | } | 156 | } |
128 | - return nil, nil | 157 | + return cnt, noticeList, nil |
129 | } | 158 | } |
130 | 159 | ||
131 | // 设置消息:分红预算消息 | 160 | // 设置消息:分红预算消息 |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type UpdateSystemSettingCommand struct { | ||
10 | + // 设置对应的编码 | ||
11 | + SettingCode string `json:"settingCode" valid:"Required"` | ||
12 | + // 公司id | ||
13 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
14 | + //设定的值 | ||
15 | + Value string `json:"value" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (updateSystemSettingCommand *UpdateSystemSettingCommand) Valid(validation *validation.Validation) { | ||
19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (updateSystemSettingCommand *UpdateSystemSettingCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(updateSystemSettingCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetSystemSettingQuery struct { | ||
10 | + // 设置对应的编码 | ||
11 | + SettingCode string `json:"settingCode" valid:"Required"` | ||
12 | + // 企业id | ||
13 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getSystemSettingQuery *GetSystemSettingQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getSystemSettingQuery *GetSystemSettingQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(getSystemSettingQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListSystemSettingQuery struct { | ||
10 | + // 公司id | ||
11 | + CompanyId int64 `json:"companyId,omitempty"` | ||
12 | + // 设置对应的编码 | ||
13 | + SettingCode string `json:"settingCode,omitempty"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listSystemSettingQuery *ListSystemSettingQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listSystemSettingQuery *ListSystemSettingQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listSystemSettingQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/command" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/query" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" | ||
9 | +) | ||
10 | + | ||
11 | +// 用户的系统设置 | ||
12 | +type SystemSettingService struct { | ||
13 | +} | ||
14 | + | ||
15 | +// 返回用户的系统设置 | ||
16 | +func (systemSettingService *SystemSettingService) GetSystemSetting(getSystemSettingQuery *query.GetSystemSettingQuery) (interface{}, error) { | ||
17 | + if err := getSystemSettingQuery.ValidateQuery(); err != nil { | ||
18 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
19 | + } | ||
20 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
21 | + if err != nil { | ||
22 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
23 | + } | ||
24 | + if err := transactionContext.StartTransaction(); err != nil { | ||
25 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
26 | + } | ||
27 | + defer func() { | ||
28 | + transactionContext.RollbackTransaction() | ||
29 | + }() | ||
30 | + var systemSettingRepository domain.SystemSettingRepository | ||
31 | + if value, err := factory.CreateSystemSettingRepository(map[string]interface{}{ | ||
32 | + "transactionContext": transactionContext, | ||
33 | + }); err != nil { | ||
34 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
35 | + } else { | ||
36 | + systemSettingRepository = value | ||
37 | + } | ||
38 | + systemSetting, err := systemSettingRepository.FindOne(map[string]interface{}{ | ||
39 | + "companyId": getSystemSettingQuery.CompanyId, | ||
40 | + "settingCode": getSystemSettingQuery.SettingCode, | ||
41 | + }) | ||
42 | + if err != nil { | ||
43 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
44 | + } | ||
45 | + if systemSetting == nil { | ||
46 | + //获取默认设置项 | ||
47 | + setting := domain.SystemSetting{} | ||
48 | + defaultSet := setting.GetDefaultSetting(getSystemSettingQuery.SettingCode) | ||
49 | + if len(defaultSet) == 0 { | ||
50 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取设置项失败,settingCode="+getSystemSettingQuery.SettingCode) | ||
51 | + } | ||
52 | + defaultSet[0].CompanyId = getSystemSettingQuery.CompanyId | ||
53 | + systemSetting = &defaultSet[0] | ||
54 | + } | ||
55 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
56 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
57 | + } | ||
58 | + return systemSetting, nil | ||
59 | +} | ||
60 | + | ||
61 | +// 返回用户的系统设置列表 | ||
62 | +func (systemSettingService *SystemSettingService) ListSystemSetting(listSystemSettingQuery *query.ListSystemSettingQuery) (interface{}, error) { | ||
63 | + if err := listSystemSettingQuery.ValidateQuery(); err != nil { | ||
64 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
65 | + } | ||
66 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
67 | + if err != nil { | ||
68 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
69 | + } | ||
70 | + if err := transactionContext.StartTransaction(); err != nil { | ||
71 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
72 | + } | ||
73 | + defer func() { | ||
74 | + transactionContext.RollbackTransaction() | ||
75 | + }() | ||
76 | + var systemSettingRepository domain.SystemSettingRepository | ||
77 | + if value, err := factory.CreateSystemSettingRepository(map[string]interface{}{ | ||
78 | + "transactionContext": transactionContext, | ||
79 | + }); err != nil { | ||
80 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
81 | + } else { | ||
82 | + systemSettingRepository = value | ||
83 | + } | ||
84 | + queryOption := map[string]interface{}{ | ||
85 | + "companyId": listSystemSettingQuery.CompanyId, | ||
86 | + } | ||
87 | + if len(listSystemSettingQuery.SettingCode) > 0 { | ||
88 | + queryOption["settingCode"] = listSystemSettingQuery.SettingCode | ||
89 | + } | ||
90 | + _, systemSettings, err := systemSettingRepository.Find(queryOption) | ||
91 | + if err != nil { | ||
92 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
93 | + } | ||
94 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
95 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
96 | + } | ||
97 | + settingMap := map[string]*domain.SystemSetting{} | ||
98 | + for i := range systemSettings { | ||
99 | + code := systemSettings[i].SettingCode | ||
100 | + settingMap[code] = systemSettings[i] | ||
101 | + } | ||
102 | + defaultSettings := new(domain.SystemSetting).GetDefaultSetting("") | ||
103 | + for i := range defaultSettings { | ||
104 | + if v, ok := settingMap[defaultSettings[i].SettingCode]; ok { | ||
105 | + defaultSettings[i].Value = v.Value | ||
106 | + } | ||
107 | + defaultSettings[i].CompanyId = listSystemSettingQuery.CompanyId | ||
108 | + } | ||
109 | + return map[string]interface{}{ | ||
110 | + "systemSettings": defaultSettings, | ||
111 | + }, nil | ||
112 | +} | ||
113 | + | ||
114 | +// 更新用户的系统设置 | ||
115 | +func (systemSettingService *SystemSettingService) UpdateSystemSetting(updateSystemSettingCommand *command.UpdateSystemSettingCommand) (interface{}, error) { | ||
116 | + if err := updateSystemSettingCommand.ValidateCommand(); err != nil { | ||
117 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
118 | + } | ||
119 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
120 | + if err != nil { | ||
121 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
122 | + } | ||
123 | + if err := transactionContext.StartTransaction(); err != nil { | ||
124 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
125 | + } | ||
126 | + defer func() { | ||
127 | + transactionContext.RollbackTransaction() | ||
128 | + }() | ||
129 | + var systemSettingRepository domain.SystemSettingRepository | ||
130 | + if value, err := factory.CreateSystemSettingRepository(map[string]interface{}{ | ||
131 | + "transactionContext": transactionContext, | ||
132 | + }); err != nil { | ||
133 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
134 | + } else { | ||
135 | + systemSettingRepository = value | ||
136 | + } | ||
137 | + _, systemSettings, err := systemSettingRepository.Find(map[string]interface{}{ | ||
138 | + "settingCode": updateSystemSettingCommand.SettingCode, | ||
139 | + "companyId": updateSystemSettingCommand.CompanyId, | ||
140 | + }) | ||
141 | + if err != nil { | ||
142 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
143 | + } | ||
144 | + var systemSetting *domain.SystemSetting | ||
145 | + if len(systemSettings) == 0 { | ||
146 | + defaultSet := new(domain.SystemSetting).GetDefaultSetting(updateSystemSettingCommand.SettingCode) | ||
147 | + if len(defaultSet) > 0 { | ||
148 | + systemSetting = &defaultSet[0] | ||
149 | + systemSetting.CompanyId = updateSystemSettingCommand.CompanyId | ||
150 | + } | ||
151 | + } else { | ||
152 | + systemSetting = systemSettings[0] | ||
153 | + if err := systemSetting.Update(map[string]interface{}{ | ||
154 | + "value": updateSystemSettingCommand.Value, | ||
155 | + }); err != nil { | ||
156 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
157 | + } | ||
158 | + } | ||
159 | + if systemSetting == nil { | ||
160 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "settingCode错误,settingCode="+updateSystemSettingCommand.SettingCode) | ||
161 | + } | ||
162 | + | ||
163 | + if systemSetting, err := systemSettingRepository.Save(systemSetting); err != nil { | ||
164 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
165 | + } else { | ||
166 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
167 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
168 | + } | ||
169 | + return systemSetting, nil | ||
170 | + } | ||
171 | +} | ||
172 | + | ||
173 | +func NewSystemSettingService(options map[string]interface{}) *SystemSettingService { | ||
174 | + newSystemSettingService := &SystemSettingService{} | ||
175 | + return newSystemSettingService | ||
176 | +} |
pkg/domain/system_setting.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +// 系统参数设置 | ||
4 | +type SystemSetting struct { | ||
5 | + // 公司id | ||
6 | + CompanyId int64 `json:"companyId"` | ||
7 | + // 管控层级 | ||
8 | + ControlLevel string `json:"controlLevel"` | ||
9 | + // 描述 | ||
10 | + Description string `json:"description"` | ||
11 | + // 设置对应的编码 | ||
12 | + SettingCode string `json:"settingCode"` | ||
13 | + // 设置对应的名称 | ||
14 | + SettingName string `json:"settingName"` | ||
15 | + // 数据id | ||
16 | + SystemSettingId int64 `json:"systemSettingId"` | ||
17 | + // 设定的值 | ||
18 | + Value string `json:"value"` | ||
19 | + // 值类型 | ||
20 | + ValueType string `json:"valueType"` | ||
21 | +} | ||
22 | + | ||
23 | +type SystemSettingRepository interface { | ||
24 | + Save(systemSetting *SystemSetting) (*SystemSetting, error) | ||
25 | + Remove(systemSetting *SystemSetting) (*SystemSetting, error) | ||
26 | + FindOne(queryOptions map[string]interface{}) (*SystemSetting, error) | ||
27 | + Find(queryOptions map[string]interface{}) (int64, []*SystemSetting, error) | ||
28 | +} | ||
29 | + | ||
30 | +func (systemSetting *SystemSetting) Identify() interface{} { | ||
31 | + if systemSetting.SystemSettingId == 0 { | ||
32 | + return nil | ||
33 | + } | ||
34 | + return systemSetting.SystemSettingId | ||
35 | +} | ||
36 | + | ||
37 | +func (systemSetting *SystemSetting) Update(data map[string]interface{}) error { | ||
38 | + if companyId, ok := data["companyId"]; ok { | ||
39 | + systemSetting.CompanyId = companyId.(int64) | ||
40 | + } | ||
41 | + if controlLevel, ok := data["controlLevel"]; ok { | ||
42 | + systemSetting.ControlLevel = controlLevel.(string) | ||
43 | + } | ||
44 | + if description, ok := data["description"]; ok { | ||
45 | + systemSetting.Description = description.(string) | ||
46 | + } | ||
47 | + if settingCode, ok := data["settingCode"]; ok { | ||
48 | + systemSetting.SettingCode = settingCode.(string) | ||
49 | + } | ||
50 | + if settingName, ok := data["settingName"]; ok { | ||
51 | + systemSetting.SettingName = settingName.(string) | ||
52 | + } | ||
53 | + if systemSettingId, ok := data["systemSettingId"]; ok { | ||
54 | + systemSetting.SystemSettingId = systemSettingId.(int64) | ||
55 | + } | ||
56 | + if value, ok := data["value"]; ok { | ||
57 | + systemSetting.Value = value.(string) | ||
58 | + } | ||
59 | + if valueType, ok := data["valueType"]; ok { | ||
60 | + systemSetting.ValueType = valueType.(string) | ||
61 | + } | ||
62 | + return nil | ||
63 | +} | ||
64 | + | ||
65 | +var defaultsysSettingList = []SystemSetting{ | ||
66 | + { | ||
67 | + ControlLevel: "系统级", | ||
68 | + ValueType: "字符", | ||
69 | + Value: "TL123456!", | ||
70 | + SettingName: "用户初始化密码", | ||
71 | + SettingCode: "XT001", | ||
72 | + Description: "用于用户初始化设置初始化密码", | ||
73 | + }, | ||
74 | +} | ||
75 | + | ||
76 | +func (systemSetting *SystemSetting) GetDefaultSetting(settingCode string) []SystemSetting { | ||
77 | + var list []SystemSetting | ||
78 | + if len(settingCode) > 0 { | ||
79 | + for i := range defaultsysSettingList { | ||
80 | + if defaultsysSettingList[i].SettingCode == settingCode { | ||
81 | + list = append(list, defaultsysSettingList[i]) | ||
82 | + } | ||
83 | + } | ||
84 | + } else { | ||
85 | + list = make([]SystemSetting, len(defaultsysSettingList)) | ||
86 | + copy(list, defaultsysSettingList) | ||
87 | + } | ||
88 | + return list | ||
89 | +} |
1 | +package models | ||
2 | + | ||
3 | +type SystemSetting struct { | ||
4 | + tableName string `pg:"system_settings,alias:system_setting"` | ||
5 | + // 公司id | ||
6 | + CompanyId int64 | ||
7 | + // 管控层级 | ||
8 | + ControlLevel string | ||
9 | + // 描述 | ||
10 | + Description string | ||
11 | + // 设置对应的编码 | ||
12 | + SettingCode string | ||
13 | + // 设置对应的名称 | ||
14 | + SettingName string | ||
15 | + // 数据id | ||
16 | + SystemSettingId int64 | ||
17 | + // 设定的值 | ||
18 | + Value string | ||
19 | + // 值类型 | ||
20 | + ValueType string | ||
21 | +} |
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToSystemSettingDomainModelFromPgModels(systemSettingModel *models.SystemSetting) (*domain.SystemSetting, error) { | ||
9 | + return &domain.SystemSetting{ | ||
10 | + CompanyId: systemSettingModel.CompanyId, | ||
11 | + ControlLevel: systemSettingModel.ControlLevel, | ||
12 | + Description: systemSettingModel.Description, | ||
13 | + SettingCode: systemSettingModel.SettingCode, | ||
14 | + SettingName: systemSettingModel.SettingName, | ||
15 | + SystemSettingId: systemSettingModel.SystemSettingId, | ||
16 | + Value: systemSettingModel.Value, | ||
17 | + ValueType: systemSettingModel.ValueType, | ||
18 | + }, nil | ||
19 | +} |
@@ -6,7 +6,6 @@ import ( | @@ -6,7 +6,6 @@ import ( | ||
6 | "github.com/go-pg/pg/v10" | 6 | "github.com/go-pg/pg/v10" |
7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 7 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
9 | - "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform" |
@@ -17,11 +16,7 @@ type NoticePersonalRepository struct { | @@ -17,11 +16,7 @@ type NoticePersonalRepository struct { | ||
17 | } | 16 | } |
18 | 17 | ||
19 | func (repository *NoticePersonalRepository) nextIdentify() (int64, error) { | 18 | func (repository *NoticePersonalRepository) nextIdentify() (int64, error) { |
20 | - IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | - if err != nil { | ||
22 | - return 0, err | ||
23 | - } | ||
24 | - id, err := IdWorker.NextId() | 19 | + id, err := idWorker.NextId() |
25 | return id, err | 20 | return id, err |
26 | } | 21 | } |
27 | func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePersonal) (*domain.NoticePersonal, error) { | 22 | func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePersonal) (*domain.NoticePersonal, error) { |
@@ -157,6 +152,10 @@ func (repository *NoticePersonalRepository) Find(queryOptions map[string]interfa | @@ -157,6 +152,10 @@ func (repository *NoticePersonalRepository) Find(queryOptions map[string]interfa | ||
157 | query := sqlbuilder.BuildQuery(tx.Model(¬icePersonalModels), queryOptions) | 152 | query := sqlbuilder.BuildQuery(tx.Model(¬icePersonalModels), queryOptions) |
158 | query.SetOffsetAndLimit(20) | 153 | query.SetOffsetAndLimit(20) |
159 | query.SetOrderDirect("notice_personal_id", "DESC") | 154 | query.SetOrderDirect("notice_personal_id", "DESC") |
155 | + query.SetWhereByQueryOption("notice_personal.user_id", "userId") | ||
156 | + query.SetWhereByQueryOption("notice_personal.org_id", "orgId") | ||
157 | + query.SetWhereByQueryOption("notice_personal.company_id", "companyId") | ||
158 | + query.SetWhereByQueryOption("notice_personal.is_read", "isRead") | ||
160 | if count, err := query.SelectAndCount(); err != nil { | 159 | if count, err := query.SelectAndCount(); err != nil { |
161 | return 0, noticePersonals, err | 160 | return 0, noticePersonals, err |
162 | } else { | 161 | } else { |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/go-pg/pg/v10" | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform" | ||
12 | +) | ||
13 | + | ||
14 | +type SystemSettingRepository struct { | ||
15 | + transactionContext *pgTransaction.TransactionContext | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *SystemSettingRepository) nextIdentify() (int64, error) { | ||
19 | + id, err := idWorker.NextId() | ||
20 | + return id, err | ||
21 | +} | ||
22 | +func (repository *SystemSettingRepository) Save(systemSetting *domain.SystemSetting) (*domain.SystemSetting, error) { | ||
23 | + sqlBuildFields := []string{ | ||
24 | + "company_id", | ||
25 | + "control_level", | ||
26 | + "description", | ||
27 | + "setting_code", | ||
28 | + "setting_name", | ||
29 | + "system_setting_id", | ||
30 | + "value", | ||
31 | + "value_type", | ||
32 | + } | ||
33 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
34 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
35 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
36 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "systemSetting_id") | ||
37 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
38 | + tx := repository.transactionContext.PgTx | ||
39 | + if systemSetting.Identify() == nil { | ||
40 | + systemSettingId, err := repository.nextIdentify() | ||
41 | + if err != nil { | ||
42 | + return systemSetting, err | ||
43 | + } else { | ||
44 | + systemSetting.SystemSettingId = systemSettingId | ||
45 | + } | ||
46 | + if _, err := tx.QueryOne( | ||
47 | + pg.Scan( | ||
48 | + &systemSetting.CompanyId, | ||
49 | + &systemSetting.ControlLevel, | ||
50 | + &systemSetting.Description, | ||
51 | + &systemSetting.SettingCode, | ||
52 | + &systemSetting.SettingName, | ||
53 | + &systemSetting.SystemSettingId, | ||
54 | + &systemSetting.Value, | ||
55 | + &systemSetting.ValueType, | ||
56 | + ), | ||
57 | + fmt.Sprintf("INSERT INTO system_settings (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
58 | + systemSetting.CompanyId, | ||
59 | + systemSetting.ControlLevel, | ||
60 | + systemSetting.Description, | ||
61 | + systemSetting.SettingCode, | ||
62 | + systemSetting.SettingName, | ||
63 | + systemSetting.SystemSettingId, | ||
64 | + systemSetting.Value, | ||
65 | + systemSetting.ValueType, | ||
66 | + ); err != nil { | ||
67 | + return systemSetting, err | ||
68 | + } | ||
69 | + } else { | ||
70 | + if _, err := tx.QueryOne( | ||
71 | + pg.Scan( | ||
72 | + &systemSetting.CompanyId, | ||
73 | + &systemSetting.ControlLevel, | ||
74 | + &systemSetting.Description, | ||
75 | + &systemSetting.SettingCode, | ||
76 | + &systemSetting.SettingName, | ||
77 | + &systemSetting.SystemSettingId, | ||
78 | + &systemSetting.Value, | ||
79 | + &systemSetting.ValueType, | ||
80 | + ), | ||
81 | + fmt.Sprintf("UPDATE system_settings SET %s WHERE system_setting_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
82 | + systemSetting.CompanyId, | ||
83 | + systemSetting.ControlLevel, | ||
84 | + systemSetting.Description, | ||
85 | + systemSetting.SettingCode, | ||
86 | + systemSetting.SettingName, | ||
87 | + systemSetting.SystemSettingId, | ||
88 | + systemSetting.Value, | ||
89 | + systemSetting.ValueType, | ||
90 | + systemSetting.Identify(), | ||
91 | + ); err != nil { | ||
92 | + return systemSetting, err | ||
93 | + } | ||
94 | + } | ||
95 | + return systemSetting, nil | ||
96 | +} | ||
97 | +func (repository *SystemSettingRepository) Remove(systemSetting *domain.SystemSetting) (*domain.SystemSetting, error) { | ||
98 | + tx := repository.transactionContext.PgTx | ||
99 | + systemSettingModel := new(models.SystemSetting) | ||
100 | + systemSettingModel.SystemSettingId = systemSetting.Identify().(int64) | ||
101 | + if _, err := tx.Model(systemSettingModel).WherePK().Delete(); err != nil { | ||
102 | + return systemSetting, err | ||
103 | + } | ||
104 | + return systemSetting, nil | ||
105 | +} | ||
106 | +func (repository *SystemSettingRepository) FindOne(queryOptions map[string]interface{}) (*domain.SystemSetting, error) { | ||
107 | + tx := repository.transactionContext.PgTx | ||
108 | + systemSettingModel := new(models.SystemSetting) | ||
109 | + query := sqlbuilder.BuildQuery(tx.Model(systemSettingModel), queryOptions) | ||
110 | + query.SetWhereByQueryOption("system_setting.system_setting_id = ?", "systemSettingId") | ||
111 | + query.SetWhereByQueryOption("system_setting.setting_code=?", "settingCode") | ||
112 | + query.SetWhereByQueryOption("system_setting.companyId=?", "companyId") | ||
113 | + if err := query.First(); err != nil { | ||
114 | + if err.Error() == "pg: no rows in result set" { | ||
115 | + return nil, fmt.Errorf("没有此资源") | ||
116 | + } else { | ||
117 | + return nil, err | ||
118 | + } | ||
119 | + } | ||
120 | + if systemSettingModel.SystemSettingId == 0 { | ||
121 | + return nil, nil | ||
122 | + } else { | ||
123 | + return transform.TransformToSystemSettingDomainModelFromPgModels(systemSettingModel) | ||
124 | + } | ||
125 | +} | ||
126 | +func (repository *SystemSettingRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.SystemSetting, error) { | ||
127 | + tx := repository.transactionContext.PgTx | ||
128 | + var systemSettingModels []*models.SystemSetting | ||
129 | + systemSettings := make([]*domain.SystemSetting, 0) | ||
130 | + query := sqlbuilder.BuildQuery(tx.Model(&systemSettingModels), queryOptions) | ||
131 | + query.SetOffsetAndLimit(20) | ||
132 | + query.SetOrderDirect("system_setting_id", "DESC") | ||
133 | + query.SetWhereByQueryOption("system_setting.setting_code=?", "settingCode") | ||
134 | + query.SetWhereByQueryOption("system_setting.companyId=?", "companyId") | ||
135 | + if count, err := query.SelectAndCount(); err != nil { | ||
136 | + return 0, systemSettings, err | ||
137 | + } else { | ||
138 | + for _, systemSettingModel := range systemSettingModels { | ||
139 | + if systemSetting, err := transform.TransformToSystemSettingDomainModelFromPgModels(systemSettingModel); err != nil { | ||
140 | + return 0, systemSettings, err | ||
141 | + } else { | ||
142 | + systemSettings = append(systemSettings, systemSetting) | ||
143 | + } | ||
144 | + } | ||
145 | + return int64(count), systemSettings, nil | ||
146 | + } | ||
147 | +} | ||
148 | +func NewSystemSettingRepository(transactionContext *pgTransaction.TransactionContext) (*SystemSettingRepository, error) { | ||
149 | + if transactionContext == nil { | ||
150 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
151 | + } else { | ||
152 | + return &SystemSettingRepository{ | ||
153 | + transactionContext: transactionContext, | ||
154 | + }, nil | ||
155 | + } | ||
156 | +} |
@@ -14,7 +14,11 @@ type NoticePersonalController struct { | @@ -14,7 +14,11 @@ type NoticePersonalController struct { | ||
14 | func (controller *NoticePersonalController) GetNoticePersonalList() { | 14 | func (controller *NoticePersonalController) GetNoticePersonalList() { |
15 | noticePersonalService := service.NewNoticePersonalService(nil) | 15 | noticePersonalService := service.NewNoticePersonalService(nil) |
16 | getNoticePersonalListQuery := &query.GetNoticePersonalListQuery{} | 16 | getNoticePersonalListQuery := &query.GetNoticePersonalListQuery{} |
17 | - data, err := noticePersonalService.GetNoticePersonalList(getNoticePersonalListQuery) | 17 | + cnt, list, err := noticePersonalService.GetNoticePersonalList(getNoticePersonalListQuery) |
18 | + data := map[string]interface{}{ | ||
19 | + "count": cnt, | ||
20 | + "list": list, | ||
21 | + } | ||
18 | controller.Response(data, err) | 22 | controller.Response(data, err) |
19 | } | 23 | } |
20 | 24 |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/query" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/service" | ||
8 | +) | ||
9 | + | ||
10 | +type SystemSettingController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *SystemSettingController) UpdateSystemSetting() { | ||
15 | + systemSettingService := service.NewSystemSettingService(nil) | ||
16 | + updateSystemSettingCommand := &command.UpdateSystemSettingCommand{} | ||
17 | + controller.Unmarshal(updateSystemSettingCommand) | ||
18 | + data, err := systemSettingService.UpdateSystemSetting(updateSystemSettingCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *SystemSettingController) GetSystemSetting() { | ||
23 | + systemSettingService := service.NewSystemSettingService(nil) | ||
24 | + getSystemSettingQuery := &query.GetSystemSettingQuery{} | ||
25 | + data, err := systemSettingService.GetSystemSetting(getSystemSettingQuery) | ||
26 | + controller.Response(data, err) | ||
27 | +} | ||
28 | + | ||
29 | +func (controller *SystemSettingController) ListSystemSetting() { | ||
30 | + systemSettingService := service.NewSystemSettingService(nil) | ||
31 | + listSystemSettingQuery := &query.ListSystemSettingQuery{} | ||
32 | + data, err := systemSettingService.ListSystemSetting(listSystemSettingQuery) | ||
33 | + controller.Response(data, err) | ||
34 | +} |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/system-settings/", &controllers.SystemSettingController{}, "Put:UpdateSystemSetting") | ||
10 | + web.Router("/system-settings/get", &controllers.SystemSettingController{}, "Post:GetSystemSetting") | ||
11 | + web.Router("/system-settings/search", &controllers.SystemSettingController{}, "Post:ListSystemSetting") | ||
12 | +} |
-
请 注册 或 登录 后发表评论