作者 tangxuhui
@@ -696,7 +696,7 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs @@ -696,7 +696,7 @@ func (svr AuthService) GetCompanyOrgsByUser(queryParam *query.GetCompanyOrgsByUs
696 696
697 for i := range result.Users { 697 for i := range result.Users {
698 user := result.Users[i] 698 user := result.Users[i]
699 - if _, ok := mapCompany[user.Company.CompanyId]; !ok { 699 + if _, ok := mapCompany[user.Company.CompanyId]; !ok && len(user.UserOrg) > 0 {
700 companys = append(companys, dto.CompanyItem{ 700 companys = append(companys, dto.CompanyItem{
701 CompanyId: user.Company.CompanyId, 701 CompanyId: user.Company.CompanyId,
702 CompanyName: user.Company.CompanyName, 702 CompanyName: user.Company.CompanyName,
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
4 "strconv" 5 "strconv"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
@@ -81,9 +82,13 @@ func (srv CooperationApplicationsService) SearchCooperationApplications(applicat @@ -81,9 +82,13 @@ func (srv CooperationApplicationsService) SearchCooperationApplications(applicat
81 IsCanceled: 1, 82 IsCanceled: 1,
82 }) 83 })
83 for i := 0; i < len(resultApplications.Grid.List); i++ { 84 for i := 0; i < len(resultApplications.Grid.List); i++ {
84 - resultApplications.Grid.List[i].Department.DepartmentID = resultApplications.Grid.List[i].Org.OrgID  
85 - resultApplications.Grid.List[i].Department.DepartmentName = resultApplications.Grid.List[i].Org.OrgName 85 + resultApplications.Grid.List[i].Department.DepartmentID = int(resultApplications.Grid.List[i].CooperationApplicationApplicant.Department.DepartmentId)
  86 + resultApplications.Grid.List[i].Department.DepartmentName = resultApplications.Grid.List[i].CooperationApplicationApplicant.Department.DepartmentName
  87 + if len(resultApplications.Grid.List[i].Department.DepartmentName) == 0 && resultApplications.Grid.List[i].Department.DepartmentID == 0 {
  88 + resultApplications.Grid.List[i].Department.DepartmentName = domain.CooperationUserDepartmentName
  89 + }
86 } 90 }
  91 +
87 if err != nil { 92 if err != nil {
88 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 93 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
89 } 94 }
@@ -168,10 +173,6 @@ func (srv CooperationApplicationsService) PersonSearchCooperationApplications(ap @@ -168,10 +173,6 @@ func (srv CooperationApplicationsService) PersonSearchCooperationApplications(ap
168 } 173 }
169 // var dataList []dto.CooperationApplication 174 // var dataList []dto.CooperationApplication
170 175
171 - // for i := range resultApplications.Gride.List {  
172 - // item := dto.ToCooperationApplication(&resultApplications.Gride.List[i])  
173 - // dataList = append(dataList, *item)  
174 - // }  
175 return resultApplications, nil 176 return resultApplications, nil
176 } 177 }
177 178
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
4 "strconv" 6 "strconv"
5 7
6 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
@@ -103,16 +105,17 @@ func (srv CooperationProjectService) SearchCooperationProject(projectQuery *comm @@ -103,16 +105,17 @@ func (srv CooperationProjectService) SearchCooperationProject(projectQuery *comm
103 105
104 // PersonSearchCooperationProject 共创用户获取共创项目列表 106 // PersonSearchCooperationProject 共创用户获取共创项目列表
105 func (srv CooperationProjectService) PersonSearchCooperationProject(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) { 107 func (srv CooperationProjectService) PersonSearchCooperationProject(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) {
  108 + extQueries := extQuires(projectQuery.Operator)
106 creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( 109 creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
107 projectQuery.Operator) 110 projectQuery.Operator)
108 - //orgidStr := strconv.Itoa(projectQuery.OrgId)  
109 result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{ 111 result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
110 - PageNumber: projectQuery.PageNumber + 1, //手机序号从0开始的  
111 - PageSize: projectQuery.PageSize,  
112 - OrgId: projectQuery.OrgId,  
113 - Status: 1, //搜索状态为“招标中”项目  
114 - Keyword: projectQuery.Keyword,  
115 - //UserBaseId: projectQuery.Operator.UserBaseId, 112 + PageNumber: projectQuery.PageNumber + 1, //手机序号从0开始的
  113 + PageSize: projectQuery.PageSize,
  114 + OrgId: projectQuery.OrgId,
  115 + Status: 1, //搜索状态为“招标中”项目
  116 + Keyword: projectQuery.Keyword,
  117 + SearchCooperationProjectExtQueriesFlag: 1,
  118 + SearchCooperationProjectExtQueries: extQueries,
116 }) 119 })
117 if err != nil { 120 if err != nil {
118 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 121 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -120,6 +123,40 @@ func (srv CooperationProjectService) PersonSearchCooperationProject(projectQuery @@ -120,6 +123,40 @@ func (srv CooperationProjectService) PersonSearchCooperationProject(projectQuery
120 return int(result.Total), result.List, nil 123 return int(result.Total), result.List, nil
121 } 124 }
122 125
  126 +func extQuires(operator domain.Operator) []*allied_creation_cooperation.SearchCooperationProjectExtQuery {
  127 + var extQueries = make([]*allied_creation_cooperation.SearchCooperationProjectExtQuery, 0)
  128 + if operator.UserBaseId > 0 {
  129 + gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
  130 + operator)
  131 + users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
  132 + Limit: 100,
  133 + Offset: 0,
  134 + UserBaseId: operator.UserBaseId,
  135 + EnableStatus: domain.UserStatusEnable,
  136 + })
  137 + if err != nil {
  138 + return extQueries
  139 + }
  140 + for i := range users.Users {
  141 + u := users.Users[i]
  142 + q := &allied_creation_cooperation.SearchCooperationProjectExtQuery{
  143 + ExtCompanyId: int64(u.Company.CompanyId),
  144 + //ExtOrgId: int64(u.Org.OrgId),
  145 + //ExtOrgIds: int64(u.UserOrg),
  146 + ExtUserId: int64(u.UserId),
  147 + ExtUserBaseId: int64(u.UserBaseId),
  148 + ExtCooperationProjectUndertakerTypes: []int32{int32(u.UserType & 3), 3},
  149 + }
  150 + for j := range u.UserOrg {
  151 + org := u.UserOrg[j]
  152 + q.ExtOrgIds = append(q.ExtOrgIds, int64(org.OrgID))
  153 + }
  154 + extQueries = append(extQueries, q)
  155 + }
  156 + }
  157 + return extQueries
  158 +}
  159 +
123 // PersonSearchCooperationProject 共创用户获取共创项目列表 160 // PersonSearchCooperationProject 共创用户获取共创项目列表
124 //func (srv CooperationProjectService) PersonRecommendCooperationProject(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) { 161 //func (srv CooperationProjectService) PersonRecommendCooperationProject(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) {
125 // creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( 162 // creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
@@ -109,7 +109,12 @@ func (srv CompanyCreditAccountService) CreditAccountPaySearch(cmd *command.Credi @@ -109,7 +109,12 @@ func (srv CompanyCreditAccountService) CreditAccountPaySearch(cmd *command.Credi
109 } 109 }
110 var items = make([]*dto.CreditAccountItem, 0) 110 var items = make([]*dto.CreditAccountItem, 0)
111 if len(cooperationContractNumbers) == 0 { 111 if len(cooperationContractNumbers) == 0 {
112 - return items, nil 112 + return map[string]interface{}{
  113 + "grid": map[string]interface{}{
  114 + "list": items,
  115 + "sum": 0,
  116 + },
  117 + }, nil
113 } 118 }
114 119
115 var beginTime, endTime time.Time 120 var beginTime, endTime time.Time
@@ -176,10 +181,14 @@ func (srv CompanyCreditAccountService) PaymentHistoryStatistics(cmd *command.Cre @@ -176,10 +181,14 @@ func (srv CompanyCreditAccountService) PaymentHistoryStatistics(cmd *command.Cre
176 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( 181 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
177 cmd.Operator) 182 cmd.Operator)
178 183
179 - var response = struct { 184 + type responseType struct {
180 RankItems interface{} `json:"rankItems"` 185 RankItems interface{} `json:"rankItems"`
181 TotalPaymentAmount interface{} `json:"totalPaymentAmount"` 186 TotalPaymentAmount interface{} `json:"totalPaymentAmount"`
182 - }{} 187 + }
  188 + var response = responseType{
  189 + RankItems: []struct{}{},
  190 + TotalPaymentAmount: 0,
  191 + }
183 cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{ 192 cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{
184 "companyId": cmd.Operator.CompanyId, 193 "companyId": cmd.Operator.CompanyId,
185 "orgId": cmd.Operator.OrgId, 194 "orgId": cmd.Operator.OrgId,
@@ -166,6 +166,9 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer @@ -166,6 +166,9 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer
166 166
167 // CooperationProjectRecommend TODO:其他公司按公开的项目查 猜你喜欢(共创项目) 167 // CooperationProjectRecommend TODO:其他公司按公开的项目查 猜你喜欢(共创项目)
168 func (srv PersonStatisticsService) CooperationProjectRecommend(projectQuery *command.ListCooperationProjectQuery) (int64, interface{}, error) { 168 func (srv PersonStatisticsService) CooperationProjectRecommend(projectQuery *command.ListCooperationProjectQuery) (int64, interface{}, error) {
  169 + if projectQuery.Operator.UserBaseId > 0 {
  170 +
  171 + }
169 creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( 172 creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
170 projectQuery.Operator) 173 projectQuery.Operator)
171 result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{ 174 result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
@@ -188,7 +188,7 @@ func (srv UserService) DepartmentsUsers(departmentsUsersQuery *query.Departments @@ -188,7 +188,7 @@ func (srv UserService) DepartmentsUsers(departmentsUsersQuery *query.Departments
188 CompanyId: departmentsUsersQuery.Operator.CompanyId, 188 CompanyId: departmentsUsersQuery.Operator.CompanyId,
189 OrganizationId: departmentsUsersQuery.Operator.OrgId, 189 OrganizationId: departmentsUsersQuery.Operator.OrgId,
190 UserType: domain.UserTypeEmployee, //TODO:是否要共创用户 190 UserType: domain.UserTypeEmployee, //TODO:是否要共创用户
191 - InEnableStatus: []int{domain.UserStatusEnable, domain.UserStatusDisable}, 191 + InEnableStatus: []int{domain.UserStatusEnable},
192 }) 192 })
193 if err != nil { 193 if err != nil {
194 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 194 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -70,11 +70,12 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -70,11 +70,12 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
70 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 70 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
71 } 71 }
72 resultApplication, err := creationCooperationGateway.CooperationApplicationsSearch(allied_creation_cooperation.ReqCooperationApplicationSearch{ 72 resultApplication, err := creationCooperationGateway.CooperationApplicationsSearch(allied_creation_cooperation.ReqCooperationApplicationSearch{
73 - CooperationProjectNumber: resultProject.CooperationProject.CooperationProjectNumber,  
74 - PageNumber: 0,  
75 - PageSize: 0,  
76 - CompanyId: resultProject.Company.CompanyId,  
77 - OrgId: int64(resultProject.Org.OrgId), 73 + CooperationProjectNumber: resultProject.CooperationProject.CooperationProjectNumber,
  74 + PageNumber: 0,
  75 + PageSize: 0,
  76 + CompanyId: resultProject.Company.CompanyId,
  77 + OrgId: int64(resultProject.Org.OrgId),
  78 + CooperationApplicationStatus: 2, //审核通过的
78 }) 79 })
79 if err != nil { 80 if err != nil {
80 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 81 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1 +package command
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "github.com/beego/beego/v2/core/validation"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  8 +)
  9 +
  10 +type ExportDataCommand struct {
  11 + //操作人
  12 + Operator domain.Operator `json:"-"`
  13 + // 业务编码
  14 + Ids []string `json:"ids"`
  15 + Where json.RawMessage `json:"where"`
  16 + // 业务编码
  17 + Code string `form:"code"`
  18 +}
  19 +
  20 +func (exportDataCommand *ExportDataCommand) Valid(validation *validation.Validation) {
  21 +
  22 +}
  23 +
  24 +func (exportDataCommand *ExportDataCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(exportDataCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + for _, validErr := range valid.Errors {
  32 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  33 + }
  34 + }
  35 + return nil
  36 +}
  37 +
  38 +func (exportDataCommand *ExportDataCommand) UnmarshalQuery(query interface{}) error {
  39 + return json.Unmarshal(exportDataCommand.Where, query)
  40 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
  8 +)
  9 +
  10 +// ExportCompanyUser 导出公司用户信息列表
  11 +func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
  12 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
  13 + result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
  14 + Limit: 10000,
  15 + CompanyId: companyUserListQuery.Operator.CompanyId,
  16 + OrganizationId: 0,
  17 + DepartmentId: 0,
  18 + UserName: companyUserListQuery.UserName,
  19 + DepName: companyUserListQuery.DepartmentName,
  20 + Phone: "",
  21 + UserType: domain.UserTypeEmployee,
  22 + InOrgIds: companyUserListQuery.Operator.OrgIds,
  23 + PullRealTime: true,
  24 + })
  25 + if err != nil {
  26 + return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
  27 + }
  28 + return ExportCompanyUserData(result.Users), nil
  29 +}
  30 +
  31 +// ExportCooperationUser 导出共创用户信息列表
  32 +func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CooperationUserListQuery) (ExportCooperationUserData, error) {
  33 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
  34 + result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
  35 + Limit: 10000,
  36 + CompanyId: companyUserListQuery.Operator.CompanyId,
  37 + OrganizationId: 0,
  38 + DepartmentId: 0,
  39 + UserName: companyUserListQuery.UserName,
  40 + CooperationCompany: companyUserListQuery.CooperationCompany,
  41 + Phone: "",
  42 + UserType: domain.UserTypeCooperation,
  43 + InOrgIds: companyUserListQuery.Operator.OrgIds,
  44 + })
  45 + if err != nil {
  46 + return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
  47 + }
  48 + return ExportCooperationUserData(result.Users), nil
  49 +}
@@ -7,7 +7,6 @@ import ( @@ -7,7 +7,6 @@ import (
7 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
8 "github.com/linmadan/egglib-go/utils/excel" 8 "github.com/linmadan/egglib-go/utils/excel"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
10 - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"  
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/domainService"
13 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 12 "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 { @@ -20,158 +19,62 @@ func NewExcelDataService(param map[string]interface{}) *ExcelDataService {
20 return &ExcelDataService{} 19 return &ExcelDataService{}
21 } 20 }
22 21
23 -// ExportCompanyUser 导出公司用户信息列表  
24 -func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {  
25 - creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)  
26 - result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{  
27 - Limit: 10000,  
28 - CompanyId: companyUserListQuery.Operator.CompanyId,  
29 - OrganizationId: 0,  
30 - DepartmentId: 0,  
31 - UserName: companyUserListQuery.UserName,  
32 - DepName: companyUserListQuery.DepartmentName,  
33 - Phone: "",  
34 - UserType: domain.UserTypeEmployee,  
35 - InOrgIds: companyUserListQuery.Operator.OrgIds, 22 +// ImportCooperationUser 导入共创用户信息
  23 +func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {
  24 + initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)
  25 + if err != nil {
  26 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  27 + }
  28 + userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
  29 + orgResult, err := userGateway.OrgGet(allied_creation_user.ReqOrgGet{
  30 + OrgId: int(importDataCommand.Operator.OrgId),
36 }) 31 })
37 if err != nil { 32 if err != nil {
38 - return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) 33 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  34 + }
  35 + excelImport := excel.NewExcelImport()
  36 + excelImport.RowBegin = 3 //第二行开始读取
  37 + excelImport.DataFields = []excel.DataField{
  38 + {EnName: "userCode", CnName: "*用户编码"},
  39 + {EnName: "userName", CnName: "*用户姓名"},
  40 + {EnName: "cooperationCompany", CnName: "合伙公司"},
  41 + {EnName: "cooperationDeadline", CnName: "合伙到期"},
  42 + {EnName: "enableStatus", CnName: "*用户状态"},
  43 + {EnName: "phone", CnName: "*手机号"},
  44 + {EnName: "email", CnName: "邮箱"},
  45 + }
  46 + excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
  47 + if err != nil {
  48 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  49 + }
  50 + users := make([]allied_creation_user.BatchAddUserItem, 0)
  51 + for _, v := range excelData {
  52 + if srv.fieldValueAllEmpty(v) {
  53 + continue
  54 + }
  55 + item := allied_creation_user.BatchAddUserItem{
  56 + CompanyId: importDataCommand.Operator.CompanyId,
  57 + UserType: domain.UserTypeCooperation,
  58 + UserCode: v["userCode"],
  59 + Org: orgResult.OrgCode,
  60 + UserName: strings.TrimSpace(v["userName"]),
  61 + Phone: strings.TrimSpace(v["phone"]),
  62 + Email: strings.TrimSpace(v["email"]),
  63 + EnableStatus: strings.TrimSpace(v["enableStatus"]),
  64 + CooperationCompany: v["cooperationCompany"],
  65 + CooperationDeadline: v["cooperationDeadline"],
  66 + }
  67 + users = append(users, item)
39 } 68 }
40 - return ExportCompanyUserData(result.Users), nil  
41 -}  
42 69
43 -// ExportCooperationUser 导出共创用户信息列表  
44 -func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCooperationUserData, error) {  
45 - creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)  
46 - result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{  
47 - Limit: 10000,  
48 - CompanyId: companyUserListQuery.Operator.CompanyId,  
49 - OrganizationId: 0,  
50 - DepartmentId: 0,  
51 - UserName: companyUserListQuery.UserName,  
52 - DepName: companyUserListQuery.DepartmentName,  
53 - Phone: "",  
54 - UserType: domain.UserTypeCooperation,  
55 - InOrgIds: companyUserListQuery.Operator.OrgIds, 70 + result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{
  71 + Users: users,
  72 + Password: initPassword,
56 }) 73 })
57 if err != nil { 74 if err != nil {
58 - return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err) 75 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
59 } 76 }
60 - return ExportCooperationUserData(result.Users), nil  
61 -}  
62 -  
63 -// ImportCompanyUser 导入公司用户信息  
64 -func (srv ExcelDataService) ImportCompanyUser2(importDataCommand *command.ImportDataCommand) (interface{}, error) {  
65 - //initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)  
66 - //if err != nil {  
67 - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
68 - //}  
69 - //excelImport := excel.NewExcelImport()  
70 - //excelImport.RowBegin = 2 //第二行开始读取  
71 - //excelImport.DataFields = []excel.DataField{  
72 - // {EnName: "UserCode", CnName: "*用户编号"},  
73 - // {EnName: "UserName", CnName: "*用户姓名"},  
74 - // {EnName: "OrganizationID", CnName: "*组织机构"},  
75 - // {EnName: "DepartmentID", CnName: "*所属部门"},  
76 - // {EnName: "Phone", CnName: "*手机号"},  
77 - // {EnName: "Email", CnName: "邮箱"},  
78 - // {EnName: "Status", CnName: "状态"},  
79 - //}  
80 - //excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)  
81 - //if err != nil {  
82 - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
83 - //}  
84 - //users := make([]allied_creation_user.BatchAddUserItem, 0)  
85 - //for _, v := range excelData {  
86 - // item := allied_creation_user.BatchAddUserItem{  
87 - // CompanyID: importDataCommand.Operator.CompanyId,  
88 - // UserType: domain.UserTypeEmployee,  
89 - // UserCode: v["UserCode"],  
90 - // OrganizationID: 0,  
91 - // DepartmentID: 0,  
92 - // UserInfo: allied_creation_user.BatchAddUserItemUserInfo{  
93 - // UserName: v["UserName"],  
94 - // Phone: v["Phone"],  
95 - // Email: v["Email"],  
96 - // },  
97 - // CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{},  
98 - // }  
99 - // item.OrganizationID, err = strconv.Atoi(v["OrganizationID"])  
100 - // if err != nil {  
101 - // return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("用户:%v 组织值:%v 类型无效(数值类型)", item.UserInfo.UserName, item.OrganizationID))  
102 - // }  
103 - // item.DepartmentID, err = strconv.Atoi(v["DepartmentID"])  
104 - // if err != nil {  
105 - // return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("用户:%v 部门值:%v 类型无效(数值类型)", item.UserInfo.UserName, item.DepartmentID))  
106 - // }  
107 - // users = append(users, item)  
108 - //}  
109 - //userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)  
110 - //result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{  
111 - // Users: users,  
112 - // Password: initPassword,  
113 - //})  
114 - //if err != nil {  
115 - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
116 - //}  
117 - //return result, nil  
118 - return nil, nil  
119 -}  
120 -  
121 -// ImportCooperationUser 导入共创用户信息  
122 -func (srv ExcelDataService) ImportCooperationUser(importDataCommand *command.ImportDataCommand) (interface{}, error) {  
123 - //initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)  
124 - //if err != nil {  
125 - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
126 - //}  
127 - //excelImport := excel.NewExcelImport()  
128 - //excelImport.RowBegin = 2 //第二行开始读取  
129 - //excelImport.DataFields = []excel.DataField{  
130 - // {EnName: "UserCode", CnName: "*用户编号"},  
131 - // {EnName: "UserName", CnName: "*用户姓名"},  
132 - // {EnName: "CooperationCompany", CnName: "*合伙公司"},  
133 - // {EnName: "CooperationDeadline", CnName: "*合伙到期"},  
134 - // {EnName: "Phone", CnName: "*手机号"},  
135 - // {EnName: "Email", CnName: "邮箱"},  
136 - //}  
137 - //excelData, err := excelImport.OpenExcelFromIoReader(importDataCommand.Reader)  
138 - //if err != nil {  
139 - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
140 - //}  
141 - //users := make([]allied_creation_user.BatchAddUserItem, 0)  
142 - //var fail int  
143 - //for _, v := range excelData {  
144 - // item := allied_creation_user.BatchAddUserItem{  
145 - // CompanyID: importDataCommand.Operator.CompanyId,  
146 - // UserType: domain.UserTypeCooperation,  
147 - // UserCode: v["UserCode"],  
148 - // OrganizationID: int(importDataCommand.Operator.OrgId),  
149 - // UserInfo: allied_creation_user.BatchAddUserItemUserInfo{  
150 - // UserName: v["UserName"],  
151 - // Phone: v["Phone"],  
152 - // Email: v["Email"],  
153 - // },  
154 - // CooperationInfo: allied_creation_user.BatchAddUserItemCooperationInfo{  
155 - // CooperationCompany: v["CooperationCompany"],  
156 - // },  
157 - // }  
158 - // item.CooperationInfo.CooperationDeadline, err = time.Parse("2006-01-02", v["CooperationDeadline"])  
159 - // if err != nil {  
160 - // fail++  
161 - // continue  
162 - // }  
163 - // users = append(users, item)  
164 - //}  
165 - //userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)  
166 - //result, err := userGateway.UserBatchAdd(allied_creation_user.ReqBatchAddUser{  
167 - // Users: users,  
168 - // Password: initPassword,  
169 - //})  
170 - //if err != nil {  
171 - // return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
172 - //}  
173 - //return result, nil  
174 - return nil, nil 77 + return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil
175 } 78 }
176 79
177 // ImportCompanyUser 导入公司用户信息 80 // ImportCompanyUser 导入公司用户信息
@@ -197,21 +100,19 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD @@ -197,21 +100,19 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD
197 } 100 }
198 users := make([]allied_creation_user.BatchAddUserItem, 0) 101 users := make([]allied_creation_user.BatchAddUserItem, 0)
199 for _, v := range excelData { 102 for _, v := range excelData {
  103 + if srv.fieldValueAllEmpty(v) {
  104 + continue
  105 + }
200 item := allied_creation_user.BatchAddUserItem{ 106 item := allied_creation_user.BatchAddUserItem{
201 CompanyId: importDataCommand.Operator.CompanyId, 107 CompanyId: importDataCommand.Operator.CompanyId,
202 UserType: domain.UserTypeEmployee, 108 UserType: domain.UserTypeEmployee,
203 - UserCode: v["userCode"],  
204 - Org: v["org"],  
205 - Department: v["department"],  
206 - UserName: v["userName"],  
207 - Phone: v["phone"],  
208 - Email: v["email"],  
209 - EnableStatus: domain.UserStatusEnable,  
210 - }  
211 - if status, ok := v["status"]; ok {  
212 - if strings.TrimSpace(status) != "启用" {  
213 - item.EnableStatus = domain.UserStatusDisable  
214 - } 109 + UserCode: strings.TrimSpace(v["userCode"]),
  110 + Org: strings.TrimSpace(v["org"]),
  111 + Department: strings.TrimSpace(v["department"]),
  112 + UserName: strings.TrimSpace(v["userName"]),
  113 + Phone: strings.TrimSpace(v["phone"]),
  114 + Email: strings.TrimSpace(v["email"]),
  115 + EnableStatus: strings.TrimSpace(v["enableStatus"]),
215 } 116 }
216 users = append(users, item) 117 users = append(users, item)
217 } 118 }
@@ -223,9 +124,10 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD @@ -223,9 +124,10 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD
223 if err != nil { 124 if err != nil {
224 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 125 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
225 } 126 }
226 - return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(excelData)), nil 127 + return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil
227 } 128 }
228 129
  130 +// ImportOrganization 导入组织
