作者 tangxuhui

Merge branch 'dev' into test

... ... @@ -10,5 +10,6 @@ type CompanyUserListQuery struct {
//所属部门
DepartmentName string `json:"departmentName"`
//操作人
Operator domain.Operator `json:"-"`
Operator domain.Operator `json:"-"`
SelectedField []string `json:"selectedField"`
}
... ...
... ... @@ -10,5 +10,6 @@ type CooperationUserListQuery struct {
//用户名称
UserName string `json:"userName"`
//共创公司
CooperationCompany string `json:"cooperationCompany"`
CooperationCompany string `json:"cooperationCompany"`
SelectedField []string `json:"selectedField"`
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"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
if err != nil {
return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
return ExportCompanyUserData(result.Users), nil
return ExportCompanyUserData{
SourceData: result.Users,
SelectedField: companyUserListQuery.SelectedField,
}, nil
}
// ExportCooperationUser 导出共创用户信息列表
... ... @@ -45,5 +49,5 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co
if err != nil {
return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
return ExportCooperationUserData(result.Users), nil
return ExportCooperationUserData{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil
}
... ...
... ... @@ -216,3 +216,14 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import
"url": url,
}, nil
}
func (srv ExcelDataService) GetExcelDataFields(code string) (interface{}, error) {
dataFileds := []DataFieldOptions{}
switch code {
case domain.ExportCompanyUser:
dataFileds = (ExportCompanyUserData{}).AllFields()
case domain.ExportCooperationUser:
dataFileds = (ExportCooperationUserData{}).AllFields()
}
return dataFileds, nil
}
... ...
... ... @@ -5,13 +5,22 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
type DataFieldOptions struct {
EnName string `json:"enName"`
CnName string `json:"cnName"`
IsDefault bool `json:"isDefault"`
}
// ExportCompanyUserData 导出公司用户数据
type ExportCompanyUserData []allied_creation_user.UserDetail
type ExportCompanyUserData struct {
SourceData []allied_creation_user.UserDetail
SelectedField []string
}
var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
return []excel.DataField{
func (data ExportCompanyUserData) AllFields() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
{EnName: "Phone", CnName: "手机号"},
... ... @@ -21,25 +30,42 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
}
}
func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
fields := []excel.DataField{}
allFields := data.AllFields()
for _, value2 := range allFields {
if len(data.SelectedField) == 0 || value2.IsDefault {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
continue
}
for _, value3 := range data.SelectedField {
if value2.EnName == value3 {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
}
}
}
return fields
}
func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {
if index > data.DataListLen() {
return ""
}
switch enName {
case "UserCode":
return data[index].UserCode
return data.SourceData[index].UserCode
case "UserName":
return data[index].UserInfo.UserName
return data.SourceData[index].UserInfo.UserName
case "Phone":
return data[index].UserInfo.Phone
return data.SourceData[index].UserInfo.Phone
case "DepartmentName":
if data[index].Department != nil {
return data[index].Department.DepartmentName
if data.SourceData[index].Department != nil {
return data.SourceData[index].Department.DepartmentName
} else {
return ""
}
case "EnableStatus":
status := data[index].EnableStatus
status := data.SourceData[index].EnableStatus
statusName := ""
// 状态(1:启用 2:禁用 3:注销)
switch status {
... ... @@ -52,8 +78,8 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int
}
return statusName
case "OrgName":
if data[index].Org != nil {
return data[index].Org.OrgName
if data.SourceData[index].Org != nil {
return data.SourceData[index].Org.OrgName
} else {
return ""
}
... ... @@ -62,7 +88,7 @@ func (data ExportCompanyUserData) CellValue(index int, enName string) (value int
}
func (data ExportCompanyUserData) DataListLen() int {
return len(data)
return len(data.SourceData)
}
func (data ExportCompanyUserData) TableTitle() []string {
... ... @@ -70,21 +96,39 @@ func (data ExportCompanyUserData) TableTitle() []string {
}
//ExportCooperationUserData 导出共创用户数据
type ExportCooperationUserData []allied_creation_user.UserDetail
type ExportCooperationUserData struct {
SourceData []allied_creation_user.UserDetail
SelectedField []string
}
var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
return []excel.DataField{
func (data ExportCooperationUserData) AllFields() []DataFieldOptions {
return []DataFieldOptions{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
{EnName: "Phone", CnName: "手机号"},
{EnName: "CooperationCompany", CnName: "共创公司"},
{EnName: "CooperationDeadline", CnName: "共创到期"},
{EnName: "EnableStatus", CnName: "状态"},
}
}
//{EnName: "Email", CnName: "邮箱"},
func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
fields := []excel.DataField{}
allFields := data.AllFields()
for _, value2 := range allFields {
if len(data.SelectedField) == 0 || value2.IsDefault {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
continue
}
for _, value3 := range data.SelectedField {
if value2.EnName == value3 {
fields = append(fields, excel.DataField{EnName: value2.EnName, CnName: value2.CnName})
}
}
}
return fields
}
func (data ExportCooperationUserData) CellValue(index int, enName string) (value interface{}) {
... ... @@ -93,22 +137,22 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
}
switch enName {
case "UserCode":
return data[index].UserCode
return data.SourceData[index].UserCode
case "UserName":
return data[index].UserInfo.UserName
return data.SourceData[index].UserInfo.UserName
case "CooperationCompany":
return data[index].CooperationInfo.CooperationCompany
return data.SourceData[index].CooperationInfo.CooperationCompany
case "CooperationDeadline":
if data[index].CooperationInfo.CooperationDeadline.IsZero() || data[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
if data.SourceData[index].CooperationInfo.CooperationDeadline.IsZero() || data.SourceData[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
return ""
}
return data[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
return data.SourceData[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
case "Phone":
return data[index].UserInfo.Phone
return data.SourceData[index].UserInfo.Phone
case "Email":
return data[index].UserInfo.Email
return data.SourceData[index].UserInfo.Email
case "EnableStatus":
status := data[index].EnableStatus
status := data.SourceData[index].EnableStatus
statusName := ""
// 状态(1:启用 2:禁用 3:注销)
switch status {
... ... @@ -125,7 +169,7 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
}
func (data ExportCooperationUserData) DataListLen() int {
return len(data)
return len(data.SourceData)
}
func (data ExportCooperationUserData) TableTitle() []string {
... ...
... ... @@ -32,55 +32,12 @@ func (controller *ReverseProxyController) SuplusSaleApp() {
panic(err)
}
controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/suplus-sale-app", "", 1)
targetQuery := target.RawQuery
directorFunc := func(req *http.Request) {
req.Host = target.Host
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
req.URL.Path, req.URL.RawPath = joinURLPath(target, controller.Ctx.Request.URL)
if targetQuery == "" || req.URL.RawQuery == "" {
req.URL.RawQuery = targetQuery + req.URL.RawQuery
} else {
req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery
}
if _, ok := req.Header["User-Agent"]; !ok {
// explicitly disable User-Agent so it's not set to default value
req.Header.Set("User-Agent", "")
}
newProxy := httputil.NewSingleHostReverseProxy(target)
directorFunc := newProxy.Director
newDirectorFunc := func(r *http.Request) {
directorFunc(r)
r.Host = target.Host
}
newProxy := &httputil.ReverseProxy{Director: directorFunc}
newProxy.Director = newDirectorFunc
newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request)
}
func joinURLPath(a, b *url.URL) (path, rawpath string) {
if a.RawPath == "" && b.RawPath == "" {
return singleJoiningSlash(a.Path, b.Path), ""
}
// Same as singleJoiningSlash, but uses EscapedPath to determine
// whether a slash should be added
apath := a.EscapedPath()
bpath := b.EscapedPath()
aslash := strings.HasSuffix(apath, "/")
bslash := strings.HasPrefix(bpath, "/")
switch {
case aslash && bslash:
return a.Path + b.Path[1:], apath + bpath[1:]
case !aslash && !bslash:
return a.Path + "/" + b.Path, apath + "/" + bpath
}
return a.Path + b.Path, apath + bpath
}
func singleJoiningSlash(a, b string) string {
aslash := strings.HasSuffix(a, "/")
bslash := strings.HasPrefix(b, "/")
switch {
case aslash && bslash:
return a + b[1:]
case !aslash && !bslash:
return a + "/" + b
}
return a + b
}
... ...
... ... @@ -46,11 +46,11 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin
}
// ImportDividendsOrder 导入分红订单
func (controller ExcelDataController) ImportDividendsOrder() {
func (controller *ExcelDataController) ImportDividendsOrder() {
importDividendsOrder(controller)
}
func importDividendsOrder(controller ExcelDataController) {
func importDividendsOrder(controller *ExcelDataController) {
fileReader, err := controller.GetExcelFile()
if err != nil {
... ... @@ -109,11 +109,11 @@ func importDividendsOrder(controller ExcelDataController) {
}
// ImportDividendsReturnedOrder 导入分红退货单
func (controller ExcelDataController) ImportDividendsReturnedOrder() {
func (controller *ExcelDataController) ImportDividendsReturnedOrder() {
importDividendsReturnedOrder(controller)
}
func importDividendsReturnedOrder(controller ExcelDataController) {
func importDividendsReturnedOrder(controller *ExcelDataController) {
fileReader, err := controller.GetExcelFile()
if err != nil {
... ... @@ -172,7 +172,7 @@ func importDividendsReturnedOrder(controller ExcelDataController) {
}
// FileImport 文件导入
func (controller ExcelDataController) FileImport() {
func (controller *ExcelDataController) FileImport() {
code := controller.GetString("code")
switch code {
case domain.ImportDividendsOrders:
... ... @@ -184,7 +184,7 @@ func (controller ExcelDataController) FileImport() {
}
}
func defaultImport(controller ExcelDataController) {
func defaultImport(controller *ExcelDataController) {
var (
data interface{}
err error
... ... @@ -213,7 +213,7 @@ func defaultImport(controller ExcelDataController) {
controller.Response(data, err)
}
func (controller ExcelDataController) FileImportTemplate() {
func (controller *ExcelDataController) FileImportTemplate() {
excelService := service.NewExcelDataService(nil)
cmd := &command.ImportDataCommand{}
code := controller.GetString(":code")
... ... @@ -224,11 +224,11 @@ func (controller ExcelDataController) FileImportTemplate() {
}
// FileExport 文件导出
func (controller ExcelDataController) FileExport() {
func (controller *ExcelDataController) FileExport() {
fileExport(controller, "")
}
func fileExport(controller ExcelDataController, code string) {
func fileExport(controller *ExcelDataController, code string) {
// 1.读取command
exportDataCommand := &command.ExportDataCommand{}
err := controller.Unmarshal(exportDataCommand)
... ... @@ -280,11 +280,16 @@ func fileExport(controller ExcelDataController, code string) {
}
// ExportCompanyUser 导出公司用户
func (controller ExcelDataController) ExportCompanyUser() {
func (controller *ExcelDataController) ExportCompanyUser() {
fileExport(controller, domain.ExportCompanyUser)
}
// ExportCooperationUser 导出共创用户
func (controller ExcelDataController) ExportCooperationUser() {
func (controller *ExcelDataController) ExportCooperationUser() {
fileExport(controller, domain.ExportCooperationUser)
}
//GetExcelDataFields 获取导出excel数据的可选字段
func (controller *ExcelDataController) GetExcelDataFields() {
}
... ...
... ... @@ -9,4 +9,6 @@ func init() {
/***** 转发销售导航的请求*****/
web.Router("/suplus-sale-app/v1/platform/district", &mobile_client.ReverseProxyController{}, "post:SuplusSaleApp")
web.Router("/suplus-sale-app/v1/platform/page", &mobile_client.ReverseProxyController{}, "post:SuplusSaleApp")
}
... ...