作者 Your Name

调整导入导出

  1 +{
  2 + // 使用 IntelliSense 了解相关属性。
  3 + // 悬停以查看现有属性的描述。
  4 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  5 + "version": "0.2.0",
  6 + "configurations": [
  7 + {
  8 + "name": "Launch file",
  9 + "type": "go",
  10 + "request": "launch",
  11 + "mode": "debug",
  12 + "program": "./main.go",
  13 + "buildFlags": ""
  14 + }
  15 + ]
  16 +}
1 package beego 1 package beego
2 2
3 import ( 3 import (
  4 + "net/http"
  5 + "os"
  6 + "strconv"
  7 +
4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
7 chart_editor "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/chart-editor" 11 chart_editor "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/chart-editor"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/cost_structured" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/cost_structured"
9 - "net/http"  
10 - "os"  
11 - "strconv"  
12 13
13 "github.com/beego/beego/v2/server/web/context" 14 "github.com/beego/beego/v2/server/web/context"
14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" 15 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
@@ -38,7 +39,7 @@ func init() { @@ -38,7 +39,7 @@ func init() {
38 } 39 }
39 } 40 }
40 //https支持 41 //https支持
41 - web.BConfig.Listen.EnableHTTPS = true 42 + web.BConfig.Listen.EnableHTTPS = false
42 web.BConfig.Listen.HTTPSPort = 443 43 web.BConfig.Listen.HTTPSPort = 443
43 web.BConfig.Listen.HTTPSCertFile = "./config/fjmaimaimai.com_bundle.crt" 44 web.BConfig.Listen.HTTPSCertFile = "./config/fjmaimaimai.com_bundle.crt"
44 web.BConfig.Listen.HTTPSKeyFile = "./config/fjmaimaimai.com.key" 45 web.BConfig.Listen.HTTPSKeyFile = "./config/fjmaimaimai.com.key"
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 }
@@ -3,14 +3,15 @@ package middleware @@ -3,14 +3,15 @@ package middleware
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 "fmt" 5 "fmt"
  6 + "io/ioutil"
  7 + "net/http"
  8 + "strings"
  9 +
6 "github.com/beego/beego/v2/client/httplib" 10 "github.com/beego/beego/v2/client/httplib"
7 "github.com/beego/beego/v2/server/web" 11 "github.com/beego/beego/v2/server/web"
8 "github.com/beego/beego/v2/server/web/context" 12 "github.com/beego/beego/v2/server/web/context"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" 14 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
11 - "io/ioutil"  
12 - "net/http"  
13 - "strings"  
14 ) 15 )
15 16
16 type internalService interface { 17 type internalService interface {
@@ -53,6 +54,7 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc @@ -53,6 +54,7 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc
53 } 54 }
54 req.Header("orgIds", fmt.Sprintf("%v", strings.Join(orgIdList, ","))) 55 req.Header("orgIds", fmt.Sprintf("%v", strings.Join(orgIdList, ",")))
55 } 56 }
  57 +
56 req.Body(ctx.Input.RequestBody) 58 req.Body(ctx.Input.RequestBody)
57 response, err := req.Response() 59 response, err := req.Response()
58 if err != nil { 60 if err != nil {