229 func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, error) { 131 func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, error) {
230 excelImport := excel.NewExcelImport() 132 excelImport := excel.NewExcelImport()
231 excelImport.RowBegin = 3 //第二行开始读取 133 excelImport.RowBegin = 3 //第二行开始读取
@@ -240,6 +142,9 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import @@ -240,6 +142,9 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import
240 } 142 }
241 items := make([]allied_creation_user.BatchAddOrgItem, 0) 143 items := make([]allied_creation_user.BatchAddOrgItem, 0)
242 for _, v := range excelData { 144 for _, v := range excelData {
  145 + if srv.fieldValueAllEmpty(v) {
  146 + continue
  147 + }
243 item := allied_creation_user.BatchAddOrgItem{ 148 item := allied_creation_user.BatchAddOrgItem{
244 CompanyId: importDataCommand.Operator.CompanyId, 149 CompanyId: importDataCommand.Operator.CompanyId,
245 OrgCode: v["orgCode"], 150 OrgCode: v["orgCode"],
@@ -255,7 +160,7 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import @@ -255,7 +160,7 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import
255 if err != nil { 160 if err != nil {
256 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 161 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
257 } 162 }
258 - return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(excelData)), nil 163 + return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(items)), nil
259 } 164 }
260 165
261 // 导入结果 166 // 导入结果
@@ -282,15 +187,25 @@ func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, fa @@ -282,15 +187,25 @@ func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, fa
282 return result 187 return result
283 } 188 }
284 189
285 -// ImportCompanyUser 导入公司用户信息 190 +func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool {
  191 + isAllEmpty := true
  192 + for _, v := range param {
  193 + value := strings.TrimSpace(v)
  194 + if len(value) > 0 {
  195 + isAllEmpty = false
  196 + }
  197 + }
  198 + return isAllEmpty
  199 +}
  200 +
  201 +// FileImportTemplate 导入模板
