xsource

package
v0.3.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause-Clear Imports: 10 Imported by: 0

Documentation

Overview

溯源模块

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(source *Source) error

创建批次信息

source	待创建的批次信息

func CreateChild

func CreateChild(id, num uint) error

创建批次产品

id	批次ID
num	创建条数

func CreateChildCode

func CreateChildCode(id uint, child []string) error

创建批次产品【根据已有商品code】

id	批次ID
child	待存入的goods_code

func CreateDesc

func CreateDesc(sid uint, source []SourceDesc) error

创建批次描述信息

sid		批次ID
source	待创建的批次描述信息

func NsqRun

func NsqRun(param []byte) error

队列监听,用于同步插入查询结果

xsource.find	<SourceLog>

func Regedit

func Regedit(c *Config)

注入配置项

Types

type Config

type Config struct {
	DB              *gorm.DB // 数据库连接
	SourceName      string   // 溯源批次表名称
	SourceDescName  string   // 溯源批次附属信息表
	SourceChildName string   // 溯源详情表名称
	SourceLogName   string   // 流转表名称
}

溯源模块逻辑 1. 后台插入产品详情信息,插入产品名称、产品描述、产品图片等 2. 生产产品时,追加插入产品的附加信息 3.

此方法使用Create等方法插入初始数据,然后使用InfoGoods来查询/验证,使用LogList来确定之前查询的次数及IP等信息

type Source

type Source struct {
	ID        uint   `gorm:"id;primaryKey;not null;autoIncrement" form:"id" json:"id"`                         // 待溯源商品ID
	Name      string `gorm:"column:name;type:VARCHAR(200);comment:待溯源商品名称" json:"name" form:"name"`            // 待溯源商品名称
	UserId    uint   `gorm:"column:user_id;comment:发布人ID" json:"user_id" form:"user_id"`                       // 发布人ID
	CreatedAt string `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"` // 创建时间
	UpdatedAt string `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at" form:"updated_at"` // 修改时间
}

待溯源批次表

func Info

func Info(id uint) (*Source, error)

获取批次详情

id	批次ID

func (*Source) TableName

func (c *Source) TableName() string

表名

type SourceChild

type SourceChild struct {
	ID        uint64 `gorm:"id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" form:"id" json:"id"`                            // 待溯源商品ID
	SourceId  uint   `gorm:"source_id;comment:溯源批次ID" form:"source_id" json:"source_id"`                                               // 所查询的商品ID
	GoodsCode string `gorm:"column:goods_code;type:VARCHAR(50);comment:待溯源商品标识;UNIQUE:goods_code" json:"goods_code" form:"goods_code"` // 待溯源商品标识,如果未传入则自动生成一个uuid来作为标识
	CreatedAt string `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"`                         // 创建时间
}

溯源商品表

func InfoChild

func InfoChild(id uint, offset, limit int) (int64, []SourceChild, error)

获取批次商品详情

id		批次ID
offset	跳过条数
limit	查询条数

func InfoGoods

func InfoGoods(id uint64, code, msg, ua, ip string, is_find uint8) (*SourceChild, error)

根据商品code/id查询批次商品信息

id		商品ID
code	商品唯一code
msg		操作备注
ua		操作客户端的UserAgent
ip		操作客户端的IP地址
is_find	操作类型 0-内部流转 1-查询 2-产品作废

func (*SourceChild) TableName

func (c *SourceChild) TableName() string

表名

type SourceDesc

type SourceDesc struct {
	ID        uint   `gorm:"id;primaryKey;not null;autoIncrement" form:"id" json:"id"`                   // 待溯源商品ID
	SourceId  uint   `gorm:"source_id;comment:溯源批次ID;index:source_id" form:"source_id" json:"source_id"` // 所查询的批次ID
	Types     uint   `gorm:"column:types;comment:描述项的名称,KV" json:"types" form:"types"`                   // 描述项的名称
	TypesName string `gorm:"-" json:"types_name" form:"types_name"`                                      // 描述项的名称,具体值
	Value     string `gorm:"column:value;type:VARCHAR(200);comment:描述项的值" json:"value" form:"value"`     // 描述项的值
}

待溯源批次描述表

func InfoDesc

func InfoDesc(id uint) ([]SourceDesc, error)

获取批次描述详情

id	批次ID

func (*SourceDesc) TableName

func (c *SourceDesc) TableName() string

表名

type SourceLog

type SourceLog struct {
	ID            uint64 `gorm:"id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" form:"id" json:"id"` // 待溯源商品ID
	SourceChildId uint64 ``                                                                                     // 所查询的商品ID
	/* 134-byte string literal not displayed */
	Ip     uint   `gorm:"column:ip;comment:操作地址IP,KV" json:"ip" form:"ip"`                 // 操作地址IP
	Msg    string `gorm:"column:msg;type:VARCHAR(200);comment:备注信息" json:"msg" form:"msg"` // 操作备注
	IsFind uint8  ``                                                                       // 是否是查询操作【用于区分内部流转还是外部查询】
	/* 148-byte string literal not displayed */
	UserAgent uint   `gorm:"column:user_agent;comment:操作用户的UA标识,KV" json:"user_agent" form:"user_agent"`       // 操作用户的UA标识
	CreatedAt string `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"` // 创建时间
}

溯源入库/出库/运输/查询等的日志

func LogList

func LogList(id uint64) ([]SourceLog, error)

溯源商品查询日志

id	溯源产品ID

func (*SourceLog) TableName

func (c *SourceLog) TableName() string

表名

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL