正在显示
10 个修改的文件
包含
417 行增加
和
6 行删除
| @@ -59,6 +59,7 @@ func (data *importAttendance) validField() error { | @@ -59,6 +59,7 @@ func (data *importAttendance) validField() error { | ||
| 59 | return nil | 59 | return nil |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | +// 导入生产计划 | ||
| 62 | func (srv ExcelDataService) ImportDataAttendance(importDataCommand *command.ImportDataCommand) (interface{}, error) { | 63 | func (srv ExcelDataService) ImportDataAttendance(importDataCommand *command.ImportDataCommand) (interface{}, error) { |
| 63 | excelImport := excel.NewExcelImport() | 64 | excelImport := excel.NewExcelImport() |
| 64 | excelImport.RowBegin = 2 //第二行开始读取 | 65 | excelImport.RowBegin = 2 //第二行开始读取 |
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + "github.com/linmadan/egglib-go/utils/excel" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/ecelData/command" | ||
| 7 | + productRecordCommand "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/command" | ||
| 8 | + productRecordService "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productRecord/service" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +// ImportProductRecord 导入生产记录 | ||
| 13 | +func (srv ExcelDataService) ImportProductRecord(importDataCommand *command.ImportDataCommand) (interface{}, error) { | ||
| 14 | + excelImport := excel.NewExcelImport() | ||
| 15 | + excelImport.RowBegin = 3 //第二行开始读取 | ||
| 16 | + excelImport.DataFields = []excel.DataField{ | ||
| 17 | + {EnName: "CreatedDate", CnName: "日期"}, | ||
| 18 | + {EnName: "WorkshopName", CnName: "车间"}, | ||
| 19 | + {EnName: "LineName", CnName: "线别"}, | ||
| 20 | + {EnName: "SectionName", CnName: "工段"}, | ||
| 21 | + {EnName: "WorkerName", CnName: "姓名"}, | ||
| 22 | + {EnName: "ProductGroupName", CnName: "班组"}, | ||
| 23 | + {EnName: "Weigh", CnName: "二级品重量"}, | ||
| 24 | + } | ||
| 25 | + excelData, err := converter.OpenImportFileFromIoReader(excelImport, importDataCommand.Reader, importDataCommand.FileExt) //excelImport.OpenExcelFromIoReader(importDataCommand.Reader) | ||
| 26 | + if err != nil { | ||
| 27 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 28 | + } | ||
| 29 | + items := make([]productRecordCommand.BatchAddProductRecordCommand, 0, len(excelData)) | ||
| 30 | + item := productRecordCommand.BatchAddProductRecordCommand{} | ||
| 31 | + for _, v := range excelData { | ||
| 32 | + item = productRecordCommand.BatchAddProductRecordCommand{ | ||
| 33 | + CreatedDate: v["CreatedDate"], | ||
| 34 | + WorkshopName: v["WorkshopName"], | ||
| 35 | + LineName: v["LineName"], | ||
| 36 | + SectionName: v["SectionName"], | ||
| 37 | + WorkerName: v["WorkerName"], | ||
| 38 | + BatchNumber: v["BatchNumber"], | ||
| 39 | + ProductGroupName: v["ProductGroupName"], | ||
| 40 | + Weigh: v["Weigh"], | ||
| 41 | + FailReason: "", | ||
| 42 | + } | ||
| 43 | + items = append(items, item) | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + svr := productRecordService.NewProductRecordService(nil) | ||
| 47 | + failRows, err := svr.BatchAddProductRecord(importDataCommand.Operator, items) | ||
| 48 | + if err != nil { | ||
| 49 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 50 | + } | ||
| 51 | + return srv.importResultWithHeader(excelImport.DataFields, failRows, len(items)), nil | ||
| 52 | +} |
| @@ -6,6 +6,8 @@ import ( | @@ -6,6 +6,8 @@ import ( | ||
| 6 | "strings" | 6 | "strings" |
| 7 | "time" | 7 | "time" |
| 8 | 8 | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log" | ||
| 10 | + | ||
| 9 | "github.com/linmadan/egglib-go/core/application" | 11 | "github.com/linmadan/egglib-go/core/application" |
| 10 | "github.com/linmadan/egglib-go/transaction/pg" | 12 | "github.com/linmadan/egglib-go/transaction/pg" |
| 11 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 13 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
| @@ -414,7 +416,7 @@ func (productRecordService *ProductRecordService) CancelProductRecord(cmd *comma | @@ -414,7 +416,7 @@ func (productRecordService *ProductRecordService) CancelProductRecord(cmd *comma | ||
| 414 | return struct{}{}, nil | 416 | return struct{}{}, nil |
| 415 | } | 417 | } |
| 416 | 418 | ||
| 417 | -//BatchAddProductRecord 从文件导入的数据,批量添加生产记录 | 419 | +// BatchAddProductRecord 从文件导入的数据,批量添加生产记录 |
| 418 | func (productRecordService *ProductRecordService) BatchAddProductRecord(operate *domain.OperateInfo, param []command.BatchAddProductRecordCommand) ( | 420 | func (productRecordService *ProductRecordService) BatchAddProductRecord(operate *domain.OperateInfo, param []command.BatchAddProductRecordCommand) ( |
| 419 | failRows []interface{}, err error) { | 421 | failRows []interface{}, err error) { |
| 420 | transactionContext, err := factory.CreateTransactionContext(nil) | 422 | transactionContext, err := factory.CreateTransactionContext(nil) |
| @@ -570,7 +572,7 @@ func (productRecordService *ProductRecordService) BatchAddProductRecord(operate | @@ -570,7 +572,7 @@ func (productRecordService *ProductRecordService) BatchAddProductRecord(operate | ||
| 570 | Weigh: weigh, | 572 | Weigh: weigh, |
| 571 | WeighBefore: weigh, | 573 | WeighBefore: weigh, |
| 572 | WeighAfter: weigh, | 574 | WeighAfter: weigh, |
| 573 | - ApproveStatus: domain.ProductRecordNotApprove, | 575 | + ApproveStatus: domain.ProductRecordAutoApproved, |
| 574 | ApproveAt: nowTime.Unix(), | 576 | ApproveAt: nowTime.Unix(), |
| 575 | ApproveUser: operateUser, | 577 | ApproveUser: operateUser, |
| 576 | UnitConversionId: productPlanData.Ext.ProductPlanExt.ProductId, | 578 | UnitConversionId: productPlanData.Ext.ProductPlanExt.ProductId, |
| @@ -603,7 +605,13 @@ func (productRecordService *ProductRecordService) BatchAddProductRecord(operate | @@ -603,7 +605,13 @@ func (productRecordService *ProductRecordService) BatchAddProductRecord(operate | ||
| 603 | if err := transactionContext.CommitTransaction(); err != nil { | 605 | if err := transactionContext.CommitTransaction(); err != nil { |
| 604 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 606 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 605 | } | 607 | } |
| 606 | - //自动审核 | ||
| 607 | - // | ||
| 608 | - return nil, nil | 608 | + for i := range productRecordList { |
| 609 | + err = domainService.SendProductRecordStaticsJob(productRecordList[i]) | ||
| 610 | + if err != nil { | ||
| 611 | + e := fmt.Sprintf("【发送产量统计任务失败】 ProductRecordId=%d, %s", productRecordList[i].ProductRecordId, err.Error()) | ||
| 612 | + log.Logger.Error(e) | ||
| 613 | + return failRows, err | ||
| 614 | + } | ||
| 615 | + } | ||
| 616 | + return failRows, err | ||
| 609 | } | 617 | } |
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productTrouble/command" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +// 事故管理 | ||
| 10 | +type ProductTroubleService struct{} | ||
| 11 | + | ||
| 12 | +func NewProductTroubleService(options map[string]interface{}) *ProductTroubleService { | ||
| 13 | + newService := &ProductTroubleService{} | ||
| 14 | + return newService | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func (srv ProductTroubleService) SaveProductTrouble(param *command.CreatedProductTroubleCommand) (map[string]interface{}, error) { | ||
| 18 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 19 | + if err != nil { | ||
| 20 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 21 | + } | ||
| 22 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 23 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 24 | + } | ||
| 25 | + defer func() { | ||
| 26 | + transactionContext.RollbackTransaction() | ||
| 27 | + }() | ||
| 28 | + | ||
| 29 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 30 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 31 | + } | ||
| 32 | + return map[string]interface{}{ | ||
| 33 | + "id": 0, | ||
| 34 | + }, nil | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +func (srv ProductTroubleService) GetProductTrouble(id int64) (map[string]interface{}, error) { | ||
| 38 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 39 | + if err != nil { | ||
| 40 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 41 | + } | ||
| 42 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 43 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 44 | + } | ||
| 45 | + defer func() { | ||
| 46 | + transactionContext.RollbackTransaction() | ||
| 47 | + }() | ||
| 48 | + | ||
| 49 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 50 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 51 | + } | ||
| 52 | + return map[string]interface{}{ | ||
| 53 | + "id": 0, | ||
| 54 | + }, nil | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +func (srv ProductTroubleService) DeleteProductTrouble(id int64) error { | ||
| 58 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 59 | + if err != nil { | ||
| 60 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 61 | + } | ||
| 62 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 63 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 64 | + } | ||
| 65 | + defer func() { | ||
| 66 | + transactionContext.RollbackTransaction() | ||
| 67 | + }() | ||
| 68 | + | ||
| 69 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 70 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 71 | + } | ||
| 72 | + return nil | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +func (srv ProductTroubleService) ApproveProductTrouble(id int64) error { | ||
| 76 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 77 | + if err != nil { | ||
| 78 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 79 | + } | ||
| 80 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 81 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 82 | + } | ||
| 83 | + defer func() { | ||
| 84 | + transactionContext.RollbackTransaction() | ||
| 85 | + }() | ||
| 86 | + | ||
| 87 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 88 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 89 | + } | ||
| 90 | + return nil | ||
| 91 | +} |
pkg/domain/product_trouble.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "errors" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +// 事故管理数据结构 | ||
| 9 | +type ProductTrouble struct { | ||
| 10 | + Id int `json:"id"` // id | ||
| 11 | + CompanyId int `json:"companyId"` //企业id | ||
| 12 | + OrgId int `json:"orgId"` //组织ID | ||
| 13 | + WorkStation WorkStation `json:"workStation"` // 工作位置 | ||
| 14 | + ProductWorker *User `json:"productWorker,omitempty"` // 生产工人 | ||
| 15 | + AmountLoss float64 `json:"amountLoss"` // 损失的金额 | ||
| 16 | + Types TroubleType `json:"types"` // 事故类型 | ||
| 17 | + RecordData time.Time `json:"recordData"` // 事故发生的日期 | ||
| 18 | + Remark string `json:"remakr"` // 备注 | ||
| 19 | + ApproveStatus ProductTroubleApprove `json:"approveStatus"` // 审核状态 1:未审核 2:已审核 3.自动审核 | ||
| 20 | + ApproveAt *time.Time `json:"approveAt"` // 审核时间 | ||
| 21 | + ApproveUser *User `json:"approveUser"` // 审核人 | ||
| 22 | + CreatedAt time.Time `json:"createdAt,omitempty"` // 创建时间 | ||
| 23 | + UpdatedAt time.Time `json:"updatedAt,omitempty"` // 更新时间 | ||
| 24 | + DeletedAt *time.Time `json:"deletedAt,omitempty"` // 删除时间 | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +// 事故类型 | ||
| 28 | +type TroubleType int | ||
| 29 | + | ||
| 30 | +// 事故类型 1 安全事故 ,2 质量事故, 3 金属事故 ,4 非金属事故 | ||
| 31 | +const ( | ||
| 32 | + TroubleType1 TroubleType = 1 | ||
| 33 | + TroubleType2 TroubleType = 2 | ||
| 34 | + TroubleType3 TroubleType = 3 | ||
| 35 | + TroubleType4 TroubleType = 4 | ||
| 36 | +) | ||
| 37 | + | ||
| 38 | +// 事故管理 审核状态 | ||
| 39 | +type ProductTroubleApprove int | ||
| 40 | + | ||
| 41 | +// 审核状态 1:未审核 2:已审核 | ||
| 42 | +const ( | ||
| 43 | + TroubleWaitApprove ProductTroubleApprove = 1 | ||
| 44 | + TroubleIsApprove ProductTroubleApprove = 2 | ||
| 45 | +) | ||
| 46 | + | ||
| 47 | +type ProductTroubleRepository interface { | ||
| 48 | + Save(param *ProductTrouble) (*ProductTrouble, error) | ||
| 49 | + Remove(param *ProductTrouble) (*ProductTrouble, error) | ||
| 50 | + FindOne(queryOptions map[string]interface{}) (*ProductTrouble, error) | ||
| 51 | + Find(queryOptions map[string]interface{}) (int64, []*ProductTrouble, error) | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +func (m *ProductTrouble) SetTypes(v int) error { | ||
| 55 | + troubleType := TroubleType(v) | ||
| 56 | + switch troubleType { | ||
| 57 | + case TroubleType1, TroubleType2, TroubleType3, TroubleType4: | ||
| 58 | + m.Types = troubleType | ||
| 59 | + default: | ||
| 60 | + return errors.New("ProductTrouble.Types 值错误") | ||
| 61 | + } | ||
| 62 | + return nil | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +// 审核事故数据 | ||
| 66 | +func (m *ProductTrouble) Approve() error { | ||
| 67 | + nowTime := time.Now() | ||
| 68 | + switch m.ApproveStatus { | ||
| 69 | + case TroubleIsApprove: | ||
| 70 | + return errors.New("事故不需要重复审核") | ||
| 71 | + default: | ||
| 72 | + m.ApproveAt = &nowTime | ||
| 73 | + m.ApproveStatus = TroubleIsApprove | ||
| 74 | + } | ||
| 75 | + return nil | ||
| 76 | +} |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "time" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +// 事故管理数据结构 | ||
| 10 | +type ProductTrouble struct { | ||
| 11 | + tableName string `comment:" 事故管理" pg:"manufacture.product_trouble,alias:product_trouble"` | ||
| 12 | + Id int ` pg:"pk:id"` // id | ||
| 13 | + CompanyId int //企业id | ||
| 14 | + OrgId int //组织ID | ||
| 15 | + WorkStation domain.WorkStation // 工作位置 | ||
| 16 | + ProductWorker *domain.User // 生产工人 | ||
| 17 | + AmountLoss float64 // 损失的金额 | ||
| 18 | + Types int // 事故类型 | ||
| 19 | + RecordData time.Time // 事故发生的日期 | ||
| 20 | + Remark string // 备注 | ||
| 21 | + ApproveStatus int // 审核状态 1:未审核 2:已审核 3.自动审核 | ||
| 22 | + ApproveAt *time.Time // 审核时间 | ||
| 23 | + ApproveUser *domain.User // 审核人 | ||
| 24 | + CreatedAt time.Time // 创建时间 | ||
| 25 | + UpdatedAt time.Time // 更新时间 | ||
| 26 | + DeletedAt *time.Time // 删除时间 | ||
| 27 | +} |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "time" | ||
| 6 | + | ||
| 7 | + "github.com/go-pg/pg/v10" | ||
| 8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type ProductTroubleRepository struct { | ||
| 14 | + transactionContext *pgTransaction.TransactionContext | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +var _ domain.ProductTroubleRepository = (*ProductTroubleRepository)(nil) | ||
| 18 | + | ||
| 19 | +func NewProductTroubleRepository(transactionContext *pgTransaction.TransactionContext) (*ProductTroubleRepository, error) { | ||
| 20 | + if transactionContext == nil { | ||
| 21 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 22 | + } else { | ||
| 23 | + return &ProductTroubleRepository{ | ||
| 24 | + transactionContext: transactionContext, | ||
| 25 | + }, nil | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func (repo *ProductTroubleRepository) Save(param *domain.ProductTrouble) (*domain.ProductTrouble, error) { | ||
| 30 | + m := models.ProductTrouble{ | ||
| 31 | + Id: param.Id, | ||
| 32 | + CompanyId: param.CompanyId, | ||
| 33 | + OrgId: param.OrgId, | ||
| 34 | + WorkStation: param.WorkStation, | ||
| 35 | + ProductWorker: param.ProductWorker, | ||
| 36 | + AmountLoss: param.AmountLoss, | ||
| 37 | + Types: int(param.Types), | ||
| 38 | + RecordData: param.RecordData, | ||
| 39 | + Remark: param.Remark, | ||
| 40 | + ApproveStatus: int(param.ApproveStatus), | ||
| 41 | + ApproveAt: param.ApproveAt, | ||
| 42 | + ApproveUser: param.ApproveUser, | ||
| 43 | + CreatedAt: param.CreatedAt, | ||
| 44 | + UpdatedAt: param.UpdatedAt, | ||
| 45 | + DeletedAt: param.DeletedAt, | ||
| 46 | + } | ||
| 47 | + tx := repo.transactionContext.PgTx | ||
| 48 | + if param.Id == 0 { | ||
| 49 | + _, err := tx.Model(&m).Insert() | ||
| 50 | + if err != nil { | ||
| 51 | + return nil, err | ||
| 52 | + } | ||
| 53 | + param.Id = m.Id | ||
| 54 | + } else { | ||
| 55 | + _, err := tx.Model(&m).WherePK().Update() | ||
| 56 | + if err != nil { | ||
| 57 | + return nil, err | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + return param, nil | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +func (repo *ProductTroubleRepository) Remove(param *domain.ProductTrouble) (*domain.ProductTrouble, error) { | ||
| 65 | + tx := repo.transactionContext.PgTx | ||
| 66 | + m := new(models.ProductTrouble) | ||
| 67 | + m.Id = param.Id | ||
| 68 | + nowTime := time.Now() | ||
| 69 | + param.DeletedAt = &nowTime | ||
| 70 | + _, err := tx.Model(m). | ||
| 71 | + WherePK().Set("deleted_at=?", nowTime). | ||
| 72 | + Update() | ||
| 73 | + if err != nil { | ||
| 74 | + return param, err | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + return nil, nil | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +func (repo *ProductTroubleRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProductTrouble, error) { | ||
| 81 | + tx := repo.transactionContext.PgTx | ||
| 82 | + m := new(models.ProductTrouble) | ||
| 83 | + query := tx.Model(m).Where("deleted_at isnull") | ||
| 84 | + if v, ok := queryOptions["id"]; ok { | ||
| 85 | + query.Where("id=?", v) | ||
| 86 | + } | ||
| 87 | + err := query.First() | ||
| 88 | + if err != nil { | ||
| 89 | + if err == pg.ErrNoRows { | ||
| 90 | + return nil, domain.ErrorNotFound | ||
| 91 | + } else { | ||
| 92 | + return nil, err | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + result := repo.TransformToDomain(m) | ||
| 96 | + return result, nil | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +func (repo *ProductTroubleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProductTrouble, error) { | ||
| 100 | + tx := repo.transactionContext.PgTx | ||
| 101 | + m := []models.ProductTrouble{} | ||
| 102 | + query := tx.Model(&m). | ||
| 103 | + Where("deleted_at isnull"). | ||
| 104 | + Limit(20) | ||
| 105 | + if v, ok := queryOptions["limit"].(int); ok { | ||
| 106 | + query.Limit(v) | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + if v, ok := queryOptions["offset"].(int); ok { | ||
| 110 | + query.Offset(v) | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + cnt, err := query.SelectAndCount() | ||
| 114 | + if err != nil { | ||
| 115 | + return 0, nil, err | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + var listData []*domain.ProductTrouble | ||
| 119 | + for i := range m { | ||
| 120 | + temp := repo.TransformToDomain(&m[i]) | ||
| 121 | + listData = append(listData, temp) | ||
| 122 | + } | ||
| 123 | + return int64(cnt), listData, nil | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +func (repo *ProductTroubleRepository) TransformToDomain(param *models.ProductTrouble) *domain.ProductTrouble { | ||
| 127 | + return &domain.ProductTrouble{ | ||
| 128 | + Id: param.Id, | ||
| 129 | + CompanyId: param.CompanyId, | ||
| 130 | + OrgId: param.OrgId, | ||
| 131 | + WorkStation: param.WorkStation, | ||
| 132 | + ProductWorker: param.ProductWorker, | ||
| 133 | + AmountLoss: param.AmountLoss, | ||
| 134 | + Types: domain.TroubleType(param.Types), | ||
| 135 | + RecordData: param.RecordData, | ||
| 136 | + Remark: param.Remark, | ||
| 137 | + ApproveStatus: domain.ProductTroubleApprove(param.ApproveStatus), | ||
| 138 | + ApproveAt: param.ApproveAt, | ||
| 139 | + ApproveUser: param.ApproveUser, | ||
| 140 | + CreatedAt: param.CreatedAt, | ||
| 141 | + UpdatedAt: param.UpdatedAt, | ||
| 142 | + DeletedAt: param.DeletedAt, | ||
| 143 | + } | ||
| 144 | +} |
| @@ -55,6 +55,8 @@ func (controller *ExcelDataController) FileImport() { | @@ -55,6 +55,8 @@ func (controller *ExcelDataController) FileImport() { | ||
| 55 | // data, err = excelService.ImportCooperationUser(cmd) | 55 | // data, err = excelService.ImportCooperationUser(cmd) |
| 56 | //case domain.ImportOrganization: | 56 | //case domain.ImportOrganization: |
| 57 | // data, err = excelService.ImportOrganization(cmd) | 57 | // data, err = excelService.ImportOrganization(cmd) |
| 58 | + case "ImportProductRecord": | ||
| 59 | + data, err = excelService.ImportProductRecord(cmd) | ||
| 58 | case "ImportAttendance": | 60 | case "ImportAttendance": |
| 59 | data, err = excelService.ImportDataAttendance(cmd) | 61 | data, err = excelService.ImportDataAttendance(cmd) |
| 60 | default: | 62 | default: |
| @@ -112,7 +114,7 @@ func (controller *ExcelDataController) FileExport() { | @@ -112,7 +114,7 @@ func (controller *ExcelDataController) FileExport() { | ||
| 112 | controller.responseExcelByFile(controller.Ctx, excelTool, filename) | 114 | controller.responseExcelByFile(controller.Ctx, excelTool, filename) |
| 113 | } | 115 | } |
| 114 | 116 | ||
| 115 | -//GetExcelDataFields 获取导出excel数据的可选字段 | 117 | +// GetExcelDataFields 获取导出excel数据的可选字段 |
| 116 | func (controller *ExcelDataController) GetExcelDataFields() { | 118 | func (controller *ExcelDataController) GetExcelDataFields() { |
| 117 | 119 | ||
| 118 | } | 120 | } |
-
请 注册 或 登录 后发表评论