正在显示
10 个修改的文件
包含
219 行增加
和
6 行删除
@@ -72,9 +72,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c | @@ -72,9 +72,9 @@ func (deviceCollectionService *DeviceCollectionService) CreateDeviceCollection(c | ||
72 | 72 | ||
73 | // 创建 | 73 | // 创建 |
74 | func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createDeviceCollectionCommand *command.CreateDeviceCollectionCommand) (interface{}, error) { | 74 | func (deviceCollectionService *DeviceCollectionService) DeviceCollection(createDeviceCollectionCommand *command.CreateDeviceCollectionCommand) (interface{}, error) { |
75 | - if err := createDeviceCollectionCommand.ValidateCommand(); err != nil { | ||
76 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
77 | - } | 75 | + //if err := createDeviceCollectionCommand.ValidateCommand(); err != nil { |
76 | + // return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
77 | + //} | ||
78 | 78 | ||
79 | newDeviceCollection := &domain.DeviceCollection{ | 79 | newDeviceCollection := &domain.DeviceCollection{ |
80 | //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId, | 80 | //DeviceCollectionId: createDeviceCollectionCommand.DeviceCollectionId, |
pkg/application/factory/service_gateway.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import service_gateway "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/digitization_server" | ||
4 | + | ||
5 | +func CreateFontServiceGateway(options map[string]interface{}) (service_gateway.DigitizationServiceGateway, error) { | ||
6 | + return service_gateway.NewHttpLibAlliedCreationStandardServiceGateway(), nil | ||
7 | +} |
@@ -10,9 +10,9 @@ import ( | @@ -10,9 +10,9 @@ import ( | ||
10 | ) | 10 | ) |
11 | 11 | ||
12 | func (workshopService *WorkshopService) WorkshopConsume(cmd *command.WorkshopDataConsumeCommand) (interface{}, error) { | 12 | func (workshopService *WorkshopService) WorkshopConsume(cmd *command.WorkshopDataConsumeCommand) (interface{}, error) { |
13 | - if err := cmd.ValidateCommand(); err != nil { | ||
14 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
15 | - } | 13 | + //if err := cmd.ValidateCommand(); err != nil { |
14 | + // return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
15 | + //} | ||
16 | transactionContext, err := factory.CreateTransactionContext(nil) | 16 | transactionContext, err := factory.CreateTransactionContext(nil) |
17 | if err != nil { | 17 | if err != nil { |
18 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 18 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -29,6 +29,9 @@ var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied | @@ -29,6 +29,9 @@ var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied | ||
29 | 29 | ||
30 | var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" | 30 | var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" |
31 | 31 | ||
32 | +//数控 | ||
33 | +var ALLIED_CREATION_STANDARD = "http://digitization-server-dev.fjmaimaimai.com" | ||
34 | + | ||
32 | var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} | 35 | var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} |
33 | 36 | ||
34 | const CUSTOMER_ACCOUNT_DELIMITER = "," | 37 | const CUSTOMER_ACCOUNT_DELIMITER = "," |
1 | +package service_gateway | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils" | ||
6 | + "strconv" | ||
7 | + "time" | ||
8 | +) | ||
9 | + | ||
10 | +type HttpLibAlliedCreationStandardServiceGateway struct { | ||
11 | + HttpLibBaseServiceGateway | ||
12 | + baseURL string | ||
13 | +} | ||
14 | +type Field struct { | ||
15 | + Index int `json:"index"` | ||
16 | + Name string `json:"name"` | ||
17 | + SqlType string `json:"sqlType"` | ||
18 | + SqlName string `json:"sqlName"` | ||
19 | + Flag int `json:"flag"` | ||
20 | +} | ||
21 | + | ||
22 | +type Conditions struct { | ||
23 | + Field *Field `json:"field"` | ||
24 | + In []string `json:"in"` | ||
25 | + Ex []string `json:"ex"` | ||
26 | +} | ||
27 | + | ||
28 | +type Where struct { //输入 | ||
29 | + PageNumber int `json:"pageNumber"` | ||
30 | + PageSize int `json:"pageSize"` | ||
31 | + Conditions []*Conditions `json:"conditions"` | ||
32 | +} | ||
33 | + | ||
34 | +func NewHttpLibAlliedCreationStandardServiceGateway() *HttpLibAlliedCreationStandardServiceGateway { | ||
35 | + return &HttpLibAlliedCreationStandardServiceGateway{ | ||
36 | + HttpLibBaseServiceGateway: HttpLibBaseServiceGateway{ | ||
37 | + ConnectTimeout: 100 * time.Second, | ||
38 | + ReadWriteTimeout: 30 * time.Second, | ||
39 | + }, | ||
40 | + baseURL: constant.ALLIED_CREATION_STANDARD, | ||
41 | + } | ||
42 | +} | ||
43 | + | ||
44 | +//获取下拉列表0 | ||
45 | +func (serviceGateway *HttpLibAlliedCreationStandardServiceGateway) GetBusiness() (map[string]interface{}, error) { | ||
46 | + AppKey := "gBzrh4BBeVeGQbRngPTUTRZOAcqtSVr9" //可更改 | ||
47 | + AppSecret := "oCUsnka2RUjMKPWjiUbSOcKbqV1pYsaT" //产品不一样密钥不一样 | ||
48 | + timestamp := strconv.FormatInt(time.Now().Unix(), 10) //当前时间戳 | ||
49 | + sign := utils.GenMd5(AppKey + AppSecret + timestamp) | ||
50 | + //serviceGateway.baseURL="http://127.1.0.1:8080" | ||
51 | + req, err := serviceGateway.CreateRequest(serviceGateway.baseURL+"/data/business/search", "post").Header("AppKey", AppKey).Header("Timestamp", timestamp).Header("Sign", sign).JSONBody(map[string]interface{}{}) | ||
52 | + if err != nil { | ||
53 | + return nil, err | ||
54 | + } | ||
55 | + //var response DataTableSearch | ||
56 | + response := make(map[string]interface{}) | ||
57 | + err = req.ToJSON(&response) | ||
58 | + if err != nil { | ||
59 | + return nil, err | ||
60 | + } | ||
61 | + data, err := serviceGateway.responseHandle(response) | ||
62 | + return data, err | ||
63 | +} |
1 | +package service_gateway | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "fmt" | ||
6 | + "strconv" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/beego/beego/v2/client/httplib" | ||
11 | +) | ||
12 | + | ||
13 | +type MessageCode struct { | ||
14 | + Code int `json:"code"` | ||
15 | + Msg string `json:"msg"` | ||
16 | +} | ||
17 | + | ||
18 | +//GatewayResponse 统一消息返回格式 | ||
19 | +type GatewayResponse struct { | ||
20 | + MessageCode | ||
21 | + Data json.RawMessage `json:"data"` | ||
22 | +} | ||
23 | + | ||
24 | +type HttpLibBaseServiceGateway struct { | ||
25 | + ConnectTimeout time.Duration | ||
26 | + ReadWriteTimeout time.Duration | ||
27 | +} | ||
28 | + | ||
29 | +func (serviceGateway *HttpLibBaseServiceGateway) CreateRequest(url string, method string) *httplib.BeegoHTTPRequest { | ||
30 | + var request *httplib.BeegoHTTPRequest | ||
31 | + switch method { | ||
32 | + case "get": | ||
33 | + request = httplib.Get(url) | ||
34 | + | ||
35 | + case "post": | ||
36 | + request = httplib.Post(url) | ||
37 | + | ||
38 | + case "put": | ||
39 | + request = httplib.Put(url) | ||
40 | + | ||
41 | + case "delete": | ||
42 | + request = httplib.Delete(url) | ||
43 | + | ||
44 | + case "head": | ||
45 | + request = httplib.Head(url) | ||
46 | + | ||
47 | + default: | ||
48 | + request = httplib.Get(url) | ||
49 | + } | ||
50 | + return request.SetTimeout(serviceGateway.ConnectTimeout, serviceGateway.ReadWriteTimeout) | ||
51 | +} | ||
52 | + | ||
53 | +func (serviceGateway *HttpLibBaseServiceGateway) responseHandle(response map[string]interface{}) (map[string]interface{}, error) { | ||
54 | + data := make(map[string]interface{}) | ||
55 | + var err error | ||
56 | + if code, ok := response["code"]; ok { | ||
57 | + code := code.(float64) | ||
58 | + if code == 0 { | ||
59 | + if response["data"] == nil { | ||
60 | + data = nil | ||
61 | + } else { | ||
62 | + data = response["data"].(map[string]interface{}) | ||
63 | + } | ||
64 | + } else { | ||
65 | + msg := response["msg"].(string) | ||
66 | + err = fmt.Errorf(strings.Join([]string{strconv.FormatFloat(code, 'f', -1, 64), msg}, " ")) | ||
67 | + } | ||
68 | + } else { | ||
69 | + jsonBytes, marshalErr := json.Marshal(response) | ||
70 | + if marshalErr != nil { | ||
71 | + err = marshalErr | ||
72 | + } | ||
73 | + err = fmt.Errorf("无法解析的网关服务数据返回格式:%s", string(jsonBytes)) | ||
74 | + } | ||
75 | + return data, err | ||
76 | +} | ||
77 | + | ||
78 | +func (serviceGateway *HttpLibBaseServiceGateway) GetResponseData(result GatewayResponse, data interface{}) error { | ||
79 | + if result.Code != 0 { | ||
80 | + return fmt.Errorf(result.Msg) | ||
81 | + } | ||
82 | + if data == nil { | ||
83 | + return nil | ||
84 | + } | ||
85 | + err := json.Unmarshal(result.Data, data) | ||
86 | + if err != nil { | ||
87 | + return err | ||
88 | + } | ||
89 | + return nil | ||
90 | +} |
@@ -2,6 +2,8 @@ package utils | @@ -2,6 +2,8 @@ package utils | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "bytes" | 4 | "bytes" |
5 | + "crypto/md5" | ||
6 | + "encoding/hex" | ||
5 | "encoding/json" | 7 | "encoding/json" |
6 | "fmt" | 8 | "fmt" |
7 | "github.com/beego/beego/v2/core/validation" | 9 | "github.com/beego/beego/v2/core/validation" |
@@ -443,3 +445,15 @@ func GbkToUtf8(s []byte) ([]byte, error) { | @@ -443,3 +445,15 @@ func GbkToUtf8(s []byte) ([]byte, error) { | ||
443 | } | 445 | } |
444 | return d, nil | 446 | return d, nil |
445 | } | 447 | } |
448 | + | ||
449 | +// GenMd5 Generate a 32-bit md5 string | ||
450 | +func GenMd5(src interface{}) string { | ||
451 | + h := md5.New() | ||
452 | + if s, ok := src.(string); ok { | ||
453 | + h.Write([]byte(s)) | ||
454 | + } else { | ||
455 | + h.Write([]byte(fmt.Sprint(src))) | ||
456 | + } | ||
457 | + | ||
458 | + return hex.EncodeToString(h.Sum(nil)) | ||
459 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
6 | + service_gateway "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/digitization_server" | ||
7 | +) | ||
8 | + | ||
9 | +type DigitizationController struct { | ||
10 | + beego.BaseController | ||
11 | +} | ||
12 | + | ||
13 | +func (controller *DigitizationController) GetDigitization() { | ||
14 | + var byteBankServiceGateway service_gateway.DigitizationServiceGateway | ||
15 | + value, err := factory.CreateFontServiceGateway(map[string]interface{}{}) | ||
16 | + if err == nil { | ||
17 | + byteBankServiceGateway = value | ||
18 | + } | ||
19 | + data, err := byteBankServiceGateway.GetBusiness() | ||
20 | + controller.Response(data, err) | ||
21 | +} |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/data/digitization", &controllers.DigitizationController{}, "Post:GetDigitization") | ||
10 | +} |
-
请 注册 或 登录 后发表评论