作者 tangxuhui

更新个人消息推送

... ... @@ -8,7 +8,10 @@ import (
type AgreeJoinCreationProjectCommand struct {
// 接收方用户id
UserId int64 `json:"userId" valid:"Required"`
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId" valid:"Required"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
// 共创项目名称
... ...
... ... @@ -8,9 +8,14 @@ import (
type InformExpectedDividendsCommand struct {
// 用户id
UserId int64 `json:"userId" valid:"Required"`
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
UserBaseId int64 `json:"userBaseId" valid:"Required"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
//共创项目编号
CreationProjectNumber string `json:"creationProjectNumber" valid:"Required"`
// 共创项目名称
CreationProjectName string `json:"creationProjectName" valid:"Required"`
// 共创合约id
... ... @@ -20,7 +25,11 @@ type InformExpectedDividendsCommand struct {
// 共创合约编号
CreationContractNumber string `json:"creationContractNumber" valid:"Required"`
// 产品名称
ProductName string `json:"productName" valid:"Required"`
ProductName []string `json:"productName" valid:"Required"`
//分红预算id
DividendsEstimateId int64 `json:"dividendsEstimateId" valid:"Required"`
//预算金额
DividendsAmount string `json:"dividendsAmount" valid:"Required"`
}
func (informExpectedDividendsCommand *InformExpectedDividendsCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -8,11 +8,16 @@ import (
type InformJoinCreationContractCommand struct {
// 接收方用户id
UserId int64 `json:"userId" valid:"Required"`
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
UserBaseId int64 `json:"userBaseId" valid:"Required"`
OrgId int64 `json:"orgId"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
// 共创项目名称
CreationProjectName string `json:"creationProjectName" valid:"Required"`
// 共创项目编号
CreationProjectNumber string `json:"creationProjectNumber" valid:"Required"`
// 共创合约id
CreationContractId int64 `json:"creationContractId" valid:"Required"`
// 共创合约名称
... ...
... ... @@ -8,7 +8,10 @@ import (
type RefuseJoinCreationProjectCommand struct {
// 接收方用户id
UserId int64 `json:"userId" valid:"Required"`
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
UserBaseId int64 `json:"userBaseId" valid:"Required"`
OrgId int64 `json:"orgId"`
// 共创项目id
CreationProjectId int64 `json:"creationProjectId" valid:"Required"`
// 共创项目名称
... ...
package service
import (
"bytes"
"encoding/json"
"html/template"
"strings"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/noticePersonal/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
// 个人消息通知
... ... @@ -26,6 +33,72 @@ func (noticePersonalService *NoticePersonalService) AgreeJoinCreationProject(agr
defer func() {
transactionContext.RollbackTransaction()
}()
var noticeSettingRepository domain.NoticeSettingRepository
if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
_, settings, err := noticeSettingRepository.Find(map[string]interface{}{
"orgId": agreeJoinCreationProjectCommand.OrgId,
"moduleAction": domain.Action01_01,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(settings) == 0 {
//未设置消息模板
return "未设置对应的消息模板", nil
}
if settings[0].IsPush == domain.NoticeSettingIsNotPush {
return "消息是否推送已设为否", nil
}
noticeContent := settings[0].Content
tpl, err := template.New("AgreeJoinCreationProject").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
//数据字段映射
data := map[string]string{
domain.Param01_01_01: agreeJoinCreationProjectCommand.CreationProjectNumber,
domain.Param01_01_02: agreeJoinCreationProjectCommand.CreationProjectName,
}
tplResult := bytes.Buffer{}
err = tpl.Execute(&tplResult, data)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息体生成失败"+err.Error())
}
extendData := map[string]interface{}{
"creationProjectId": agreeJoinCreationProjectCommand.CreationProjectId,
}
extendStr, _ := json.Marshal(extendData)
noticePersonal := domain.NoticePersonal{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Extend: string(extendStr),
CompanyId: agreeJoinCreationProjectCommand.CompanyId,
Content: tplResult.String(),
IsRead: domain.NoticePersonalIsNotRead,
Module: domain.Action01_01,
ModuleAction: domain.Action01_01,
UserBaseId: agreeJoinCreationProjectCommand.UserBaseId,
OrgId: agreeJoinCreationProjectCommand.OrgId,
UserId: agreeJoinCreationProjectCommand.UserId,
}
var noticePersonalRepository domain.NoticePersonalRepository
if value, err := factory.CreateNoticePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticePersonalRepository = value
}
_, err = noticePersonalRepository.Save(&noticePersonal)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -47,6 +120,8 @@ func (noticePersonalService *NoticePersonalService) GetNoticePersonalList(getNot
defer func() {
transactionContext.RollbackTransaction()
}()
//TODO
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -68,6 +143,81 @@ func (noticePersonalService *NoticePersonalService) InformExpectedDividends(info
defer func() {
transactionContext.RollbackTransaction()
}()
var noticeSettingRepository domain.NoticeSettingRepository
if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
_, settings, err := noticeSettingRepository.Find(map[string]interface{}{
"orgId": informExpectedDividendsCommand.OrgId,
"moduleAction": domain.Action01_04,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(settings) == 0 {
//未设置消息模板
return nil, nil
}
noticeContent := settings[0].Content
tpl, err := template.New("AgreeJoinCreationProject").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
// Param01_04_01 = "param01_04_01" //分红预算消息-共创项目编号
// Param01_04_02 = "param01_04_02" //分红预算消息-共创项目名称
// Param01_04_03 = "param01_04_03" //分红预算消息-项目合约编号
// Param01_04_04 = "param01_04_04" //分红预算消息-项目合约名称
// Param01_04_05 = "param01_04_05" //分红预算消息-订单产品信息
// Param01_04_06 = "param01_04_06" //分红预算消息-分红金额
//数据字段映射
data := map[string]string{
domain.Param01_04_01: informExpectedDividendsCommand.CreationProjectNumber,
domain.Param01_04_02: informExpectedDividendsCommand.CreationProjectName,
domain.Param01_04_03: informExpectedDividendsCommand.CreationContractNumber,
domain.Param01_04_04: informExpectedDividendsCommand.CreationContractName,
domain.Param01_04_05: strings.Join(informExpectedDividendsCommand.ProductName, ","),
domain.Param01_04_06: informExpectedDividendsCommand.DividendsAmount,
}
tplResult := bytes.Buffer{}
err = tpl.Execute(&tplResult, data)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息体生成失败"+err.Error())
}
extendData := map[string]interface{}{
"creationProjectId": informExpectedDividendsCommand.CreationProjectId,
"creationContractId": informExpectedDividendsCommand.CreationContractId,
"dividendsEstimateId": informExpectedDividendsCommand.DividendsEstimateId,
}
extendStr, _ := json.Marshal(extendData)
noticePersonal := domain.NoticePersonal{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Extend: string(extendStr),
CompanyId: informExpectedDividendsCommand.CompanyId,
Content: tplResult.String(),
IsRead: domain.NoticePersonalIsNotRead,
Module: domain.Action01_01,
ModuleAction: domain.Action01_01,
UserBaseId: informExpectedDividendsCommand.UserBaseId,
OrgId: informExpectedDividendsCommand.OrgId,
UserId: informExpectedDividendsCommand.UserId,
}
var noticePersonalRepository domain.NoticePersonalRepository
if value, err := factory.CreateNoticePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticePersonalRepository = value
}
_, err = noticePersonalRepository.Save(&noticePersonal)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -89,6 +239,76 @@ func (noticePersonalService *NoticePersonalService) InformJoinCreationContract(i
defer func() {
transactionContext.RollbackTransaction()
}()
//TODO
var noticeSettingRepository domain.NoticeSettingRepository
if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
_, settings, err := noticeSettingRepository.Find(map[string]interface{}{
"orgId": informJoinCreationContractCommand.OrgId,
"moduleAction": domain.Action01_03,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(settings) == 0 {
//未设置消息模板
return nil, nil
}
noticeContent := settings[0].Content
tpl, err := template.New("AgreeJoinCreationProject").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
// Param01_03_01 = "param01_03_01" //共创确认-共创项目编号
// Param01_03_02 = "param01_03_02" //共创确认-共创项目名称
// Param01_03_03 = "param01_03_03" //共创确认-项目合约编号
// Param01_03_04 = "param01_03_04" //共创确认-项目合约名称
//数据字段映射
data := map[string]string{
domain.Param01_03_01: informJoinCreationContractCommand.CreationProjectNumber,
domain.Param01_03_02: informJoinCreationContractCommand.CreationProjectName,
domain.Param01_03_03: informJoinCreationContractCommand.CreationContractNumber,
domain.Param01_03_04: informJoinCreationContractCommand.CreationContractName,
}
tplResult := bytes.Buffer{}
err = tpl.Execute(&tplResult, data)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息体生成失败"+err.Error())
}
extendData := map[string]interface{}{}
extendStr, _ := json.Marshal(extendData)
noticePersonal := domain.NoticePersonal{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Extend: string(extendStr),
CompanyId: informJoinCreationContractCommand.CompanyId,
Content: tplResult.String(),
IsRead: domain.NoticePersonalIsNotRead,
Module: domain.Action01_01,
ModuleAction: domain.Action01_01,
UserBaseId: informJoinCreationContractCommand.UserBaseId,
OrgId: informJoinCreationContractCommand.OrgId,
UserId: informJoinCreationContractCommand.UserId,
}
var noticePersonalRepository domain.NoticePersonalRepository
if value, err := factory.CreateNoticePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticePersonalRepository = value
}
_, err = noticePersonalRepository.Save(&noticePersonal)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -110,6 +330,9 @@ func (noticePersonalService *NoticePersonalService) RefuseJoinCreationProject(re
defer func() {
transactionContext.RollbackTransaction()
}()
//TODO
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -24,7 +24,7 @@ type NoticePersonal struct {
// 内容模板
Content string `json:"content"`
// 是否已读【1:未读】【2:已读】
IsRead string `json:"isRead"`
IsRead int `json:"isRead"`
// 消息对应的业务模块
Module string `json:"module"`
// 业务环节
... ... @@ -33,8 +33,6 @@ type NoticePersonal struct {
UserBaseId int64 `json:"userBaseId"`
// 组织id
OrgId int64 `json:"orgId"`
// 消息对应的编码
SysCode string `json:"sysCode"`
// 接收方用户id
UserId int64 `json:"userId"`
}
... ... @@ -73,7 +71,7 @@ func (noticePersonal *NoticePersonal) Update(data map[string]interface{}) error
noticePersonal.Content = content.(string)
}
if isRead, ok := data["isRead"]; ok {
noticePersonal.IsRead = isRead.(string)
noticePersonal.IsRead = isRead.(int)
}
if module, ok := data["module"]; ok {
noticePersonal.Module = module.(string)
... ... @@ -87,9 +85,7 @@ func (noticePersonal *NoticePersonal) Update(data map[string]interface{}) error
if organizationId, ok := data["organizationId"]; ok {
noticePersonal.OrgId = organizationId.(int64)
}
if sysCode, ok := data["sysCode"]; ok {
noticePersonal.SysCode = sysCode.(string)
}
if userId, ok := data["userId"]; ok {
noticePersonal.UserId = userId.(int64)
}
... ...
... ... @@ -77,8 +77,8 @@ const (
//业务环节
const (
Action01_01 = "action01_01" //天联共创-共创申请通过
Action01_02 = "action01_02" //天联共创-共创申请拒绝
Action01_01 = "action01_01" //天联共创-共创申请审核通过
Action01_02 = "action01_02" //天联共创-共创申请审核拒绝
Action01_03 = "action01_03" //天联共创-共创确认
Action01_04 = "action01_04" //天联共创-分红预算消息
Action01_05 = "action01_05" //天联共创-账期结算消息
... ...
... ... @@ -17,7 +17,7 @@ type NoticePersonal struct {
// 内容模板
Content string
// 是否已读【1:未读】【2:已读】
IsRead string
IsRead int
// 消息对应的业务模块
Module string
// 业务环节
... ...
... ... @@ -18,7 +18,6 @@ func TransformToNoticePersonalDomainModelFromPgModels(noticePersonalModel *model
ModuleAction: noticePersonalModel.ModuleAction,
NoticePersonalId: noticePersonalModel.NoticePersonalId,
OrgId: noticePersonalModel.OrgId,
SysCode: noticePersonalModel.SysCode,
UserId: noticePersonalModel.UserId,
}, nil
}
... ...
... ... @@ -37,7 +37,6 @@ func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePe
"module_action",
"notice_personal_id",
"org_id",
"sys_code",
"user_id",
"user_base_id",
}
... ... @@ -67,7 +66,6 @@ func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePe
&noticePersonal.ModuleAction,
&noticePersonal.NoticePersonalId,
&noticePersonal.OrgId,
&noticePersonal.SysCode,
&noticePersonal.UserId,
&noticePersonal.UserBaseId,
),
... ... @@ -83,7 +81,6 @@ func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePe
noticePersonal.ModuleAction,
noticePersonal.NoticePersonalId,
noticePersonal.OrgId,
noticePersonal.SysCode,
noticePersonal.UserId,
noticePersonal.UserBaseId,
); err != nil {
... ... @@ -103,7 +100,6 @@ func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePe
&noticePersonal.ModuleAction,
&noticePersonal.NoticePersonalId,
&noticePersonal.OrgId,
&noticePersonal.SysCode,
&noticePersonal.UserId,
&noticePersonal.UserBaseId,
),
... ... @@ -119,7 +115,6 @@ func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePe
noticePersonal.ModuleAction,
noticePersonal.NoticePersonalId,
noticePersonal.OrgId,
noticePersonal.SysCode,
noticePersonal.UserId,
noticePersonal.Identify(),
); err != nil {
... ...