作者 tangxuhui

更新 个人消息设置

{"D:\\workspaceGo\\src\\allied-creation-basic\\pkg\\port\\beego":1626939040308494800}
\ No newline at end of file
{"D:\\workspaceGo\\src\\allied-creation-basic\\pkg\\port\\beego":1627098261724696100}
\ No newline at end of file
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type CreditAccountEstimateCommand struct {
// 接收方用户id
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId" valid:"Required"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
// 结算单号
CreditAccountOrderNum string `json:"creditAccountOrderNum" valid:"Required"`
// 结算金额
SettlementAmount string `json:"settlementAmount" valid:"Required"`
// 结算单id
CreditAccountId int64 `json:"creditAccountId" valid:"Required"`
// 分红预算id
DividendsEstimateId int64 `json:"dividendsEstimateId" valid:"Required"`
//分红预算单号
DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"`
}
func (creditAccountEstimateCommand *CreditAccountEstimateCommand) Valid(validation *validation.Validation) {
}
func (creditAccountEstimateCommand *CreditAccountEstimateCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(creditAccountEstimateCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type CreditAccountPaymentCommand struct {
// 接收方用户id
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId" valid:"Required"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
// 结算单号
CreditAccountOrderNum string `json:"creditAccountOrderNum" valid:"Required"`
// 结算金额
SettlementAmount string `json:"settlementAmount" valid:"Required"`
// 实际支付金额
ActuallyPaidAmount string `json:"actuallyPaidAmount"`
//结算单id
CreditAccountId int64 `json:"creditAccountId"`
}
func (creditAccountPaymentCommand *CreditAccountPaymentCommand) Valid(validation *validation.Validation) {
}
func (creditAccountPaymentCommand *CreditAccountPaymentCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(creditAccountPaymentCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -102,7 +102,7 @@ func (noticePersonalService *NoticePersonalService) AgreeJoinCreationProject(agr
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return noticePersonal, nil
}
// 获取消息列表
... ... @@ -160,12 +160,10 @@ func (noticePersonalService *NoticePersonalService) InformExpectedDividends(info
}
if len(settings) == 0 {
//未设置消息模板
return nil, nil
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())
if settings[0].IsPush == domain.NoticeSettingIsNotPush {
return "消息是否推送已设为否", nil
}
// Param01_04_01 = "param01_04_01" //分红预算消息-共创项目编号
// Param01_04_02 = "param01_04_02" //分红预算消息-共创项目名称
... ... @@ -182,6 +180,11 @@ func (noticePersonalService *NoticePersonalService) InformExpectedDividends(info
domain.Param01_04_05: strings.Join(informExpectedDividendsCommand.ProductName, ","),
domain.Param01_04_06: informExpectedDividendsCommand.DividendsAmount,
}
noticeContent := settings[0].Content
tpl, err := template.New("InformExpectedDividends").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
tplResult := bytes.Buffer{}
err = tpl.Execute(&tplResult, data)
if err != nil {
... ... @@ -221,7 +224,7 @@ func (noticePersonalService *NoticePersonalService) InformExpectedDividends(info
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return noticePersonal, nil
}
// 设置消息:共创确认
... ... @@ -240,7 +243,6 @@ func (noticePersonalService *NoticePersonalService) InformJoinCreationContract(i
transactionContext.RollbackTransaction()
}()
//TODO
var noticeSettingRepository domain.NoticeSettingRepository
if value, err := factory.CreateNoticeSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -258,10 +260,13 @@ func (noticePersonalService *NoticePersonalService) InformJoinCreationContract(i
}
if len(settings) == 0 {
//未设置消息模板
return nil, nil
return "未设置对应的消息模板", nil
}
if settings[0].IsPush == domain.NoticeSettingIsNotPush {
return "消息是否推送已设为否", nil
}
noticeContent := settings[0].Content
tpl, err := template.New("AgreeJoinCreationProject").Parse(noticeContent)
tpl, err := template.New("InformJoinCreationContract").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
... ... @@ -312,7 +317,7 @@ func (noticePersonalService *NoticePersonalService) InformJoinCreationContract(i
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return noticePersonal, nil
}
// 设置消息:共创申请审核拒绝
... ... @@ -331,12 +336,266 @@ func (noticePersonalService *NoticePersonalService) RefuseJoinCreationProject(re
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": refuseJoinCreationProjectCommand.OrgId,
"moduleAction": domain.Action01_02,
})
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
}
// Param01_02_01 = "param01_02_01" //共创申请拒绝-共创项目编号
// Param01_02_02 = "param01_02_02" //共创申请拒绝-共创项目名称
//数据字段映射
data := map[string]string{
domain.Param01_02_01: refuseJoinCreationProjectCommand.CreationProjectNumber,
domain.Param01_02_02: refuseJoinCreationProjectCommand.CreationProjectName,
}
noticeContent := settings[0].Content
tpl, err := template.New("RefuseJoinCreationProject").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
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": refuseJoinCreationProjectCommand.CreationProjectId,
}
extendStr, _ := json.Marshal(extendData)
noticePersonal := domain.NoticePersonal{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Extend: string(extendStr),
CompanyId: refuseJoinCreationProjectCommand.CompanyId,
Content: tplResult.String(),
IsRead: domain.NoticePersonalIsNotRead,
Module: domain.Action01_01,
ModuleAction: domain.Action01_01,
UserBaseId: refuseJoinCreationProjectCommand.UserBaseId,
OrgId: refuseJoinCreationProjectCommand.OrgId,
UserId: refuseJoinCreationProjectCommand.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())
}
return nil, nil
return noticePersonal, nil
}
// 设置消息:账期结算消息-分红预算
func (noticePersonalService *NoticePersonalService) CreditAccountEstimate(creditAccountEstimateCommand *command.CreditAccountEstimateCommand) (interface{}, error) {
if err := creditAccountEstimateCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, 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 nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
_, settings, err := noticeSettingRepository.Find(map[string]interface{}{
"orgId": creditAccountEstimateCommand.OrgId,
"moduleAction": domain.Action01_05,
})
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
}
// Param01_05_01 = "param01_05_01" //账期结算消息-账期结算单号
// Param01_05_02 = "param01_05_02" //账期结算消息-结算金额
// Param01_05_03 = "param01_05_03" //账期结算消息-分红预算单号
//数据字段映射
data := map[string]string{
domain.Param01_05_01: creditAccountEstimateCommand.CreditAccountOrderNum,
domain.Param01_05_02: creditAccountEstimateCommand.SettlementAmount,
domain.Param01_05_03: creditAccountEstimateCommand.DividendsEstimateOrderNumber,
}
noticeContent := settings[0].Content
tpl, err := template.New("CreditAccountEstimate").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
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{}{
"creditAccountId": creditAccountEstimateCommand.CreditAccountId,
"dividendsEstimateId": creditAccountEstimateCommand.DividendsEstimateId,
}
extendStr, _ := json.Marshal(extendData)
noticePersonal := domain.NoticePersonal{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Extend: string(extendStr),
CompanyId: creditAccountEstimateCommand.CompanyId,
Content: tplResult.String(),
IsRead: domain.NoticePersonalIsNotRead,
Module: domain.Action01_01,
ModuleAction: domain.Action01_01,
UserBaseId: creditAccountEstimateCommand.UserBaseId,
OrgId: creditAccountEstimateCommand.OrgId,
UserId: creditAccountEstimateCommand.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())
}
return noticePersonal, nil
}
// 设置消息:账期结算消息-分红预算
func (noticePersonalService *NoticePersonalService) CreditAccountPayment(creditAccountPaymentCommand *command.CreditAccountPaymentCommand) (interface{}, error) {
if err := creditAccountPaymentCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, 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 nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticeSettingRepository = value
}
_, settings, err := noticeSettingRepository.Find(map[string]interface{}{
"orgId": creditAccountPaymentCommand.OrgId,
"moduleAction": domain.Action01_05,
})
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
}
// Param01_06_01 = "param01_06_01" //支付消息-账期结算单号
// Param01_06_02 = "param01_06_02" //支付消息-结算金额
// Param01_06_03 = "param01_06_03" //支付消息-实付金额
//数据字段映射
data := map[string]string{
domain.Param01_06_01: creditAccountPaymentCommand.CreditAccountOrderNum,
domain.Param01_06_02: creditAccountPaymentCommand.SettlementAmount,
domain.Param01_06_03: creditAccountPaymentCommand.ActuallyPaidAmount,
}
noticeContent := settings[0].Content
tpl, err := template.New("CreditAccountPayment").Parse(noticeContent)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "消息模板解析失败"+err.Error())
}
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{}{
"creditAccountId": creditAccountPaymentCommand.CreditAccountId,
}
extendStr, _ := json.Marshal(extendData)
noticePersonal := domain.NoticePersonal{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Extend: string(extendStr),
CompanyId: creditAccountPaymentCommand.CompanyId,
Content: tplResult.String(),
IsRead: domain.NoticePersonalIsNotRead,
Module: domain.Action01_01,
ModuleAction: domain.Action01_01,
UserBaseId: creditAccountPaymentCommand.UserBaseId,
OrgId: creditAccountPaymentCommand.OrgId,
UserId: creditAccountPaymentCommand.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())
}
return noticePersonal, nil
}
func NewNoticePersonalService(options map[string]interface{}) *NoticePersonalService {
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"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/application/noticePersonal/service"
)
type NoticePersonalController struct {
beego.BaseController
}
func (controller *NoticePersonalController) GetNoticePersonalList() {
noticePersonalService := service.NewNoticePersonalService(nil)
getNoticePersonalListQuery := &query.GetNoticePersonalListQuery{}
data, err := noticePersonalService.GetNoticePersonalList(getNoticePersonalListQuery)
controller.Response(data, err)
}
func (controller *NoticePersonalController) AgreeJoinCreationProject() {
noticePersonalService := service.NewNoticePersonalService(nil)
agreeJoinCreationProjectCommand := &command.AgreeJoinCreationProjectCommand{}
controller.Unmarshal(agreeJoinCreationProjectCommand)
data, err := noticePersonalService.AgreeJoinCreationProject(agreeJoinCreationProjectCommand)
controller.Response(data, err)
}
func (controller *NoticePersonalController) InformExpectedDividends() {
noticePersonalService := service.NewNoticePersonalService(nil)
informExpectedDividendsCommand := &command.InformExpectedDividendsCommand{}
controller.Unmarshal(informExpectedDividendsCommand)
data, err := noticePersonalService.InformExpectedDividends(informExpectedDividendsCommand)
controller.Response(data, err)
}
func (controller *NoticePersonalController) RefuseJoinCreationProject() {
noticePersonalService := service.NewNoticePersonalService(nil)
refuseJoinCreationProjectCommand := &command.RefuseJoinCreationProjectCommand{}
controller.Unmarshal(refuseJoinCreationProjectCommand)
data, err := noticePersonalService.RefuseJoinCreationProject(refuseJoinCreationProjectCommand)
controller.Response(data, err)
}
func (controller *NoticePersonalController) InformJoinCreationContract() {
noticePersonalService := service.NewNoticePersonalService(nil)
informJoinCreationContractCommand := &command.InformJoinCreationContractCommand{}
controller.Unmarshal(informJoinCreationContractCommand)
data, err := noticePersonalService.InformJoinCreationContract(informJoinCreationContractCommand)
controller.Response(data, err)
}
func (controller *NoticePersonalController) CreditAccountEstimate() {
noticePersonalService := service.NewNoticePersonalService(nil)
creditAccountEstimateCommand := &command.CreditAccountEstimateCommand{}
controller.Unmarshal(creditAccountEstimateCommand)
data, err := noticePersonalService.CreditAccountEstimate(creditAccountEstimateCommand)
controller.Response(data, err)
}
func (controller *NoticePersonalController) CreditAccountPayment() {
noticePersonalService := service.NewNoticePersonalService(nil)
creditAccountPaymentCommand := &command.CreditAccountPaymentCommand{}
controller.Unmarshal(creditAccountPaymentCommand)
data, err := noticePersonalService.CreditAccountPayment(creditAccountPaymentCommand)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego/controllers"
)
func init() {
web.Router("/notice-personal/", &controllers.NoticePersonalController{}, "Post:GetNoticePersonalList")
web.Router("/notice-personal/agree-join-creation-project", &controllers.NoticePersonalController{}, "Post:AgreeJoinCreationProject")
web.Router("/notice-personal/inform-expected-dividends", &controllers.NoticePersonalController{}, "Post:InformExpectedDividends")
web.Router("/notice-personal/refuse-join-creation-project", &controllers.NoticePersonalController{}, "Post:RefuseJoinCreationProject")
web.Router("/notice-personal/inform-join-creation-contract", &controllers.NoticePersonalController{}, "Post:InformJoinCreationContract")
web.Router("/notice-personal/credit-account/dividends-estimate", &controllers.NoticePersonalController{}, "Post:CreditAccountEstimate")
web.Router("/notice-personal/notice-personal/credit-account/payment", &controllers.NoticePersonalController{}, "Post:CreditAccountPayment")
}
... ...