|
1
|
package web_client
|
1
|
package web_client
|
|
2
|
|
2
|
|
|
3
|
import (
|
3
|
import (
|
|
|
|
4
|
+ "bytes"
|
|
4
|
"fmt"
|
5
|
"fmt"
|
|
5
|
"io"
|
6
|
"io"
|
|
|
|
7
|
+ "mime/multipart"
|
|
6
|
"net/http"
|
8
|
"net/http"
|
|
7
|
- "net/http/httputil"
|
|
|
|
8
|
"net/url"
|
9
|
"net/url"
|
|
9
|
"strings"
|
10
|
"strings"
|
|
10
|
|
11
|
|
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
|
12
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
|
|
12
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers"
|
13
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers"
|
|
13
|
- "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware"
|
|
|
|
14
|
|
14
|
|
|
15
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
15
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
|
16
|
|
16
|
|
|
17
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
17
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
|
18
|
|
18
|
|
|
19
|
"github.com/beego/beego/v2/server/web/context"
|
19
|
"github.com/beego/beego/v2/server/web/context"
|
|
|
|
20
|
+ "github.com/linmadan/egglib-go/core/application"
|
|
20
|
"github.com/linmadan/egglib-go/utils/excel"
|
21
|
"github.com/linmadan/egglib-go/utils/excel"
|
|
21
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
|
22
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
|
|
22
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
|
23
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
|
|
@@ -187,30 +188,32 @@ func (controller *ExcelDataController) FileImport() { |
|
@@ -187,30 +188,32 @@ func (controller *ExcelDataController) FileImport() { |
|
187
|
case domain.ImportDividendsReturnOrders:
|
188
|
case domain.ImportDividendsReturnOrders:
|
|
188
|
importDividendsReturnedOrder(controller)
|
189
|
importDividendsReturnedOrder(controller)
|
|
189
|
case "ImportProductRecordLevel2", "ImportAttendance", "ImportProductTrouble":
|
190
|
case "ImportProductRecordLevel2", "ImportAttendance", "ImportProductTrouble":
|
|
190
|
- //车间制造-二级品审核导入
|
|
|
|
191
|
- target, err := url.Parse(constant.ALLIED_CREATION_MANUFACTURE_HOST)
|
191
|
+ sourceFile, err := controller.GetExcelFile()
|
|
192
|
if err != nil {
|
192
|
if err != nil {
|
|
193
|
- panic(err)
|
193
|
+ e := application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
|
194
|
+ controller.Response(nil, e)
|
|
|
|
195
|
+ return
|
|
194
|
}
|
196
|
}
|
|
195
|
- tokenData, _ := middleware.FormCtxLoginToken(controller.Ctx)
|
|
|
|
196
|
- controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/v1/web", "", 1)
|
|
|
|
197
|
- newProxy := httputil.NewSingleHostReverseProxy(target)
|
|
|
|
198
|
- directorFunc := newProxy.Director
|
|
|
|
199
|
- newDirectorFunc := func(r *http.Request) {
|
|
|
|
200
|
- r.Header.Add("orgId", fmt.Sprintf("%v", tokenData.OrgId))
|
|
|
|
201
|
- r.Header.Add("companyId", fmt.Sprintf("%v", tokenData.CompanyId))
|
|
|
|
202
|
- r.Header.Add("userId", fmt.Sprintf("%v", tokenData.UserId))
|
|
|
|
203
|
- orgIdList := make([]string, 0)
|
|
|
|
204
|
- for i := range tokenData.OrgIds {
|
|
|
|
205
|
- orgIdList = append(orgIdList, fmt.Sprintf("%d", tokenData.OrgIds[i]))
|
|
|
|
206
|
- }
|
|
|
|
207
|
- r.Header.Add("orgIds", strings.Join(orgIdList, ","))
|
|
|
|
208
|
- directorFunc(r)
|
|
|
|
209
|
- r.Host = target.Host
|
197
|
+ bodyBuf := &bytes.Buffer{}
|
|
|
|
198
|
+ formWriter := multipart.NewWriter(bodyBuf)
|
|
|
|
199
|
+ fileWriter, _ := formWriter.CreateFormFile("file", code+".xlsx")
|
|
|
|
200
|
+ io.Copy(fileWriter, sourceFile)
|
|
|
|
201
|
+ formWriter.WriteField("code", code)
|
|
|
|
202
|
+ formWriter.Close()
|
|
|
|
203
|
+ target, _ := url.Parse(constant.ALLIED_CREATION_MANUFACTURE_HOST)
|
|
|
|
204
|
+ targetPath := strings.Replace(controller.Ctx.Request.URL.Path, "/v1/web", "", 1)
|
|
|
|
205
|
+ resp, err := http.Post(
|
|
|
|
206
|
+ target.String()+targetPath,
|
|
|
|
207
|
+ formWriter.FormDataContentType(),
|
|
|
|
208
|
+ bodyBuf,
|
|
|
|
209
|
+ )
|
|
|
|
210
|
+ if err != nil {
|
|
|
|
211
|
+ e := application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
|
212
|
+ controller.Response(nil, e)
|
|
|
|
213
|
+ return
|
|
210
|
}
|
214
|
}
|
|
211
|
- newProxy.Director = newDirectorFunc
|
|
|
|
212
|
- newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request)
|
|
|
|
213
|
-
|
215
|
+ respData, _ := io.ReadAll(resp.Body)
|
|
|
|
216
|
+ controller.Ctx.ResponseWriter.Write(respData)
|
|
214
|
default:
|
217
|
default:
|
|
215
|
defaultImport(controller)
|
218
|
defaultImport(controller)
|
|
216
|
}
|
219
|
}
|