package db
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/go-xorm/xorm"
|
|
"LAPP_PRN_Service/common"
|
|
"xorm.io/core"
|
|
)
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Struct Name : PrintDetail
|
|
*-----------------------------------------------------------------------------
|
|
*
|
|
* @Description : PrintDetail的实体映射
|
|
*
|
|
* @Author : lou wenzhi
|
|
*
|
|
* @Date : 2021-04-13 13:08:46
|
|
*
|
|
******************************************************************************/
|
|
type PrintDetail struct {
|
|
PlantNr int `xorm:"pk int 'PlantNr'" json:"PrintDetail-PlantNr"`
|
|
PrintHeadId string `xorm:"pk varchar(40) 'PrintHeadId'" json:"PrintDetail-PrintHeadId"`
|
|
Pos int `xorm:"pk smallint 'Pos'" json:"PrintDetail-Pos"`
|
|
VarName string `xorm:"varchar(18) 'VarName' not null" json:"PrintDetail-VarName"`
|
|
VarValue string `xorm:"varchar(40) 'VarValue' not null" json:"PrintDetail-VarValue"`
|
|
VarType string `xorm:"varchar(10) 'VarType' not null" json:"PrintDetail-VarType"`
|
|
VarPos string `xorm:"varchar(10) 'VarPos' not null" json:"PrintDetail-VarPos"`
|
|
LastModify common.DateTime `xorm:"datetime 'LastModify' not null updated" json:"PrintDetail-LastModify"`
|
|
LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"PrintDetail-LastUser"`
|
|
CreateTime common.DateTime `xorm:"datetime 'CreateTime' not null created" json:"PrintDetail-CreateTime"`
|
|
}
|
|
|
|
func (t *PrintDetail) TableName() string {
|
|
return "PrintDetail"
|
|
}
|
|
|
|
//增
|
|
func (t *PrintDetail) Add() error {
|
|
e := G_DbEngine
|
|
printdetailtab := new(PrintDetail)
|
|
affw, err := e.Table("PrintDetail").ID(core.PK{PlantNr, t.PrintHeadId, t.Pos}).Count(printdetailtab)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if affw > 0 {
|
|
return errors.New("数据已经存在!")
|
|
}
|
|
_, err = e.Table("PrintDetail").Insert(t)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
//增
|
|
func (t *PrintDetail) Insert(session *xorm.Session) error {
|
|
printdetailtab := new(PrintDetail)
|
|
affw, err := session.Table("PrintDetail").ID(core.PK{PlantNr, t.PrintHeadId, t.Pos}).Count(printdetailtab)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if affw > 0 {
|
|
return errors.New("数据已经存在!")
|
|
}
|
|
_, err = session.Table("PrintDetail").Insert(t)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
//删
|
|
func (t *PrintDetail) Del() bool {
|
|
e := G_DbEngine
|
|
_, err := e.ID(core.PK{PlantNr, t.PrintHeadId, t.Pos}).Delete(&PrintDetail{})
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
//改
|
|
func (t *PrintDetail) Update() bool {
|
|
e := G_DbEngine
|
|
_, err := e.ID(core.PK{PlantNr, t.PrintHeadId, t.Pos}).Update(t)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
//更新指定字段
|
|
func (t *PrintDetail) UpdateFields(session *xorm.Session, fields string) (err error) {
|
|
if _, err = session.Table("PrintDetail").ID(core.PK{PlantNr, t.PrintHeadId, t.Pos}).Cols(fields).Update(t); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//查
|
|
func (t *PrintDetail) SelectOne() (data PrintDetail, err error) {
|
|
e := G_DbEngine
|
|
_, err = e.ID(core.PK{PlantNr, t.PrintHeadId, t.Pos}).Get(&data)
|
|
if err != nil {
|
|
return data, err
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
//查询明细
|
|
func (t *PrintDetail) SelectAll() (data []PrintDetail, err error) {
|
|
e := G_DbEngine
|
|
err = e.ID(core.PK{PlantNr, t.PrintHeadId}).Find(&data)
|
|
if err != nil {
|
|
return data, err
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
//统计
|
|
func (t *PrintDetail) Sum(session *xorm.Session, pos []string) (int64, error) {
|
|
printdetailtab := new(PrintDetail)
|
|
total, err := session.Table("PrintDetail").In("Pos", pos).Where("PlantNr = ? and PrintHeadId = ?", PlantNr, t.PrintHeadId).SumInt(printdetailtab, "VarValue")
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return total, nil
|
|
}
|