作者 yangfu

导出公司用户修改

package command
import (
"encoding/json"
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type ExportDataCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 业务编码
Ids []string `json:"ids"`
Where json.RawMessage `json:"where"`
// 业务编码
Code string `form:"code"`
}
func (exportDataCommand *ExportDataCommand) Valid(validation *validation.Validation) {
}
func (exportDataCommand *ExportDataCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(exportDataCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
func (exportDataCommand *ExportDataCommand) UnmarshalQuery(query interface{}) error {
return json.Unmarshal(exportDataCommand.Where, query)
}
... ...
package service
import (
"fmt"
"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"
)
// 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{
Limit: 10000,
CompanyId: companyUserListQuery.Operator.CompanyId,
OrganizationId: 0,
DepartmentId: 0,
UserName: companyUserListQuery.UserName,
DepName: companyUserListQuery.DepartmentName,
Phone: "",
UserType: domain.UserTypeEmployee,
InOrgIds: companyUserListQuery.Operator.OrgIds,
})
if err != nil {
return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
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{
Limit: 10000,
CompanyId: companyUserListQuery.Operator.CompanyId,
OrganizationId: 0,
DepartmentId: 0,
UserName: companyUserListQuery.UserName,
DepName: companyUserListQuery.DepartmentName,
Phone: "",
UserType: domain.UserTypeCooperation,
InOrgIds: companyUserListQuery.Operator.OrgIds,
})
if err != nil {
return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
return ExportCooperationUserData(result.Users), nil
}
... ...
... ... @@ -7,7 +7,6 @@ import (
"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/domainService"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
... ... @@ -20,104 +19,6 @@ 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{
Limit: 10000,
CompanyId: companyUserListQuery.Operator.CompanyId,
OrganizationId: 0,
DepartmentId: 0,
UserName: companyUserListQuery.UserName,
DepName: companyUserListQuery.DepartmentName,
Phone: "",
UserType: domain.UserTypeEmployee,
InOrgIds: companyUserListQuery.Operator.OrgIds,
})
if err != nil {
return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
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{
Limit: 10000,
CompanyId: companyUserListQuery.Operator.CompanyId,
OrganizationId: 0,
DepartmentId: 0,
UserName: companyUserListQuery.UserName,
DepName: companyUserListQuery.DepartmentName,
Phone: "",
UserType: domain.UserTypeCooperation,
InOrgIds: companyUserListQuery.Operator.OrgIds,
})
if err != nil {
return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
}
return ExportCooperationUserData(result.Users), nil
}
// 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)
... ... @@ -226,6 +127,7 @@ func (srv ExcelDataService) ImportCompanyUser(importDataCommand *command.ImportD
return srv.importResultWithHeader(excelImport.DataFields, result.FailRows, len(users)), nil
}
// ImportOrganization 导入组织
func (srv ExcelDataService) ImportOrganization(importDataCommand *command.ImportDataCommand) (interface{}, error) {
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
... ... @@ -296,14 +198,14 @@ func (srv ExcelDataService) fieldValueAllEmpty(param map[string]string) bool {
return isAllEmpty
}
// ImportCompanyUser 导入公司用户信息
// FileImportTemplate 导入模板
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/20210917/object/1631843469_DykNwexeYYtzxzbwsER5RrzCS7QRwGmd.xlsx",
domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210924/object/1632465394_kRTz5FfjXABF2hb6d2Nd3JMJ3Xz7zBE2.xlsx",
domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210924/object/1632465400_ndAJycEn2jxnPFdzjMnsE6rT3xWb22xk.xlsx",
domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210924/object/1632472672_hbFG5Ad3JFZM7fCerb5eShaRneCRkHsY.xlsx",
}
var url string
var ok bool
... ...
... ... @@ -5,7 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
//exportCompanyUserData 导出公司用户数据
// ExportCompanyUserData 导出公司用户数据
type ExportCompanyUserData []allied_creation_user.UserDetail
var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
... ... @@ -14,10 +14,10 @@ func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
return []excel.DataField{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
{EnName: "Phone", CnName: "手机号"},
{EnName: "OrgName", CnName: "组织机构"},
{EnName: "DepartmentName", CnName: "所属部门"},
{EnName: "EnableStatus", CnName: "状态"},
{EnName: "OrgName", CnName: "组织机构"},
{EnName: "Phone", CnName: "手机号"},
}
}
... ... @@ -69,7 +69,7 @@ func (data ExportCompanyUserData) TableTitle() []string {
return nil
}
//exportCompanyUserData 导出共创用户数据
//ExportCooperationUserData 导出共创用户数据
type ExportCooperationUserData []allied_creation_user.UserDetail
var _ excel.ExcelMaker = (*ExportCooperationUserData)(nil)
... ...
... ... @@ -47,21 +47,58 @@ func (controller *ExcelDataController) fieldValueAllEmpty(param map[string]strin
// ExportCompanyUser 导出公司用户
func (controller ExcelDataController) ExportCompanyUser() {
excelService := service.NewExcelDataService(nil)
companyUserListQuery := &query.CompanyUserListQuery{}
err := controller.Unmarshal(companyUserListQuery)
//excelService := service.NewExcelDataService(nil)
//companyUserListQuery := &query.CompanyUserListQuery{}
//err := controller.Unmarshal(companyUserListQuery)
//if err != nil {
// log.Logger.Debug("json err:" + err.Error())
// controller.Response(nil, err)
// return
//}
//companyUserListQuery.Operator = controller.GetOperator()
//data, err := excelService.ExportCompanyUser(companyUserListQuery)
//if err != nil {
// log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
// controller.Response(nil, err)
// return
//}
//excelTool := excel.NewExcelExport()
//err = excelTool.ExportData(data, "")
//if err != nil {
// log.Logger.Debug("excelTool.ExportData err:" + err.Error())
// controller.Response(nil, err)
// return
//}
//controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
// 1.读取command
exportDataCommand := &command.ExportDataCommand{}
err := controller.Unmarshal(exportDataCommand)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
controller.Response(nil, err)
return
}
companyUserListQuery.Operator = controller.GetOperator()
data, err := excelService.ExportCompanyUser(companyUserListQuery)
exportDataCommand.Operator = controller.GetOperator()
// 2.读取data
var data excel.ExcelMaker
var filename string
var excelService = service.NewExcelDataService(nil)
switch exportDataCommand.Code {
default:
companyUserListQuery := &query.CompanyUserListQuery{}
exportDataCommand.UnmarshalQuery(companyUserListQuery)
companyUserListQuery.Operator = exportDataCommand.Operator
data, err = excelService.ExportCompanyUser(companyUserListQuery)
filename = "导出公司用户"
}
if err != nil {
log.Logger.Debug("excelService.ExportCompanyUser err:" + err.Error())
log.Logger.Debug("excelService.Export err:" + err.Error())
controller.Response(nil, err)
return
}
// 3.返回文件
excelTool := excel.NewExcelExport()
err = excelTool.ExportData(data, "")
if err != nil {
... ... @@ -69,7 +106,7 @@ func (controller ExcelDataController) ExportCompanyUser() {
controller.Response(nil, err)
return
}
controller.responseExcelByFile(controller.Ctx, excelTool, "导出公司用户")
controller.responseExcelByFile(controller.Ctx, excelTool, filename)
}
// ExportCooperationUser 导出共创用户
... ... @@ -276,3 +313,44 @@ func (controller ExcelDataController) FileImportTemplate() {
data, err := excelService.FileImportTemplate(cmd)
controller.Response(data, err)
}
// FileExport 文件导出
func (controller ExcelDataController) FileExport() {
// 1.读取command
exportDataCommand := &command.ExportDataCommand{}
err := controller.Unmarshal(exportDataCommand)
if err != nil {
log.Logger.Debug("json err:" + err.Error())
controller.Response(nil, err)
return
}
exportDataCommand.Operator = controller.GetOperator()
// 2.读取data
var data excel.ExcelMaker
var filename string
var excelService = service.NewExcelDataService(nil)
switch exportDataCommand.Code {
default:
companyUserListQuery := &query.CompanyUserListQuery{}
exportDataCommand.UnmarshalQuery(companyUserListQuery)
companyUserListQuery.Operator = exportDataCommand.Operator
data, err = excelService.ExportCompanyUser(companyUserListQuery)
filename = "导出公司用户"
}
if err != nil {
log.Logger.Debug("excelService.Export err:" + err.Error())
controller.Response(nil, err)
return
}
// 3.返回文件
excelTool := excel.NewExcelExport()
err = excelTool.ExportData(data, "")
if err != nil {
log.Logger.Debug("excelTool.ExportData err:" + err.Error())
controller.Response(nil, err)
return
}
controller.responseExcelByFile(controller.Ctx, excelTool, filename)
}
... ...
... ... @@ -13,5 +13,6 @@ func init() {
web.Router("/v1/web/excel/import/dividends-returned-orders", &web_client.ExcelDataController{}, "Post:ImportDividendsReturnedOrder")
web.Router("/v1/web/file-import", &web_client.ExcelDataController{}, "Post:FileImport")
web.Router("/v1/web/file-export", &web_client.ExcelDataController{}, "Post:FileExport")
web.Router("/v1/web/file-import-template/:code", &web_client.ExcelDataController{}, "Get:FileImportTemplate")
}
... ...