作者 tangxuhui

更新

@@ -13,3 +13,19 @@ func CreateDictionaryRepository(options map[string]interface{}) (domain.Dictiona @@ -13,3 +13,19 @@ func CreateDictionaryRepository(options map[string]interface{}) (domain.Dictiona
13 } 13 }
14 return repository.NewDictionaryRepository(transactionContext) 14 return repository.NewDictionaryRepository(transactionContext)
15 } 15 }
  16 +
  17 +func CreateNoticeSettingRepository(options map[string]interface{}) (domain.NoticeSettingRepository, error) {
  18 + var transactionContext *pg.TransactionContext
  19 + if value, ok := options["transactionContext"]; ok {
  20 + transactionContext = value.(*pg.TransactionContext)
  21 + }
  22 + return repository.NewNoticeSettingRepository(transactionContext)
  23 +}
  24 +
  25 +func CreateNoticeEmptyRepository(options map[string]interface{}) (domain.NoticeEmptyRepository, error) {
  26 + var transactionContext *pg.TransactionContext
  27 + if value, ok := options["transactionContext"]; ok {
  28 + transactionContext = value.(*pg.TransactionContext)
  29 + }
  30 + return repository.NewNoticeEmptyRepository(transactionContext)
  31 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type RemoveNoticeSettingCommand struct {
  10 + // 消息id
  11 + NoticeSettingId int64 `json:"noticeSettingId" valid:"Required"`
  12 +}
  13 +
  14 +func (removeNoticeSettingCommand *RemoveNoticeSettingCommand) Valid(validation *validation.Validation) {
  15 + validation.SetError("CustomValid", "未实现的自定义认证")
  16 +}
  17 +
  18 +func (removeNoticeSettingCommand *RemoveNoticeSettingCommand) ValidateCommand() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(removeNoticeSettingCommand)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type UpdateNoticeSettingCommand struct {
  10 + NoticeSettingId int64 `json:"noticeSettingId"`
  11 + // 公司id
  12 + CompanyId int64 `json:"companyId"`
  13 + // 内容模板
  14 + Content string `json:"content"`
  15 + // 是否推送 【是:1】【否:2】
  16 + IsPush int `json:"isPush"`
  17 + // 消息对应的业务模块
  18 + Module string `json:"module"`
  19 + // 业务环节
  20 + ModuleAction string `json:"moduleAction"`
  21 + // 组织id
  22 + OrganizationId int64 `json:"organizationId"`
  23 + // 消息对应的编码
  24 + SysCode string `json:"sysCode"`
  25 +}
  26 +
  27 +func (updateNoticeSettingCommand *UpdateNoticeSettingCommand) Valid(validation *validation.Validation) {
  28 + validation.SetError("CustomValid", "未实现的自定义认证")
  29 +}
  30 +
  31 +func (updateNoticeSettingCommand *UpdateNoticeSettingCommand) ValidateCommand() error {
  32 + valid := validation.Validation{}
  33 + b, err := valid.Valid(updateNoticeSettingCommand)
  34 + if err != nil {
  35 + return err
  36 + }
  37 + if !b {
  38 + for _, validErr := range valid.Errors {
  39 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  40 + }
  41 + }
  42 + return nil
  43 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type GetNoticeSettingQuery struct {
  10 + // 消息id
  11 + NoticeSettingId int64 `json:"noticeSettingId" valid:"Required"`
  12 +}
  13 +
  14 +func (getNoticeSettingQuery *GetNoticeSettingQuery) Valid(validation *validation.Validation) {
  15 + validation.SetError("CustomValid", "未实现的自定义认证")
  16 +}
  17 +
  18 +func (getNoticeSettingQuery *GetNoticeSettingQuery) ValidateQuery() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(getNoticeSettingQuery)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type ListNoticeSettingQuery struct {
  10 + // 查询偏离量
  11 + Offset int `json:"offset" valid:"Required"`
  12 + // 查询限制
  13 + Limit int `json:"limit" valid:"Required"`
  14 +}
  15 +
  16 +func (listNoticeSettingQuery *ListNoticeSettingQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (listNoticeSettingQuery *ListNoticeSettingQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(listNoticeSettingQuery)
  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 + "fmt"
  5 +
  6 + "github.com/linmadan/egglib-go/core/application"
  7 + "github.com/linmadan/egglib-go/utils/tool_funs"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticeSetting/command"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticeSetting/query"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
  12 +)
  13 +
  14 +// 编排消息通知内容
  15 +type NoticeSettingService struct {
  16 +}
  17 +
  18 +// 返回编排消息通知内容
  19 +func (noticeSettingService *NoticeSettingService) GetNoticeSetting(getNoticeSettingQuery *query.GetNoticeSettingQuery) (interface{}, error) {
  20 + if err := getNoticeSettingQuery.ValidateQuery(); err != nil {
  21 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  22 + }
  23 + transactionContext, err := factory.CreateTransactionContext(nil)
  24 + if err != nil {
  25 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  26 + }
  27 + if err := transactionContext.StartTransaction(); err != nil {
  28 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  29 + }
  30 + defer func() {
  31 + transactionContext.RollbackTransaction()
  32 + }()
  33 + var noticeSettingRepository domain.NoticeSettingRepository
  34 + if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
  35 + "transactionContext": transactionContext,
  36 + }); err != nil {
  37 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  38 + } else {
  39 + noticeSettingRepository = value
  40 + }
  41 + noticeSetting, err := noticeSettingRepository.FindOne(map[string]interface{}{"noticeSettingId": getNoticeSettingQuery.NoticeSettingId})
  42 + if err != nil {
  43 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  44 + }
  45 + if noticeSetting == nil {
  46 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getNoticeSettingQuery.NoticeSettingId)))
  47 + } else {
  48 + if err := transactionContext.CommitTransaction(); err != nil {
  49 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  50 + }
  51 + return noticeSetting, nil
  52 + }
  53 +}
  54 +
  55 +// 返回编排消息通知内容列表
  56 +func (noticeSettingService *NoticeSettingService) ListNoticeSetting(listNoticeSettingQuery *query.ListNoticeSettingQuery) (interface{}, error) {
  57 + if err := listNoticeSettingQuery.ValidateQuery(); err != nil {
  58 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  59 + }
  60 + transactionContext, err := factory.CreateTransactionContext(nil)
  61 + if err != nil {
  62 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  63 + }
  64 + if err := transactionContext.StartTransaction(); err != nil {
  65 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  66 + }
  67 + defer func() {
  68 + transactionContext.RollbackTransaction()
  69 + }()
  70 + var noticeSettingRepository domain.NoticeSettingRepository
  71 + if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
  72 + "transactionContext": transactionContext,
  73 + }); err != nil {
  74 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  75 + } else {
  76 + noticeSettingRepository = value
  77 + }
  78 + if count, noticeSettings, err := noticeSettingRepository.Find(tool_funs.SimpleStructToMap(listNoticeSettingQuery)); err != nil {
  79 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  80 + } else {
  81 + if err := transactionContext.CommitTransaction(); err != nil {
  82 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  83 + }
  84 + return map[string]interface{}{
  85 + "count": count,
  86 + "noticeSettings": noticeSettings,
  87 + }, nil
  88 + }
  89 +}
  90 +
  91 +// 更新编排消息通知内容
  92 +func (noticeSettingService *NoticeSettingService) UpdateNoticeSetting(updateNoticeSettingCommand *command.UpdateNoticeSettingCommand) (interface{}, error) {
  93 + if err := updateNoticeSettingCommand.ValidateCommand(); err != nil {
  94 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  95 + }
  96 + transactionContext, err := factory.CreateTransactionContext(nil)
  97 + if err != nil {
  98 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  99 + }
  100 + if err := transactionContext.StartTransaction(); err != nil {
  101 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  102 + }
  103 + defer func() {
  104 + transactionContext.RollbackTransaction()
  105 + }()
  106 + var noticeSettingRepository domain.NoticeSettingRepository
  107 + if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
  108 + "transactionContext": transactionContext,
  109 + }); err != nil {
  110 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  111 + } else {
  112 + noticeSettingRepository = value
  113 + }
  114 +
  115 + noticeSetting, err := noticeSettingRepository.FindOne(map[string]interface{}{"noticeSettingId": updateNoticeSettingCommand.NoticeSettingId})
  116 + if err != nil {
  117 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  118 + }
  119 + if noticeSetting == nil {
  120 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateNoticeSettingCommand.NoticeSettingId)))
  121 + }
  122 + if err := noticeSetting.Update(tool_funs.SimpleStructToMap(updateNoticeSettingCommand)); err != nil {
  123 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  124 + }
  125 + if noticeSetting, err := noticeSettingRepository.Save(noticeSetting); err != nil {
  126 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  127 + } else {
  128 + if err := transactionContext.CommitTransaction(); err != nil {
  129 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  130 + }
  131 + return noticeSetting, nil
  132 + }
  133 +}
  134 +
  135 +func NewNoticeSettingService(options map[string]interface{}) *NoticeSettingService {
  136 + newNoticeSettingService := &NoticeSettingService{}
  137 + return newNoticeSettingService
  138 +}
  1 +package domain
  2 +
  3 +// 系统默认的空白消息配置样板
  4 +type NoticeEmpty struct {
  5 + // 消息id
  6 + NoticeEmptyId int64 `json:"noticeEmptyId"`
  7 + // 内容模板
  8 + Content string `json:"content"`
  9 + // 是否推送 【是:1】【否:2】
  10 + IsPush int `json:"isPush"`
  11 + // 消息对应的业务模块
  12 + Module string `json:"module"`
  13 + // 业务环节
  14 + ModuleAction string `json:"moduleAction"`
  15 + // 消息对应的编码
  16 + SysCode string `json:"sysCode"`
  17 +}
  18 +
  19 +type NoticeEmptyRepository interface {
  20 + // Save(noticeEmpty *NoticeEmpty) (*NoticeEmpty, error) //用不到
  21 + // Remove(noticeEmpty *NoticeEmpty) (*NoticeEmpty, error)//用户不到
  22 + // FindOne(queryOptions map[string]interface{}) (*NoticeEmpty, error) //用不到
  23 + Find(queryOptions map[string]interface{}) (int64, []*NoticeEmpty, error)
  24 +}
  25 +
  26 +func (noticeEmpty *NoticeEmpty) Identify() interface{} {
  27 + if noticeEmpty.NoticeEmptyId == 0 {
  28 + return nil
  29 + }
  30 + return noticeEmpty.NoticeEmptyId
  31 +}
  32 +
  33 +func (noticeEmpty *NoticeEmpty) Update(data map[string]interface{}) error {
  34 + if noticeEmptyId, ok := data["noticeEmptyId"]; ok {
  35 + noticeEmpty.NoticeEmptyId = noticeEmptyId.(int64)
  36 + }
  37 + if content, ok := data["content"]; ok {
  38 + noticeEmpty.Content = content.(string)
  39 + }
  40 + if isPush, ok := data["isPush"]; ok {
  41 + noticeEmpty.IsPush = isPush.(int)
  42 + }
  43 + if module, ok := data["module"]; ok {
  44 + noticeEmpty.Module = module.(string)
  45 + }
  46 + if moduleAction, ok := data["moduleAction"]; ok {
  47 + noticeEmpty.ModuleAction = moduleAction.(string)
  48 + }
  49 + if sysCode, ok := data["sysCode"]; ok {
  50 + noticeEmpty.SysCode = sysCode.(string)
  51 + }
  52 + return nil
  53 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 编排消息通知内容
  6 +type NoticeSetting struct {
  7 + // 消息id
  8 + NoticeSettingId int64 `json:"noticeSettingId"`
  9 + // 公司id
  10 + CompanyId int64 `json:"companyId"`
  11 + // 内容模板
  12 + Content string `json:"content"`
  13 + // 是否推送 【是:1】【否:2】
  14 + IsPush int `json:"isPush"`
  15 + // 消息对应的业务模块
  16 + Module string `json:"module"`
  17 + // 业务环节
  18 + ModuleAction string `json:"moduleAction"`
  19 + // 组织id
  20 + OrgId int64 `json:"orgId"`
  21 + // 消息对应的编码
  22 + SysCode string `json:"sysCode"`
  23 + // 创建时间
  24 + CreatedAt time.Time `json:"createdAt"`
  25 + // 删除时间
  26 + DeletedAt time.Time `json:"deletedAt"`
  27 + // 更新时间
  28 + UpdatedAt time.Time `json:"updatedAt"`
  29 +}
  30 +
  31 +type NoticeSettingRepository interface {
  32 + Save(noticeSetting *NoticeSetting) (*NoticeSetting, error)
  33 + Remove(noticeSetting *NoticeSetting) (*NoticeSetting, error)
  34 + FindOne(queryOptions map[string]interface{}) (*NoticeSetting, error)
  35 + Find(queryOptions map[string]interface{}) (int64, []*NoticeSetting, error)
  36 +}
  37 +
  38 +func (noticeSetting *NoticeSetting) Identify() interface{} {
  39 + if noticeSetting.NoticeSettingId == 0 {
  40 + return nil
  41 + }
  42 + return noticeSetting.NoticeSettingId
  43 +}
  44 +
  45 +func (noticeSetting *NoticeSetting) Update(data map[string]interface{}) error {
  46 + if companyId, ok := data["companyId"]; ok {
  47 + noticeSetting.CompanyId = companyId.(int64)
  48 + }
  49 + if content, ok := data["content"]; ok {
  50 + noticeSetting.Content = content.(string)
  51 + }
  52 + if isPush, ok := data["isPush"]; ok {
  53 + noticeSetting.IsPush = isPush.(int)
  54 + }
  55 + if module, ok := data["module"]; ok {
  56 + noticeSetting.Module = module.(string)
  57 + }
  58 + if moduleAction, ok := data["moduleAction"]; ok {
  59 + noticeSetting.ModuleAction = moduleAction.(string)
  60 + }
  61 + if noticeSettingId, ok := data["noticeSettingId"]; ok {
  62 + noticeSetting.NoticeSettingId = noticeSettingId.(int64)
  63 + }
  64 + if organizationId, ok := data["orgId"]; ok {
  65 + noticeSetting.OrgId = organizationId.(int64)
  66 + }
  67 + if sysCode, ok := data["sysCode"]; ok {
  68 + noticeSetting.SysCode = sysCode.(string)
  69 + }
  70 + if createdAt, ok := data["createdAt"]; ok {
  71 + noticeSetting.CreatedAt = createdAt.(time.Time)
  72 + }
  73 + if deletedAt, ok := data["deletedAt"]; ok {
  74 + noticeSetting.DeletedAt = deletedAt.(time.Time)
  75 + }
  76 + if updatedAt, ok := data["updatedAt"]; ok {
  77 + noticeSetting.UpdatedAt = updatedAt.(time.Time)
  78 + }
  79 + return nil
  80 +}
  1 +package domain
  2 +
  3 +//NoticeModule 消息模块
  4 +type NoticeModule struct {
  5 + ModuleCode string `json:"Code"`
  6 + Name string `json:"name"`
  7 +}
  8 +
  9 +//NoticeModuleAction 业务环节
  10 +type NoticeModuleAction struct {
  11 + ModuleCode string `json:"module_code"`
  12 + ActionCode string `json:"action_Code"`
  13 + Name string `json:"name"`
  14 +}
  15 +
  16 +// 编排消息需要的变量
  17 +type NoticeSettingParam struct {
  18 + // 变量的代码标识
  19 + ParamCode string `json:"paramCode"`
  20 + // 变量名称描述
  21 + ParamName string `json:"paramName"`
  22 + // 业务环节
  23 + ModuleAction string `json:"moduleAction"`
  24 + // 消息对应的业务模块
  25 + Module string `json:"module"`
  26 +}
  27 +
  28 +//GetNoticeModuleList 获取消息模块列表
  29 +func GetNoticeModuleList() []NoticeModule {
  30 + return noticeModuleList
  31 +}
  32 +
  33 +//GetNoticeModuleActionList 获取业务环节列表
  34 +func GetNoticeModuleActionList() []NoticeModuleAction {
  35 + return noticeModuleActionList
  36 +}
  37 +
  38 +//GetNoticeSettingParamList 获取变量列表
  39 +func GetNoticeSettingParamList(actionCode string) []NoticeSettingParam {
  40 + if len(actionCode) == 0 {
  41 + return noticeSettingParamList
  42 + }
  43 + var list []NoticeSettingParam
  44 + for i := range noticeSettingParamList {
  45 + if noticeSettingParamList[i].ModuleAction == actionCode {
  46 + list = append(list, noticeSettingParamList[i])
  47 + }
  48 + }
  49 + return list
  50 +}
  51 +
  52 +//ValidNoticeModule 校验NoticeModule编码
  53 +func ValidNoticeModule(code string) bool {
  54 + for i := range noticeModuleList {
  55 + if noticeModuleList[i].ModuleCode == code {
  56 + return true
  57 + }
  58 + }
  59 + return false
  60 +}
  61 +
  62 +//ValidNoticeModuleAction 校验NoticeModuleAction编码
  63 +func ValidNoticeModuleAction(moduleCode string, actioncode string) bool {
  64 + for i := range noticeModuleActionList {
  65 + if (noticeModuleActionList[i].ActionCode == actioncode) &&
  66 + (noticeModuleActionList[i].ModuleCode == moduleCode) {
  67 + return true
  68 + }
  69 + }
  70 + return false
  71 +}
  72 +
  73 +//业务模块
  74 +const (
  75 + Module01 = "module01" // 天联共创
  76 +)
  77 +
  78 +//业务环节
  79 +const (
  80 + Action01_01 = "action01_01" //天联共创-共创申请通过
  81 + Action01_02 = "action01_02" //天联共创-共创申请拒绝
  82 + Action01_03 = "action01_03" //天联共创-共创确认
  83 + Action01_04 = "action01_04" //天联共创-分红预算消息
  84 + Action01_05 = "action01_05" //天联共创-账期结算消息
  85 + Action01_06 = "action01_06" //天联共创-支付消息
  86 +)
  87 +
  88 +//业务环节变量
  89 +const (
  90 + Param01_01_01 = "param01_01_01" //共创申请通过-共创项目编号
  91 + Param01_01_02 = "param01_01_02" //共创申请通过-共创项目名称
  92 +
  93 + Param01_02_01 = "param01_02_01" //共创申请拒绝-共创项目编号
  94 + Param01_02_02 = "param01_02_02" //共创申请拒绝-共创项目名称
  95 +
  96 + Param01_03_01 = "param01_03_01" //共创确认-共创项目编号
  97 + Param01_03_02 = "param01_03_02" //共创确认-共创项目名称
  98 + Param01_03_03 = "param01_03_03" //共创确认-项目合约编号
  99 + Param01_03_04 = "param01_03_04" //共创确认-项目合约名称
  100 +
  101 + Param01_04_01 = "param01_04_01" //分红预算消息-共创项目编号
  102 + Param01_04_02 = "param01_04_02" //分红预算消息-共创项目名称
  103 + Param01_04_03 = "param01_04_03" //分红预算消息-项目合约编号
  104 + Param01_04_04 = "param01_04_04" //分红预算消息-项目合约名称
  105 + Param01_04_05 = "param01_04_05" //分红预算消息-订单产品信息
  106 + Param01_04_06 = "param01_04_06" //分红预算消息-分红金额
  107 +
  108 + Param01_05_01 = "param01_05_01" //账期结算消息-账期结算单号
  109 + Param01_05_02 = "param01_05_02" //账期结算消息-结算金额
  110 + Param01_05_03 = "param01_05_03" //账期结算消息-分红预算单号
  111 +
  112 + Param01_06_01 = "param01_06_01" //支付消息-账期结算单号
  113 + Param01_06_02 = "param01_06_02" //支付消息-结算金额
  114 + Param01_06_03 = "param01_06_03" //支付消息-实付金额
  115 +)
  116 +
  117 +//noticeModuleList 模块列表
  118 +var noticeModuleList = []NoticeModule{
  119 + {ModuleCode: Module01, Name: "天联共创"},
  120 +}
  121 +
  122 +//noticeModuleActionList 业务环节列表
  123 +var noticeModuleActionList = []NoticeModuleAction{
  124 + {ModuleCode: Module01, ActionCode: Action01_01, Name: "共创申请通过"},
  125 + {ModuleCode: Module01, ActionCode: Action01_02, Name: "共创申请拒绝"},
  126 + {ModuleCode: Module01, ActionCode: Action01_03, Name: "共创确认"},
  127 + {ModuleCode: Module01, ActionCode: Action01_04, Name: "分红预算消息"},
  128 + {ModuleCode: Module01, ActionCode: Action01_05, Name: "账期结算消息"},
  129 + {ModuleCode: Module01, ActionCode: Action01_06, Name: "支付消息"},
  130 +}
  131 +
  132 +//noticeSettingParamList 业务变量列表
  133 +var noticeSettingParamList = []NoticeSettingParam{
  134 + {ModuleAction: Module01, Module: Action01_01, ParamCode: Param01_01_01, ParamName: "共创项目编号"},
  135 + {ModuleAction: Module01, Module: Action01_01, ParamCode: Param01_01_02, ParamName: "共创项目名称"},
  136 +
  137 + {ModuleAction: Module01, Module: Action01_02, ParamCode: Param01_02_01, ParamName: "共创项目编号"},
  138 + {ModuleAction: Module01, Module: Action01_02, ParamCode: Param01_02_02, ParamName: "共创项目名称"},
  139 +
  140 + {ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_01, ParamName: "共创项目编号"},
  141 + {ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_02, ParamName: "共创项目名称"},
  142 + {ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_03, ParamName: "项目合约编号"},
  143 + {ModuleAction: Module01, Module: Action01_03, ParamCode: Param01_03_04, ParamName: "项目合约名称"},
  144 +
  145 + {ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_01, ParamName: "共创项目编号"},
  146 + {ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_02, ParamName: "共创项目名称"},
  147 + {ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_03, ParamName: "项目合约编号"},
  148 + {ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_04, ParamName: "项目合约名称"},
  149 + {ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_05, ParamName: "订单产品信息"},
  150 + {ModuleAction: Module01, Module: Action01_04, ParamCode: Param01_04_06, ParamName: "分红金额"},
  151 +
  152 + {ModuleAction: Module01, Module: Action01_05, ParamCode: Param01_05_01, ParamName: "账期结算单号"},
  153 + {ModuleAction: Module01, Module: Action01_05, ParamCode: Param01_05_02, ParamName: "结算金额"},
  154 + {ModuleAction: Module01, Module: Action01_05, ParamCode: Param01_05_03, ParamName: "分红预算单号"},
  155 +
  156 + {ModuleAction: Module01, Module: Action01_06, ParamCode: Param01_06_01, ParamName: "账期结算单号"},
  157 + {ModuleAction: Module01, Module: Action01_06, ParamCode: Param01_06_02, ParamName: "结算金额"},
  158 + {ModuleAction: Module01, Module: Action01_06, ParamCode: Param01_06_03, ParamName: "实付金额"},
  159 +}
@@ -5,7 +5,7 @@ import ( @@ -5,7 +5,7 @@ import (
5 ) 5 )
6 6
7 type Dictionary struct { 7 type Dictionary struct {
8 - tableName string `pg:"dictionary"` 8 + tableName string `pg:"dictionarys"`
9 // 字典编号 主键 9 // 字典编号 主键
10 DictionaryId int64 `pg:",pk"` 10 DictionaryId int64 `pg:",pk"`
11 // 字典编码 11 // 字典编码
  1 +package models
  2 +
  3 +type NoticeEmpty struct {
  4 + tableName string `pg:"notice_emptys,alias:notice_empty"`
  5 + // 消息id
  6 + NoticeEmptyId int64
  7 + // 内容模板
  8 + Content string
  9 + // 是否推送 【是:1】【否:2】
  10 + IsPush int
  11 + // 消息对应的业务模块
  12 + Module string
  13 + // 业务环节
  14 + ModuleAction string
  15 + // 消息对应的编码
  16 + SysCode string
  17 +}
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type NoticeSetting struct {
  6 + tableName string `pg:"notice_settings"`
  7 + // 公司id
  8 + CompanyId int64
  9 + // 内容模板
  10 + Content string
  11 + // 是否推送 【是:1】【否:2】
  12 + IsPush int
  13 + // 消息对应的业务模块
  14 + Module string
  15 + // 业务环节
  16 + ModuleAction string
  17 + // 消息id
  18 + NoticeSettingId int64
  19 + // 组织id
  20 + OrgId int64
  21 + // 消息对应的编码
  22 + SysCode string
  23 + // 创建时间
  24 + CreatedAt time.Time
  25 + // 删除时间
  26 + DeletedAt time.Time
  27 + // 更新时间
  28 + UpdatedAt time.Time
  29 +}
  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 TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel *models.NoticeEmpty) (*domain.NoticeEmpty, error) {
  9 + return &domain.NoticeEmpty{
  10 + NoticeEmptyId: noticeEmptyModel.NoticeEmptyId,
  11 + Content: noticeEmptyModel.Content,
  12 + IsPush: noticeEmptyModel.IsPush,
  13 + Module: noticeEmptyModel.Module,
  14 + ModuleAction: noticeEmptyModel.ModuleAction,
  15 + SysCode: noticeEmptyModel.SysCode,
  16 + }, nil
  17 +}
  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 TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel *models.NoticeSetting) (*domain.NoticeSetting, error) {
  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 + OrganizationId: noticeSettingModel.OrganizationId,
  17 + SysCode: noticeSettingModel.SysCode,
  18 + CreatedAt: noticeSettingModel.CreatedAt,
  19 + DeletedAt: noticeSettingModel.DeletedAt,
  20 + UpdatedAt: noticeSettingModel.UpdatedAt,
  21 + }, nil
  22 +}
  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 + "github.com/linmadan/egglib-go/utils/snowflake"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
  11 + "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"
  13 +)
  14 +
  15 +type NoticeEmptyRepository struct {
  16 + transactionContext *pgTransaction.TransactionContext
  17 +}
  18 +
  19 +func (repository *NoticeEmptyRepository) nextIdentify() (int64, error) {
  20 + IdWorker, err := snowflake.NewIdWorker(1)
  21 + if err != nil {
  22 + return 0, err
  23 + }
  24 + id, err := IdWorker.NextId()
  25 + return id, err
  26 +}
  27 +
  28 +func (repository *NoticeEmptyRepository) Save(noticeEmpty *domain.NoticeEmpty) (*domain.NoticeEmpty, error) {
  29 + sqlBuildFields := []string{
  30 + "notice_empty_id",
  31 + "content",
  32 + "is_push",
  33 + "module",
  34 + "module_action",
  35 + "sys_code",
  36 + }
  37 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  38 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
  39 + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  40 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "noticeEmpty_id")
  41 + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
  42 + tx := repository.transactionContext.PgTx
  43 + if noticeEmpty.Identify() == nil {
  44 + noticeEmptyId, err := repository.nextIdentify()
  45 + if err != nil {
  46 + return noticeEmpty, err
  47 + } else {
  48 + noticeEmpty.NoticeEmptyId = noticeEmptyId
  49 + }
  50 + if _, err := tx.QueryOne(
  51 + pg.Scan(
  52 + &noticeEmpty.NoticeEmptyId,
  53 + &noticeEmpty.Content,
  54 + &noticeEmpty.IsPush,
  55 + &noticeEmpty.Module,
  56 + &noticeEmpty.ModuleAction,
  57 + &noticeEmpty.SysCode,
  58 + ),
  59 + fmt.Sprintf("INSERT INTO notice_emptys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  60 + noticeEmpty.NoticeEmptyId,
  61 + noticeEmpty.Content,
  62 + noticeEmpty.IsPush,
  63 + noticeEmpty.Module,
  64 + noticeEmpty.ModuleAction,
  65 + noticeEmpty.SysCode,
  66 + ); err != nil {
  67 + return noticeEmpty, err
  68 + }
  69 + } else {
  70 + if _, err := tx.QueryOne(
  71 + pg.Scan(
  72 + &noticeEmpty.NoticeEmptyId,
  73 + &noticeEmpty.Content,
  74 + &noticeEmpty.IsPush,
  75 + &noticeEmpty.Module,
  76 + &noticeEmpty.ModuleAction,
  77 + &noticeEmpty.SysCode,
  78 + ),
  79 + fmt.Sprintf("UPDATE notice_emptys SET %s WHERE notice_empty_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  80 + noticeEmpty.NoticeEmptyId,
  81 + noticeEmpty.Content,
  82 + noticeEmpty.IsPush,
  83 + noticeEmpty.Module,
  84 + noticeEmpty.ModuleAction,
  85 + noticeEmpty.SysCode,
  86 + noticeEmpty.Identify(),
  87 + ); err != nil {
  88 + return noticeEmpty, err
  89 + }
  90 + }
  91 + return noticeEmpty, nil
  92 +}
  93 +
  94 +func (repository *NoticeEmptyRepository) Remove(noticeEmpty *domain.NoticeEmpty) (*domain.NoticeEmpty, error) {
  95 + tx := repository.transactionContext.PgTx
  96 + noticeEmptyModel := new(models.NoticeEmpty)
  97 + noticeEmptyModel.NoticeEmptyId = noticeEmpty.Identify().(int64)
  98 + if _, err := tx.Model(noticeEmptyModel).WherePK().Delete(); err != nil {
  99 + return noticeEmpty, err
  100 + }
  101 + return noticeEmpty, nil
  102 +}
  103 +func (repository *NoticeEmptyRepository) FindOne(queryOptions map[string]interface{}) (*domain.NoticeEmpty, error) {
  104 + tx := repository.transactionContext.PgTx
  105 + noticeEmptyModel := new(models.NoticeEmpty)
  106 + query := sqlbuilder.BuildQuery(tx.Model(noticeEmptyModel), queryOptions)
  107 + query.SetWhereByQueryOption("notice_empty.notice_empty_id = ?", "noticeEmptyId")
  108 + if err := query.First(); err != nil {
  109 + if err.Error() == "pg: no rows in result set" {
  110 + return nil, fmt.Errorf("没有此资源")
  111 + } else {
  112 + return nil, err
  113 + }
  114 + }
  115 + if noticeEmptyModel.NoticeEmptyId == 0 {
  116 + return nil, nil
  117 + } else {
  118 + return transform.TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel)
  119 + }
  120 +}
  121 +func (repository *NoticeEmptyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.NoticeEmpty, error) {
  122 + tx := repository.transactionContext.PgTx
  123 + var noticeEmptyModels []*models.NoticeEmpty
  124 + noticeEmptys := make([]*domain.NoticeEmpty, 0)
  125 + query := sqlbuilder.BuildQuery(tx.Model(&noticeEmptyModels), queryOptions)
  126 + query.SetOffsetAndLimit(20)
  127 + query.SetOrderDirect("notice_empty_id", "DESC")
  128 + if count, err := query.SelectAndCount(); err != nil {
  129 + return 0, noticeEmptys, err
  130 + } else {
  131 + for _, noticeEmptyModel := range noticeEmptyModels {
  132 + if noticeEmpty, err := transform.TransformToNoticeEmptyDomainModelFromPgModels(noticeEmptyModel); err != nil {
  133 + return 0, noticeEmptys, err
  134 + } else {
  135 + noticeEmptys = append(noticeEmptys, noticeEmpty)
  136 + }
  137 + }
  138 + return int64(count), noticeEmptys, nil
  139 + }
  140 +}
  141 +func NewNoticeEmptyRepository(transactionContext *pgTransaction.TransactionContext) (*NoticeEmptyRepository, error) {
  142 + if transactionContext == nil {
  143 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  144 + } else {
  145 + return &NoticeEmptyRepository{
  146 + transactionContext: transactionContext,
  147 + }, nil
  148 + }
  149 +}
  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 NoticeSettingRepository struct {
  15 + transactionContext *pgTransaction.TransactionContext
  16 +}
  17 +
  18 +func (repository *NoticeSettingRepository) nextIdentify() (int64, error) {
  19 + id, err := idWorker.NextId()
  20 + return id, err
  21 +}
  22 +func (repository *NoticeSettingRepository) Save(noticeSetting *domain.NoticeSetting) (*domain.NoticeSetting, error) {
  23 + sqlBuildFields := []string{
  24 + "company_id",
  25 + "content",
  26 + "is_push",
  27 + "module",
  28 + "module_action",
  29 + "notice_setting_id",
  30 + "organization_id",
  31 + "sys_code",
  32 + "created_at",
  33 + "deleted_at",
  34 + "updated_at",
  35 + }
  36 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  37 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
  38 + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  39 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "noticeSetting_id")
  40 + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
  41 + tx := repository.transactionContext.PgTx
  42 + if noticeSetting.Identify() == nil {
  43 + noticeSettingId, err := repository.nextIdentify()
  44 + if err != nil {
  45 + return noticeSetting, err
  46 + } else {
  47 + noticeSetting.NoticeSettingId = noticeSettingId
  48 + }
  49 + if _, err := tx.QueryOne(
  50 + pg.Scan(
  51 + &noticeSetting.CompanyId,
  52 + &noticeSetting.Content,
  53 + &noticeSetting.IsPush,
  54 + &noticeSetting.Module,
  55 + &noticeSetting.ModuleAction,
  56 + &noticeSetting.NoticeSettingId,
  57 + &noticeSetting.OrgId,
  58 + &noticeSetting.SysCode,
  59 + &noticeSetting.CreatedAt,
  60 + &noticeSetting.DeletedAt,
  61 + &noticeSetting.UpdatedAt,
  62 + ),
  63 + fmt.Sprintf("INSERT INTO notice_settings (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  64 + noticeSetting.CompanyId,
  65 + noticeSetting.Content,
  66 + noticeSetting.IsPush,
  67 + noticeSetting.Module,
  68 + noticeSetting.ModuleAction,
  69 + noticeSetting.NoticeSettingId,
  70 + noticeSetting.OrgId,
  71 + noticeSetting.SysCode,
  72 + noticeSetting.CreatedAt,
  73 + noticeSetting.DeletedAt,
  74 + noticeSetting.UpdatedAt,
  75 + ); err != nil {
  76 + return noticeSetting, err
  77 + }
  78 + } else {
  79 + if _, err := tx.QueryOne(
  80 + pg.Scan(
  81 + &noticeSetting.CompanyId,
  82 + &noticeSetting.Content,
  83 + &noticeSetting.IsPush,
  84 + &noticeSetting.Module,
  85 + &noticeSetting.ModuleAction,
  86 + &noticeSetting.NoticeSettingId,
  87 + &noticeSetting.OrgId,
  88 + &noticeSetting.SysCode,
  89 + &noticeSetting.CreatedAt,
  90 + &noticeSetting.DeletedAt,
  91 + &noticeSetting.UpdatedAt,
  92 + ),
  93 + fmt.Sprintf("UPDATE notice_settings SET %s WHERE notice_setting_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  94 + noticeSetting.CompanyId,
  95 + noticeSetting.Content,
  96 + noticeSetting.IsPush,
  97 + noticeSetting.Module,
  98 + noticeSetting.ModuleAction,
  99 + noticeSetting.NoticeSettingId,
  100 + noticeSetting.OrgId,
  101 + noticeSetting.SysCode,
  102 + noticeSetting.CreatedAt,
  103 + noticeSetting.DeletedAt,
  104 + noticeSetting.UpdatedAt,
  105 + noticeSetting.Identify(),
  106 + ); err != nil {
  107 + return noticeSetting, err
  108 + }
  109 + }
  110 + return noticeSetting, nil
  111 +}
  112 +func (repository *NoticeSettingRepository) Remove(noticeSetting *domain.NoticeSetting) (*domain.NoticeSetting, error) {
  113 + tx := repository.transactionContext.PgTx
  114 + noticeSettingModel := new(models.NoticeSetting)
  115 + noticeSettingModel.NoticeSettingId = noticeSetting.Identify().(int64)
  116 + if _, err := tx.Model(noticeSettingModel).WherePK().Delete(); err != nil {
  117 + return noticeSetting, err
  118 + }
  119 + return noticeSetting, nil
  120 +}
  121 +func (repository *NoticeSettingRepository) FindOne(queryOptions map[string]interface{}) (*domain.NoticeSetting, error) {
  122 + tx := repository.transactionContext.PgTx
  123 + noticeSettingModel := new(models.NoticeSetting)
  124 + query := sqlbuilder.BuildQuery(tx.Model(noticeSettingModel), queryOptions)
  125 + query.SetWhereByQueryOption("notice_setting.notice_setting_id = ?", "noticeSettingId")
  126 + query.SetWhereByQueryOption("notice_setting.module_action=?", "moduleAction")
  127 + if err := query.First(); err != nil {
  128 + if err.Error() == "pg: no rows in result set" {
  129 + return nil, fmt.Errorf("没有此资源")
  130 + } else {
  131 + return nil, err
  132 + }
  133 + }
  134 + if noticeSettingModel.NoticeSettingId == 0 {
  135 + return nil, nil
  136 + } else {
  137 + return transform.TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel)
  138 + }
  139 +}
  140 +func (repository *NoticeSettingRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.NoticeSetting, error) {
  141 + tx := repository.transactionContext.PgTx
  142 + var noticeSettingModels []*models.NoticeSetting
  143 + noticeSettings := make([]*domain.NoticeSetting, 0)
  144 + query := sqlbuilder.BuildQuery(tx.Model(&noticeSettingModels), queryOptions)
  145 + query.SetOffsetAndLimit(20)
  146 + query.SetOrderDirect("notice_setting_id", "DESC")
  147 + query.SetWhereByQueryOption("notice_setting.module_action=?", "moduleAction")
  148 + query.SetWhereByQueryOption("notice_setting.org_id=?", "orgId")
  149 + if count, err := query.SelectAndCount(); err != nil {
  150 + return 0, noticeSettings, err
  151 + } else {
  152 + for _, noticeSettingModel := range noticeSettingModels {
  153 + if noticeSetting, err := transform.TransformToNoticeSettingDomainModelFromPgModels(noticeSettingModel); err != nil {
  154 + return 0, noticeSettings, err
  155 + } else {
  156 + noticeSettings = append(noticeSettings, noticeSetting)
  157 + }
  158 + }
  159 + return int64(count), noticeSettings, nil
  160 + }
  161 +}
  162 +func NewNoticeSettingRepository(transactionContext *pgTransaction.TransactionContext) (*NoticeSettingRepository, error) {
  163 + if transactionContext == nil {
  164 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  165 + } else {
  166 + return &NoticeSettingRepository{
  167 + transactionContext: transactionContext,
  168 + }, nil
  169 + }
  170 +}