新增wms系统设置表,保存库存结算时间点,给前端提供查询和保存配置接口
1个文件已删除
4个文件已添加
8个文件已修改
896 ■■■■■ 已修改文件
conf/config.yaml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/const.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/system_config.go 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 163 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 163 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
example.xlsx 补丁 | 查看 | 原始文档 | blame | 历史
models/db.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/system_config.go 244 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/config_type.go 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/system_config.go 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
task/month_stats.go 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
constvar/const.go
@@ -316,3 +316,9 @@
)
const DoMonthStatsToken = "Eoh2ZAUJjtbmu0TBkc3dq7MPCpL4riw5NVxOfgXYlKvHF6sR"
type SystemConfigType int
const (
    SystemConfigTypeInventoryCutOffPoint SystemConfigType = 1 //库存结算时间点
)
controllers/system_config.go
New file
@@ -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, "参数解析失败,数据类型错误")
        return
    }
    if err := structx.AssignTo(reqParams, &params); 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(&params); err != nil {
            logx.Errorf("SystemConfig create err: %v", err)
            util.ResponseFormat(c, code.SaveFail, "插入失败")
            return
        }
    } else {
        if err := models.NewSystemConfigSearch().SetID(params.ID).Update(&params); 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(&params); 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)
}
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": {
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": {
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:
example.xlsx
Binary files differ
models/db.go
@@ -122,6 +122,7 @@
        MonthStats{},
        Attribute{},
        AttributeValue{},
        SystemConfig{},
    )
    return err
}
models/system_config.go
New file
@@ -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
}
request/config_type.go
New file
@@ -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 每月库存结算时间点
}
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
}
service/system_config.go
New file
@@ -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("库存结算时间点日期不正确,应在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)
}
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)