SJA APS后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
3.8 KiB

package db
import (
"errors"
"github.com/go-xorm/xorm"
"leit.com/leit_seat_aps/common"
"xorm.io/core"
)
//打印头表
type Printheadtab struct {
Finr int `xorm:"pk"`
Printheadid string `xorm:"pk"`
Printerid string
Printfiletype string
Printobjid string
Printobjtype string
Status string
Templatefile string
Printcopies int
Printedtime string
Printedcopies int
Orientation int
Lastmodif string
Lastuser string
Credatuz string
Itemlst []Printdetailtab `xorm:"-"`
}
func (t *Printheadtab) Clipped() {
common.TrimStruct(t, *t)
}
func (t *Printheadtab) TableName() string {
return "printheadtab"
}
//增
func (t *Printheadtab) Add() error {
e := G_DbEngine
printheadtab := new(Printheadtab)
affw, err := e.Table("printheadtab").ID(core.PK{G_FINR, t.Printheadid}).Count(printheadtab)
if err != nil {
return err
}
if affw > 0 {
return errors.New("数据已经存在!")
}
_, err = e.Table("printheadtab").Insert(t)
if err != nil {
return err
}
return nil
}
//增
func (t *Printheadtab) Insert(session *xorm.Session) error {
printheadtab := new(Printheadtab)
affw, err := session.Table("printheadtab").ID(core.PK{G_FINR, t.Printheadid}).Count(printheadtab)
if err != nil {
return err
}
if affw > 0 {
return errors.New("数据已经存在!")
}
_, err = session.Table("printheadtab").Insert(t)
if err != nil {
return err
}
return nil
}
//删
func (t *Printheadtab) Del() bool {
e := G_DbEngine
_, err := e.ID(core.PK{G_FINR, t.Printheadid}).Delete(&Printheadtab{})
if err != nil {
return false
}
return true
}
//改
func (t *Printheadtab) Update() bool {
e := G_DbEngine
_, err := e.ID(core.PK{G_FINR, t.Printheadid}).Update(t)
if err != nil {
return false
}
return true
}
//更新指定字段
func (t *Printheadtab) UpdateFields(session *xorm.Session, fields string) (err error) {
if _, err = session.Table("printheadtab").ID(core.PK{G_FINR, t.Printheadid}).Cols(fields).Update(t); err != nil {
return
}
return
}
//查
func (t *Printheadtab) SelectOne() (data Printheadtab, err error) {
var (
i int
itemlst []Printdetailtab
)
e := G_DbEngine
_, err = e.ID(core.PK{G_FINR, t.Printheadid}).Get(&data)
if err != nil {
return
}
// 获取明细列表
data.Clipped()
if err = e.Where("finr = ? and printheadid = ?",
G_FINR, t.Printheadid).OrderBy("pos").Find(&itemlst); err != nil {
return
}
for i, _ = range itemlst {
itemlst[i].Clipped()
}
data.Itemlst = itemlst
return data, nil
}
// 获取指定类型的开口打印头
func (t *Printheadtab) GetOpenSheetOnes() (datalst []Printheadtab, err error) {
var (
i, j int
itemlst []Printdetailtab
statusarray []string
)
e := G_DbEngine
statusarray = make([]string, 2)
statusarray[0] = "N" // 新建
statusarray[1] = "R" // 重打
// 获取指定类型的开口打印头
if err = e.Where("finr = ? and printfiletype = ?",
G_FINR, "EXCEL").In("status", statusarray).Asc("credatuz").Find(&datalst); err != nil {
return
}
for i = 0; i < len(datalst); i++ {
datalst[i].Clipped()
// 获取明细列表
itemlst = []Printdetailtab{}
if err = e.Where("finr = ? and printheadid = ?",
G_FINR, t.Printheadid).OrderBy("pos").Find(&itemlst); err != nil {
return
}
for j = 0; j < len(itemlst); j++ {
itemlst[j].Clipped()
}
datalst[i].Itemlst = itemlst
}
return datalst, nil
}
//删除七天前的打印记录及其明细
func (t *Printheadtab) DelBefore7DayRecords(daytime string) bool {
e := G_DbEngine
_, err := e.Table("printheadtab").Where("fint = ? and credatuz < ?", G_FINR, daytime).Delete(&Printheadtab{})
if err != nil {
return false
}
_, err = e.Table("printdetailtab").Where("fint = ? and credatuz < ?", G_FINR, daytime).Delete(&Printdetailtab{})
if err != nil {
return false
}
return true
}