service.go 3.5 KB
package service

import (
	"strconv"

	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
)

// 字典服务
type DictionayService struct {
}

func NewDictionayService(options map[string]interface{}) *DictionayService {
	return &DictionayService{}
}

// 创建字典
func (dictionaryService *DictionayService) CreateDictionay(createCommand *command.CreateDictionaryCommand) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
		createCommand.Operator)
	result, err := creationBasicGateway.DictionaryAdd(allied_creation_basic.ReqDictionaryAdd{
		DictCode:  createCommand.DictCode,
		DictName:  createCommand.DictName,
		Describe:  createCommand.Describe,
		DictItems: createCommand.DictItems,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return result, nil
}

// 更新字典
func (dictionaryService *DictionayService) UpdateDictionay(updateCommand *command.UpdateDictionaryCommand) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
		updateCommand.Operator)
	result, err := creationBasicGateway.DictionaryUpdate(allied_creation_basic.ReqDictionaryUpdate{
		DictionaryId: updateCommand.DictionaryId,
		DictCode:     updateCommand.DictCode,
		DictName:     updateCommand.DictName,
		Describe:     updateCommand.Describe,
		DictItems:    updateCommand.DictItems,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return result, nil
}

//获取字典
func (dictionaryService *DictionayService) GetDictionay(getQuery *query.GetDictionaryQuery) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
		getQuery.Operator)
	result, err := creationBasicGateway.DictionaryGet(allied_creation_basic.ReqDictionaryGet{
		DictionaryId: getQuery.DictionaryId,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return result, nil
}

//获取字典
func (dictionaryService *DictionayService) RemoveDictionay(removeCommand *command.RemoveDictionaryCommand) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
		removeCommand.Operator)
	var dictionaryIds []int
	for _, v := range removeCommand.DictionaryIds {
		id, _ := strconv.Atoi(v)
		dictionaryIds = append(dictionaryIds, id)
	}
	result, err := creationBasicGateway.DictionaryRemove(allied_creation_basic.ReqDictionaryRemove{
		DictionaryIds: dictionaryIds,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return result, nil
}

//获取字典
func (dictionaryService *DictionayService) ListDictionay(searchQuery *query.ListDictionaryQuery) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(
		searchQuery.Operator)
	result, err := creationBasicGateway.DictionarySearch(allied_creation_basic.ReqDictionarySearch{
		Pageindex: searchQuery.Pageindex,
		PageSize:  searchQuery.PageSize,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return result, nil
}