作者 yangfu

导入用户

  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/beego/beego/v2/core/validation"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  7 + "io"
  8 +)
  9 +
  10 +type ImportDataCommand struct {
  11 + //操作人
  12 + Operator domain.Operator `json:"-"`
  13 + Reader io.Reader `json:"-"`
  14 +}
  15 +
  16 +func (importDataCommand *ImportDataCommand) Valid(validation *validation.Validation) {
  17 +
  18 +}
  19 +
  20 +func (importDataCommand *ImportDataCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(importDataCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + for _, validErr := range valid.Errors {
  28 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  29 + }
  30 + }
  31 + return nil
  32 +}
@@ -2,10 +2,14 @@ package service @@ -2,10 +2,14 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - 5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/excel"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
8 "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"
  11 + "strconv"
  12 + "time"
9 ) 13 )
10 14
11 type ExcelDataService struct { 15 type ExcelDataService struct {
@@ -15,7 +19,7 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService { @@ -15,7 +19,7 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService {
15 return &ExcelDataService{} 19 return &ExcelDataService{}
16 } 20 }
17 21
18 -// 导出公司用户信息列表 22 +// ExportCompanyUser 导出公司用户信息列表
19 func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) { 23 func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
20 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator) 24 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
21 result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ 25 result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
@@ -35,7 +39,7 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan @@ -35,7 +39,7 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan
35 return ExportCompanyUserData(result.Users), nil 39 return ExportCompanyUserData(result.Users), nil
36 } 40 }
37 41
38 -// 导出共创用户信息列表 42 +// ExportCooperationUser 导出共创用户信息列表
39 func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) { 43 func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) {
40 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator) 44 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
41 result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ 45 result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
@@ -54,3 +58,107 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co @@ -54,3 +58,107 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co
54 } 58 }
55 return ExportCooperationUserData(result.Users), nil 59 return ExportCooperationUserData(result.Users), nil
56 } 60 }
  61 +
  62 +// ImportCompanyUser 导入公司用户信息
  63 +func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  64 + excelImport := excel.NewExcelImport()
  65 + excelImport.RowBegin = 2 //第二行开始读取
  66 + excelImport.DataFields = []excel.DataField{
  67 + {EnName: "UserCode", CnName: "*用户编号"},
  68 + {EnName: "UserName", CnName: "*用户姓名"},
  69 + {EnName: "OrganizationID", CnName: "*组织机构"},
  70 + {EnName: "DepartmentID", CnName: "*所属部门"},
  71 + {EnName: "Phone", CnName: "*手机号"},
  72 + {EnName: "Email", CnName: "邮箱"},
  73 + }
  74 + excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  75 + if err != nil {
  76 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  77 + }
  78 + users := make([]allied_creation_user.BatchAddUserItem, 0)
  79 + var fail int
  80 + for _, v := range excelData {
  81 + item := allied_creation_user.BatchAddUserItem{
  82 + CompanyID: importDataCommand.Operator.CompanyId,
  83 + UserType: domain.UserTypeEmployee,
  84 + UserCode: v["UserCode"],
  85 + OrganizationID: 0,
  86 + DepartmentID: 0,
  87 + UserInfo: allied_creation_user.BatchAddUserItemUserInfo{
  88 + UserName: v["UserName"],
  89 + Phone: v["Phone"],
  90 + Email: v["Email"],
  91 + },
  92 + CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{},
  93 + }
  94 + item.OrganizationID, err = strconv.Atoi(v["OrganizationID"])
  95 + if err != nil {
  96 + fail++
  97 + continue
  98 + }
  99 + item.DepartmentID, err = strconv.Atoi(v["DepartmentID"])
  100 + if err != nil {
  101 + fail++
  102 + continue
  103 + }
  104 + users = append(users, item)
  105 + }
  106 + userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
  107 + result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
  108 + Users: users,
  109 + })
  110 + if err != nil {
  111 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  112 + }
  113 + return result, nil
  114 +}
  115 +
  116 +// ImportCooperationUser 导入共创用户信息
  117 +func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  118 + excelImport := excel.NewExcelImport()
  119 + excelImport.RowBegin = 2 //第二行开始读取
  120 + excelImport.DataFields = []excel.DataField{
  121 + {EnName: "UserCode", CnName: "*用户编号"},
  122 + {EnName: "UserName", CnName: "*用户姓名"},
  123 + {EnName: "CooperationCompany", CnName: "*合伙公司"},
  124 + {EnName: "CooperationDeadline", CnName: "*合伙到期"},
  125 + {EnName: "Phone", CnName: "*手机号"},
  126 + {EnName: "Email", CnName: "邮箱"},
  127 + }
  128 + excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  129 + if err != nil {
  130 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  131 + }
  132 + users := make([]allied_creation_user.BatchAddUserItem, 0)
  133 + var fail int
  134 + for _, v := range excelData {
  135 + item := allied_creation_user.BatchAddUserItem{
  136 + CompanyID: importDataCommand.Operator.CompanyId,
  137 + UserType: domain.UserTypeCooperation,
  138 + UserCode: v["UserCode"],
  139 + OrganizationID: int(importDataCommand.Operator.OrgId),
  140 + UserInfo: allied_creation_user.BatchAddUserItemUserInfo{
  141 + UserName: v["UserName"],
  142 + Phone: v["Phone"],
  143 + Email: v["Email"],
  144 + },
  145 + CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{
  146 + CooperationCompany: v["CooperationCompany"],
  147 + },
  148 + }
  149 + item.CooperationInfo.CooperationDeadline, err = time.Parse("2006-01-02", v["CooperationDeadline"])
  150 + if err != nil {
  151 + fail++
  152 + continue
  153 + }
  154 + users = append(users, item)
  155 + }
  156 + userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
  157 + result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
  158 + Users: users,
  159 + })
  160 + if err != nil {
  161 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  162 + }
  163 + return result, nil
  164 +}
