From 0579d8ed7f53a1883dde8b6cb9df258370348e1e Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 27 六月 2024 18:23:15 +0800 Subject: [PATCH] 新增wms系统设置表,保存库存结算时间点,给前端提供查询和保存配置接口 --- models/system_config.go | 244 ++++++++++++++++ request/config_type.go | 14 controllers/system_config.go | 83 +++++ docs/swagger.yaml | 103 ++++++ service/system_config.go | 73 ++++ docs/docs.go | 163 ++++++++++ conf/config.yaml | 4 docs/swagger.json | 163 ++++++++++ router/router.go | 8 constvar/const.go | 6 /dev/null | 0 task/month_stats.go | 34 - models/db.go | 1 13 files changed, 857 insertions(+), 39 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index 35102d0..d608c0d 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -27,8 +27,8 @@ storePath: uploads/file grpcServer: apsAddr: 127.0.0.1:9091 - crmAddr: 192.168.20.119:9092 - srmAddr: 192.168.20.119:9093 + crmAddr: 127.0.0.1:9092 + srmAddr: 127.0.0.1:9093 dingTalk: alarmKey: SEC31ccce95daf26763ab54575bd4cac156f22ed0a42f3e27d3edd06edb77b3d221 alarmUrl: https://oapi.dingtalk.com/robot/send?access_token=c6023d2c55058b86d59290ad205eff86a8c681a7807f76c569f91434663081fa diff --git a/constvar/const.go b/constvar/const.go index c128d57..b965525 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -316,3 +316,9 @@ ) const DoMonthStatsToken = "Eoh2ZAUJjtbmu0TBkc3dq7MPCpL4riw5NVxOfgXYlKvHF6sR" + +type SystemConfigType int + +const ( + SystemConfigTypeInventoryCutOffPoint SystemConfigType = 1 //搴撳瓨缁撶畻鏃堕棿鐐� +) diff --git a/controllers/system_config.go b/controllers/system_config.go new file mode 100644 index 0000000..60b2523 --- /dev/null +++ b/controllers/system_config.go @@ -0,0 +1,83 @@ +package controllers + +import ( + "github.com/gin-gonic/gin" + "wms/extend/code" + "wms/extend/util" + "wms/models" + "wms/pkg/logx" + "wms/pkg/structx" + "wms/request" + "wms/service" +) + +type SystemConfigController struct{} + +// SaveConfig +// @Tags 绯荤粺璁剧疆 +// @Summary 淇濆瓨绯荤粺璁剧疆 +// @Produce application/json +// @Param object body request.SystemConfig true "绯荤粺璁剧疆淇℃伅"' +// @Param Authorization header string true "token" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/systemConfig/save [post] +func (slf SystemConfigController) SaveConfig(c *gin.Context) { + var reqParams request.SystemConfig + var params models.SystemConfig + if err := c.BindJSON(&reqParams); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + if err := structx.AssignTo(reqParams, ¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲閿欒") + return + } + + srv := service.NewSystemConfigService() + + if err := srv.ParamsCheck(params); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + + if params.Id == 0 { + if err := models.NewSystemConfigSearch().Create(¶ms); err != nil { + logx.Errorf("SystemConfig create err: %v", err) + util.ResponseFormat(c, code.SaveFail, "鎻掑叆澶辫触") + return + } + } else { + if err := models.NewSystemConfigSearch().SetID(params.ID).Update(¶ms); err != nil { + logx.Errorf("SystemConfig update err: %v", err) + util.ResponseFormat(c, code.SaveFail, "鎻掑叆澶辫触") + return + } + } + + util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛") +} + +// GetSystemConfig +// @Tags 绯荤粺璁剧疆 +// @Summary 鏍规嵁璁剧疆绫诲瀷鏌ヨ绯荤粺璁剧疆 +// @Produce application/json +// @Param object query request.GetSystemConfig true "鏌ヨ鍙傛暟" +// @Param Authorization header string true "token" +// @Success 200 {object} util.Response{data=models.SystemConfig} "鎴愬姛" +// @Router /api-wms/v1/systemConfig/get [get] +func (slf SystemConfigController) GetSystemConfig(c *gin.Context) { + var params request.GetSystemConfig + if err := c.ShouldBindQuery(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + + if params.ConfigType == 0 { + util.ResponseFormat(c, code.RequestParamError, "閰嶇疆绫诲瀷缂哄け") + return + } + + config, _ := models.NewSystemConfigSearch().SetConfigType(params.ConfigType).First() + + util.ResponseFormat(c, code.Success, config) +} diff --git a/docs/docs.go b/docs/docs.go index 4ef8f28..3297b01 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -3273,6 +3273,99 @@ } } }, + "/api-wms/v1/systemConfig/get": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "绯荤粺璁剧疆" + ], + "summary": "鏍规嵁璁剧疆绫诲瀷鏌ヨ绯荤粺璁剧疆", + "parameters": [ + { + "enum": [ + 1 + ], + "type": "integer", + "x-enum-comments": { + "SystemConfigTypeInventoryCutOffPoint": "搴撳瓨缁撶畻鏃堕棿鐐�" + }, + "x-enum-varnames": [ + "SystemConfigTypeInventoryCutOffPoint" + ], + "description": "1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐�", + "name": "configType", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.SystemConfig" + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/systemConfig/save": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "绯荤粺璁剧疆" + ], + "summary": "淇濆瓨绯荤粺璁剧疆", + "parameters": [ + { + "description": "绯荤粺璁剧疆淇℃伅", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SystemConfig" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-wms/v1/warehouse/getWarehouseDetails/{id}": { "get": { "produces": [ @@ -3848,6 +3941,18 @@ "RuleType_ProductCategory" ] }, + "constvar.SystemConfigType": { + "type": "integer", + "enum": [ + 1 + ], + "x-enum-comments": { + "SystemConfigTypeInventoryCutOffPoint": "搴撳瓨缁撶畻鏃堕棿鐐�" + }, + "x-enum-varnames": [ + "SystemConfigTypeInventoryCutOffPoint" + ] + }, "constvar.WhetherType": { "type": "integer", "enum": [ @@ -4198,10 +4303,6 @@ "type": "integer" }, "barCode": { - "description": "鍒涘缓浜�", - "type": "string" - }, - "barcode": { "description": "鏉$爜", "type": "string" }, @@ -4982,6 +5083,36 @@ "type": "string" }, "updateTime": { + "type": "string" + } + } + }, + "models.SystemConfig": { + "type": "object", + "properties": { + "configType": { + "description": "姣忔湀搴撳瓨缁撶畻鏃堕棿鐐�", + "allOf": [ + { + "$ref": "#/definitions/constvar.SystemConfigType" + } + ] + }, + "createTime": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "description": "璁剧疆鍚嶇О", + "type": "string" + }, + "updateTime": { + "type": "string" + }, + "val": { + "description": "璁剧疆鍊�", "type": "string" } } @@ -5926,6 +6057,30 @@ } } }, + "request.SystemConfig": { + "type": "object", + "properties": { + "ID": { + "type": "integer" + }, + "configType": { + "description": "1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐�", + "allOf": [ + { + "$ref": "#/definitions/constvar.SystemConfigType" + } + ] + }, + "name": { + "description": "璁剧疆鍚嶇О", + "type": "string" + }, + "val": { + "description": "璁剧疆鍊�", + "type": "string" + } + } + }, "request.UnitDict": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index ec65698..7bd351e 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -3262,6 +3262,99 @@ } } }, + "/api-wms/v1/systemConfig/get": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "绯荤粺璁剧疆" + ], + "summary": "鏍规嵁璁剧疆绫诲瀷鏌ヨ绯荤粺璁剧疆", + "parameters": [ + { + "enum": [ + 1 + ], + "type": "integer", + "x-enum-comments": { + "SystemConfigTypeInventoryCutOffPoint": "搴撳瓨缁撶畻鏃堕棿鐐�" + }, + "x-enum-varnames": [ + "SystemConfigTypeInventoryCutOffPoint" + ], + "description": "1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐�", + "name": "configType", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.SystemConfig" + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/systemConfig/save": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "绯荤粺璁剧疆" + ], + "summary": "淇濆瓨绯荤粺璁剧疆", + "parameters": [ + { + "description": "绯荤粺璁剧疆淇℃伅", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SystemConfig" + } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-wms/v1/warehouse/getWarehouseDetails/{id}": { "get": { "produces": [ @@ -3837,6 +3930,18 @@ "RuleType_ProductCategory" ] }, + "constvar.SystemConfigType": { + "type": "integer", + "enum": [ + 1 + ], + "x-enum-comments": { + "SystemConfigTypeInventoryCutOffPoint": "搴撳瓨缁撶畻鏃堕棿鐐�" + }, + "x-enum-varnames": [ + "SystemConfigTypeInventoryCutOffPoint" + ] + }, "constvar.WhetherType": { "type": "integer", "enum": [ @@ -4187,10 +4292,6 @@ "type": "integer" }, "barCode": { - "description": "鍒涘缓浜�", - "type": "string" - }, - "barcode": { "description": "鏉$爜", "type": "string" }, @@ -4971,6 +5072,36 @@ "type": "string" }, "updateTime": { + "type": "string" + } + } + }, + "models.SystemConfig": { + "type": "object", + "properties": { + "configType": { + "description": "姣忔湀搴撳瓨缁撶畻鏃堕棿鐐�", + "allOf": [ + { + "$ref": "#/definitions/constvar.SystemConfigType" + } + ] + }, + "createTime": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "description": "璁剧疆鍚嶇О", + "type": "string" + }, + "updateTime": { + "type": "string" + }, + "val": { + "description": "璁剧疆鍊�", "type": "string" } } @@ -5915,6 +6046,30 @@ } } }, + "request.SystemConfig": { + "type": "object", + "properties": { + "ID": { + "type": "integer" + }, + "configType": { + "description": "1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐�", + "allOf": [ + { + "$ref": "#/definitions/constvar.SystemConfigType" + } + ] + }, + "name": { + "description": "璁剧疆鍚嶇О", + "type": "string" + }, + "val": { + "description": "璁剧疆鍊�", + "type": "string" + } + } + }, "request.UnitDict": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index d6f01be..3262537 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -308,6 +308,14 @@ x-enum-varnames: - RuleType_Product - RuleType_ProductCategory + constvar.SystemConfigType: + enum: + - 1 + type: integer + x-enum-comments: + SystemConfigTypeInventoryCutOffPoint: 搴撳瓨缁撶畻鏃堕棿鐐� + x-enum-varnames: + - SystemConfigTypeInventoryCutOffPoint constvar.WhetherType: enum: - 1 @@ -552,9 +560,6 @@ autoIncr: type: integer barCode: - description: 鍒涘缓浜� - type: string - barcode: description: 鏉$爜 type: string buyExplain: @@ -1099,6 +1104,25 @@ description: 鍗曚綅 type: string updateTime: + type: string + type: object + models.SystemConfig: + properties: + configType: + allOf: + - $ref: '#/definitions/constvar.SystemConfigType' + description: 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐� + createTime: + type: string + id: + type: integer + name: + description: 璁剧疆鍚嶇О + type: string + updateTime: + type: string + val: + description: 璁剧疆鍊� type: string type: object models.UnitDict: @@ -1755,6 +1779,21 @@ items: $ref: '#/definitions/request.UnitDict' type: array + type: object + request.SystemConfig: + properties: + ID: + type: integer + configType: + allOf: + - $ref: '#/definitions/constvar.SystemConfigType' + description: 1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐� + name: + description: 璁剧疆鍚嶇О + type: string + val: + description: 璁剧疆鍊� + type: string type: object request.UnitDict: properties: @@ -4146,6 +4185,64 @@ summary: 鏇存柊閲嶈璐ц鍒� tags: - 閲嶈璐ц鍒� + /api-wms/v1/systemConfig/get: + get: + parameters: + - description: 1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐� + enum: + - 1 + in: query + name: configType + required: true + type: integer + x-enum-comments: + SystemConfigTypeInventoryCutOffPoint: 搴撳瓨缁撶畻鏃堕棿鐐� + x-enum-varnames: + - SystemConfigTypeInventoryCutOffPoint + - description: token + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.Response' + - properties: + data: + $ref: '#/definitions/models.SystemConfig' + type: object + summary: 鏍规嵁璁剧疆绫诲瀷鏌ヨ绯荤粺璁剧疆 + tags: + - 绯荤粺璁剧疆 + /api-wms/v1/systemConfig/save: + post: + parameters: + - description: 绯荤粺璁剧疆淇℃伅 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.SystemConfig' + - description: token + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 淇濆瓨绯荤粺璁剧疆 + tags: + - 绯荤粺璁剧疆 /api-wms/v1/warehouse/getWarehouseDetails/{id}: get: parameters: diff --git a/example.xlsx b/example.xlsx deleted file mode 100644 index 5e4b104..0000000 --- a/example.xlsx +++ /dev/null Binary files differ diff --git a/models/db.go b/models/db.go index de0c2d2..4708383 100644 --- a/models/db.go +++ b/models/db.go @@ -122,6 +122,7 @@ MonthStats{}, Attribute{}, AttributeValue{}, + SystemConfig{}, ) return err } diff --git a/models/system_config.go b/models/system_config.go new file mode 100644 index 0000000..e36d115 --- /dev/null +++ b/models/system_config.go @@ -0,0 +1,244 @@ +package models + +import ( + "fmt" + "gorm.io/gorm" + "wms/constvar" + "wms/pkg/mysqlx" +) + +type ( + // SystemConfig 绯荤粺璁剧疆 + SystemConfig struct { + WmsModel + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ConfigType constvar.SystemConfigType `json:"configType" gorm:"type:int;not null"` //姣忔湀搴撳瓨缁撶畻鏃堕棿鐐� + Name string `json:"name" gorm:"index;type:varchar(255);not null;default:'';comment:璁剧疆鍚�"` //璁剧疆鍚嶇О + Val string `json:"val" gorm:"index;type:varchar(255);not null;comment:璁剧疆鍊�"` //璁剧疆鍊� + } + + SystemConfigSearch struct { + SystemConfig + Order string + PageNum int + PageSize int + Keyword string + Orm *gorm.DB + } +) + +func (slf *SystemConfig) TableName() string { + return "wms_system_config" +} + +func NewSystemConfigSearch() *SystemConfigSearch { + return &SystemConfigSearch{Orm: mysqlx.GetDB()} +} + +func (slf *SystemConfigSearch) SetOrm(tx *gorm.DB) *SystemConfigSearch { + slf.Orm = tx + return slf +} + +func (slf *SystemConfigSearch) SetPage(page, size int) *SystemConfigSearch { + slf.PageNum, slf.PageSize = page, size + return slf +} + +func (slf *SystemConfigSearch) SetOrder(order string) *SystemConfigSearch { + slf.Order = order + return slf +} + +func (slf *SystemConfigSearch) SetConfigType(configType constvar.SystemConfigType) *SystemConfigSearch { + slf.ConfigType = configType + return slf +} + +func (slf *SystemConfigSearch) SetID(id uint) *SystemConfigSearch { + slf.ID = id + return slf +} + +func (slf *SystemConfigSearch) SetValue(name string) *SystemConfigSearch { + slf.Name = name + return slf +} + +func (slf *SystemConfigSearch) SetKeyword(keyword string) *SystemConfigSearch { + slf.Keyword = keyword + return slf +} + +func (slf *SystemConfigSearch) build() *gorm.DB { + var db = slf.Orm.Table(slf.TableName()) + + if slf.ID != 0 { + db = db.Where("id = ?", slf.ID) + } + + if slf.Order != "" { + db = db.Order(slf.Order) + } + + if slf.Keyword != "" { + db = db.Where("name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) + } + if slf.Name != "" { + db = db.Where("name = ?", slf.Name) + } + + if slf.ConfigType != 0 { + db = db.Where("config_type = ?", slf.ConfigType) + } + + return db +} + +// Create 鍗曟潯鎻掑叆 +func (slf *SystemConfigSearch) Create(record *SystemConfig) error { + var db = slf.build() + + if err := db.Create(record).Error; err != nil { + return err + } + + return nil +} + +// CreateBatch 鎵归噺鎻掑叆 +func (slf *SystemConfigSearch) CreateBatch(records []*SystemConfig) error { + var db = slf.build() + + if err := db.Create(&records).Error; err != nil { + return fmt.Errorf("create batch err: %v, records: %+v", err, records) + } + + return nil +} + +func (slf *SystemConfigSearch) Update(record *SystemConfig) error { + var db = slf.build() + + if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { + return fmt.Errorf("save err: %v, record: %+v", err, record) + } + + return nil +} + +func (slf *SystemConfigSearch) UpdateByMap(upMap map[string]interface{}) error { + var ( + db = slf.build() + ) + + if err := db.Updates(upMap).Error; err != nil { + return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) + } + + return nil +} + +func (slf *SystemConfigSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error { + var ( + db = slf.Orm.Table(slf.TableName()).Where(query, args...) + ) + + if err := db.Updates(upMap).Error; err != nil { + return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap) + } + + return nil +} + +func (slf *SystemConfigSearch) Delete() error { + var db = slf.build() + return db.Delete(&SystemConfig{}).Error +} + +func (slf *SystemConfigSearch) First() (*SystemConfig, error) { + var ( + record = new(SystemConfig) + db = slf.build() + ) + + if err := db.First(record).Error; err != nil { + return record, err + } + + return record, nil +} + +func (slf *SystemConfigSearch) Find() ([]*SystemConfig, int64, error) { + var ( + records = make([]*SystemConfig, 0) + total int64 + db = slf.build() + ) + + if err := db.Count(&total).Error; err != nil { + return records, total, fmt.Errorf("find count err: %v", err) + } + if slf.PageNum*slf.PageSize > 0 { + db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) + } + if err := db.Find(&records).Error; err != nil { + return records, total, fmt.Errorf("find records err: %v", err) + } + + return records, total, nil +} + +func (slf *SystemConfigSearch) FindNotTotal() ([]*SystemConfig, error) { + var ( + records = make([]*SystemConfig, 0) + db = slf.build() + ) + + if slf.PageNum*slf.PageSize > 0 { + db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) + } + if err := db.Find(&records).Error; err != nil { + return records, fmt.Errorf("find records err: %v", err) + } + + return records, nil +} + +// FindByQuery 鎸囧畾鏉′欢鏌ヨ. +func (slf *SystemConfigSearch) FindByQuery(query string, args []interface{}) ([]*SystemConfig, int64, error) { + var ( + records = make([]*SystemConfig, 0) + total int64 + db = slf.Orm.Table(slf.TableName()).Where(query, args...) + ) + + if err := db.Count(&total).Error; err != nil { + return records, total, fmt.Errorf("find by query count err: %v", err) + } + if slf.PageNum*slf.PageSize > 0 { + db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) + } + if err := db.Find(&records).Error; err != nil { + return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) + } + + return records, total, nil +} + +// FindByQueryNotTotal 鎸囧畾鏉′欢鏌ヨ&涓嶆煡璇㈡�绘潯鏁�. +func (slf *SystemConfigSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*SystemConfig, error) { + var ( + records = make([]*SystemConfig, 0) + db = slf.Orm.Table(slf.TableName()).Where(query, args...) + ) + + if slf.PageNum*slf.PageSize > 0 { + db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) + } + if err := db.Find(&records).Error; err != nil { + return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) + } + + return records, nil +} diff --git a/request/config_type.go b/request/config_type.go new file mode 100644 index 0000000..f0430d7 --- /dev/null +++ b/request/config_type.go @@ -0,0 +1,14 @@ +package request + +import "wms/constvar" + +type SystemConfig struct { + ID uint `json:"ID"` + ConfigType constvar.SystemConfigType `json:"configType" gorm:"type:int;not null"` //1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐� + Name string `json:"name" gorm:"index;type:varchar(255);not null;default:'';comment:璁剧疆鍚�"` //璁剧疆鍚嶇О + Val string `json:"val" gorm:"index;type:varchar(255);not null;comment:璁剧疆鍊�"` //璁剧疆鍊� +} + +type GetSystemConfig struct { + ConfigType constvar.SystemConfigType `form:"configType" binding:"required"` //1 姣忔湀搴撳瓨缁撶畻鏃堕棿鐐� +} diff --git a/router/router.go b/router/router.go index 95f4a3f..d336bb3 100644 --- a/router/router.go +++ b/router/router.go @@ -214,5 +214,13 @@ attributeValueAPI.GET("primary/:id", attributeValueController.PrimaryAttributeValue) //鍒犻櫎 } + //绯荤粺閰嶇疆 + sysCfgCtl := new(controllers.SystemConfigController) + sysCfgApi := r.Group(urlPrefix + "/systemConfig") + { + sysCfgApi.POST("save", sysCfgCtl.SaveConfig) //淇濆瓨绯荤粺璁剧疆 + sysCfgApi.GET("get", sysCfgCtl.GetSystemConfig) //鑾峰彇绯荤粺閰嶇疆 + } + return r } diff --git a/service/system_config.go b/service/system_config.go new file mode 100644 index 0000000..daab2d6 --- /dev/null +++ b/service/system_config.go @@ -0,0 +1,73 @@ +package service + +import ( + "errors" + "github.com/spf13/cast" + "gorm.io/gorm" + "strings" + "time" + "wms/constvar" + "wms/models" +) + +type SystemConfigService struct { +} + +func NewSystemConfigService() *SystemConfigService { + return &SystemConfigService{} +} + +func (slf SystemConfigService) ParamsCheck(params models.SystemConfig) (err error) { + var oldRecord *models.SystemConfig + if params.Id != 0 { + oldRecord, err = models.NewSystemConfigSearch().SetID(params.ID).First() + if err == gorm.ErrRecordNotFound { + return errors.New("閰嶇疆涓嶅瓨鍦�") + } + } + if oldRecord == nil || params.ConfigType != oldRecord.ConfigType { + _, err = models.NewSystemConfigSearch().SetConfigType(params.ConfigType).First() + if err != gorm.ErrRecordNotFound { + return errors.New("閰嶇疆椤归噸澶�") + } + } + + switch params.ConfigType { + case constvar.SystemConfigTypeInventoryCutOffPoint: + _, _, err = slf.CheckInventoryCutOffPoint(params.Val) + if err != nil { + return err + } + } + + return nil +} + +func (slf SystemConfigService) CheckInventoryCutOffPoint(val string) (day int, timeStr string, err error) { + if !strings.Contains(val, "-") { + err = errors.New("搴撳瓨缁撶畻鏃堕棿鐐瑰簲璇ョ敤鍒嗛殧绗�'-'鍒嗛殧鏃ユ湡鍜屾椂闂�") + return + } + arr := strings.Split(val, "-") + if len(arr) != 2 { + err = errors.New("搴撳瓨缁撶畻鏃堕棿鐐瑰簲璇ョ敤鍒嗛殧绗�'-'鍒嗛殧鏃ユ湡鍜屾椂闂达紝涓斿彧鑳芥湁涓�涓垎闅旂") + return + } + day = cast.ToInt(arr[0]) + if day < 0 || day > 28 { + err = errors.New("搴撳瓨缁撶畻鏃堕棿鐐规棩鏈熶笉姝g‘锛屽簲鍦�1~28涔嬮棿") + return + } + timeStr = arr[1] + _, err = time.ParseInLocation("15:04", arr[1], time.Local) + return +} + +func (slf SystemConfigService) GetInventoryCutOffPoint() (day int, timeStr string, err error) { + config, err := models.NewSystemConfigSearch().SetConfigType(constvar.SystemConfigTypeInventoryCutOffPoint).First() + if err != nil { + err = errors.New("搴撳瓨缁撶畻鏃堕棿鐐规湭閰嶇疆") + return + } + return slf.CheckInventoryCutOffPoint(config.Val) +} diff --git a/task/month_stats.go b/task/month_stats.go index 6d82bb4..a6b2669 100644 --- a/task/month_stats.go +++ b/task/month_stats.go @@ -103,35 +103,17 @@ moreValueArr := make([]models.UnitItems, 0, len(product.MoreUnitList)) inputMoreValueArr := make([]models.UnitItems, 0, len(product.MoreUnitList)) outputMoreValueArr := make([]models.UnitItems, 0, len(product.MoreUnitList)) - for _, unitItem := range product.MoreUnitList { - if !amount.IsZero() { - moreValueArr = append(moreValueArr, models.UnitItems{ - Amount: amount.Mul(unitItem.Amount), - Unit: unitItem.Unit, - Floating: unitItem.Floating, - }) - } + if !amount.IsZero() { + moreValueArr = service.CreateMoreUnit(amount, product.MoreUnitList) + } + if !inputMap[productId].IsZero() { + inputMoreValueArr = service.CreateMoreUnit(inputMap[productId], product.MoreUnitList) + } - if !inputMap[productId].IsZero() { - inputMoreValueArr = append(inputMoreValueArr, models.UnitItems{ - Amount: inputMap[productId].Mul(unitItem.Amount), - Unit: unitItem.Unit, - Floating: unitItem.Floating, - }) - } - - if !outputMap[productId].IsZero() { - outputMoreValueArr = append(outputMoreValueArr, models.UnitItems{ - Amount: outputMap[productId].Mul(unitItem.Amount), - Unit: unitItem.Unit, - Floating: unitItem.Floating, - }) - } + if !outputMap[productId].IsZero() { + outputMoreValueArr = service.CreateMoreUnit(outputMap[productId], product.MoreUnitList) } bys, _ := json.Marshal(moreValueArr) - if len(moreValueArr) > 0 { - fmt.Println(moreValueArr) - } moreUnits = string(bys) bys, _ = json.Marshal(inputMoreValueArr) inputMoreUnits = string(bys) -- Gitblit v1.8.0