作者 Your Name

添加 公司用户导出

... ... @@ -147,6 +147,7 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
... ... @@ -194,7 +195,9 @@ github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFB
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj3nKI=
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
... ... @@ -233,7 +236,9 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 h1:EpI0bqf/eX9SdZDwlMmahKM+CDBgNbsXMhsN28XrM8o=
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.4.1 h1:veeeFLAJwsNEBPBlDepzPIYS1eLyBVcXNZUW79exZ1E=
github.com/xuri/excelize/v2 v2.4.1/go.mod h1:rSu0C3papjzxQA3sdK8cU544TebhrPUoTOaGPIh0Q1A=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
... ... @@ -258,6 +263,7 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
... ...
package query
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type CompanyUserListQuery struct {
//用户姓名
UserName string `json:"userName"`
//所属部门
DepartmentName string `json:"departmentName"`
//操作人
Operator domain.Operator `json:"-"`
}
... ...
package query
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type CooperationUserListQuery struct {
//操作人
Operator domain.Operator `json:"-"`
//用户名称
UserName string `json:"userName"`
//共创公司
CooperationCompany string `json:"cooperationCompany"`
}
... ...
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"
)
type ExcelDataService struct {
}
func NewExcelDataService(param map[string]interface{}) *ExcelDataService {
return &ExcelDataService{}
}
// 导出公司用户信息列表
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
}
... ...
package service
import (
"github.com/linmadan/egglib-go/utils/excel"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
//exportCompanyUserData 导出公司用户数据
type ExportCompanyUserData []allied_creation_user.UserDetail
var _ excel.ExcelMaker = (*ExportCompanyUserData)(nil)
func (data ExportCompanyUserData) DataFieldList() []excel.DataField {
return []excel.DataField{
{EnName: "UserCode", CnName: "用户编码"},
{EnName: "UserName", CnName: "用户姓名"},
{EnName: "Phone", CnName: "手机号"},
{EnName: "DepartmentName", CnName: "所属部门"},
{EnName: "EnableStatus", CnName: "状态"},
{EnName: "OrgName", CnName: "组织机构"},
}
}
func (data ExportCompanyUserData) CellValue(index int, enName string) (value interface{}) {
if index > data.DataListLen() {
return ""
}
switch enName {
case "UserCode":
return data[index].UserCode
case "UserName":
return data[index].UserInfo.UserName
case "Phone":
return data[index].UserInfo.Phone
case "DepartmentName":
if data[index].Department != nil {
return data[index].Department.DepartmentName
} else {
return ""
}
case "EnableStatus":
status := data[index].EnableStatus
statusName := ""
// 状态(1:启用 2:禁用 3:注销)
switch status {
case 1:
statusName = "启用"
case 2:
statusName = "禁用"
case 3:
statusName = "注销"
}
return statusName
case "OrgName":
if data[index].Org != nil {
return data[index].Org.OrgName
} else {
return ""
}
}
return nil
}
func (data ExportCompanyUserData) DataListLen() int {
return len(data)
}
func (data ExportCompanyUserData) TableTitle() []string {
return nil
}
... ...
package allied_creation_cooperation
import (
"encoding/json"
"fmt"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
//ReqImportDividendsReturnedOrder 导入退货数据
type (
ImportDividendsReturnedOrderGood struct {
OrderGoodAmount float64 `json:"orderGoodAmount"` // 订单产品金额
OrderGoodName string `json:"orderGoodName"` // 订单产品名称
OrderGoodPrice float64 `json:"orderGoodPrice"` // 订单产品单价
OrderGoodQuantity int64 `json:"orderGoodQuantity"` // 订单产品数量
DividendsOrderNumber int64 `json:"dividendsOrderNumber"` // 关联分红订单号
CooperationContractNumber string `json:"cooperationContractNumber"` // 关联的共创合约编号
OrderGoodExpense float64 `json:"orderGoodExpense"` // 订单产品费用
}
ImportDividendsReturnedOrderData struct {
DividendsReturnedOrderRefund float64 `json:"dividendsReturnedOrderRefund"` // 退货金额
DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"` //退货客户名称
OriginalOrderNum string `json:"originalOrderNum"` // 来源单号,源单号,订单号
DividendsReturnedDate time.Time `json:"dividendsReturnedDate"` //退货日期
RegionName string `json:"regionName"` // 退货区域名称
OrderGoods []*ImportDividendsReturnedOrderGood `json:"orderGoods"` // 订单产品列表
Remarks string `json:"remarks"` // 备注
}
//请求参数
ReqImportDividendsReturnedOrder struct {
// 分红退货单数据
DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表
}
//响应参数
DataImportDividendsReturnedOrder struct {
}
)
// ImportDividendsReturnedOrder 导入退货数据
func (gateway HttplibAlliedCreationCooperation) ImportDividendsReturnedOrder(param ReqDividendsEstimateSearchDividend) (*DataDividendsEstimateSearchDividend, error) {
url := gateway.baseUrL + "/dividends-returned-orders/import"
method := "POST"
req := gateway.CreateRequest(url, method)
// oneDemo
log.Logger.Debug("向业务模块请求数据:导入退货数据。", map[string]interface{}{
"api": method + ":" + url,
// "param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求查询业绩分红失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取查询业绩分红失败:%w", err)
}
log.Logger.Debug("获取业务模块请求数据:查询业绩分红。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析查询业绩分红:%w", err)
}
var data DataDividendsEstimateSearchDividend
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -28,9 +28,13 @@ func (gateway HttplibAlliedCreationUser) UserSearch(param ReqUserSearch) (*DataU
if err != nil {
return nil, fmt.Errorf("获取搜索用户列表失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:搜索用户列表。", map[string]interface{}{
"result": string(byteResult),
})
if param.Limit > 50 {
//太多就不打印了
log.Logger.Debug("获取用户模块请求数据:搜索用户列表。", map[string]interface{}{
"result": string(byteResult),
})
}
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
... ...
package web_client
import (
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/utils/excel"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
type ExcelDataController struct {
baseController
}
func (controller *ExcelDataController) responseExcelByFile(ctx *context.Context, excelExport *excel.ExcelExport, fileName string) error {
ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)
ctx.Output.Header("Content-Description", "File Transfer")
ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
ctx.Output.Header("Content-Transfer-Encoding", "binary")
ctx.Output.Header("Expires", "0")
ctx.Output.Header("Cache-Control", "must-revalidate")
ctx.Output.Header("Pragma", "public")
//跳过保存文件,直接写入ctx.ResponseWriter
excelExport.ExcelFile.Write(ctx.ResponseWriter)
return nil
}
//导出公司用户
func (controller ExcelDataController) ExportCompanyUser() {
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, "导出公司用户")
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
)
func init() {
web.Router("/v1/web/excel/export/company-user", &web_client.ExcelDataController{}, "Post:ExportCompanyUser")
}
... ...