| | |
| | | "srm/model/common/response" |
| | | "srm/model/test" |
| | | testReq "srm/model/test/request" |
| | | testResp "srm/model/test/response" |
| | | "srm/proto/product" |
| | | "srm/service" |
| | | ) |
| | |
| | | } |
| | | for _, t := range p.List { |
| | | var num int64 |
| | | db := global.GVA_DB.Model(&test.Product{}) |
| | | db := global.GVA_DB.Model(&test.SupplierMaterial{}) |
| | | err := db.Where("number = ?", t.Number).Where("supplier_id = ?", t.SupplierId).Count(&num).Error |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body test.Product true "删除Product" |
| | | // @Param data body request.GetById true "删除Product" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" |
| | | // @Router /p/deleteProduct [delete] |
| | | func (pApi *ProductApi) DeleteProduct(c *gin.Context) { |
| | | var p test.Product |
| | | var p request.GetById |
| | | err := c.ShouldBindJSON(&p) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | if err := pService.DeleteProduct(p); err != nil { |
| | | if err := pService.DeleteProduct(p.ID); err != nil { |
| | | global.GVA_LOG.Error("删除失败!", zap.Error(err)) |
| | | response.FailWithMessage("删除失败", c) |
| | | } else { |
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body test.Product true "更新Product" |
| | | // @Param data body test.SupplierMaterial true "更新Product" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" |
| | | // @Router /p/updateProduct [put] |
| | | func (pApi *ProductApi) UpdateProduct(c *gin.Context) { |
| | | var p test.Product |
| | | var p test.SupplierMaterial |
| | | err := c.ShouldBindJSON(&p) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data query test.Product true "用id查询Product" |
| | | // @Param data query request.GetById true "用id查询Product" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" |
| | | // @Router /p/findProduct [get] |
| | | func (pApi *ProductApi) FindProduct(c *gin.Context) { |
| | | var p test.Product |
| | | var p request.GetById |
| | | err := c.ShouldBindQuery(&p) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | if list, total, err := pService.GetProductInfoList(pageInfo); err != nil { |
| | | list, total, err := pService.GetProductInfoList(pageInfo) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | } else { |
| | | //添加供应商名称 |
| | | for i := 0; i < len(list); i++ { |
| | | list[i].SupplierName = list[i].Supplier.Name |
| | | } |
| | | response.OkWithDetailed(response.PageResult{ |
| | | List: list, |
| | | Total: total, |
| | | Page: pageInfo.Page, |
| | | PageSize: pageInfo.PageSize, |
| | | }, "获取成功", c) |
| | | return |
| | | } |
| | | |
| | | productList := make([]testResp.Product, 0, len(list)) |
| | | |
| | | for _, item := range list { |
| | | productList = append(productList, testResp.Product{ |
| | | Name: item.Name, |
| | | Number: item.Number, |
| | | SupplierId: item.SupplierId, |
| | | Unit: item.Unit, |
| | | PurchasePrice: item.PurchasePrice, |
| | | DeliveryTime: item.DeliveryTime, |
| | | ShippingDuration: item.ShippingDuration, |
| | | Specifications: item.Specifications, |
| | | ModelNumber: item.ModelNumber, |
| | | ProductType: "", |
| | | MinimumStock: item.MinimumStock, |
| | | MaximumStock: item.MaximumStock, |
| | | Remark: "", |
| | | SupplierName: item.Supplier.Name, |
| | | }) |
| | | } |
| | | |
| | | response.OkWithDetailed(response.PageResult{ |
| | | List: list, |
| | | Total: total, |
| | | Page: pageInfo.Page, |
| | | PageSize: pageInfo.PageSize, |
| | | }, "获取成功", c) |
| | | } |
| | | |
| | | var ( |
| | |
| | | ProductName: pageInfo.Name, |
| | | }) |
| | | rawProductList := getProductListResponse.List |
| | | productList := make([]test.Product, len(rawProductList)) |
| | | productList := make([]testResp.Product, len(rawProductList)) |
| | | |
| | | for k, v := range rawProductList { |
| | | productList[k].Number = v.Number |
| | | productList[k].Name = v.Name |
| | | productList[k].Unit = v.Unit |
| | | productList[k].PurchasePrice = v.SalePrice |
| | | min := int(v.MinInventory) |
| | | min := int64(v.MinInventory) |
| | | productList[k].MinimumStock = min |
| | | max := int(v.MaxInventory) |
| | | max := int64(v.MaxInventory) |
| | | productList[k].MaximumStock = max |
| | | productList[k].Remark = v.Node |
| | | productList[k].ProductType = v.MaterialMode |
| | |
| | | singular: false |
| | | log-zap: false |
| | | disable: true |
| | | mssql: |
| | | prefix: "" |
| | | port: "" |
| | | config: "" |
| | | db-name: "" |
| | | username: "" |
| | | password: "" |
| | | path: "" |
| | | engine: "" |
| | | log-mode: "" |
| | | max-idle-conns: 10 |
| | | max-open-conns: 100 |
| | | singular: false |
| | | log-zap: false |
| | | mysql: |
| | | prefix: "" |
| | | port: "3306" |
| | |
| | | password: c++java123 |
| | | path: 192.168.20.119 |
| | | engine: "" |
| | | log-mode: error |
| | | log-mode: info |
| | | max-idle-conns: 10 |
| | | max-open-conns: 100 |
| | | singular: false |
| | | log-zap: false |
| | | oracle: |
| | | prefix: "" |
| | | port: "" |
| | | config: "" |
| | | db-name: "" |
| | | username: "" |
| | | password: "" |
| | | path: "" |
| | | engine: "" |
| | | log-mode: "" |
| | | max-idle-conns: 10 |
| | | max-open-conns: 100 |
| | | singular: false |
| | | log-zap: false |
| | | pgsql: |
| | | prefix: "" |
| | | port: "" |
| | | config: "" |
| | | db-name: "" |
| | | username: "" |
| | | password: "" |
| | | path: "" |
| | | engine: "" |
| | | log-mode: "" |
| | | max-idle-conns: 10 |
| | | max-open-conns: 100 |
| | | singular: false |
| | | log-zap: false |
| | | sqlite: |
| | | prefix: "" |
| | | port: "" |
| | | config: "" |
| | | db-name: "" |
| | | username: "" |
| | | password: "" |
| | | path: "" |
| | | engine: "" |
| | | log-mode: "" |
| | | max-idle-conns: 10 |
| | | max-open-conns: 100 |
| | | singular: false |
| | | log-zap: false |
| | | log-zap: true |
| | | system: |
| | | env: public |
| | | db-type: mysql |
| | |
| | | start: true |
| | | with_seconds: false |
| | | zap: |
| | | level: info |
| | | level: debug |
| | | prefix: '[srm]' |
| | | format: console |
| | | director: log |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/request.GetById" |
| | | } |
| | | } |
| | | ], |
| | |
| | | "summary": "用id查询Product", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "created_at", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "maximumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "minimumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "modelNumber", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "name", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "number", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "productType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "number", |
| | | "name": "purchasePrice", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "remark", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "shippingDuration", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "specifications", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "supplierId", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "supplierName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "unit", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "updated_at", |
| | | "in": "query" |
| | | } |
| | | ], |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "created_at", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "endCreatedAt", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "关键字", |
| | | "name": "keyword", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "maximumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "minimumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "remark", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "shippingDuration", |
| | | "in": "query" |
| | |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "startCreatedAt", |
| | | "name": "supplier", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "unit", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "updated_at", |
| | | "in": "query" |
| | | } |
| | | ], |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "created_at", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "endCreatedAt", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "关键字", |
| | | "name": "keyword", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "maximumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "minimumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "remark", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "shippingDuration", |
| | | "in": "query" |
| | |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "startCreatedAt", |
| | | "name": "supplier", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "unit", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "updated_at", |
| | | "in": "query" |
| | | } |
| | | ], |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/test.SupplierMaterial" |
| | | } |
| | | } |
| | | ], |
| | |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | | "type": "string" |
| | | }, |
| | | "purchaseId": { |
| | | "description": "采购id", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.GetById": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.IdsReq": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.Product": { |
| | | "type": "object", |
| | | "properties": { |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "shippingDuration": { |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "supplier": { |
| | | "type": "string" |
| | | }, |
| | | "supplierId": { |
| | | "type": "integer" |
| | | }, |
| | | "supplierName": { |
| | | "type": "string" |
| | | }, |
| | | "supplierNumber": { |
| | | "type": "string" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.ProductCreate": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/request.Product" |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "test.Product": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "type": "string" |
| | | }, |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | | }, |
| | | "maximumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "minimumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "shippingDuration": { |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "supplier": { |
| | | "$ref": "#/definitions/test.Supplier" |
| | | }, |
| | | "supplierId": { |
| | | "type": "integer" |
| | | }, |
| | | "supplierName": { |
| | | "type": "string" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | }, |
| | | "updated_at": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "test.Supplier": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "test.SupplierMaterial": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "type": "string" |
| | | }, |
| | | "deliveryTime": { |
| | | "description": "供货时长", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | | }, |
| | | "maximumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "minimumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "shippingDuration": { |
| | | "description": "物流时长", |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "supplier": { |
| | | "$ref": "#/definitions/test.Supplier" |
| | | }, |
| | | "supplierId": { |
| | | "type": "integer" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | }, |
| | | "updated_at": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "test.SupplierType": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/request.GetById" |
| | | } |
| | | } |
| | | ], |
| | |
| | | "summary": "用id查询Product", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "created_at", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "maximumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "minimumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "modelNumber", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "name", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "number", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "productType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "number", |
| | | "name": "purchasePrice", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "remark", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "shippingDuration", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "specifications", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "supplierId", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "supplierName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "unit", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "updated_at", |
| | | "in": "query" |
| | | } |
| | | ], |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "created_at", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "endCreatedAt", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "关键字", |
| | | "name": "keyword", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "maximumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "minimumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "remark", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "shippingDuration", |
| | | "in": "query" |
| | |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "startCreatedAt", |
| | | "name": "supplier", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "unit", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "updated_at", |
| | | "in": "query" |
| | | } |
| | | ], |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "created_at", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "endCreatedAt", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "description": "主键ID", |
| | | "name": "id", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "关键字", |
| | | "name": "keyword", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "maximumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "minimumStock", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "remark", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "shippingDuration", |
| | | "in": "query" |
| | |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "startCreatedAt", |
| | | "name": "supplier", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | { |
| | | "type": "string", |
| | | "name": "unit", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "updated_at", |
| | | "in": "query" |
| | | } |
| | | ], |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/test.SupplierMaterial" |
| | | } |
| | | } |
| | | ], |
| | |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | | "type": "string" |
| | | }, |
| | | "purchaseId": { |
| | | "description": "采购id", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.GetById": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.IdsReq": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.Product": { |
| | | "type": "object", |
| | | "properties": { |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "shippingDuration": { |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "supplier": { |
| | | "type": "string" |
| | | }, |
| | | "supplierId": { |
| | | "type": "integer" |
| | | }, |
| | | "supplierName": { |
| | | "type": "string" |
| | | }, |
| | | "supplierNumber": { |
| | | "type": "string" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.ProductCreate": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/request.Product" |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "test.Product": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "type": "string" |
| | | }, |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | | }, |
| | | "maximumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "minimumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "shippingDuration": { |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "supplier": { |
| | | "$ref": "#/definitions/test.Supplier" |
| | | }, |
| | | "supplierId": { |
| | | "type": "integer" |
| | | }, |
| | | "supplierName": { |
| | | "type": "string" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | }, |
| | | "updated_at": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "test.Supplier": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "test.SupplierMaterial": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "type": "string" |
| | | }, |
| | | "deliveryTime": { |
| | | "description": "供货时长", |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | | }, |
| | | "maximumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "minimumStock": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "shippingDuration": { |
| | | "description": "物流时长", |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "supplier": { |
| | | "$ref": "#/definitions/test.Supplier" |
| | | }, |
| | | "supplierId": { |
| | | "type": "integer" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | }, |
| | | "updated_at": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "test.SupplierType": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | type: number |
| | | productId: |
| | | description: 产品id |
| | | type: integer |
| | | type: string |
| | | purchaseId: |
| | | description: 采购id |
| | | type: integer |
| | |
| | | purchase: |
| | | $ref: '#/definitions/purchaserequest.Purchase' |
| | | type: object |
| | | request.GetById: |
| | | properties: |
| | | id: |
| | | description: 主键ID |
| | | type: integer |
| | | type: object |
| | | request.IdsReq: |
| | | properties: |
| | | ids: |
| | |
| | | $ref: '#/definitions/test.Industry' |
| | | type: array |
| | | type: object |
| | | request.Product: |
| | | properties: |
| | | deliveryTime: |
| | | type: integer |
| | | modelNumber: |
| | | type: string |
| | | name: |
| | | type: string |
| | | number: |
| | | type: string |
| | | productType: |
| | | type: string |
| | | purchasePrice: |
| | | type: number |
| | | shippingDuration: |
| | | type: integer |
| | | specifications: |
| | | type: string |
| | | supplier: |
| | | type: string |
| | | supplierId: |
| | | type: integer |
| | | supplierName: |
| | | type: string |
| | | supplierNumber: |
| | | type: string |
| | | unit: |
| | | type: string |
| | | type: object |
| | | request.ProductCreate: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/test.Product' |
| | | $ref: '#/definitions/request.Product' |
| | | type: array |
| | | type: object |
| | | request.SupplierStatus: |
| | |
| | | uuid: |
| | | type: string |
| | | type: object |
| | | test.Product: |
| | | properties: |
| | | created_at: |
| | | type: string |
| | | deliveryTime: |
| | | type: integer |
| | | id: |
| | | description: 主键ID |
| | | type: integer |
| | | maximumStock: |
| | | type: integer |
| | | minimumStock: |
| | | type: integer |
| | | modelNumber: |
| | | type: string |
| | | name: |
| | | type: string |
| | | number: |
| | | type: string |
| | | productType: |
| | | type: string |
| | | purchasePrice: |
| | | type: number |
| | | remark: |
| | | type: string |
| | | shippingDuration: |
| | | type: integer |
| | | specifications: |
| | | type: string |
| | | supplier: |
| | | $ref: '#/definitions/test.Supplier' |
| | | supplierId: |
| | | type: integer |
| | | supplierName: |
| | | type: string |
| | | unit: |
| | | type: string |
| | | updated_at: |
| | | type: string |
| | | type: object |
| | | test.Supplier: |
| | | properties: |
| | | account: |
| | |
| | | updated_at: |
| | | type: string |
| | | url: |
| | | type: string |
| | | type: object |
| | | test.SupplierMaterial: |
| | | properties: |
| | | created_at: |
| | | type: string |
| | | deliveryTime: |
| | | description: 供货时长 |
| | | type: integer |
| | | id: |
| | | description: 主键ID |
| | | type: integer |
| | | maximumStock: |
| | | type: integer |
| | | minimumStock: |
| | | type: integer |
| | | modelNumber: |
| | | type: string |
| | | name: |
| | | type: string |
| | | number: |
| | | type: string |
| | | purchasePrice: |
| | | type: number |
| | | shippingDuration: |
| | | description: 物流时长 |
| | | type: integer |
| | | specifications: |
| | | type: string |
| | | supplier: |
| | | $ref: '#/definitions/test.Supplier' |
| | | supplierId: |
| | | type: integer |
| | | unit: |
| | | type: string |
| | | updated_at: |
| | | type: string |
| | | type: object |
| | | test.SupplierType: |
| | |
| | | name: data |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/test.Product' |
| | | $ref: '#/definitions/request.GetById' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | consumes: |
| | | - application/json |
| | | parameters: |
| | | - in: query |
| | | name: created_at |
| | | type: string |
| | | - in: query |
| | | name: deliveryTime |
| | | type: integer |
| | | - description: 主键ID |
| | | in: query |
| | | name: id |
| | | type: integer |
| | | - in: query |
| | | name: maximumStock |
| | | type: integer |
| | | - in: query |
| | | name: minimumStock |
| | | type: integer |
| | | - in: query |
| | | name: modelNumber |
| | | type: string |
| | | - in: query |
| | | name: name |
| | | type: string |
| | | - in: query |
| | | name: number |
| | | type: string |
| | | - in: query |
| | | name: productType |
| | | type: string |
| | | - in: query |
| | | name: purchasePrice |
| | | type: number |
| | | - in: query |
| | | name: remark |
| | | type: string |
| | | - in: query |
| | | name: shippingDuration |
| | | type: integer |
| | | - in: query |
| | | name: specifications |
| | | type: string |
| | | - in: query |
| | | name: supplierId |
| | | type: integer |
| | | - in: query |
| | | name: supplierName |
| | | type: string |
| | | - in: query |
| | | name: unit |
| | | type: string |
| | | - in: query |
| | | name: updated_at |
| | | type: string |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | - application/json |
| | | parameters: |
| | | - in: query |
| | | name: created_at |
| | | type: string |
| | | - in: query |
| | | name: deliveryTime |
| | | type: integer |
| | | - in: query |
| | | name: endCreatedAt |
| | | type: string |
| | | - description: 主键ID |
| | | in: query |
| | | name: id |
| | | type: integer |
| | | - description: 关键字 |
| | | in: query |
| | | name: keyword |
| | | type: string |
| | | - in: query |
| | | name: maximumStock |
| | | type: integer |
| | | - in: query |
| | | name: minimumStock |
| | | type: integer |
| | | - in: query |
| | | name: modelNumber |
| | | type: string |
| | |
| | | name: purchasePrice |
| | | type: number |
| | | - in: query |
| | | name: remark |
| | | type: string |
| | | - in: query |
| | | name: shippingDuration |
| | | type: integer |
| | | - in: query |
| | | name: specifications |
| | | type: string |
| | | - in: query |
| | | name: startCreatedAt |
| | | name: supplier |
| | | type: string |
| | | - in: query |
| | | name: supplierId |
| | |
| | | type: string |
| | | - in: query |
| | | name: unit |
| | | type: string |
| | | - in: query |
| | | name: updated_at |
| | | type: string |
| | | produces: |
| | | - application/json |
| | |
| | | - application/json |
| | | parameters: |
| | | - in: query |
| | | name: created_at |
| | | type: string |
| | | - in: query |
| | | name: deliveryTime |
| | | type: integer |
| | | - in: query |
| | | name: endCreatedAt |
| | | type: string |
| | | - description: 主键ID |
| | | in: query |
| | | name: id |
| | | type: integer |
| | | - description: 关键字 |
| | | in: query |
| | | name: keyword |
| | | type: string |
| | | - in: query |
| | | name: maximumStock |
| | | type: integer |
| | | - in: query |
| | | name: minimumStock |
| | | type: integer |
| | | - in: query |
| | | name: modelNumber |
| | | type: string |
| | |
| | | name: purchasePrice |
| | | type: number |
| | | - in: query |
| | | name: remark |
| | | type: string |
| | | - in: query |
| | | name: shippingDuration |
| | | type: integer |
| | | - in: query |
| | | name: specifications |
| | | type: string |
| | | - in: query |
| | | name: startCreatedAt |
| | | name: supplier |
| | | type: string |
| | | - in: query |
| | | name: supplierId |
| | |
| | | type: string |
| | | - in: query |
| | | name: unit |
| | | type: string |
| | | - in: query |
| | | name: updated_at |
| | | type: string |
| | | produces: |
| | | - application/json |
| | |
| | | name: data |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/test.Product' |
| | | $ref: '#/definitions/test.SupplierMaterial' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | test.SupplierType{}, |
| | | test.Supplier{}, |
| | | test.Contract{}, |
| | | test.SupplierMaterial{}, |
| | | purchase.Purchase{}, |
| | | purchase.PurchaseProducts{}, |
| | | ) |
| | |
| | | } |
| | | |
| | | go test.InitProductServiceConn() |
| | | defer test.CloseProductServiceConn() |
| | | initialize.InitRpcClient() |
| | | defer initialize.CloseRpcClient() |
| | | |
| | |
| | | |
| | | type PurchaseProducts struct { |
| | | global.GVA_MODEL |
| | | PurchaseId int `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购id |
| | | ProductId int `json:"productId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"` // 产品id |
| | | Product test.Product `json:"-" gorm:"foreignKey:ProductId"` |
| | | Amount decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:采购数量"` // 采购数量 |
| | | Price decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购单价"` // 采购单价 |
| | | Total decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购总价"` // 采购总价 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:描述"` //描述 |
| | | PurchaseId int `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购id |
| | | ProductId string `json:"productId" form:"productId" gorm:"type:varchar(255);not null;default '';comment:产品id"` // 产品id |
| | | Product test.SupplierMaterial `json:"-" gorm:"foreignKey:ProductId"` |
| | | Amount decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:采购数量"` // 采购数量 |
| | | Price decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购单价"` // 采购单价 |
| | | Total decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:采购总价"` // 采购总价 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:描述"` //描述 |
| | | } |
| | | |
| | | func (PurchaseProducts) TableName() string { |
New file |
| | |
| | | package test |
| | | |
| | | // Attachment 结构体 |
| | | type Attachment struct { |
| | | ID uint `gorm:"primarykey"` // 主键ID |
| | | FileName string `json:"fileName" gorm:"type:varchar(127);comment:文件名"` |
| | | FileUrl string `json:"FileUrl" gorm:"type:varchar(255);comment:文件地址"` |
| | | Ext string `json:"ext" gorm:"type:varchar(15);comment:文件后缀名"` |
| | | FileType FileType `json:"fileType" gorm:"type:varchar(31);comment:文件类型 pic:图片;thumbnail:缩略图;file:文件"` |
| | | } |
| | | |
| | | // TableName MaterialAttachment 表名 |
| | | func (Attachment) TableName() string { |
| | | return "attachment" |
| | | } |
| | | |
| | | type FileType string |
| | | |
| | | const ( |
| | | FileType_File FileType = "file" //文件 |
| | | FileType_Picture FileType = "picture" //图片 |
| | | FileType_Thumbnail FileType = "thumbnail" //缩略图 |
| | | ) |
New file |
| | |
| | | package test |
| | | |
| | | import ( |
| | | "github.com/shopspring/decimal" |
| | | ) |
| | | |
| | | // Material 结构体 |
| | | type Material struct { |
| | | ID string |
| | | Name string `gorm:"type:varchar(191);not null;comment:物料名称" json:"name"` |
| | | MaterialType MaterialType `gorm:"index;type:int(11);comment:物料类型(数字)" json:"materialType"` |
| | | Model MaterialMode `gorm:"type:varchar(191);not null;comment:物料类型(字符串)" json:"model"` |
| | | Explain string `gorm:"type:varchar(512);comment:编号说明" json:"explain"` |
| | | CodeStandardID string `gorm:"type:varchar(191);comment:编码规范ID" json:"codeStandardID"` |
| | | Specs string `gorm:"type:varchar(191);comment:物料规格" json:"specs"` |
| | | Type string `gorm:"type:varchar(191);comment:物料型号" json:"type"` |
| | | MinInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:最小库存" json:"minInventory"` |
| | | MaxInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:最大库存" json:"maxInventory"` |
| | | Amount decimal.Decimal `gorm:"type:decimal(35,18);comment:数量" json:"amount"` |
| | | LockAmount decimal.Decimal `gorm:"type:decimal(35,18);default:0;comment:锁定数量" json:"lockAmount"` |
| | | Unit string `gorm:"type:varchar(100);comment:单位" json:"unit"` |
| | | Note string `gorm:"type:varchar(1024);comment:备注" json:"note"` |
| | | TemplateID string `gorm:"type:varchar(191);comment:模板ID" json:"-"` |
| | | FSource string `gorm:"type:varchar(191);comment:生产车间" json:"-"` |
| | | Status MaterialStatus `gorm:"type:int(11);comment:状态" json:"status"` |
| | | Supplier string `gorm:"type:varchar(191);comment:供应商" json:"supplier"` |
| | | PurchasePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:采购价格" json:"purchasePrice"` |
| | | PurchaseAheadDay int `gorm:"type:int(11);comment:采购提前期(天)" json:"purchaseAheadDay"` |
| | | ProduceAheadDay int `gorm:"type:int(11);comment:制造提前期(天)" json:"produceAheadDay"` |
| | | MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:最小采购量" json:"minPurchaseAmount"` |
| | | PurchaseType PurchaseType `gorm:"type:int(11);comment:采购类型" json:"purchaseType"` |
| | | IsSale *bool `gorm:"type:tinyint(1);comment:是否销售" json:"isSale"` |
| | | SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"` |
| | | AutoIncr uint `gorm:"type:int(11);comment:自增ID;default:0;" json:"autoIncr"` |
| | | AttachmentList []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"` |
| | | } |
| | | |
| | | // PurchaseType 采购类型 |
| | | type PurchaseType int |
| | | |
| | | const ( |
| | | PurchaseTypeOutSource PurchaseType = iota + 1 // 采购 |
| | | PurchaseTypeSelf // 自制 |
| | | PurchaseTypeEntrust // 委外 |
| | | ) |
| | | |
| | | type MaterialStatus int |
| | | |
| | | const ( |
| | | MaterialStatusCreate MaterialStatus = iota // 新建 |
| | | MaterialStatusActive // 启用 |
| | | MaterialStatusInactive = -1 // 停用 |
| | | ) |
| | | |
| | | // MaterialMode 物料类型(字符串) |
| | | type MaterialMode string |
| | | |
| | | const ( |
| | | MaterialModeRaw MaterialMode = "原材料" |
| | | MaterialModeSemi MaterialMode = "半成品" |
| | | MaterialModeFinished MaterialMode = "成品" |
| | | MaterialModeAuxiliary MaterialMode = "辅料" //辅料 |
| | | MaterialModeConsumables MaterialMode = "耗材" //耗材 |
| | | MaterialModeOther MaterialMode = "其他" //其他 |
| | | ) |
| | | |
| | | func (t MaterialMode) Valid() bool { |
| | | if t != MaterialModeRaw && |
| | | t != MaterialModeSemi && |
| | | t != MaterialModeAuxiliary && |
| | | t != MaterialModeConsumables && |
| | | t != MaterialModeOther && |
| | | t != MaterialModeFinished { |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | func (t MaterialMode) Type() MaterialType { |
| | | switch t { |
| | | case MaterialModeRaw: |
| | | return MaterialTypeRaw |
| | | case MaterialModeSemi: |
| | | return MaterialTypeSemi |
| | | case MaterialModeFinished: |
| | | return MaterialTypeFinished |
| | | } |
| | | return MaterialType(0) |
| | | } |
| | | |
| | | // MaterialType 物料类型(数字) |
| | | type MaterialType int |
| | | |
| | | const ( |
| | | MaterialTypeRaw = iota + 1 // 原材料 |
| | | MaterialTypeSemi // 半成品 |
| | | MaterialTypeFinished // 成品 |
| | | MaterialTypeAuxiliary //辅料 |
| | | MaterialTypeConsumables //耗材 |
| | | MaterialTypeOther //其他 |
| | | ) |
| | | |
| | | func (t MaterialType) Valid() bool { |
| | | if t < MaterialTypeRaw || |
| | | t > MaterialTypeFinished { |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | // TableName Product 表名 |
| | | func (Material) TableName() string { |
| | | return "material" |
| | | } |
| | |
| | | package test |
| | | |
| | | import "srm/global" |
| | | import ( |
| | | "srm/global" |
| | | ) |
| | | |
| | | // Product 结构体 |
| | | type Product struct { |
| | | // SupplierMaterial 结构体 |
| | | type SupplierMaterial struct { |
| | | global.GVA_MODEL |
| | | Name string `json:"name" form:"name" gorm:"column:name;comment:名称;size:255;"` |
| | | Number string `json:"number" form:"number" gorm:"column:number;comment:编码;size:255;"` |
| | | Name string `gorm:"type:varchar(191);not null;comment:物料名称" json:"name"` |
| | | Number string `json:"number" form:"number" gorm:"column:number;comment:物料编码;size:255;"` |
| | | SupplierId uint `json:"supplierId" form:"supplierId" gorm:"column:supplier_id;comment:供应商id;size:255;"` |
| | | Supplier Supplier `json:"supplier" form:"supplier" gorm:"foreignKey:SupplierId;references:ID;comment:供应商"` |
| | | Supplier Supplier `json:"supplier" form:"supplier" gorm:"foreignKey:SupplierId;comment:供应商"` |
| | | Unit string `json:"unit" form:"unit" gorm:"column:unit;comment:计量单位;size:255;"` |
| | | PurchasePrice float64 `json:"purchasePrice" form:"purchasePrice" gorm:"column:purchase_price;comment:采购价格;"` |
| | | DeliveryTime int `json:"deliveryTime" form:"deliveryTime" gorm:"column:delivery_time;comment:;size:11;"` |
| | | ShippingDuration int `json:"shippingDuration" form:"shippingDuration" gorm:"column:shipping_duration;comment:物流时长;size:11;"` |
| | | DeliveryTime int `json:"deliveryTime" form:"deliveryTime" gorm:"column:delivery_time;comment:;size:11;"` //供货时长 |
| | | ShippingDuration int `json:"shippingDuration" form:"shippingDuration" gorm:"column:shipping_duration;comment:物流时长;size:11;"` //物流时长 |
| | | Specifications string `json:"specifications" form:"specifications" gorm:"column:specifications;comment:规格;size:255;"` |
| | | ModelNumber string `json:"modelNumber" form:"modelNumber" gorm:"column:model_number;comment:型号;size:255;"` |
| | | ProductType string `json:"productType" form:"productType" gorm:"column:product_type;comment:产品类别;size:255;"` |
| | | MinimumStock int `json:"minimumStock" form:"minimumStock" gorm:"column:minimum_stock;comment:最低库存;"` |
| | | MaximumStock int `json:"maximumStock" form:"maximumStock" gorm:"column:maximum_stock;comment:最高库存;"` |
| | | Remark string `json:"remark" form:"remark" gorm:"column:remark;comment:备注;size:255;"` |
| | | SupplierName string `json:"supplierName" gorm:"-"` |
| | | MinimumStock int64 `json:"minimumStock" form:"minimumStock" gorm:"column:minimum_stock;comment:最低库存;"` |
| | | MaximumStock int64 `json:"maximumStock" form:"maximumStock" gorm:"column:maximum_stock;comment:最高库存;"` |
| | | } |
| | | |
| | | // TableName Product 表名 |
| | | func (Product) TableName() string { |
| | | return "srm_product" |
| | | func (SupplierMaterial) TableName() string { |
| | | return "srm_supplier_material" |
| | | } |
| | |
| | | |
| | | import ( |
| | | "srm/model/common/request" |
| | | "srm/model/test" |
| | | "time" |
| | | ) |
| | | |
| | | type ProductSearch struct { |
| | | test.Product |
| | | SupplierNumber string `json:"supplierNumber" form:"supplierNumber"` |
| | | StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"` |
| | | EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"` |
| | | Product |
| | | request.PageInfo |
| | | } |
| | | |
| | | type ProductCreate struct { |
| | | List []*test.Product `json:"list"` |
| | | List []*Product `json:"list"` |
| | | } |
| | | |
| | | type Product struct { |
| | | Name string `json:"name" form:"name" gorm:"column:name;comment:名称;size:255;"` |
| | | Number string `json:"number" form:"number" gorm:"column:number;comment:编码;size:255;"` |
| | | SupplierId uint `json:"supplierId" form:"supplierId" gorm:"column:supplier_id;comment:供应商id;size:255;"` |
| | | Supplier string `json:"supplier" form:"supplier" gorm:"foreignKey:SupplierId;references:ID;comment:供应商"` |
| | | Unit string `json:"unit" form:"unit" gorm:"column:unit;comment:计量单位;size:255;"` |
| | | PurchasePrice float64 `json:"purchasePrice" form:"purchasePrice" gorm:"column:purchase_price;comment:采购价格;"` |
| | | DeliveryTime int `json:"deliveryTime" form:"deliveryTime" gorm:"column:delivery_time;comment:;size:11;"` |
| | | ShippingDuration int `json:"shippingDuration" form:"shippingDuration" gorm:"column:shipping_duration;comment:物流时长;size:11;"` |
| | | Specifications string `json:"specifications" form:"specifications" gorm:"column:specifications;comment:规格;size:255;"` |
| | | ModelNumber string `json:"modelNumber" form:"modelNumber" gorm:"column:model_number;comment:型号;size:255;"` |
| | | ProductType string `json:"productType" form:"productType" gorm:"column:product_type;comment:产品类别;size:255;"` |
| | | SupplierName string `json:"supplierName" gorm:"-"` |
| | | SupplierNumber string `json:"supplierNumber" form:"supplierNumber"` |
| | | } |
New file |
| | |
| | | package productresponse |
| | | |
| | | type Product struct { |
| | | Name string `json:"name" form:"name" gorm:"column:name;comment:名称;size:255;"` |
| | | Number string `json:"number" form:"number" gorm:"column:number;comment:编码;size:255;"` |
| | | SupplierId uint `json:"supplierId" form:"supplierId" gorm:"column:supplier_id;comment:供应商id;size:255;"` |
| | | Unit string `json:"unit" form:"unit" gorm:"column:unit;comment:计量单位;size:255;"` |
| | | PurchasePrice float64 `json:"purchasePrice" form:"purchasePrice" gorm:"column:purchase_price;comment:采购价格;"` |
| | | DeliveryTime int `json:"deliveryTime" form:"deliveryTime" gorm:"column:delivery_time;comment:;size:11;"` |
| | | ShippingDuration int `json:"shippingDuration" form:"shippingDuration" gorm:"column:shipping_duration;comment:物流时长;size:11;"` |
| | | Specifications string `json:"specifications" form:"specifications" gorm:"column:specifications;comment:规格;size:255;"` |
| | | ModelNumber string `json:"modelNumber" form:"modelNumber" gorm:"column:model_number;comment:型号;size:255;"` |
| | | ProductType string `json:"productType" form:"productType" gorm:"column:product_type;comment:产品类别;size:255;"` |
| | | MinimumStock int64 `json:"minimumStock" form:"minimumStock" gorm:"column:minimum_stock;comment:最低库存;"` |
| | | MaximumStock int64 `json:"maximumStock" form:"maximumStock" gorm:"column:maximum_stock;comment:最高库存;"` |
| | | Remark string `json:"remark" form:"remark" gorm:"column:remark;comment:备注;size:255;"` |
| | | SupplierName string `json:"supplierName" gorm:"-"` |
| | | } |
| | |
| | | var purchaseList = make([]*purchase.Purchase, 0) |
| | | if info.Keyword != "" { |
| | | db.Distinct("srm_purchase.id").Joins("left join srm_purchase_products on srm_purchase_products.purchase_id = srm_purchase.id"). |
| | | Joins("left join srm_product on srm_product.Id = srm_purchase_products.product_id"). |
| | | Joins("left join material on material.id = srm_purchase_products.product_id"). |
| | | Joins("left join srm_supplier on srm_supplier.Id = srm_purchase.supplier_id"). |
| | | Where("srm_purchase.name like ?", "%"+info.Keyword+"%"). |
| | | Or("srm_product.name like ?", "%"+info.Keyword+"%"). |
| | | Or("material.name like ?", "%"+info.Keyword+"%"). |
| | | Or("srm_supplier.name like ?", "%"+info.Keyword+"%") |
| | | err = db.Limit(limit).Offset(offset).Find(&ids).Error |
| | | if err != nil { |
| | |
| | | } |
| | | productIds := make([]uint, 0, len(productList)) |
| | | for _, product := range productList { |
| | | productIds = append(productIds, uint(product.ProductId)) |
| | | productIds = append(productIds, product.ID) |
| | | } |
| | | productService := &test.ProductService{} |
| | | _, productMap, err := productService.GetProducts(productIds) |
| | |
| | | } |
| | | inspectOrders := make([]*qualityinspect.QualityInspect, 0, len(productList)) |
| | | for _, productItem := range productList { |
| | | product := productMap[uint(productItem.ProductId)] |
| | | product := productMap[productItem.ID] |
| | | if product == nil { |
| | | continue |
| | | } |
| | |
| | | |
| | | // CreateProduct 创建Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) CreateProduct(p []*test.Product) (err error) { |
| | | err = global.GVA_DB.Create(p).Error |
| | | func (pService *ProductService) CreateProduct(pList []*testReq.Product) (err error) { |
| | | |
| | | products := make([]*test.SupplierMaterial, 0, len(pList)) |
| | | |
| | | for _, p := range pList { |
| | | products = append(products, &test.SupplierMaterial{ |
| | | Name: p.Name, |
| | | Number: p.Number, |
| | | SupplierId: p.SupplierId, |
| | | Unit: p.Unit, |
| | | PurchasePrice: p.PurchasePrice, |
| | | DeliveryTime: p.DeliveryTime, |
| | | ShippingDuration: p.ShippingDuration, |
| | | Specifications: p.Specifications, |
| | | }) |
| | | } |
| | | |
| | | err = global.GVA_DB.Create(products).Error |
| | | return err |
| | | } |
| | | |
| | | // DeleteProduct 删除Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) DeleteProduct(p test.Product) (err error) { |
| | | err = global.GVA_DB.Delete(&p).Error |
| | | func (pService *ProductService) DeleteProduct(id int) (err error) { |
| | | err = global.GVA_DB.Delete(&test.SupplierMaterial{}, "id = ?", id).Error |
| | | return err |
| | | } |
| | | |
| | | // DeleteProductByIds 批量删除Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) DeleteProductByIds(ids request.IdsReq) (err error) { |
| | | err = global.GVA_DB.Delete(&[]test.Product{}, "id in ?", ids.Ids).Error |
| | | err = global.GVA_DB.Delete(&[]test.SupplierMaterial{}, "id in ?", ids.Ids).Error |
| | | return err |
| | | } |
| | | |
| | | // UpdateProduct 更新Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) UpdateProduct(p test.Product) (err error) { |
| | | func (pService *ProductService) UpdateProduct(p test.SupplierMaterial) (err error) { |
| | | err = global.GVA_DB.Updates(&p).Error |
| | | return err |
| | | } |
| | | |
| | | // GetProduct 根据id获取Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) GetProduct(id uint) (p test.Product, err error) { |
| | | func (pService *ProductService) GetProduct(id int) (p test.SupplierMaterial, err error) { |
| | | err = global.GVA_DB.Where("id = ?", id).First(&p).Error |
| | | return |
| | | } |
| | | |
| | | // GetProductInfoList 分页获取Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) GetProductInfoList(info testReq.ProductSearch) (list []test.Product, total int64, err error) { |
| | | func (pService *ProductService) GetProductInfoList(info testReq.ProductSearch) (list []test.SupplierMaterial, total int64, err error) { |
| | | limit := info.PageSize |
| | | offset := info.PageSize * (info.Page - 1) |
| | | // 创建db |
| | | db := global.GVA_DB.Model(&test.Product{}) |
| | | var ps []test.Product |
| | | // 如果有条件搜索 下方会自动创建搜索语句 |
| | | db := global.GVA_DB.Model(&test.SupplierMaterial{}) |
| | | var ps []test.SupplierMaterial |
| | | //搜索框合一添加查询条件 |
| | | if info.Keyword != "" { |
| | | db = db.Where("srm_product.name LIKE ?", "%"+info.Keyword+"%").Joins("srm_supplier").Or("srm_supplier.name LIKE ?", "%"+info.Keyword+"%") |
| | | } |
| | | if info.StartCreatedAt != nil && info.EndCreatedAt != nil { |
| | | db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt) |
| | | db = db.Where("srm_supplier_material.name LIKE ?", "%"+info.Keyword+"%").Joins("srm_supplier").Or("srm_supplier.name LIKE ?", "%"+info.Keyword+"%") |
| | | } |
| | | if info.Name != "" { |
| | | db = db.Where("name LIKE ?", "%"+info.Name+"%") |
| | | } |
| | | if info.Number != "" { |
| | | db = db.Where("number LIKE ?", "%"+info.Number+"%") |
| | | } |
| | | if info.Unit != "" { |
| | | db = db.Where("unit LIKE ?", "%"+info.Unit+"%") |
| | | } |
| | | |
| | | if info.SupplierId != 0 { |
| | | db = db.Where("supplier_id = ?", info.SupplierId) |
| | | } |
| | | |
| | | if info.MaximumStock != 0 { |
| | | db = db.Where("maximum_stock = ?", info.MaximumStock) |
| | | } |
| | | |
| | | if info.MinimumStock != 0 { |
| | | db = db.Where("minimum_stock = ?", info.MinimumStock) |
| | | } |
| | | |
| | | if info.PurchasePrice != 0 { |
| | | db = db.Where("purchase_price = ?", info.PurchasePrice) |
| | | } |
| | | |
| | | if info.Specifications != "" { |
| | | db = db.Where("specifications LIKE ?", "%"+info.Specifications+"%") |
| | | } |
| | | |
| | | if info.ModelNumber != "" { |
| | | db = db.Where("model_number LIKE ?", "%"+info.ModelNumber+"%") |
| | | } |
| | | |
| | | if info.ProductType != "" { |
| | | db = db.Where("product_type LIKE ?", "%"+info.ProductType+"%") |
| | | } |
| | | |
| | | if info.SupplierNumber != "" { |
| | | db = db.Joins("srm_supplier").Where("srm_supplier.number LIKE ?", "%"+info.SupplierNumber+"%") |
| | | } |
| | | |
| | | if info.DeliveryTime != 0 { |
| | | db = db.Where("delivery_time = ?", info.DeliveryTime) |
| | | } |
| | | |
| | | if info.ShippingDuration != 0 { |
| | | db = db.Where("shipping_duration = ?", info.ShippingDuration) |
| | | } |
| | | |
| | | err = db.Count(&total).Error |
| | |
| | | } |
| | | |
| | | // GetProducts 根据ids获取Product记录 |
| | | func (pService *ProductService) GetProducts(ids []uint) (p []*test.Product, m map[uint]*test.Product, err error) { |
| | | func (pService *ProductService) GetProducts(ids []uint) (p []*test.SupplierMaterial, m map[uint]*test.SupplierMaterial, err error) { |
| | | err = global.GVA_DB.Where("id in ?", ids).Find(&p).Error |
| | | if err != nil { |
| | | return |
| | | } |
| | | m = make(map[uint]*test.Product, len(p)) |
| | | m = make(map[uint]*test.SupplierMaterial, len(p)) |
| | | for _, product := range p { |
| | | m[product.ID] = product |
| | | } |