作者 tangxuhui

Merge branch 'dev' into test

@@ -10,5 +10,6 @@ type CompanyUserListQuery struct { @@ -10,5 +10,6 @@ type CompanyUserListQuery struct {
10 //所属部门 10 //所属部门
11 DepartmentName string `json:"departmentName"` 11 DepartmentName string `json:"departmentName"`
12 //操作人 12 //操作人
13 - Operator domain.Operator `json:"-"` 13 + Operator domain.Operator `json:"-"`
  14 + SelectedField []string `json:"selectedField"`
14 } 15 }
@@ -10,5 +10,6 @@ type CooperationUserListQuery struct { @@ -10,5 +10,6 @@ type CooperationUserListQuery struct {
10 //用户名称 10 //用户名称
11 UserName string `json:"userName"` 11 UserName string `json:"userName"`
12 //共创公司 12 //共创公司
13 - CooperationCompany string `json:"cooperationCompany"` 13 + CooperationCompany string `json:"cooperationCompany"`
  14 + SelectedField []string `json:"selectedField"`
14 } 15 }
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 +
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
@@ -25,7 +26,10 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan @@ -25,7 +26,10 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan
25 if err != nil { 26 if err != nil {
26 return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) 27 return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
27 } 28 }
28 - return ExportCompanyUserData(result.Users), nil 29 + return ExportCompanyUserData{
  30 + SourceData: result.Users,
  31 + SelectedField: companyUserListQuery.SelectedField,
  32 + }, nil
29 } 33 }
30 34
31 // ExportCooperationUser 导出共创用户信息列表 35 // ExportCooperationUser 导出共创用户信息列表
@@ -45,5 +49,5 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co @@ -45,5 +49,5 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co
45 if err != nil { 49 if err != nil {
46 return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) 50 return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
47 } 51 }
48 - return ExportCooperationUserData(result.Users), nil 52 + return ExportCooperationUserData{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil
49 } 53 }
@@ -216,3 +216,14 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import @@ -216,3 +216,14 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import
216 "url": url, 216 "url": url,
217 }, nil 217 }, nil
218 } 218 }
  219 +
  220 +func (srv ExcelDataService) GetExcelDataFields(code string) (interface{}, error) {
  221 + dataFileds := []DataFieldOptions{}
  222 + switch code {
  223 + case domain.ExportCompanyUser:
  224 + dataFileds = (ExportCompanyUserData{}).AllFields()
  225 + case domain.ExportCooperationUser:
  226 + dataFileds = (ExportCooperationUserData{}).AllFields()
  227 + }
  228 + return dataFileds, nil
  229 +}
@@ -5,13 +5,22 @@ import ( @@ -5,13 +5,22 @@ import (
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
6 ) 6 )
7 7
  8 +type DataFieldOptions struct {
  9 + EnName string `json:"enName"`
  10 + CnName string `json:"cnName"`
  11 + IsDefault bool `json:"isDefault"`
  12 +}
  13 +
8 // ExportCompanyUserData 导出公司用户数据 14 // ExportCompanyUserData 导出公司用户数据
9 -type ExportCompanyUserData []allied_creation_user.UserDetail 15 +type ExportCompanyUserData struct {
  16 + SourceData []allied_creation_user.UserDetail
  17 + SelectedField []string
  18 +}
10 19
11 var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil) 20 var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
12 21
13 -func (data ExportCompanyUserData) DataFieldList() []excel.DataField {  
14 - return []excel.DataField{ 22 +func (data ExportCompanyUserData) AllFields() []DataFieldOptions {
  23 + return []DataFieldOptions{
15 {EnName: "UserCode", CnName: "用户编码"}, 24 {EnName: "UserCode", CnName: "用户编码"},
16 {EnName: "UserName", CnName: "用户姓名"}, 25 {EnName: "UserName", CnName: "用户姓名"},
17 {EnName: "Phone", CnName: "手机号"}, 26 {EnName: "Phone", CnName: "手机号"},
@@ -21,25 +30,42 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField { @@ -21,25 +30,42 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
21 } 30 }
22 } 31 }
23 32
  33 +func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
  34 + fields := []excel.DataField{}
  35 + allFields := data.AllFields()
  36 + for _, value2 := range allFields {
  37 + if len(data.SelectedField) == 0 || value2.IsDefault {
  38 + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
  39 + continue
  40 + }
  41 + for _, value3 := range data.SelectedField {
  42 + if value2.EnName == value3 {
  43 + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
  44 + }
  45 + }
  46 + }
  47 + return fields
  48 +}
  49 +
