| | |
| | | // @Produce application/json |
| | | // @Param object body request.SendProcessParams true "查询参数" |
| | | // @Success 200 {object} contextx.Response{data=response.ProductProgress} "成功" |
| | | // @Router /v1/plc/productProgress [get] |
| | | // @Router /v1/plc/productProgress [post] |
| | | func (slf *PlcApi) GetProductProgress(c *gin.Context) { |
| | | var params request.SendProcessParams |
| | | var params request.GetProductProgress |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | |
| | | params.PageSize = 1 |
| | | } |
| | | |
| | | taskDataList, count, code := service.NewTaskService().GetTask(params.Page, params.PageSize) |
| | | taskResponse, code := service.NewTaskService().GetTask(params.Page, params.PageSize) |
| | | if code != ecode.OK { |
| | | ctx.Fail(code) |
| | | return |
| | | } |
| | | taskResponse := &response.TaskResponse{ |
| | | Tasks: taskDataList, |
| | | TaskCount: count, |
| | | } |
| | | ctx.OkWithDetailed(taskResponse) |
| | | } |
| | |
| | | "system": { |
| | | "env": "develop", |
| | | "port": 8003, |
| | | "deviceId": "111", |
| | | "deviceId": "qwwt", |
| | | "netSetShellPath": "/data/network/", |
| | | "netUpShellName": "up.sh", |
| | | "netDownShellName": "down.sh" |
| | |
| | | } |
| | | }, |
| | | "/v1/plc/productProgress": { |
| | | "get": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | |
| | | "common.ProductProcedure": { |
| | | "type": "object", |
| | | "properties": { |
| | | "allProcedureNames": { |
| | | "description": "所属工单工序列表", |
| | | "type": "array", |
| | | "items": { |
| | | "type": "string" |
| | | } |
| | | }, |
| | | "deviceId": { |
| | | "type": "string" |
| | | }, |
| | |
| | | }, |
| | | "procedure": { |
| | | "$ref": "#/definitions/model.Procedures" |
| | | }, |
| | | "workers": { |
| | | "description": "人员列表", |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/common.ProcedureWorker" |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | }, |
| | | "/v1/plc/productProgress": { |
| | | "get": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | |
| | | "common.ProductProcedure": { |
| | | "type": "object", |
| | | "properties": { |
| | | "allProcedureNames": { |
| | | "description": "所属工单工序列表", |
| | | "type": "array", |
| | | "items": { |
| | | "type": "string" |
| | | } |
| | | }, |
| | | "deviceId": { |
| | | "type": "string" |
| | | }, |
| | |
| | | }, |
| | | "procedure": { |
| | | "$ref": "#/definitions/model.Procedures" |
| | | }, |
| | | "workers": { |
| | | "description": "人员列表", |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/common.ProcedureWorker" |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | type: object |
| | | common.ProductProcedure: |
| | | properties: |
| | | allProcedureNames: |
| | | description: 所属工单工序列表 |
| | | items: |
| | | type: string |
| | | type: array |
| | | deviceId: |
| | | type: string |
| | | deviceName: |
| | |
| | | type: integer |
| | | procedure: |
| | | $ref: '#/definitions/model.Procedures' |
| | | workers: |
| | | description: 人员列表 |
| | | items: |
| | | $ref: '#/definitions/common.ProcedureWorker' |
| | | type: array |
| | | type: object |
| | | info: |
| | | contact: {} |
| | |
| | | tags: |
| | | - Config |
| | | /v1/plc/productProgress: |
| | | get: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | |
| | | StartTime int64 `gorm:"comment:计划开始时间" json:"startTime"` |
| | | EndTime int64 `gorm:"comment:计划结束时间" json:"endTime"` |
| | | WorkHours decimal.Decimal `gorm:"type:decimal(35,18);comment:工时" json:"workHours"` |
| | | InputMaterials []*ProcedureMaterial `json:"inputMaterials"` // 输入物料列表 |
| | | OutputMaterials []*ProcedureMaterial `json:"outputMaterials"` // 输出物料列表 |
| | | Workers []*ProcedureWorker `json:"workers"` // 人员列表 |
| | | InputMaterials []*ProcedureMaterial `json:"inputMaterials"` // 输入物料列表 |
| | | OutputMaterials []*ProcedureMaterial `json:"outputMaterials"` // 输出物料列表 |
| | | Workers []*ProcedureWorker `json:"workers"` // 人员列表 |
| | | AllProcedureNames []string `json:"allProcedureNames"` // 所属工单工序列表 |
| | | } |
| | | |
| | | DeliverScheduleTask struct { |
| | |
| | | |
| | | import ( |
| | | "apsClient/model" |
| | | "apsClient/model/common" |
| | | ) |
| | | |
| | | type PageResult struct { |
| | |
| | | } |
| | | |
| | | type TaskData struct { |
| | | Order *model.Order |
| | | Procedure *model.Procedures |
| | | Order *model.Order |
| | | Procedure *model.Procedures |
| | | |
| | | Position int //当前任务在设备第几个位置 |
| | | AllProcedures []string |
| | | CurrentProcedureIndex int |
| | |
| | | type TaskResponse struct { |
| | | Tasks []*TaskData |
| | | TaskCount int64 |
| | | Workers []*common.ProcedureWorker `json:"workers"` // 人员列表 |
| | | } |
| | | |
| | | type Config struct { |
| | |
| | | } |
| | | |
| | | procedureRecords := make([]*model.Procedures, 0, len(task.Procedures)) |
| | | procedureIds := make([]string, 0, len(task.Procedures)) |
| | | for _, procedure := range task.Procedures { |
| | | procedureRecord := model.Procedures{ |
| | | WorkOrderID: task.WorkOrder.WorkOrderID, |
| | |
| | | } |
| | | procedureRecord.ProcedureData = string(procedureData) |
| | | procedureRecords = append(procedureRecords, &procedureRecord) |
| | | procedureIds = append(procedureIds, procedure.ProcedureID) |
| | | } |
| | | |
| | | var orderRecord model.Order |
| | |
| | | plcApi := new(v1.PlcApi) |
| | | plcGroup := v1Group.Group("plc") |
| | | { |
| | | plcGroup.GET("productProgress", plcApi.GetProductProgress) // 获取网络配置 |
| | | plcGroup.POST("setProductNumber", plcApi.SetProductNumber) // 下发生产总量 |
| | | plcGroup.POST("productProgress", plcApi.GetProductProgress) // 获取网络配置 |
| | | plcGroup.POST("setProductNumber", plcApi.SetProductNumber) // 下发生产总量 |
| | | } |
| | | |
| | | InitPlcBrandRouter(v1Group) |
| | |
| | | } |
| | | |
| | | // GetTask 获取任务,未完成的开始时间最早的任务 |
| | | func (slf TaskService) GetTask(page, pageSize int) (taskDataList []*response.TaskData, count int64, code int) { |
| | | func (slf TaskService) GetTask(page, pageSize int) (taskResp *response.TaskResponse, code int) { |
| | | var taskList []*response.TaskData |
| | | var count int64 |
| | | var workers []*common.ProcedureWorker |
| | | nowTs := time.Now().Unix() |
| | | var ( |
| | | err error |
| | |
| | | SetPage(page, pageSize). |
| | | FindNotTotal() |
| | | if err != nil { |
| | | return nil, 0, ecode.DBErr |
| | | return nil, ecode.DBErr |
| | | } |
| | | count, err = model.NewProceduresSearch(nil). |
| | | SetDeviceId(conf.Conf.System.DeviceId). |
| | | SetStatusNot(model.ProcedureStatusFinished). |
| | | Count() |
| | | if err != nil { |
| | | return nil, 0, ecode.DBErr |
| | | return nil, ecode.DBErr |
| | | } |
| | | if len(procedures) == 0 { |
| | | return nil, 0, ecode.OK |
| | | return nil, ecode.OK |
| | | } |
| | | |
| | | for _, procedure := range procedures { |
| | |
| | | } |
| | | orders, err = model.NewOrderSearch(nil).SetWorkOrderIds(workOrderIds).FindNotTotal() //由工序反推工单 |
| | | if err != nil { |
| | | return nil, 0, ecode.DBErr |
| | | return nil, ecode.DBErr |
| | | } |
| | | |
| | | orderMap := make(map[string]*model.Order, len(workOrderIds)) |
| | |
| | | taskData := response.TaskData{ |
| | | Order: orderMap[procedure.WorkOrderID], |
| | | Procedure: procedure, |
| | | AllProcedures: nil, |
| | | AllProcedures: procedure.ProceduresInfo.AllProcedureNames, |
| | | CurrentProcedureIndex: 0, |
| | | Position: procedure.Position, |
| | | } |
| | | taskDataList = append(taskDataList, &taskData) |
| | | index := 0 |
| | | for _, name := range procedure.ProceduresInfo.AllProcedureNames { |
| | | if name == procedure.ProceduresInfo.ProcedureName { |
| | | break |
| | | } |
| | | index++ |
| | | } |
| | | taskData.CurrentProcedureIndex = index |
| | | taskList = append(taskList, &taskData) |
| | | workers = append(workers, procedure.ProceduresInfo.Workers...) |
| | | } |
| | | return taskDataList, count, ecode.OK |
| | | taskResp = &response.TaskResponse{ |
| | | Tasks: taskList, |
| | | TaskCount: count, |
| | | Workers: slf.WorkerDistinct(workers), |
| | | } |
| | | return taskResp, ecode.OK |
| | | } |
| | | |
| | | func (slf TaskService) WorkerDistinct(workers []*common.ProcedureWorker) (NoRepeatedWorkers []*common.ProcedureWorker) { |
| | | exists := make(map[string]bool, 0) |
| | | for _, worker := range workers { |
| | | key := fmt.Sprintf("%v%v", worker.WorkerID, worker.StartTime) |
| | | if !exists[key] { |
| | | NoRepeatedWorkers = append(NoRepeatedWorkers, worker) |
| | | exists[key] = true |
| | | } |
| | | } |
| | | return NoRepeatedWorkers |
| | | } |
| | | |
| | | func (slf TaskService) GetProcedureById(id int) (*model.Procedures, int) { |