zhangqian
2023-08-19 066a30751bdc20f9e83b34539de71ae392783e1b
网络配置获取和删除,品牌增删改查
11个文件已添加
13个文件已修改
2472 ■■■■ 已修改文件
api/v1/config.go 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/config2.go 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/plc_brand.go 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/task.go 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/plcBrand.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 564 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 564 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 364 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/common/common.go 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/net_config.go 217 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/plc_brand.go 145 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/procedures.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/plcBrand.go 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/schedule_task.go 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/common.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/work_order.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
nsq/msg_handler.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/contextx/contextx.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/plc_brand.go 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/config.go 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/plc_brand.go 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/task.go 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/config.go
New file
@@ -0,0 +1,66 @@
package v1
import (
    "apsClient/model"
    _ "apsClient/model/response"
    "apsClient/pkg/contextx"
    "apsClient/pkg/ecode"
    "apsClient/pkg/logx"
    "apsClient/service"
    "github.com/gin-gonic/gin"
)
type ConfigApi struct{}
// GetNetConfig
// @Tags      Config
// @Summary   获取网络配置
// @Produce   application/json
// @Success   200   {object}  contextx.Response{data=[]model.NetConfig}  "成功"
// @Router    /v1/config/net [get]
func (slf *ConfigApi) GetNetConfig(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    ConfigData, err := service.NewConfigService().GetNetConfigList()
    if err != nil {
        logx.Errorf("get net config error: %v", err.Error())
        ctx.FailWithMsg(ecode.UnknownErr, "获取网络配置失败")
        return
    }
    ctx.OkWithDetailed(ConfigData)
}
// SetNetConfig
// @Tags      Config
// @Summary   设置网络配置
// @Produce   application/json
// @Param      object    body  model.NetConfig    true    "参数"
// @Success   200   {object}  contextx.Response{data=[]response.ProcessParams}  "成功"
// @Router    /v1/config/net [put]
func (slf *ConfigApi) SetNetConfig(c *gin.Context) {
    var params model.NetConfig
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    _, err := service.NewConfigService().GetNetConfig(params.Id)
    if err != nil {
        logx.Errorf("get net config error: %v", err.Error())
        ctx.FailWithMsg(ecode.UnknownErr, "获取网络配置失败")
        return
    }
    err = service.NewConfigService().SetNetConfig(params.Id, &params)
    if err != nil {
        logx.Errorf("SetNetConfig error: %v", err.Error())
        ctx.FailWithMsg(ecode.DBErr, "设置失败")
        return
    }
    ctx.Ok()
}
api/v1/config2.go
New file
@@ -0,0 +1,66 @@
package v1
import (
    "apsClient/model"
    _ "apsClient/model/response"
    "apsClient/pkg/contextx"
    "apsClient/pkg/ecode"
    "apsClient/pkg/logx"
    "apsClient/service"
    "github.com/gin-gonic/gin"
)
type ConfigApi2 struct{}
// GetNetConfig
// @Tags      Config
// @Summary   获取网络配置
// @Produce   application/json
// @Success   200   {object}  contextx.Response{data=[]model.NetConfig}  "成功"
// @Router    /v1/cc/nn [get]
func (slf *ConfigApi2) GetNetConfig(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    ConfigData, err := service.NewConfigService().GetNetConfigList()
    if err != nil {
        logx.Errorf("get net config error: %v", err.Error())
        ctx.FailWithMsg(ecode.UnknownErr, "获取网络配置失败")
        return
    }
    ctx.OkWithDetailed(ConfigData)
}
// SetNetConfig
// @Tags      Config
// @Summary   设置网络配置
// @Produce   application/json
// @Param      object    body  model.NetConfig    true    "参数"
// @Success   200   {object}  contextx.Response{data=[]response.ProcessParams}  "成功"
// @Router    /v1/cc/nn [put]
func (slf *ConfigApi2) SetNetConfig(c *gin.Context) {
    var params model.NetConfig
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    _, err := service.NewConfigService().GetNetConfig(params.Id)
    if err != nil {
        logx.Errorf("get net config error: %v", err.Error())
        ctx.FailWithMsg(ecode.UnknownErr, "获取网络配置失败")
        return
    }
    err = service.NewConfigService().SetNetConfig(params.Id, &params)
    if err != nil {
        logx.Errorf("SetNetConfig error: %v", err.Error())
        ctx.FailWithMsg(ecode.DBErr, "设置失败")
        return
    }
    ctx.Ok()
}
api/v1/plc_brand.go
New file
@@ -0,0 +1,110 @@
package v1
import (
    "apsClient/model/request"
    "apsClient/model/response"
    "apsClient/pkg/contextx"
    "apsClient/pkg/ecode"
    "apsClient/service"
    "github.com/gin-gonic/gin"
    "strconv"
)
type PlcBrandApi struct{}
// Add
// @Tags    plc品牌
// @Summary    添加plc品牌
// @Produce    application/json
// @Param        object    body        request.AddPlcBrand    true    "查询参数"
// @Success    200        {object}    contextx.Response{}
// @Router        /v1/plcBrand/add [post]
func (s *PlcBrandApi) Add(c *gin.Context) {
    var params request.AddPlcBrand
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := service.NewPlcBrandService().AddPlcBrand(&params.PlcBrand)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
// @Tags        plc品牌
// @Summary    删除plc品牌
// @Produce    application/json
// @Param        id    path        int    true    "查询参数"
// @Success    200    {object}    contextx.Response{}
// @Router        /v1/plcBrand/delete/{id} [delete]
func (s *PlcBrandApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := service.NewPlcBrandService().DeletePlcBrand(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
// @Tags        plc品牌
// @Summary    更新plc品牌
// @Produce    application/json
// @Param        object    body        request.UpdatePlcBrand    true    "查询参数"
// @Success    200        {object}    contextx.Response{}
// @Router        /v1/plcBrand/update [put]
func (s *PlcBrandApi) Update(c *gin.Context) {
    var params request.UpdatePlcBrand
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    if params.Id == 0 {
        ctx.Fail(ecode.ParamsErr)
    }
    params.PlcBrand.Id = params.Id
    errCode := service.NewPlcBrandService().UpdatePlcBrand(&params.PlcBrand)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
// @Tags        plc品牌
// @Summary    获取plc品牌列表
// @Produce    application/json
// @Success    200    {object}    response.ListResponse{data=[]model.PlcBrand}
// @Router        /v1/plcBrand/list [get]
func (s *PlcBrandApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    plcBrand, total, errCode := service.NewPlcBrandService().GetPlcBrandList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.ListResponse{
        Data:  plcBrand,
        Count: total,
    })
}
api/v1/task.go
@@ -59,6 +59,12 @@
        ctx.Fail(code)
        return
    }
    if procedure.Status != model.ProcedureStatusUnFinished {
        ctx.FailWithMsg(ecode.ParamsErr, "该工序已结束")
        return
    }
    order, err := service.NewTaskService().GetOrderByWorkOrderId(procedure.WorkOrderID)
    if err != nil {
        ctx.Fail(ecode.UnknownErr)
@@ -77,7 +83,7 @@
    if err != nil {
        logx.Errorf("TaskStart Notice GetProcessModel error: %v", err.Error())
        ctx.Fail(ecode.UnknownErr)
        ctx.FailWithMsg(ecode.UnknownErr, "未获取到工艺参数")
        return
    }
    processParamsArr := make([]*response.ProcessParams, 0, len(resp.ParamsMap))
constvar/plcBrand.go
New file
@@ -0,0 +1,12 @@
package constvar
type PlcBrandQueryClass string
const (
    PlcBrandQueryClassExpireLessThen60Days PlcBrandQueryClass = ""
)
type PlcBrandKeywordType string
const (
    PlcBrandKeywordCustomerName   PlcBrandKeywordType = ""
)
docs/docs.go
@@ -16,6 +16,282 @@
    "host": "{{.Host}}",
    "basePath": "{{.BasePath}}",
    "paths": {
        "/v1/cc/nn": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "获取网络配置",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.NetConfig"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            },
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "设置网络配置",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/model.NetConfig"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/response.ProcessParams"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/v1/config/net": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "获取网络配置",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.NetConfig"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            },
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "设置网络配置",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/model.NetConfig"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/response.ProcessParams"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "添加plc品牌",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddPlcBrand"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "删除plc品牌",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "获取plc品牌列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.ListResponse"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.PlcBrand"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "更新plc品牌",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdatePlcBrand"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/task/finish/{id}": {
            "put": {
                "produces": [
@@ -148,6 +424,90 @@
        }
    },
    "definitions": {
        "common.ProcedureMaterial": {
            "type": "object",
            "properties": {
                "amount": {
                    "type": "number"
                },
                "materialId": {
                    "type": "string"
                },
                "materialName": {
                    "type": "string"
                },
                "unit": {
                    "type": "string"
                }
            }
        },
        "common.ProcedureWorker": {
            "type": "object",
            "properties": {
                "endTime": {
                    "type": "integer"
                },
                "phoneNum": {
                    "type": "string"
                },
                "startTime": {
                    "type": "integer"
                },
                "workerId": {
                    "type": "string"
                },
                "workerName": {
                    "type": "string"
                }
            }
        },
        "common.ProductProcedure": {
            "type": "object",
            "properties": {
                "deviceId": {
                    "type": "string"
                },
                "deviceName": {
                    "type": "string"
                },
                "endTime": {
                    "type": "integer"
                },
                "inputMaterials": {
                    "description": "输入物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/common.ProcedureMaterial"
                    }
                },
                "outputMaterials": {
                    "description": "输出物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/common.ProcedureMaterial"
                    }
                },
                "procedureId": {
                    "type": "string"
                },
                "procedureName": {
                    "type": "string"
                },
                "startTime": {
                    "type": "integer"
                },
                "workHours": {
                    "type": "number"
                },
                "workers": {
                    "description": "人员列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/common.ProcedureWorker"
                    }
                }
            }
        },
        "contextx.Response": {
            "type": "object",
            "properties": {
@@ -159,6 +519,63 @@
                    "type": "string"
                }
            }
        },
        "model.NetConfig": {
            "type": "object",
            "required": [
                "gateway",
                "ip",
                "mask",
                "networkCard"
            ],
            "properties": {
                "dns": {
                    "description": "dns",
                    "type": "string"
                },
                "gateway": {
                    "description": "网关",
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "ip": {
                    "description": "本机ip",
                    "type": "string"
                },
                "mask": {
                    "description": "子网掩码",
                    "type": "string"
                },
                "networkCard": {
                    "description": "网卡",
                    "type": "string"
                },
                "status": {
                    "description": "状态(1启用2禁用)",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.NetConfigStatus"
                        }
                    ]
                }
            }
        },
        "model.NetConfigStatus": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-comments": {
                "NetConfigStatusDisabled": "关闭",
                "NetConfigStatusEnabled": "开启"
            },
            "x-enum-varnames": [
                "NetConfigStatusEnabled",
                "NetConfigStatusDisabled"
            ]
        },
        "model.Order": {
            "type": "object",
@@ -194,6 +611,9 @@
                "startTime": {
                    "type": "integer"
                },
                "status": {
                    "$ref": "#/definitions/model.OrderStatus"
                },
                "unit": {
                    "type": "string"
                },
@@ -202,103 +622,98 @@
                }
            }
        },
        "model.Procedures": {
        "model.OrderStatus": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-varnames": [
                "OrderStatusUnFinished",
                "OrderStatusFinished"
            ]
        },
        "model.PlcBrand": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.ProcedureStatus": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-varnames": [
                "ProcedureStatusUnFinished",
                "ProcedureStatusFinished"
            ]
        },
        "model.Procedures": {
            "type": "object",
            "properties": {
                "endTime": {
                    "type": "integer"
                },
                "id": {
                    "type": "integer"
                },
                "procedure": {
                    "description": "request.ProductProcedure  对象",
                    "description": "common.ProductProcedure  对象",
                    "allOf": [
                        {
                            "$ref": "#/definitions/request.ProductProcedure"
                            "$ref": "#/definitions/common.ProductProcedure"
                        }
                    ]
                }
            }
        },
        "request.ProcedureMaterial": {
            "type": "object",
            "properties": {
                "amount": {
                    "type": "number"
                },
                "materialId": {
                    "type": "string"
                },
                "materialName": {
                    "type": "string"
                },
                "unit": {
                    "type": "string"
                }
            }
        },
        "request.ProcedureWorker": {
            "type": "object",
            "properties": {
                "endTime": {
                    "type": "integer"
                },
                "phoneNum": {
                    "type": "string"
                },
                "startTime": {
                    "type": "integer"
                },
                "workerId": {
                    "type": "string"
                "status": {
                    "$ref": "#/definitions/model.ProcedureStatus"
                }
            }
        },
        "request.AddPlcBrand": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "workerName": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.ProductProcedure": {
        "request.UpdatePlcBrand": {
            "type": "object",
            "properties": {
                "deviceId": {
                    "type": "string"
                },
                "deviceName": {
                    "type": "string"
                },
                "endTime": {
                "id": {
                    "type": "integer"
                },
                "inputMaterials": {
                    "description": "输入物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.ProcedureMaterial"
                    }
                },
                "outputMaterials": {
                    "description": "输出物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.ProcedureMaterial"
                    }
                },
                "procedureId": {
                "name": {
                    "type": "string"
                },
                "procedureName": {
                    "type": "string"
                },
                "startTime": {
                }
            }
        },
        "response.ListResponse": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "workHours": {
                    "type": "number"
                "count": {
                    "type": "integer"
                },
                "workers": {
                    "description": "人员列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.ProcedureWorker"
                    }
                "data": {},
                "msg": {
                    "type": "string"
                }
            }
        },
