From 2f32021ab211cd901e36c4cbc5875f0f072385bb Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 14 十一月 2023 14:00:39 +0800 Subject: [PATCH] 自动获取物料编码 --- controllers/product_controller.go | 7 proto/code.proto | 48 + controllers/code.go | 109 ++++ models/material.go | 30 docs/swagger.yaml | 143 +++++ request/code_request.go | 32 + docs/docs.go | 212 ++++++++ docs/swagger.json | 212 ++++++++ router/router.go | 7 proto/code/code_grpc.pb.go | 101 +++ models/db.go | 28 + main.go | 2 proto/code/code.pb.go | 584 ++++++++++++++++++++++ 13 files changed, 1,483 insertions(+), 32 deletions(-) diff --git a/controllers/code.go b/controllers/code.go new file mode 100644 index 0000000..f293bb3 --- /dev/null +++ b/controllers/code.go @@ -0,0 +1,109 @@ +package controllers + +import ( + "github.com/gin-gonic/gin" + "github.com/spf13/cast" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "wms/conf" + cd "wms/extend/code" + "wms/extend/util" + "wms/models" + "wms/pkg/contextx" + "wms/pkg/logx" + "wms/proto/code" + "wms/request" +) + +type CodeApi struct{} + +var ( + codeServiceConn *grpc.ClientConn +) + +func InitCodeServiceConn() { + var err error + codeServiceConn, err = grpc.Dial(conf.GrpcServerConf.ApsAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + logx.Errorf("grpc dial product service error: %v", err.Error()) + return + } +} + +func CloseCodeServiceConn() { + if codeServiceConn != nil { + codeServiceConn.Close() + } +} + +// GetCodeList +// +// @Tags 缂栫爜 +// @Summary 鑾峰彇缂栫爜鍒楄〃 +// @Produce application/json +// @Param object query request.GetCodeList true "鍙傛暟" +// @Success 200 {object} util.ResponseList{data=[]code.CodeStandard} +// +// @Router /api-wms/v1/code/getCodeList [get] +func (ca *CodeApi) GetCodeList(c *gin.Context) { + var params request.GetCodeList + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + params.CodeStandID = c.Query("codeStandID") + params.Name = c.Query("name") + params.Type = c.Query("type") + client := code.NewCodeServiceClient(codeServiceConn) + list, err := client.GetCodeList(ctx.GetCtx(), &code.GetCodeListRequest{ + Page: cast.ToInt32(params.Page), + PageSize: cast.ToInt32(params.PageSize), + CodeStandID: params.CodeStandID, + Name: params.Name, + Type: params.Type, + }) + if err != nil { + logx.Errorf("GetCodeList err: %v", err.Error()) + util.ResponseFormat(c, cd.RequestParamError, "浜у搧鍚嶇О涓嶈兘涓虹┖") + return + } + util.ResponseFormatList(c, cd.Success, list.List, int(list.Total)) +} + +// GetAutoCode +// +// @Tags 缂栫爜 +// @Summary 鑾峰彇鑷姩缂栫爜 +// @Produce application/json +// @Param object body code.CodeStandard true "鍙傛暟" +// @Success 200 {object} util.ResponseList{data=map[string]interface{}} +// +// @Router /api-wms/v1/code/getAutoCode [post] +func (ca *CodeApi) GetAutoCode(c *gin.Context) { + var params code.CodeStandard + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + var ( + id = 0 + err error + ) + switch params.Type { + case "鐗╂枡缂栫爜": + id, err = models.NewMaterialSearch().MaxAutoIncr() + default: + util.ResponseFormat(c, cd.RequestError, "缂栫爜瑙勫垯涓嶅瓨鍦�") + return + } + if err != nil { + util.ResponseFormat(c, cd.RequestError, "鑾峰彇鏈�澶у�煎け璐�") + return + } + m := make(map[string]interface{}) + autoCode := models.GetAutoCode(id, ¶ms) + m["id"] = autoCode + m["codeStandardID"] = params.ID + m["maxAutoIncr"] = id + 1 + ctx.OkWithDetailed(m) +} diff --git a/controllers/product_controller.go b/controllers/product_controller.go index a7dab0d..26b5918 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -15,7 +15,6 @@ "wms/models" "wms/pkg/logx" "wms/request" - "wms/utils" ) type ProductController struct { @@ -34,6 +33,10 @@ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") return } + if params.ID == "" { + util.ResponseFormat(c, code.RequestParamError, "浜у搧缂栫爜涓嶈兘涓虹┖") + return + } if params.Name == "" { util.ResponseFormat(c, code.RequestParamError, "浜у搧鍚嶇О涓嶈兘涓虹┖") return @@ -46,7 +49,7 @@ util.ResponseFormat(c, code.RequestParamError, "鍗曚綅涓嶈兘涓虹┖") return } - params.ID = utils.GetUUID() + //params.ID = utils.GetUUID() err := models.NewMaterialSearch().Create(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "浜у搧淇℃伅淇濆瓨澶辫触") diff --git a/docs/docs.go b/docs/docs.go index 794a765..76ee786 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -166,6 +166,112 @@ } } }, + "/api-wms/v1/code/getAutoCode": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "缂栫爜" + ], + "summary": "鑾峰彇鑷姩缂栫爜", + "parameters": [ + { + "description": "鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/code.CodeStandard" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "object", + "additionalProperties": true + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/code/getCodeList": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "缂栫爜" + ], + "summary": "鑾峰彇缂栫爜鍒楄〃", + "parameters": [ + { + "type": "string", + "name": "codeStandID", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "description": "椤电爜", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "姣忛〉澶у皬", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "type", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/code.CodeStandard" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/company/company": { "get": { "produces": [ @@ -2272,6 +2378,69 @@ } }, "definitions": { + "code.CodeAuto": { + "type": "object", + "properties": { + "AutoLength": { + "type": "integer" + }, + "Desc": { + "type": "string" + }, + "PrefixMethod": { + "type": "integer" + }, + "PrefixValue": { + "type": "string" + }, + "SuffixMethod": { + "type": "integer" + } + } + }, + "code.CodeRule": { + "type": "object", + "properties": { + "Desc": { + "type": "string" + }, + "Length": { + "type": "integer" + }, + "Name": { + "type": "string" + } + } + }, + "code.CodeStandard": { + "type": "object", + "properties": { + "AutoRule": { + "$ref": "#/definitions/code.CodeAuto" + }, + "ID": { + "type": "string" + }, + "List": { + "type": "array", + "items": { + "$ref": "#/definitions/code.CodeRule" + } + }, + "Method": { + "type": "integer" + }, + "Name": { + "type": "string" + }, + "Status": { + "type": "string" + }, + "Type": { + "type": "string" + } + } + }, "constvar.BaseOperationType": { "type": "integer", "enum": [ @@ -2494,6 +2663,24 @@ "Consumables", "Server", "StoredProduct" + ] + }, + "constvar.PurchaseType": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ], + "x-enum-comments": { + "PurchaseTypeEntrust": "濮斿", + "PurchaseTypeOutSource": "閲囪喘", + "PurchaseTypeSelf": "鑷埗" + }, + "x-enum-varnames": [ + "PurchaseTypeOutSource", + "PurchaseTypeSelf", + "PurchaseTypeEntrust" ] }, "constvar.ReservationMethod": { @@ -2749,6 +2936,9 @@ "$ref": "#/definitions/models.Attachment" } }, + "autoIncr": { + "type": "integer" + }, "barcode": { "description": "鏉$爜", "type": "string" @@ -2767,6 +2957,10 @@ }, "categoryName": { "description": "浜у搧绫诲埆鍚嶇О", + "type": "string" + }, + "codeStandardID": { + "description": "Explain string ` + "`" + `gorm:\"type:varchar(512);comment:缂栧彿璇存槑\" json:\"explain\"` + "`" + `", "type": "string" }, "companyId": { @@ -2829,7 +3023,7 @@ ] }, "isSale": { - "description": "PurchaseType constvar.PurchaseType ` + "`" + `gorm:\"type:int(11);comment:閲囪喘绫诲瀷\" json:\"purchaseType\"` + "`" + `", + "description": "鏄惁閿�鍞�", "type": "boolean" }, "makeAdvanceTime": { @@ -2841,7 +3035,7 @@ "type": "number" }, "minInventory": { - "description": "Explain string ` + "`" + `gorm:\"type:varchar(512);comment:缂栧彿璇存槑\" json:\"explain\"` + "`" + `\nCodeStandardID string ` + "`" + `gorm:\"type:varchar(191);comment:缂栫爜瑙勮寖ID\" json:\"codeStandardID\"` + "`" + `\nSpecs string ` + "`" + `gorm:\"type:varchar(191);comment:鐗╂枡瑙勬牸\" json:\"specs\"` + "`" + `\nType string ` + "`" + `gorm:\"type:varchar(191);comment:鐗╂枡鍨嬪彿\" json:\"type\"` + "`" + `", + "description": "鏈�灏忓簱瀛�", "type": "number" }, "minPurchaseAmount": { @@ -2858,6 +3052,9 @@ }, "name": { "description": "鐗╂枡鍚嶇О", + "type": "string" + }, + "note": { "type": "string" }, "orderAdvanceTime": { @@ -2900,6 +3097,9 @@ "description": "閲囪喘浠锋牸", "type": "number" }, + "purchaseType": { + "$ref": "#/definitions/constvar.PurchaseType" + }, "salePrice": { "description": "閿�鍞崟浠�", "type": "number" @@ -2912,12 +3112,18 @@ "description": "閿�鍞鏄�", "type": "string" }, + "specs": { + "type": "string" + }, "supplier": { "description": "FSource string ` + "`" + `gorm:\"type:varchar(191);comment:鐢熶骇杞﹂棿\" json:\"-\"` + "`" + `\nStatus constvar.MaterialStatus ` + "`" + `gorm:\"type:int(11);comment:鐘舵�乗" json:\"status\"` + "`" + `", "type": "string" }, "templateID": { - "description": "Note string ` + "`" + `gorm:\"type:varchar(1024);comment:澶囨敞\" json:\"note\"` + "`" + `", + "description": "妯℃澘ID", + "type": "string" + }, + "type": { "type": "string" }, "unit": { diff --git a/docs/swagger.json b/docs/swagger.json index 9cbcfea..fb080eb 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -154,6 +154,112 @@ } } }, + "/api-wms/v1/code/getAutoCode": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "缂栫爜" + ], + "summary": "鑾峰彇鑷姩缂栫爜", + "parameters": [ + { + "description": "鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/code.CodeStandard" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "object", + "additionalProperties": true + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/code/getCodeList": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "缂栫爜" + ], + "summary": "鑾峰彇缂栫爜鍒楄〃", + "parameters": [ + { + "type": "string", + "name": "codeStandID", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "description": "椤电爜", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "姣忛〉澶у皬", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "type", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/code.CodeStandard" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/company/company": { "get": { "produces": [ @@ -2260,6 +2366,69 @@ } }, "definitions": { + "code.CodeAuto": { + "type": "object", + "properties": { + "AutoLength": { + "type": "integer" + }, + "Desc": { + "type": "string" + }, + "PrefixMethod": { + "type": "integer" + }, + "PrefixValue": { + "type": "string" + }, + "SuffixMethod": { + "type": "integer" + } + } + }, + "code.CodeRule": { + "type": "object", + "properties": { + "Desc": { + "type": "string" + }, + "Length": { + "type": "integer" + }, + "Name": { + "type": "string" + } + } + }, + "code.CodeStandard": { + "type": "object", + "properties": { + "AutoRule": { + "$ref": "#/definitions/code.CodeAuto" + }, + "ID": { + "type": "string" + }, + "List": { + "type": "array", + "items": { + "$ref": "#/definitions/code.CodeRule" + } + }, + "Method": { + "type": "integer" + }, + "Name": { + "type": "string" + }, + "Status": { + "type": "string" + }, + "Type": { + "type": "string" + } + } + }, "constvar.BaseOperationType": { "type": "integer", "enum": [ @@ -2482,6 +2651,24 @@ "Consumables", "Server", "StoredProduct" + ] + }, + "constvar.PurchaseType": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ], + "x-enum-comments": { + "PurchaseTypeEntrust": "濮斿", + "PurchaseTypeOutSource": "閲囪喘", + "PurchaseTypeSelf": "鑷埗" + }, + "x-enum-varnames": [ + "PurchaseTypeOutSource", + "PurchaseTypeSelf", + "PurchaseTypeEntrust" ] }, "constvar.ReservationMethod": { @@ -2737,6 +2924,9 @@ "$ref": "#/definitions/models.Attachment" } }, + "autoIncr": { + "type": "integer" + }, "barcode": { "description": "鏉$爜", "type": "string" @@ -2755,6 +2945,10 @@ }, "categoryName": { "description": "浜у搧绫诲埆鍚嶇О", + "type": "string" + }, + "codeStandardID": { + "description": "Explain string `gorm:\"type:varchar(512);comment:缂栧彿璇存槑\" json:\"explain\"`", "type": "string" }, "companyId": { @@ -2817,7 +3011,7 @@ ] }, "isSale": { - "description": "PurchaseType constvar.PurchaseType `gorm:\"type:int(11);comment:閲囪喘绫诲瀷\" json:\"purchaseType\"`", + "description": "鏄惁閿�鍞�", "type": "boolean" }, "makeAdvanceTime": { @@ -2829,7 +3023,7 @@ "type": "number" }, "minInventory": { - "description": "Explain string `gorm:\"type:varchar(512);comment:缂栧彿璇存槑\" json:\"explain\"`\nCodeStandardID string `gorm:\"type:varchar(191);comment:缂栫爜瑙勮寖ID\" json:\"codeStandardID\"`\nSpecs string `gorm:\"type:varchar(191);comment:鐗╂枡瑙勬牸\" json:\"specs\"`\nType string `gorm:\"type:varchar(191);comment:鐗╂枡鍨嬪彿\" json:\"type\"`", + "description": "鏈�灏忓簱瀛�", "type": "number" }, "minPurchaseAmount": { @@ -2846,6 +3040,9 @@ }, "name": { "description": "鐗╂枡鍚嶇О", + "type": "string" + }, + "note": { "type": "string" }, "orderAdvanceTime": { @@ -2888,6 +3085,9 @@ "description": "閲囪喘浠锋牸", "type": "number" }, + "purchaseType": { + "$ref": "#/definitions/constvar.PurchaseType" + }, "salePrice": { "description": "閿�鍞崟浠�", "type": "number" @@ -2900,12 +3100,18 @@ "description": "閿�鍞鏄�", "type": "string" }, + "specs": { + "type": "string" + }, "supplier": { "description": "FSource string `gorm:\"type:varchar(191);comment:鐢熶骇杞﹂棿\" json:\"-\"`\nStatus constvar.MaterialStatus `gorm:\"type:int(11);comment:鐘舵�乗" json:\"status\"`", "type": "string" }, "templateID": { - "description": "Note string `gorm:\"type:varchar(1024);comment:澶囨敞\" json:\"note\"`", + "description": "妯℃澘ID", + "type": "string" + }, + "type": { "type": "string" }, "unit": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6754d44..37b8823 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,4 +1,45 @@ definitions: + code.CodeAuto: + properties: + AutoLength: + type: integer + Desc: + type: string + PrefixMethod: + type: integer + PrefixValue: + type: string + SuffixMethod: + type: integer + type: object + code.CodeRule: + properties: + Desc: + type: string + Length: + type: integer + Name: + type: string + type: object + code.CodeStandard: + properties: + AutoRule: + $ref: '#/definitions/code.CodeAuto' + ID: + type: string + List: + items: + $ref: '#/definitions/code.CodeRule' + type: array + Method: + type: integer + Name: + type: string + Status: + type: string + Type: + type: string + type: object constvar.BaseOperationType: enum: - 1 @@ -181,6 +222,20 @@ - Consumables - Server - StoredProduct + constvar.PurchaseType: + enum: + - 1 + - 2 + - 3 + type: integer + x-enum-comments: + PurchaseTypeEntrust: 濮斿 + PurchaseTypeOutSource: 閲囪喘 + PurchaseTypeSelf: 鑷埗 + x-enum-varnames: + - PurchaseTypeOutSource + - PurchaseTypeSelf + - PurchaseTypeEntrust constvar.ReservationMethod: enum: - 1 @@ -359,6 +414,8 @@ items: $ref: '#/definitions/models.Attachment' type: array + autoIncr: + type: integer barcode: description: 鏉$爜 type: string @@ -373,6 +430,10 @@ type: integer categoryName: description: 浜у搧绫诲埆鍚嶇О + type: string + codeStandardID: + description: Explain string `gorm:"type:varchar(512);comment:缂栧彿璇存槑" + json:"explain"` type: string companyId: description: 鍏徃id @@ -418,8 +479,7 @@ - $ref: '#/definitions/constvar.InvoicingStrategy' description: 寮�绁ㄧ瓥鐣� isSale: - description: PurchaseType constvar.PurchaseType `gorm:"type:int(11);comment:閲囪喘绫诲瀷" - json:"purchaseType"` + description: 鏄惁閿�鍞� type: boolean makeAdvanceTime: description: 鍒堕�犲墠缃椂闂�(澶�) @@ -428,11 +488,7 @@ description: 鏈�澶у簱瀛� type: number minInventory: - description: |- - 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"` + description: 鏈�灏忓簱瀛� type: number minPurchaseAmount: description: |- @@ -446,6 +502,8 @@ json:"materialType"` name: description: 鐗╂枡鍚嶇О + type: string + note: type: string orderAdvanceTime: description: 璁㈠崟鍑嗗澶╂暟(澶�) @@ -473,6 +531,8 @@ purchasePrice: description: 閲囪喘浠锋牸 type: number + purchaseType: + $ref: '#/definitions/constvar.PurchaseType' salePrice: description: 閿�鍞崟浠� type: number @@ -482,14 +542,17 @@ sellExplain: description: 閿�鍞鏄� type: string + specs: + type: string supplier: description: |- FSource string `gorm:"type:varchar(191);comment:鐢熶骇杞﹂棿" json:"-"` Status constvar.MaterialStatus `gorm:"type:int(11);comment:鐘舵��" json:"status"` type: string templateID: - description: Note string `gorm:"type:varchar(1024);comment:澶囨敞" - json:"note"` + description: 妯℃澘ID + type: string + type: type: string unit: description: LockAmount decimal.Decimal `gorm:"type:decimal(35,18);default:0;comment:閿佸畾鏁伴噺" @@ -1578,6 +1641,68 @@ summary: 涓婁紶闄勪欢 tags: - 闄勪欢绠$悊 + /api-wms/v1/code/getAutoCode: + post: + parameters: + - description: 鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/code.CodeStandard' + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + additionalProperties: true + type: object + type: object + summary: 鑾峰彇鑷姩缂栫爜 + tags: + - 缂栫爜 + /api-wms/v1/code/getCodeList: + get: + parameters: + - in: query + name: codeStandID + type: string + - in: query + name: name + type: string + - description: 椤电爜 + in: query + name: page + type: integer + - description: 姣忛〉澶у皬 + in: query + name: pageSize + type: integer + - in: query + name: type + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/code.CodeStandard' + type: array + type: object + summary: 鑾峰彇缂栫爜鍒楄〃 + tags: + - 缂栫爜 /api-wms/v1/company/company: get: parameters: diff --git a/main.go b/main.go index c6017aa..0fb90de 100644 --- a/main.go +++ b/main.go @@ -46,6 +46,7 @@ //鍚姩grpc瀹㈡埛绔� go controllers.InitInventoryOrderServiceConn() go controllers.InitProductInventoryServiceConn() + go controllers.InitCodeServiceConn() //鍚姩grpc鏈嶅姟 go func() { ln, err := net.Listen("tcp", ":"+conf.WebConf.GrpcPort) @@ -78,6 +79,7 @@ controllers.CloseInventoryOrderServiceConn() controllers.CloseProductInventoryServiceConn() + controllers.CloseCodeServiceConn() // 鍏抽棴HTTP鏈嶅姟鍣� if err := server.Shutdown(ctx); err != nil { logx.Infof("鏈嶅姟浼橀泤閫�鍑哄け璐�: %v", err) diff --git a/models/db.go b/models/db.go index e4c25d0..53e3be6 100644 --- a/models/db.go +++ b/models/db.go @@ -3,11 +3,14 @@ import ( "fmt" "gorm.io/gorm/schema" + "strconv" + "time" "wms/conf" "wms/extend/util" "wms/pkg/logx" "wms/pkg/mysqlx" "wms/pkg/snowflake" + "wms/proto/code" "gorm.io/gorm" ) @@ -55,6 +58,31 @@ return nil } +func GetAutoCode(id int, codeStandard *code.CodeStandard) string { + autoCode := "" + var prefixValue string + if codeStandard.AutoRule.PrefixMethod == 2 { // 鏉ユ簮鍗曟嵁 + prefixValue = "" + } else { // 鍥哄畾鍊� + prefixValue = codeStandard.AutoRule.PrefixValue + } + strMaxAutoIncr := strconv.Itoa(id + 1) + count := int(codeStandard.AutoRule.AutoLength) - len(strMaxAutoIncr) + for i := 0; i < count; i++ { + strMaxAutoIncr = "0" + strMaxAutoIncr + } + + var suffixValue string + if codeStandard.AutoRule.SuffixMethod == 2 { // 骞存湀鏃�+鑷闀� + suffixValue = fmt.Sprintf("%v%v", time.Now().Format("20060102"), strMaxAutoIncr) + } else { // 鑷闀� + suffixValue = strMaxAutoIncr + } + + autoCode = prefixValue + suffixValue + return autoCode +} + func Init() error { fmt.Printf("dsn=%v\n", conf.DbConf.Dsn) if err := mysqlx.Init(conf.DbConf, logx.GetLogger()); err != nil { diff --git a/models/material.go b/models/material.go index 69c33d0..fd2e51b 100644 --- a/models/material.go +++ b/models/material.go @@ -16,15 +16,15 @@ //MaterialType constvar.ProductType `gorm:"index;type:int(11);comment:鐗╂枡绫诲瀷(鏁板瓧)" json:"materialType"` Model constvar.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"` //鏁伴噺 + 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"` + 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:"templateID"` //妯℃澘ID //FSource string `gorm:"type:varchar(191);comment:鐢熶骇杞﹂棿" json:"-"` //Status constvar.MaterialStatus `gorm:"type:int(11);comment:鐘舵��" json:"status"` @@ -32,11 +32,11 @@ 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 constvar.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:"-"` + MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忛噰璐噺" json:"minPurchaseAmount"` //鏈�灏忛噰璐噺 + PurchaseType constvar.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"` //wms娣诲姞瀛楁 ProductType constvar.ProductType `gorm:"type:int(11);comment:浜у搧绫诲瀷" json:"productType"` //浜у搧绫诲瀷 InvoicingStrategy constvar.InvoicingStrategy `gorm:"type:int(11);comment:寮�绁ㄧ瓥鐣�" json:"invoicingStrategy"` //寮�绁ㄧ瓥鐣� @@ -487,9 +487,9 @@ // return fileName, nil //} -func (slf *MaterialSearch) MaxAutoIncr() (int64, error) { +func (slf *MaterialSearch) MaxAutoIncr() (int, error) { type Result struct { - Max int64 + Max int } var ( diff --git a/proto/code.proto b/proto/code.proto new file mode 100644 index 0000000..e394b43 --- /dev/null +++ b/proto/code.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; + +option go_package = "./code"; + +service codeService { + rpc GetCodeList(GetCodeListRequest) returns(GetCodeListResponse) {} +} + +message CodeStandard { + string ID = 1; + string Name = 2; + string Type = 3; + int32 Method = 4; + string Status = 5; + repeated CodeRule List = 6; + CodeAuto AutoRule = 7; +} + +message CodeRule { + string Name = 1; + int32 Length = 2; + string Desc = 3; +} + +message CodeAuto { + int32 PrefixMethod = 1; + string PrefixValue = 2; + int32 SuffixMethod = 3; + int32 AutoLength = 4; + string Desc = 5; +} + + + +message GetCodeListRequest{ + int32 page = 1; + int32 pageSize = 2; + string CodeStandID = 3; + string Name = 4; + string Type = 5; +} + +message GetCodeListResponse{ + int32 Code = 1; + string Msg = 2; + repeated CodeStandard List = 3; + int64 Total = 4; +} \ No newline at end of file diff --git a/proto/code/code.pb.go b/proto/code/code.pb.go new file mode 100644 index 0000000..adb2ca8 --- /dev/null +++ b/proto/code/code.pb.go @@ -0,0 +1,584 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v4.24.0 +// source: code.proto + +package code + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type CodeStandard struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` + Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"` + Type string `protobuf:"bytes,3,opt,name=Type,proto3" json:"Type,omitempty"` + Method int32 `protobuf:"varint,4,opt,name=Method,proto3" json:"Method,omitempty"` + Status string `protobuf:"bytes,5,opt,name=Status,proto3" json:"Status,omitempty"` + List []*CodeRule `protobuf:"bytes,6,rep,name=List,proto3" json:"List,omitempty"` + AutoRule *CodeAuto `protobuf:"bytes,7,opt,name=AutoRule,proto3" json:"AutoRule,omitempty"` +} + +func (x *CodeStandard) Reset() { + *x = CodeStandard{} + if protoimpl.UnsafeEnabled { + mi := &file_code_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CodeStandard) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CodeStandard) ProtoMessage() {} + +func (x *CodeStandard) ProtoReflect() protoreflect.Message { + mi := &file_code_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CodeStandard.ProtoReflect.Descriptor instead. +func (*CodeStandard) Descriptor() ([]byte, []int) { + return file_code_proto_rawDescGZIP(), []int{0} +} + +func (x *CodeStandard) GetID() string { + if x != nil { + return x.ID + } + return "" +} + +func (x *CodeStandard) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *CodeStandard) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *CodeStandard) GetMethod() int32 { + if x != nil { + return x.Method + } + return 0 +} + +func (x *CodeStandard) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *CodeStandard) GetList() []*CodeRule { + if x != nil { + return x.List + } + return nil +} + +func (x *CodeStandard) GetAutoRule() *CodeAuto { + if x != nil { + return x.AutoRule + } + return nil +} + +type CodeRule struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"` + Length int32 `protobuf:"varint,2,opt,name=Length,proto3" json:"Length,omitempty"` + Desc string `protobuf:"bytes,3,opt,name=Desc,proto3" json:"Desc,omitempty"` +} + +func (x *CodeRule) Reset() { + *x = CodeRule{} + if protoimpl.UnsafeEnabled { + mi := &file_code_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CodeRule) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CodeRule) ProtoMessage() {} + +func (x *CodeRule) ProtoReflect() protoreflect.Message { + mi := &file_code_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CodeRule.ProtoReflect.Descriptor instead. +func (*CodeRule) Descriptor() ([]byte, []int) { + return file_code_proto_rawDescGZIP(), []int{1} +} + +func (x *CodeRule) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *CodeRule) GetLength() int32 { + if x != nil { + return x.Length + } + return 0 +} + +func (x *CodeRule) GetDesc() string { + if x != nil { + return x.Desc + } + return "" +} + +type CodeAuto struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PrefixMethod int32 `protobuf:"varint,1,opt,name=PrefixMethod,proto3" json:"PrefixMethod,omitempty"` + PrefixValue string `protobuf:"bytes,2,opt,name=PrefixValue,proto3" json:"PrefixValue,omitempty"` + SuffixMethod int32 `protobuf:"varint,3,opt,name=SuffixMethod,proto3" json:"SuffixMethod,omitempty"` + AutoLength int32 `protobuf:"varint,4,opt,name=AutoLength,proto3" json:"AutoLength,omitempty"` + Desc string `protobuf:"bytes,5,opt,name=Desc,proto3" json:"Desc,omitempty"` +} + +func (x *CodeAuto) Reset() { + *x = CodeAuto{} + if protoimpl.UnsafeEnabled { + mi := &file_code_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CodeAuto) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CodeAuto) ProtoMessage() {} + +func (x *CodeAuto) ProtoReflect() protoreflect.Message { + mi := &file_code_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CodeAuto.ProtoReflect.Descriptor instead. +func (*CodeAuto) Descriptor() ([]byte, []int) { + return file_code_proto_rawDescGZIP(), []int{2} +} + +func (x *CodeAuto) GetPrefixMethod() int32 { + if x != nil { + return x.PrefixMethod + } + return 0 +} + +func (x *CodeAuto) GetPrefixValue() string { + if x != nil { + return x.PrefixValue + } + return "" +} + +func (x *CodeAuto) GetSuffixMethod() int32 { + if x != nil { + return x.SuffixMethod + } + return 0 +} + +func (x *CodeAuto) GetAutoLength() int32 { + if x != nil { + return x.AutoLength + } + return 0 +} + +func (x *CodeAuto) GetDesc() string { + if x != nil { + return x.Desc + } + return "" +} + +type GetCodeListRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` + PageSize int32 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` + CodeStandID string `protobuf:"bytes,3,opt,name=CodeStandID,proto3" json:"CodeStandID,omitempty"` + Name string `protobuf:"bytes,4,opt,name=Name,proto3" json:"Name,omitempty"` + Type string `protobuf:"bytes,5,opt,name=Type,proto3" json:"Type,omitempty"` +} + +func (x *GetCodeListRequest) Reset() { + *x = GetCodeListRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_code_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetCodeListRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetCodeListRequest) ProtoMessage() {} + +func (x *GetCodeListRequest) ProtoReflect() protoreflect.Message { + mi := &file_code_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetCodeListRequest.ProtoReflect.Descriptor instead. +func (*GetCodeListRequest) Descriptor() ([]byte, []int) { + return file_code_proto_rawDescGZIP(), []int{3} +} + +func (x *GetCodeListRequest) GetPage() int32 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *GetCodeListRequest) GetPageSize() int32 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetCodeListRequest) GetCodeStandID() string { + if x != nil { + return x.CodeStandID + } + return "" +} + +func (x *GetCodeListRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *GetCodeListRequest) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +type GetCodeListResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int32 `protobuf:"varint,1,opt,name=Code,proto3" json:"Code,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg,omitempty"` + List []*CodeStandard `protobuf:"bytes,3,rep,name=List,proto3" json:"List,omitempty"` + Total int64 `protobuf:"varint,4,opt,name=Total,proto3" json:"Total,omitempty"` +} + +func (x *GetCodeListResponse) Reset() { + *x = GetCodeListResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_code_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetCodeListResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetCodeListResponse) ProtoMessage() {} + +func (x *GetCodeListResponse) ProtoReflect() protoreflect.Message { + mi := &file_code_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetCodeListResponse.ProtoReflect.Descriptor instead. +func (*GetCodeListResponse) Descriptor() ([]byte, []int) { + return file_code_proto_rawDescGZIP(), []int{4} +} + +func (x *GetCodeListResponse) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetCodeListResponse) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +func (x *GetCodeListResponse) GetList() []*CodeStandard { + if x != nil { + return x.List + } + return nil +} + +func (x *GetCodeListResponse) GetTotal() int64 { + if x != nil { + return x.Total + } + return 0 +} + +var File_code_proto protoreflect.FileDescriptor + +var file_code_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbc, 0x01, 0x0a, + 0x0c, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x12, 0x0e, 0x0a, + 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x44, 0x12, 0x12, 0x0a, + 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x16, 0x0a, + 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1d, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x06, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x75, 0x6c, 0x65, 0x52, 0x04, + 0x4c, 0x69, 0x73, 0x74, 0x12, 0x25, 0x0a, 0x08, 0x41, 0x75, 0x74, 0x6f, 0x52, 0x75, 0x6c, 0x65, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x41, 0x75, 0x74, + 0x6f, 0x52, 0x08, 0x41, 0x75, 0x74, 0x6f, 0x52, 0x75, 0x6c, 0x65, 0x22, 0x4a, 0x0a, 0x08, 0x43, + 0x6f, 0x64, 0x65, 0x52, 0x75, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x4c, + 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x4c, 0x65, 0x6e, + 0x67, 0x74, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x65, 0x73, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x44, 0x65, 0x73, 0x63, 0x22, 0xa8, 0x01, 0x0a, 0x08, 0x43, 0x6f, 0x64, 0x65, + 0x41, 0x75, 0x74, 0x6f, 0x12, 0x22, 0x0a, 0x0c, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x4d, 0x65, + 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x50, 0x72, 0x65, 0x66, + 0x69, 0x78, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x50, 0x72, 0x65, 0x66, + 0x69, 0x78, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x50, + 0x72, 0x65, 0x66, 0x69, 0x78, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x53, 0x75, + 0x66, 0x66, 0x69, 0x78, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x0c, 0x53, 0x75, 0x66, 0x66, 0x69, 0x78, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1e, + 0x0a, 0x0a, 0x41, 0x75, 0x74, 0x6f, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x0a, 0x41, 0x75, 0x74, 0x6f, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x12, + 0x0a, 0x04, 0x44, 0x65, 0x73, 0x63, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x65, + 0x73, 0x63, 0x22, 0x8e, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x4c, 0x69, + 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x67, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, + 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x43, 0x6f, 0x64, + 0x65, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x43, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x49, 0x44, 0x12, 0x12, 0x0a, 0x04, 0x4e, + 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x54, + 0x79, 0x70, 0x65, 0x22, 0x74, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x4c, 0x69, + 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x10, + 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, + 0x12, 0x21, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, + 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x52, 0x04, 0x4c, + 0x69, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x05, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x32, 0x49, 0x0a, 0x0b, 0x63, 0x6f, 0x64, + 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3a, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x43, + 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x13, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x64, + 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x47, + 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_code_proto_rawDescOnce sync.Once + file_code_proto_rawDescData = file_code_proto_rawDesc +) + +func file_code_proto_rawDescGZIP() []byte { + file_code_proto_rawDescOnce.Do(func() { + file_code_proto_rawDescData = protoimpl.X.CompressGZIP(file_code_proto_rawDescData) + }) + return file_code_proto_rawDescData +} + +var file_code_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_code_proto_goTypes = []interface{}{ + (*CodeStandard)(nil), // 0: CodeStandard + (*CodeRule)(nil), // 1: CodeRule + (*CodeAuto)(nil), // 2: CodeAuto + (*GetCodeListRequest)(nil), // 3: GetCodeListRequest + (*GetCodeListResponse)(nil), // 4: GetCodeListResponse +} +var file_code_proto_depIdxs = []int32{ + 1, // 0: CodeStandard.List:type_name -> CodeRule + 2, // 1: CodeStandard.AutoRule:type_name -> CodeAuto + 0, // 2: GetCodeListResponse.List:type_name -> CodeStandard + 3, // 3: codeService.GetCodeList:input_type -> GetCodeListRequest + 4, // 4: codeService.GetCodeList:output_type -> GetCodeListResponse + 4, // [4:5] is the sub-list for method output_type + 3, // [3:4] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_code_proto_init() } +func file_code_proto_init() { + if File_code_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_code_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CodeStandard); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_code_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CodeRule); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_code_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CodeAuto); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_code_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetCodeListRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_code_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetCodeListResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_code_proto_rawDesc, + NumEnums: 0, + NumMessages: 5, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_code_proto_goTypes, + DependencyIndexes: file_code_proto_depIdxs, + MessageInfos: file_code_proto_msgTypes, + }.Build() + File_code_proto = out.File + file_code_proto_rawDesc = nil + file_code_proto_goTypes = nil + file_code_proto_depIdxs = nil +} diff --git a/proto/code/code_grpc.pb.go b/proto/code/code_grpc.pb.go new file mode 100644 index 0000000..eafdff8 --- /dev/null +++ b/proto/code/code_grpc.pb.go @@ -0,0 +1,101 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. + +package code + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// CodeServiceClient is the client API for CodeService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type CodeServiceClient interface { + GetCodeList(ctx context.Context, in *GetCodeListRequest, opts ...grpc.CallOption) (*GetCodeListResponse, error) +} + +type codeServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewCodeServiceClient(cc grpc.ClientConnInterface) CodeServiceClient { + return &codeServiceClient{cc} +} + +func (c *codeServiceClient) GetCodeList(ctx context.Context, in *GetCodeListRequest, opts ...grpc.CallOption) (*GetCodeListResponse, error) { + out := new(GetCodeListResponse) + err := c.cc.Invoke(ctx, "/codeService/GetCodeList", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// CodeServiceServer is the server API for CodeService service. +// All implementations must embed UnimplementedCodeServiceServer +// for forward compatibility +type CodeServiceServer interface { + GetCodeList(context.Context, *GetCodeListRequest) (*GetCodeListResponse, error) + mustEmbedUnimplementedCodeServiceServer() +} + +// UnimplementedCodeServiceServer must be embedded to have forward compatible implementations. +type UnimplementedCodeServiceServer struct { +} + +func (UnimplementedCodeServiceServer) GetCodeList(context.Context, *GetCodeListRequest) (*GetCodeListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCodeList not implemented") +} +func (UnimplementedCodeServiceServer) mustEmbedUnimplementedCodeServiceServer() {} + +// UnsafeCodeServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to CodeServiceServer will +// result in compilation errors. +type UnsafeCodeServiceServer interface { + mustEmbedUnimplementedCodeServiceServer() +} + +func RegisterCodeServiceServer(s grpc.ServiceRegistrar, srv CodeServiceServer) { + s.RegisterService(&CodeService_ServiceDesc, srv) +} + +func _CodeService_GetCodeList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetCodeListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CodeServiceServer).GetCodeList(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/codeService/GetCodeList", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CodeServiceServer).GetCodeList(ctx, req.(*GetCodeListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// CodeService_ServiceDesc is the grpc.ServiceDesc for CodeService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var CodeService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "codeService", + HandlerType: (*CodeServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetCodeList", + Handler: _CodeService_GetCodeList_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "code.proto", +} diff --git a/request/code_request.go b/request/code_request.go new file mode 100644 index 0000000..ecc73fa --- /dev/null +++ b/request/code_request.go @@ -0,0 +1,32 @@ +package request + +type GetCodeList struct { + PageInfo + CodeStandID string `json:"codeStandID"` + Name string `json:"name"` + Type string `json:"type"` +} + +type CodeStandard struct { + ID string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + Method int32 `json:"method"` + Status string `json:"status"` + List []*CodeRule `json:"list"` + AutoRule *CodeAuto `json:"autoRule"` +} + +type CodeRule struct { + Name string `json:"name"` + Length int32 `json:"length"` + Desc string `json:"desc"` +} + +type CodeAuto struct { + PrefixMethod int32 `json:"prefixMethod"` + PrefixValue string `json:"prefixValue"` + SuffixMethod int32 `json:"suffixMethod"` + AutoLength int32 `json:"autoLength"` + Desc string `json:"desc"` +} diff --git a/router/router.go b/router/router.go index 50e80d4..67aeb13 100644 --- a/router/router.go +++ b/router/router.go @@ -163,5 +163,12 @@ attachmentAPI.POST("uploadFiles", attachmentController.UploadFiles) //涓婁紶鏂囦欢 } + codeApiController := new(controllers.CodeApi) + codeApi := r.Group(urlPrefix + "/code") + { + codeApi.GET("getCodeList", codeApiController.GetCodeList) //鑾峰彇缂栫爜鍒楄〃 + codeApi.POST("getAutoCode", codeApiController.GetAutoCode) //鑾峰彇鑷姩缂栫爜 + } + return r } -- Gitblit v1.8.0