|
|
- package models
-
- import (
- "LAPP_LF_MOM_BACKEND/conf"
- "LAPP_LF_MOM_BACKEND/db"
- "LAPP_LF_MOM_BACKEND/utils"
- "errors"
- "log"
- "xorm.io/core"
- )
-
- type Printheadtab struct {
- Finr int `xorm:"not null pk comment('车间编号') INT(0)" json:"printheadtab-finr"`
- Printheadid string `xorm:"not null pk comment('打印信息头id') VARCHAR(40)" json:"printheadtab-printheadid"`
- Printerid string `xorm:"not null comment('打印机id') VARCHAR(18)" json:"printheadtab-printerid"`
- Printfiletype string `xorm:"not null comment('打印机文件类型') VARCHAR(10)" json:"printheadtab-printfiletype"`
- Printeventtype string `xorm:"not null comment('打印事件类型') VARCHAR(10)" json:"printheadtab-printeventtype"`
- Printobjid string `xorm:"not null comment('printheadtab.printobjid') VARCHAR(40)" json:"printheadtab-printobjid"`
- Printobjtype string `xorm:"not null comment('printheadtab.printobjtype') VARCHAR(12)" json:"printheadtab-printobjtype"`
- Status string `xorm:"not null comment('状态') VARCHAR(1)" json:"printheadtab-status"`
- Templatefile string `xorm:"not null comment('模板文件') VARCHAR(40)" json:"printheadtab-templatefile"`
- Termnr string `xorm:"not null comment('终端编号') VARCHAR(30)" json:"printheadtab-termnr"`
- Webaddress string `xorm:"not null comment('web地址') VARCHAR(40)" json:"printheadtab-webaddress"`
- Printcopies int `xorm:"not null comment('计划打印份数') INT(0)" json:"printheadtab-printcopies"`
- Printedtime string `xorm:"not null comment('实际打印时间') VARCHAR(14)" json:"printheadtab-printedtime"`
- Printedcopies int `xorm:"not null comment('已打印份数') INT(0)" json:"printheadtab-printedcopies"`
- Ival1 int `xorm:"not null comment('printhedtab.ival1') INT(0)" json:"printheadtab-ival1"`
- Ival2 int `xorm:"not null comment('printhedtab.ival2') INT(0)" json:"printheadtab-ival2"`
- Cval1 string `xorm:"not null comment('printhedtab.cval1') VARCHAR(60)" json:"printheadtab-cval1"`
- Cval2 string `xorm:"not null comment('printhedtab.cval2') VARCHAR(60)" json:"printheadtab-cval2"`
- Lastmodif string `xorm:"not null comment('上一次更改日期') VARCHAR(14)" json:"printheadtab-lastmodif"`
- Lastuser string `xorm:"not null comment('最近编辑人员') VARCHAR(20)" json:"printheadtab-lastuser"`
- Createdby string `xorm:"not null comment('创建者') VARCHAR(20)" json:"printheadtab-createdby"`
- Credatuz string `xorm:"not null comment('创建时间') VARCHAR(14)" json:"printheadtab-credatuz"`
- }
-
-
- func (t *Printheadtab) TableName() string {
- return "printheadtab"
- }
-
- // 清除string字段的右侧空格
- func (t *Printheadtab) Clipped() {
- utils.TrimStruct(t, *t)
- }
-
- //增
- func (t *Printheadtab) Add() error {
- e := db.Eloquent.Master()
- countrole := new(Printheadtab)
- affw, err := e.Table("printheadtab").ID(core.PK{t.Finr, t.Printheadid}).Count(countrole)
- 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) Del() bool {
- e := db.Eloquent.Master()
- _, err := e.ID(core.PK{t.Finr, t.Printheadid}).Delete(&Printheadtab{})
- if err != nil {
- return false
- }
- return true
- }
-
- //改
- func (t *Printheadtab) Update() bool {
- e := db.Eloquent.Master()
- _, err := e.ID(core.PK{t.Finr, t.Printheadid}).Update(t)
- if err != nil {
- return false
- }
- return true
- }
-
- //查
- func (t *Printheadtab) SelectOne() (Printheadtab, error) {
- e := db.Eloquent.Master()
- var data Printheadtab
- _, err := e.ID(core.PK{t.Finr, t.Printheadid}).Get(&data)
- if err != nil {
- return data, err
- }
- return data, nil
- }
-
- //分页
- func (t *Printheadtab) GetPage(pageSize int, pageIndex int) ([]Printheadtab, int, error) {
- data := make([]Printheadtab, 0)
- e := db.Eloquent.Master()
- table := e.Table("printheadtab").Where("finr = ? ", t.Finr)
- where := "where finr = " + "'" + utils.ValueToString(t.Finr, "") + "'"
- if !utils.ValueIsEmpty(t.Printheadid) {
- table = table.And("printheadid = ?", t.Printheadid)
- where += " and printheadid = " + "'" + t.Printheadid + "'"
- }
- Offset := (pageIndex - 1) * pageSize
- err := e.SQL("SELECT TOP " + utils.ValueToString(pageSize, "") + " printheadtab.* FROM printheadtab " + where + " AND (convert(varchar(10),finr)+convert(varchar(40),printheadid) NOT IN (SELECT TOP " + utils.ValueToString(Offset, "") + " convert(varchar(10),finr)+convert(varchar(40),printheadid) FROM printheadtab " + where + " ORDER BY credatuz DESC)) ORDER BY credatuz DESC").Find(&data)
- pcount := new(Printheadtab)
- count, err := table.Count(pcount)
- if err != nil {
- return data, 0, err
- }
- for k, _ := range data {
- data[k].Clipped()
- }
- return data, int(count), nil
- }
-
- func (t *Printheadtab) GetPrintheadList(conf *conf.EnvConfig) ( []Printheadtab, error ) {
- var printheadlist []Printheadtab
- e := db.Eloquent.Master()
- // 获取所有开口的打印任务头
- err := e.Where("finr = ? and status = ?",conf.Finr, "N").Find(&printheadlist)
- if err != nil{
- log.Printf("failed to query printheadtab due to: %v", err)
- return nil, err
- }
-
- return printheadlist, nil
- }
|