package service
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"github.com/go-xorm/xorm"
|
|
"leit.com/leit_seat_aps/common"
|
|
"leit.com/leit_seat_aps/db"
|
|
"time"
|
|
)
|
|
|
|
// 定义发运车
|
|
type BL_Shipcar struct {
|
|
ShipTmplId string
|
|
Paktypdict map[string]db.Jit_shiptemplate_itemlst
|
|
Shipcartab db.Jit_shiptemplate
|
|
}
|
|
|
|
// 定义发运车订单
|
|
type BL_ShipcarOrder struct {
|
|
Shiporderid string
|
|
ShipTmplId string
|
|
Workloaddict map[string]BL_ShipcarWorkload
|
|
Spordtab db.Jit_shiporder
|
|
}
|
|
|
|
// 发运车装载负荷情况
|
|
type BL_ShipcarWorkload struct {
|
|
Packtypeid string // 包装类型
|
|
Maxqty int // 该包装类型最多可装载量
|
|
Planqty int // 计划装载量
|
|
Fillqty int // 实际已装载
|
|
}
|
|
|
|
// 检查包装单是否适配当前发运车,将包装单对应的包装类型的最大数量和实际数量进行比对
|
|
func (bl_sco *BL_ShipcarOrder) CanFillPackOrder(pkotab db.Jit_packorder) (can bool) {
|
|
var (
|
|
bl_scwl BL_ShipcarWorkload
|
|
i int
|
|
ok bool
|
|
)
|
|
|
|
// 对于未适配模板的发运单(未计划)则基于可适配最大数进行匹配
|
|
// 对于适配模板的发运单(已计划)则基于指定包装项的计划数和已填充数来进行匹配
|
|
if bl_sco.Spordtab.Status < common.SPO_STATUS_PLANNED {
|
|
// 获取发运单对应包装类型的负载对象
|
|
if bl_scwl, ok = bl_sco.Workloaddict[pkotab.Packtypeid]; !ok {
|
|
can = false
|
|
return
|
|
}
|
|
// 将负载对象的可填充数与最大可填充数进行比较,如果到达最大可填充数,则不再可填充
|
|
if bl_scwl.Fillqty >= bl_scwl.Maxqty {
|
|
can = false
|
|
} else {
|
|
can = true
|
|
}
|
|
} else {
|
|
can = false
|
|
for i = 0; i < len(bl_sco.Spordtab.Itemlst); i++ {
|
|
if bl_sco.Spordtab.Itemlst[i].Packtypeid == pkotab.Packtypeid {
|
|
if bl_sco.Spordtab.Itemlst[i].Shortship > 0 {
|
|
if bl_sco.Spordtab.Itemlst[i].Fillqty < bl_sco.Spordtab.Itemlst[i].Shortshipqty && bl_sco.Spordtab.Itemlst[i].Status < common.SPO_STATUS_RELEASED {
|
|
can = true
|
|
break
|
|
}
|
|
} else {
|
|
if bl_sco.Spordtab.Itemlst[i].Fillqty < bl_sco.Spordtab.Itemlst[i].Planqty && bl_sco.Spordtab.Itemlst[i].Status < common.SPO_STATUS_RELEASED {
|
|
can = true
|
|
break
|
|
}
|
|
}
|
|
} else {
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 将包装订单插入到当前发运车
|
|
func (bl_sco *BL_ShipcarOrder) AddPackOrder(session *xorm.Session, pkotab db.Jit_packorder) (err error) {
|
|
var (
|
|
spoitemtab_match, spoitemtab db.Jit_shiporder_itemlst
|
|
spodatatab db.Jit_shiporder_datalst
|
|
i int
|
|
found bool
|
|
)
|
|
|
|
// 获取发运车数据
|
|
if err = bl_sco.GetOrderDataBySession(session); err != nil {
|
|
return
|
|
}
|
|
|
|
// 找到发运车对应的发运子项
|
|
found = false
|
|
for i = 0; i < len(bl_sco.Spordtab.Itemlst); i++ {
|
|
if pkotab.Packtypeid == bl_sco.Spordtab.Itemlst[i].Packtypeid {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
err = errors.New(fmt.Sprintf("The packorder %s packtype not match shipcar order %s",
|
|
pkotab.Packorderid, pkotab.Packtypeid, bl_sco.Shiporderid))
|
|
return
|
|
} else {
|
|
spoitemtab_match = bl_sco.Spordtab.Itemlst[i]
|
|
}
|
|
|
|
// 更新包装的装载状态
|
|
pkotab.Loadstatus = common.PKO_STATUS_LOADED
|
|
pkotab.Lastmodif = common.Date(time.Now().Unix(), "YYYYMMDDHHmmss")
|
|
if err = pkotab.UpdateFields(session, "loadstatus, lastmodif"); err != nil {
|
|
return
|
|
}
|
|
|
|
// 插入包装行数据
|
|
spodatatab = db.Jit_shiporder_datalst{}
|
|
spodatatab.Finr = db.G_FINR
|
|
spodatatab.Shiporderid = bl_sco.Spordtab.Shiporderid
|
|
spodatatab.Packtypeid = pkotab.Packtypeid
|
|
spodatatab.Packorderid = pkotab.Packorderid
|
|
spodatatab.Planqty = 1
|
|
spodatatab.Actqty = 0
|
|
spodatatab.Status = common.SPO_STATUS_RELEASED
|
|
spodatatab.Lastuser = "service"
|
|
spodatatab.Credatuz = common.Date(time.Now().Unix(), "YYYYMMDDHHmmss")
|
|
if err = spodatatab.Insert(session); err != nil {
|
|
return
|
|
}
|
|
|
|
// 更新包装子项的实际已装运数 Fillqty
|
|
if spoitemtab, err = spoitemtab_match.SelectOneBySession(session); err != nil {
|
|
return
|
|
}
|
|
|
|
spoitemtab.Fillqty = len(spoitemtab.Itemlst)
|
|
|
|
// 对于未计划的发运单不更新发运单项的状态
|
|
if bl_sco.Spordtab.Status > common.SPO_STATUS_UNPLANNED {
|
|
if spoitemtab.Shortship > 0 && spoitemtab.Fillqty >= spoitemtab.Shortshipqty {
|
|
spoitemtab.Status = common.Max(spoitemtab.Status, common.SPO_STATUS_RELEASED)
|
|
}
|
|
if spoitemtab.Shortship <= 0 && spoitemtab.Fillqty >= spoitemtab.Planqty {
|
|
spoitemtab.Status = common.Max(spoitemtab.Status, common.SPO_STATUS_RELEASED)
|
|
}
|
|
}
|
|
|
|
spoitemtab.Lastmodif = common.Date(time.Now().Unix(), "YYYYMMDDHHmmss")
|
|
if err = spoitemtab.UpdateFields(session, "fillqty, status, lastmodif"); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取发运单数据
|
|
func (bl_sco *BL_ShipcarOrder) GetOrderDataBySession(session *xorm.Session) (err error) {
|
|
bl_sco.Spordtab.Shiporderid = bl_sco.Shiporderid
|
|
if bl_sco.Spordtab, err = bl_sco.Spordtab.SelectOneBySession(session); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|