增加当前时间可以开始但是未开始的任务接口,增加是否可以开始字段
| | |
| | | params.PageSize = 1 |
| | | } |
| | | |
| | | taskResponse, code := service.NewTaskService().GetTask(params.Page, params.PageSize) |
| | | taskResponse, code := service.NewTaskService().GetTask(params.Page, params.PageSize, service.TaskModeCurrent) //取进行中的或未开始的 |
| | | if code != ecode.OK { |
| | | ctx.Fail(code) |
| | | return |
| | | } |
| | | if len(taskResponse.Tasks) == 0 { |
| | | taskResponse, code = service.NewTaskService().GetTask(params.Page, params.PageSize, service.TaskModeLastFinished) //取上一个完成的 |
| | | if code != ecode.OK { |
| | | ctx.Fail(code) |
| | | return |
| | | } |
| | | } |
| | | |
| | | for _, task := range taskResponse.Tasks { |
| | | if task.Procedure.Status == model.ProcedureStatusWaitProcess { |
| | | task.CanStarted = true |
| | | } |
| | | } |
| | | |
| | | ctx.OkWithDetailed(taskResponse) |
| | | } |
| | | |
| | | // TaskGetUnStarted |
| | | // @Tags Task |
| | | // @Summary 获取未开始的任务 |
| | | // @Produce application/json |
| | | // @Param object query request.TaskList true "查询参数" |
| | | // @Success 200 {object} contextx.Response{data=response.TaskData} "成功" |
| | | // @Router /v1/task/get/unStarted [get] |
| | | func (slf *TaskApi) TaskGetUnStarted(c *gin.Context) { |
| | | var params request.TaskList |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | if params.Page <= 0 { |
| | | params.Page = 1 |
| | | } |
| | | if params.PageSize <= 0 { |
| | | params.PageSize = 1 |
| | | } |
| | | |
| | | taskResponse, code := service.NewTaskService().GetTask(params.Page, params.PageSize, service.TaskModeUnStarted) //时间到了未开始的 |
| | | if code != ecode.OK { |
| | | ctx.Fail(code) |
| | | return |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/v1/task/get/unStarted": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Task" |
| | | ], |
| | | "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.TaskData" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/v1/task/sendProcessParams": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | "type": "object", |
| | | "properties": { |
| | | "address": { |
| | | "description": "PortName string ` + "`" + `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"` + "`" + `\nFrequency int ` + "`" + `gorm:\"type:int(11);comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"` + "`" + `", |
| | | "description": "PortName string ` + "`" + `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"` + "`" + `\nFrequency int ` + "`" + `gorm:\"comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"` + "`" + `", |
| | | "type": "string" |
| | | }, |
| | | "baudRate": { |
| | |
| | | "type": "object", |
| | | "properties": { |
| | | "address": { |
| | | "description": "PortName string ` + "`" + `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"` + "`" + `\nFrequency int ` + "`" + `gorm:\"type:int(11);comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"` + "`" + `", |
| | | "description": "PortName string ` + "`" + `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"` + "`" + `\nFrequency int ` + "`" + `gorm:\"comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"` + "`" + `", |
| | | "type": "string" |
| | | }, |
| | | "baudRate": { |
| | |
| | | "type": "string" |
| | | } |
| | | }, |
| | | "canStarted": { |
| | | "description": "是否可以开始生产", |
| | | "type": "boolean" |
| | | }, |
| | | "currentProcedureIndex": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/v1/task/get/unStarted": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Task" |
| | | ], |
| | | "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.TaskData" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/v1/task/sendProcessParams": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | "type": "object", |
| | | "properties": { |
| | | "address": { |
| | | "description": "PortName string `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"`\nFrequency int `gorm:\"type:int(11);comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"`", |
| | | "description": "PortName string `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"`\nFrequency int `gorm:\"comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"`", |
| | | "type": "string" |
| | | }, |
| | | "baudRate": { |
| | |
| | | "type": "object", |
| | | "properties": { |
| | | "address": { |
| | | "description": "PortName string `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"`\nFrequency int `gorm:\"type:int(11);comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"`", |
| | | "description": "PortName string `gorm:\"type:varchar(191);comment:端口名称\" json:\"portName\"`\nFrequency int `gorm:\"comment:数据更新频率 0-实时更新 1-1次/秒\" json:\"frequency\"`", |
| | | "type": "string" |
| | | }, |
| | | "baudRate": { |
| | |
| | | "type": "string" |
| | | } |
| | | }, |
| | | "canStarted": { |
| | | "description": "是否可以开始生产", |
| | | "type": "boolean" |
| | | }, |
| | | "currentProcedureIndex": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | address: |
| | | description: |- |
| | | PortName string `gorm:"type:varchar(191);comment:端口名称" json:"portName"` |
| | | Frequency int `gorm:"type:int(11);comment:数据更新频率 0-实时更新 1-1次/秒" json:"frequency"` |
| | | Frequency int `gorm:"comment:数据更新频率 0-实时更新 1-1次/秒" json:"frequency"` |
| | | type: string |
| | | baudRate: |
| | | description: 串口波特率, method = serial时 用 |
| | |
| | | address: |
| | | description: |- |
| | | PortName string `gorm:"type:varchar(191);comment:端口名称" json:"portName"` |
| | | Frequency int `gorm:"type:int(11);comment:数据更新频率 0-实时更新 1-1次/秒" json:"frequency"` |
| | | Frequency int `gorm:"comment:数据更新频率 0-实时更新 1-1次/秒" json:"frequency"` |
| | | type: string |
| | | baudRate: |
| | | description: 串口波特率, method = serial时 用 |
| | |
| | | items: |
| | | type: string |
| | | type: array |
| | | canStarted: |
| | | description: 是否可以开始生产 |
| | | type: boolean |
| | | currentProcedureIndex: |
| | | type: integer |
| | | order: |
| | |
| | | summary: 获取任务 |
| | | tags: |
| | | - Task |
| | | /v1/task/get/unStarted: |
| | | 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.TaskData' |
| | | type: object |
| | | summary: 获取未开始的任务 |
| | | tags: |
| | | - Task |
| | | /v1/task/sendProcessParams: |
| | | post: |
| | | parameters: |
| | |
| | | Position int //当前任务在设备第几个位置 |
| | | AllProcedures []string |
| | | CurrentProcedureIndex int |
| | | CanStarted bool //是否可以开始生产 |
| | | } |
| | | |
| | | type TaskResponse struct { |
| | |
| | | taskApi := new(v1.TaskApi) |
| | | taskGroup := v1Group.Group("task") |
| | | { |
| | | taskGroup.GET("countdown", taskApi.TaskCountdown) // 新任务倒计时 |
| | | taskGroup.GET("get", taskApi.TaskGet) // 获取工序 |
| | | taskGroup.GET("start/:id", taskApi.GetProcessParams) // 获取工艺参数 |
| | | taskGroup.POST("sendProcessParams", taskApi.TaskStart) // 下发工艺参数并开始工序 |
| | | taskGroup.PUT("finish/:id", taskApi.TaskFinish) // 完成工序 |
| | | taskGroup.GET("countdown", taskApi.TaskCountdown) // 新任务倒计时 |
| | | taskGroup.GET("get", taskApi.TaskGet) // 获取工序 |
| | | taskGroup.GET("get/unStarted", taskApi.TaskGetUnStarted) // 时间到了未开始的任务 |
| | | taskGroup.GET("start/:id", taskApi.GetProcessParams) // 获取工艺参数 |
| | | taskGroup.POST("sendProcessParams", taskApi.TaskStart) // 下发工艺参数并开始工序 |
| | | taskGroup.PUT("finish/:id", taskApi.TaskFinish) // 完成工序 |
| | | } |
| | | |
| | | configApi := new(v1.ConfigApi) |
| | |
| | | return &TaskService{} |
| | | } |
| | | |
| | | type TaskMode int |
| | | |
| | | const ( |
| | | TaskModeUnStarted TaskMode = 1 //未开始的 |
| | | TaskModeCurrent TaskMode = 2 |
| | | TaskModeLastFinished TaskMode = 3 //上一个结束的 |
| | | ) |
| | | |
| | | // GetTask 获取任务,未完成的开始时间小于等于当前时间,结束时间大于当前时间的任务 |
| | | func (slf TaskService) GetTask(page, pageSize int) (taskResp *response.TaskResponse, code int) { |
| | | func (slf TaskService) GetTask(page, pageSize int, mode TaskMode) (taskResp *response.TaskResponse, code int) { |
| | | var taskList []*response.TaskData |
| | | var count int64 |
| | | var workers []*common.ProcedureWorker |
| | |
| | | procedures []*model.Procedures |
| | | workOrderIds []string |
| | | ) |
| | | procedures, err = model.NewProceduresSearch(nil).SetOrder("start_time asc"). |
| | | SetStartTimeMax(nowTs). |
| | | SetEndTimeMin(nowTs). |
| | | search := model.NewProceduresSearch(nil). |
| | | SetDeviceId(conf.Conf.System.DeviceId). |
| | | SetStatusNot(model.ProcedureStatusFinished). |
| | | SetPage(page, pageSize). |
| | | SetOrder("status desc"). |
| | | FindNotTotal() |
| | | SetPage(page, pageSize) |
| | | |
| | | if mode == TaskModeUnStarted { |
| | | search.SetStatus(model.ProcedureStatusWaitProcess). |
| | | SetStartTimeMax(nowTs). |
| | | SetEndTimeMin(nowTs). |
| | | SetOrder("start_time asc") |
| | | } else if mode == TaskModeCurrent { |
| | | search.SetStatusNot(model.ProcedureStatusFinished). |
| | | SetStartTimeMax(nowTs). |
| | | SetEndTimeMin(nowTs). |
| | | SetOrder("start_time asc, status desc") |
| | | } else if mode == TaskModeLastFinished { |
| | | search.SetStatus(model.ProcedureStatusFinished).SetOrder("updated_at desc") |
| | | } |
| | | |
| | | procedures, err = search.FindNotTotal() |
| | | if err != nil { |
| | | return nil, ecode.DBErr |
| | | } |
| | | count, err = model.NewProceduresSearch(nil). |
| | | SetDeviceId(conf.Conf.System.DeviceId). |
| | | SetStatusNot(model.ProcedureStatusFinished). |
| | | Count() |
| | | count, err = search.Count() |
| | | if err != nil { |
| | | return nil, ecode.DBErr |
| | | } |