From 03915064efe8fd7f222e4aac199af7e2d37deec6 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 15 十一月 2023 20:11:20 +0800
Subject: [PATCH] 增加产品类别
---
/dev/null | 23 -----
model/test/response/product.go | 13 +++
service/test/product.go | 23 +++++
model/test/product.go | 1
model/test/material.go | 8 -
docs/swagger.yaml | 19 ++--
api/v1/test/product.go | 65 ++++++++--------
docs/docs.go | 30 ++++---
model/test/request/product.go | 2
docs/swagger.json | 30 ++++---
10 files changed, 116 insertions(+), 98 deletions(-)
diff --git a/api/v1/test/product.go b/api/v1/test/product.go
index bcd2eea..aba8c67 100644
--- a/api/v1/test/product.go
+++ b/api/v1/test/product.go
@@ -2,7 +2,6 @@
import (
"github.com/gin-gonic/gin"
- "github.com/spf13/cast"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
@@ -12,7 +11,6 @@
"srm/model/test"
testReq "srm/model/test/request"
testResp "srm/model/test/response"
- "srm/proto/product"
"srm/service"
)
@@ -195,6 +193,7 @@
MaximumStock: item.MaximumStock,
Remark: "",
SupplierName: item.Supplier.Name,
+ CategoryName: item.CategoryName,
})
}
@@ -242,39 +241,39 @@
return
}
- cli := product.NewProductServiceClient(productServiceConn)
- getProductListResponse, err := cli.GetProductList(c, &product.GetProductListRequest{
- Page: cast.ToInt32(pageInfo.Page),
- PageSize: cast.ToInt32(pageInfo.PageSize),
- ProductNumber: pageInfo.Number,
- ProductName: pageInfo.Name,
- })
- rawProductList := getProductListResponse.List
- 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 := int64(v.MinInventory)
- productList[k].MinimumStock = min
- max := int64(v.MaxInventory)
- productList[k].MaximumStock = max
- productList[k].Remark = v.Node
- productList[k].ProductType = v.MaterialMode
- }
-
- if err != nil || getProductListResponse.Code != 0 {
+ list, total, err := pService.GetMaterials(pageInfo)
+ if err != nil {
global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err))
response.FailWithMessage("鑾峰彇澶辫触", c)
- } else {
- response.OkWithDetailed(response.PageResult{
- List: productList,
- Total: int64(len(productList)),
- Page: pageInfo.Page,
- PageSize: pageInfo.PageSize,
- }, "鑾峰彇鎴愬姛", c)
+ return
}
+ productList := make([]testResp.Material, len(list))
+
+ for _, item := range list {
+ productList = append(productList, testResp.Material{
+ Name: item.Name,
+ Number: item.ID,
+ Unit: item.Unit,
+ Specifications: item.Specs,
+ ModelNumber: string(item.Model),
+ MinimumStock: item.MinInventory.IntPart(),
+ MaximumStock: item.MaxInventory.IntPart(),
+ Remark: "",
+ CategoryName: item.CategoryName,
+ })
+ }
+
+ if err != nil {
+ global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err))
+ response.FailWithMessage("鑾峰彇澶辫触", c)
+ }
+
+ response.OkWithDetailed(response.PageResult{
+ List: productList,
+ Total: total,
+ Page: pageInfo.Page,
+ PageSize: pageInfo.PageSize,
+ }, "鑾峰彇鎴愬姛", c)
+
}
diff --git a/docs/docs.go b/docs/docs.go
index a8e10bb..bb1bbe9 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -1257,6 +1257,11 @@
"summary": "鍒嗛〉鑾峰彇Product鍒楄〃",
"parameters": [
{
+ "type": "string",
+ "name": "categoryName",
+ "in": "query"
+ },
+ {
"type": "integer",
"name": "deliveryTime",
"in": "query"
@@ -1292,11 +1297,6 @@
"type": "integer",
"description": "姣忛〉澶у皬",
"name": "pageSize",
- "in": "query"
- },
- {
- "type": "string",
- "name": "productType",
"in": "query"
},
{
@@ -1369,6 +1369,11 @@
"summary": "鍒嗛〉鑾峰彇Product鍒楄〃",
"parameters": [
{
+ "type": "string",
+ "name": "categoryName",
+ "in": "query"
+ },
+ {
"type": "integer",
"name": "deliveryTime",
"in": "query"
@@ -1404,11 +1409,6 @@
"type": "integer",
"description": "姣忛〉澶у皬",
"name": "pageSize",
- "in": "query"
- },
- {
- "type": "string",
- "name": "productType",
"in": "query"
},
{
@@ -3807,6 +3807,9 @@
"request.Product": {
"type": "object",
"properties": {
+ "categoryName": {
+ "type": "string"
+ },
"deliveryTime": {
"type": "integer"
},
@@ -3817,9 +3820,6 @@
"type": "string"
},
"number": {
- "type": "string"
- },
- "productType": {
"type": "string"
},
"purchasePrice": {
@@ -4111,6 +4111,10 @@
"test.SupplierMaterial": {
"type": "object",
"properties": {
+ "categoryName": {
+ "description": "浜у搧绫诲埆鍚嶇О",
+ "type": "string"
+ },
"created_at": {
"type": "string"
},
diff --git a/docs/swagger.json b/docs/swagger.json
index 285d41b..c682e63 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -1248,6 +1248,11 @@
"summary": "鍒嗛〉鑾峰彇Product鍒楄〃",
"parameters": [
{
+ "type": "string",
+ "name": "categoryName",
+ "in": "query"
+ },
+ {
"type": "integer",
"name": "deliveryTime",
"in": "query"
@@ -1283,11 +1288,6 @@
"type": "integer",
"description": "姣忛〉澶у皬",
"name": "pageSize",
- "in": "query"
- },
- {
- "type": "string",
- "name": "productType",
"in": "query"
},
{
@@ -1360,6 +1360,11 @@
"summary": "鍒嗛〉鑾峰彇Product鍒楄〃",
"parameters": [
{
+ "type": "string",
+ "name": "categoryName",
+ "in": "query"
+ },
+ {
"type": "integer",
"name": "deliveryTime",
"in": "query"
@@ -1395,11 +1400,6 @@
"type": "integer",
"description": "姣忛〉澶у皬",
"name": "pageSize",
- "in": "query"
- },
- {
- "type": "string",
- "name": "productType",
"in": "query"
},
{
@@ -3798,6 +3798,9 @@
"request.Product": {
"type": "object",
"properties": {
+ "categoryName": {
+ "type": "string"
+ },
"deliveryTime": {
"type": "integer"
},
@@ -3808,9 +3811,6 @@
"type": "string"
},
"number": {
- "type": "string"
- },
- "productType": {
"type": "string"
},
"purchasePrice": {
@@ -4102,6 +4102,10 @@
"test.SupplierMaterial": {
"type": "object",
"properties": {
+ "categoryName": {
+ "description": "浜у搧绫诲埆鍚嶇О",
+ "type": "string"
+ },
"created_at": {
"type": "string"
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index daac693..f2579ec 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -658,6 +658,8 @@
type: object
request.Product:
properties:
+ categoryName:
+ type: string
deliveryTime:
type: integer
modelNumber:
@@ -665,8 +667,6 @@
name:
type: string
number:
- type: string
- productType:
type: string
purchasePrice:
type: number
@@ -860,6 +860,9 @@
type: object
test.SupplierMaterial:
properties:
+ categoryName:
+ description: 浜у搧绫诲埆鍚嶇О
+ type: string
created_at:
type: string
deliveryTime:
@@ -1660,6 +1663,9 @@
- application/json
parameters:
- in: query
+ name: categoryName
+ type: string
+ - in: query
name: deliveryTime
type: integer
- description: 鍏抽敭瀛�
@@ -1683,9 +1689,6 @@
in: query
name: pageSize
type: integer
- - in: query
- name: productType
- type: string
- in: query
name: purchasePrice
type: number
@@ -1728,6 +1731,9 @@
- application/json
parameters:
- in: query
+ name: categoryName
+ type: string
+ - in: query
name: deliveryTime
type: integer
- description: 鍏抽敭瀛�
@@ -1751,9 +1757,6 @@
in: query
name: pageSize
type: integer
- - in: query
- name: productType
- type: string
- in: query
name: purchasePrice
type: number
diff --git a/model/test/attachment.go b/model/test/attachment.go
deleted file mode 100644
index fd58dc0..0000000
--- a/model/test/attachment.go
+++ /dev/null
@@ -1,23 +0,0 @@
-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" //缂╃暐鍥�
-)
diff --git a/model/test/material.go b/model/test/material.go
index 31d322d..25053cb 100644
--- a/model/test/material.go
+++ b/model/test/material.go
@@ -10,8 +10,6 @@
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"`
@@ -19,9 +17,7 @@
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"`
@@ -29,10 +25,8 @@
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"`
+ CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О
}
// PurchaseType 閲囪喘绫诲瀷
diff --git a/model/test/product.go b/model/test/product.go
index 258f6c0..9eeb50e 100644
--- a/model/test/product.go
+++ b/model/test/product.go
@@ -19,6 +19,7 @@
ModelNumber string `json:"modelNumber" form:"modelNumber" gorm:"column:model_number;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:鏈�楂樺簱瀛�;"`
+ CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О
}
// TableName Product 琛ㄥ悕
diff --git a/model/test/request/product.go b/model/test/request/product.go
index 1268b07..4949214 100644
--- a/model/test/request/product.go
+++ b/model/test/request/product.go
@@ -24,7 +24,7 @@
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;"`
+ CategoryName string `json:"categoryName" form:"categoryName" gorm:"column:category_name;comment:浜у搧绫诲埆;size:255;"`
SupplierName string `json:"supplierName" gorm:"-"`
SupplierNumber string `json:"supplierNumber" form:"supplierNumber"`
}
diff --git a/model/test/response/product.go b/model/test/response/product.go
index 853d096..928f4a7 100644
--- a/model/test/response/product.go
+++ b/model/test/response/product.go
@@ -15,4 +15,17 @@
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:"-"`
+ CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О
+}
+
+type Material 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;"`
+ Unit string `json:"unit" form:"unit" gorm:"column:unit;comment:璁¢噺鍗曚綅;size:255;"`
+ 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;"`
+ 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;"`
+ CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О
}
diff --git a/service/test/product.go b/service/test/product.go
index 7449f97..8ad82b5 100644
--- a/service/test/product.go
+++ b/service/test/product.go
@@ -26,6 +26,7 @@
DeliveryTime: p.DeliveryTime,
ShippingDuration: p.ShippingDuration,
Specifications: p.Specifications,
+ CategoryName: p.CategoryName,
})
}
@@ -105,3 +106,25 @@
}
return
}
+
+// GetMaterials 鑾峰彇鐗╂枡
+func (pService *ProductService) GetMaterials(info testReq.ProductSearch) (list []test.Material, total int64, err error) {
+ limit := info.PageSize
+ offset := info.PageSize * (info.Page - 1)
+ // 鍒涘缓db
+ db := global.GVA_DB.Model(&test.Material{})
+ var ps []test.Material
+ if info.Keyword != "" {
+ db = db.Where("name LIKE ? or number LIKE ?", "%"+info.Name+"%", "%"+info.Number+"%")
+ }
+
+ db = db.Where("purchase_type = ?", test.PurchaseTypeOutSource)
+
+ err = db.Count(&total).Error
+ if err != nil {
+ return
+ }
+
+ err = db.Limit(limit).Offset(offset).Find(&ps).Error
+ return ps, total, err
+}
--
Gitblit v1.8.0