作者 yangfu

导入修改

... ... @@ -182,13 +182,13 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "userCode", CnName: "*用户编"},
{EnName: "userCode", CnName: "*用户编"},
{EnName: "userName", CnName: "*用户姓名"},
{EnName: "org", CnName: "*组织机构"},
{EnName: "department", CnName: "*所属部门"},
{EnName: "enableStatus", CnName: "*用户状态"},
{EnName: "phone", CnName: "*手机号"},
{EnName: "email", CnName: "邮箱"},
{EnName: "enableStatus", CnName: "状态"},
}
excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
if err != nil {
... ... @@ -229,9 +229,9 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "OrgCode", CnName: "*部门编码"},
{EnName: "OrgName", CnName: "*部门名称"},
{EnName: "ParentOrgCode", CnName: "*上级部门编码"},
{EnName: "orgCode", CnName: "*部门编码"},
{EnName: "orgName", CnName: "*部门名称"},
{EnName: "parentOrgCode", CnName: "*上级部门编码"},
}
excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
if err != nil {
... ... @@ -241,9 +241,9 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import
for _, v := range excelData {
item := allied_creation_user.BatchAddOrgItem{
CompanyId: importDataCommand.Operator.CompanyId,
OrgCode: v["OrgCode"],
OrgName: v["OrgName"],
ParentOrgCode: v["ParentOrgCode"],
OrgCode: v["orgCode"],
OrgName: v["orgName"],
ParentOrgCode: v["parentOrgCode"],
}
items = append(items, item)
}
... ... @@ -254,7 +254,7 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return result, nil
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(excelData)), nil
}
// 导入结果
... ... @@ -284,11 +284,11 @@ func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, fa
// ImportCompanyUser 导入公司用户信息
func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) {
var mapTemplate = map[string]string{
domain.TemplateCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
// 模板待更新
domain.TemplateOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.TemplateCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.TemplateDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
}
var url string
... ...
... ... @@ -53,7 +53,7 @@ const (
// 导入公司用户
ImportCompanyUser = "ADMIN_SYSTEM-MANAGE_BASE_USER"
// 导入公司组织
ImportOrganization = "ImportOrganization"
ImportOrganization = "ADMIN_SYSTEM-MANAGE_BASE_DEPARTMENT"
// 导入共创用户
ImportCooperationUser = "ADMIN_SYSTEM-MANAGE_BASE_ALLIED-USER"
... ... @@ -62,18 +62,3 @@ const (
// 导入退货订单
ImportDividendsReturnOrders = "BUSINESS_ALLIED-CREATION_BONUS_RETURN"
)
//excel 导入模板
const (
// 导入公司用户
TemplateCompanyUser = "ADMIN_SYSTEM-MANAGE_BASE_USER"
// 导入公司组织
TemplateOrganization = "TemplateOrganization"
// 导入共创用户
TemplateCooperationUser = "ADMIN_SYSTEM-MANAGE_BASE_ALLIED-USER"
// 分红订单模板
TemplateDividendsOrders = "BUSINESS_ALLIED-CREATION_BONUS_ORDER"
// 导入退货订单
TemplateDividendsReturnOrders = "BUSINESS_ALLIED-CREATION_BONUS_RETURN"
)
... ...
... ... @@ -226,7 +226,7 @@ func (gateway HttplibAlliedCreationUser) OrgSearch(param ReqOrgSearch) (*DataOrg
return &data, err
}
func (gateway HttplibAlliedCreationUser) OrgBatchAdd(param ReqBatchAddOrg) (*DataBatchAddOrg, error) {
func (gateway HttplibAlliedCreationUser) OrgBatchAdd(param ReqBatchAddOrg) (*DataImportResponse, error) {
url := fmt.Sprintf("%s%s", gateway.baseUrL, "/org/batch-add")
method := "post"
req := gateway.CreateRequest(url, method)
... ... @@ -252,7 +252,7 @@ func (gateway HttplibAlliedCreationUser) OrgBatchAdd(param ReqBatchAddOrg) (*Dat
if err != nil {
return nil, fmt.Errorf("解析批量添加用户:%w", err)
}
var data DataBatchAddOrg
var data DataImportResponse
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package web_client
import (
"fmt"
"io"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
... ... @@ -43,7 +45,7 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin
return isAllEmpty
}
//导出公司用户
// ExportCompanyUser 导出公司用户
func (controller ExcelDataController) ExportCompanyUser() {
excelService := service.NewExcelDataService(nil)
companyUserListQuery := &query.CompanyUserListQuery{}
... ... @@ -70,7 +72,7 @@ func (controller ExcelDataController) ExportCompanyUser() {
controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
}
//导出共创用户
// ExportCooperationUser 导出共创用户
func (controller ExcelDataController) ExportCooperationUser() {
excelService := service.NewExcelDataService(nil)
companyUserListQuery := &query.CompanyUserListQuery{}
... ... @@ -97,7 +99,7 @@ func (controller ExcelDataController) ExportCooperationUser() {
controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")
}
// ImportDividendsOrder TODO 导入分红订单
// ImportDividendsOrder 导入分红订单
func (controller ExcelDataController) ImportDividendsOrder() {
importDividendsOrder(controller)
}
... ... @@ -223,95 +225,51 @@ func importDividendsReturnedOrder(controller ExcelDataController) {
controller.Response(result, nil)
}
func (controller ExcelDataController) ImportCompanyUser() {
importCompanyUser(controller)
}
func importCompanyUser(controller ExcelDataController) {
excelService := service.NewExcelDataService(nil)
r, err := controller.GetExcelFile()
if err != nil {
controller.Response(nil, err)
return
}
cmd := &command.ImportDataCommand{}
cmd.Operator = controller.GetOperator()
cmd.Reader = r
data, err := excelService.ImportCompanyUser(cmd)
controller.Response(data, err)
}
func (controller ExcelDataController) ImportCooperationUser() {
importCooperationUser(controller)
}
func importCooperationUser(controller ExcelDataController) {
excelService := service.NewExcelDataService(nil)
r, err := controller.GetExcelFile()
if err != nil {
controller.Response(nil, err)
return
// FileImport 文件导入
func (controller ExcelDataController) FileImport() {
code := controller.GetString("code")
switch code {
case domain.ImportDividendsOrders:
importDividendsOrder(controller)
case domain.ImportDividendsReturnOrders:
importDividendsReturnedOrder(controller)
default:
defaultImport(controller)
}
cmd := &command.ImportDataCommand{}
cmd.Operator = controller.GetOperator()
cmd.Reader = r
data, err := excelService.ImportCooperationUser(cmd)
controller.Response(data, err)
}
func importOrganization(controller ExcelDataController) {
func defaultImport(controller ExcelDataController) {
var (
data interface{}
err error
r io.Reader
)
excelService := service.NewExcelDataService(nil)
r, err := controller.GetExcelFile()
r, err = controller.GetExcelFile()
if err != nil {
controller.Response(nil, err)
return
}
cmd := &command.ImportDataCommand{}
controller.ParseForm(cmd)
cmd.Operator = controller.GetOperator()
cmd.Reader = r
data, err := excelService.ImportOrganization(cmd)
controller.Response(data, err)
}
func (controller ExcelDataController) ImportOrganization() {
importOrganization(controller)
}
func (controller ExcelDataController) FileImport() {
// excelService := service.NewExcelDataService(nil)
// r, err := controller.GetExcelFile()
// if err != nil {
// controller.Response(nil, err)
// return
// }
// cmd := &command.ImportDataCommand{}
//controller.Unmarshal(cmd)
// controller.ParseForm(cmd)
// cmd.Operator = controller.GetOperator()
// cmd.Reader = r
// var (
// data interface{}
// err error
// )
code := controller.GetString("code")
switch code {
switch cmd.Code {
case domain.ImportCompanyUser:
importCompanyUser(controller)
data, err = excelService.ImportCompanyUser(cmd)
case domain.ImportCooperationUser:
importCooperationUser(controller)
case domain.ImportDividendsOrders:
importDividendsOrder(controller)
case domain.ImportDividendsReturnOrders:
importDividendsReturnedOrder(controller)
data, err = excelService.ImportCooperationUser(cmd)
case domain.ImportOrganization:
importOrganization(controller)
data, err = excelService.ImportOrganization(cmd)
default:
err = fmt.Errorf("导入不存在 Code:%v", cmd.Code)
}
// controller.Response(data, err)
controller.Response(data, err)
}
func (controller ExcelDataController) FileImportTemplate() {
excelService := service.NewExcelDataService(nil)
cmd := &command.ImportDataCommand{}
//controller.Unmarshal(cmd)
code := controller.GetString(":code")
cmd.Code = code
var data interface{}
... ...
... ... @@ -9,14 +9,9 @@ func init() {
web.Router("/v1/web/excel/export/company-user", &web_client.ExcelDataController{}, "Post:ExportCompanyUser")
web.Router("/v1/web/excel/export/cooperation-user", &web_client.ExcelDataController{}, "Post:ExportCooperationUser")
web.Router("/v1/web/excel/import/company-user", &web_client.ExcelDataController{}, "Post:ImportCompanyUser")
web.Router("/v1/web/excel/import/cooperation-user", &web_client.ExcelDataController{}, "Post:ImportCooperationUser")
web.Router("/v1/web/excel/import/dividends-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsOrder")
web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder")
web.Router("/v1/web/excel/import/organization", &web_client.ExcelDataController{}, "Post:ImportOrganization")
web.Router("/v1/web/file-import", &web_client.ExcelDataController{}, "Post:FileImport")
web.Router("/v1/web/file-import-template/:code", &web_client.ExcelDataController{}, "Get:FileImportTemplate")
}
... ...