| | |
| | | import ( |
| | | "context" |
| | | "errors" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | |
| | | return |
| | | } |
| | | |
| | | autoCode, _ := getAutoCode(params.Type) |
| | | record := models.MiniDict{ |
| | | Type: params.Type, |
| | | Code: autoCode, |
| | | Name: params.Name, |
| | | Value: params.Value, |
| | | IsDefault: params.IsDefault, |
| | |
| | | |
| | | record := models.MiniDict{ |
| | | Type: params.Type, |
| | | Code: params.Code, |
| | | Name: params.Name, |
| | | Value: params.Value, |
| | | IsDefault: params.IsDefault, |
| | |
| | | return |
| | | } |
| | | |
| | | //if !params.Type.Valid() { |
| | | // util.ResponseFormat(c, code.RequestParamError, "字典类型错误") |
| | | // return |
| | | //} |
| | | dictSearch := models.NewMiniDictSearch() |
| | | if params.Type.Valid() { |
| | | dictSearch.SetType(params.Type) |
| | | } |
| | | |
| | | list, total, err := dictSearch.Find() |
| | | list, total, err := models.NewMiniDictSearch().SetKeyword(params.Keyword).SetType(params.Type).Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, list, int(total)) |
| | | } |
| | | |
| | | // GetSilkDictList |
| | | // |
| | | // @Tags 数据字典 |
| | | // @Summary 获取庄口列表 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param type path string true "字典类型" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.SilkDict} "成功" |
| | | // @Router /api-wms/v1/dict/getSilkDictList/{type} [get] |
| | | func (slf DictController) GetSilkDictList(c *gin.Context) { |
| | | |
| | | dictType, err := strconv.Atoi(c.Param("type")) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "请传入正确的字典类型") |
| | | return |
| | | } |
| | | |
| | | list, err := models.NewSilkDictSearch().SetDictType(models.SilkDictType(dictType)).FindAll() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, list) |
| | | } |
| | | |
| | | // GetUserList |
| | |
| | | } |
| | | util.ResponseFormat(c, code.Success, list.List) |
| | | } |
| | | |
| | | // GetAutoCode 获取字典自动编码 |
| | | func getAutoCode(dictType constvar.MiniDictType) (string, error) { |
| | | |
| | | var prefix string |
| | | switch constvar.MiniDictType(dictType) { |
| | | case constvar.StorageType: |
| | | prefix = "IN0" |
| | | case constvar.StockoutType: |
| | | prefix = "OUT" |
| | | case constvar.TransferType: |
| | | prefix = "TF0" |
| | | case constvar.TakeStockType: |
| | | prefix = "TS0" |
| | | case constvar.DisuseType: |
| | | prefix = "DIS" |
| | | case constvar.ProductSource: |
| | | prefix = "PS0" |
| | | default: |
| | | return "", errors.New("编码规则不存在") |
| | | } |
| | | id, err := models.NewMiniDictSearch().SetType(constvar.MiniDictType(dictType)).MaxAutoIncr() |
| | | if err != nil { |
| | | return "", errors.New("获取最大值失败") |
| | | } |
| | | |
| | | strMaxAutoIncr := strconv.Itoa(id + 1) |
| | | count := 5 - len(strMaxAutoIncr) |
| | | for i := 0; i < count; i++ { |
| | | strMaxAutoIncr = "0" + strMaxAutoIncr |
| | | } |
| | | |
| | | return fmt.Sprintf("%v%v", prefix, strMaxAutoIncr), nil |
| | | } |