|
package db
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/go-xorm/xorm"
|
|
"leit.com/leit_seat_aps/common"
|
|
"xorm.io/core"
|
|
)
|
|
|
|
//生产订单生产包装状态
|
|
type Prod_wo_packstatus struct {
|
|
Finr int `xorm:"pk" json:"prod_wo_packstatus.finr"`
|
|
Workordernr string `xorm:"pk" json:"prod_wo_packstatus.workordernr"`
|
|
Projnr string `json:"prod_wo_packstatus.projnr"`
|
|
Packorderid string `json:"prod_wo_packstatus.packorderid"`
|
|
Packstatus int `json:"prod_wo_packstatus.packstatus"`
|
|
Status1 int `json:"prod_wo_packstatus.status1"`
|
|
Status2 int `json:"prod_wo_packstatus.status2"`
|
|
Lastmodif string `json:"prod_wo_packstatus.lastmodif"`
|
|
Lastuser string `json:"prod_wo_packstatus.lastuser"`
|
|
Credatuz string `json:"prod_wo_packstatus.credatuz"`
|
|
}
|
|
|
|
// 带生产包装状态的生产工单
|
|
type VWorkOrderPackStatus struct {
|
|
Pln_workorder `xorm:"extends"`
|
|
Prod_wo_packstatus `xorm:"extends"`
|
|
}
|
|
|
|
func (t *Prod_wo_packstatus) Clipped() {
|
|
common.TrimStruct(t, *t)
|
|
}
|
|
|
|
func (t *Prod_wo_packstatus) TableName() string {
|
|
return "prod_wo_packstatus"
|
|
}
|
|
|
|
//增
|
|
func (t *Prod_wo_packstatus) Add() error {
|
|
e := G_DbEngine
|
|
prodpakstatab := new(Prod_wo_packstatus)
|
|
affw, err := e.Table("prod_wo_packstatus").ID(core.PK{G_FINR, t.Workordernr}).Count(prodpakstatab)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if affw > 0 {
|
|
return errors.New("数据已经存在!")
|
|
}
|
|
_, err = e.Table("prod_wo_packstatus").Insert(t)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
//增
|
|
func (t *Prod_wo_packstatus) Insert(session *xorm.Session) error {
|
|
prodpakstatab := new(Prod_wo_packstatus)
|
|
affw, err := session.Table("prod_wo_packstatus").ID(core.PK{G_FINR, t.Workordernr}).Count(prodpakstatab)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if affw > 0 {
|
|
return errors.New("数据已经存在!")
|
|
}
|
|
_, err = session.Table("prod_wo_packstatus").Insert(t)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
//删
|
|
func (t *Prod_wo_packstatus) Del() bool {
|
|
e := G_DbEngine
|
|
_, err := e.ID(core.PK{G_FINR, t.Workordernr}).Delete(&Prod_wo_packstatus{})
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
//改
|
|
func (t *Prod_wo_packstatus) Update() bool {
|
|
e := G_DbEngine
|
|
_, err := e.ID(core.PK{G_FINR, t.Workordernr}).Update(t)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
//改
|
|
func (t *Prod_wo_packstatus) UpdateBySession(session *xorm.Session) bool {
|
|
_, err := session.ID(core.PK{G_FINR, t.Workordernr}).Update(t)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
//更新指定字段
|
|
func (t *Prod_wo_packstatus) UpdateFields(session *xorm.Session, fields string) (err error) {
|
|
if _, err = session.Table("prod_wo_packstatus").ID(core.PK{G_FINR, t.Workordernr}).Cols(fields).Update(t); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//查
|
|
func (t *Prod_wo_packstatus) SelectOne() (data Prod_wo_packstatus, err error) {
|
|
e := G_DbEngine
|
|
_, err = e.ID(core.PK{G_FINR, t.Workordernr}).Get(&data)
|
|
if err != nil {
|
|
return data, err
|
|
}
|
|
|
|
return data, nil
|
|
}
|
|
|
|
// 获取已下达未生产包装,类型为SEQ的生产订单
|
|
func (t *Prod_wo_packstatus) GetUnpackedWOByStartOemseq(startseq int, endseq int) (datalist []VWorkOrderPackStatus, err error) {
|
|
e := G_DbEngine
|
|
datalist = make([]VWorkOrderPackStatus, 0)
|
|
if endseq < startseq || endseq <= 0 {
|
|
if err = e.Table("pln_workorder").Alias("wo").Join("INNER", []string{"prod_wo_packstatus", "pkostat"},
|
|
"wo.finr = pkostat.finr and wo.workordernr = pkostat.workordernr and wo.projnr = pkostat.projnr").Where("wo.finr = ? and wo.ordertype = ? and wo.oemseq >= ? and wo.status >= ? and wo.status < ? and wo.shippable = ? and pkostat.packstatus = ?",
|
|
G_FINR, common.WO_TYPE_SEQ, startseq, common.WO_STATUS_RELEASED, common.WO_STATUS_CLOSED, 1, common.MESWO_UNPACK_STATUS).OrderBy("wo.oemseq, wo.worklineid").Find(&datalist); err != nil {
|
|
return
|
|
}
|
|
}else{
|
|
if err = e.Table("pln_workorder").Alias("wo").Join("INNER", []string{"prod_wo_packstatus", "pkostat"},
|
|
"wo.finr = pkostat.finr and wo.workordernr = pkostat.workordernr and wo.projnr = pkostat.projnr").Where("wo.finr = ? and wo.ordertype = ? and wo.oemseq >= ? and wo.oemseq <= ? and wo.status >= ? and wo.status < ? and wo.shippable = ? and pkostat.packstatus = ?",
|
|
G_FINR, common.WO_TYPE_SEQ, startseq, endseq, common.WO_STATUS_RELEASED, common.WO_STATUS_CLOSED, 1, common.MESWO_UNPACK_STATUS).OrderBy("wo.oemseq, wo.worklineid").Find(&datalist); err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|