package service
|
|
|
|
import (
|
|
"leit.com/leit_seat_aps/db"
|
|
"strings"
|
|
)
|
|
|
|
// 供应组业务对象
|
|
type BL_SupplyGroup struct {
|
|
Supplygroupid string
|
|
Partfamilyid string // 零件族ID
|
|
Worklineid string // 产线ID
|
|
Sgtype string // 供应组类型
|
|
Shippablesg int // 是否需要包装发运
|
|
Multioutput bool
|
|
Modfactor int
|
|
Sgchildrendict map[string]string // 存放子供应组名
|
|
SgAssigndict map[string]db.Me_supplygroup_assignment // 供应组分配信息
|
|
Sg_attr_dict map[int]BL_SupplyGroup_Atcod // 供应组分配的属性字典
|
|
Bl_sgpartDict map[string]BL_SgPart // 存储供应组关联的零件
|
|
Bl_ordattrdict map[int]BL_OrdAttribute // 客户订单在该SupplyGroup解析所得属性清单字典
|
|
Supplygrouptab db.Me_supplygroup
|
|
}
|
|
|
|
// 供应组分配的属性对象
|
|
type BL_SupplyGroup_Atcod struct {
|
|
Supplygroupid string // 供应组ID
|
|
Attrcode int // 属性ID
|
|
Mandatory int // 是否强制需要
|
|
Verifyrule string // 验证规则
|
|
Supplygroup_attrtab db.Me_supplygroup_atcodlst
|
|
}
|
|
|
|
// 供应组零件业务对象
|
|
type BL_SgPart struct {
|
|
Partid string // 零件号
|
|
OriPartid string // 不带AI的原始零件号
|
|
Ai string // 工艺变更版本号
|
|
Qty int // 零件数量
|
|
Supplygroupid string // 供应组ID
|
|
Originalsgid string // 对于非共用件,值=供应组ID;对于共用件,值=零件原来所属的共用供应组ID
|
|
AtcodDict map[int]BL_Attribute
|
|
}
|
|
|
|
// 获取项目的供应组字典
|
|
func (bl_sg *BL_SupplyGroup) Copy() (bl_sgto BL_SupplyGroup, err error) {
|
|
var (
|
|
bl_sgpt, bl_sgptto BL_SgPart
|
|
bl_sgat, bl_sgatto BL_SupplyGroup_Atcod
|
|
)
|
|
|
|
bl_sgto = BL_SupplyGroup{}
|
|
bl_sgto.Supplygroupid = bl_sg.Supplygroupid
|
|
bl_sgto.Partfamilyid = bl_sg.Partfamilyid
|
|
bl_sgto.Worklineid = bl_sg.Worklineid
|
|
bl_sgto.Sgtype = bl_sg.Sgtype
|
|
bl_sgto.Sg_attr_dict = bl_sg.Sg_attr_dict
|
|
bl_sgto.Supplygrouptab = bl_sg.Supplygrouptab
|
|
|
|
bl_sgto.Bl_sgpartDict = make(map[string]BL_SgPart)
|
|
for _, bl_sgpt = range bl_sg.Bl_sgpartDict {
|
|
bl_sgptto = BL_SgPart{}
|
|
bl_sgptto.Supplygroupid = bl_sgpt.Supplygroupid
|
|
bl_sgptto.Partid = bl_sgpt.Partid
|
|
bl_sgptto.Qty = bl_sgpt.Qty
|
|
bl_sgptto.Originalsgid = bl_sgpt.Originalsgid
|
|
bl_sgptto.AtcodDict = bl_sgpt.AtcodDict
|
|
bl_sgto.Bl_sgpartDict[bl_sgptto.Partid] = bl_sgptto
|
|
}
|
|
|
|
bl_sgto.Sg_attr_dict = make(map[int]BL_SupplyGroup_Atcod)
|
|
for _, bl_sgat = range bl_sg.Sg_attr_dict {
|
|
bl_sgatto = BL_SupplyGroup_Atcod{}
|
|
bl_sgatto.Supplygroupid = bl_sgat.Supplygroupid
|
|
bl_sgatto.Attrcode = bl_sgat.Attrcode
|
|
bl_sgatto.Mandatory = bl_sgat.Mandatory
|
|
bl_sgatto.Verifyrule = bl_sgat.Verifyrule
|
|
bl_sgatto.Supplygroup_attrtab = bl_sgat.Supplygroup_attrtab
|
|
bl_sg.Sg_attr_dict[bl_sgatto.Attrcode] = bl_sgatto
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取供应组列表
|
|
func GetSupplygrouptabList() (sgtablist []db.Me_supplygroup, err error) {
|
|
if err = db.G_DbEngine.Where("finr = ?", db.G_FINR).Find(&sgtablist); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取项目供应组列表
|
|
func GetProjectSupplygrouptabList(projnr string) (sgtablist []db.Me_supplygroup, err error) {
|
|
var (
|
|
pftablist []db.Me_partfamily
|
|
i int
|
|
pfarray []string
|
|
)
|
|
// 获取指定项目的零件族数组
|
|
if pftablist, err = GetProjectPartfamilytabList(projnr); err != nil {
|
|
return
|
|
}
|
|
pfarray = make([]string, len(pftablist))
|
|
for i = 0; i < len(pftablist); i++ {
|
|
pfarray[i] = pftablist[i].Partfamilyid
|
|
}
|
|
if err = db.G_DbEngine.Where("finr = ?", db.G_FINR).In("partfamilyid", pfarray).Find(&sgtablist); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取项目供应组属性列表
|
|
func GetProjectSupplygroupAtcodtabList(projnr string) (sgatcodtablist []db.Me_supplygroup_atcodlst, err error) {
|
|
var (
|
|
sgtablist []db.Me_supplygroup
|
|
i int
|
|
sgarray []string
|
|
)
|
|
// 获取指定项目的零件族数组
|
|
if sgtablist, err = GetProjectSupplygrouptabList(projnr); err != nil {
|
|
return
|
|
}
|
|
sgarray = make([]string, len(sgtablist))
|
|
for i = 0; i < len(sgtablist); i++ {
|
|
sgarray[i] = sgtablist[i].Supplygroupid
|
|
}
|
|
if err = db.G_DbEngine.Where("finr = ?", db.G_FINR).In("supplygroupid", sgarray).Find(&sgatcodtablist); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取指定项目的供应组主数据字典
|
|
func GetProjectSupplygroupDict(projnr string) (sgdict map[string]BL_SupplyGroup, err error) {
|
|
var (
|
|
sgtablst []db.Me_supplygroup
|
|
sgattrtablst []db.Me_supplygroup_atcodlst
|
|
bl_sg BL_SupplyGroup
|
|
bl_sgattr BL_SupplyGroup_Atcod
|
|
i int
|
|
ok bool
|
|
)
|
|
sgdict = make(map[string]BL_SupplyGroup)
|
|
// 获取项目的供应组列表
|
|
if sgtablst, err = GetProjectSupplygrouptabList(projnr); err != nil {
|
|
return
|
|
}
|
|
// 获取项目的供应组属性列表
|
|
if sgattrtablst, err = GetProjectSupplygroupAtcodtabList(projnr); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历供应组列表
|
|
for i = 0; i < len(sgtablst); i++ {
|
|
sgtablst[i].Clipped()
|
|
bl_sg = BL_SupplyGroup{}
|
|
bl_sg.Supplygroupid = sgtablst[i].Supplygroupid
|
|
bl_sg.Partfamilyid = sgtablst[i].Partfamilyid
|
|
bl_sg.Worklineid = sgtablst[i].Worklineid
|
|
bl_sg.Sgtype = strings.ToUpper(sgtablst[i].Sgtype)
|
|
if sgtablst[i].Multioutput > 0 {
|
|
bl_sg.Multioutput = true
|
|
} else {
|
|
bl_sg.Multioutput = false
|
|
}
|
|
bl_sg.Modfactor = sgtablst[i].Modfactor
|
|
bl_sg.Shippablesg = sgtablst[i].Shippablesg
|
|
bl_sg.Sg_attr_dict = make(map[int]BL_SupplyGroup_Atcod)
|
|
bl_sg.Supplygrouptab = sgtablst[i]
|
|
sgdict[bl_sg.Supplygroupid] = bl_sg
|
|
}
|
|
|
|
// 遍历供应组属性列表
|
|
for i = 0; i < len(sgattrtablst); i++ {
|
|
sgattrtablst[i].Clipped()
|
|
if bl_sg, ok = sgdict[sgattrtablst[i].Supplygroupid]; !ok {
|
|
continue
|
|
}
|
|
bl_sgattr = BL_SupplyGroup_Atcod{}
|
|
bl_sgattr.Attrcode = sgattrtablst[i].Attrcode
|
|
bl_sgattr.Mandatory = sgattrtablst[i].Mandatory
|
|
bl_sgattr.Verifyrule = sgattrtablst[i].Verifyrule
|
|
bl_sgattr.Supplygroup_attrtab = sgattrtablst[i]
|
|
bl_sg.Sg_attr_dict[bl_sgattr.Attrcode] = bl_sgattr
|
|
// 更新回供应组字典
|
|
sgdict[bl_sg.Supplygroupid] = bl_sg
|
|
}
|
|
return
|
|
}
|