正在显示
13 个修改的文件
包含
326 行增加
和
10 行删除
| 1 | +package query | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
| 4 | + | ||
| 5 | +type SearchProductQuery struct { | ||
| 6 | + // 产品名称 | ||
| 7 | + ProductName string `json:"productName,omitempty"` | ||
| 8 | + // 产品类别 | ||
| 9 | + ProductCategory string `cname:"产品类别" json:"productCategory"` | ||
| 10 | + //操作人 | ||
| 11 | + Operator domain.Operator `json:"-"` | ||
| 12 | + SelectedField []string `json:"selectedField"` | ||
| 13 | +} |
| @@ -2,6 +2,7 @@ package service | @@ -2,6 +2,7 @@ package service | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture" | ||
| 5 | 6 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" |
| @@ -51,3 +52,16 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co | @@ -51,3 +52,16 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co | ||
| 51 | } | 52 | } |
| 52 | return ExportCooperationUserData{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil | 53 | return ExportCooperationUserData{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil |
| 53 | } | 54 | } |
| 55 | + | ||
| 56 | +// ExportCooperationUser 导出共创用户信息列表 | ||
| 57 | +func (srv ExcelDataService) ExportProducts(cmd *query.SearchProductQuery) (ExportProductsData, error) { | ||
| 58 | + creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator) | ||
| 59 | + result, err := creationUserGateway.SearchProduct(allied_creation_manufacture.SearchProductRequest{ | ||
| 60 | + ProductName: cmd.ProductName, | ||
| 61 | + ProductCategory: cmd.ProductCategory, | ||
| 62 | + }) | ||
| 63 | + if err != nil { | ||
| 64 | + return ExportProductsData{}, fmt.Errorf("获取企业用户数据失败:%w", err) | ||
| 65 | + } | ||
| 66 | + return ExportProductsData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil | ||
| 67 | +} |
| @@ -2,6 +2,7 @@ package service | @@ -2,6 +2,7 @@ package service | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture" | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/converter" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/converter" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -161,6 +162,43 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import | @@ -161,6 +162,43 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import | ||
| 161 | return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(items)), nil | 162 | return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(items)), nil |
| 162 | } | 163 | } |
| 163 | 164 | ||
| 165 | +// ImportProduct 导入生产信息 | ||
| 166 | +func (srv ExcelDataService) ImportProduct(importDataCommand *command.ImportDataCommand) (interface{}, error) { | ||
| 167 | + excelImport := excel.NewExcelImport() | ||
| 168 | + excelImport.RowBegin = 3 //第二行开始读取 | ||
| 169 | + excelImport.DataFields = []excel.DataField{ | ||
| 170 | + {EnName: "productCode", CnName: "产品编号"}, | ||
| 171 | + {EnName: "productName", CnName: "*品名"}, | ||
| 172 | + {EnName: "unit", CnName: "*规格"}, | ||
| 173 | + {EnName: "productCategory", CnName: "*类别"}, | ||
| 174 | + {EnName: "unitWeight", CnName: "投入单份重量"}, | ||
| 175 | + } | ||
| 176 | + excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader) | ||
| 177 | + if err != nil { | ||
| 178 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 179 | + } | ||
| 180 | + items := make([]*domain.ImportProductItem, 0) | ||
| 181 | + for _, v := range excelData { | ||
| 182 | + item := &domain.ImportProductItem{ | ||
| 183 | + ProductCode: strings.TrimSpace(v["productCode"]), | ||
| 184 | + ProductName: strings.TrimSpace(v["productName"]), | ||
| 185 | + ProductCategory: strings.TrimSpace(v["productCategory"]), | ||
| 186 | + Unit: strings.TrimSpace(v["unit"]), | ||
| 187 | + UnitWeight: strings.TrimSpace(v["unitWeight"]), | ||
| 188 | + } | ||
| 189 | + items = append(items, item) | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + svr := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(importDataCommand.Operator) | ||
| 193 | + result, err := svr.BatchAddProduct(allied_creation_manufacture.BatchAddProductRequest{ | ||
| 194 | + List: items, | ||
| 195 | + }) | ||
| 196 | + if err != nil { | ||
| 197 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 198 | + } | ||
| 199 | + return srv.importResultWithHeader(excelImport.DataFields, *result, len(items)), nil | ||
| 200 | +} | ||
| 201 | + | ||
| 164 | // 导入结果 | 202 | // 导入结果 |
| 165 | func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, failRows []interface{}, totalRow int) interface{} { | 203 | func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, failRows []interface{}, totalRow int) interface{} { |
| 166 | var result = map[string]interface{}{ | 204 | var result = map[string]interface{}{ |
| 1 | package service | 1 | package service |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "fmt" | ||
| 4 | "github.com/linmadan/egglib-go/utils/excel" | 5 | "github.com/linmadan/egglib-go/utils/excel" |
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture" | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" |
| 6 | ) | 8 | ) |
| 7 | 9 | ||
| @@ -175,3 +177,65 @@ func (data ExportCooperationUserData) DataListLen() int { | @@ -175,3 +177,65 @@ func (data ExportCooperationUserData) DataListLen() int { | ||
| 175 | func (data ExportCooperationUserData) TableTitle() []string { | 177 | func (data ExportCooperationUserData) TableTitle() []string { |
| 176 | return nil | 178 | return nil |
| 177 | } | 179 | } |
| 180 | + | ||
| 181 | +//ExportProductsData 导出产品数据 | ||
| 182 | +type ExportProductsData struct { | ||
| 183 | + SourceData []allied_creation_manufacture.SearchProductItem | ||
| 184 | + SelectedField []string | ||
| 185 | +} | ||
| 186 | + | ||
| 187 | +var _ excel.ExcelMaker = (*ExportProductsData)(nil) | ||
| 188 | + | ||
| 189 | +func (data ExportProductsData) AllFields() []DataFieldOptions { | ||
| 190 | + return []DataFieldOptions{ | ||
| 191 | + {EnName: "productCode", CnName: "产品编号"}, | ||
| 192 | + {EnName: "productName", CnName: "*品名"}, | ||
| 193 | + {EnName: "unit", CnName: "*规格"}, | ||
| 194 | + {EnName: "productCategory", CnName: "*类别"}, | ||
| 195 | + {EnName: "unitWeight", CnName: "投入单份重量"}, | ||
| 196 | + } | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +func (data ExportProductsData) DataFieldList() []excel.DataField { | ||
| 200 | + fields := []excel.DataField{} | ||
| 201 | + allFields := data.AllFields() | ||
| 202 | + for _, value2 := range allFields { | ||
| 203 | + if len(data.SelectedField) == 0 || value2.IsDefault { | ||
| 204 | + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName}) | ||
| 205 | + continue | ||
| 206 | + } | ||
| 207 | + for _, value3 := range data.SelectedField { | ||
| 208 | + if value2.EnName == value3 { | ||
| 209 | + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName}) | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + } | ||
| 213 | + return fields | ||
| 214 | +} | ||
| 215 | + | ||
| 216 | +func (data ExportProductsData) CellValue(index int, enName string) (value interface{}) { | ||
| 217 | + if index > data.DataListLen() { | ||
| 218 | + return "" | ||
| 219 | + } | ||
| 220 | + switch enName { | ||
| 221 | + case "productCode": | ||
| 222 | + return data.SourceData[index].ProductCode | ||
| 223 | + case "productName": | ||
| 224 | + return data.SourceData[index].ProductName | ||
| 225 | + case "unit": | ||
| 226 | + return data.SourceData[index].Unit | ||
| 227 | + case "productCategory": | ||
| 228 | + return data.SourceData[index].ProductCategory | ||
| 229 | + case "unitWeight": | ||
| 230 | + return fmt.Sprintf("%v", data.SourceData[index].UnitWeight) | ||
| 231 | + } | ||
| 232 | + return nil | ||
| 233 | +} | ||
| 234 | + | ||
| 235 | +func (data ExportProductsData) DataListLen() int { | ||
| 236 | + return len(data.SourceData) | ||
| 237 | +} | ||
| 238 | + | ||
| 239 | +func (data ExportProductsData) TableTitle() []string { | ||
| 240 | + return nil | ||
| 241 | +} |
| @@ -27,6 +27,9 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creatio | @@ -27,6 +27,9 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creatio | ||
| 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 | +// 天联共创 生产制造模块 | ||
| 31 | +var ALLIED_CREATION_MANUFACTURE_HOST = "http://localhost:8083" | ||
| 32 | + | ||
| 30 | // 版本更新模块 | 33 | // 版本更新模块 |
| 31 | 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" |
| 32 | 35 |
| @@ -63,6 +63,9 @@ const ( | @@ -63,6 +63,9 @@ const ( | ||
| 63 | ImportDividendsOrders = "BUSINESS_ALLIED-CREATION_BONUS_ORDER" | 63 | ImportDividendsOrders = "BUSINESS_ALLIED-CREATION_BONUS_ORDER" |
| 64 | // 导入退货订单 | 64 | // 导入退货订单 |
| 65 | ImportDividendsReturnOrders = "BUSINESS_ALLIED-CREATION_BONUS_RETURN" | 65 | ImportDividendsReturnOrders = "BUSINESS_ALLIED-CREATION_BONUS_RETURN" |
| 66 | + | ||
| 67 | + // 导入产品 | ||
| 68 | + ImportProducts = "ImportProducts" | ||
| 66 | ) | 69 | ) |
| 67 | 70 | ||
| 68 | const ( | 71 | const ( |
| @@ -70,6 +73,9 @@ const ( | @@ -70,6 +73,9 @@ const ( | ||
| 70 | ExportCompanyUser = "ExportCompanyUser" | 73 | ExportCompanyUser = "ExportCompanyUser" |
| 71 | // 导入共创用户 | 74 | // 导入共创用户 |
| 72 | ExportCooperationUser = "ExportCooperationUser" | 75 | ExportCooperationUser = "ExportCooperationUser" |
| 76 | + | ||
| 77 | + // 导入产品 | ||
| 78 | + ExportProducts = "ExportProducts" | ||
| 73 | ) | 79 | ) |
| 74 | 80 | ||
| 75 | const ( | 81 | const ( |
pkg/domain/excel.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +// 导入数据体 | ||
| 4 | +type ImportProductItem struct { | ||
| 5 | + // 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001 | ||
| 6 | + ProductCode string `json:"productCode,omitempty"` | ||
| 7 | + // 产品名称 | ||
| 8 | + ProductName string `json:"productName,omitempty"` | ||
| 9 | + // 产品类别 | ||
| 10 | + ProductCategory string `json:"productCategory,omitempty"` | ||
| 11 | + // 单位 | ||
| 12 | + Unit string `json:"unit,omitempty"` | ||
| 13 | + // 单份重量(原材料) | ||
| 14 | + UnitWeight string `json:"unitWeight,omitempty"` | ||
| 15 | + // 失败理由 | ||
| 16 | + FailReason string `json:"failReason"` | ||
| 17 | +} |
| 1 | +package allied_creation_manufacture | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "time" | ||
| 6 | + | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +//HttpLibAlliedCreationManufacture 生产制造模块 | ||
| 13 | +type HttpLibAlliedCreationManufacture struct { | ||
| 14 | + service_gateway.BaseServiceGateway | ||
| 15 | + baseUrL string | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewHttpLibAlliedCreationManufacture(operator domain.Operator) *HttpLibAlliedCreationManufacture { | ||
| 19 | + return &HttpLibAlliedCreationManufacture{ | ||
| 20 | + BaseServiceGateway: service_gateway.BaseServiceGateway{ | ||
| 21 | + ConnectTimeout: 100 * time.Second, | ||
| 22 | + ReadWriteTimeout: 100 * time.Second, | ||
| 23 | + CompanyId: operator.CompanyId, | ||
| 24 | + OrgId: operator.OrgId, | ||
| 25 | + UserId: operator.UserId, | ||
| 26 | + UserBaseId: operator.UserBaseId, | ||
| 27 | + }, | ||
| 28 | + baseUrL: constant.ALLIED_CREATION_MANUFACTURE_HOST, | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +func (gateway HttpLibAlliedCreationManufacture) BaseUrl() string { | ||
| 34 | + return gateway.baseUrL | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +//BatchAddProduct 批量添加产品 | ||
| 38 | +func (gateway HttpLibAlliedCreationManufacture) BatchAddProduct(param BatchAddProductRequest) (*BatchAddProductResponse, error) { | ||
| 39 | + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/products/batch-add") | ||
| 40 | + method := "post" | ||
| 41 | + var data BatchAddProductResponse | ||
| 42 | + err := gateway.FastDoRequest(url, method, param, &data) | ||
| 43 | + return &data, err | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +type BatchAddProductRequest struct { | ||
| 47 | + List []*domain.ImportProductItem `json:"list"` | ||
| 48 | +} | ||
| 49 | +type BatchAddProductResponse []interface{} | ||
| 50 | + | ||
| 51 | +//BatchAddProduct 批量添加产品 | ||
| 52 | +func (gateway HttpLibAlliedCreationManufacture) SearchProduct(param SearchProductRequest) (*SearchProductResponse, error) { | ||
| 53 | + url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/products/search") | ||
| 54 | + method := "post" | ||
| 55 | + var data SearchProductResponse | ||
| 56 | + err := gateway.FastDoRequest(url, method, param, &data) | ||
| 57 | + return &data, err | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +type ( | ||
| 61 | + SearchProductRequest struct { | ||
| 62 | + // 页码 | ||
| 63 | + PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
| 64 | + // 页数 | ||
| 65 | + PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
| 66 | + // 产品名称 | ||
| 67 | + ProductName string `json:"productName,omitempty"` | ||
| 68 | + // 产品类别 | ||
| 69 | + ProductCategory string `cname:"产品类别" json:"productCategory"` | ||
| 70 | + } | ||
| 71 | + SearchProductResponse struct { | ||
| 72 | + Grid struct { | ||
| 73 | + List []SearchProductItem `json:"list"` | ||
| 74 | + Total int `json:"total"` | ||
| 75 | + } `json:"grid"` | ||
| 76 | + } | ||
| 77 | + SearchProductItem struct { | ||
| 78 | + ProductID int `json:"productId"` | ||
| 79 | + ProductCode string `json:"productCode"` | ||
| 80 | + ProductName string `json:"productName"` | ||
| 81 | + ProductCategory string `json:"productCategory"` | ||
| 82 | + Unit string `json:"unit"` | ||
| 83 | + UnitWeight float64 `json:"unitWeight"` | ||
| 84 | + } | ||
| 85 | +) |
| @@ -66,3 +66,40 @@ func (gateway BaseServiceGateway) GetResponseData(result GatewayResponse, data i | @@ -66,3 +66,40 @@ func (gateway BaseServiceGateway) GetResponseData(result GatewayResponse, data i | ||
| 66 | } | 66 | } |
| 67 | return nil | 67 | return nil |
| 68 | } | 68 | } |
| 69 | + | ||
| 70 | +func (gateway BaseServiceGateway) FastDoRequest(url, method string, param interface{}, data interface{}) error { | ||
| 71 | + err := gateway.DoRequest(Request{ | ||
| 72 | + Url: url, | ||
| 73 | + Method: method, | ||
| 74 | + Param: param, | ||
| 75 | + }, &data) | ||
| 76 | + if err != nil { | ||
| 77 | + return err | ||
| 78 | + } | ||
| 79 | + return nil | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +func (gateway BaseServiceGateway) DoRequest(requestParam Request, val interface{}) error { | ||
| 83 | + r := gateway.CreateRequest(requestParam.Url, requestParam.Method) | ||
| 84 | + req, err := r.JSONBody(requestParam.Param) | ||
| 85 | + if err != nil { | ||
| 86 | + return err | ||
| 87 | + } | ||
| 88 | + byteResult, err := req.Bytes() | ||
| 89 | + if err != nil { | ||
| 90 | + return err | ||
| 91 | + } | ||
| 92 | + var result GatewayResponse | ||
| 93 | + err = json.Unmarshal(byteResult, &result) | ||
| 94 | + if err != nil { | ||
| 95 | + return err | ||
| 96 | + } | ||
| 97 | + err = gateway.GetResponseData(result, val) | ||
| 98 | + return nil | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +type Request struct { | ||
| 102 | + Url string | ||
| 103 | + Method string | ||
| 104 | + Param interface{} | ||
| 105 | +} |
| @@ -2,6 +2,7 @@ package beego | @@ -2,6 +2,7 @@ package beego | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | 4 | "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" | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" |
| 6 | "net/http" | 7 | "net/http" |
| 7 | "os" | 8 | "os" |
| @@ -63,6 +64,9 @@ func init() { | @@ -63,6 +64,9 @@ func init() { | ||
| 63 | //)) | 64 | //)) |
| 64 | 65 | ||
| 65 | web.InsertFilter("/v1/common/user/area/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/common/user", allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{}))) | 66 | web.InsertFilter("/v1/common/user/area/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/common/user", allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{}))) |
| 67 | + | ||
| 68 | + web.InsertFilter("/v1/manufacture/*", web.BeforeRouter, middleware.CheckAccessToken()) | ||
| 69 | + web.InsertFilter("/v1/manufacture/*", web.BeforeRouter, middleware.RedirectInternalService("/v1/manufacture", allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(domain.Operator{}))) | ||
| 66 | } | 70 | } |
| 67 | 71 | ||
| 68 | func AllowCors() func(ctx *context.Context) { | 72 | func AllowCors() func(ctx *context.Context) { |
| @@ -209,6 +209,8 @@ func defaultImport(controller *ExcelDataController) { | @@ -209,6 +209,8 @@ func defaultImport(controller *ExcelDataController) { | ||
| 209 | data, err = excelService.ImportCooperationUser(cmd) | 209 | data, err = excelService.ImportCooperationUser(cmd) |
| 210 | case domain.ImportOrganization: | 210 | case domain.ImportOrganization: |
| 211 | data, err = excelService.ImportOrganization(cmd) | 211 | data, err = excelService.ImportOrganization(cmd) |
| 212 | + case domain.ImportProducts: | ||
| 213 | + data, err = excelService.ImportProduct(cmd) | ||
| 212 | default: | 214 | default: |
| 213 | err = fmt.Errorf("导入不存在 Code:%v", cmd.Code) | 215 | err = fmt.Errorf("导入不存在 Code:%v", cmd.Code) |
| 214 | } | 216 | } |
| @@ -261,6 +263,12 @@ func fileExport(controller *ExcelDataController, code string) { | @@ -261,6 +263,12 @@ func fileExport(controller *ExcelDataController, code string) { | ||
| 261 | companyUserListQuery.Operator = exportDataCommand.Operator | 263 | companyUserListQuery.Operator = exportDataCommand.Operator |
| 262 | data, err = excelService.ExportCooperationUser(companyUserListQuery) | 264 | data, err = excelService.ExportCooperationUser(companyUserListQuery) |
| 263 | filename = "导出共创用户" | 265 | filename = "导出共创用户" |
| 266 | + case domain.ExportProducts: | ||
| 267 | + companyUserListQuery := &query.SearchProductQuery{} | ||
| 268 | + exportDataCommand.UnmarshalQuery(companyUserListQuery) | ||
| 269 | + companyUserListQuery.Operator = exportDataCommand.Operator | ||
| 270 | + data, err = excelService.ExportProducts(companyUserListQuery) | ||
| 271 | + filename = "导出商品" | ||
| 264 | default: | 272 | default: |
| 265 | err = fmt.Errorf("export type :%v not exists", exportDataCommand.Code) | 273 | err = fmt.Errorf("export type :%v not exists", exportDataCommand.Code) |
| 266 | } | 274 | } |
| @@ -14,8 +14,8 @@ type CtxKeyLoginToken struct{} | @@ -14,8 +14,8 @@ type CtxKeyLoginToken struct{} | ||
| 14 | 14 | ||
| 15 | func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) { | 15 | func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) { |
| 16 | val := ctx.Input.GetData(CtxKeyLoginToken{}) | 16 | val := ctx.Input.GetData(CtxKeyLoginToken{}) |
| 17 | - if v, ok := val.(domain.LoginToken); ok { | ||
| 18 | - return v, true | 17 | + if v, ok := val.(*domain.LoginToken); ok { |
| 18 | + return *v, true | ||
| 19 | } | 19 | } |
| 20 | return domain.LoginToken{}, false | 20 | return domain.LoginToken{}, false |
| 21 | } | 21 | } |
| @@ -34,19 +34,19 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc | @@ -34,19 +34,19 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc | ||
| 34 | "code": 1, | 34 | "code": 1, |
| 35 | "data": struct{}{}, | 35 | "data": struct{}{}, |
| 36 | }, false, false) | 36 | }, false, false) |
| 37 | - } else { | ||
| 38 | - ctx.Output.SetStatus(http.StatusOK) | ||
| 39 | - ctx.Output.JSON(map[string]interface{}{ | ||
| 40 | - "msg": "成功", | ||
| 41 | - "code": 0, | ||
| 42 | - "data": data, | ||
| 43 | - }, false, false) | ||
| 44 | } | 37 | } |
| 45 | }() | 38 | }() |
| 46 | - | ||
| 47 | method := strings.ToLower(ctx.Request.Method) | 39 | method := strings.ToLower(ctx.Request.Method) |
| 48 | url := strings.Replace(ctx.Request.RequestURI, prefix, "", 1) | 40 | url := strings.Replace(ctx.Request.RequestURI, prefix, "", 1) |
| 49 | req := svr.CreateRequest(svr.BaseUrl()+url, method) | 41 | req := svr.CreateRequest(svr.BaseUrl()+url, method) |
| 42 | + | ||
| 43 | + // 传递当前登录信息(可配置) | ||
| 44 | + loginToken, ok := FormCtxLoginToken(ctx) | ||
| 45 | + if ok && loginToken.CompanyId > 0 && loginToken.OrgId > 0 { | ||
| 46 | + req.Header("companyId", fmt.Sprintf("%v", loginToken.CompanyId)) | ||
| 47 | + req.Header("orgId", fmt.Sprintf("%v", loginToken.OrgId)) | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | req.Body(ctx.Input.RequestBody) | 50 | req.Body(ctx.Input.RequestBody) |
| 51 | response, err := req.Response() | 51 | response, err := req.Response() |
| 52 | if err != nil { | 52 | if err != nil { |
| @@ -63,6 +63,13 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc | @@ -63,6 +63,13 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc | ||
| 63 | } | 63 | } |
| 64 | defer response.Body.Close() | 64 | defer response.Body.Close() |
| 65 | 65 | ||
| 66 | + // 透传非json数据 | ||
| 67 | + contentType := response.Header.Get("Content-Type") | ||
| 68 | + if contentType != "application/json" { | ||
| 69 | + copyResponse(ctx, response, byteResult) | ||
| 70 | + return | ||
| 71 | + } | ||
| 72 | + | ||
| 66 | var result service_gateway.GatewayResponse | 73 | var result service_gateway.GatewayResponse |
| 67 | err = json.Unmarshal(byteResult, &result) | 74 | err = json.Unmarshal(byteResult, &result) |
| 68 | if err != nil { | 75 | if err != nil { |
| @@ -70,5 +77,25 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc | @@ -70,5 +77,25 @@ func RedirectInternalService(prefix string, svr internalService) web.FilterFunc | ||
| 70 | } | 77 | } |
| 71 | 78 | ||
| 72 | err = svr.GetResponseData(result, &data) | 79 | err = svr.GetResponseData(result, &data) |
| 80 | + if err != nil { | ||
| 81 | + return | ||
| 82 | + } | ||
| 83 | + ctx.Output.SetStatus(http.StatusOK) | ||
| 84 | + ctx.Output.JSON(map[string]interface{}{ | ||
| 85 | + "msg": "成功", | ||
| 86 | + "code": 0, | ||
| 87 | + "data": data, | ||
| 88 | + }, false, false) | ||
| 89 | + } | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +func copyResponse(ctx *context.Context, response *http.Response, data []byte) { | ||
| 93 | + for k, v := range response.Header { | ||
| 94 | + if len(v) == 0 { | ||
| 95 | + continue | ||
| 96 | + } | ||
| 97 | + ctx.Output.Header(k, strings.Join(v, ",")) | ||
| 73 | } | 98 | } |
| 99 | + ctx.Output.SetStatus(response.StatusCode) | ||
| 100 | + ctx.Output.Body(data) | ||
| 74 | } | 101 | } |
-
请 注册 或 登录 后发表评论