import.go
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command"
"strings"
"github.com/linmadan/egglib-go/utils/excel"
)
type ExcelDataService struct {
}
func NewExcelDataService(param map[string]interface{}) *ExcelDataService {
return &ExcelDataService{}
}
// 导入结果
func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, failRows []interface{}, totalRow int) interface{} {
var result = map[string]interface{}{
"successCount": 0,
"fail": struct{}{},
}
if len(failRows) == 0 {
result["successCount"] = totalRow
}
if len(failRows) > 0 {
fail := map[string]interface{}{
"body": failRows,
}
var header = make(map[string]string)
for i := 0; i < len(headers); i++ {
item := headers[i]
header[item.EnName] = item.CnName
}
fail["header"] = header
result["fail"] = fail
}
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
}
//// 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/20210927/object/1632743206_NPYTKw6RGhXn4TpYNEQhGGdCkXKXTnxM.xlsx",
//domain.ImportCooperationUser: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210926/object/1632635345_SbfzmkXjQHhCwPw4MB7zb5EBBtdp2MSE.xlsx",
//domain.ImportDividendsReturnOrders: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210927/object/1632743214_rNHm6ZBXZaC5xKTrsE7M4h45MY6n6Ff3.xlsx",
}
var url string
var ok bool
if url, ok = mapTemplate[importDataCommand.Code]; !ok {
return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("模板:%v 不存在", importDataCommand.Code))
}
return map[string]string{
"url": url,
}, nil
}
func (srv ExcelDataService) GetExcelDataFields(code string) (interface{}, error) {
dataFields := []DataFieldOptions{}
//switch code {
//case domain.ExportCompanyUser:
// dataFileds = (ExportCompanyUserData{}).AllFields()
//case domain.ExportCooperationUser:
// dataFileds = (ExportCooperationUserData{}).AllFields()
//}
return dataFields, nil
}