package service
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"leit.com/leit_seat_aps/common"
|
|
"leit.com/leit_seat_aps/db"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// 用于TOD解析的项目主数据对象
|
|
type TodProject struct {
|
|
Projectid string
|
|
Projecttab db.Me_project // 项目表
|
|
Mesprojtab db.Prod_project // 生产项目表
|
|
Attrdict map[int]BL_Attribute // 所有的用于解析的产品属性
|
|
Partdict map[string]BL_Part // 所有的用于解析的零件清单
|
|
Partfamdict map[string]BL_PartFamily // 所有的用于解析的零件族
|
|
Supplygrpdict map[string]BL_SupplyGroup // 所有的用于解析的供应组
|
|
Partruledict map[string]BL_PartAssignRule // Key = 零件号+零件族+待分配数量
|
|
Carmodeldict map[string]BL_Carmodel // 车型字典
|
|
}
|
|
|
|
// 获取项目指定属性类型的属性主数据字典
|
|
func (tp *TodProject) GetAttributeList(attrtype int) (err error) {
|
|
var (
|
|
attrtab db.Me_attribute
|
|
attrtablist []db.Me_attribute
|
|
bl_attr BL_Attribute
|
|
i int
|
|
)
|
|
|
|
// 初始化项目的属性字典
|
|
tp.Attrdict = make(map[int]BL_Attribute)
|
|
attrtab = db.Me_attribute{}
|
|
|
|
if attrtablist, err = attrtab.GetTypeAttributes(attrtype); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历属性列表并写入属性字典
|
|
for i = 0; i < len(attrtablist); i++ {
|
|
attrtablist[i].Clipped()
|
|
bl_attr = BL_Attribute{}
|
|
bl_attr.Attrcode = attrtablist[i].Attrcode
|
|
bl_attr.Attrname = attrtablist[i].Attrname
|
|
bl_attr.Descr = attrtablist[i].Descr
|
|
bl_attr.Attrtype = attrtablist[i].Attrtype
|
|
bl_attr.Attrtab = attrtablist[i]
|
|
bl_attr.Atvaltablst = attrtablist[i].Valst
|
|
tp.Attrdict[bl_attr.Attrcode] = bl_attr
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取项目的零件字典
|
|
func (tp *TodProject) GetPartList() (err error) {
|
|
var (
|
|
partab db.Me_part
|
|
partablst []db.Me_part
|
|
i, j int
|
|
bl_pt BL_Part
|
|
bl_ptattr BL_PartAttribute
|
|
)
|
|
|
|
// 初始化项目的零件字典
|
|
tp.Partdict = make(map[string]BL_Part)
|
|
partab = db.Me_part{}
|
|
if partablst, err = partab.GetProjectAll(tp.Projectid); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历零件列表并写入字典
|
|
for i = 0; i < len(partablst); i++ {
|
|
bl_pt = BL_Part{}
|
|
bl_pt.Partid = partablst[i].Partid
|
|
bl_pt.Projnr = partablst[i].Projnr
|
|
bl_pt.AtcodDict = make(map[int]BL_PartAttribute)
|
|
for j = 0; j < len(partablst[i].Attrlst); j++ {
|
|
bl_ptattr = BL_PartAttribute{}
|
|
bl_ptattr.Attrcode = partablst[i].Attrlst[j].Attrcode
|
|
bl_ptattr.Attrvalue = partablst[i].Attrlst[j].Attrvalue
|
|
bl_ptattr.Partattrtab = partablst[i].Attrlst[j]
|
|
bl_pt.AtcodDict[bl_ptattr.Attrcode] = bl_ptattr
|
|
}
|
|
tp.Partdict[bl_pt.Partid] = bl_pt
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取项目的零件族字典
|
|
func (tp *TodProject) GetPartFamilyList() (err error) {
|
|
var (
|
|
pftab db.Me_partfamily
|
|
pftablst []db.Me_partfamily
|
|
i, j int
|
|
bl_pf BL_PartFamily
|
|
bl_pfattr BL_PartFamily_Atcod
|
|
)
|
|
|
|
// 初始化项目的零件族字典
|
|
tp.Partfamdict = make(map[string]BL_PartFamily)
|
|
pftab = db.Me_partfamily{}
|
|
if pftablst, err = pftab.GetProjectAll(tp.Projectid); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历零件族列表并写入字典
|
|
for i = 0; i < len(pftablst); i++ {
|
|
bl_pf = BL_PartFamily{}
|
|
bl_pf.Partfamilyid = pftablst[i].Partfamilyid
|
|
bl_pf.Pf_attr_dict = make(map[int]BL_PartFamily_Atcod)
|
|
for j = 0; j < len(pftablst[i].Atcodlst); j++ {
|
|
bl_pfattr = BL_PartFamily_Atcod{}
|
|
bl_pfattr.Attrcode = pftablst[i].Atcodlst[j].Attrcode
|
|
bl_pfattr.Mandatory = pftablst[i].Atcodlst[j].Mandatory
|
|
bl_pfattr.Verifyrule = pftablst[i].Atcodlst[j].Verifyrule
|
|
bl_pfattr.Partfamily_attrtab = pftablst[i].Atcodlst[j]
|
|
bl_pf.Pf_attr_dict[bl_pfattr.Attrcode] = bl_pfattr
|
|
}
|
|
tp.Partfamdict[bl_pf.Partfamilyid] = bl_pf
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取项目的供应组字典
|
|
func (tp *TodProject) GetSupplyGroupList() (err error) {
|
|
var (
|
|
sgtab db.Me_supplygroup
|
|
sgtablst []db.Me_supplygroup
|
|
i, j, k int
|
|
bl_sg BL_SupplyGroup
|
|
bl_csg BL_SupplyGroup
|
|
bl_sgattr BL_SupplyGroup_Atcod
|
|
ok bool
|
|
)
|
|
|
|
// 初始化项目的供应组字典
|
|
tp.Supplygrpdict = make(map[string]BL_SupplyGroup)
|
|
sgtab = db.Me_supplygroup{}
|
|
if sgtablst, err = sgtab.GetProjectAll(tp.Projectid); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历供应组列表并写入字典
|
|
for i = 0; i < len(sgtablst); i++ {
|
|
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 bl_sg.Sgtype == common.SG_TYPE_NORMAL {
|
|
bl_sg.Sgchildrendict = make(map[string]string)
|
|
}
|
|
if sgtablst[i].Multioutput > 0 {
|
|
bl_sg.Multioutput = true
|
|
} else {
|
|
bl_sg.Multioutput = false
|
|
}
|
|
bl_sg.SgAssigndict = make(map[string]db.Me_supplygroup_assignment)
|
|
bl_sg.Modfactor = sgtablst[i].Modfactor
|
|
bl_sg.Shippablesg = sgtablst[i].Shippablesg
|
|
bl_sg.Supplygrouptab = sgtablst[i]
|
|
bl_sg.Sg_attr_dict = make(map[int]BL_SupplyGroup_Atcod)
|
|
// 加载供应组的属性信息
|
|
for j = 0; j < len(sgtablst[i].Atcodlst); j++ {
|
|
bl_sgattr = BL_SupplyGroup_Atcod{}
|
|
bl_sgattr.Attrcode = sgtablst[i].Atcodlst[j].Attrcode
|
|
bl_sgattr.Mandatory = sgtablst[i].Atcodlst[j].Mandatory
|
|
bl_sgattr.Verifyrule = sgtablst[i].Atcodlst[j].Verifyrule
|
|
bl_sgattr.Supplygroup_attrtab = sgtablst[i].Atcodlst[j]
|
|
bl_sg.Sg_attr_dict[bl_sgattr.Attrcode] = bl_sgattr
|
|
}
|
|
// 加载供应组的分配信息
|
|
if bl_sg.Sgtype == common.SG_TYPE_NORMAL && bl_sg.Shippablesg == 0 {
|
|
for k = 0; k < len(sgtablst[i].Asnsglst); k++ {
|
|
bl_sg.SgAssigndict[sgtablst[i].Asnsglst[k].Fsupplygroupid] = sgtablst[i].Asnsglst[k]
|
|
}
|
|
}
|
|
tp.Supplygrpdict[bl_sg.Supplygroupid] = bl_sg
|
|
}
|
|
|
|
// 遍历子供应组
|
|
for _, bl_csg = range tp.Supplygrpdict {
|
|
if bl_csg.Sgtype == common.SG_TYPE_CHILD {
|
|
if bl_sg, ok = tp.Supplygrpdict[strings.TrimSpace(bl_csg.Supplygrouptab.Fsupplygroupid)]; !ok {
|
|
err = errors.New(fmt.Sprintf("Child supplygroup %s parent supplygroup %s is not existing!", bl_csg.Supplygroupid, bl_csg.Supplygrouptab.Fsupplygroupid))
|
|
}
|
|
bl_sg.Sgchildrendict[bl_csg.Supplygroupid] = bl_csg.Supplygroupid
|
|
//tp.Supplygrpdict[bl_sg.Supplygroupid] = bl_sg
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取项目的供应组字典
|
|
func (tp *TodProject) CopySupplyGroup(sgid string) (bl_sg BL_SupplyGroup, err error) {
|
|
var (
|
|
bl_sgfrom BL_SupplyGroup
|
|
bl_sgpt, bl_sgptfrom BL_SgPart
|
|
bl_sgat, bl_sgatfrom BL_SupplyGroup_Atcod
|
|
ok bool
|
|
)
|
|
|
|
if bl_sgfrom, ok = tp.Supplygrpdict[sgid]; !ok {
|
|
return
|
|
}
|
|
|
|
bl_sg = BL_SupplyGroup{}
|
|
bl_sg.Supplygroupid = bl_sgfrom.Supplygroupid
|
|
bl_sg.Partfamilyid = bl_sgfrom.Partfamilyid
|
|
bl_sg.Worklineid = bl_sgfrom.Worklineid
|
|
bl_sg.Sgtype = bl_sgfrom.Sgtype
|
|
bl_sg.Sg_attr_dict = bl_sgfrom.Sg_attr_dict
|
|
bl_sg.Supplygrouptab = bl_sgfrom.Supplygrouptab
|
|
bl_sg.Bl_sgpartDict = make(map[string]BL_SgPart)
|
|
|
|
for _, bl_sgptfrom = range bl_sgfrom.Bl_sgpartDict {
|
|
bl_sgpt = BL_SgPart{}
|
|
bl_sgpt.Supplygroupid = bl_sgptfrom.Supplygroupid
|
|
bl_sgpt.Partid = bl_sgptfrom.Partid
|
|
bl_sgpt.Qty = bl_sgptfrom.Qty
|
|
bl_sgpt.Originalsgid = bl_sgptfrom.Originalsgid
|
|
bl_sgpt.AtcodDict = bl_sgptfrom.AtcodDict
|
|
bl_sg.Bl_sgpartDict[bl_sgpt.Partid] = bl_sgpt
|
|
}
|
|
|
|
bl_sg.Sg_attr_dict = make(map[int]BL_SupplyGroup_Atcod)
|
|
for _, bl_sgatfrom = range bl_sgfrom.Sg_attr_dict {
|
|
bl_sgat = BL_SupplyGroup_Atcod{}
|
|
bl_sgat.Supplygroupid = bl_sgatfrom.Supplygroupid
|
|
bl_sgat.Attrcode = bl_sgatfrom.Attrcode
|
|
bl_sgat.Mandatory = bl_sgatfrom.Mandatory
|
|
bl_sgat.Verifyrule = bl_sgatfrom.Verifyrule
|
|
bl_sgat.Supplygroup_attrtab = bl_sgatfrom.Supplygroup_attrtab
|
|
bl_sg.Sg_attr_dict[bl_sgat.Attrcode] = bl_sgat
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取项目的零件分配规则字典
|
|
func (tp *TodProject) GetPartRuleList() (err error) {
|
|
var (
|
|
ptruletab db.Me_partrule
|
|
ptruletablst []db.Me_partrule
|
|
i, j int
|
|
key string
|
|
bl_ptrule BL_PartAssignRule
|
|
)
|
|
|
|
// 初始化项目的零件规则字典
|
|
tp.Partruledict = make(map[string]BL_PartAssignRule)
|
|
ptruletab = db.Me_partrule{}
|
|
if ptruletablst, err = ptruletab.GetProjectAll(tp.Projectid); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历零件数量分配规则列表并写入字典
|
|
for i = 0; i < len(ptruletablst); i++ {
|
|
bl_ptrule = BL_PartAssignRule{}
|
|
bl_ptrule.Ruleid = ptruletablst[i].Ruleid
|
|
bl_ptrule.Partid = ptruletablst[i].Partid
|
|
bl_ptrule.Partfamilyid = ptruletablst[i].Partrule_cprecond
|
|
bl_ptrule.Qty = ptruletablst[i].Partrule_iprecond
|
|
bl_ptrule.Partruletab = ptruletablst[i]
|
|
bl_ptrule.Assignnruledict = make(map[string]db.Me_partrule_qtyassign)
|
|
for j = 0; j < len(ptruletablst[i].Qtyasnlst); j++ {
|
|
ptruletablst[i].Qtyasnlst[j].Clipped()
|
|
key = ptruletablst[i].Qtyasnlst[j].Supplygroupid
|
|
bl_ptrule.Assignnruledict[key] = ptruletablst[i].Qtyasnlst[j]
|
|
}
|
|
// 项目零件分配规则Key = 零件ID+数量
|
|
key = bl_ptrule.Partid + "+" + strconv.Itoa(bl_ptrule.Qty)
|
|
tp.Partruledict[key] = bl_ptrule
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取项目的车型字典
|
|
func (tp *TodProject) GetCarModelList() (err error) {
|
|
var (
|
|
cmtab db.Me_carmodel
|
|
cmtablst []db.Me_carmodel
|
|
i, j int
|
|
key string
|
|
bl_cm BL_Carmodel
|
|
bl_cmattr BL_Carmodel_Atcod
|
|
)
|
|
|
|
// 初始化项目的车型字典
|
|
tp.Carmodeldict = make(map[string]BL_Carmodel)
|
|
cmtab = db.Me_carmodel{}
|
|
if cmtablst, err = cmtab.GetProjectAll(tp.Projectid); err != nil {
|
|
return
|
|
}
|
|
|
|
// 遍历车型列表并写入字典
|
|
for i = 0; i < len(cmtablst); i++ {
|
|
bl_cm = BL_Carmodel{}
|
|
bl_cm.Carmodelid = cmtablst[i].Carmodelid
|
|
bl_cm.Carmodeltab = cmtablst[i]
|
|
bl_cm.Cm_pf_dict = make(map[string]string)
|
|
bl_cm.Cm_attr_dict = make(map[int]BL_Carmodel_Atcod)
|
|
// 存储零件族ID
|
|
for j = 0; j < len(cmtablst[i].Pflst); j++ {
|
|
key = cmtablst[i].Pflst[j].Partfamilyid
|
|
bl_cm.Cm_pf_dict[key] = key
|
|
}
|
|
// 存储车型分配的属性列表
|
|
for j = 0; j < len(cmtablst[i].Atcodlst); j++ {
|
|
bl_cmattr = BL_Carmodel_Atcod{}
|
|
bl_cmattr.Carmodelid = cmtablst[i].Atcodlst[j].Carmodelid
|
|
bl_cmattr.Attrcode = cmtablst[i].Atcodlst[j].Attrcode
|
|
bl_cmattr.Mandatory = cmtablst[i].Atcodlst[j].Mandatory
|
|
bl_cmattr.Verifyrule = cmtablst[i].Atcodlst[j].Verifyrule
|
|
bl_cmattr.Carmodel_attrtab = cmtablst[i].Atcodlst[j]
|
|
bl_cm.Cm_attr_dict[bl_cmattr.Attrcode] = bl_cmattr
|
|
}
|
|
tp.Carmodeldict[bl_cm.Carmodelid] = bl_cm
|
|
}
|
|
|
|
return
|
|
}
|