审查视图

pkg/application/common/service/service.go 4.3 KB
tangxuhui authored
1 2 3
package service

import (
yangfu authored
4 5
	"fmt"
	"github.com/linmadan/egglib-go/core/application"
tangxuhui authored
6
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
yangfu authored
7 8
	"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"
yangfu authored
9
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
yangfu authored
10
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/version_server"
tangxuhui authored
11 12
)
yangfu authored
13 14 15
const IOSPage = "http://fir.fjmaimaimai.com/pdvn"
const ANDPage = "http://fir.fjmaimaimai.com/ben1"
tangxuhui authored
16 17 18 19 20 21 22 23
type CommonService struct {
}

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

//GetDictionaryByCode 根据code获取字典数据
tangxuhui authored
24
func (srv *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDictionaryByCodeQuery) (interface{}, error) {
yangfu authored
25 26 27 28 29 30
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(domain.Operator{})
	result, err := creationBasicGateway.GetDictionarysByCode(allied_creation_basic.ReqGetDictionaryByCode{
		DictCodes: getDictionaryQuery.DictCode,
	})
	if err != nil {
		return nil, err
yangfu authored
31
	}
yangfu authored
32 33 34 35 36 37 38 39 40 41 42 43 44 45
	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
			}
		}
	}
yangfu authored
46 47 48
	return map[string]interface{}{
		"dictionarys": response,
	}, nil
tangxuhui authored
49
}
tangxuhui authored
50
51
//LatestVersionInfo 版本升级
yangfu authored
52
func (srv *CommonService) LatestVersionInfo(q *query.GetLatestVersionQuery) (interface{}, error) {
yangfu authored
53
	vs := version_server.NewHttpLibVersionServer()
yangfu authored
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
	// 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/ben1",
				"updateType":   0,
				"channel":      1,
			},
		}, nil
	}
yangfu authored
69 70 71 72 73 74
	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())
yangfu authored
75
	}
yangfu authored
76
	return data, nil
77 78 79
}

//AppSharing 获取分享链接地址
yangfu authored
80
func (srv *CommonService) AppSharing(q *query.GetLatestVersionQuery) (interface{}, error) {
yangfu authored
81 82 83
	//page := IOSPage
	//if q.DeviceType == "1" { // 安卓
	//	page = ANDPage
yangfu authored
84
	//}
yangfu authored
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
	//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
tangxuhui authored
100
}
yangfu authored
101 102 103 104 105 106 107 108 109 110 111 112

// 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
}
113
yangfu authored
114 115 116 117 118 119 120 121 122 123 124 125 126 127
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
}