|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type FactoryOrd struct {
- Db *xorm.Engine `json:"db"`
- OutOrderNo string `json:"user_identity_id"`
- }
-
- func (factoryOrdOrdDb *FactoryOrd) Set(outOrderNo string) { // set方法
- factoryOrdOrdDb.Db = Db
- factoryOrdOrdDb.OutOrderNo = outOrderNo
- }
-
- func (factoryOrdOrdDb *FactoryOrd) GetFactoryOrdById(id int) (m *model.FactoryOrd, err error) {
- m = new(model.FactoryOrd)
- has, err := factoryOrdOrdDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (factoryOrdOrdDb *FactoryOrd) GetFactoryOrd() (m *model.FactoryOrd, err error) {
- m = new(model.FactoryOrd)
- has, err := factoryOrdOrdDb.Db.Where("out_order_no =?", factoryOrdOrdDb.OutOrderNo).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (factoryOrdOrdDb *FactoryOrd) FactoryOrdInsert(m *model.FactoryOrd) (int, error) {
- _, err := factoryOrdOrdDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (factoryOrdOrdDb *FactoryOrd) FactoryOrdInsertBySession(session *xorm.Session, m *model.FactoryOrd) (int, error) {
- _, err := session.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (factoryOrdOrdDb *FactoryOrd) BatchAddFactoryOrds(mm []*model.FactoryOrd) (int64, error) {
- affected, err := factoryOrdOrdDb.Db.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (factoryOrdOrdDb *FactoryOrd) FactoryOrdDeleteById(id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return Db.In("id", id).Delete(model.FactoryOrd{})
- } else {
- return Db.Where("id = ?", id).Delete(model.FactoryOrd{})
- }
- }
-
- func (factoryOrdOrdDb *FactoryOrd) FactoryOrdDelete() (int64, error) {
- return Db.Where("out_order_no = ?", factoryOrdOrdDb.OutOrderNo).Delete(model.FactoryOrd{})
- }
-
- func (factoryOrdOrdDb *FactoryOrd) FactoryOrdUpdate(m *model.FactoryOrd, forceColums ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColums != nil {
- affected, err = factoryOrdOrdDb.Db.Where("out_order_no=?", factoryOrdOrdDb.OutOrderNo).Cols(forceColums...).Update(m)
- } else {
- affected, err = factoryOrdOrdDb.Db.Where("out_order_no=?", factoryOrdOrdDb.OutOrderNo).Update(m)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- type FactoryOrdWithUserIdentity struct {
- model.FactoryOrd `xorm:"extends"`
- model.UserIdentity `xorm:"extends"`
- model.Enterprise `xorm:"extends"`
- model.User `xorm:"extends"`
- model.FactoryDevice `xorm:"extends"`
- }
-
- func (FactoryOrdWithUserIdentity) TableName() string {
- return "factory_ord"
- }
-
- type FactoryOrdWithUserIdentityV2 struct {
- model.FactoryOrd `xorm:"extends"`
- model.Enterprise `xorm:"extends"`
- }
-
- func (FactoryOrdWithUserIdentityV2) TableName() string {
- return "factory_ord"
- }
|