@@ -314,6 +729,15 @@
        "response.TaskData": {
            "type": "object",
            "properties": {
                "deviceName": {
                    "type": "string"
                },
                "deviceStatus": {
                    "type": "string"
                },
                "nextProcedure": {
                    "$ref": "#/definitions/model.Procedures"
                },
                "order": {
                    "$ref": "#/definitions/model.Order"
                },
docs/swagger.json
@@ -4,6 +4,282 @@
        "contact": {}
    },
    "paths": {
        "/v1/cc/nn": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "获取网络配置",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.NetConfig"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            },
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "设置网络配置",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/model.NetConfig"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/response.ProcessParams"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/v1/config/net": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "获取网络配置",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.NetConfig"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            },
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Config"
                ],
                "summary": "设置网络配置",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/model.NetConfig"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/response.ProcessParams"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "添加plc品牌",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddPlcBrand"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "删除plc品牌",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "获取plc品牌列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.ListResponse"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.PlcBrand"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/v1/plcBrand/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "plc品牌"
                ],
                "summary": "更新plc品牌",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdatePlcBrand"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/task/finish/{id}": {
            "put": {
                "produces": [
@@ -136,6 +412,90 @@
        }
    },
    "definitions": {
        "common.ProcedureMaterial": {
            "type": "object",
            "properties": {
                "amount": {
                    "type": "number"
                },
                "materialId": {
                    "type": "string"
                },
                "materialName": {
                    "type": "string"
                },
                "unit": {
                    "type": "string"
                }
            }
        },
        "common.ProcedureWorker": {
            "type": "object",
            "properties": {
                "endTime": {
                    "type": "integer"
                },
                "phoneNum": {
                    "type": "string"
                },
                "startTime": {
                    "type": "integer"
                },
                "workerId": {
                    "type": "string"
                },
                "workerName": {
                    "type": "string"
                }
            }
        },
        "common.ProductProcedure": {
            "type": "object",
            "properties": {
                "deviceId": {
                    "type": "string"
                },
                "deviceName": {
                    "type": "string"
                },
                "endTime": {
                    "type": "integer"
                },
                "inputMaterials": {
                    "description": "输入物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/common.ProcedureMaterial"
                    }
                },
                "outputMaterials": {
                    "description": "输出物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/common.ProcedureMaterial"
                    }
                },
                "procedureId": {
                    "type": "string"
                },
                "procedureName": {
                    "type": "string"
                },
                "startTime": {
                    "type": "integer"
                },
                "workHours": {
                    "type": "number"
                },
                "workers": {
                    "description": "人员列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/common.ProcedureWorker"
                    }
                }
            }
        },
        "contextx.Response": {
            "type": "object",
            "properties": {
@@ -147,6 +507,63 @@
                    "type": "string"
                }
            }
        },
        "model.NetConfig": {
            "type": "object",
            "required": [
                "gateway",
                "ip",
                "mask",
                "networkCard"
            ],
            "properties": {
                "dns": {
                    "description": "dns",
                    "type": "string"
                },
                "gateway": {
                    "description": "网关",
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "ip": {
                    "description": "本机ip",
                    "type": "string"
                },
                "mask": {
                    "description": "子网掩码",
                    "type": "string"
                },
                "networkCard": {
                    "description": "网卡",
                    "type": "string"
                },
                "status": {
                    "description": "状态(1启用2禁用)",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.NetConfigStatus"
                        }
                    ]
                }
            }
        },
        "model.NetConfigStatus": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-comments": {
                "NetConfigStatusDisabled": "关闭",
                "NetConfigStatusEnabled": "开启"
            },
            "x-enum-varnames": [
                "NetConfigStatusEnabled",
                "NetConfigStatusDisabled"
            ]
        },
        "model.Order": {
            "type": "object",
@@ -182,6 +599,9 @@
                "startTime": {
                    "type": "integer"
                },
                "status": {
                    "$ref": "#/definitions/model.OrderStatus"
                },
                "unit": {
                    "type": "string"
                },
@@ -190,103 +610,98 @@
                }
            }
        },
        "model.Procedures": {
        "model.OrderStatus": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-varnames": [
                "OrderStatusUnFinished",
                "OrderStatusFinished"
            ]
        },
        "model.PlcBrand": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.ProcedureStatus": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-varnames": [
                "ProcedureStatusUnFinished",
                "ProcedureStatusFinished"
            ]
        },
        "model.Procedures": {
            "type": "object",
            "properties": {
                "endTime": {
                    "type": "integer"
                },
                "id": {
                    "type": "integer"
                },
                "procedure": {
                    "description": "request.ProductProcedure  对象",
                    "description": "common.ProductProcedure  对象",
                    "allOf": [
                        {
                            "$ref": "#/definitions/request.ProductProcedure"
                            "$ref": "#/definitions/common.ProductProcedure"
                        }
                    ]
                }
            }
        },
        "request.ProcedureMaterial": {
            "type": "object",
            "properties": {
                "amount": {
                    "type": "number"
                },
                "materialId": {
                    "type": "string"
                },
                "materialName": {
                    "type": "string"
                },
                "unit": {
                    "type": "string"
                }
            }
        },
        "request.ProcedureWorker": {
            "type": "object",
            "properties": {
                "endTime": {
                    "type": "integer"
                },
                "phoneNum": {
                    "type": "string"
                },
                "startTime": {
                    "type": "integer"
                },
                "workerId": {
                    "type": "string"
                "status": {
                    "$ref": "#/definitions/model.ProcedureStatus"
                }
            }
        },
        "request.AddPlcBrand": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "workerName": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.ProductProcedure": {
        "request.UpdatePlcBrand": {
            "type": "object",
            "properties": {
                "deviceId": {
                    "type": "string"
                },
                "deviceName": {
                    "type": "string"
                },
                "endTime": {
                "id": {
                    "type": "integer"
                },
                "inputMaterials": {
                    "description": "输入物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.ProcedureMaterial"
                    }
                },
                "outputMaterials": {
                    "description": "输出物料列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.ProcedureMaterial"
                    }
                },
                "procedureId": {
                "name": {
                    "type": "string"
                },
                "procedureName": {
                    "type": "string"
                },
                "startTime": {
                }
            }
        },
        "response.ListResponse": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "workHours": {
                    "type": "number"
                "count": {
                    "type": "integer"
                },
                "workers": {
                    "description": "人员列表",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.ProcedureWorker"
                    }
                "data": {},
                "msg": {
                    "type": "string"
                }
            }
        },
