| | |
| | | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "go.uber.org/zap" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | |
| | | "srm/model/test" |
| | | testReq "srm/model/test/request" |
| | | testResp "srm/model/test/response" |
| | | "srm/proto/product" |
| | | "srm/service" |
| | | ) |
| | | |
| | |
| | | MaximumStock: item.MaximumStock, |
| | | Remark: "", |
| | | SupplierName: item.Supplier.Name, |
| | | CategoryName: item.CategoryName, |
| | | }) |
| | | } |
| | | |
| | |
| | | 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) |
| | | |
| | | } |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "categoryName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "productType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "categoryName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "productType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "request.Product": { |
| | | "type": "object", |
| | | "properties": { |
| | | "categoryName": { |
| | | "type": "string" |
| | | }, |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | |
| | | "test.SupplierMaterial": { |
| | | "type": "object", |
| | | "properties": { |
| | | "categoryName": { |
| | | "description": "产品类别名称", |
| | | "type": "string" |
| | | }, |
| | | "created_at": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "categoryName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "productType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "summary": "分页获取Product列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | | "name": "categoryName", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "integer", |
| | | "name": "deliveryTime", |
| | | "in": "query" |
| | |
| | | "type": "integer", |
| | | "description": "每页大小", |
| | | "name": "pageSize", |
| | | "in": "query" |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "name": "productType", |
| | | "in": "query" |
| | | }, |
| | | { |
| | |
| | | "request.Product": { |
| | | "type": "object", |
| | | "properties": { |
| | | "categoryName": { |
| | | "type": "string" |
| | | }, |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchasePrice": { |
| | |
| | | "test.SupplierMaterial": { |
| | | "type": "object", |
| | | "properties": { |
| | | "categoryName": { |
| | | "description": "产品类别名称", |
| | | "type": "string" |
| | | }, |
| | | "created_at": { |
| | | "type": "string" |
| | | }, |
| | |
| | | type: object |
| | | request.Product: |
| | | properties: |
| | | categoryName: |
| | | type: string |
| | | deliveryTime: |
| | | type: integer |
| | | modelNumber: |
| | |
| | | name: |
| | | type: string |
| | | number: |
| | | type: string |
| | | productType: |
| | | type: string |
| | | purchasePrice: |
| | | type: number |
| | |
| | | type: object |
| | | test.SupplierMaterial: |
| | | properties: |
| | | categoryName: |
| | | description: 产品类别名称 |
| | | type: string |
| | | created_at: |
| | | type: string |
| | | deliveryTime: |
| | |
| | | - application/json |
| | | parameters: |
| | | - in: query |
| | | name: categoryName |
| | | type: string |
| | | - in: query |
| | | name: deliveryTime |
| | | type: integer |
| | | - description: 关键字 |
| | |
| | | in: query |
| | | name: pageSize |
| | | type: integer |
| | | - in: query |
| | | name: productType |
| | | type: string |
| | | - in: query |
| | | name: purchasePrice |
| | | type: number |
| | |
| | | - application/json |
| | | parameters: |
| | | - in: query |
| | | name: categoryName |
| | | type: string |
| | | - in: query |
| | | name: deliveryTime |
| | | type: integer |
| | | - description: 关键字 |
| | |
| | | in: query |
| | | name: pageSize |
| | | type: integer |
| | | - in: query |
| | | name: productType |
| | | type: string |
| | | - in: query |
| | | name: purchasePrice |
| | | type: number |
| | |
| | | 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"` |
| | |
| | | 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"` |
| | |
| | | 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 采购类型 |
| | |
| | | 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 表名 |
| | |
| | | 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"` |
| | | } |
| | |
| | | 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"` //产品类别名称 |
| | | } |
| | |
| | | DeliveryTime: p.DeliveryTime, |
| | | ShippingDuration: p.ShippingDuration, |
| | | Specifications: p.Specifications, |
| | | CategoryName: p.CategoryName, |
| | | }) |
| | | } |
| | | |
| | |
| | | } |
| | | 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 |
| | | } |