|
@@ -2,10 +2,14 @@ package service |
|
@@ -2,10 +2,14 @@ package service |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"fmt"
|
4
|
"fmt"
|
5
|
-
|
5
|
+ "github.com/linmadan/egglib-go/core/application"
|
|
|
6
|
+ "github.com/linmadan/egglib-go/utils/excel"
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
|
|
|
11
|
+ "strconv"
|
|
|
12
|
+ "time"
|
9
|
)
|
13
|
)
|
10
|
|
14
|
|
11
|
type ExcelDataService struct {
|
15
|
type ExcelDataService struct {
|
|
@@ -15,7 +19,7 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService { |
|
@@ -15,7 +19,7 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService { |
15
|
return &ExcelDataService{}
|
19
|
return &ExcelDataService{}
|
16
|
}
|
20
|
}
|
17
|
|
21
|
|
18
|
-// 导出公司用户信息列表
|
22
|
+// ExportCompanyUser 导出公司用户信息列表
|
19
|
func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
|
23
|
func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
|
20
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
|
24
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
|
21
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
25
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
@@ -35,7 +39,7 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan |
|
@@ -35,7 +39,7 @@ func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.Compan |
35
|
return ExportCompanyUserData(result.Users), nil
|
39
|
return ExportCompanyUserData(result.Users), nil
|
36
|
}
|
40
|
}
|
37
|
|
41
|
|
38
|
-// 导出共创用户信息列表
|
42
|
+// ExportCooperationUser 导出共创用户信息列表
|
39
|
func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) {
|
43
|
func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) {
|
40
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
|
44
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
|
41
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
45
|
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
|
|
@@ -54,3 +58,107 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co |
|
@@ -54,3 +58,107 @@ func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.Co |
54
|
}
|
58
|
}
|
55
|
return ExportCooperationUserData(result.Users), nil
|
59
|
return ExportCooperationUserData(result.Users), nil
|
56
|
}
|
60
|
}
|
|
|
61
|
+
|
|
|
62
|
+// ImportCompanyUser 导入公司用户信息
|
|
|
63
|
+func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
64
|
+ excelImport := excel.NewExcelImport()
|
|
|
65
|
+ excelImport.RowBegin = 2 //第二行开始读取
|
|
|
66
|
+ excelImport.DataFields = []excel.DataField{
|
|
|
67
|
+ {EnName: "UserCode", CnName: "*用户编号"},
|
|
|
68
|
+ {EnName: "UserName", CnName: "*用户姓名"},
|
|
|
69
|
+ {EnName: "OrganizationID", CnName: "*组织机构"},
|
|
|
70
|
+ {EnName: "DepartmentID", CnName: "*所属部门"},
|
|
|
71
|
+ {EnName: "Phone", CnName: "*手机号"},
|
|
|
72
|
+ {EnName: "Email", CnName: "邮箱"},
|
|
|
73
|
+ }
|
|
|
74
|
+ excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
|
|
|
75
|
+ if err != nil {
|
|
|
76
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
77
|
+ }
|
|
|
78
|
+ users := make([]allied_creation_user.BatchAddUserItem, 0)
|
|
|
79
|
+ var fail int
|
|
|
80
|
+ for _, v := range excelData {
|
|
|
81
|
+ item := allied_creation_user.BatchAddUserItem{
|
|
|
82
|
+ CompanyID: importDataCommand.Operator.CompanyId,
|
|
|
83
|
+ UserType: domain.UserTypeEmployee,
|
|
|
84
|
+ UserCode: v["UserCode"],
|
|
|
85
|
+ OrganizationID: 0,
|
|
|
86
|
+ DepartmentID: 0,
|
|
|
87
|
+ UserInfo: allied_creation_user.BatchAddUserItemUserInfo{
|
|
|
88
|
+ UserName: v["UserName"],
|
|
|
89
|
+ Phone: v["Phone"],
|
|
|
90
|
+ Email: v["Email"],
|
|
|
91
|
+ },
|
|
|
92
|
+ CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{},
|
|
|
93
|
+ }
|
|
|
94
|
+ item.OrganizationID, err = strconv.Atoi(v["OrganizationID"])
|
|
|
95
|
+ if err != nil {
|
|
|
96
|
+ fail++
|
|
|
97
|
+ continue
|
|
|
98
|
+ }
|
|
|
99
|
+ item.DepartmentID, err = strconv.Atoi(v["DepartmentID"])
|
|
|
100
|
+ if err != nil {
|
|
|
101
|
+ fail++
|
|
|
102
|
+ continue
|
|
|
103
|
+ }
|
|
|
104
|
+ users = append(users, item)
|
|
|
105
|
+ }
|
|
|
106
|
+ userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
|
|
|
107
|
+ result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
|
|
|
108
|
+ Users: users,
|
|
|
109
|
+ })
|
|
|
110
|
+ if err != nil {
|
|
|
111
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
112
|
+ }
|
|
|
113
|
+ return result, nil
|
|
|
114
|
+}
|
|
|
115
|
+
|
|
|
116
|
+// ImportCooperationUser 导入共创用户信息
|
|
|
117
|
+func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
|
|
|
118
|
+ excelImport := excel.NewExcelImport()
|
|
|
119
|
+ excelImport.RowBegin = 2 //第二行开始读取
|
|
|
120
|
+ excelImport.DataFields = []excel.DataField{
|
|
|
121
|
+ {EnName: "UserCode", CnName: "*用户编号"},
|
|
|
122
|
+ {EnName: "UserName", CnName: "*用户姓名"},
|
|
|
123
|
+ {EnName: "CooperationCompany", CnName: "*合伙公司"},
|
|
|
124
|
+ {EnName: "CooperationDeadline", CnName: "*合伙到期"},
|
|
|
125
|
+ {EnName: "Phone", CnName: "*手机号"},
|
|
|
126
|
+ {EnName: "Email", CnName: "邮箱"},
|
|
|
127
|
+ }
|
|
|
128
|
+ excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
|
|
|
129
|
+ if err != nil {
|
|
|
130
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
131
|
+ }
|
|
|
132
|
+ users := make([]allied_creation_user.BatchAddUserItem, 0)
|
|
|
133
|
+ var fail int
|
|
|
134
|
+ for _, v := range excelData {
|
|
|
135
|
+ item := allied_creation_user.BatchAddUserItem{
|
|
|
136
|
+ CompanyID: importDataCommand.Operator.CompanyId,
|
|
|
137
|
+ UserType: domain.UserTypeCooperation,
|
|
|
138
|
+ UserCode: v["UserCode"],
|
|
|
139
|
+ OrganizationID: int(importDataCommand.Operator.OrgId),
|
|
|
140
|
+ UserInfo: allied_creation_user.BatchAddUserItemUserInfo{
|
|
|
141
|
+ UserName: v["UserName"],
|
|
|
142
|
+ Phone: v["Phone"],
|
|
|
143
|
+ Email: v["Email"],
|
|
|
144
|
+ },
|
|
|
145
|
+ CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{
|
|
|
146
|
+ CooperationCompany: v["CooperationCompany"],
|
|
|
147
|
+ },
|
|
|
148
|
+ }
|
|
|
149
|
+ item.CooperationInfo.CooperationDeadline, err = time.Parse("2006-01-02", v["CooperationDeadline"])
|
|
|
150
|
+ if err != nil {
|
|
|
151
|
+ fail++
|
|
|
152
|
+ continue
|
|
|
153
|
+ }
|
|
|
154
|
+ users = append(users, item)
|
|
|
155
|
+ }
|
|
|
156
|
+ userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
|
|
|
157
|
+ result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
|
|
|
158
|
+ Users: users,
|
|
|
159
|
+ })
|
|
|
160
|
+ if err != nil {
|
|
|
161
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
162
|
+ }
|
|
|
163
|
+ return result, nil
|
|
|
164
|
+} |