作者 liujunxiong

合并分支 'dev' 到 'test'

Dev



查看合并请求 !13
package factory
import service_gateway "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/digitization_server"
func CreateFontServiceGateway(options map[string]interface{}) (service_gateway.DigitizationServiceGateway, error) {
return service_gateway.NewHttpLibAlliedCreationStandardServiceGateway(), nil
}
... ...
... ... @@ -29,6 +29,9 @@ var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied
var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301"
//数控
var ALLIED_CREATION_STANDARD = "http://digitization-server-dev.fjmaimaimai.com"
var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384}
const CUSTOMER_ACCOUNT_DELIMITER = ","
... ...
package service_gateway
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"strconv"
"time"
)
type HttpLibAlliedCreationStandardServiceGateway struct {
HttpLibBaseServiceGateway
baseURL string
}
type Field struct {
Index int `json:"index"`
Name string `json:"name"`
SqlType string `json:"sqlType"`
SqlName string `json:"sqlName"`
Flag int `json:"flag"`
}
type Conditions struct {
Field *Field `json:"field"`
In []string `json:"in"`
Ex []string `json:"ex"`
}
type Where struct { //输入
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
Conditions []*Conditions `json:"conditions"`
}
func NewHttpLibAlliedCreationStandardServiceGateway() *HttpLibAlliedCreationStandardServiceGateway {
return &HttpLibAlliedCreationStandardServiceGateway{
HttpLibBaseServiceGateway: HttpLibBaseServiceGateway{
ConnectTimeout: 100 * time.Second,
ReadWriteTimeout: 30 * time.Second,
},
baseURL: constant.ALLIED_CREATION_STANDARD,
}
}
//获取下拉列表0
func (serviceGateway *HttpLibAlliedCreationStandardServiceGateway) GetBusiness() (map[string]interface{}, error) {
AppKey := "gBzrh4BBeVeGQbRngPTUTRZOAcqtSVr9" //可更改
AppSecret := "oCUsnka2RUjMKPWjiUbSOcKbqV1pYsaT" //产品不一样密钥不一样
timestamp := strconv.FormatInt(time.Now().Unix(), 10) //当前时间戳
sign := utils.GenMd5(AppKey + AppSecret + timestamp)
//serviceGateway.baseURL="http://127.1.0.1:8080"
req, err := serviceGateway.CreateRequest(serviceGateway.baseURL+"/data/business/search", "post").Header("AppKey", AppKey).Header("Timestamp", timestamp).Header("Sign", sign).JSONBody(map[string]interface{}{})
if err != nil {
return nil, err
}
//var response DataTableSearch
response := make(map[string]interface{})
err = req.ToJSON(&response)
if err != nil {
return nil, err
}
data, err := serviceGateway.responseHandle(response)
return data, err
}
... ...
package service_gateway
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"github.com/beego/beego/v2/client/httplib"
)
type MessageCode struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
//GatewayResponse 统一消息返回格式
type GatewayResponse struct {
MessageCode
Data json.RawMessage `json:"data"`
}
type HttpLibBaseServiceGateway struct {
ConnectTimeout time.Duration
ReadWriteTimeout time.Duration
}
func (serviceGateway *HttpLibBaseServiceGateway) CreateRequest(url string, method string) *httplib.BeegoHTTPRequest {
var request *httplib.BeegoHTTPRequest
switch method {
case "get":
request = httplib.Get(url)
case "post":
request = httplib.Post(url)
case "put":
request = httplib.Put(url)
case "delete":
request = httplib.Delete(url)
case "head":
request = httplib.Head(url)
default:
request = httplib.Get(url)
}
return request.SetTimeout(serviceGateway.ConnectTimeout, serviceGateway.ReadWriteTimeout)
}
func (serviceGateway *HttpLibBaseServiceGateway) responseHandle(response map[string]interface{}) (map[string]interface{}, error) {
data := make(map[string]interface{})
var err error
if code, ok := response["code"]; ok {
code := code.(float64)
if code == 0 {
if response["data"] == nil {
data = nil
} else {
data = response["data"].(map[string]interface{})
}
} else {
msg := response["msg"].(string)
err = fmt.Errorf(strings.Join([]string{strconv.FormatFloat(code, 'f', -1, 64), msg}, " "))
}
} else {
jsonBytes, marshalErr := json.Marshal(response)
if marshalErr != nil {
err = marshalErr
}
err = fmt.Errorf("无法解析的网关服务数据返回格式:%s", string(jsonBytes))
}
return data, err
}
func (serviceGateway *HttpLibBaseServiceGateway) GetResponseData(result GatewayResponse, data interface{}) error {
if result.Code != 0 {
return fmt.Errorf(result.Msg)
}
if data == nil {
return nil
}
err := json.Unmarshal(result.Data, data)
if err != nil {
return err
}
return nil
}
... ...
package service_gateway
type DigitizationServiceGateway interface {
GetBusiness() (map[string]interface{}, error) // 获取导入下拉列表
}
... ...
... ... @@ -2,6 +2,8 @@ package utils
import (
"bytes"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/beego/beego/v2/core/validation"
... ... @@ -443,3 +445,15 @@ func GbkToUtf8(s []byte) ([]byte, error) {
}
return d, nil
}
// GenMd5 Generate a 32-bit md5 string
func GenMd5(src interface{}) string {
h := md5.New()
if s, ok := src.(string); ok {
h.Write([]byte(s))
} else {
h.Write([]byte(fmt.Sprint(src)))
}
return hex.EncodeToString(h.Sum(nil))
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
service_gateway "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/digitization_server"
)
type DigitizationController struct {
beego.BaseController
}
func (controller *DigitizationController) GetDigitization() {
var byteBankServiceGateway service_gateway.DigitizationServiceGateway
value, err := factory.CreateFontServiceGateway(map[string]interface{}{})
if err == nil {
byteBankServiceGateway = value
}
data, err := byteBankServiceGateway.GetBusiness()
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
)
func init() {
web.Router("/data/digitization", &controllers.DigitizationController{}, "Post:GetDigitization")
}
... ...