New file |
| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "apsClient/model/request" |
| | | "apsClient/pkg/contextx" |
| | | "apsClient/pkg/ecode" |
| | | "apsClient/service" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type ProcessModelApi struct{} |
| | | |
| | | // List |
| | | // @Tags 工艺模型 |
| | | // @Summary 获取工艺模型列表 |
| | | // @Produce application/json |
| | | // @Param object query request.ProcessModelList true "查询参数" |
| | | // @Success 200 {object} contextx.Response{data=response.TaskCountdown} "成功" |
| | | // @Router /v1/processModel/list [get] |
| | | func (slf *ProcessModelApi) List(c *gin.Context) { |
| | | var params request.ProcessModelList |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | list, total, err := service.GetProcessModelList(params.Page, params.PageSize) |
| | | if err != nil { |
| | | ctx.Fail(ecode.DBErr) |
| | | return |
| | | } |
| | | ctx.ResultList(list, total) |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/v1/processModel/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "工艺模型" |
| | | ], |
| | | "summary": "获取工艺模型列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.TaskCountdown" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/v1/task/countdown": { |
| | | "get": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/v1/processModel/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "工艺模型" |
| | | ], |
| | | "summary": "获取工艺模型列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.TaskCountdown" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/v1/task/countdown": { |
| | | "get": { |
| | | "produces": [ |
| | |
| | | summary: 更新plc品牌 |
| | | tags: |
| | | - plc品牌 |
| | | /v1/processModel/list: |
| | | get: |
| | | parameters: |
| | | - description: 页码 |
| | | in: query |
| | | name: page |
| | | type: integer |
| | | - description: 每页大小 |
| | | in: query |
| | | name: pageSize |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/contextx.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.TaskCountdown' |
| | | type: object |
| | | summary: 获取工艺模型列表 |
| | | tags: |
| | | - 工艺模型 |
| | | /v1/task/countdown: |
| | | get: |
| | | produces: |
| | |
| | | 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"` //工艺模型编号 |
| | |
| | | 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消息 |
| | | DeviceId string `json:"deviceId" gorm:"-"` //用于过滤获取nsq消息 |
| | | IsNew bool `json:"isNew" gorm:"column:is_new;comment:是否最新的"` //是否最新的 |
| | | } |
| | | |
| | | 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 { |
| | |
| | | slf.Product = product |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProcessModelSearch) SetProcedure(procedure string) *ProcessModelSearch { |
| | | slf.Procedure = procedure |
| | | return slf |
| | | } |
| | | |
| | | 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("`procedure` = ?", slf.Procedure) |
| | | } |
| | | |
| | | if len(slf.Procedures) != 0 { |
| | | db = db.Where("`procedure` in ?", slf.Procedures) |
| | | } |
| | | |
| | | if len(slf.Number) != 0 { |
| | | db = db.Where("number = ?", slf.Number) |
| | | } |
| | |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.IsNew { |
| | | db = db.Where("is_new = ?", 1) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | |
| | | ProcedureId int `json:"procedureId" binding:"required"` |
| | | Channel int32 `json:"channel"` |
| | | } |
| | | |
| | | // ProcessModelList 工艺参数列表请求参数 |
| | | type ProcessModelList struct { |
| | | PageInfo |
| | | } |
| | |
| | | logx.Infof("unmarshal process params sync err :%s", err) |
| | | return err |
| | | } |
| | | err = model.NewProcessModelSearch().Save(&processModel) |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = model.NewProcessModelSearch().SetOrm(db).SetProduct(processModel.Product).SetProcedure(processModel.Procedure). |
| | | UpdateByMap(map[string]interface{}{"is_new": 0}) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | processModel.IsNew = true |
| | | return model.NewProcessModelSearch().SetOrm(db).Create(&processModel) |
| | | }) |
| | | |
| | | if err != nil { |
| | | logx.Infof("save process params sync err :%s", err) |
| | | return err |
| | |
| | | plcGroup.POST("setProductNumber", plcApi.SetProductNumber) // 下发生产总量 |
| | | } |
| | | |
| | | processModelApi := new(v1.ProcessModelApi) |
| | | processModelGroup := v1Group.Group("processModel") |
| | | { |
| | | processModelGroup.GET("list", processModelApi.List) // 新任务倒计时 |
| | | } |
| | | |
| | | eventsApi := new(v1.EventsApi) |
| | | eventsGroup := v1Group.Group("events") |
| | | { |
| | |
| | | package service |
| | | |
| | | type ProcessModel struct{} |
| | | |
| | | const ( |
| | | GetProcessModelUrl = "/api-s/v1/processParams/info" |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/model" |
| | | ) |
| | | |
| | | type GetProcessModelParams struct { |
| | | WorkOrder string `json:"workOrder,omitempty" form:"workOrder"` //工序编号 |
| | | OrderId string `json:"orderId"` // 订单号 |
| | | Product string `json:"password"` // 产品 |
| | | Procedure string `json:"procedure"` // 工序 |
| | | Device string `json:"device"` // 设备 |
| | | func GetProcessModelList(page, pageSize int) (list []*model.ProcessModel, total int64, err error) { |
| | | device, err := model.NewDeviceSearch().SetDeviceId(conf.Conf.System.DeviceId).First() |
| | | if err != nil { |
| | | return |
| | | } |
| | | list, total, err = model.NewProcessModelSearch(). |
| | | SetIsNew(true). |
| | | SetPage(page, pageSize).SetProcedures(device.ProceduresArr).Find() |
| | | return |
| | | } |
| | | type GetProcessModel struct { |
| | | Number string `json:"number"` //工艺模型编号 |
| | | OrderId string `json:"orderId"` //订单id |
| | | Product string `json:"product"` //产品名称 |
| | | Procedure string `json:"procedure"` //工序 |
| | | WorkOrder string `json:"workOrder"` //工单 |
| | | Device string `json:"device"` //设备 |
| | | ParamsMap map[string]interface{} `json:"paramsMap"` |
| | | } |
| | | |
| | | type GetProcessModelResponse struct { |
| | | Code int |
| | | Msg string |
| | | Data GetProcessModel |
| | | } |
| | | |
| | | //// GetProcessModel 获取工艺模型 |
| | | //func (slf ProcessModel) GetProcessModel(params GetProcessModelParams) (GetProcessModel GetProcessModel, err error) { |
| | | // resp := new(GetProcessModelResponse) |
| | | // err = httpx.SendPostAndParseJson(conf.Conf.Services.ApsServer+GetProcessModelUrl, params, resp) |
| | | // return resp.Data, err |
| | | //} |
| | |
| | | "apsClient/pkg/ecode" |
| | | "apsClient/pkg/logx" |
| | | "apsClient/pkg/structx" |
| | | "encoding/json" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "time" |
| | |
| | | return nil, err |
| | | } |
| | | if err == nil { |
| | | err = json.Unmarshal([]byte(data.Params), &data.ParamsMap) |
| | | if err != nil { |
| | | logx.Errorf("process model json.Unmarshal:%v", err) |
| | | return |
| | | } |
| | | return data, nil |
| | | } |
| | | |