@@ -349,20 +349,22 @@ type ( @@ -349,20 +349,22 @@ type (
349 } 349 }
350 350
351 BatchAddUserItem struct { 351 BatchAddUserItem struct {
352 - CompanyID int `json:"companyId"`  
353 - UserType int `json:"userType"`  
354 - UserCode string `json:"userCode"`  
355 - OrganizationID int `json:"organizationId"`  
356 - DepartmentID int `json:"departmentId"`  
357 - UserInfo struct {  
358 - Phone string `json:"phone"`  
359 - UserName string `json:"userName"`  
360 - Email string `json:"email"`  
361 - Avatar string `json:"avatar"`  
362 - } `json:"userInfo"`  
363 - CooperationInfo struct {  
364 - CooperationCompany string `json:"cooperationCompany"`  
365 - CooperationDeadline time.Time `json:"cooperationDeadline"`  
366 - } `json:"cooperationInfo"` 352 + CompanyID int64 `json:"companyId"`
  353 + UserType int `json:"userType"`
  354 + UserCode string `json:"userCode"`
  355 + OrganizationID int `json:"organizationId"`
  356 + DepartmentID int `json:"departmentId"`
  357 + UserInfo BatchAddUserItemUserInfo `json:"userInfo"`
  358 + CooperationInfo BatchAddUserItemCooperationInfo `json:"cooperationInfo"`
  359 + }
  360 + BatchAddUserItemUserInfo struct {
  361 + Phone string `json:"phone"`
  362 + UserName string `json:"userName"`
  363 + Email string `json:"email"`
  364 + Avatar string `json:"avatar"`
  365 + }
  366 + BatchAddUserItemCooperationInfo struct {
  367 + CooperationCompany string `json:"cooperationCompany"`
  368 + CooperationDeadline time.Time `json:"cooperationDeadline"`
367 } 369 }
368 ) 370 )
1 package controllers 1 package controllers
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
5 "github.com/linmadan/egglib-go/utils/json" 6 "github.com/linmadan/egglib-go/utils/json"
6 "github.com/linmadan/egglib-go/web/beego" 7 "github.com/linmadan/egglib-go/web/beego"
@@ -8,6 +9,8 @@ import ( @@ -8,6 +9,8 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware"
  12 + "io"
  13 + "path/filepath"
11 ) 14 )
12 15
13 type BaseController struct { 16 type BaseController struct {
@@ -108,6 +111,19 @@ func (controller *BaseController) BodyKeys() map[string]interface{} { @@ -108,6 +111,19 @@ func (controller *BaseController) BodyKeys() map[string]interface{} {
108 return bodyKV 111 return bodyKV
109 } 112 }
110 113
  114 +func (controller *BaseController) GetExcelFile() (io.Reader, error) {
  115 + excelFile, fileHeader, err := controller.GetFile("file")
  116 + if err != nil {
  117 + log.Logger.Error(err.Error())
  118 + return nil, fmt.Errorf("上传文件不存在")
  119 + }
  120 + ext := filepath.Ext(fileHeader.Filename)
  121 + if !(ext == "xlsx" || ext == "xls") {
  122 + return nil, fmt.Errorf("仅支持上传文件格式 xls/xlsx")
  123 + }
  124 + return excelFile, nil
  125 +}
  126 +
111 func Must(err error) { 127 func Must(err error) {
112 if err != nil { 128 if err != nil {
113 log.Logger.Error(err.Error()) 129 log.Logger.Error(err.Error())
1 -package web_client  
2 -  
3 -import (  
4 - "path/filepath"  
5 -  
6 - "github.com/beego/beego/v2/server/web/context"  
7 - "github.com/linmadan/egglib-go/utils/excel"  
8 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"  
9 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"  
10 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"  
11 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"  
12 -)  
13 -  
14 -type ExcelDataController struct {  
15 - baseController  
16 -}  
17 -  
18 -func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {  
19 - ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)  
20 - ctx.Output.Header("Content-Description", "File Transfer")  
21 - ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")  
22 - ctx.Output.Header("Content-Transfer-Encoding", "binary")  
23 - ctx.Output.Header("Expires", "0")  
24 - ctx.Output.Header("Cache-Control", "must-revalidate")  
25 - ctx.Output.Header("Pragma", "public")  
26 - //跳过保存文件,直接写入ctx.ResponseWriter  
27 - excelExport.ExcelFile.Write(ctx.ResponseWriter)  
28 - return nil  
29 -}  
30 -  
31 -//导出公司用户  
32 -func (controller ExcelDataController) ExportCompanyUser() {  
33 - excelService := service.NewExcelDataService(nil)  
34 - companyUserListQuery := &query.CompanyUserListQuery{}  
35 - err := controller.Unmarshal(companyUserListQuery)  
36 - if err != nil {  
37 - log.Logger.Debug("json err:" + err.Error())  
38 - controller.Response(nil, err)  
39 - return  
40 - }  
41 - companyUserListQuery.Operator = controller.GetOperator()  
42 - data, err := excelService.ExportCompanyUser(companyUserListQuery)  
43 - if err != nil {  
44 - log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())  
45 - controller.Response(nil, err)  
46 - return  
47 - }  
48 - excelTool := excel.NewExcelExport()  
49 - err = excelTool.ExportData(data, "")  
50 - if err != nil {  
51 - log.Logger.Debug("excelTool.ExportData err:" + err.Error())  
52 - controller.Response(nil, err)  
53 - return  
54 - }  
55 - controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")  
56 -}  
57 -  
58 -//导出共创用户  
59 -func (controller ExcelDataController) ExportCooperationUser() {  
60 - excelService := service.NewExcelDataService(nil)  
61 - companyUserListQuery := &query.CompanyUserListQuery{}  
62 - err := controller.Unmarshal(companyUserListQuery)  
63 - if err != nil {  
64 - log.Logger.Debug("json err:" + err.Error())  
65 - controller.Response(nil, err)  
66 - return  
67 - }  
68 - companyUserListQuery.Operator = controller.GetOperator()  
69 - data, err := excelService.ExportCooperationUser(companyUserListQuery)  
70 - if err != nil {  
71 - log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())  
72 - controller.Response(nil, err)  
73 - return  
74 - }  
75 - excelTool := excel.NewExcelExport()  
76 - err = excelTool.ExportData(data, "")  
77 - if err != nil {  
78 - log.Logger.Debug("excelTool.ExportData err:" + err.Error())  
79 - controller.Response(nil, err)  
80 - return  
81 - }  
82 - controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")  
83 -}  
84 -  
85 -func (controller ExcelDataController) ImportDividendsReturnedOrder() {  
86 - excelFile, fileHeader, err := controller.GetFile("file")  
87 - if err != nil {  
88 - log.Logger.Error("接收文件失败," + err.Error())  
89 - controller.Response(nil, err)  
90 - return  
91 - }  
92 - if filepath.Ext(fileHeader.Filename) == "" {  
93 - //TODO 判断文件类型  
94 - log.Logger.Error("获取到的文件:" + fileHeader.Filename)  
95 - }  
96 - excelImport := excel.NewExcelImport()  
97 - excelImport.RowBegin = 2 //第二行开始读取  
98 - excelImport.DataFields = []excel.DataField{  
99 - {EnName: "OriginalOrderNum", CnName: "*来源源单号"},  
100 - {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},  
101 - {EnName: "OrderGoodName", CnName: "*产品名称"},  
102 - {EnName: "DividendsReturnedDate", CnName: "*退货日期"},  
103 - {EnName: "OrderTime", CnName: "*订单日期"},  
104 - {EnName: "RegionName", CnName: "*退货区域"},  
105 - {EnName: "OrderGoodQuantity", CnName: "*退货数量"},  
106 - {EnName: "OrderGoodPrice", CnName: "*退货价格"},  
107 - {EnName: "CooperationContractNumber", CnName: "项目合约编号"},  
108 - }  
109 - excelData, err := excelImport.OpenExcelFromIoReader(excelFile)  
110 - if err != nil {  
111 - log.Logger.Error("解析excel文件失败," + err.Error())  
112 - controller.Response(nil, err)  
113 - return  
114 - }  
115 - //退货单数据  
116 - returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{}  
117 - for _, v := range excelData {  
118 - //TODO 按需转化  
119 - item := allied_creation_cooperation.ImportDividendsReturnedOrderData{  
120 - OriginalOrderNum: v["OriginalOrderNum"],  
121 - DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],  
122 - OrderGoodName: v["OrderGoodName"],  
123 - DividendsReturnedDate: v["DividendsReturnedDate"],  
124 - OrderTime: v["OrderTime"],  
125 - RegionName: v["RegionName"],  
126 - OrderGoodQuantity: v["OrderGoodQuantity"],  
127 - OrderGoodPrice: v["OrderGoodPrice"],  
128 - CooperationContractNumber: v["CooperationContractNumber"],  
129 - }  
130 - returnedOrderData = append(returnedOrderData, item)  
131 - }  
132 - creationCooperationGate := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(controller.GetOperator())  
133 - result, err := creationCooperationGate.ImportDividendsReturnedOrder(allied_creation_cooperation.ReqImportDividendsReturnedOrder{  
134 - DividendsReturnedOrderData: returnedOrderData,  
135 - })  
136 - if err != nil {  
137 - controller.Response(nil, err)  
138 - return  
139 - }  
140 - controller.Response(result, nil)  
141 -} 1 +package web_client
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
  5 + "path/filepath"
  6 +
  7 + "github.com/beego/beego/v2/server/web/context"
  8 + "github.com/linmadan/egglib-go/utils/excel"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
  13 +)
  14 +
  15 +type ExcelDataController struct {
  16 + baseController
  17 +}
  18 +
  19 +func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {
  20 + ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)
  21 + ctx.Output.Header("Content-Description", "File Transfer")
  22 + ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  23 + ctx.Output.Header("Content-Transfer-Encoding", "binary")
  24 + ctx.Output.Header("Expires", "0")
  25 + ctx.Output.Header("Cache-Control", "must-revalidate")
  26 + ctx.Output.Header("Pragma", "public")
  27 + //跳过保存文件,直接写入ctx.ResponseWriter
  28 + excelExport.ExcelFile.Write(ctx.ResponseWriter)
  29 + return nil
  30 +}
  31 +
  32 +//导出公司用户
  33 +func (controller ExcelDataController) ExportCompanyUser() {
  34 + excelService := service.NewExcelDataService(nil)
  35 + companyUserListQuery := &query.CompanyUserListQuery{}
  36 + err := controller.Unmarshal(companyUserListQuery)
  37 + if err != nil {
  38 + log.Logger.Debug("json err:" + err.Error())
  39 + controller.Response(nil, err)
  40 + return
  41 + }
  42 + companyUserListQuery.Operator = controller.GetOperator()
  43 + data, err := excelService.ExportCompanyUser(companyUserListQuery)
  44 + if err != nil {
  45 + log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
  46 + controller.Response(nil, err)
  47 + return
  48 + }
  49 + excelTool := excel.NewExcelExport()
  50 + err = excelTool.ExportData(data, "")
  51 + if err != nil {
  52 + log.Logger.Debug("excelTool.ExportData err:" + err.Error())
  53 + controller.Response(nil, err)
  54 + return
  55 + }
  56 + controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
  57 +}
  58 +
  59 +//导出共创用户
  60 +func (controller ExcelDataController) ExportCooperationUser() {
  61 + excelService := service.NewExcelDataService(nil)
  62 + companyUserListQuery := &query.CompanyUserListQuery{}
  63 + err := controller.Unmarshal(companyUserListQuery)
  64 + if err != nil {
  65 + log.Logger.Debug("json err:" + err.Error())
  66 + controller.Response(nil, err)
  67 + return
  68 + }
  69 + companyUserListQuery.Operator = controller.GetOperator()
  70 + data, err := excelService.ExportCooperationUser(companyUserListQuery)
  71 + if err != nil {
  72 + log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
  73 + controller.Response(nil, err)
  74 + return
  75 + }
  76 + excelTool := excel.NewExcelExport()
  77 + err = excelTool.ExportData(data, "")
  78 + if err != nil {
  79 + log.Logger.Debug("excelTool.ExportData err:" + err.Error())
  80 + controller.Response(nil, err)
  81 + return
  82 + }
  83 + controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")
  84 +}
  85 +
  86 +func (controller ExcelDataController) ImportDividendsReturnedOrder() {
  87 + excelFile, fileHeader, err := controller.GetFile("file")
  88 + if err != nil {
  89 + log.Logger.Error("接收文件失败," + err.Error())
  90 + controller.Response(nil, err)
  91 + return
  92 + }
  93 + if filepath.Ext(fileHeader.Filename) == "" {
  94 + //TODO 判断文件类型
  95 + log.Logger.Error("获取到的文件:" + fileHeader.Filename)
  96 + }
  97 + excelImport := excel.NewExcelImport()
  98 + excelImport.RowBegin = 2 //第二行开始读取
  99 + excelImport.DataFields = []excel.DataField{
  100 + {EnName: "OriginalOrderNum", CnName: "*来源源单号"},
  101 + {EnName: "DividendsReturnedCustomerName", CnName: "*客户名称"},
  102 + {EnName: "OrderGoodName", CnName: "*产品名称"},
  103 + {EnName: "DividendsReturnedDate", CnName: "*退货日期"},
  104 + {EnName: "OrderTime", CnName: "*订单日期"},
  105 + {EnName: "RegionName", CnName: "*退货区域"},
  106 + {EnName: "OrderGoodQuantity", CnName: "*退货数量"},
  107 + {EnName: "OrderGoodPrice", CnName: "*退货价格"},
  108 + {EnName: "CooperationContractNumber", CnName: "项目合约编号"},
  109 + }
  110 + excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
  111 + if err != nil {
  112 + log.Logger.Error("解析excel文件失败," + err.Error())
  113 + controller.Response(nil, err)
  114 + return
  115 + }
  116 + //退货单数据
  117 + returnedOrderData := []allied_creation_cooperation.ImportDividendsReturnedOrderData{}
  118 + for _, v := range excelData {
  119 + //TODO 按需转化
  120 + item := allied_creation_cooperation.ImportDividendsReturnedOrderData{
  121 + OriginalOrderNum: v["OriginalOrderNum"],
  122 + DividendsReturnedCustomerName: v["DividendsReturnedCustomerName"],
  123 + OrderGoodName: v["OrderGoodName"],
  124 + DividendsReturnedDate: v["DividendsReturnedDate"],
  125 + OrderTime: v["OrderTime"],
  126 + RegionName: v["RegionName"],
  127 + OrderGoodQuantity: v["OrderGoodQuantity"],
  128 + OrderGoodPrice: v["OrderGoodPrice"],
  129 + CooperationContractNumber: v["CooperationContractNumber"],
  130 + }
  131 + returnedOrderData = append(returnedOrderData, item)
  132 + }
  133 + creationCooperationGate := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(controller.GetOperator())
  134 + result, err := creationCooperationGate.ImportDividendsReturnedOrder(allied_creation_cooperation.ReqImportDividendsReturnedOrder{
  135 + DividendsReturnedOrderData: returnedOrderData,
  136 + })
  137 + if err != nil {
  138 + controller.Response(nil, err)
  139 + return
  140 + }
  141 + controller.Response(result, nil)
  142 +}
  143 +
  144 +func (controller ExcelDataController) ImportCompanyUser() {
  145 + excelService := service.NewExcelDataService(nil)
  146 + r, err := controller.GetExcelFile()
  147 + if err != nil {
  148 + controller.Response(nil, err)
  149 + return
  150 + }
  151 + cmd := &command.ImportDataCommand{}
  152 + cmd.Operator = controller.GetOperator()
  153 + cmd.Reader = r
  154 + data, err := excelService.ImportCompanyUser(cmd)
  155 + controller.Response(data, err)
  156 +}
  157 +
  158 +func (controller ExcelDataController) ImportCooperationUser() {
  159 + excelService := service.NewExcelDataService(nil)
  160 + r, err := controller.GetExcelFile()
  161 + if err != nil {
  162 + controller.Response(nil, err)
  163 + return
  164 + }
  165 + cmd := &command.ImportDataCommand{}
  166 + cmd.Operator = controller.GetOperator()
  167 + cmd.Reader = r
  168 + data, err := excelService.ImportCooperationUser(cmd)
  169 + controller.Response(data, err)
  170 +}
@@ -8,4 +8,7 @@ import ( @@ -8,4 +8,7 @@ import (
8 func init() { 8 func init() {
9 web.Router("/v1/web/excel/export/company-user", &web_client.ExcelDataController{}, "Post:ExportCompanyUser") 9 web.Router("/v1/web/excel/export/company-user", &web_client.ExcelDataController{}, "Post:ExportCompanyUser")
10 web.Router("/v1/web/excel/export/cooperation-user", &web_client.ExcelDataController{}, "Post:ExportCooperationUser") 10 web.Router("/v1/web/excel/export/cooperation-user", &web_client.ExcelDataController{}, "Post:ExportCooperationUser")
  11 +
  12 + web.Router("/v1/web/excel/import/company-user", &web_client.ExcelDataController{}, "Post:ImportCompanyUser")
  13 + web.Router("/v1/web/excel/import/cooperation-user", &web_client.ExcelDataController{}, "Post:ImportCooperationUser")
11 } 14 }