@@ -302,6 +717,15 @@
        "response.TaskData": {
            "type": "object",
            "properties": {
                "deviceName": {
                    "type": "string"
                },
                "deviceStatus": {
                    "type": "string"
                },
                "nextProcedure": {
                    "$ref": "#/definitions/model.Procedures"
                },
                "order": {
                    "$ref": "#/definitions/model.Order"
                },
docs/swagger.yaml
@@ -1,4 +1,60 @@
definitions:
  common.ProcedureMaterial:
    properties:
      amount:
        type: number
      materialId:
        type: string
      materialName:
        type: string
      unit:
        type: string
    type: object
  common.ProcedureWorker:
    properties:
      endTime:
        type: integer
      phoneNum:
        type: string
      startTime:
        type: integer
      workerId:
        type: string
      workerName:
        type: string
    type: object
  common.ProductProcedure:
    properties:
      deviceId:
        type: string
      deviceName:
        type: string
      endTime:
        type: integer
      inputMaterials:
        description: 输入物料列表
        items:
          $ref: '#/definitions/common.ProcedureMaterial'
        type: array
      outputMaterials:
        description: 输出物料列表
        items:
          $ref: '#/definitions/common.ProcedureMaterial'
        type: array
      procedureId:
        type: string
      procedureName:
        type: string
      startTime:
        type: integer
      workHours:
        type: number
      workers:
        description: 人员列表
        items:
          $ref: '#/definitions/common.ProcedureWorker'
        type: array
    type: object
  contextx.Response:
    properties:
      code:
@@ -7,6 +63,46 @@
      msg:
        type: string
    type: object
  model.NetConfig:
    properties:
      dns:
        description: dns
        type: string
      gateway:
        description: 网关
        type: string
      id:
        type: integer
      ip:
        description: 本机ip
        type: string
      mask:
        description: 子网掩码
        type: string
      networkCard:
        description: 网卡
        type: string
      status:
        allOf:
        - $ref: '#/definitions/model.NetConfigStatus'
        description: 状态(1启用2禁用)
    required:
    - gateway
    - ip
    - mask
    - networkCard
    type: object
  model.NetConfigStatus:
    enum:
    - 1
    - 2
    type: integer
    x-enum-comments:
      NetConfigStatusDisabled: 关闭
      NetConfigStatusEnabled: 开启
    x-enum-varnames:
    - NetConfigStatusEnabled
    - NetConfigStatusDisabled
  model.Order:
    properties:
      amount:
@@ -30,75 +126,74 @@
        type: string
      startTime:
        type: integer
      status:
        $ref: '#/definitions/model.OrderStatus'
      unit:
        type: string
      workOrderId:
        type: string
    type: object
  model.OrderStatus:
    enum:
    - 1
    - 2
    type: integer
    x-enum-varnames:
    - OrderStatusUnFinished
    - OrderStatusFinished
  model.PlcBrand:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  model.ProcedureStatus:
    enum:
    - 1
    - 2
    type: integer
    x-enum-varnames:
    - ProcedureStatusUnFinished
    - ProcedureStatusFinished
  model.Procedures:
    properties:
      endTime:
        type: integer
      id:
        type: integer
      procedure:
        allOf:
        - $ref: '#/definitions/request.ProductProcedure'
        description: request.ProductProcedure  对象
    type: object
  request.ProcedureMaterial:
    properties:
      amount:
        type: number
      materialId:
        type: string
      materialName:
        type: string
      unit:
        type: string
    type: object
  request.ProcedureWorker:
    properties:
      endTime:
        type: integer
      phoneNum:
        type: string
        - $ref: '#/definitions/common.ProductProcedure'
        description: common.ProductProcedure  对象
      startTime:
        type: integer
      workerId:
        type: string
      workerName:
      status:
        $ref: '#/definitions/model.ProcedureStatus'
    type: object
  request.AddPlcBrand:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  request.ProductProcedure:
  request.UpdatePlcBrand:
    properties:
      deviceId:
        type: string
      deviceName:
        type: string
      endTime:
      id:
        type: integer
      inputMaterials:
        description: 输入物料列表
        items:
          $ref: '#/definitions/request.ProcedureMaterial'
        type: array
      outputMaterials:
        description: 输出物料列表
        items:
          $ref: '#/definitions/request.ProcedureMaterial'
        type: array
      procedureId:
      name:
        type: string
      procedureName:
        type: string
      startTime:
    type: object
  response.ListResponse:
    properties:
      code:
        type: integer
      workHours:
        type: number
      workers:
        description: 人员列表
        items:
          $ref: '#/definitions/request.ProcedureWorker'
        type: array
      count:
        type: integer
      data: {}
      msg:
        type: string
    type: object
  response.ProcessParams:
    properties:
@@ -108,6 +203,12 @@
    type: object
  response.TaskData:
    properties:
      deviceName:
        type: string
      deviceStatus:
        type: string
      nextProcedure:
        $ref: '#/definitions/model.Procedures'
      order:
        $ref: '#/definitions/model.Order'
      procedure:
@@ -116,6 +217,169 @@
info:
  contact: {}
paths:
  /v1/cc/nn:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/model.NetConfig'
                  type: array
              type: object
      summary: 获取网络配置
      tags:
      - Config
    put:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/model.NetConfig'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/response.ProcessParams'
                  type: array
              type: object
      summary: 设置网络配置
      tags:
      - Config
  /v1/config/net:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/model.NetConfig'
                  type: array
              type: object
      summary: 获取网络配置
      tags:
      - Config
    put:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/model.NetConfig'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/response.ProcessParams'
                  type: array
              type: object
      summary: 设置网络配置
      tags:
      - Config
  /v1/plcBrand/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddPlcBrand'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加plc品牌
      tags:
      - plc品牌
  /v1/plcBrand/delete/{id}:
    delete:
      parameters:
      - description: 查询参数
        in: path
        name: id
        required: true
        type: integer
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 删除plc品牌
      tags:
      - plc品牌
  /v1/plcBrand/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/response.ListResponse'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/model.PlcBrand'
                  type: array
              type: object
      summary: 获取plc品牌列表
      tags:
      - plc品牌
  /v1/plcBrand/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdatePlcBrand'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新plc品牌
      tags:
      - plc品牌
  /v1/task/finish/{id}:
    put:
      parameters:
model/common/common.go
New file
@@ -0,0 +1,54 @@
package common
import "github.com/shopspring/decimal"
// 排程任务下发
type (
    WorkOrder struct {
        WorkOrderID string          `json:"workOrderId"`
        OrderID     string          `gorm:"index;type:varchar(191);not null;comment:订单ID" json:"orderId"`
        ProductID   string          `gorm:"type:varchar(191);comment:产品ID" json:"productId"`
        ProductName string          `gorm:"type:varchar(191);comment:产品名称" json:"productName"`
        Parameter   string          `gorm:"type:varchar(1024);comment:参数需求" json:"parameter"`
        Customer    string          `gorm:"type:varchar(191);comment:客户编码" json:"customer"`
        DeliverDate string          `gorm:"type:varchar(100);comment:交货日期" json:"deliverDate"`
        OrderAttr   string          `json:"orderAttr"` // 订单属性拼接的字符串,即货物描述
        Amount      decimal.Decimal `gorm:"type:decimal(35,18);comment:数量" json:"amount"`
        Unit        string          `gorm:"type:varchar(100);comment:单位" json:"unit"`
        StartTime   int64           `gorm:"comment:计划开始时间" json:"startTime"`
        EndTime     int64           `gorm:"comment:计划结束时间" json:"endTime"`
    }
    ProcedureMaterial struct {
        MaterialID   string          `gorm:"type:varchar(191);comment:物料编号" json:"materialId"`
        MaterialName string          `gorm:"unique;type:varchar(191);not null;comment:物料名称" json:"materialName"`
        Amount       decimal.Decimal `gorm:"type:decimal(35,18);comment:数量" json:"amount"`
        Unit         string          `gorm:"type:varchar(191);comment:单位" json:"unit"`
    }
    ProcedureWorker struct {
        WorkerID   string `gorm:"type:varchar(2048);comment:人员ID" json:"workerId"`
        WorkerName string `gorm:"unique;type:varchar(191);not null;comment:人员姓名" json:"workerName"`
        PhoneNum   string `gorm:"type:varchar(191);comment:手机号" json:"phoneNum"`
        StartTime  int64  `gorm:"comment:开始时间" json:"startTime"`
        EndTime    int64  `gorm:"comment:结束时间" json:"endTime"`
    }
    ProductProcedure struct {
        ProcedureID     string               `gorm:"uniqueIndex:idx_product_procedure;type:varchar(191);comment:工序ID" json:"procedureId"`
        ProcedureName   string               `gorm:"type:varchar(191);comment:工序名称,仅查询用" json:"procedureName"`
        DeviceID        string               `gorm:"type:varchar(191);not null;comment:设备ID" json:"deviceId"`
        DeviceName      string               `gorm:"type:varchar(191);not null;comment:设备名称" json:"deviceName"`
        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"`         // 人员列表
    }
    DeliverScheduleTask struct {
        WorkOrder  WorkOrder           `json:"workOrder"`
        Procedures []*ProductProcedure `json:"procedures"` // 工序列表
    }
)
model/index.go
@@ -4,6 +4,7 @@
    "apsClient/conf"
    "apsClient/pkg/logx"
    "apsClient/pkg/sqlitex"
    "sync"
)
func Init() error {
@@ -14,11 +15,48 @@
    if err := RegisterTables(); err != nil {
        return err
    }
    InsertDefaultData()
    return nil
}
func RegisterTables() error {
    db := sqlitex.GetDB()
    err := db.AutoMigrate(Order{}, Procedures{})
    err := db.AutoMigrate(
        Order{},
        Procedures{},
        NetConfig{},
        PlcBrand{},
    )
    return err
}
type InitDefaultData interface {
    InitDefaultData(errCh chan<- error, wg *sync.WaitGroup)
}
func InsertDefaultData() {
    errCh := make(chan error, 2)
    var wg sync.WaitGroup
    models := []interface{}{
        NewNetConfigSearch(nil),
    }
    for _, model := range models {
        if id, ok := model.(InitDefaultData); ok {
            wg.Add(1)
            go id.InitDefaultData(errCh, &wg)
        }
    }
    go func() {
        wg.Wait()    // 等待所有goroutine完成
        close(errCh) // 关闭错误通道
    }()
    for err := range errCh {
        if err != nil {
            logx.Errorf("InitDefaultData err: %v", err.Error())
        }
    }
}
model/net_config.go
New file
@@ -0,0 +1,217 @@
package model
import (
    "apsClient/pkg/sqlitex"
    "fmt"
    "gorm.io/gorm"
    "sync"
)
type (
    NetConfig struct {
        gorm.Model  `json:"-"`
        Id          int             `gorm:"primarykey;type:int;" json:"id"`
        NetworkCard string          `gorm:"type:varchar(100);not null;default '';comment:网卡" json:"networkCard" binding:"required"` //网卡
        IP          string          `gorm:"type:varchar(100);not null;default '';comment:本机ip" json:"ip" binding:"required"`        //本机ip
        MASK        string          `gorm:"type:varchar(100);not null;default '';comment:子网掩码" json:"mask" binding:"required"`      //子网掩码
        Gateway     string          `gorm:"type:varchar(100);not null;default '';comment:网关" json:"gateway" binding:"required"`     //网关
        DNS         string          `gorm:"type:varchar(100);not null;default '';comment:DNS" json:"dns"`                           //dns
        Status      NetConfigStatus `gorm:"type:tinyint;not null;default 0;comment:状态(1启动2禁用)" json:"status"`                       //状态(1启用2禁用)
    }
    NetConfigSearch struct {
        NetConfig
        NetConfigBy  string
        PageNum      int
        PageSize     int
        Orm          *gorm.DB
        Preload      bool
        StartTimeMax int64
    }
)
type NetConfigStatus int
const (
    NetConfigStatusEnabled  NetConfigStatus = 1 //开启
    NetConfigStatusDisabled NetConfigStatus = 2 //关闭
)
func (slf *NetConfig) TableName() string {
    return "net_config"
}
func NewNetConfigSearch(db *gorm.DB) *NetConfigSearch {
    if db == nil {
        db = sqlitex.GetDB()
    }
    return &NetConfigSearch{Orm: db}
}
func (slf *NetConfigSearch) SetOrm(tx *gorm.DB) *NetConfigSearch {
    slf.Orm = tx
    return slf
}
func (slf *NetConfigSearch) SetId(id int) *NetConfigSearch {
    slf.Id = id
    return slf
}
func (slf *NetConfigSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&NetConfig{})
    return db
}
// Create 单条插入
func (slf *NetConfigSearch) Create(record *NetConfig) error {
    var db = slf.build()
    if err := db.Create(record).Error; err != nil {
        return fmt.Errorf("create err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *NetConfigSearch) Save(record *NetConfig) error {
    var db = slf.build()
    if err := db.Save(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *NetConfigSearch) UpdateByMap(upMap map[string]interface{}) error {
    var (
        db = slf.build()
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
    }
    return nil
}
func (slf *NetConfigSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
    var (
        db = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
    }
    return nil
}
func (slf *NetConfigSearch) Delete() error {
    var db = slf.build()
    if err := db.Unscoped().Delete(&NetConfig{}).Error; err != nil {
        return err
    }
    return nil
}
func (slf *NetConfigSearch) First() (*NetConfig, error) {
    var (
        record = new(NetConfig)
        db     = slf.build()
    )
    if err := db.First(record).Error; err != nil {
        return record, err
    }
    return record, nil
}
func (slf *NetConfigSearch) FindNotTotal() ([]*NetConfig, error) {
    var (
        records = make([]*NetConfig, 0)
        db      = slf.build()
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find records err: %v", err)
    }
    return records, nil
}
// FindByQuery 指定条件查询.
func (slf *NetConfigSearch) FindByQuery(query string, args []interface{}) ([]*NetConfig, int64, error) {
    var (
        records = make([]*NetConfig, 0)
        total   int64
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find by query count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, total, nil
}
func (slf *NetConfigSearch) CreateBatch(records []*NetConfig) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *NetConfigSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*NetConfig{
        {
            Id:          1,
            NetworkCard: "enp3s0",
            IP:          "",
            MASK:        "",
            Gateway:     "",
            DNS:         "",
            Status:      0,
        },
        {
            Id:          2,
            NetworkCard: "",
            IP:          "",
            MASK:        "",
            Gateway:     "",
            DNS:         "",
            Status:      0,
        },
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/plc_brand.go
New file
@@ -0,0 +1,145 @@
package model
import (
    "apsClient/constvar"
    "apsClient/pkg/sqlitex"
    "errors"
    "fmt"
    "gorm.io/gorm"
)
type (
    // PlcBrand plc品牌
    PlcBrand struct {
        Id   int    `json:"id" gorm:"column:id;type:int;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);not null;default:'';comment:名称"`
    }
    // PlcBrandSearch plc品牌搜索条件
    PlcBrandSearch struct {
        PlcBrand
        Orm         *gorm.DB
        QueryClass  constvar.PlcBrandQueryClass
        KeywordType constvar.PlcBrandKeywordType
        Keyword     string
        PageNum     int
        PageSize    int
    }
)
func (PlcBrand) TableName() string {
    return "plc_brand"
}
func NewPlcBrandSearch() *PlcBrandSearch {
    return &PlcBrandSearch{
        Orm: sqlitex.GetDB(),
    }
}
func (slf *PlcBrandSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&PlcBrand{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    return db
}
func (slf *PlcBrandSearch) Create(record *PlcBrand) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *PlcBrandSearch) CreateBatch(records []*PlcBrand) error {
    var db = slf.build()
    return db.Create(records).Error
}
func (slf *PlcBrandSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&PlcBrand{}).Error
}
func (slf *PlcBrandSearch) Update(record *PlcBrand) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *PlcBrandSearch) FindAll() ([]*PlcBrand, error) {
    var db = slf.build()
    var record = make([]*PlcBrand, 0)
    err := db.Find(&record).Error
    return record, err
}
func (slf *PlcBrandSearch) SetId(id int) *PlcBrandSearch {
    slf.Id = id
    return slf
}
func (slf *PlcBrandSearch) SetPage(page, size int) *PlcBrandSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *PlcBrandSearch) SetOrm(tx *gorm.DB) *PlcBrandSearch {
    slf.Orm = tx
    return slf
}
func (slf *PlcBrandSearch) First() (*PlcBrand, error) {
    var db = slf.build()
    var record = new(PlcBrand)
    err := db.First(record).Error
    return record, err
}
func (slf *PlcBrandSearch) Updates(values interface{}) error {
    var db = slf.build()
    return db.Updates(values).Error
}
func (slf *PlcBrandSearch) Save(record *PlcBrand) error {
    if record.Id == 0 {
        return errors.New("id为空")
    }
    var db = slf.build()
    if err := db.Save(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *PlcBrandSearch) Find() ([]*PlcBrand, int64, error) {
    var db = slf.build()
    var records = make([]*PlcBrand, 0)
    var total int64
    if err := db.Count(&total).Error; err != nil {
        return records, total, err
    }
    if slf.PageNum > 0 && slf.PageSize > 0 {
        db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
    }
    err := db.Find(&records).Error
    return records, total, err
}
// InitDefaultData 初始化数据
func (slf *PlcBrandSearch) InitDefaultData() error {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    if err := db.Count(&total).Error; err != nil {
        return err
    }
    if total != 0 {
        return nil
    }
    records := []*PlcBrand{}
    return slf.CreateBatch(records)
}
model/procedures.go
@@ -1,7 +1,7 @@
package model
import (
    "apsClient/model/request"
    "apsClient/model/common"
    "apsClient/pkg/logx"
    "apsClient/pkg/sqlitex"
    "encoding/json"
@@ -18,8 +18,8 @@
        StartTime      int64  `gorm:"comment:计划开始时间" json:"startTime"`
        EndTime        int64  `gorm:"comment:计划结束时间" json:"endTime"`
        Status         ProcedureStatus
        ProcedureData  string                   `json:"-"`                  //request.ProductProcedure  json串
        ProceduresInfo request.ProductProcedure `json:"procedure" gorm:"-"` //request.ProductProcedure  对象
        ProcedureData  string                  `json:"-"`                  //common.ProductProcedure  json串
        ProceduresInfo common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure  对象
    }
    ProceduresSearch struct {
@@ -44,7 +44,7 @@
    return "procedures"
}
func (slf *Procedures) AfterFind(db *gorm.DB) error {
    var proceduresInfo request.ProductProcedure
    var proceduresInfo common.ProductProcedure
    err := json.Unmarshal([]byte(slf.ProcedureData), &proceduresInfo)
    if err != nil {
        logx.Errorf("AfterFind Unmarshal err: %v", err.Error())
@@ -107,6 +107,10 @@
        db = db.Order(slf.Order)
    }
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    }
    if slf.WorkOrderID != "" {
        db = db.Where("work_order_id = ?", slf.WorkOrderID)
    }
model/request/plcBrand.go
New file
@@ -0,0 +1,22 @@
package request
import (
    "apsClient/constvar"
    "apsClient/model"
)
type AddPlcBrand struct {
    model.PlcBrand
}
type UpdatePlcBrand struct {
    Id int `json:"id"`
    model.PlcBrand
}
type GetPlcBrandList struct {
    PageInfo
    QueryClass  constvar.PlcBrandQueryClass  `json:"queryClass" form:"queryClass"`
    KeywordType constvar.PlcBrandKeywordType `json:"keywordType"  form:"keywordType"`
    Keyword     string                       `json:"keyword" form:"keyword"`
}
model/request/schedule_task.go
@@ -1,54 +1 @@
package request
import "github.com/shopspring/decimal"
// 排程任务下发
type (
    WorkOrder struct {
        WorkOrderID string          `json:"workOrderId"`
        OrderID     string          `gorm:"index;type:varchar(191);not null;comment:订单ID" json:"orderId"`
        ProductID   string          `gorm:"type:varchar(191);comment:产品ID" json:"productId"`
        ProductName string          `gorm:"type:varchar(191);comment:产品名称" json:"productName"`
        Parameter   string          `gorm:"type:varchar(1024);comment:参数需求" json:"parameter"`
        Customer    string          `gorm:"type:varchar(191);comment:客户编码" json:"customer"`
        DeliverDate string          `gorm:"type:varchar(100);comment:交货日期" json:"deliverDate"`
        OrderAttr   string          `json:"orderAttr"` // 订单属性拼接的字符串,即货物描述
        Amount      decimal.Decimal `gorm:"type:decimal(35,18);comment:数量" json:"amount"`
        Unit        string          `gorm:"type:varchar(100);comment:单位" json:"unit"`
        StartTime   int64           `gorm:"comment:计划开始时间" json:"startTime"`
        EndTime     int64           `gorm:"comment:计划结束时间" json:"endTime"`
    }
    ProcedureMaterial struct {
        MaterialID   string          `gorm:"type:varchar(191);comment:物料编号" json:"materialId"`
        MaterialName string          `gorm:"unique;type:varchar(191);not null;comment:物料名称" json:"materialName"`
        Amount       decimal.Decimal `gorm:"type:decimal(35,18);comment:数量" json:"amount"`
        Unit         string          `gorm:"type:varchar(191);comment:单位" json:"unit"`
    }
    ProcedureWorker struct {
        WorkerID   string `gorm:"type:varchar(2048);comment:人员ID" json:"workerId"`
        WorkerName string `gorm:"unique;type:varchar(191);not null;comment:人员姓名" json:"workerName"`
        PhoneNum   string `gorm:"type:varchar(191);comment:手机号" json:"phoneNum"`
        StartTime  int64  `gorm:"comment:开始时间" json:"startTime"`
        EndTime    int64  `gorm:"comment:结束时间" json:"endTime"`
    }
    ProductProcedure struct {
        ProcedureID     string               `gorm:"uniqueIndex:idx_product_procedure;type:varchar(191);comment:工序ID" json:"procedureId"`
        ProcedureName   string               `gorm:"type:varchar(191);comment:工序名称,仅查询用" json:"procedureName"`
        DeviceID        string               `gorm:"type:varchar(191);not null;comment:设备ID" json:"deviceId"`
        DeviceName      string               `gorm:"type:varchar(191);not null;comment:设备名称" json:"deviceName"`
        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"`         // 人员列表
    }
    DeliverScheduleTask struct {
        WorkOrder  WorkOrder           `json:"workOrder"`
        Procedures []*ProductProcedure `json:"procedures"` // 工序列表
    }
)
model/response/common.go
@@ -11,12 +11,31 @@
    PageSize int         `json:"pageSize"`
}
type ListResponse struct {
    Code  int         `json:"code"`
    Msg   string      `json:"msg"`
    Data  interface{} `json:"data"`
    Count int64       `json:"count"`
}
type TaskData struct {
    Order     *model.Order
    Procedure *model.Procedures
    Order         *model.Order
    Procedure     *model.Procedures
    NextProcedure *model.Procedures
    Config
}
type Config struct {
    DeviceName   string
    DeviceStatus string
}
type ProcessParams struct {
    Key   string
    Value interface{}
}
type NetConfig struct {
    DeviceName   string
    DeviceStatus string
}
model/work_order.go
@@ -97,7 +97,7 @@
    }
    if slf.WorkOrderID != "" {
        db = db.Where("work_order_id = ?", slf.OrderID)
        db = db.Where("work_order_id = ?", slf.WorkOrderID)
    }
    if slf.Status != 0 {
nsq/msg_handler.go
@@ -3,7 +3,7 @@
import (
    "apsClient/conf"
    "apsClient/model"
    "apsClient/model/request"
    "apsClient/model/common"
    "apsClient/pkg/logx"
    "apsClient/pkg/structx"
    "encoding/json"
@@ -19,7 +19,7 @@
func (slf *ScheduleTask) HandleMessage(data []byte) (err error) {
    logx.Infof("get an message :%s", data)
    var tasks = make([]*request.DeliverScheduleTask, 0)
    var tasks = make([]*common.DeliverScheduleTask, 0)
    err = json.Unmarshal(data, &tasks)
    if err != nil {
        logx.Errorf("ScheduleTask HandleMessage Unmarshal json err: %v", err.Error())
pkg/contextx/contextx.go
@@ -96,6 +96,10 @@
    slf.Result(errCode, map[string]interface{}{}, ecode.GetMsg(errCode))
}
func (slf *Context) FailWithMsg(errCode int, msg string) {
    slf.Result(errCode, map[string]interface{}{}, msg)
}
func (slf *Context) FailWithDetailed(errCode int, data interface{}) {
    slf.Result(errCode, data, ecode.GetMsg(errCode))
}
router/index.go
@@ -41,5 +41,21 @@
        taskGroup.POST("sendProcessParams/:id", taskApi.SendProcessParams) // 下发工艺参数
    }
    configApi := new(v1.ConfigApi)
    configGroup := v1Group.Group("config")
    {
        configGroup.GET("net", configApi.GetNetConfig)  // 获取网络配置
        configGroup.POST("net", configApi.SetNetConfig) // 设置网络
    }
    configApi1 := new(v1.ConfigApi2)
    configGroup1 := v1Group.Group("cc")
    {
        configGroup1.GET("nn", configApi1.GetNetConfig)  // 获取网络配置
        configGroup1.POST("nn", configApi1.SetNetConfig) // 设置网络
    }
    InitPlcBrandRouter(v1Group)
    return Router
}
router/plc_brand.go
New file
@@ -0,0 +1,17 @@
package router
import (
    v1 "apsClient/api/v1"
    "github.com/gin-gonic/gin"
)
func InitPlcBrandRouter(router *gin.RouterGroup) {
    PlcBrandRouter := router.Group("plcBrand")
    PlcBrandApi := v1.PlcBrandApi{}
    {
        PlcBrandRouter.POST("add", PlcBrandApi.Add)             // 添加plc品牌
        PlcBrandRouter.DELETE("delete/:id", PlcBrandApi.Delete) // 删除plc品牌
        PlcBrandRouter.PUT("update", PlcBrandApi.Update)        // 更新plc品牌
        PlcBrandRouter.GET("list", PlcBrandApi.List)            // 获取plc品牌列表
    }
}
service/config.go
New file
@@ -0,0 +1,27 @@
package service
import (
    "apsClient/model"
)
type ConfigService struct {
}
func NewConfigService() *ConfigService {
    return &ConfigService{}
}
// GetNetConfigList 获取网络配置列表
func (slf ConfigService) GetNetConfigList() (ConfigData []*model.NetConfig, err error) {
    return model.NewNetConfigSearch(nil).FindNotTotal()
}
// GetNetConfig 获取网络配置
func (slf ConfigService) GetNetConfig(id int) (ConfigData *model.NetConfig, err error) {
    return model.NewNetConfigSearch(nil).SetId(id).First()
}
// SetNetConfig 设置网络配置
func (slf ConfigService) SetNetConfig(id int, config *model.NetConfig) error {
    return model.NewNetConfigSearch(nil).SetId(id).Save(config)
}
service/plc_brand.go
New file
@@ -0,0 +1,73 @@
package service
import (
    "apsClient/model"
    "apsClient/model/request"
    "apsClient/pkg/ecode"
)
type PlcBrandService struct{}
func NewPlcBrandService() PlcBrandService {
    return PlcBrandService{}
}
func (PlcBrandService) AddPlcBrand(plcBrand *model.PlcBrand) int {
    err := model.NewPlcBrandSearch().Create(plcBrand)
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}
func (PlcBrandService) GetPlcBrand(id int) (*model.PlcBrand, int) {
    plcBrand, err := model.NewPlcBrandSearch().SetId(id).First()
    if err != nil {
        return nil, ecode.DBErr
    }
    return plcBrand, ecode.OK
}
func (PlcBrandService) DeletePlcBrand(id int) int {
    err := model.NewPlcBrandSearch().SetId(id).Delete()
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}
func (PlcBrandService) GetPlcBrandList() ([]*model.PlcBrand, int64, int) {
    list, total, err := model.NewPlcBrandSearch().Find()
    if err != nil {
        return nil, 0, ecode.DBErr
    }
    return list, total, ecode.OK
}
func (PlcBrandService) UpdatePlcBrands(PlcBrands []*request.UpdatePlcBrand) int {
    for _, v := range PlcBrands {
        // check PlcBrand exist
        _, err := model.NewPlcBrandSearch().SetId(v.Id).First()
        if err != nil {
            return ecode.DBErr
        }
        err = model.NewPlcBrandSearch().SetId(v.Id).Updates(map[string]interface{}{})
        if err != nil {
            return ecode.DBErr
        }
    }
    return ecode.OK
}
func (PlcBrandService) UpdatePlcBrand(plcBrand *model.PlcBrand) int {
    err := model.NewPlcBrandSearch().SetId(plcBrand.Id).Save(plcBrand)
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}
service/task.go
@@ -52,9 +52,18 @@
    if err != nil {
        return nil, ecode.DBErr
    }
    nextProcedure := new(model.Procedures)
    nextProcedure, err = model.NewProceduresSearch(nil).
        SetWorkOrderId(order.WorkOrderID).
        SetStatus(model.ProcedureStatusUnFinished).
        SetId(procedure.ID + 1).First()
    if err == nil {
        nextProcedure.ProceduresInfo.ProcedureName = "--"
    }
    taskData = new(response.TaskData)
    taskData.Order = order
    taskData.Procedure = procedure
    taskData.NextProcedure = nextProcedure
    return taskData, ecode.OK
}