|
|
package web_client
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/command"
|
|
|
|
|
|
"github.com/beego/beego/v2/server/web/context"
|
...
|
...
|
@@ -100,18 +99,16 @@ func (controller ExcelDataController) ExportCooperationUser() { |
|
|
|
|
|
// ImportDividendsOrder TODO 导入分红订单
|
|
|
func (controller ExcelDataController) ImportDividendsOrder() {
|
|
|
excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
importDividendsOrder(controller)
|
|
|
}
|
|
|
|
|
|
func importDividendsOrder(controller ExcelDataController) {
|
|
|
|
|
|
fileReader, err := controller.GetExcelFile()
|
|
|
if err != nil {
|
|
|
log.Logger.Error("接收文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
|
|
return
|
|
|
}
|
|
|
if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
//TODO 判断文件类型
|
|
|
log.Logger.Error("获取到的文件:" + fileHeader.Filename)
|
|
|
controller.Response(nil, errors.New("上传到的文件类型错误"))
|
|
|
return
|
|
|
}
|
|
|
excelImport := excel.NewExcelImport()
|
|
|
excelImport.RowBegin = 2 //第2行开始读取
|
|
|
excelImport.DataFields = []excel.DataField{
|
...
|
...
|
@@ -125,7 +122,7 @@ func (controller ExcelDataController) ImportDividendsOrder() { |
|
|
{EnName: "Expense", CnName: "费用"},
|
|
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
|
|
}
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(fileReader)
|
|
|
if err != nil {
|
|
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
...
|
...
|
@@ -165,18 +162,16 @@ func (controller ExcelDataController) ImportDividendsOrder() { |
|
|
|
|
|
// ImportDividendsReturnedOrder 导入分红退货单
|
|
|
func (controller ExcelDataController) ImportDividendsReturnedOrder() {
|
|
|
excelFile, fileHeader, err := controller.GetFile("file")
|
|
|
importDividendsReturnedOrder(controller)
|
|
|
}
|
|
|
|
|
|
func importDividendsReturnedOrder(controller ExcelDataController) {
|
|
|
|
|
|
fileReader, err := controller.GetExcelFile()
|
|
|
if err != nil {
|
|
|
log.Logger.Error("接收文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
|
|
return
|
|
|
}
|
|
|
if filepath.Ext(fileHeader.Filename) != ".xlsx" {
|
|
|
//TODO 判断文件类型
|
|
|
log.Logger.Error("获取到的文件:" + filepath.Ext(fileHeader.Filename))
|
|
|
controller.Response(nil, errors.New("上传的文件类型错误"))
|
|
|
return
|
|
|
}
|
|
|
excelImport := excel.NewExcelImport()
|
|
|
excelImport.RowBegin = 2 //第2行表头开始读取
|
|
|
excelImport.DataFields = []excel.DataField{
|
...
|
...
|
@@ -190,7 +185,7 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { |
|
|
{EnName: "OrderGoodPrice", CnName: "*退货价格"},
|
|
|
{EnName: "CooperationContractNumber", CnName: "项目合约编号"},
|
|
|
}
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(excelFile)
|
|
|
excelData, err := excelImport.OpenExcelFromIoReader(fileReader)
|
|
|
if err != nil {
|
|
|
log.Logger.Error("解析excel文件失败," + err.Error())
|
|
|
controller.Response(nil, err)
|
...
|
...
|
@@ -229,6 +224,9 @@ func (controller ExcelDataController) ImportDividendsReturnedOrder() { |
|
|
}
|
|
|
|
|
|
func (controller ExcelDataController) ImportCompanyUser() {
|
|
|
importCompanyUser(controller)
|
|
|
}
|
|
|
func importCompanyUser(controller ExcelDataController) {
|
|
|
excelService := service.NewExcelDataService(nil)
|
|
|
r, err := controller.GetExcelFile()
|
|
|
if err != nil {
|
...
|
...
|
@@ -243,6 +241,9 @@ func (controller ExcelDataController) ImportCompanyUser() { |
|
|
}
|
|
|
|
|
|
func (controller ExcelDataController) ImportCooperationUser() {
|
|
|
importCooperationUser(controller)
|
|
|
}
|
|
|
func importCooperationUser(controller ExcelDataController) {
|
|
|
excelService := service.NewExcelDataService(nil)
|
|
|
r, err := controller.GetExcelFile()
|
|
|
if err != nil {
|
...
|
...
|
@@ -271,26 +272,37 @@ func (controller ExcelDataController) ImportOrganization() { |
|
|
}
|
|
|
|
|
|
func (controller ExcelDataController) FileImport() {
|
|
|
excelService := service.NewExcelDataService(nil)
|
|
|
r, err := controller.GetExcelFile()
|
|
|
if err != nil {
|
|
|
controller.Response(nil, err)
|
|
|
return
|
|
|
}
|
|
|
cmd := &command.ImportDataCommand{}
|
|
|
// excelService := service.NewExcelDataService(nil)
|
|
|
// r, err := controller.GetExcelFile()
|
|
|
// if err != nil {
|
|
|
// controller.Response(nil, err)
|
|
|
// return
|
|
|
// }
|
|
|
// cmd := &command.ImportDataCommand{}
|
|
|
//controller.Unmarshal(cmd)
|
|
|
controller.ParseForm(cmd)
|
|
|
cmd.Operator = controller.GetOperator()
|
|
|
cmd.Reader = r
|
|
|
var data interface{}
|
|
|
switch cmd.Code {
|
|
|
// controller.ParseForm(cmd)
|
|
|
// cmd.Operator = controller.GetOperator()
|
|
|
// cmd.Reader = r
|
|
|
// var (
|
|
|
// data interface{}
|
|
|
// err error
|
|
|
// )
|
|
|
code := controller.GetString("code")
|
|
|
switch code {
|
|
|
case domain.ImportCompanyUser:
|
|
|
data, err = excelService.ImportCompanyUser(cmd)
|
|
|
importCompanyUser(controller)
|
|
|
case domain.ImportCooperationUser:
|
|
|
importCooperationUser(controller)
|
|
|
case domain.ImportDividendsOrders:
|
|
|
importDividendsOrder(controller)
|
|
|
case domain.ImportOrganization:
|
|
|
importDividendsReturnedOrder(controller)
|
|
|
}
|
|
|
controller.Response(data, err)
|
|
|
// controller.Response(data, err)
|
|
|
}
|
|
|
|
|
|
func (controller ExcelDataController) FileImportTemplate() {
|
|
|
|
|
|
excelService := service.NewExcelDataService(nil)
|
|
|
cmd := &command.ImportDataCommand{}
|
|
|
//controller.Unmarshal(cmd)
|
...
|
...
|
|