|
|
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(¬icePersonal)
|
|
|
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(¬icePersonal)
|
|
|
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(¬icePersonal)
|
|
|
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())
|
|
|
}
|
...
|
...
|
|