package service
|
|
|
|
import (
|
|
"leit.com/leit_seat_aps/db"
|
|
)
|
|
|
|
// 属性对象
|
|
type BL_Attribute struct {
|
|
Attrcode int // 属性ID
|
|
Attrname string // 属性名
|
|
Descr string // 属性描述
|
|
Attrtype int // 属性类型:1=产品属性;2=生产属性
|
|
Attrtab db.Me_attribute // 属性表记录
|
|
Atvaltablst []db.Me_attribute_valst // 属性值列表
|
|
}
|
|
|
|
// 订单属性对象
|
|
type BL_OrdAttribute struct {
|
|
Attrcode int // 属性ID
|
|
Attrvaldict map[string]string // 属性值字典
|
|
Attrvalst []BL_OrdAttrValue // 属性值列表
|
|
}
|
|
|
|
// 订单属性值对象
|
|
type BL_OrdAttrValue struct {
|
|
Attrvalue string // 属性值
|
|
Partid string // 零件号
|
|
}
|
|
|
|
// 属性分配
|
|
type BL_AttrAssign struct {
|
|
Attrcode int // 属性ID
|
|
Mandatory int // 是否强制必须
|
|
Rule string
|
|
Value1 string
|
|
Value2 string
|
|
}
|
|
|
|
// 获取指定类型的属性列表
|
|
func GetAttributetabList(attrtype int) (attrtablist []db.Me_attribute, err error) {
|
|
if attrtype > 0 {
|
|
err = db.G_DbEngine.Where("finr = ?", db.G_FINR).Find(&attrtablist)
|
|
} else {
|
|
err = db.G_DbEngine.Where("finr = ? and attrtype = ?", db.G_FINR, attrtype).Find(&attrtablist)
|
|
}
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取属性值列表
|
|
func GetAttributeValtabList() (attrvaltablist []db.Me_attribute_valst, err error) {
|
|
if err = db.G_DbEngine.Where("finr = ?", db.G_FINR).Find(&attrvaltablist); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取指定属性类型的属性主数据字典
|
|
func GetAttributeListDict(attrtype int) (attrdict map[int]BL_Attribute, err error) {
|
|
var (
|
|
attablist []db.Me_attribute
|
|
atvaltablist []db.Me_attribute_valst
|
|
bl_attr BL_Attribute
|
|
i int
|
|
ok bool
|
|
)
|
|
attrdict = make(map[int]BL_Attribute)
|
|
if attablist, err = GetAttributetabList(attrtype); err != nil {
|
|
return
|
|
}
|
|
if atvaltablist, err = GetAttributeValtabList(); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历属性列表并写入属性字典
|
|
for i = 0; i < len(attablist); i++ {
|
|
attablist[i].Clipped()
|
|
bl_attr = BL_Attribute{}
|
|
bl_attr.Attrcode = attablist[i].Attrcode
|
|
bl_attr.Attrname = attablist[i].Attrname
|
|
bl_attr.Descr = attablist[i].Descr
|
|
bl_attr.Attrtype = attablist[i].Attrtype
|
|
bl_attr.Attrtab = attablist[i]
|
|
attrdict[bl_attr.Attrcode] = bl_attr
|
|
}
|
|
|
|
// 遍历属性值列表,添加到对应的属性业务对象并更新属性字典
|
|
for i = 0; i < len(atvaltablist); i++ {
|
|
atvaltablist[i].Clipped()
|
|
if bl_attr, ok = attrdict[atvaltablist[i].Attrcode]; !ok {
|
|
continue
|
|
}
|
|
bl_attr.Atvaltablst = append(bl_attr.Atvaltablst, atvaltablist[i])
|
|
attrdict[bl_attr.Attrcode] = bl_attr
|
|
}
|
|
return
|
|
}
|
|
|
|
func (bl_attr *BL_Attribute) GetValPos(attrval string) (pos int) {
|
|
var i int
|
|
|
|
pos = -1
|
|
for i = 0; i < len(bl_attr.Atvaltablst); i++ {
|
|
if attrval == bl_attr.Atvaltablst[i].Shortcode {
|
|
pos = i
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|