fonchain-fiee/pkg/service/artistInfo/mailArtwork/syncToArtworkSystem.go

136 lines
4.4 KiB
Go
Raw Normal View History

2025-02-19 06:24:15 +00:00
// Package mailArtwork -----------------------------
// @file : syncToArtworkSystem.go
// @author : JJXu
// @contact : wavingbear@163.com
// @time : 2024/12/3 下午3:59
// -------------------------------------------
package mailArtwork
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/dorlolo/simpleRequest"
"github.com/fonchain_enterprise/fonchain-main/api/artwork"
"github.com/fonchain_enterprise/fonchain-main/pkg/config"
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/stime"
"time"
)
// SyncToInStorageOfArtworkSystem 同步入库信息到的画作系统
func SyncToInStorageOfArtworkSystem(artworkUid string, trackingNo string, authorization string) (err error) {
var respErr error
var detail = map[string]any{
"insto_soure": "寄画管理",
"insto_time": time.Now().Format(stime.Format_Normal_YMDhms),
"insto_express_no": nil,
"insto_digi_cert": nil,
"insto_receipt": nil,
"insto_detail": trackingNo,
"insto_route": nil,
}
detailJson, _ := json.Marshal(detail)
httpReq := simpleRequest.NewRequest()
httpReq.Headers().ConentType_json().Set(e.Authorization, authorization)
httpMethod, dataId := getHttpMethodOfUpdateStorage(artworkUid, 1)
params := map[string]any{
"Type": 1,
"Detail": string(detailJson),
"ArtworkUuid": artworkUid,
}
if dataId > 0 {
params["Id"] = dataId
}
fmt.Printf("request Params:%+v", params)
httpReq.Body().Sets(params)
reqUrl := "http://127.0.0.1" + config.HttpPort + "/artwork/storage"
var respBody []byte
respBody, respErr = httpReq.LaunchTo(reqUrl, httpMethod)
fmt.Printf("request resp:%+v\n", string(respBody))
var resp TransportResponse
if respErr == nil {
_ = json.Unmarshal(respBody, &resp)
}
if respErr != nil || resp.Status != 0 {
return errors.New("入库信息同步失败,请至画作系统手动修改")
}
return
}
// SyncToOutStorageOfArtworkSystem 同步出库信息到的画作系统
func SyncToOutStorageOfArtworkSystem(artworkUid string, trackingNo string, returnReason string, authorization string) (err error) {
var respErr error
var detail = map[string]any{
"outsto_time": time.Now().Format(stime.Format_Normal_YMDhms),
"outsto_receive_time": "",
"outsto_reason": "退还画家",
"outsto_img": nil,
"tracking_no": trackingNo,
"remark": returnReason,
}
detailJson, _ := json.Marshal(detail)
httpReq := simpleRequest.NewRequest()
httpReq.Headers().ConentType_json().Set(e.Authorization, authorization)
httpMethod, dataId := getHttpMethodOfUpdateStorage(artworkUid, 3)
httpMethod = "PUT" //请求方式都为put
fmt.Println("detailJson", string(detailJson))
params := map[string]any{
"Type": 3,
"Detail": string(detailJson),
"ArtworkUuid": artworkUid,
}
if dataId > 0 {
params["Id"] = dataId
}
httpReq.Body().Sets(params)
reqUrl := "http://127.0.0.1" + config.HttpPort + "/artwork/storage"
fmt.Println("reqUrl:", reqUrl)
var respBody []byte
respBody, respErr = httpReq.LaunchTo(reqUrl, httpMethod)
fmt.Printf("request resp:%+v\n", string(respBody))
var resp TransportResponse
if respErr == nil {
_ = json.Unmarshal(respBody, &resp)
}
if respErr != nil || resp.Status != 0 {
return errors.New("出库信息同步失败,请至画作系统手动修改")
}
return
}
// getHttpMethodOfUpdateStorage 获取同步到画作系统时的请求方式,没有值为post有值为put
// storageType: 1=入库 3=出库
func getHttpMethodOfUpdateStorage(artworkUid string, storageType int32) (httpMethod string, id int32) {
resp, err := service.GrpcArtworkImpl.StorageInfo(context.Background(), &artwork.StorageInfoRequest{
Type: storageType,
ArtworkUuid: artworkUid,
})
fmt.Printf("getHttpMethodOfUpdateStorage:%+v\n", resp)
httpMethod = "PUT"
if err != nil || resp == nil || len(resp.StorageData) == 0 {
httpMethod = "POST"
}
if len(resp.StorageData) > 0 {
//var mapStorageData StorageDetail
//_ = json.Unmarshal([]byte(Detail), &mapStorageData)
id = resp.StorageData[0].Id
fmt.Println("StorageDetail.id", resp.StorageData[0].Id)
}
fmt.Println("getHttpMethodOfUpdateStorage method is ", httpMethod)
return
}
type TransportResponse struct {
Status int `json:"status"`
Msg string `json:"msg"`
Err string `json:"err"`
}
// 其它值不需要只要一个Id
type StorageDetail struct {
Id int32 `json:"Id"`
}