...
|
...
|
@@ -2,10 +2,14 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
"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/service_gateway/allied_creation_user"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type ExcelDataService struct {
|
...
|
...
|
@@ -15,7 +19,7 @@ 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{
|
...
|
...
|
@@ -35,7 +39,7 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan |
|
|
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{
|
...
|
...
|
@@ -54,3 +58,107 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co |
|
|
}
|
|
|
return ExportCooperationUserData(result.Users), nil
|
|
|
}
|
|
|
|
|
|
// ImportCompanyUser 导入公司用户信息
|
|
|
func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportDataCommand) (interface{}, 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: "邮箱"},
|
|
|
}
|
|
|
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.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 {
|
|
|
fail++
|
|
|
continue
|
|
|
}
|
|
|
item.DepartmentID, err = strconv.Atoi(v["DepartmentID"])
|
|
|
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,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
// ImportCooperationUser 导入共创用户信息
|
|
|
func (srv ExcelDataService) ImportCooperationUser(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: "邮箱"},
|
|
|
}
|
|
|
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,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
return result, nil
|
|
|
} |
...
|
...
|
|