作者 tangxuhui

调整数据结构

{"D:\\workspaceGo\\src\\allied-creation-basic\\pkg\\port\\beego":1629534039183149400}
\ No newline at end of file
{"D:\\workspaceGo\\src\\allied-creation-basic\\pkg\\port\\beego":1629701389888857200}
\ No newline at end of file
... ...
... ... @@ -10,9 +10,10 @@ type ListNoticeSettingQuery struct {
// 查询偏离量
PageIndex int `json:"pageIndex"`
// 查询限制
PageSize int `json:"pageSize" valid:"Required"`
CompanyId int64 `json:"companyId" valid:"Required"`
OrgId int64 `json:"orgId"`
PageSize int `json:"pageSize" valid:"Required"`
CompanyId int64 `json:"companyId" valid:"Required"`
OrgIds []int64 `json:"orgIds"`
ModuleActionName string `json:"moduleActionName"` //消息环节名称
}
func (listNoticeSettingQuery *ListNoticeSettingQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -84,8 +84,11 @@ func (noticeSettingService *NoticeSettingService) ListNoticeSetting(listNoticeSe
"pageSize": listNoticeSettingQuery.PageSize,
"companyId": listNoticeSettingQuery.CompanyId,
}
if listNoticeSettingQuery.OrgId > 0 {
queryOption["orgId"] = listNoticeSettingQuery.OrgId
if len(listNoticeSettingQuery.OrgIds) > 0 {
queryOption["orgIds"] = listNoticeSettingQuery.OrgIds
}
if len(listNoticeSettingQuery.ModuleActionName) > 0 {
queryOption["moduleActionName"] = "%" + listNoticeSettingQuery.ModuleActionName + "%"
}
if count, noticeSettings, err := noticeSettingRepository.Find(queryOption); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -211,15 +214,25 @@ func (noticeSettingService *NoticeSettingService) AddNoticeSetting(addNoticeSett
if len(noticeSettings) > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "该环节配置已存在")
}
moduleAction, err := domain.GetNoticeModuleAction(addNoticeSettingCommand.Module, addNoticeSettingCommand.ModuleAction)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
module, err := domain.GetNoticeModule(addNoticeSettingCommand.Module)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
noticeSetting = &domain.NoticeSetting{
CompanyId: addNoticeSettingCommand.CompanyId,
Content: addNoticeSettingCommand.Content,
IsPush: addNoticeSettingCommand.IsPush,
Module: addNoticeSettingCommand.Module,
ModuleAction: addNoticeSettingCommand.ModuleAction,
OrgId: addNoticeSettingCommand.OrgId,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CompanyId: addNoticeSettingCommand.CompanyId,
Content: addNoticeSettingCommand.Content,
IsPush: addNoticeSettingCommand.IsPush,
Module: addNoticeSettingCommand.Module,
ModuleName: module.ModuleName,
ModuleAction: addNoticeSettingCommand.ModuleAction,
ModuleActionName: moduleAction.ActionName,
OrgId: addNoticeSettingCommand.OrgId,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if noticeSetting, err := noticeSettingRepository.Save(noticeSetting); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -231,68 +244,6 @@ func (noticeSettingService *NoticeSettingService) AddNoticeSetting(addNoticeSett
}
}
// //InitNoticeSetting 为企业初始化消息列表,填充空白的消息模板
// func (noticeSettingService *NoticeSettingService) InitNoticeSetting(initCommand *command.InitNoticeSettingCommand) error {
// if err := initCommand.ValidateCommand(); err != nil {
// return application.ThrowError(application.ARG_ERROR, err.Error())
// }
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// var noticeSettingRepository domain.NoticeSettingRepository
// if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// } else {
// noticeSettingRepository = value
// }
// _, noticeSets, err := noticeSettingRepository.Find(map[string]interface{}{
// "companyId": initCommand.CompanyId,
// "orgId": initCommand.OrgId,
// })
// if err != nil {
// return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// notticeExist := make(map[string]int)
// for i := range noticeSets {
// notticeExist[noticeSets[i].ModuleAction] = 1
// }
// defaultModuleAction := domain.GetNoticeModuleActionList()
// newEmptySetting := []domain.NoticeSetting{}
// for _, act := range defaultModuleAction {
// if _, ok := notticeExist[act.ActionCode]; !ok {
// newEmptySetting = append(newEmptySetting, domain.NoticeSetting{
// CompanyId: initCommand.CompanyId,
// OrgId: initCommand.OrgId,
// Module: act.ModuleCode,
// ModuleAction: act.ActionCode,
// CreatedAt: time.Now(),
// UpdatedAt: time.Now(),
// Content: "",
// IsPush: domain.NoticeSettingIsNotPush,
// })
// }
// }
// for i := range newEmptySetting {
// _, err = noticeSettingRepository.Save(&newEmptySetting[i])
// if err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return nil
// }
func NewNoticeSettingService(options map[string]interface{}) *NoticeSettingService {
newNoticeSettingService := &NoticeSettingService{}
return newNoticeSettingService
... ...
... ... @@ -19,9 +19,11 @@ type NoticeSetting struct {
// 是否推送 【是:1】【否:2】
IsPush int `json:"isPush"`
// 消息对应的业务模块
Module string `json:"module"`
Module string `json:"module"`
ModuleName string `json:"moduleName"`
// 业务环节
ModuleAction string `json:"moduleAction"`
ModuleAction string `json:"moduleAction"`
ModuleActionName string `json:"moduleActionName"`
// 组织id
OrgId int64 `json:"orgId"`
// 创建时间
... ...
... ... @@ -82,6 +82,15 @@ func GetNoticeModuleAction(moduleCode string, actioncode string) (NoticeModuleAc
return NoticeModuleAction{}, errors.New("未找到对应的消息动作")
}
func GetNoticeModule(moduleCode string) (NoticeModule, error) {
for i := range noticeModuleList {
if noticeModuleList[i].ModuleCode == moduleCode {
return noticeModuleList[i], nil
}
}
return NoticeModule{}, errors.New("未找到对应的消息模块")
}
//业务模块
const (
Module00 = "module00" // 系统消息
... ...
... ... @@ -11,9 +11,11 @@ type NoticeSetting struct {
// 是否推送 【是:1】【否:2】
IsPush int
// 消息对应的业务模块
Module string
Module string
ModuleName string
// 业务环节
ModuleAction string
ModuleAction string
ModuleActionName string
// 消息id
NoticeSettingId int64 `pg:",pk"`
// 组织id
... ...
... ... @@ -7,15 +7,17 @@ import (
func TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel *models.NoticeSetting) (*domain.NoticeSetting, error) {
return &domain.NoticeSetting{
CompanyId: noticeSettingModel.CompanyId,
Content: noticeSettingModel.Content,
IsPush: noticeSettingModel.IsPush,
Module: noticeSettingModel.Module,
ModuleAction: noticeSettingModel.ModuleAction,
NoticeSettingId: noticeSettingModel.NoticeSettingId,
OrgId: noticeSettingModel.OrgId,
CreatedAt: noticeSettingModel.CreatedAt,
DeletedAt: noticeSettingModel.DeletedAt,
UpdatedAt: noticeSettingModel.UpdatedAt,
CompanyId: noticeSettingModel.CompanyId,
Content: noticeSettingModel.Content,
IsPush: noticeSettingModel.IsPush,
Module: noticeSettingModel.Module,
ModuleName: noticeSettingModel.ModuleName,
ModuleAction: noticeSettingModel.ModuleAction,
ModuleActionName: noticeSettingModel.ModuleName,
NoticeSettingId: noticeSettingModel.NoticeSettingId,
OrgId: noticeSettingModel.OrgId,
CreatedAt: noticeSettingModel.CreatedAt,
DeletedAt: noticeSettingModel.DeletedAt,
UpdatedAt: noticeSettingModel.UpdatedAt,
}, nil
}
... ...
... ... @@ -25,7 +25,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
"content",
"is_push",
"module",
"module_name",
"module_action",
"module_action_name",
"notice_setting_id",
"org_id",
"created_at",
... ... @@ -51,7 +53,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
&noticeSetting.Content,
&noticeSetting.IsPush,
&noticeSetting.Module,
&noticeSetting.ModuleName,
&noticeSetting.ModuleAction,
&noticeSetting.ModuleActionName,
&noticeSetting.NoticeSettingId,
&noticeSetting.OrgId,
&noticeSetting.CreatedAt,
... ... @@ -63,7 +67,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
noticeSetting.Content,
noticeSetting.IsPush,
noticeSetting.Module,
noticeSetting.ModuleName,
noticeSetting.ModuleAction,
noticeSetting.ModuleActionName,
noticeSetting.NoticeSettingId,
noticeSetting.OrgId,
noticeSetting.CreatedAt,
... ... @@ -79,7 +85,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
&noticeSetting.Content,
&noticeSetting.IsPush,
&noticeSetting.Module,
&noticeSetting.ModuleName,
&noticeSetting.ModuleAction,
&noticeSetting.ModuleActionName,
&noticeSetting.NoticeSettingId,
&noticeSetting.OrgId,
&noticeSetting.CreatedAt,
... ... @@ -91,7 +99,9 @@ func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSett
noticeSetting.Content,
noticeSetting.IsPush,
noticeSetting.Module,
noticeSetting.ModuleName,
noticeSetting.ModuleAction,
noticeSetting.ModuleActionName,
noticeSetting.NoticeSettingId,
noticeSetting.OrgId,
noticeSetting.CreatedAt,
... ... @@ -144,6 +154,11 @@ func (repository *NoticeSettingRepository) Find(queryOptions map[string]interfac
query.SetWhereByQueryOption("notice_setting.module_action=?", "moduleAction")
query.SetWhereByQueryOption("notice_setting.org_id=?", "orgId")
query.SetWhereByQueryOption("notice_setting.company_id=?", "companyId")
query.SetWhereByQueryOption("notice_setting.module_action_name like ?", "moduleActionName")
if v, ok := queryOptions["orgIds"]; ok {
query.WhereIn("notice_setting.orgId in (?)", v)
}
if count, err := query.SelectAndCount(); err != nil {
return 0, noticeSettings, err
} else {
... ...
... ... @@ -132,6 +132,7 @@ func (repository *SystemSettingRepository) Find(queryOptions map[string]interfac
query.SetOrderDirect("system_setting_id", "DESC")
query.SetWhereByQueryOption("system_setting.setting_code=?", "settingCode")
query.SetWhereByQueryOption("system_setting.company_id=?", "companyId")
if count, err := query.SelectAndCount(); err != nil {
return 0, systemSettings, err
} else {
... ...