service.go 4.3 KB
package service

import (
	"fmt"
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/version_server"
)

const IOSPage = "http://fir.fjmaimaimai.com/pdvn"
const ANDPage = "http://fir.fjmaimaimai.com/ben1"

type CommonService struct {
}

func NewCommonService(options map[string]interface{}) *CommonService {
	return &CommonService{}
}

//GetDictionaryByCode 根据code获取字典数据
func (srv *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDictionaryByCodeQuery) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(domain.Operator{})
	result, err := creationBasicGateway.GetDictionarysByCode(allied_creation_basic.ReqGetDictionaryByCode{
		DictCodes: getDictionaryQuery.DictCode,
	})
	if err != nil {
		return nil, err
	}
	var response = make([]interface{}, 0)
	if result == nil || len(result.Dictionarys) == 0 {
		return response, nil
	}
	for i := range getDictionaryQuery.DictCode {
		code := getDictionaryQuery.DictCode[i]
		for j := range result.Dictionarys {
			item := result.Dictionarys[j]
			if item.DictCode == code {
				response = append(response, item)
				break
			}
		}
	}
	return map[string]interface{}{
		"dictionarys": response,
	}, nil
}

//LatestVersionInfo 版本升级
func (srv *CommonService) LatestVersionInfo(q *query.GetLatestVersionQuery) (interface{}, error) {
	vs := version_server.NewHttpLibVersionServer()
	// TODO:版本管理系统按应用名称查询相应版本信息,目前维护人没在,此处先写死手动维护
	if len(q.AppName) != 0 && q.AppName == "com.mmm.manufacture-weigh.pad" {
		return map[string]interface{}{
			"version": map[string]interface{}{
				"versionName":  "版本 v1.0.1",
				"content":      "版本升级",
				"title":        "版本升级",
				"versionNo":    "100001",
				"downloadFile": "upgrade",
				"downloadPage": "http://fir.fjmaimaimai.com/45v7",
				"updateType":   0,
				"channel":      1,
			},
		}, nil
	}
	data, err := vs.GetLatestVersion(q.Request, version_server.ReqLatestVersion{
		VersionNo: q.VersionNo,
		Channel:   q.Channel,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return data, nil
}

//AppSharing 获取分享链接地址
func (srv *CommonService) AppSharing(q *query.GetLatestVersionQuery) (interface{}, error) {
	//page := IOSPage
	//if q.DeviceType == "1" { // 安卓
	//	page = ANDPage
	//}
	//return map[string]interface{}{
	//	"version": map[string]interface{}{
	//		"downloadPage": page,
	//		"downloadFile": "",
	//	},
	//}, nil
	vs := version_server.NewHttpLibVersionServer()
	data, err := vs.GetLatestVersion(q.Request, version_server.ReqLatestVersion{
		VersionNo: q.VersionNo,
		Channel:   q.Channel,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return data, nil
}

// AdvancedSetting 高级查询 配置
func (srv *CommonService) AdvancedSetting(q *query.GetAdvancedSettingQuery) (interface{}, error) {
	if err := q.ValidateQuery(); err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	m, ok := domain.GetModel(q.Model)
	if !ok {
		return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("模型:%v 不存在", q.Model))
	}
	return m, nil
}

func (srv *CommonService) BlockChainBrowser(q *query.GetBlockChainTokenQuery) (interface{}, error) {
	if q.UpChainId == 0 {
		return nil, application.ThrowError(application.BUSINESS_ERROR, "未查询到区块链数据")
	}
	alliedCreationUser := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
	result, err := alliedCreationUser.BlockChainsToken(allied_creation_user.ReqBlockChainToken{
		Type:      q.Type,
		UpChainID: q.UpChainId,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return result, nil
}