作者 Your Name

Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/allied-crea…

…tion-gateway into test
package service
import (
"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"
"github.com/linmadan/egglib-go/core/application"
... ... @@ -103,16 +105,16 @@ func (srv CooperationProjectService) SearchCooperationProject(projectQuery *comm
// PersonSearchCooperationProject 共创用户获取共创项目列表
func (srv CooperationProjectService) PersonSearchCooperationProject(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) {
extQueries := extQuires(projectQuery.Operator)
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
projectQuery.Operator)
//orgidStr := strconv.Itoa(projectQuery.OrgId)
result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
PageNumber: projectQuery.PageNumber + 1, //手机序号从0开始的
PageSize: projectQuery.PageSize,
OrgId: projectQuery.OrgId,
Status: 1, //搜索状态为“招标中”项目
Keyword: projectQuery.Keyword,
//UserBaseId: projectQuery.Operator.UserBaseId,
PageNumber: projectQuery.PageNumber + 1, //手机序号从0开始的
PageSize: projectQuery.PageSize,
OrgId: projectQuery.OrgId,
Status: 1, //搜索状态为“招标中”项目
Keyword: projectQuery.Keyword,
SearchCooperationProjectExtQueries: extQueries,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -120,6 +122,40 @@ func (srv CooperationProjectService) PersonSearchCooperationProject(projectQuery
return int(result.Total), result.List, nil
}
func extQuires(operator domain.Operator) []*allied_creation_cooperation.SearchCooperationProjectExtQuery {
var extQueries = make([]*allied_creation_cooperation.SearchCooperationProjectExtQuery, 0)
if operator.UserBaseId > 0 {
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
operator)
users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
Limit: 100,
Offset: 0,
UserBaseId: operator.UserBaseId,
EnableStatus: domain.UserStatusEnable,
})
if err != nil {
return extQueries
}
for i := range users.Users {
u := users.Users[i]
q := &allied_creation_cooperation.SearchCooperationProjectExtQuery{
ExtCompanyId: int64(u.Company.CompanyId),
//ExtOrgId: int64(u.Org.OrgId),
//ExtOrgIds: int64(u.UserOrg),
ExtUserId: int64(u.UserId),
ExtUserBaseId: int64(u.UserBaseId),
ExtCooperationProjectUndertakerTypes: []int32{int32(u.UserType & 3), 3},
}
for j := range u.UserOrg {
org := u.UserOrg[j]
q.ExtOrgIds = append(q.ExtOrgIds, int64(org.OrgID))
}
extQueries = append(extQueries, q)
}
}
return extQueries
}
// PersonSearchCooperationProject 共创用户获取共创项目列表
//func (srv CooperationProjectService) PersonRecommendCooperationProject(projectQuery *command.PersonSearchCooperationProjectQuery) (int, interface{}, error) {
// creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
... ...
... ... @@ -166,6 +166,9 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer
// CooperationProjectRecommend TODO:其他公司按公开的项目查 猜你喜欢(共创项目)
func (srv PersonStatisticsService) CooperationProjectRecommend(projectQuery *command.ListCooperationProjectQuery) (int64, interface{}, error) {
if projectQuery.Operator.UserBaseId > 0 {
}
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
projectQuery.Operator)
result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
... ...
... ... @@ -120,58 +120,60 @@ func (srv ExcelDataService) ImportCompanyUser2(importDataCommand *command.Import
// 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
initPassword, _, err := domainService.GetInitPassword(importDataCommand.Operator)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
userGateway := allied_creation_user.NewHttplibAlliedCreationUser(importDataCommand.Operator)
orgResult, err := userGateway.OrgGet(allied_creation_user.ReqOrgGet{
OrgId: int(importDataCommand.Operator.OrgId),
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "userCode", CnName: "*用户编码"},
{EnName: "userName", CnName: "*用户姓名"},
{EnName: "cooperationCompany", CnName: "*合伙公司"},
{EnName: "cooperationDeadline", CnName: "*合伙到期"},
{EnName: "enableStatus", 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)
for _, v := range excelData {
if srv.fieldValueAllEmpty(v) {
continue
}
item := allied_creation_user.BatchAddUserItem{
CompanyId: importDataCommand.Operator.CompanyId,
UserType: domain.UserTypeCooperation,
UserCode: v["userCode"],
Org: orgResult.OrgCode,
UserName: strings.TrimSpace(v["userName"]),
Phone: strings.TrimSpace(v["phone"]),
Email: strings.TrimSpace(v["email"]),
EnableStatus: strings.TrimSpace(v["enableStatus"]),
CooperationCompany: v["cooperationCompany"],
CooperationDeadline: v["cooperationDeadline"],
}
users = append(users, item)
}
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 srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil
}
// ImportCompanyUser 导入公司用户信息
... ... @@ -197,21 +199,19 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD
}
users := make([]allied_creation_user.BatchAddUserItem, 0)
for _, v := range excelData {
if srv.fieldValueAllEmpty(v) {
continue
}
item := allied_creation_user.BatchAddUserItem{
CompanyId: importDataCommand.Operator.CompanyId,
UserType: domain.UserTypeEmployee,
UserCode: v["userCode"],
Org: v["org"],
Department: v["department"],
UserName: v["userName"],
Phone: v["phone"],
Email: v["email"],
EnableStatus: domain.UserStatusEnable,
}
if status, ok := v["status"]; ok {
if strings.TrimSpace(status) != "启用" {
item.EnableStatus = domain.UserStatusDisable
}
UserCode: strings.TrimSpace(v["userCode"]),
Org: strings.TrimSpace(v["org"]),
Department: strings.TrimSpace(v["department"]),
UserName: strings.TrimSpace(v["userName"]),
Phone: strings.TrimSpace(v["phone"]),
Email: strings.TrimSpace(v["email"]),
EnableStatus: strings.TrimSpace(v["enableStatus"]),
}
users = append(users, item)
}
... ... @@ -223,7 +223,7 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(excelData)), nil
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil
}
func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, error) {
... ... @@ -240,6 +240,9 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import
}
items := make([]allied_creation_user.BatchAddOrgItem, 0)
for _, v := range excelData {
if srv.fieldValueAllEmpty(v) {
continue
}
item := allied_creation_user.BatchAddOrgItem{
CompanyId: importDataCommand.Operator.CompanyId,
OrgCode: v["orgCode"],
... ... @@ -255,7 +258,7 @@ func (srv ExcelDataService) ImportOrganization(importDataCommand *command.Import
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(excelData)), nil
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(items)), nil
}
// 导入结果
... ... @@ -282,15 +285,25 @@ func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, fa
return result
}
func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool {
isAllEmpty := true
for _, v := range param {
value := strings.TrimSpace(v)
if len(value) > 0 {
isAllEmpty = false
}
}
return isAllEmpty
}
// ImportCompanyUser 导入公司用户信息
func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.ImportDataCommand) (interface{}, error) {
var mapTemplate = map[string]string{
domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",
domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx",
domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807770_sBtA4dYcmESZy6Q2ycfGSCKGdFtBETQZ.xlsx",
// 模板待更新
domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210909/object/1631171021_baB6y5zdpwC2WnsHFQhKC3dkQEaAYMNZ.xlsx",
domain.ImportCompanyUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807485_EaxECeRz23WpzrMZmbwdEPRJ3Pdxpx5X.xlsx",
domain.ImportOrganization: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210916/object/1631807490_r2XWhGmbWWmpbeePBkZ3EJQFKcZEMpEm.xlsx",
domain.ImportDividendsOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210917/object/1631843469_DykNwexeYYtzxzbwsER5RrzCS7QRwGmd.xlsx",
domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210918/object/1631932960_fen6RZS7ZesyDPMzXactKKCenhRMkfRb.xlsx",
domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210918/object/1631933214_MbTxsQtnEEMprHADFR6MedfZBkxYWBYA.xlsx",
}
var url string
var ok bool
... ...
... ... @@ -171,6 +171,20 @@ type (
//查询共创项目
type (
SearchCooperationProjectExtQuery struct {
// 公司ID,通过集成REST上下文获取
ExtCompanyId int64 `cname:"公司ID" json:"extCompanyId,omitempty"`
// 组织机构ID
ExtOrgId int64 `cname:"组织机构ID" json:"extOrgId,omitempty"`
// 关联的组织机构ID列表
ExtOrgIds []int64 `cname:"关联的组织机构ID列表" json:"extOrgIds,omitempty"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
ExtUserId int64 `cname:"用户ID" json:"extUserId,omitempty"`
// 用户基础数据id
ExtUserBaseId int64 `cname:"用户基础数据ID" json:"extUserBaseId,omitempty"`
// 共创项目承接对象,1员工,2共创用户,3公开,可多选
ExtCooperationProjectUndertakerTypes []int32 `json:"extCooperationProjectUndertakerTypes"`
}
ReqCooperationProjectSearch struct {
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
... ... @@ -192,6 +206,8 @@ type (
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
// 共创项目承接对象,1员工,2共创用户,4公开,可以多选
CooperationProjectUndertakerType int32 `json:"cooperationProjectUndertakerType"`
// 额外的查询条件
SearchCooperationProjectExtQueries []*SearchCooperationProjectExtQuery `cname:"额外的查询条件" json:"searchCooperationProjectExtQueries"`
}
DataCooperationProjectSearchItem struct {
CooperationProjectID string `json:"cooperationProjectId"`
... ...
... ... @@ -393,11 +393,11 @@ type (
// 部门编码
Department string `json:"department,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `json:"enableStatus,omitempty"`
EnableStatus string `json:"enableStatus,omitempty"`
// 共创公司 cooperationCompany
CooperationCompany string `json:"cooperationCompany"`
// 共创到期时间 (yyyy-MM-dd) cooperationDeadline
CooperationDeadline time.Time `json:"cooperationDeadline"`
CooperationDeadline string `json:"cooperationDeadline"`
// 失败理由
FailReason string `json:"failReason"`
}
... ...