package models
|
|
|
|
import (
|
|
"lapp_-wy/db"
|
|
"lapp_-wy/utils"
|
|
"errors"
|
|
"xorm.io/core"
|
|
)
|
|
|
|
type Buildingtab struct {
|
|
Cid int `json:"cid" xorm:"not null pk INT(4)"`
|
|
Buildingid string `json:"buildingid" xorm:"not null pk VARCHAR(100)"`
|
|
Descr string `json:"descr" xorm:"VARCHAR(255)"`
|
|
Address string `json:"address" xorm:"VARCHAR(255)"`
|
|
Constructionarea float64 `json:"constructionarea" xorm:"DECIMAL(10,2)"`
|
|
Totalhouseholds int `json:"totalhouseholds" xorm:"INT(4)"`
|
|
Propertytypeid string `json:"propertytypeid" xorm:"VARCHAR(100)"`
|
|
Createtime string `json:"createtime" xorm:"VARCHAR(14)"`
|
|
Lastmodifytime string `json:"lastmodifytime" xorm:"VARCHAR(14)"`
|
|
Lastmodifyby string `json:"lastmodifyby" xorm:"VARCHAR(40)"`
|
|
}
|
|
|
|
func (t *Buildingtab) TableName() string {
|
|
return "buildingtab"
|
|
}
|
|
|
|
// 清除string字段的右侧空格
|
|
func (t *Buildingtab) Clipped() {
|
|
utils.TrimStruct(t, *t)
|
|
}
|
|
|
|
//增
|
|
func (t *Buildingtab) Add() error {
|
|
e := db.MasterEngine()
|
|
countrole := new(Buildingtab)
|
|
affw, err := e.Table("buildingtab").ID(core.PK{t.Cid, t.Buildingid}).Count(countrole)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if affw > 0 {
|
|
return errors.New("数据已经存在!")
|
|
}
|
|
_, err = e.Table("buildingtab").Insert(t)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
//删
|
|
func (t *Buildingtab) Del() bool {
|
|
e := db.MasterEngine()
|
|
_, err := e.ID(core.PK{t.Cid, t.Buildingid}).Delete(&Buildingtab{})
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
//改
|
|
func (t *Buildingtab) Update() bool {
|
|
e := db.MasterEngine()
|
|
_, err := e.ID(core.PK{t.Cid, t.Buildingid}).Update(t)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
//查
|
|
func (t *Buildingtab) SelectOne() (Buildingtab, error) {
|
|
e := db.MasterEngine()
|
|
var data Buildingtab
|
|
_, err := e.ID(core.PK{t.Cid, t.Buildingid}).Get(&data)
|
|
if err != nil {
|
|
return data, err
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
//分页
|
|
func (t *Buildingtab) GetPage(pageSize int, pageIndex int) ([]Buildingtab, int, error) {
|
|
data := make([]Buildingtab, 0)
|
|
e := db.MasterEngine()
|
|
query := e.Table("buildingtab").Where("cid = ? ", t.Cid)
|
|
table := e.Table("buildingtab").Where("cid = ? ", t.Cid)
|
|
if !utils.ValueIsEmpty(t.Descr) {
|
|
descr := "%" + t.Descr + "%"
|
|
query = query.And("descr like ?", descr)
|
|
table = query.And("descr like ?", descr)
|
|
}
|
|
Offset := (pageIndex - 1) * pageSize
|
|
err := query.Limit(pageSize,Offset).Desc("createtime").Find(&data)
|
|
pcount := new(Buildingtab)
|
|
count, err := table.Count(pcount)
|
|
if err != nil {
|
|
return data, 0, err
|
|
}
|
|
return data, int(count), nil
|
|
}
|
|
|
|
//查询所有
|
|
func (t *Buildingtab) SelectAll() ([]*Buildingtab, error) {
|
|
e := db.MasterEngine()
|
|
data := make([]*Buildingtab, 0)
|
|
|
|
err := e.Where("cid = ?", t.Cid).Find(&data)
|
|
if err != nil {
|
|
return data, err
|
|
}
|
|
return data, nil
|
|
}
|