From 129d3fafa1d5eedf93467424338b57622f636d86 Mon Sep 17 00:00:00 2001 From: daiyb <570956418@qq.com> Date: Fri, 13 Jun 2025 19:00:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=A1=E6=89=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/config/config.go | 1 + docs/dev/conf.ini | 2 +- docs/prod/conf.ini | 2 +- docs/test/conf.ini | 2 +- pkg/model/cast/approval.go | 24 ++++++++++++++++++++++ pkg/service/cast/approval.go | 39 ++++++++++++++++++++++++++++++++++++ pkg/service/cast/work.go | 5 +++-- pkg/utils/http.go | 34 +++++++++++++++++++++++++++++++ 8 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 pkg/model/cast/approval.go create mode 100644 pkg/service/cast/approval.go create mode 100644 pkg/utils/http.go diff --git a/cmd/config/config.go b/cmd/config/config.go index 11d4629..16daf68 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -114,6 +114,7 @@ type System struct { HttpPort string Host string RedirectUri string + ErpHost string } type Oss struct { AccessKeyId string diff --git a/docs/dev/conf.ini b/docs/dev/conf.ini index 0761869..6e076bd 100644 --- a/docs/dev/conf.ini +++ b/docs/dev/conf.ini @@ -4,7 +4,7 @@ AppMode = "dev" HttpPort = ":8085" Host = "https://common.szjixun.cn" RedirectUri = "/api/redirect/url" - +ErpHost = "http://114.218.158.24:9020" [bos] Ak = "ALTAKxrqOQHnAN525Tb2GX4Bhe" Sk = "d2ecaa9d75114d3b9f42b99014198306" diff --git a/docs/prod/conf.ini b/docs/prod/conf.ini index bd00c95..0a9e81d 100644 --- a/docs/prod/conf.ini +++ b/docs/prod/conf.ini @@ -4,7 +4,7 @@ AppMode = "prod" HttpPort = ":8085" Host = "https://common.szjixun.cn" RedirectUri = "/api/redirect/url" - +ErpHost = "https://erpapi.fontree.cn" [bos] Ak = "ALTAKxrqOQHnAN525Tb2GX4Bhe" Sk = "d2ecaa9d75114d3b9f42b99014198306" diff --git a/docs/test/conf.ini b/docs/test/conf.ini index b6d7bc9..5fbd9bb 100644 --- a/docs/test/conf.ini +++ b/docs/test/conf.ini @@ -4,7 +4,7 @@ AppMode = "test" HttpPort = ":8085" Host = "https://common.szjixun.cn" RedirectUri = "/api/redirect/url" - +ErpHost = "http://114.218.158.24:9020" [bos] Ak = "ALTAKxrqOQHnAN525Tb2GX4Bhe" Sk = "d2ecaa9d75114d3b9f42b99014198306" diff --git a/pkg/model/cast/approval.go b/pkg/model/cast/approval.go new file mode 100644 index 0000000..3539ac4 --- /dev/null +++ b/pkg/model/cast/approval.go @@ -0,0 +1,24 @@ +package cast + +type ApprovalDetailResponse struct { + Status int `json:"status"` + Data Data `json:"data"` + Msg string `json:"msg"` + Code int `json:"code"` + Error *string `json:"error"` + Err string `json:"err"` + Keys []string `json:"keys"` + Positions *interface{} `json:"positions"` +} + +type Data struct { + Count int `json:"Count"` + Data []Item `json:"data"` + Status int `json:"Status"` +} + +type Item struct { + ID int `json:"ID"` + Domain string `json:"Domain"` + Status int `json:"Status"` +} diff --git a/pkg/service/cast/approval.go b/pkg/service/cast/approval.go new file mode 100644 index 0000000..06e3705 --- /dev/null +++ b/pkg/service/cast/approval.go @@ -0,0 +1,39 @@ +package cast + +import ( + "encoding/json" + "errors" + "fmt" + "fonchain-fiee/cmd/config" + "fonchain-fiee/pkg/e" + "fonchain-fiee/pkg/utils" + modelCast "fonchain-fiee/pkg/model/cast" +) + +type CastService struct { +} + +func (c *CastService) ApprovalDetail(approvalIds []int) (data map[int]int, err error) { + idsBytes, _ := json.Marshal(approvalIds) + var respBody string + url := fmt.Sprintf(config.AppConfig.System.ErpHost + "/approval/list/ex") + respBody, err = utils.Post(url, string(idsBytes)) + if err != nil { + return + } + var respDetail modelCast.ApprovalDetailResponse + if err = json.Unmarshal([]byte(respBody), &respDetail); err != nil { + err = errors.New(e.GetMsg(e.JsonUnmarshal)) + return + } + if respDetail.Status == 0 && len(respDetail.Data.Data) > 0 { + data = make(map[int]int, len(respDetail.Data.Data)) + for _, v := range respDetail.Data.Data { + data[v.ID] = v.Status + } + } else { + err = errors.New(e.GetMsg(e.ErrorHttp)) + return + } + return +} diff --git a/pkg/service/cast/work.go b/pkg/service/cast/work.go index eddb1a9..d6bca84 100644 --- a/pkg/service/cast/work.go +++ b/pkg/service/cast/work.go @@ -81,13 +81,14 @@ func UpdateWorkVideo(ctx *gin.Context) { } func UpdateApproval(ctx *gin.Context) { - var req *cast.UpdateApprovalReq + var req *cast.UpdateStatusReq var err error if err = ctx.ShouldBind(&req); err != nil { service.Error(ctx, err) return } - resp, err := service.CastProvider.UpdateApproval(ctx, req) + req.WorkAction = cast.WorkActionENUM_APPROVAL + resp, err := service.CastProvider.UpdateStatus(ctx, req) if err != nil { service.Error(ctx, err) return diff --git a/pkg/utils/http.go b/pkg/utils/http.go new file mode 100644 index 0000000..0ab8e10 --- /dev/null +++ b/pkg/utils/http.go @@ -0,0 +1,34 @@ +package utils + +import ( + "bytes" + "io/ioutil" + "net/http" +) + +func Post(url, data string) (string, error) { + reader := bytes.NewReader([]byte(data)) + + request, err := http.NewRequest("POST", url, reader) + if err != nil { + return "", err + } + defer request.Body.Close() //程序在使用完回复后必须关闭回复的主体 + request.Header.Set("Content-Type", "application/json;charset=UTF-8") + //必须设定该参数,POST参数才能正常提交,意思是以json串提交数据 + + client := http.Client{} + resp, err := client.Do(request) //Do 方法发送请求,返回 HTTP 回复 + if err != nil { + return "", err + } + + respBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return "", err + } + + //byte数组直接转成string,优化内存 + // str := (*string)(unsafe.Pointer(&respBytes)) + return string(respBytes), nil +}