| | |
| | | package model |
| | | |
| | | import ( |
| | | "apsClient/pkg/logx" |
| | | "apsClient/pkg/sqlitex" |
| | | "encoding/json" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | // ProcessModel 工艺流程参数 |
| | | // ProcessModel 工艺参数 |
| | | ProcessModel struct { |
| | | gorm.Model `json:"-"` |
| | | Number string `gorm:"index;column:number;type:varchar(255);not null;default '';comment:工艺模型编号" json:"number"` //工艺模型编号 |
| | | OrderId string `gorm:"column:order_id;type:varchar(255);not null;default '';comment:订单id" json:"orderId"` //订单id |
| | | Product string `gorm:"column:product;type:varchar(255);not null;default '';comment:产品名称" json:"product"` //产品名称 |
| | | Procedure string `gorm:"column:procedure;type:varchar(255);not null;default '';comment:工序" json:"procedure"` //工序 |
| | | WorkOrder string `gorm:"column:work_order;type:varchar(255);not null;default '';comment:工单" json:"workOrder"` //工单 |
| | | Device string `gorm:"column:device;type:varchar(255);not null;default '';comment:设备" json:"device"` //设备 |
| | | Params string `json:"-" gorm:"type:text;comment:工艺参数键值对json串"` |
| | | ParamsMap map[string]interface{} `json:"paramsMap" gorm:"-"` |
| | | gorm.Model `json:"-"` |
| | | Number string `gorm:"index;column:number;type:varchar(255);not null;default '';comment:工艺模型编号" json:"number"` //工艺模型编号 |
| | | Product string `gorm:"column:product;type:varchar(255);not null;default '';comment:产品名称" json:"product"` //产品名称 |
| | | Procedure string `gorm:"column:procedure;type:varchar(255);not null;default '';comment:工序" json:"procedure"` //工序 |
| | | Params string `gorm:"type:text;comment:工艺参数键值对json串"` |
| | | ParamsMap map[string]interface{} `json:"paramsMap" gorm:"-"` |
| | | DeviceId string `json:"deviceId" gorm:"-"` //用于过滤获取nsq消息 |
| | | IsNew bool `json:"-" gorm:"column:is_new;comment:是否最新的"` //是否最新的 |
| | | IsUpdate bool `json:"isUpdate" gorm:"-"` //前端用 |
| | | NewParamsMap map[string]interface{} `json:"newParamsMap" gorm:"-"` |
| | | NewNumber string `json:"newNumber" gorm:"-"` |
| | | } |
| | | |
| | | ProcessModelSearch struct { |
| | | ProcessModel |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Procedures []string |
| | | } |
| | | ) |
| | | |
| | | func (slf *ProcessModel) TableName() string { |
| | | return "process_model" |
| | | } |
| | | |
| | | func (slf *ProcessModel) AfterFind(db *gorm.DB) error { |
| | | err := json.Unmarshal([]byte(slf.Params), &slf.ParamsMap) |
| | | if err != nil { |
| | | logx.Errorf("process model json.Unmarshal:%v", err) |
| | | return err |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func NewProcessModelSearch() *ProcessModelSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProcessModelSearch) SetWorkOrder(workOrder string) *ProcessModelSearch { |
| | | slf.WorkOrder = workOrder |
| | | return slf |
| | | } |
| | | func (slf *ProcessModelSearch) SetOrderId(orderId string) *ProcessModelSearch { |
| | | slf.OrderId = orderId |
| | | return slf |
| | | } |
| | | func (slf *ProcessModelSearch) SetProduct(product string) *ProcessModelSearch { |
| | | slf.Product = product |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProcessModelSearch) SetProcedure(procedure string) *ProcessModelSearch { |
| | | slf.Procedure = procedure |
| | | return slf |
| | | } |
| | | func (slf *ProcessModelSearch) SetDevice(device string) *ProcessModelSearch { |
| | | slf.Device = device |
| | | |
| | | func (slf *ProcessModelSearch) SetProcedures(procedures []string) *ProcessModelSearch { |
| | | slf.Procedures = procedures |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProcessModelSearch) SetIsNew(isNew bool) *ProcessModelSearch { |
| | | slf.IsNew = isNew |
| | | return slf |
| | | } |
| | | |
| | |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | |
| | | if len(slf.WorkOrder) != 0 { |
| | | db = db.Where("work_order = ?", slf.WorkOrder) |
| | | } |
| | | |
| | | if len(slf.OrderId) != 0 { |
| | | db = db.Where("order_id = ?", slf.OrderId) |
| | | } |
| | | |
| | | if len(slf.Product) != 0 { |
| | | db = db.Where("product = ?", slf.Product) |
| | | } |
| | |
| | | db = db.Where("`procedure` = ?", slf.Procedure) |
| | | } |
| | | |
| | | if len(slf.Device) != 0 { |
| | | db = db.Where("device = ?", slf.Device) |
| | | if len(slf.Procedures) != 0 { |
| | | db = db.Where("`procedure` in ?", slf.Procedures) |
| | | } |
| | | |
| | | if len(slf.Number) != 0 { |
| | |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.IsNew { |
| | | db = db.Where("is_new = ?", 1) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |