|
|
- package models
-
- import (
- "lapp_-wy/db"
- "lapp_-wy/utils"
- "errors"
- "xorm.io/core"
- )
-
- type Assettab struct {
- Cid int `json:"cid" xorm:"not null pk INT(10)"`
- Assetid string `json:"assetid" xorm:"not null pk VARCHAR(40)"`
- Descr string `json:"descr" xorm:"default 'NULL' VARCHAR(255)"`
- Status int `json:"status" xorm:"default NULL INT(11)"`
- Brand string `json:"brand" xorm:"default 'NULL' VARCHAR(40)"`
- Model string `json:"model" xorm:"default 'NULL' VARCHAR(100)"`
- Qty int `json:"qty" xorm:"default NULL INT(11)"`
- User string `json:"user" xorm:"default 'NULL' VARCHAR(20)"`
- Department string `json:"department" xorm:"default 'NULL' VARCHAR(40)"`
- Os string `json:"os" xorm:"default 'NULL' VARCHAR(20)"`
- Vendor string `json:"vendor" xorm:"default 'NULL' VARCHAR(100)"`
- Installdate string `json:"installdate" xorm:"default 'NULL' VARCHAR(8)"`
- Spec1 string `json:"spec1" xorm:"default 'NULL' VARCHAR(40)"`
- Spec2 string `json:"spec2" xorm:"default 'NULL' VARCHAR(40)"`
- Spec3 string `json:"spec3" xorm:"default 'NULL' VARCHAR(40)"`
- Spec4 string `json:"spec4" xorm:"default 'NULL' VARCHAR(40)"`
- Createtime string `json:"createtime" xorm:"default 'NULL' VARCHAR(14)"`
- Lastmodifytime string `json:"lastmodifytime" xorm:"default 'NULL' VARCHAR(20)"`
- Lastmodifyby string `json:"lastmodifyby" xorm:"default 'NULL' VARCHAR(20)"`
- }
-
- func (t *Assettab) TableName() string {
- return "assettab"
- }
-
- // 清除string字段的右侧空格
- func (t *Assettab) Clipped() {
- utils.TrimStruct(t, *t)
- }
-
- //增
- func (t *Assettab) Add() error {
- e := db.MasterEngine()
- countrole := new(Assettab)
- affw, err := e.Table("assettab").ID(core.PK{t.Cid,t.Assetid}).Count(countrole)
- if err != nil {
- return err
- }
- if affw > 0 {
- return errors.New("数据已经存在!")
- }
- _, err = e.Table("assettab").Insert(t)
- if err != nil {
- return err
- }
- return nil
- }
-
- //删
- func (t *Assettab) Del() bool {
- e := db.MasterEngine()
- _, err := e.ID(core.PK{t.Cid,t.Assetid}).Delete(&Assettab{})
- if err != nil {
- return false
- }
- return true
- }
-
- //改
- func (t *Assettab) Update() bool {
- e := db.MasterEngine()
- _, err := e.ID(core.PK{t.Cid,t.Assetid}).Update(t)
- if err != nil {
- return false
- }
- return true
- }
-
- //查
- func (t *Assettab) SelectOne() (Assettab, error) {
- e := db.MasterEngine()
- var data Assettab
- _, err := e.ID(core.PK{t.Cid,t.Assetid}).Get(&data)
- if err != nil {
- return data, err
- }
- return data, nil
- }
-
- //分页
- func (t *Assettab) GetPage(pageSize int, pageIndex int) ([]Assettab, int, error) {
- data := make([]Assettab, 0)
- e := db.MasterEngine()
- query := e.Table("assettab").Where("cid = ? ", t.Cid)
- table := e.Table("assettab").Where("cid = ? ", t.Cid)
- if !utils.ValueIsEmpty(t.Descr) {
- descr := "%" + t.Descr + "%"
- query = query.And("descr like ?", descr)
- table = table.And("descr like ?", descr)
- }
- Offset := (pageIndex - 1) * pageSize
- err := query.Limit(pageSize,Offset).Desc("createtime").Find(&data)
- pcount := new(Assettab)
- count, err := table.Count(pcount)
- if err != nil {
- return data, 0, err
- }
- return data, int(count), nil
- }
|