...
|
...
|
@@ -9,8 +9,7 @@ import ( |
|
|
"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"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
type ExcelDataService struct {
|
...
|
...
|
@@ -61,6 +60,120 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co |
|
|
}
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
// ImportCompanyUser 导入公司用户信息
|
|
|
func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)
|
|
|
if err != nil {
|
...
|
...
|
@@ -71,8 +184,8 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD |
|
|
excelImport.DataFields = []excel.DataField{
|
|
|
{EnName: "UserCode", CnName: "*用户编号"},
|
|
|
{EnName: "UserName", CnName: "*用户姓名"},
|
|
|
{EnName: "OrganizationID", CnName: "*组织机构"},
|
|
|
{EnName: "DepartmentID", CnName: "*所属部门"},
|
|
|
{EnName: "Organization", CnName: "*组织机构"},
|
|
|
{EnName: "Department", CnName: "*所属部门"},
|
|
|
{EnName: "Phone", CnName: "*手机号"},
|
|
|
{EnName: "Email", CnName: "邮箱"},
|
|
|
{EnName: "Status", CnName: "状态"},
|
...
|
...
|
@@ -84,25 +197,20 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD |
|
|
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{},
|
|
|
CompanyId: importDataCommand.Operator.CompanyId,
|
|
|
UserType: domain.UserTypeEmployee,
|
|
|
UserCode: v["UserCode"],
|
|
|
Org: v["Organization"],
|
|
|
Department: v["Department"],
|
|
|
UserName: v["UserName"],
|
|
|
Phone: v["Phone"],
|
|
|
Email: v["Email"],
|
|
|
EnableStatus: domain.UserStatusEnable,
|
|
|
}
|
|
|
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))
|
|
|
if status, ok := v["Status"]; ok {
|
|
|
if strings.TrimSpace(status) != "启用" {
|
|
|
item.EnableStatus = domain.UserStatusDisable
|
|
|
}
|
|
|
}
|
|
|
users = append(users, item)
|
|
|
}
|
...
|
...
|
@@ -117,54 +225,31 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD |
|
|
return result, 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())
|
|
|
}
|
|
|
func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, 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: "邮箱"},
|
|
|
{EnName: "OrgCode", CnName: "*部门编码"},
|
|
|
{EnName: "OrgName", CnName: "*部门名称"},
|
|
|
{EnName: "ParentOrgCode", 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
|
|
|
items := make([]allied_creation_user.BatchAddOrgItem, 0)
|
|
|
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
|
|
|
item := allied_creation_user.BatchAddOrgItem{
|
|
|
CompanyId: importDataCommand.Operator.CompanyId,
|
|
|
OrgCode: v["OrgCode"],
|
|
|
OrgName: v["OrgName"],
|
|
|
ParentOrgCode: v["ParentOrgCode"],
|
|
|
}
|
|
|
users = append(users, item)
|
|
|
items = append(items, item)
|
|
|
}
|
|
|
userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
|
|
|
result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
|
|
|
Users: users,
|
|
|
Password: initPassword,
|
|
|
result, err := userGateway.OrgBatchAdd(allied_creation_user.ReqBatchAddOrg{
|
|
|
OrgList: items,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
...
|
...
|
|