|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
)
|
|
|
|
|
|
// DividendsEstimateService 分红预算服务
|
|
|
type DividendsEstimateService struct {
|
|
|
}
|
|
|
|
|
|
// CancelDividendsEstimate 取消分红预算
|
|
|
func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimate(cancelDividendsEstimateCommand *command.CancelDividendsEstimateCommand) (interface{}, error) {
|
|
|
if err := cancelDividendsEstimateCommand.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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// CreateDividendsEstimate 创建分红预算服务
|
|
|
func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimate(createDividendsEstimateCommand *command.CreateDividendsEstimateCommand) (interface{}, error) {
|
|
|
if err := createDividendsEstimateCommand.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()
|
|
|
}()
|
|
|
newDividendsEstimate := &domain.DividendsEstimate{
|
|
|
//CompanyId: createDividendsEstimateCommand.CompanyId,
|
|
|
//OrgId: createDividendsEstimateCommand.OrgId,
|
|
|
//UserId: createDividendsEstimateCommand.UserId,
|
|
|
}
|
|
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
if dividendsEstimate, err := dividendsEstimateRepository.Save(newDividendsEstimate); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsEstimate, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// EstimateDividendsIncentives 确定预算分红激励
|
|
|
func (dividendsEstimateService *DividendsEstimateService) EstimateDividendsIncentives(estimateDividendsIncentivesCommand *command.EstimateDividendsIncentivesCommand) (interface{}, error) {
|
|
|
if err := estimateDividendsIncentivesCommand.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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// EstimateMoneyIncentives 确定预算金额激励分红
|
|
|
func (dividendsEstimateService *DividendsEstimateService) EstimateMoneyIncentives(estimateMoneyIncentivesCommand *command.EstimateMoneyIncentivesCommand) (interface{}, error) {
|
|
|
if err := estimateMoneyIncentivesCommand.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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// GetDividendsEstimate 返回分红预算服务
|
|
|
func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(getDividendsEstimateQuery *query.GetDividendsEstimateQuery) (interface{}, error) {
|
|
|
if err := getDividendsEstimateQuery.ValidateQuery(); 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 dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsEstimate == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getDividendsEstimateQuery.DividendsEstimateId)))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsEstimate, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// ListDividendsEstimate 返回分红预算服务列表
|
|
|
func (dividendsEstimateService *DividendsEstimateService) ListDividendsEstimate(listDividendsEstimateQuery *query.ListDividendsEstimateQuery) (interface{}, error) {
|
|
|
if err := listDividendsEstimateQuery.ValidateQuery(); 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 dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(tool_funs.SimpleStructToMap(listDividendsEstimateQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"count": count,
|
|
|
"dividendsEstimates": dividendsEstimates,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// ListDividendsIncentives 返回业绩激励分红
|
|
|
func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentives(listDividendsIncentivesQuery *query.ListDividendsIncentivesQuery) (interface{}, error) {
|
|
|
if err := listDividendsIncentivesQuery.ValidateQuery(); 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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// ListMoneyIncentives 返回金额激励分红
|
|
|
func (dividendsEstimateService *DividendsEstimateService) ListMoneyIncentives(listMoneyIncentivesQuery *query.ListMoneyIncentivesQuery) (interface{}, error) {
|
|
|
if err := listMoneyIncentivesQuery.ValidateQuery(); 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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// RemoveDividendsEstimate 移除分红预算服务
|
|
|
func (dividendsEstimateService *DividendsEstimateService) RemoveDividendsEstimate(removeDividendsEstimateCommand *command.RemoveDividendsEstimateCommand) (interface{}, error) {
|
|
|
if err := removeDividendsEstimateCommand.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 dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": removeDividendsEstimateCommand.DividendsEstimateId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsEstimate == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDividendsEstimateCommand.DividendsEstimateId)))
|
|
|
}
|
|
|
if dividendsEstimate, err := dividendsEstimateRepository.Remove(dividendsEstimate); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsEstimate, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// SearchDividendsEstimate 查询分红预算单
|
|
|
func (dividendsEstimateService *DividendsEstimateService) SearchDividendsEstimate(searchDividendsEstimateQuery *query.SearchDividendsEstimateQuery) (interface{}, error) {
|
|
|
if err := searchDividendsEstimateQuery.ValidateQuery(); 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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// SearchDividendsIncentives 查询业绩分红
|
|
|
func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncentives(searchDividendsIncentivesQuery *query.SearchDividendsIncentivesQuery) (interface{}, error) {
|
|
|
if err := searchDividendsIncentivesQuery.ValidateQuery(); 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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// SearchMoneyIncentives 查询金额激励分红
|
|
|
func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentives(searchMoneyIncentivesQuery *query.SearchMoneyIncentivesQuery) (interface{}, error) {
|
|
|
if err := searchMoneyIncentivesQuery.ValidateQuery(); 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()
|
|
|
}()
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// UpdateDividendsEstimate 更新分红预算服务
|
|
|
func (dividendsEstimateService *DividendsEstimateService) UpdateDividendsEstimate(updateDividendsEstimateCommand *command.UpdateDividendsEstimateCommand) (interface{}, error) {
|
|
|
if err := updateDividendsEstimateCommand.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 dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": updateDividendsEstimateCommand.DividendsEstimateId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsEstimate == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsEstimateCommand.DividendsEstimateId)))
|
|
|
}
|
|
|
if err := dividendsEstimate.Update(tool_funs.SimpleStructToMap(updateDividendsEstimateCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsEstimate, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsEstimate, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func NewDividendsEstimateService(options map[string]interface{}) *DividendsEstimateService {
|
|
|
newDividendsEstimateService := &DividendsEstimateService{}
|
|
|
return newDividendsEstimateService
|
|
|
} |
...
|
...
|
|