...
|
...
|
@@ -7,7 +7,6 @@ import ( |
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/excel"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
|
|
"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/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
|
...
|
...
|
@@ -20,158 +19,62 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService { |
|
|
return &ExcelDataService{}
|
|
|
}
|
|
|
|
|
|
// ExportCompanyUser 导出公司用户信息列表
|
|
|
func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
|
|
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
Limit: 10000,
|
|
|
CompanyId: companyUserListQuery.Operator.CompanyId,
|
|
|
OrganizationId: 0,
|
|
|
DepartmentId: 0,
|
|
|
UserName: companyUserListQuery.UserName,
|
|
|
DepName: companyUserListQuery.DepartmentName,
|
|
|
Phone: "",
|
|
|
UserType: domain.UserTypeEmployee,
|
|
|
InOrgIds: companyUserListQuery.Operator.OrgIds,
|
|
|
// ImportCooperationUser 导入共创用户信息
|
|
|
func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
|
|
|
orgResult, err := userGateway.OrgGet(allied_creation_user.ReqOrgGet{
|
|
|
OrgId: int(importDataCommand.Operator.OrgId),
|
|
|
})
|
|
|
if err != nil {
|
|
|
return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
excelImport := excel.NewExcelImport()
|
|
|
excelImport.RowBegin = 3 //第二行开始读取
|
|
|
excelImport.DataFields = []excel.DataField{
|
|
|
{EnName: "userCode", CnName: "*用户编码"},
|
|
|
{EnName: "userName", CnName: "*用户姓名"},
|
|
|
{EnName: "cooperationCompany", CnName: "合伙公司"},
|
|
|
{EnName: "cooperationDeadline", CnName: "合伙到期"},
|
|
|
{EnName: "enableStatus", CnName: "*用户状态"},
|
|
|
{EnName: "phone", CnName: "*手机号"},
|
|
|
{EnName: "email", CnName: "邮箱"},
|
|
|
}
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
users := make([]allied_creation_user.BatchAddUserItem, 0)
|
|
|
for _, v := range excelData {
|
|
|
if srv.fieldValueAllEmpty(v) {
|
|
|
continue
|
|
|
}
|
|
|
item := allied_creation_user.BatchAddUserItem{
|
|
|
CompanyId: importDataCommand.Operator.CompanyId,
|
|
|
UserType: domain.UserTypeCooperation,
|
|
|
UserCode: v["userCode"],
|
|
|
Org: orgResult.OrgCode,
|
|
|
UserName: strings.TrimSpace(v["userName"]),
|
|
|
Phone: strings.TrimSpace(v["phone"]),
|
|
|
Email: strings.TrimSpace(v["email"]),
|
|
|
EnableStatus: strings.TrimSpace(v["enableStatus"]),
|
|
|
CooperationCompany: v["cooperationCompany"],
|
|
|
CooperationDeadline: v["cooperationDeadline"],
|
|
|
}
|
|
|
users = append(users, item)
|
|
|
}
|
|
|
return ExportCompanyUserData(result.Users), nil
|
|
|
}
|
|
|
|
|
|
// ExportCooperationUser 导出共创用户信息列表
|
|
|
func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
|
|
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
|
Limit: 10000,
|
|
|
CompanyId: companyUserListQuery.Operator.CompanyId,
|
|
|
OrganizationId: 0,
|
|
|
DepartmentId: 0,
|
|
|
UserName: companyUserListQuery.UserName,
|
|
|
DepName: companyUserListQuery.DepartmentName,
|
|
|
Phone: "",
|
|
|
UserType: domain.UserTypeCooperation,
|
|
|
InOrgIds: companyUserListQuery.Operator.OrgIds,
|
|
|
result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
|
|
|
Users: users,
|
|
|
Password: initPassword,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
return ExportCooperationUserData(result.Users), nil
|
|
|
}
|
|
|
|
|
|
// ImportCompanyUser 导入公司用户信息
|
|
|
func (srv ExcelDataService) ImportCompanyUser2(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
//initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
//}
|
|
|
//excelImport := excel.NewExcelImport()
|
|
|
//excelImport.RowBegin = 2 //第二行开始读取
|
|
|
//excelImport.DataFields = []excel.DataField{
|
|
|
// {EnName: "UserCode", CnName: "*用户编号"},
|
|
|
// {EnName: "UserName", CnName: "*用户姓名"},
|
|
|
// {EnName: "OrganizationID", CnName: "*组织机构"},
|
|
|
// {EnName: "DepartmentID", CnName: "*所属部门"},
|
|
|
// {EnName: "Phone", CnName: "*手机号"},
|
|
|
// {EnName: "Email", CnName: "邮箱"},
|
|
|
// {EnName: "Status", CnName: "状态"},
|
|
|
//}
|
|
|
//excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
//}
|
|
|
//users := make([]allied_creation_user.BatchAddUserItem, 0)
|
|
|
//for _, v := range excelData {
|
|
|
// item := allied_creation_user.BatchAddUserItem{
|
|
|
// CompanyID: importDataCommand.Operator.CompanyId,
|
|
|
// UserType: domain.UserTypeEmployee,
|
|
|
// UserCode: v["UserCode"],
|
|
|
// OrganizationID: 0,
|
|
|
// DepartmentID: 0,
|
|
|
// UserInfo: allied_creation_user.BatchAddUserItemUserInfo{
|
|
|
// UserName: v["UserName"],
|
|
|
// Phone: v["Phone"],
|
|
|
// Email: v["Email"],
|
|
|
// },
|
|
|
// CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{},
|
|
|
// }
|
|
|
// item.OrganizationID, err = strconv.Atoi(v["OrganizationID"])
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("用户:%v 组织值:%v 类型无效(数值类型)", item.UserInfo.UserName, item.OrganizationID))
|
|
|
// }
|
|
|
// item.DepartmentID, err = strconv.Atoi(v["DepartmentID"])
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("用户:%v 部门值:%v 类型无效(数值类型)", item.UserInfo.UserName, item.DepartmentID))
|
|
|
// }
|
|
|
// users = append(users, item)
|
|
|
//}
|
|
|
//userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
|
|
|
//result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
|
|
|
// Users: users,
|
|
|
// Password: initPassword,
|
|
|
//})
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
//}
|
|
|
//return result, nil
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// ImportCooperationUser 导入共创用户信息
|
|
|
func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
//initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
//}
|
|
|
//excelImport := excel.NewExcelImport()
|
|
|
//excelImport.RowBegin = 2 //第二行开始读取
|
|
|
//excelImport.DataFields = []excel.DataField{
|
|
|
// {EnName: "UserCode", CnName: "*用户编号"},
|
|
|
// {EnName: "UserName", CnName: "*用户姓名"},
|
|
|
// {EnName: "CooperationCompany", CnName: "*合伙公司"},
|
|
|
// {EnName: "CooperationDeadline", CnName: "*合伙到期"},
|
|
|
// {EnName: "Phone", CnName: "*手机号"},
|
|
|
// {EnName: "Email", CnName: "邮箱"},
|
|
|
//}
|
|
|
//excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
//}
|
|
|
//users := make([]allied_creation_user.BatchAddUserItem, 0)
|
|
|
//var fail int
|
|
|
//for _, v := range excelData {
|
|
|
// item := allied_creation_user.BatchAddUserItem{
|
|
|
// CompanyID: importDataCommand.Operator.CompanyId,
|
|
|
// UserType: domain.UserTypeCooperation,
|
|
|
// UserCode: v["UserCode"],
|
|
|
// OrganizationID: int(importDataCommand.Operator.OrgId),
|
|
|
// UserInfo: allied_creation_user.BatchAddUserItemUserInfo{
|
|
|
// UserName: v["UserName"],
|
|
|
// Phone: v["Phone"],
|
|
|
// Email: v["Email"],
|
|
|
// },
|
|
|
// CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{
|
|
|
// CooperationCompany: v["CooperationCompany"],
|
|
|
// },
|
|
|
// }
|
|
|
// item.CooperationInfo.CooperationDeadline, err = time.Parse("2006-01-02", v["CooperationDeadline"])
|
|
|
// if err != nil {
|
|
|
// fail++
|
|
|
// continue
|
|
|
// }
|
|
|
// users = append(users, item)
|
|
|
//}
|
|
|
//userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
|
|
|
//result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
|
|
|
// Users: users,
|
|
|
// Password: initPassword,
|
|
|
//})
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
//}
|
|
|
//return result, nil
|
|
|
return nil, nil
|
|
|
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil
|
|
|
}
|
|
|
|
|
|
// ImportCompanyUser 导入公司用户信息
|
...
|
...
|
@@ -197,21 +100,19 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD |
|
|
}
|
|
|
users := make([]allied_creation_user.BatchAddUserItem, 0)
|
|
|
for _, v := range excelData {
|
|
|
if srv.fieldValueAllEmpty(v) {
|
|
|
continue
|
|
|
}
|
|
|
item := allied_creation_user.BatchAddUserItem{
|
|
|
CompanyId: importDataCommand.Operator.CompanyId,
|
|
|
UserType: domain.UserTypeEmployee,
|
|
|
UserCode: v["userCode"],
|
|
|
Org: v["org"],
|
|
|
Department: v["department"],
|
|
|
UserName: v["userName"],
|
|
|
Phone: v["phone"],
|
|
|
Email: v["email"],
|
|
|
EnableStatus: domain.UserStatusEnable,
|
|
|
}
|
|
|
if status, ok := v["status"]; ok {
|
|
|
if strings.TrimSpace(status) != "启用" {
|
|
|
item.EnableStatus = domain.UserStatusDisable
|
|
|
}
|
|
|
UserCode: strings.TrimSpace(v["userCode"]),
|
|
|
Org: strings.TrimSpace(v["org"]),
|
|
|
Department: strings.TrimSpace(v["department"]),
|
|
|
UserName: strings.TrimSpace(v["userName"]),
|
|
|
Phone: strings.TrimSpace(v["phone"]),
|
|
|
Email: strings.TrimSpace(v["email"]),
|
|
|
EnableStatus: strings.TrimSpace(v["enableStatus"]),
|
|
|
}
|
|
|
users = append(users, item)
|
|
|
}
|
...
|
...
|
@@ -223,9 +124,10 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(excelData)), nil
|
|
|
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil
|
|
|
}
|
|
|
|
|
|
// ImportOrganization 导入组织
|
|
|
func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
excelImport := excel.NewExcelImport()
|
|
|
excelImport.RowBegin = 3 //第二行开始读取
|
...
|
...
|
@@ -240,6 +142,9 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import |
|
|
}
|
|
|
items := make([]allied_creation_user.BatchAddOrgItem, 0)
|
|
|
for _, v := range excelData {
|
|
|
if srv.fieldValueAllEmpty(v) {
|
|
|
continue
|
|
|
}
|
|
|
item := allied_creation_user.BatchAddOrgItem{
|
|
|
CompanyId: importDataCommand.Operator.CompanyId,
|
|
|
OrgCode: v["orgCode"],
|
...
|
...
|
@@ -255,7 +160,7 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(excelData)), nil
|
|
|
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(items)), nil
|
|
|
}
|
|
|
|
|
|
// 导入结果
|
...
|
...
|
@@ -282,15 +187,25 @@ func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, fa |
|
|
return result
|
|
|
}
|
|
|
|
|
|
// ImportCompanyUser 导入公司用户信息
|
|
|
func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool {
|
|
|
isAllEmpty := true
|
|
|
for _, v := range param {
|
|
|
value := strings.TrimSpace(v)
|
|
|
if len(value) > 0 {
|
|
|
isAllEmpty = false
|
|
|
}
|
|
|
}
|
|
|
return isAllEmpty
|
|
|
}
|
|
|
|
|
|
// FileImportTemplate 导入模板
|
|
|
func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
var mapTemplate = map[string]string{
|
|
|
domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",
|
|
|
domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx",
|
|
|
domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807770_sBtA4dYcmESZy6Q2ycfGSCKGdFtBETQZ.xlsx",
|
|
|
// 模板待更新
|
|
|
domain.ImportCooperationUser: "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",
|
|
|
domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",
|
|
|
domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx",
|
|
|
domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743206_NPYTKw6RGhXn4TpYNEQhGGdCkXKXTnxM.xlsx",
|
|
|
domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210926/object/1632635345_SbfzmkXjQHhCwPw4MB7zb5EBBtdp2MSE.xlsx",
|
|
|
domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx",
|
|
|
}
|
|
|
var url string
|
|
|
var ok bool
|
...
|
...
|
|