286 func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) { 202 func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) {
287 var mapTemplate = map[string]string{ 203 var mapTemplate = map[string]string{
288 - domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",  
289 - domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx",  
290 - domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807770_sBtA4dYcmESZy6Q2ycfGSCKGdFtBETQZ.xlsx",  
291 - // 模板待更新  
292 - domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",  
293 - domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx", 204 + domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",
  205 + domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx",
  206 + domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743206_NPYTKw6RGhXn4TpYNEQhGGdCkXKXTnxM.xlsx",
  207 + domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210926/object/1632635345_SbfzmkXjQHhCwPw4MB7zb5EBBtdp2MSE.xlsx",
  208 + domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx",
294 } 209 }
295 var url string 210 var url string
296 var ok bool 211 var ok bool
@@ -5,7 +5,7 @@ import ( @@ -5,7 +5,7 @@ import (
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
6 ) 6 )
7 7
8 -//exportCompanyUserData 导出公司用户数据 8 +// ExportCompanyUserData 导出公司用户数据
9 type ExportCompanyUserData []allied_creation_user.UserDetail 9 type ExportCompanyUserData []allied_creation_user.UserDetail
10 10
11 var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil) 11 var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
@@ -69,7 +69,7 @@ func (data ExportCompanyUserData) TableTitle() []string { @@ -69,7 +69,7 @@ func (data ExportCompanyUserData) TableTitle() []string {
69 return nil 69 return nil
70 } 70 }
71 71
72 -//exportCompanyUserData 导出共创用户数据 72 +//ExportCooperationUserData 导出共创用户数据
73 type ExportCooperationUserData []allied_creation_user.UserDetail 73 type ExportCooperationUserData []allied_creation_user.UserDetail
74 74
75 var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil) 75 var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
@@ -78,10 +78,12 @@ func (data ExportCooperationUserData) DataFieldList() []excel.DataField { @@ -78,10 +78,12 @@ func (data ExportCooperationUserData) DataFieldList() []excel.DataField {
78 return []excel.DataField{ 78 return []excel.DataField{
79 {EnName: "UserCode", CnName: "用户编码"}, 79 {EnName: "UserCode", CnName: "用户编码"},
80 {EnName: "UserName", CnName: "用户姓名"}, 80 {EnName: "UserName", CnName: "用户姓名"},
81 - {EnName: "CooperationCompany", CnName: "合作公司"},  
82 - {EnName: "CooperationDeadline", CnName: "合作到期"},  
83 {EnName: "Phone", CnName: "手机号"}, 81 {EnName: "Phone", CnName: "手机号"},
84 - {EnName: "Email", CnName: "邮箱"}, 82 + {EnName: "CooperationCompany", CnName: "共创公司"},
  83 + {EnName: "CooperationDeadline", CnName: "共创到期"},
  84 + {EnName: "EnableStatus", CnName: "状态"},
  85 +
  86 + //{EnName: "Email", CnName: "邮箱"},
85 } 87 }
86 } 88 }
87 89
@@ -97,11 +99,27 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value @@ -97,11 +99,27 @@ func (data ExportCooperationUserData) CellValue(index int, enName string) (value
97 case "CooperationCompany": 99 case "CooperationCompany":
98 return data[index].CooperationInfo.CooperationCompany 100 return data[index].CooperationInfo.CooperationCompany
99 case "CooperationDeadline": 101 case "CooperationDeadline":
  102 + if data[index].CooperationInfo.CooperationDeadline.IsZero() || data[index].CooperationInfo.CooperationDeadline.Unix() == 0 {
  103 + return ""
  104 + }
100 return data[index].CooperationInfo.CooperationDeadline.Format("2006-01-02") 105 return data[index].CooperationInfo.CooperationDeadline.Format("2006-01-02")
101 case "Phone": 106 case "Phone":
102 return data[index].UserInfo.Phone 107 return data[index].UserInfo.Phone
103 case "Email": 108 case "Email":
104 return data[index].UserInfo.Email 109 return data[index].UserInfo.Email
  110 + case "EnableStatus":
  111 + status := data[index].EnableStatus
  112 + statusName := ""
  113 + // 状态(1:启用 2:禁用 3:注销)
  114 + switch status {
  115 + case 1:
  116 + statusName = "启用"
  117 + case 2:
  118 + statusName = "禁用"
  119 + case 3:
  120 + statusName = "注销"
  121 + }
  122 + return statusName
105 } 123 }
106 return nil 124 return nil
107 } 125 }
@@ -18,6 +18,7 @@ type OrgItem struct { @@ -18,6 +18,7 @@ type OrgItem struct {
18 type DepartmentUsersDto struct { 18 type DepartmentUsersDto struct {
19 Departments []*Department `json:"departments,omitempty"` 19 Departments []*Department `json:"departments,omitempty"`
20 Users []interface{} `json:"users,omitempty"` 20 Users []interface{} `json:"users,omitempty"`
  21 + Applicants []interface{} `json:"applicants,omitempty"`
21 } 22 }
22 23
23 type Department struct { 24 type Department struct {
@@ -27,9 +28,10 @@ type Department struct { @@ -27,9 +28,10 @@ type Department struct {
27 } 28 }
28 29
29 type User struct { 30 type User struct {
30 - UserID int `json:"userId,string"`  
31 - UserCode string `json:"userCode"`  
32 - UserInfo map[string]interface{} `json:"userInfo"` 31 + UserID int `json:"userId,string"`
  32 + UserCode string `json:"userCode"`
  33 + UserInfo map[string]interface{} `json:"userInfo"`
  34 + Department interface{} `json:"department,omitempty"`
33 } 35 }
34 36
35 func (dto *DepartmentUsersDto) LoadDto(dataType int, subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error { 37 func (dto *DepartmentUsersDto) LoadDto(dataType int, subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error {
@@ -12,6 +12,8 @@ type DepartmentsUsersQuery struct { @@ -12,6 +12,8 @@ type DepartmentsUsersQuery struct {
12 Operator domain.Operator `json:"-"` 12 Operator domain.Operator `json:"-"`
13 // 类型0:部门用户列表 1:全部用户列表(不包含部门) 13 // 类型0:部门用户列表 1:全部用户列表(不包含部门)
14 Type int `json:"type"` 14 Type int `json:"type"`
  15 + // 共创项目ID - 获取项目申请人列表
  16 + CooperationProjectId int `json:"cooperationProjectId,string"`
15 } 17 }
16 18
17 func (departmentsUsersQuery *DepartmentsUsersQuery) Valid(validation *validation.Validation) { 19 func (departmentsUsersQuery *DepartmentsUsersQuery) Valid(validation *validation.Validation) {
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
4 "strconv" 5 "strconv"
5 6
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
@@ -174,6 +175,44 @@ func (orgsService OrgsService) DepartmentsUsers(departmentsUsersQuery *query.Dep @@ -174,6 +175,44 @@ func (orgsService OrgsService) DepartmentsUsers(departmentsUsersQuery *query.Dep
174 if err := departmentUsersDto.LoadDto(departmentsUsersQuery.Type, orgs, users); err != nil { 175 if err := departmentUsersDto.LoadDto(departmentsUsersQuery.Type, orgs, users); err != nil {
175 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 176 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
176 } 177 }
  178 +
  179 + // 项目申请人
  180 + if departmentsUsersQuery.CooperationProjectId != 0 {
  181 + creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(departmentsUsersQuery.Operator)
  182 + resultProject, err := creationCooperationGateway.CooperationProjectGet(allied_creation_cooperation.ReqCooperationProjectGet{
  183 + CooperationProjectId: departmentsUsersQuery.CooperationProjectId,
  184 + })
  185 + if err != nil {
  186 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  187 + }
  188 + resultApplication, err := creationCooperationGateway.CooperationApplicationsSearch(allied_creation_cooperation.ReqCooperationApplicationSearch{
  189 + CooperationProjectNumber: resultProject.CooperationProject.CooperationProjectNumber,
  190 + PageNumber: 0,
  191 + PageSize: 1000,
  192 + CompanyId: resultProject.Company.CompanyId,
  193 + OrgId: int64(resultProject.Org.OrgId),
  194 + CooperationApplicationStatus: 2, //审核通过的
  195 + })
  196 + if err != nil {
  197 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  198 + }
  199 + applications := make([]interface{}, 0)
  200 + for i := range resultApplication.Grid.List {
  201 + item := resultApplication.Grid.List[i]
  202 + user := dto.User{
  203 + UserID: item.CooperationApplicationApplicant.UserID,
  204 + UserCode: item.CooperationApplicationApplicant.UserInfo.UserCode,
  205 + UserInfo: map[string]interface{}{
  206 + "userName": item.CooperationApplicationApplicant.UserInfo.UserName,
  207 + "phone": item.CooperationApplicationApplicant.UserInfo.UserPhone,
  208 + },
  209 + Department: item.CooperationApplicationApplicant.Department,
  210 + }
  211 + applications = append(applications, user)
  212 + }
  213 + departmentUsersDto.Applicants = applications
  214 + }
  215 +
177 return departmentUsersDto, nil 216 return departmentUsersDto, nil
178 } 217 }
179 218
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/beego/beego/v2/core/validation"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  7 +)
  8 +
  9 +// 共创项目用户查询
  10 +type CooperationProjectUsersQuery struct {
  11 + //操作人
  12 + Operator domain.Operator `json:"-"`
  13 + // 共创项目ID - 获取项目申请人列表
  14 + CooperationProjectId int `json:"cooperationProjectId,string"`
  15 +}
  16 +
  17 +func (departmentsUsersQuery *CooperationProjectUsersQuery) Valid(validation *validation.Validation) {
  18 +
  19 +}
  20 +
  21 +func (departmentsUsersQuery *CooperationProjectUsersQuery) ValidateQuery() error {
  22 + valid := validation.Validation{}
  23 + b, err := valid.Valid(departmentsUsersQuery)
  24 + if err != nil {
  25 + return err
  26 + }
  27 + if !b {
  28 + for _, validErr := range valid.Errors {
  29 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  30 + }
  31 + }
  32 + return nil
  33 +}
@@ -3,6 +3,7 @@ package service @@ -3,6 +3,7 @@ package service
3 import ( 3 import (
4 "crypto/sha1" 4 "crypto/sha1"
5 "fmt" 5 "fmt"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
6 "strconv" 7 "strconv"
7 "time" 8 "time"
8 9
@@ -570,3 +571,46 @@ func (usersService *UsersService) GetInitPassword(operator domain.Operator) (str @@ -570,3 +571,46 @@ func (usersService *UsersService) GetInitPassword(operator domain.Operator) (str
570 password = fmt.Sprintf("%x", sha1.Sum([]byte(reqResult.Value))) 571 password = fmt.Sprintf("%x", sha1.Sum([]byte(reqResult.Value)))
571 return password, reqResult.Value, err 572 return password, reqResult.Value, err
572 } 573 }
  574 +
  575 +// SelectorCooperationProjectUsers 共创项目用户下拉列表
  576 +func (usersService *UsersService) SelectorCooperationProjectUsers(q *query.CooperationProjectUsersQuery) (interface{}, error) {
  577 + applications := make([]interface{}, 0)
  578 + // 项目申请人
  579 + if q.CooperationProjectId != 0 {
  580 + creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(q.Operator)
  581 + resultProject, err := creationCooperationGateway.CooperationProjectGet(allied_creation_cooperation.ReqCooperationProjectGet{
  582 + CooperationProjectId: q.CooperationProjectId,
  583 + })
  584 + if err != nil {
  585 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  586 + }
  587 + resultApplication, err := creationCooperationGateway.CooperationApplicationsSearch(allied_creation_cooperation.ReqCooperationApplicationSearch{
  588 + CooperationProjectNumber: resultProject.CooperationProject.CooperationProjectNumber,
  589 + PageNumber: 0,
  590 + PageSize: 1000,
  591 + CompanyId: resultProject.Company.CompanyId,
  592 + OrgId: int64(resultProject.Org.OrgId),
  593 + CooperationApplicationStatus: 2, //审核通过的
  594 + })
  595 + if err != nil {
  596 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  597 + }
  598 +
  599 + for i := range resultApplication.Grid.List {
  600 + item := resultApplication.Grid.List[i]
  601 + user := map[string]interface{}{
  602 + "userId": item.CooperationApplicationApplicant.UserID,
  603 + "userCode": item.CooperationApplicationApplicant.UserInfo.UserCode,
  604 + "userInfo": map[string]interface{}{
  605 + "userName": item.CooperationApplicationApplicant.UserInfo.UserName,
  606 + "phone": item.CooperationApplicationApplicant.UserInfo.UserPhone,
  607 + },
  608 + "department": item.CooperationApplicationApplicant.Department,
  609 + }
  610 + applications = append(applications, user)
  611 + }
  612 + }
  613 + return map[string]interface{}{
  614 + "applicants": applications,
  615 + }, nil
  616 +}
@@ -62,3 +62,14 @@ const ( @@ -62,3 +62,14 @@ const (
62 // 导入退货订单 62 // 导入退货订单
63 ImportDividendsReturnOrders = "BUSINESS_ALLIED-CREATION_BONUS_RETURN" 63 ImportDividendsReturnOrders = "BUSINESS_ALLIED-CREATION_BONUS_RETURN"
64 ) 64 )
  65 +
  66 +const (
  67 + // 导入公司用户
  68 + ExportCompanyUser = "ExportCompanyUser"
  69 + // 导入共创用户
  70 + ExportCooperationUser = "ExportCooperationUser"
  71 +)
  72 +
  73 +const (
  74 + CooperationUserDepartmentName = "共创用户"
  75 +)
@@ -173,6 +173,20 @@ type ( @@ -173,6 +173,20 @@ type (
173 173
174 //查询共创项目 174 //查询共创项目
175 type ( 175 type (
  176 + SearchCooperationProjectExtQuery struct {
  177 + // 公司ID,通过集成REST上下文获取
  178 + ExtCompanyId int64 `cname:"公司ID" json:"extCompanyId,omitempty"`
  179 + // 组织机构ID
  180 + ExtOrgId int64 `cname:"组织机构ID" json:"extOrgId,omitempty"`
  181 + // 关联的组织机构ID列表
  182 + ExtOrgIds []int64 `cname:"关联的组织机构ID列表" json:"extOrgIds,omitempty"`
  183 + // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
  184 + ExtUserId int64 `cname:"用户ID" json:"extUserId,omitempty"`
  185 + // 用户基础数据id
  186 + ExtUserBaseId int64 `cname:"用户基础数据ID" json:"extUserBaseId,omitempty"`
  187 + // 共创项目承接对象,1员工,2共创用户,3公开,可多选
  188 + ExtCooperationProjectUndertakerTypes []int32 `json:"extCooperationProjectUndertakerTypes"`
  189 + }
176 ReqCooperationProjectSearch struct { 190 ReqCooperationProjectSearch struct {
177 PageNumber int `json:"pageNumber"` 191 PageNumber int `json:"pageNumber"`
178 PageSize int `json:"pageSize"` 192 PageSize int `json:"pageSize"`
@@ -194,6 +208,10 @@ type ( @@ -194,6 +208,10 @@ type (
194 UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"` 208 UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
195 // 共创项目承接对象,1员工,2共创用户,4公开,可以多选 209 // 共创项目承接对象,1员工,2共创用户,4公开,可以多选
196 CooperationProjectUndertakerType int32 `json:"cooperationProjectUndertakerType"` 210 CooperationProjectUndertakerType int32 `json:"cooperationProjectUndertakerType"`
  211 + // 额外的查询条件 0:不需要额外查询 1:额外查询
  212 + SearchCooperationProjectExtQueriesFlag int `cname:"额外的查询条件标识" json:"searchCooperationProjectExtQueriesFlag"`
  213 + // 额外的查询条件
  214 + SearchCooperationProjectExtQueries []*SearchCooperationProjectExtQuery `cname:"额外的查询条件" json:"searchCooperationProjectExtQueries"`
197 } 215 }
198 DataCooperationProjectSearchItem struct { 216 DataCooperationProjectSearchItem struct {
199 CooperationProjectID string `json:"cooperationProjectId"` 217 CooperationProjectID string `json:"cooperationProjectId"`
@@ -43,6 +43,8 @@ type UserDetail struct { @@ -43,6 +43,8 @@ type UserDetail struct {
43 Department *struct { 43 Department *struct {
44 DepartmentId int `json:"departmentId"` 44 DepartmentId int `json:"departmentId"`
45 DepartmentName string `json:"departmentName"` 45 DepartmentName string `json:"departmentName"`
  46 + // 部门编号
  47 + DepartmentNumber string `json:"departmentNumber"`
46 } `json:"department,omitempty"` 48 } `json:"department,omitempty"`
47 UserRole []struct { 49 UserRole []struct {
48 RoleID int `json:"roleId"` 50 RoleID int `json:"roleId"`
@@ -393,11 +395,11 @@ type ( @@ -393,11 +395,11 @@ type (
393 // 部门编码 395 // 部门编码
394 Department string `json:"department,omitempty"` 396 Department string `json:"department,omitempty"`
395 // 状态(1:启用 2:禁用 3:注销) 397 // 状态(1:启用 2:禁用 3:注销)
396 - EnableStatus int `json:"enableStatus,omitempty"` 398 + EnableStatus string `json:"enableStatus,omitempty"`
397 // 共创公司 cooperationCompany 399 // 共创公司 cooperationCompany
398 CooperationCompany string `json:"cooperationCompany"` 400 CooperationCompany string `json:"cooperationCompany"`
399 // 共创到期时间 (yyyy-MM-dd) cooperationDeadline 401 // 共创到期时间 (yyyy-MM-dd) cooperationDeadline
400 - CooperationDeadline time.Time `json:"cooperationDeadline"` 402 + CooperationDeadline string `json:"cooperationDeadline"`
401 // 失败理由 403 // 失败理由
402 FailReason string `json:"failReason"` 404 FailReason string `json:"failReason"`
403 } 405 }
@@ -97,8 +97,8 @@ func (controller *BaseController) GetOperator() domain.Operator { @@ -97,8 +97,8 @@ func (controller *BaseController) GetOperator() domain.Operator {
97 OrgIds: loginToken.OrgIds, 97 OrgIds: loginToken.OrgIds,
98 } 98 }
99 99
100 - // TODO:打印测试日志  
101 - log.Logger.Debug("operator " + json.MarshalToString(op)) 100 + // 打印测试日志
  101 + // log.Logger.Debug("operator " + json.MarshalToString(op))
102 return op 102 return op
103 } 103 }
104 104
@@ -45,60 +45,6 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin @@ -45,60 +45,6 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin
45 return isAllEmpty 45 return isAllEmpty
46 } 46 }
47 47
48 -// ExportCompanyUser 导出公司用户  
49 -func (controller ExcelDataController) ExportCompanyUser() {  
50 - excelService := service.NewExcelDataService(nil)  
51 - companyUserListQuery := &query.CompanyUserListQuery{}  
52 - err := controller.Unmarshal(companyUserListQuery)  
53 - if err != nil {  
54 - log.Logger.Debug("json err:" + err.Error())  
55 - controller.Response(nil, err)  
56 - return  
57 - }  
58 - companyUserListQuery.Operator = controller.GetOperator()  
59 - data, err := excelService.ExportCompanyUser(companyUserListQuery)  
60 - if err != nil {  
61 - log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())  
62 - controller.Response(nil, err)  
63 - return  
64 - }  
65 - excelTool := excel.NewExcelExport()  
66 - err = excelTool.ExportData(data, "")  
67 - if err != nil {  
68 - log.Logger.Debug("excelTool.ExportData err:" + err.Error())  
69 - controller.Response(nil, err)  
70 - return  
71 - }  
72 - controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")  
73 -}  
74 -  
75 -// ExportCooperationUser 导出共创用户  
76 -func (controller ExcelDataController) ExportCooperationUser() {  
77 - excelService := service.NewExcelDataService(nil)  
78 - companyUserListQuery := &query.CompanyUserListQuery{}  
79 - err := controller.Unmarshal(companyUserListQuery)  
80 - if err != nil {  
81 - log.Logger.Debug("json err:" + err.Error())  
82 - controller.Response(nil, err)  
83 - return  
84 - }  
85 - companyUserListQuery.Operator = controller.GetOperator()  
86 - data, err := excelService.ExportCooperationUser(companyUserListQuery)  
87 - if err != nil {  
88 - log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())  
89 - controller.Response(nil, err)  
90 - return  
91 - }  
92 - excelTool := excel.NewExcelExport()  
93 - err = excelTool.ExportData(data, "")  
94 - if err != nil {  
95 - log.Logger.Debug("excelTool.ExportData err:" + err.Error())  
96 - controller.Response(nil, err)  
97 - return  
98 - }  
99 - controller.responseExcelByFile(controller.Ctx, excelTool, "导出共创用户")  
100 -}  
101 -  
102 // ImportDividendsOrder 导入分红订单 48 // ImportDividendsOrder 导入分红订单
103 func (controller ExcelDataController) ImportDividendsOrder() { 49 func (controller ExcelDataController) ImportDividendsOrder() {
104 importDividendsOrder(controller) 50 importDividendsOrder(controller)
@@ -276,3 +222,69 @@ func (controller ExcelDataController) FileImportTemplate() { @@ -276,3 +222,69 @@ func (controller ExcelDataController) FileImportTemplate() {
276 data, err := excelService.FileImportTemplate(cmd) 222 data, err := excelService.FileImportTemplate(cmd)
277 controller.Response(data, err) 223 controller.Response(data, err)
278 } 224 }
  225 +
  226 +// FileExport 文件导出
  227 +func (controller ExcelDataController) FileExport() {
  228 + fileExport(controller, "")
  229 +}
  230 +
  231 +func fileExport(controller ExcelDataController, code string) {
  232 + // 1.读取command
  233 + exportDataCommand := &command.ExportDataCommand{}
  234 + err := controller.Unmarshal(exportDataCommand)
  235 + if err != nil {
  236 + log.Logger.Debug("json err:" + err.Error())
  237 + controller.Response(nil, err)
  238 + return
  239 + }
  240 + exportDataCommand.Operator = controller.GetOperator()
  241 +
  242 + if exportDataCommand.Code == "" && code != "" {
  243 + exportDataCommand.Code = code
  244 + }
  245 + // 2.读取data
  246 + var data excel.ExcelMaker
  247 + var filename string
  248 + var excelService = service.NewExcelDataService(nil)
  249 + switch exportDataCommand.Code {
  250 + case domain.ExportCompanyUser:
  251 + companyUserListQuery := &query.CompanyUserListQuery{}
  252 + exportDataCommand.UnmarshalQuery(companyUserListQuery)
  253 + companyUserListQuery.Operator = exportDataCommand.Operator
  254 + data, err = excelService.ExportCompanyUser(companyUserListQuery)
  255 + filename = "导出公司用户"
  256 + case domain.ExportCooperationUser:
  257 + companyUserListQuery := &query.CooperationUserListQuery{}
  258 + exportDataCommand.UnmarshalQuery(companyUserListQuery)
  259 + companyUserListQuery.Operator = exportDataCommand.Operator
  260 + data, err = excelService.ExportCooperationUser(companyUserListQuery)
  261 + filename = "导出共创用户"
  262 + default:
  263 + err = fmt.Errorf("export type :%v not exists", exportDataCommand.Code)
  264 + }
  265 + if err != nil {
  266 + log.Logger.Debug("excelService.Export err:" + err.Error())
  267 + controller.Response(nil, err)
  268 + return
  269 + }
  270 +
  271 + // 3.返回文件
  272 + excelTool := excel.NewExcelExport()
  273 + err = excelTool.ExportData(data, "")
  274 + if err != nil {
  275 + log.Logger.Debug("excelTool.ExportData err:" + err.Error())
  276 + controller.Response(nil, err)
  277 + return
  278 + }
  279 + controller.responseExcelByFile(controller.Ctx, excelTool, filename)
  280 +}
  281 +
  282 +// ExportCompanyUser 导出公司用户
  283 +func (controller ExcelDataController) ExportCompanyUser() {
  284 + fileExport(controller, domain.ExportCompanyUser)
  285 +}
  286 +
  287 +// ExportCooperationUser 导出共创用户
  288 +func (controller ExcelDataController) ExportCooperationUser() {
  289 + fileExport(controller, domain.ExportCooperationUser)
  290 +}
@@ -157,3 +157,13 @@ func (controller *UsersController) SelectorCompanyOrgAll() { @@ -157,3 +157,13 @@ func (controller *UsersController) SelectorCompanyOrgAll() {
157 _, data, err := usersService.SelectorCompanyOrgAll(selectorQuery) 157 _, data, err := usersService.SelectorCompanyOrgAll(selectorQuery)
158 controller.Response(data, err) 158 controller.Response(data, err)
159 } 159 }
  160 +
  161 +//CompanyOrgSelector 全组织部门选择表
  162 +func (controller *UsersController) SelectorCooperationProjectUsers() {
  163 + usersService := service.NewUsersService(nil)
  164 + selectorQuery := &query.CooperationProjectUsersQuery{}
  165 + controller.Unmarshal(selectorQuery)
  166 + selectorQuery.Operator = controller.GetOperator()
  167 + data, err := usersService.SelectorCooperationProjectUsers(selectorQuery)
  168 + controller.Response(data, err)
  169 +}
@@ -13,5 +13,6 @@ func init() { @@ -13,5 +13,6 @@ func init() {
13 web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder") 13 web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder")
14 14
15 web.Router("/v1/web/file-import", &web_client.ExcelDataController{}, "Post:FileImport") 15 web.Router("/v1/web/file-import", &web_client.ExcelDataController{}, "Post:FileImport")
  16 + web.Router("/v1/web/file-export", &web_client.ExcelDataController{}, "Post:FileExport")
16 web.Router("/v1/web/file-import-template/:code", &web_client.ExcelDataController{}, "Get:FileImportTemplate") 17 web.Router("/v1/web/file-import-template/:code", &web_client.ExcelDataController{}, "Get:FileImportTemplate")
17 } 18 }
@@ -21,4 +21,6 @@ func init() { @@ -21,4 +21,6 @@ func init() {
21 web.Router("/v1/web/users/selector/org", &web_client.UsersController{}, "Post:SelectorCompanyOrg") 21 web.Router("/v1/web/users/selector/org", &web_client.UsersController{}, "Post:SelectorCompanyOrg")
22 web.Router("/v1/web/users/selector/role", &web_client.UsersController{}, "Post:SelectorCompanyRole") 22 web.Router("/v1/web/users/selector/role", &web_client.UsersController{}, "Post:SelectorCompanyRole")
23 web.Router("/v1/web/users/selector/org/all", &web_client.UsersController{}, "Post:SelectorCompanyOrgAll") 23 web.Router("/v1/web/users/selector/org/all", &web_client.UsersController{}, "Post:SelectorCompanyOrgAll")
  24 +
  25 + web.Router("/v1/web/users/selector/cooperation-project-users", &web_client.UsersController{}, "Post:SelectorCooperationProjectUsers")
24 } 26 }
@@ -13,13 +13,56 @@ func PKCS5Padding(plaintext []byte, blockSize int) []byte { @@ -13,13 +13,56 @@ func PKCS5Padding(plaintext []byte, blockSize int) []byte {
13 } 13 }
14 14
15 //@brief:去除填充数据 15 //@brief:去除填充数据
16 -func PKCS5UnPadding(origData []byte) []byte { 16 +func PKCS5UnPadding(origData []byte, blockSize int) []byte {
17 length := len(origData) 17 length := len(origData)
18 unpadding := int(origData[length-1]) 18 unpadding := int(origData[length-1])
19 return origData[:(length - unpadding)] 19 return origData[:(length - unpadding)]
20 } 20 }
21 21
22 -//@brief:AES加密 22 +// PKCS7Padding right-pads the given byte slice with 1 to n bytes, where
  23 +// n is the block size. The size of the result is x times n, where x
  24 +// is at least 1.
  25 +func PKCS7Padding(b []byte, blockSize int) []byte {
  26 + if blockSize <= 0 {
  27 + return nil
  28 + }
  29 + if b == nil || len(b) == 0 {
  30 + return nil
  31 + }
  32 + n := blockSize - (len(b) % blockSize)
  33 + pb := make([]byte, len(b)+n)
  34 + copy(pb, b)
  35 + copy(pb[len(b):], bytes.Repeat([]byte{byte(n)}, n))
  36 + return pb
  37 +}
  38 +
  39 +// PKCS7UnPadding validates and unpads data from the given bytes slice.
  40 +// The returned value will be 1 to n bytes smaller depending on the
  41 +// amount of padding, where n is the block size.
  42 +func PKCS7UnPadding(b []byte, blockSize int) []byte {
  43 + if blockSize <= 0 {
  44 + return nil
  45 + }
  46 + if b == nil || len(b) == 0 {
  47 + return nil
  48 + }
  49 + if len(b)%blockSize != 0 {
  50 + return nil
  51 + }
  52 + c := b[len(b)-1]
  53 + n := int(c)
  54 + if n == 0 || n > len(b) {
  55 + return nil
  56 + }
  57 + for i := 0; i < n; i++ {
  58 + if b[len(b)-n+i] != c {
  59 + return nil
  60 + }
  61 + }
  62 + return b[:len(b)-n]
  63 +}
  64 +
  65 +// AES加密
23 func AesEncrypt(origData, key []byte) ([]byte, error) { 66 func AesEncrypt(origData, key []byte) ([]byte, error) {
24 block, err := aes.NewCipher(key) 67 block, err := aes.NewCipher(key)
25 if err != nil { 68 if err != nil {
@@ -28,14 +71,14 @@ func AesEncrypt(origData, key []byte) ([]byte, error) { @@ -28,14 +71,14 @@ func AesEncrypt(origData, key []byte) ([]byte, error) {
28 71
29 //AES分组长度为128位,所以blockSize=16,单位字节 72 //AES分组长度为128位,所以blockSize=16,单位字节
30 blockSize := block.BlockSize() 73 blockSize := block.BlockSize()
31 - origData = PKCS5Padding(origData, blockSize) 74 + origData = PKCS7Padding(origData, blockSize)
32 blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节 75 blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节
33 crypted := make([]byte, len(origData)) 76 crypted := make([]byte, len(origData))
34 blockMode.CryptBlocks(crypted, origData) 77 blockMode.CryptBlocks(crypted, origData)
35 return crypted, nil 78 return crypted, nil
36 } 79 }
37 80
38 -//@brief:AES解密 81 +// AES解密
39 func AesDecrypt(crypted, key []byte) ([]byte, error) { 82 func AesDecrypt(crypted, key []byte) ([]byte, error) {
40 block, err := aes.NewCipher(key) 83 block, err := aes.NewCipher(key)
41 if err != nil { 84 if err != nil {
@@ -47,6 +90,6 @@ func AesDecrypt(crypted, key []byte) ([]byte, error) { @@ -47,6 +90,6 @@ func AesDecrypt(crypted, key []byte) ([]byte, error) {
47 blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节 90 blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) //初始向量的长度必须等于块block的长度16字节
48 origData := make([]byte, len(crypted)) 91 origData := make([]byte, len(crypted))
49 blockMode.CryptBlocks(origData, crypted) 92 blockMode.CryptBlocks(origData, crypted)
50 - origData = PKCS5UnPadding(origData) 93 + origData = PKCS7UnPadding(origData, blockSize)
51 return origData, nil 94 return origData, nil
52 } 95 }
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 8
9 func Test_Aes(t *testing.T) { 9 func Test_Aes(t *testing.T) {
10 //key的长度必须是16、24或者32字节,分别用于选择AES-128, AES-192, or AES-256 10 //key的长度必须是16、24或者32字节,分别用于选择AES-128, AES-192, or AES-256
11 - var aeskey = []byte("12345678abcdefgh") 11 + var aeskey = []byte("mmm.qrcode.(%^&)")
12 pass := []byte("vdncloud123456") 12 pass := []byte("vdncloud123456")
13 xpass, err := AesEncrypt(pass, aeskey) 13 xpass, err := AesEncrypt(pass, aeskey)
14 if err != nil { 14 if err != nil {