Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS
# Conflicts:
# models/db.go
New file |
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "errors" |
| | | "github.com/gin-gonic/gin" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | | "wms/request" |
| | | ) |
| | | |
| | | type LocationController struct { |
| | | } |
| | | |
| | | func (slf LocationController) ListLocationByType(c *gin.Context) { |
| | | var params request.LocationByType |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数绑定失败") |
| | | return |
| | | } |
| | | if err := slf.CheckLocationByTypeParams(params); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | } |
| | | search := models.NewLocationSearch() |
| | | search.SetType(params.Type) |
| | | if params.Keyword != "" { |
| | | search.SetKeyword(params.Keyword) |
| | | } |
| | | if params.ParentId != 0 { |
| | | search.SetParentId(params.ParentId) |
| | | } |
| | | if params.CompanyId != 0 { |
| | | search.SetCompanyId(params.CompanyId) |
| | | } |
| | | res, err := search.SetOrder("created_at desc").FindAll() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err.Error()) |
| | | } |
| | | util.ResponseFormat(c, code.Success, res) |
| | | } |
| | | |
| | | func (slf LocationController) CheckLocationByTypeParams(params request.LocationByType) error { |
| | | if params.Type == 0 { |
| | | return errors.New("请选择正确的位置类型") |
| | | } |
| | | if params.ParentId < 0 { |
| | | return errors.New("错误参数ParentId") |
| | | } |
| | | if params.CompanyId < 0 { |
| | | return errors.New("错误参数CompanyId") |
| | | } |
| | | return nil |
| | | } |
| | |
| | | |
| | | import ( |
| | | "errors" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | |
| | | var reqParams request.AddOperation |
| | | var params models.Operation |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误"+err.Error()) |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams, params); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误") |
| | | if err := structx.AssignTo(reqParams, ¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误"+err.Error()) |
| | | return |
| | | } |
| | | if err := slf.CheckParams(params); err != nil { |
| | |
| | | return errors.New("产品数量出错") |
| | | } |
| | | } |
| | | fmt.Println(111111) |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // List |
| | | // @Tags 入库/出库 |
| | | // @Summary 入库/出库列表 |
| | | // @Produce application/json |
| | | // @Accept json |
| | | // @Param object query request.OperationList true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/operation/operation [get] |
| | | func (slf OperationController) List(c *gin.Context) { |
| | | var params request.OperationList |
| | | if err := c.ShouldBindQuery(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if err := slf.CheckListParams(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | search := models.NewOperationSearch() |
| | | search.SetPage(params.Page, params.PageSize) |
| | | list, total, err := search.SetOperationTypeId(params.OperationTypeId).SetPreload(true).SetOrder("created_at desc").Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error()) |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, list, int(total)) |
| | | |
| | | } |
| | | |
| | | func (slf OperationController) CheckListParams(params *request.OperationList) error { |
| | | if !params.PageInfo.Check() { |
| | | return errors.New("数据分页信息错误") |
| | | } |
| | | if params.OperationTypeId == 0 { |
| | | return errors.New("operationTypeId为0") |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // Update |
| | | // @Tags 入库/出库 |
| | | // @Summary 修改入库/出库信息 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateOperation true "入库信息" |
| | | // @Param id path int true "入库信息id" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/operation/operation/{id} [put] |
| | | func (slf OperationController) Update(c *gin.Context) { |
| | | id := cast.ToUint(c.Param("id")) |
| | | if id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "空的记录id") |
| | | return |
| | | } |
| | | var reqParams request.UpdateOperation |
| | | var params models.Operation |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error()) |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams, ¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误"+err.Error()) |
| | | return |
| | | } |
| | | if err := slf.CheckParams(params); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(params.Id).Delete(); err != nil { |
| | | return err |
| | | } |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(params.Id).Save(¶ms); err != nil { |
| | | return err |
| | | } |
| | | return nil |
| | | }); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "修改失败:"+err.Error()) |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "修改成功") |
| | | } |
| | | |
| | | // DeleteDevice |
| | | // |
| | | // @Tags 入库/出库 |
| | | // @Summary 删除入库/出库信息 |
| | | // @Produce application/json |
| | | // @Param id path int true "id" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/operation/operation/{id} [delete] |
| | | func (slf OperationController) Delete(c *gin.Context) { |
| | | id, err := strconv.Atoi(c.Param("id")) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "错误的id值") |
| | | return |
| | | } |
| | | if id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "空的记录id") |
| | | return |
| | | } |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(id).Delete(); err != nil { |
| | | return err |
| | | } |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Delete(); err != nil { |
| | | return err |
| | | } |
| | | return nil |
| | | }); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "修改失败:"+err.Error()) |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "删除成功") |
| | | } |
| | |
| | | } |
| | | }, |
| | | "/api-wms/v1/operation/operation": { |
| | | "get": { |
| | | "consumes": [ |
| | | "application/json" |
| | | ], |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "入库/出库列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "name": "operationTypeId", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddOperation" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/operation/operation/{id}": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "修改入库/出库信息", |
| | | "parameters": [ |
| | | { |
| | | "description": "入库信息", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateOperation" |
| | | } |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "入库信息id", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "删除入库/出库信息", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "id", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | "request.AddOperation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "carrierID": { |
| | | "type": "integer" |
| | | }, |
| | | "carrierName": { |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | | "type": "integer" |
| | | }, |
| | | "companyName": { |
| | | "type": "string" |
| | | }, |
| | | "contacterID": { |
| | | "type": "integer" |
| | | }, |
| | | "contacterName": { |
| | | "type": "string" |
| | | }, |
| | | "details": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "tracking": { |
| | | "type": "string" |
| | | }, |
| | | "transferWeight": { |
| | | "type": "number" |
| | | }, |
| | | "weight": { |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateOperation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "carrierID": { |
| | | "type": "integer" |
| | | }, |
| | | "carrierName": { |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | | "type": "integer" |
| | | }, |
| | | "companyName": { |
| | | "type": "string" |
| | | }, |
| | | "contacterID": { |
| | | "type": "integer" |
| | | }, |
| | | "contacterName": { |
| | | "type": "string" |
| | | }, |
| | | "details": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.OperationDetails" |
| | | } |
| | | }, |
| | | "fromLocationId": { |
| | | "description": "源位置id", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "description": "单号", |
| | | "type": "string" |
| | | }, |
| | | "operationDate": { |
| | | "type": "string" |
| | | }, |
| | | "operationTypeId": { |
| | | "description": "作业类型id", |
| | | "type": "integer" |
| | | }, |
| | | "sourceNumber": { |
| | | "description": "源单号", |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "description": "状态", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.OperationStatus" |
| | | } |
| | | ] |
| | | }, |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "tracking": { |
| | | "type": "string" |
| | | }, |
| | | "transferWeight": { |
| | | "type": "number" |
| | | }, |
| | | "weight": { |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateOperationType": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | }, |
| | | "/api-wms/v1/operation/operation": { |
| | | "get": { |
| | | "consumes": [ |
| | | "application/json" |
| | | ], |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "入库/出库列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "name": "operationTypeId", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "页码", |
| | | "name": "page", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddOperation" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-wms/v1/operation/operation/{id}": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "修改入库/出库信息", |
| | | "parameters": [ |
| | | { |
| | | "description": "入库信息", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateOperation" |
| | | } |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "入库信息id", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "删除入库/出库信息", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "id", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | "request.AddOperation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "carrierID": { |
| | | "type": "integer" |
| | | }, |
| | | "carrierName": { |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | | "type": "integer" |
| | | }, |
| | | "companyName": { |
| | | "type": "string" |
| | | }, |
| | | "contacterID": { |
| | | "type": "integer" |
| | | }, |
| | | "contacterName": { |
| | | "type": "string" |
| | | }, |
| | | "details": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "tracking": { |
| | | "type": "string" |
| | | }, |
| | | "transferWeight": { |
| | | "type": "number" |
| | | }, |
| | | "weight": { |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateOperation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "carrierID": { |
| | | "type": "integer" |
| | | }, |
| | | "carrierName": { |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | | "type": "integer" |
| | | }, |
| | | "companyName": { |
| | | "type": "string" |
| | | }, |
| | | "contacterID": { |
| | | "type": "integer" |
| | | }, |
| | | "contacterName": { |
| | | "type": "string" |
| | | }, |
| | | "details": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.OperationDetails" |
| | | } |
| | | }, |
| | | "fromLocationId": { |
| | | "description": "源位置id", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "description": "单号", |
| | | "type": "string" |
| | | }, |
| | | "operationDate": { |
| | | "type": "string" |
| | | }, |
| | | "operationTypeId": { |
| | | "description": "作业类型id", |
| | | "type": "integer" |
| | | }, |
| | | "sourceNumber": { |
| | | "description": "源单号", |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "description": "状态", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.OperationStatus" |
| | | } |
| | | ] |
| | | }, |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "tracking": { |
| | | "type": "string" |
| | | }, |
| | | "transferWeight": { |
| | | "type": "number" |
| | | }, |
| | | "weight": { |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateOperationType": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | type: object |
| | | request.AddOperation: |
| | | properties: |
| | | carrierID: |
| | | type: integer |
| | | carrierName: |
| | | type: string |
| | | companyID: |
| | | type: integer |
| | | companyName: |
| | | type: string |
| | | contacterID: |
| | | type: integer |
| | | contacterName: |
| | | type: string |
| | | details: |
| | | items: |
| | | $ref: '#/definitions/request.OperationDetails' |
| | |
| | | toLocationId: |
| | | description: 目标位置id |
| | | type: integer |
| | | tracking: |
| | | type: string |
| | | transferWeight: |
| | | type: number |
| | | weight: |
| | | type: number |
| | | type: object |
| | | request.AddOperationType: |
| | | properties: |
| | |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | | type: object |
| | | request.UpdateOperation: |
| | | properties: |
| | | carrierID: |
| | | type: integer |
| | | carrierName: |
| | | type: string |
| | | companyID: |
| | | type: integer |
| | | companyName: |
| | | type: string |
| | | contacterID: |
| | | type: integer |
| | | contacterName: |
| | | type: string |
| | | details: |
| | | items: |
| | | $ref: '#/definitions/request.OperationDetails' |
| | | type: array |
| | | fromLocationId: |
| | | description: 源位置id |
| | | type: integer |
| | | id: |
| | | type: integer |
| | | number: |
| | | description: 单号 |
| | | type: string |
| | | operationDate: |
| | | type: string |
| | | operationTypeId: |
| | | description: 作业类型id |
| | | type: integer |
| | | sourceNumber: |
| | | description: 源单号 |
| | | type: string |
| | | status: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.OperationStatus' |
| | | description: 状态 |
| | | toLocationId: |
| | | description: 目标位置id |
| | | type: integer |
| | | tracking: |
| | | type: string |
| | | transferWeight: |
| | | type: number |
| | | weight: |
| | | type: number |
| | | type: object |
| | | request.UpdateOperationType: |
| | | properties: |
| | |
| | | tags: |
| | | - 公司 |
| | | /api-wms/v1/operation/operation: |
| | | get: |
| | | consumes: |
| | | - application/json |
| | | parameters: |
| | | - in: query |
| | | name: operationTypeId |
| | | type: integer |
| | | - description: 页码 |
| | | in: query |
| | | name: page |
| | | type: integer |
| | | - description: 每页大小 |
| | | in: query |
| | | name: pageSize |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 入库/出库列表 |
| | | tags: |
| | | - 入库/出库 |
| | | post: |
| | | parameters: |
| | | - description: 入库/出库信息 |
| | |
| | | summary: 添加入库/出库 |
| | | tags: |
| | | - 入库/出库 |
| | | /api-wms/v1/operation/operation/{id}: |
| | | delete: |
| | | parameters: |
| | | - description: id |
| | | in: path |
| | | name: id |
| | | required: true |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 删除入库/出库信息 |
| | | tags: |
| | | - 入库/出库 |
| | | put: |
| | | parameters: |
| | | - description: 入库信息 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateOperation' |
| | | - description: 入库信息id |
| | | in: path |
| | | name: id |
| | | required: true |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 修改入库/出库信息 |
| | | tags: |
| | | - 入库/出库 |
| | | /api-wms/v1/product/addProduct: |
| | | post: |
| | | parameters: |
| | |
| | | NoTemplateError = &Code{3010, "未配置订单模板"} |
| | | InternalError = &Code{3011, "内部错误"} |
| | | NoProductionRequiredError = &Code{3012, "当前库存满足毛需求量,暂时无需进行生产"} |
| | | RequestError = &Code{3013, "请求失败"} |
| | | ) |
| | |
| | | ParentId int `json:"parentId" gorm:"type:int;not null"` //上级id |
| | | CompanyId int `json:"companyId" gorm:"type:int;not null"` //公司id |
| | | Company Company `json:"company" gorm:"foreignKey:CompanyId"` //公司 |
| | | Type constvar.LocationType `json:"type" gorm:"type:tinyint;not null;comment:位置类型"` //位置类型 |
| | | Type constvar.LocationType `json:"type" gorm:"type:int(11);not null;comment:位置类型"` //位置类型 |
| | | CountFrequency int `json:"countFrequency" gorm:"type:tinyint;not null;comment:盘点频率(天)"` //盘点频率(天) |
| | | IsScrapLocation bool `json:"isScrapLocation" gorm:"type:tinyint;not null;comment:是否报废位置"` //是否报废位置 |
| | | IsReturnLocation bool `json:"isReturnLocation" gorm:"type:tinyint;not null;comment:是否退货位置"` //是否退货位置 |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetType(_type int) *LocationSearch { |
| | | slf.Type = constvar.LocationType(_type) |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetParentId(parentId int) *LocationSearch { |
| | | slf.ParentId = parentId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetCompanyId(companyId int) *LocationSearch { |
| | | slf.CompanyId = companyId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Location{}) |
| | | |
| | |
| | | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | if slf.Type != 0 { |
| | | db = db.Where("type=?", slf.Type) |
| | | } |
| | | |
| | | if slf.ParentId != 0 { |
| | | db = db.Where("parent_id=?", slf.ParentId) |
| | | } |
| | | if slf.CompanyId != 0 { |
| | | db = db.Where("company_id=?", slf.CompanyId) |
| | | } |
| | | |
| | | return db |
| | |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *LocationSearch) FindAll() ([]*Location, error) { |
| | | var ( |
| | | records = make([]*Location, 0) |
| | | db = slf.build() |
| | | ) |
| | | if err := db.Find(&records); err != nil { |
| | | return records, fmt.Errorf("func FindAll err: %v", err) |
| | | } |
| | | return records, nil |
| | | } |
| | |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "wms/constvar" |
| | | "wms/pkg/mysqlx" |
| | |
| | | Operation struct { |
| | | WmsModel |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255)"` //单号 |
| | | Number string `json:"number" gorm:"type:varchar(255)"` //单号 |
| | | SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //源单号 |
| | | OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id |
| | | Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"` //状态 |
| | |
| | | Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` |
| | | ContacterID int `json:"contacterID" gorm:"type:int;comment:联系人ID"` |
| | | ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` |
| | | Weight float64 `json:"weight" gorm:"type:decimal;comment:重量(kg)"` |
| | | TransferWeight float64 `json:"transferWeight" gorm:"type:decimal;comment:物流重量(kg)"` |
| | | Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` |
| | | TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"` |
| | | Details []*OperationDetails `json:"details"` |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationSearch) SetID(id uint) *OperationSearch { |
| | | slf.ID = id |
| | | func (slf *OperationSearch) SetID(id int) *OperationSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch { |
| | | slf.Keyword = keyword |
| | | //func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch { |
| | | // slf.Keyword = keyword |
| | | // return slf |
| | | //} |
| | | |
| | | func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch { |
| | | slf.OperationTypeId = operationTypeId |
| | | return slf |
| | | } |
| | | |
| | |
| | | func (slf *OperationSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Operation{}) |
| | | |
| | | if slf.ID != 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | //if slf.Keyword != "" { |
| | | // db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | //} |
| | | |
| | | if slf.OperationTypeId != 0 { |
| | | db.Where("operation_type_id = ?", slf.OperationTypeId) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Model(&Operation{}).Preload("Details") |
| | | } |
| | | |
| | | return db |
| | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *OperationSearch) Save(record *Operation) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *OperationSearch) Update(record *Operation) error { |
| | | var db = slf.build() |
| | | |
| | |
| | | OperationDetails struct { |
| | | WmsModel |
| | | |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | OperationId int `json:"OperationId" gorm:"type:int;not null;comment:操作记录id"` //操作id |
| | | |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | OperationId int `json:"OperationId" gorm:"type:int;not null;comment:操作记录id"` //操作id |
| | | ProductId int `json:"productId" gorm:"type:int;not null;comment:产品id"` //产品id |
| | | ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"` //产品名称 |
| | | Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:数量"` //数量 |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationDetailsSearch) SetOperationId(operationId int) *OperationDetailsSearch { |
| | | slf.OperationId = operationId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationDetailsSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&OperationDetails{}) |
| | | |
| | |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | } |
| | | |
| | | if slf.OperationId != 0 { |
| | | db = db.Where("operation_id = ?", slf.OperationId) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
New file |
| | |
| | | package request |
| | | |
| | | type LocationByType struct { |
| | | Type int `json:"type" form:"type"` |
| | | Keyword string `json:"keyword" form:"keyword"` |
| | | ParentId int `json:"parentId" form:"parentId"` |
| | | CompanyId int `json:"companyId" form:"companyId"` |
| | | } |
| | |
| | | package request |
| | | |
| | | import ( |
| | | "google.golang.org/genproto/googleapis/type/decimal" |
| | | "github.com/shopspring/decimal" |
| | | "wms/constvar" |
| | | ) |
| | | |
| | |
| | | ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:目标位置id"` //目标位置id |
| | | OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"` |
| | | Details []*OperationDetails `json:"details"` |
| | | CarrierID int `json:"carrierID" gorm:"type:int;comment:承运商ID"` |
| | | CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"` |
| | | Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` |
| | | ContacterID int `json:"contacterID" gorm:"type:int;comment:联系人ID"` |
| | | ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` |
| | | Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` |
| | | TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"` |
| | | } |
| | | |
| | | type OperationDetails struct { |
| | |
| | | Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:数量"` //数量 |
| | | FinishQuantity decimal.Decimal `json:"finishQuantity" gorm:"type:decimal(20,2);not null;comment:数量"` //完成数量 |
| | | } |
| | | |
| | | type OperationList struct { |
| | | PageInfo |
| | | OperationTypeId int `json:"operationTypeId" form:"operationTypeId"` |
| | | } |
| | | |
| | | type UpdateOperation struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255)"` //单号 |
| | | SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //源单号 |
| | | OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id |
| | | Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"` //状态 |
| | | FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:源位置id"` //源位置id |
| | | ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:目标位置id"` //目标位置id |
| | | OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"` |
| | | Details []*OperationDetails `json:"details"` |
| | | CarrierID int `json:"carrierID" gorm:"type:int;comment:承运商ID"` |
| | | CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"` |
| | | Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` |
| | | ContacterID int `json:"contacterID" gorm:"type:int;comment:联系人ID"` |
| | | ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` |
| | | Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` |
| | | TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"` |
| | | } |
| | |
| | | operationController := new(controllers.OperationController) |
| | | operationAPI := r.Group(urlPrefix + "/operation") |
| | | { |
| | | //operationAPI.GET() |
| | | operationAPI.GET("operation", operationController.List) |
| | | operationAPI.POST("operation", operationController.Add) |
| | | operationAPI.PUT("operation/:id", operationController.Update) |
| | | operationAPI.DELETE("operation/:id", operationController.Delete) |
| | | } |
| | | |
| | | //产品 |
| | |
| | | productAPI.DELETE("deleteProductCategory/:id", productController.DeleteProductCategory) //删除产品类型 |
| | | } |
| | | |
| | | locationController := new(controllers.LocationController) |
| | | locationAPI := r.Group(urlPrefix + "/location") |
| | | { |
| | | locationAPI.POST("listByType", locationController.ListLocationByType) |
| | | } |
| | | |
| | | return r |
| | | } |