|
|
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)
|
|
|
}
|
|
|
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]))
|
|
|
e := application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
controller.Response(nil, e)
|
|
|
return
|
|
|
}
|
|
|
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)
|
|
|
}
|
...
|
...
|
|