作者 Your Name

处理导入

@@ -15,16 +15,16 @@ var LOG_PREFIX = "[allied-creation-gateway]" @@ -15,16 +15,16 @@ var LOG_PREFIX = "[allied-creation-gateway]"
15 15
16 var FileStatic = "./static" 16 var FileStatic = "./static"
17 17
18 -var HTTP_PORT int = 8083 18 +var HTTP_PORT int = 8080
19 var ALLIED_CREATION_GATEWAY_HOST = "http://localhost:8080" 19 var ALLIED_CREATION_GATEWAY_HOST = "http://localhost:8080"
20 20
21 -//天联共创基础模块 21 +// 天联共创基础模块
22 var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com" 22 var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com"
23 23
24 -//天联共创用户模块 24 +// 天联共创用户模块
25 var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com" 25 var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com"
26 26
27 -//天联共创业务模块 27 +// 天联共创业务模块
28 var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com" 28 var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com"
29 29
30 // 天联共创 生产制造模块 30 // 天联共创 生产制造模块
@@ -33,10 +33,10 @@ var ALLIED_CREATION_MANUFACTURE_HOST = "http://localhost:8083" @@ -33,10 +33,10 @@ var ALLIED_CREATION_MANUFACTURE_HOST = "http://localhost:8083"
33 // 版本更新模块 33 // 版本更新模块
34 var SUPLUS_ADMIN_BASE_HOST = "http://suplus-admin-base-dev.fjmaimaimai.com" 34 var SUPLUS_ADMIN_BASE_HOST = "http://suplus-admin-base-dev.fjmaimaimai.com"
35 35
36 -//通用模块短信服务 36 +// 通用模块短信服务
37 var SMS_SERVE_HOST = "https://sms.fjmaimaimai.com:9897" 37 var SMS_SERVE_HOST = "https://sms.fjmaimaimai.com:9897"
38 38
39 -//素加销售导航服务 39 +// 素加销售导航服务
40 var SUPLUS_SALE_APP = "http://suplus-sale-app-gateway-test.fjmaimaimai.com" 40 var SUPLUS_SALE_APP = "http://suplus-sale-app-gateway-test.fjmaimaimai.com"
41 41
42 // TODO:特殊短信验证码,不验证,正式环境注入空 42 // TODO:特殊短信验证码,不验证,正式环境注入空
@@ -3,8 +3,12 @@ package web_client @@ -3,8 +3,12 @@ package web_client
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "io" 5 "io"
  6 + "net/http"
  7 + "net/http/httputil"
  8 + "net/url"
6 "strings" 9 "strings"
7 10
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware" 13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware"
10 14
@@ -17,7 +21,6 @@ import ( @@ -17,7 +21,6 @@ import (
17 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" 21 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
18 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service" 22 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
19 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation" 23 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
20 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"  
21 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" 24 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
22 ) 25 )
23 26
@@ -183,18 +186,31 @@ func (controller *ExcelDataController) FileImport() { @@ -183,18 +186,31 @@ func (controller *ExcelDataController) FileImport() {
183 importDividendsOrder(controller) 186 importDividendsOrder(controller)
184 case domain.ImportDividendsReturnOrders: 187 case domain.ImportDividendsReturnOrders:
185 importDividendsReturnedOrder(controller) 188 importDividendsReturnedOrder(controller)
186 - case "ImportProductRecordLevel2": 189 + case "ImportProductRecordLevel2", "ImportAttendance", "ImportProductTrouble":
187 //车间制造-二级品审核导入 190 //车间制造-二级品审核导入
188 - fn := middleware.RedirectInternalService("/v1/web", allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(domain.Operator{}))  
189 - fn(controller.Ctx)  
190 - case "ImportAttendance":  
191 - // 车间制造-工时管理导入  
192 - fn := middleware.RedirectInternalService("/v1/web", allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(domain.Operator{}))  
193 - fn(controller.Ctx)  
194 - case "ImportProductTrouble":  
195 - //车间制造-事故管理导入  
196 - fn := middleware.RedirectInternalService("/v1/web", allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(domain.Operator{}))  
197 - fn(controller.Ctx) 191 + target, err := url.Parse(constant.ALLIED_CREATION_MANUFACTURE_HOST)
  192 + if err != nil {
  193 + panic(err)
  194 + }
  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
  210 + }
  211 + newProxy.Director = newDirectorFunc
  212 + newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request)
  213 +
198 default: 214 default:
199 defaultImport(controller) 215 defaultImport(controller)
200 } 216 }