作者 yangfu

生产制造 - 设备导入

... ... @@ -199,6 +199,47 @@ func (srv ExcelDataService) ImportProduct(importDataCommand *command.ImportDataC
return srv.importResultWithHeader(excelImport.DataFields, *result, len(items)), nil
}
// ImportProduct 导入生产信息
func (srv ExcelDataService) ImportDevice(importDataCommand *command.ImportDataCommand) (interface{}, error) {
excelImport := excel.NewExcelImport()
excelImport.RowBegin = 3 //第二行开始读取
excelImport.DataFields = []excel.DataField{
{EnName: "deviceCode", CnName: "*设备编号"},
{EnName: "deviceName", CnName: "*设备名称"},
{EnName: "deviceModel", CnName: "*设备型号"},
{EnName: "deviceType", CnName: "*设备类型"},
{EnName: "brand", CnName: "品牌"},
{EnName: "status", CnName: "*状态"},
{EnName: "level", CnName: "*风险等级"},
}
excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
items := make([]*domain.ImportDeviceItem, 0)
for _, v := range excelData {
item := &domain.ImportDeviceItem{
DeviceCode: strings.TrimSpace(v["deviceCode"]),
DeviceName: strings.TrimSpace(v["deviceName"]),
DeviceModel: strings.TrimSpace(v["deviceModel"]),
DeviceType: strings.TrimSpace(v["deviceType"]),
Brand: strings.TrimSpace(v["brand"]),
Status: strings.TrimSpace(v["status"]),
Level: strings.TrimSpace(v["level"]),
}
items = append(items, item)
}
svr := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(importDataCommand.Operator)
result, err := svr.BatchAddDevice(allied_creation_manufacture.BatchAddDeviceRequest{
List: items,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return srv.importResultWithHeader(excelImport.DataFields, *result, len(items)), nil
}
// 导入结果
func (srv ExcelDataService) importResultWithHeader(headers []excel.DataField, failRows []interface{}, totalRow int) interface{} {
var result = map[string]interface{}{
... ... @@ -242,6 +283,8 @@ func (srv ExcelDataService) FileImportTemplate(importDataCommand *command.Import
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",
domain.ImportProducts: "https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20220120/object/1642670543_cbraNKjNPHcbN6RNBYQBrwhC7BXGbDWp.xlsx",
domain.ImportDevices: "",
}
var url string
var ok bool
... ...
... ... @@ -66,6 +66,8 @@ const (
// 导入产品
ImportProducts = "ImportProducts"
// 导入设备
ImportDevices = "ImportDevices"
)
const (
... ...
... ... @@ -15,3 +15,23 @@ type ImportProductItem struct {
// 失败理由
FailReason string `json:"failReason"`
}
// 导入设备数据体
type ImportDeviceItem struct {
// 设备编号
DeviceCode string `json:"deviceCode,omitempty"`
// 设备名称
DeviceName string `json:"deviceName,omitempty"`
// 设备型号
DeviceModel string `json:"deviceModel,omitempty"`
// 设备类型
DeviceType string `json:"deviceType,omitempty"`
// 品牌
Brand string `json:"brand,omitempty"`
// 设备状态 1:正常 2:封存 3:报废
Status string `json:"status,omitempty"`
// 风险等级 1:高 2:中 3:低
Level string `json:"level,omitempty"`
// 失败理由
FailReason string `json:"failReason"`
}
... ...
... ... @@ -83,3 +83,19 @@ type (
UnitWeight float64 `json:"unitWeight"`
}
)
/*设备*/
//BatchAddProduct 批量添加产品
func (gateway HttpLibAlliedCreationManufacture) BatchAddDevice(param BatchAddDeviceRequest) (*BatchAddProductResponse, error) {
url := fmt.Sprintf("%s%s", gateway.BaseUrl(), "/devices/batch-add")
method := "post"
var data BatchAddProductResponse
err := gateway.FastDoRequest(url, method, param, &data)
return &data, err
}
type BatchAddDeviceRequest struct {
List []*domain.ImportDeviceItem `json:"list"`
}
type BatchAddDeviceResponse []interface{}
... ...
... ... @@ -211,6 +211,8 @@ func defaultImport(controller *ExcelDataController) {
data, err = excelService.ImportOrganization(cmd)
case domain.ImportProducts:
data, err = excelService.ImportProduct(cmd)
case domain.ImportDevices:
data, err = excelService.ImportDevice(cmd)
default:
err = fmt.Errorf("导入不存在 Code:%v", cmd.Code)
}
... ...