作者 tangxuhui

调整数据结构

1 -{"D:\\workspaceGo\\src\\allied-creation-basic\\pkg\\port\\beego":1629534039183149400}  
  1 +{"D:\\workspaceGo\\src\\allied-creation-basic\\pkg\\port\\beego":1629701389888857200}
@@ -10,9 +10,10 @@ type ListNoticeSettingQuery struct { @@ -10,9 +10,10 @@ type ListNoticeSettingQuery struct {
10 // 查询偏离量 10 // 查询偏离量
11 PageIndex int `json:"pageIndex"` 11 PageIndex int `json:"pageIndex"`
12 // 查询限制 12 // 查询限制
13 - PageSize int `json:"pageSize" valid:"Required"`  
14 - CompanyId int64 `json:"companyId" valid:"Required"`  
15 - OrgId int64 `json:"orgId"` 13 + PageSize int `json:"pageSize" valid:"Required"`
  14 + CompanyId int64 `json:"companyId" valid:"Required"`
  15 + OrgIds []int64 `json:"orgIds"`
  16 + ModuleActionName string `json:"moduleActionName"` //消息环节名称
16 } 17 }
17 18
18 func (listNoticeSettingQuery *ListNoticeSettingQuery) Valid(validation *validation.Validation) { 19 func (listNoticeSettingQuery *ListNoticeSettingQuery) Valid(validation *validation.Validation) {
@@ -84,8 +84,11 @@ func (noticeSettingService *NoticeSettingService) ListNoticeSetting(listNoticeSe @@ -84,8 +84,11 @@ func (noticeSettingService *NoticeSettingService) ListNoticeSetting(listNoticeSe
84 "pageSize": listNoticeSettingQuery.PageSize, 84 "pageSize": listNoticeSettingQuery.PageSize,
85 "companyId": listNoticeSettingQuery.CompanyId, 85 "companyId": listNoticeSettingQuery.CompanyId,
86 } 86 }
87 - if listNoticeSettingQuery.OrgId > 0 {  
88 - queryOption["orgId"] = listNoticeSettingQuery.OrgId 87 + if len(listNoticeSettingQuery.OrgIds) > 0 {
  88 + queryOption["orgIds"] = listNoticeSettingQuery.OrgIds
  89 + }
  90 + if len(listNoticeSettingQuery.ModuleActionName) > 0 {
  91 + queryOption["moduleActionName"] = "%" + listNoticeSettingQuery.ModuleActionName + "%"
89 } 92 }
90 if count, noticeSettings, err := noticeSettingRepository.Find(queryOption); err != nil { 93 if count, noticeSettings, err := noticeSettingRepository.Find(queryOption); err != nil {
91 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 94 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -211,15 +214,25 @@ func (noticeSettingService *NoticeSettingService) AddNoticeSetting(addNoticeSett @@ -211,15 +214,25 @@ func (noticeSettingService *NoticeSettingService) AddNoticeSetting(addNoticeSett
211 if len(noticeSettings) > 0 { 214 if len(noticeSettings) > 0 {
212 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "该环节配置已存在") 215 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "该环节配置已存在")
213 } 216 }
  217 + moduleAction, err := domain.GetNoticeModuleAction(addNoticeSettingCommand.Module, addNoticeSettingCommand.ModuleAction)
  218 + if err != nil {
  219 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  220 + }
  221 + module, err := domain.GetNoticeModule(addNoticeSettingCommand.Module)
  222 + if err != nil {
  223 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  224 + }
214 noticeSetting = &domain.NoticeSetting{ 225 noticeSetting = &domain.NoticeSetting{
215 - CompanyId: addNoticeSettingCommand.CompanyId,  
216 - Content: addNoticeSettingCommand.Content,  
217 - IsPush: addNoticeSettingCommand.IsPush,  
218 - Module: addNoticeSettingCommand.Module,  
219 - ModuleAction: addNoticeSettingCommand.ModuleAction,  
220 - OrgId: addNoticeSettingCommand.OrgId,  
221 - CreatedAt: time.Now(),  
222 - UpdatedAt: time.Now(), 226 + CompanyId: addNoticeSettingCommand.CompanyId,
  227 + Content: addNoticeSettingCommand.Content,
  228 + IsPush: addNoticeSettingCommand.IsPush,
  229 + Module: addNoticeSettingCommand.Module,
  230 + ModuleName: module.ModuleName,
  231 + ModuleAction: addNoticeSettingCommand.ModuleAction,
  232 + ModuleActionName: moduleAction.ActionName,
  233 + OrgId: addNoticeSettingCommand.OrgId,
  234 + CreatedAt: time.Now(),
  235 + UpdatedAt: time.Now(),
223 } 236 }
224 if noticeSetting, err := noticeSettingRepository.Save(noticeSetting); err != nil { 237 if noticeSetting, err := noticeSettingRepository.Save(noticeSetting); err != nil {
225 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 238 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -231,68 +244,6 @@ func (noticeSettingService *NoticeSettingService) AddNoticeSetting(addNoticeSett @@ -231,68 +244,6 @@ func (noticeSettingService *NoticeSettingService) AddNoticeSetting(addNoticeSett
231 } 244 }
232 } 245 }
233 246
234 -// //InitNoticeSetting 为企业初始化消息列表,填充空白的消息模板  
235 -// func (noticeSettingService *NoticeSettingService) InitNoticeSetting(initCommand *command.InitNoticeSettingCommand) error {  
236 -// if err := initCommand.ValidateCommand(); err != nil {  
237 -// return application.ThrowError(application.ARG_ERROR, err.Error())  
238 -// }  
239 -// transactionContext, err := factory.CreateTransactionContext(nil)  
240 -// if err != nil {  
241 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
242 -// }  
243 -// if err := transactionContext.StartTransaction(); err != nil {  
244 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
245 -// }  
246 -// defer func() {  
247 -// transactionContext.RollbackTransaction()  
248 -// }()  
249 -// var noticeSettingRepository domain.NoticeSettingRepository  
250 -// if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{  
251 -// "transactionContext": transactionContext,  
252 -// }); err != nil {  
253 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
254 -// } else {  
255 -// noticeSettingRepository = value  
256 -// }  
257 -// _, noticeSets, err := noticeSettingRepository.Find(map[string]interface{}{  
258 -// "companyId": initCommand.CompanyId,  
259 -// "orgId": initCommand.OrgId,  
260 -// })  
261 -// if err != nil {  
262 -// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
263 -// }  
264 -// notticeExist := make(map[string]int)  
265 -// for i := range noticeSets {  
266 -// notticeExist[noticeSets[i].ModuleAction] = 1  
267 -// }  
268 -// defaultModuleAction := domain.GetNoticeModuleActionList()  
269 -// newEmptySetting := []domain.NoticeSetting{}  
270 -// for _, act := range defaultModuleAction {  
271 -// if _, ok := notticeExist[act.ActionCode]; !ok {  
272 -// newEmptySetting = append(newEmptySetting, domain.NoticeSetting{  
273 -// CompanyId: initCommand.CompanyId,  
274 -// OrgId: initCommand.OrgId,  
275 -// Module: act.ModuleCode,  
276 -// ModuleAction: act.ActionCode,  
277 -// CreatedAt: time.Now(),  
278 -// UpdatedAt: time.Now(),  
279 -// Content: "",  
280 -// IsPush: domain.NoticeSettingIsNotPush,  
281 -// })  
282 -// }  
283 -// }  
284 -// for i := range newEmptySetting {  
285 -// _, err = noticeSettingRepository.Save(&newEmptySetting[i])  
286 -// if err != nil {  
287 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
288 -// }  
289 -// }  
290 -// if err := transactionContext.CommitTransaction(); err != nil {  
291 -// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
292 -// }  
293 -// return nil  
294 -// }  
295 -  
296 func NewNoticeSettingService(options map[string]interface{}) *NoticeSettingService { 247 func NewNoticeSettingService(options map[string]interface{}) *NoticeSettingService {
297 newNoticeSettingService := &NoticeSettingService{} 248 newNoticeSettingService := &NoticeSettingService{}
298 return newNoticeSettingService 249 return newNoticeSettingService
@@ -19,9 +19,11 @@ type NoticeSetting struct { @@ -19,9 +19,11 @@ type NoticeSetting struct {
19 // 是否推送 【是:1】【否:2】 19 // 是否推送 【是:1】【否:2】
20 IsPush int `json:"isPush"` 20 IsPush int `json:"isPush"`
21 // 消息对应的业务模块 21 // 消息对应的业务模块
22 - Module string `json:"module"` 22 + Module string `json:"module"`
  23 + ModuleName string `json:"moduleName"`
23 // 业务环节 24 // 业务环节
24 - ModuleAction string `json:"moduleAction"` 25 + ModuleAction string `json:"moduleAction"`
  26 + ModuleActionName string `json:"moduleActionName"`
25 // 组织id 27 // 组织id
26 OrgId int64 `json:"orgId"` 28 OrgId int64 `json:"orgId"`
27 // 创建时间 29 // 创建时间
@@ -82,6 +82,15 @@ func GetNoticeModuleAction(moduleCode string, actioncode string) (NoticeModuleAc @@ -82,6 +82,15 @@ func GetNoticeModuleAction(moduleCode string, actioncode string) (NoticeModuleAc
82 return NoticeModuleAction{}, errors.New("未找到对应的消息动作") 82 return NoticeModuleAction{}, errors.New("未找到对应的消息动作")
83 } 83 }
84 84
  85 +func GetNoticeModule(moduleCode string) (NoticeModule, error) {
  86 + for i := range noticeModuleList {
  87 + if noticeModuleList[i].ModuleCode == moduleCode {
  88 + return noticeModuleList[i], nil
  89 + }
  90 + }
  91 + return NoticeModule{}, errors.New("未找到对应的消息模块")
  92 +}
  93 +
85 //业务模块 94 //业务模块
86 const ( 95 const (
87 Module00 = "module00" // 系统消息 96 Module00 = "module00" // 系统消息
@@ -11,9 +11,11 @@ type NoticeSetting struct { @@ -11,9 +11,11 @@ type NoticeSetting struct {
11 // 是否推送 【是:1】【否:2】 11 // 是否推送 【是:1】【否:2】
12 IsPush int 12 IsPush int
13 // 消息对应的业务模块 13 // 消息对应的业务模块
14 - Module string 14 + Module string
  15 + ModuleName string
15 // 业务环节 16 // 业务环节
16 - ModuleAction string 17 + ModuleAction string
  18 + ModuleActionName string
17 // 消息id 19 // 消息id
18 NoticeSettingId int64 `pg:",pk"` 20 NoticeSettingId int64 `pg:",pk"`
19 // 组织id 21 // 组织id
@@ -7,15 +7,17 @@ import ( @@ -7,15 +7,17 @@ import (
7 7
8 func TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel *models.NoticeSetting) (*domain.NoticeSetting, error) { 8 func TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel *models.NoticeSetting) (*domain.NoticeSetting, error) {
9 return &domain.NoticeSetting{ 9 return &domain.NoticeSetting{
10 - CompanyId: noticeSettingModel.CompanyId,  
11 - Content: noticeSettingModel.Content,  
12 - IsPush: noticeSettingModel.IsPush,  
13 - Module: noticeSettingModel.Module,  
14 - ModuleAction: noticeSettingModel.ModuleAction,  
15 - NoticeSettingId: noticeSettingModel.NoticeSettingId,  
16 - OrgId: noticeSettingModel.OrgId,  
17 - CreatedAt: noticeSettingModel.CreatedAt,  
18 - DeletedAt: noticeSettingModel.DeletedAt,  
19 - UpdatedAt: noticeSettingModel.UpdatedAt, 10 + CompanyId: noticeSettingModel.CompanyId,
  11 + Content: noticeSettingModel.Content,
  12 + IsPush: noticeSettingModel.IsPush,
  13 + Module: noticeSettingModel.Module,
  14 + ModuleName: noticeSettingModel.ModuleName,
  15 + ModuleAction: noticeSettingModel.ModuleAction,
  16 + ModuleActionName: noticeSettingModel.ModuleName,
  17 + NoticeSettingId: noticeSettingModel.NoticeSettingId,
  18 + OrgId: noticeSettingModel.OrgId,
  19 + CreatedAt: noticeSettingModel.CreatedAt,
  20 + DeletedAt: noticeSettingModel.DeletedAt,
  21 + UpdatedAt: noticeSettingModel.UpdatedAt,
20 }, nil 22 }, nil
21 } 23 }
@@ -25,7 +25,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett @@ -25,7 +25,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
25 "content", 25 "content",
26 "is_push", 26 "is_push",
27 "module", 27 "module",
  28 + "module_name",
28 "module_action", 29 "module_action",
  30 + "module_action_name",
29 "notice_setting_id", 31 "notice_setting_id",
30 "org_id", 32 "org_id",
31 "created_at", 33 "created_at",
@@ -51,7 +53,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett @@ -51,7 +53,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
51 &noticeSetting.Content, 53 &noticeSetting.Content,
52 &noticeSetting.IsPush, 54 &noticeSetting.IsPush,
53 &noticeSetting.Module, 55 &noticeSetting.Module,
  56 + &noticeSetting.ModuleName,
54 &noticeSetting.ModuleAction, 57 &noticeSetting.ModuleAction,
  58 + &noticeSetting.ModuleActionName,
55 &noticeSetting.NoticeSettingId, 59 &noticeSetting.NoticeSettingId,
56 &noticeSetting.OrgId, 60 &noticeSetting.OrgId,
57 &noticeSetting.CreatedAt, 61 &noticeSetting.CreatedAt,
@@ -63,7 +67,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett @@ -63,7 +67,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
63 noticeSetting.Content, 67 noticeSetting.Content,
64 noticeSetting.IsPush, 68 noticeSetting.IsPush,
65 noticeSetting.Module, 69 noticeSetting.Module,
  70 + noticeSetting.ModuleName,
66 noticeSetting.ModuleAction, 71 noticeSetting.ModuleAction,
  72 + noticeSetting.ModuleActionName,
67 noticeSetting.NoticeSettingId, 73 noticeSetting.NoticeSettingId,
68 noticeSetting.OrgId, 74 noticeSetting.OrgId,
69 noticeSetting.CreatedAt, 75 noticeSetting.CreatedAt,
@@ -79,7 +85,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett @@ -79,7 +85,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
79 &noticeSetting.Content, 85 &noticeSetting.Content,
80 &noticeSetting.IsPush, 86 &noticeSetting.IsPush,
81 &noticeSetting.Module, 87 &noticeSetting.Module,
  88 + &noticeSetting.ModuleName,
82 &noticeSetting.ModuleAction, 89 &noticeSetting.ModuleAction,
  90 + &noticeSetting.ModuleActionName,
83 &noticeSetting.NoticeSettingId, 91 &noticeSetting.NoticeSettingId,
84 &noticeSetting.OrgId, 92 &noticeSetting.OrgId,
85 &noticeSetting.CreatedAt, 93 &noticeSetting.CreatedAt,
@@ -91,7 +99,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett @@ -91,7 +99,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
91 noticeSetting.Content, 99 noticeSetting.Content,
92 noticeSetting.IsPush, 100 noticeSetting.IsPush,
93 noticeSetting.Module, 101 noticeSetting.Module,
  102 + noticeSetting.ModuleName,
94 noticeSetting.ModuleAction, 103 noticeSetting.ModuleAction,
  104 + noticeSetting.ModuleActionName,
95 noticeSetting.NoticeSettingId, 105 noticeSetting.NoticeSettingId,
96 noticeSetting.OrgId, 106 noticeSetting.OrgId,
97 noticeSetting.CreatedAt, 107 noticeSetting.CreatedAt,
@@ -144,6 +154,11 @@ func (repository *NoticeSettingRepository) Find(queryOptions map[string]interfac @@ -144,6 +154,11 @@ func (repository *NoticeSettingRepository) Find(queryOptions map[string]interfac
144 query.SetWhereByQueryOption("notice_setting.module_action=?", "moduleAction") 154 query.SetWhereByQueryOption("notice_setting.module_action=?", "moduleAction")
145 query.SetWhereByQueryOption("notice_setting.org_id=?", "orgId") 155 query.SetWhereByQueryOption("notice_setting.org_id=?", "orgId")
146 query.SetWhereByQueryOption("notice_setting.company_id=?", "companyId") 156 query.SetWhereByQueryOption("notice_setting.company_id=?", "companyId")
  157 + query.SetWhereByQueryOption("notice_setting.module_action_name like ?", "moduleActionName")
  158 + if v, ok := queryOptions["orgIds"]; ok {
  159 + query.WhereIn("notice_setting.orgId in (?)", v)
  160 + }
  161 +
147 if count, err := query.SelectAndCount(); err != nil { 162 if count, err := query.SelectAndCount(); err != nil {
148 return 0, noticeSettings, err 163 return 0, noticeSettings, err
149 } else { 164 } else {
@@ -132,6 +132,7 @@ func (repository *SystemSettingRepository) Find(queryOptions map[string]interfac @@ -132,6 +132,7 @@ func (repository *SystemSettingRepository) Find(queryOptions map[string]interfac
132 query.SetOrderDirect("system_setting_id", "DESC") 132 query.SetOrderDirect("system_setting_id", "DESC")
133 query.SetWhereByQueryOption("system_setting.setting_code=?", "settingCode") 133 query.SetWhereByQueryOption("system_setting.setting_code=?", "settingCode")
134 query.SetWhereByQueryOption("system_setting.company_id=?", "companyId") 134 query.SetWhereByQueryOption("system_setting.company_id=?", "companyId")
  135 +
135 if count, err := query.SelectAndCount(); err != nil { 136 if count, err := query.SelectAndCount(); err != nil {
136 return 0, systemSettings, err 137 return 0, systemSettings, err
137 } else { 138 } else {