作者 yangfu

导入用户 组织修改

... ... @@ -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,
CompanyId: importDataCommand.Operator.CompanyId,
UserType: domain.UserTypeEmployee,
UserCode: v["UserCode"],
OrganizationID: 0,
DepartmentID: 0,
UserInfo: allied_creation_user.BatchAddUserItemUserInfo{
Org: v["Organization"],
Department: v["Department"],
UserName: v["UserName"],
Phone: v["Phone"],
Email: v["Email"],
},
CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{},
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))
if status, ok := v["Status"]; ok {
if strings.TrimSpace(status) != "启用" {
item.EnableStatus = domain.UserStatusDisable
}
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)
}
... ... @@ -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())
... ...
... ... @@ -225,3 +225,34 @@ func (gateway HttplibAlliedCreationUser) OrgSearch(param ReqOrgSearch) (*DataOrg
err = gateway.GetResponseData(result, &data)
return &data, err
}
func (gateway HttplibAlliedCreationUser) OrgBatchAdd(param ReqBatchAddOrg) (*DataBatchAddOrg, error) {
url := fmt.Sprintf("%s%s", gateway.baseUrL, "/org/batch-add")
method := "post"
req := gateway.CreateRequest(url, method)
//TODO traceID
log.Logger.Debug("向用户模块请求数据:批量添加用户。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求批量添加用户失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取批量添加用户失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:批量添加用户。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析批量添加用户:%w", err)
}
var data DataBatchAddOrg
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -239,7 +239,7 @@ func (gateway HttplibAlliedCreationUser) UserBatchResetPassword(param ReqBatchRe
// UserBatchAdd 批量添加用户
func (gateway HttplibAlliedCreationUser) UserBatchAdd(param ReqBatchAddUser) (*DataBatchAddUser, error) {
url := fmt.Sprintf("%s%s", gateway.baseUrL, "/user/batch-add")
url := fmt.Sprintf("%s%s", gateway.baseUrL, "/user/batch-add2")
method := "post"
req := gateway.CreateRequest(url, method)
//TODO traceID
... ...
... ... @@ -139,3 +139,21 @@ type (
} `json:"orgs"`
}
)
type (
ReqBatchAddOrg struct {
OrgList []BatchAddOrgItem `json:"orgList"`
}
BatchAddOrgItem struct {
// 组织编码
OrgCode string `json:"orgCode,omitempty"`
// 父级组织编码
ParentOrgCode string `json:"parentOrgCode,omitempty"`
// 组织名称
OrgName string `json:"orgName,omitempty"`
// 企业id
CompanyId int64 `json:"companyId,omitempty"`
}
DataBatchAddOrg struct {
}
)
... ...
... ... @@ -348,23 +348,48 @@ type (
DataBatchAddUser struct {
}
//BatchAddUserItem struct {
// CompanyID int64 `json:"companyId"`
// UserType int `json:"userType"`
// UserCode string `json:"userCode"`
// OrganizationID int `json:"organizationId"`
// DepartmentID int `json:"departmentId"`
// UserInfo BatchAddUserItemUserInfo `json:"userInfo"`
// CooperationInfo BatchAddUserItemCooperationInfo `json:"cooperationInfo"`
//}
//BatchAddUserItemUserInfo struct {
// Phone string `json:"phone"`
// UserName string `json:"userName"`
// Email string `json:"email"`
// Avatar string `json:"avatar"`
//}
//BatchAddUserItemCooperationInfo struct {
// CooperationCompany string `json:"cooperationCompany"`
// CooperationDeadline time.Time `json:"cooperationDeadline"`
//}
BatchAddUserItem struct {
CompanyID int64 `json:"companyId"`
UserType int `json:"userType"`
UserCode string `json:"userCode"`
OrganizationID int `json:"organizationId"`
DepartmentID int `json:"departmentId"`
UserInfo BatchAddUserItemUserInfo `json:"userInfo"`
CooperationInfo BatchAddUserItemCooperationInfo `json:"cooperationInfo"`
}
BatchAddUserItemUserInfo struct {
Phone string `json:"phone"`
UserName string `json:"userName"`
Email string `json:"email"`
Avatar string `json:"avatar"`
}
BatchAddUserItemCooperationInfo struct {
// 企业id
CompanyId int64 `json:"companyId,omitempty"`
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType int `json:"userType,omitempty"`
// 用户姓名
UserName string `json:"userName,omitempty"`
// 手机号码
Phone string `json:"phone,omitempty"`
// 邮箱
Email string `json:"email,omitempty"`
// 用户编号 企业内标识
UserCode string `json:"userCode,omitempty"`
// 组织编码
Org string `json:"org,omitempty"`
// 部门编码
Department string `json:"department,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `json:"enableStatus,omitempty"`
// 共创公司 cooperationCompany
CooperationCompany string `json:"cooperationCompany"`
// 共创到期时间 (yyyy-MM-dd) cooperationDeadline
CooperationDeadline time.Time `json:"cooperationDeadline"`
}
)
... ...
... ... @@ -228,3 +228,17 @@ func (controller ExcelDataController) ImportCooperationUser() {
data, err := excelService.ImportCooperationUser(cmd)
controller.Response(data, err)
}
func (controller ExcelDataController) ImportOrganization() {
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.ImportOrganization(cmd)
controller.Response(data, err)
}
... ...
... ... @@ -14,4 +14,6 @@ func init() {
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")
}
... ...