作者 Your Name

调整导入导出

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "./main.go",
"buildFlags": ""
}
]
}
... ...
package beego
import (
"net/http"
"os"
"strconv"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
chart_editor "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/chart-editor"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/cost_structured"
"net/http"
"os"
"strconv"
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
... ... @@ -38,7 +39,7 @@ func init() {
}
}
//https支持
web.BConfig.Listen.EnableHTTPS = true
web.BConfig.Listen.EnableHTTPS = false
web.BConfig.Listen.HTTPSPort = 443
web.BConfig.Listen.HTTPSCertFile = "./config/fjmaimaimai.com_bundle.crt"
web.BConfig.Listen.HTTPSKeyFile = "./config/fjmaimaimai.com.key"
... ...
package web_client
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/http/httputil"
"net/url"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/excel"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
... ... @@ -187,30 +188,32 @@ func (controller *ExcelDataController) FileImport() {
case domain.ImportDividendsReturnOrders:
importDividendsReturnedOrder(controller)
case "ImportProductRecordLevel2", "ImportAttendance", "ImportProductTrouble":
//车间制造-二级品审核导入
target, err := url.Parse(constant.ALLIED_CREATION_MANUFACTURE_HOST)
sourceFile, err := controller.GetExcelFile()
if err != nil {
panic(err)
e := application.ThrowError(application.TRANSACTION_ERROR, err.Error())
controller.Response(nil, e)
return
}
tokenData, _ := middleware.FormCtxLoginToken(controller.Ctx)
controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/v1/web", "", 1)
newProxy := httputil.NewSingleHostReverseProxy(target)
directorFunc := newProxy.Director
newDirectorFunc := func(r *http.Request) {
r.Header.Add("orgId", fmt.Sprintf("%v", tokenData.OrgId))
r.Header.Add("companyId", fmt.Sprintf("%v", tokenData.CompanyId))
r.Header.Add("userId", fmt.Sprintf("%v", tokenData.UserId))
orgIdList := make([]string, 0)
for i := range tokenData.OrgIds {
orgIdList = append(orgIdList, fmt.Sprintf("%d", tokenData.OrgIds[i]))
}
r.Header.Add("orgIds", strings.Join(orgIdList, ","))
directorFunc(r)
r.Host = target.Host
bodyBuf := &bytes.Buffer{}
formWriter := multipart.NewWriter(bodyBuf)
fileWriter, _ := formWriter.CreateFormFile("file", code+".xlsx")
io.Copy(fileWriter, sourceFile)
formWriter.WriteField("code", code)
formWriter.Close()
target, _ := url.Parse(constant.ALLIED_CREATION_MANUFACTURE_HOST)
targetPath := strings.Replace(controller.Ctx.Request.URL.Path, "/v1/web", "", 1)
resp, err := http.Post(
target.String()+targetPath,
formWriter.FormDataContentType(),
bodyBuf,
)
if err != nil {
e := application.ThrowError(application.TRANSACTION_ERROR, err.Error())
controller.Response(nil, e)
return
}
newProxy.Director = newDirectorFunc
newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request)
respData, _ := io.ReadAll(resp.Body)
controller.Ctx.ResponseWriter.Write(respData)
default:
defaultImport(controller)
}
... ...
... ... @@ -3,14 +3,15 @@ package middleware
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"github.com/beego/beego/v2/client/httplib"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"io/ioutil"
"net/http"
"strings"
)
type internalService interface {
... ... @@ -53,6 +54,7 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc
}
req.Header("orgIds", fmt.Sprintf("%v", strings.Join(orgIdList, ",")))
}
req.Body(ctx.Input.RequestBody)
response, err := req.Response()
if err != nil {
... ...