24 func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) { 50 func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {
25 if index > data.DataListLen() { 51 if index > data.DataListLen() {
26 return "" 52 return ""
27 } 53 }
28 switch enName { 54 switch enName {
29 case "UserCode": 55 case "UserCode":
30 - return data[index].UserCode 56 + return data.SourceData[index].UserCode
31 case "UserName": 57 case "UserName":
32 - return data[index].UserInfo.UserName 58 + return data.SourceData[index].UserInfo.UserName
33 case "Phone": 59 case "Phone":
34 - return data[index].UserInfo.Phone 60 + return data.SourceData[index].UserInfo.Phone
35 case "DepartmentName": 61 case "DepartmentName":
36 - if data[index].Department != nil {  
37 - return data[index].Department.DepartmentName 62 + if data.SourceData[index].Department != nil {
  63 + return data.SourceData[index].Department.DepartmentName
38 } else { 64 } else {
39 return "" 65 return ""
40 } 66 }
41 case "EnableStatus": 67 case "EnableStatus":
42 - status := data[index].EnableStatus 68 + status := data.SourceData[index].EnableStatus
43 statusName := "" 69 statusName := ""
44 // 状态(1:启用 2:禁用 3:注销) 70 // 状态(1:启用 2:禁用 3:注销)
45 switch status { 71 switch status {
@@ -52,8 +78,8 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int @@ -52,8 +78,8 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int
52 } 78 }
53 return statusName 79 return statusName
54 case "OrgName": 80 case "OrgName":
55 - if data[index].Org != nil {  
56 - return data[index].Org.OrgName 81 + if data.SourceData[index].Org != nil {
  82 + return data.SourceData[index].Org.OrgName
57 } else { 83 } else {
58 return "" 84 return ""
59 } 85 }
@@ -62,7 +88,7 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int @@ -62,7 +88,7 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int
62 } 88 }
63 89
64 func (data ExportCompanyUserData) DataListLen() int { 90 func (data ExportCompanyUserData) DataListLen() int {
65 - return len(data) 91 + return len(data.SourceData)
66 } 92 }
67 93
68 func (data ExportCompanyUserData) TableTitle() []string { 94 func (data ExportCompanyUserData) TableTitle() []string {
@@ -70,21 +96,39 @@ func (data ExportCompanyUserData) TableTitle() []string { @@ -70,21 +96,39 @@ func (data ExportCompanyUserData) TableTitle() []string {
70 } 96 }
71 97
72 //ExportCooperationUserData 导出共创用户数据 98 //ExportCooperationUserData 导出共创用户数据
73 -type ExportCooperationUserData []allied_creation_user.UserDetail 99 +type ExportCooperationUserData struct {
  100 + SourceData []allied_creation_user.UserDetail
  101 + SelectedField []string
  102 +}
74 103
75 var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil) 104 var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
76 105
77 -func (data ExportCooperationUserData) DataFieldList() []excel.DataField {  
78 - return []excel.DataField{ 106 +func (data ExportCooperationUserData) AllFields() []DataFieldOptions {
  107 + return []DataFieldOptions{
79 {EnName: "UserCode", CnName: "用户编码"}, 108 {EnName: "UserCode", CnName: "用户编码"},
80 {EnName: "UserName", CnName: "用户姓名"}, 109 {EnName: "UserName", CnName: "用户姓名"},
81 {EnName: "Phone", CnName: "手机号"}, 110 {EnName: "Phone", CnName: "手机号"},
82 {EnName: "CooperationCompany", CnName: "共创公司"}, 111 {EnName: "CooperationCompany", CnName: "共创公司"},
83 {EnName: "CooperationDeadline", CnName: "共创到期"}, 112 {EnName: "CooperationDeadline", CnName: "共创到期"},
84 {EnName: "EnableStatus", CnName: "状态"}, 113 {EnName: "EnableStatus", CnName: "状态"},
  114 + }
  115 +}
85 116
86 - //{EnName: "Email", CnName: "邮箱"}, 117 +func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
  118 + fields := []excel.DataField{}
  119 + allFields := data.AllFields()
  120 + for _, value2 := range allFields {
  121 + if len(data.SelectedField) == 0 || value2.IsDefault {
  122 + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
  123 + continue
  124 + }
  125 + for _, value3 := range data.SelectedField {
  126 + if value2.EnName == value3 {
  127 + fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
  128 + }
  129 + }
87 } 130 }
  131 + return fields
88 } 132 }
89 133
90 func (data ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) { 134 func (data ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) {
@@ -93,22 +137,22 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value @@ -93,22 +137,22 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
93 } 137 }
94 switch enName { 138 switch enName {
95 case "UserCode": 139 case "UserCode":
96 - return data[index].UserCode 140 + return data.SourceData[index].UserCode
97 case "UserName": 141 case "UserName":
98 - return data[index].UserInfo.UserName 142 + return data.SourceData[index].UserInfo.UserName
99 case "CooperationCompany": 143 case "CooperationCompany":
100 - return data[index].CooperationInfo.CooperationCompany 144 + return data.SourceData[index].CooperationInfo.CooperationCompany
101 case "CooperationDeadline": 145 case "CooperationDeadline":
102 - if data[index].CooperationInfo.CooperationDeadline.IsZero() || data[index].CooperationInfo.CooperationDeadline.Unix() == 0 { 146 + if data.SourceData[index].CooperationInfo.CooperationDeadline.IsZero() || data.SourceData[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
103 return "" 147 return ""
104 } 148 }
105 - return data[index].CooperationInfo.CooperationDeadline.Format("2006-01-02") 149 + return data.SourceData[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
106 case "Phone": 150 case "Phone":
107 - return data[index].UserInfo.Phone 151 + return data.SourceData[index].UserInfo.Phone
108 case "Email": 152 case "Email":
109 - return data[index].UserInfo.Email 153 + return data.SourceData[index].UserInfo.Email
110 case "EnableStatus": 154 case "EnableStatus":
111 - status := data[index].EnableStatus 155 + status := data.SourceData[index].EnableStatus
112 statusName := "" 156 statusName := ""
113 // 状态(1:启用 2:禁用 3:注销) 157 // 状态(1:启用 2:禁用 3:注销)
114 switch status { 158 switch status {
@@ -125,7 +169,7 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value @@ -125,7 +169,7 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
125 } 169 }
126 170
127 func (data ExportCooperationUserData) DataListLen() int { 171 func (data ExportCooperationUserData) DataListLen() int {
128 - return len(data) 172 + return len(data.SourceData)
129 } 173 }
130 174
131 func (data ExportCooperationUserData) TableTitle() []string { 175 func (data ExportCooperationUserData) TableTitle() []string {
@@ -32,55 +32,12 @@ func (controller *ReverseProxyController) SuplusSaleApp() { @@ -32,55 +32,12 @@ func (controller *ReverseProxyController) SuplusSaleApp() {
32 panic(err) 32 panic(err)
33 } 33 }
34 controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/suplus-sale-app", "", 1) 34 controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/suplus-sale-app", "", 1)
35 - targetQuery := target.RawQuery  
36 - directorFunc := func(req *http.Request) {  
37 - req.Host = target.Host  
38 - req.URL.Scheme = target.Scheme  
39 - req.URL.Host = target.Host  
40 - req.URL.Path, req.URL.RawPath = joinURLPath(target, controller.Ctx.Request.URL)  
41 - if targetQuery == "" || req.URL.RawQuery == "" {  
42 - req.URL.RawQuery = targetQuery + req.URL.RawQuery  
43 - } else {  
44 - req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery  
45 - }  
46 - if _, ok := req.Header["User-Agent"]; !ok {  
47 - // explicitly disable User-Agent so it's not set to default value  
48 - req.Header.Set("User-Agent", "")  
49 - } 35 + newProxy := httputil.NewSingleHostReverseProxy(target)
  36 + directorFunc := newProxy.Director
  37 + newDirectorFunc := func(r *http.Request) {
  38 + directorFunc(r)
  39 + r.Host = target.Host
50 } 40 }
51 - newProxy := &httputil.ReverseProxy{Director: directorFunc} 41 + newProxy.Director = newDirectorFunc
52 newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request) 42 newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request)
53 } 43 }
54 -  
55 -func joinURLPath(a, b *url.URL) (path, rawpath string) {  
56 - if a.RawPath == "" && b.RawPath == "" {  
57 - return singleJoiningSlash(a.Path, b.Path), ""  
58 - }  
59 - // Same as singleJoiningSlash, but uses EscapedPath to determine  
60 - // whether a slash should be added  
61 - apath := a.EscapedPath()  
62 - bpath := b.EscapedPath()  
63 -  
64 - aslash := strings.HasSuffix(apath, "/")  
65 - bslash := strings.HasPrefix(bpath, "/")  
66 -  
67 - switch {  
68 - case aslash && bslash:  
69 - return a.Path + b.Path[1:], apath + bpath[1:]  
70 - case !aslash && !bslash:  
71 - return a.Path + "/" + b.Path, apath + "/" + bpath  
72 - }  
73 - return a.Path + b.Path, apath + bpath  
74 -}  
75 -  
76 -func singleJoiningSlash(a, b string) string {  
77 - aslash := strings.HasSuffix(a, "/")  
78 - bslash := strings.HasPrefix(b, "/")  
79 - switch {  
80 - case aslash && bslash:  
81 - return a + b[1:]  
82 - case !aslash && !bslash:  
83 - return a + "/" + b  
84 - }  
85 - return a + b  
86 -}  
@@ -46,11 +46,11 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin @@ -46,11 +46,11 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin
46 } 46 }
47 47
48 // ImportDividendsOrder 导入分红订单 48 // ImportDividendsOrder 导入分红订单
49 -func (controller ExcelDataController) ImportDividendsOrder() { 49 +func (controller *ExcelDataController) ImportDividendsOrder() {
50 importDividendsOrder(controller) 50 importDividendsOrder(controller)
51 } 51 }
52 52
53 -func importDividendsOrder(controller ExcelDataController) { 53 +func importDividendsOrder(controller *ExcelDataController) {
54 54
55 fileReader, err := controller.GetExcelFile() 55 fileReader, err := controller.GetExcelFile()
56 if err != nil { 56 if err != nil {
@@ -109,11 +109,11 @@ func importDividendsOrder(controller ExcelDataController) { @@ -109,11 +109,11 @@ func importDividendsOrder(controller ExcelDataController) {
109 } 109 }
110 110
111 // ImportDividendsReturnedOrder 导入分红退货单 111 // ImportDividendsReturnedOrder 导入分红退货单
112 -func (controller ExcelDataController) ImportDividendsReturnedOrder() { 112 +func (controller *ExcelDataController) ImportDividendsReturnedOrder() {
113 importDividendsReturnedOrder(controller) 113 importDividendsReturnedOrder(controller)
114 } 114 }
115 115
116 -func importDividendsReturnedOrder(controller ExcelDataController) { 116 +func importDividendsReturnedOrder(controller *ExcelDataController) {
117 117
118 fileReader, err := controller.GetExcelFile() 118 fileReader, err := controller.GetExcelFile()
119 if err != nil { 119 if err != nil {
@@ -172,7 +172,7 @@ func importDividendsReturnedOrder(controller ExcelDataController) { @@ -172,7 +172,7 @@ func importDividendsReturnedOrder(controller ExcelDataController) {
172 } 172 }
173 173
174 // FileImport 文件导入 174 // FileImport 文件导入
175 -func (controller ExcelDataController) FileImport() { 175 +func (controller *ExcelDataController) FileImport() {
176 code := controller.GetString("code") 176 code := controller.GetString("code")
177 switch code { 177 switch code {
178 case domain.ImportDividendsOrders: 178 case domain.ImportDividendsOrders:
@@ -184,7 +184,7 @@ func (controller ExcelDataController) FileImport() { @@ -184,7 +184,7 @@ func (controller ExcelDataController) FileImport() {
184 } 184 }
185 } 185 }
186 186
187 -func defaultImport(controller ExcelDataController) { 187 +func defaultImport(controller *ExcelDataController) {
188 var ( 188 var (
189 data interface{} 189 data interface{}
190 err error 190 err error
@@ -213,7 +213,7 @@ func defaultImport(controller ExcelDataController) { @@ -213,7 +213,7 @@ func defaultImport(controller ExcelDataController) {
213 controller.Response(data, err) 213 controller.Response(data, err)
214 } 214 }
215 215
216 -func (controller ExcelDataController) FileImportTemplate() { 216 +func (controller *ExcelDataController) FileImportTemplate() {
217 excelService := service.NewExcelDataService(nil) 217 excelService := service.NewExcelDataService(nil)
218 cmd := &command.ImportDataCommand{} 218 cmd := &command.ImportDataCommand{}
219 code := controller.GetString(":code") 219 code := controller.GetString(":code")
@@ -224,11 +224,11 @@ func (controller ExcelDataController) FileImportTemplate() { @@ -224,11 +224,11 @@ func (controller ExcelDataController) FileImportTemplate() {
224 } 224 }
225 225
226 // FileExport 文件导出 226 // FileExport 文件导出
227 -func (controller ExcelDataController) FileExport() { 227 +func (controller *ExcelDataController) FileExport() {
228 fileExport(controller, "") 228 fileExport(controller, "")
229 } 229 }
230 230
231 -func fileExport(controller ExcelDataController, code string) { 231 +func fileExport(controller *ExcelDataController, code string) {
232 // 1.读取command 232 // 1.读取command
233 exportDataCommand := &command.ExportDataCommand{} 233 exportDataCommand := &command.ExportDataCommand{}
234 err := controller.Unmarshal(exportDataCommand) 234 err := controller.Unmarshal(exportDataCommand)
@@ -280,11 +280,16 @@ func fileExport(controller ExcelDataController, code string) { @@ -280,11 +280,16 @@ func fileExport(controller ExcelDataController, code string) {
280 } 280 }
281 281
282 // ExportCompanyUser 导出公司用户 282 // ExportCompanyUser 导出公司用户
283 -func (controller ExcelDataController) ExportCompanyUser() { 283 +func (controller *ExcelDataController) ExportCompanyUser() {
284 fileExport(controller, domain.ExportCompanyUser) 284 fileExport(controller, domain.ExportCompanyUser)
285 } 285 }
286 286
287 // ExportCooperationUser 导出共创用户 287 // ExportCooperationUser 导出共创用户
288 -func (controller ExcelDataController) ExportCooperationUser() { 288 +func (controller *ExcelDataController) ExportCooperationUser() {
289 fileExport(controller, domain.ExportCooperationUser) 289 fileExport(controller, domain.ExportCooperationUser)
290 } 290 }
  291 +
  292 +//GetExcelDataFields 获取导出excel数据的可选字段
  293 +func (controller *ExcelDataController) GetExcelDataFields() {
  294 +
  295 +}
@@ -9,4 +9,6 @@ func init() { @@ -9,4 +9,6 @@ func init() {
9 9
10 /***** 转发销售导航的请求*****/ 10 /***** 转发销售导航的请求*****/
11 web.Router("/suplus-sale-app/v1/platform/district", &mobile_client.ReverseProxyController{}, "post:SuplusSaleApp") 11 web.Router("/suplus-sale-app/v1/platform/district", &mobile_client.ReverseProxyController{}, "post:SuplusSaleApp")
  12 + web.Router("/suplus-sale-app/v1/platform/page", &mobile_client.ReverseProxyController{}, "post:SuplusSaleApp")
  13 +
12 } 14 }