@ -1,24 +1,29 @@
package models
import (
"encoding/json"
"errors"
"fmt"
"lapp_-wy/db"
"lapp_-wy/utils"
"xorm.io/core"
"errors"
)
//车位表
type Carporttab struct {
Cid int ` json:"cid" xorm:"not null pk INT(4)" `
Carportid string ` json:"carportid" xorm:"not null pk VARCHAR(100)" `
Descr string ` json:"descr" xorm:"VARCHAR(255)" `
Status int ` json:"status" xorm:"INT(4)" `
Propertyid string ` json:"propertyid" xorm:"VARCHAR(100)" `
Propertytypeid string ` json:"propertytypeid" xorm:"VARCHAR(100)" `
Createtime string ` json:"createtime" xorm:"VARCHAR(14)" `
Lastmodifytime string ` json:"lastmodifytime" xorm:"VARCHAR(20)" `
Lastmodifyby string ` json:"lastmodifyby" xorm:"VARCHAR(20)" `
Contractid string ` json:"contractid" xorm:"VARCHAR(100)" `
Cid int ` json:"cid" xorm:"not null pk INT(4)" `
Carportid string ` json:"carportid" xorm:"not null pk VARCHAR(100)" `
Descr string ` json:"descr" xorm:"VARCHAR(255)" `
Status int ` json:"status" xorm:"INT(4)" `
Propertyid string ` json:"propertyid" xorm:"VARCHAR(100)" `
Propertytypeid string ` json:"propertytypeid" xorm:"VARCHAR(100)" `
Createtime string ` json:"createtime" xorm:"VARCHAR(14)" `
Lastmodifytime string ` json:"lastmodifytime" xorm:"VARCHAR(20)" `
Lastmodifyby string ` json:"lastmodifyby" xorm:"VARCHAR(20)" `
Contractid string ` json:"contractid" xorm:"VARCHAR(100)" `
Contact string ` json:"contact" xorm:"VARCHAR(255)" `
Phone string ` json:"phone" xorm:"VARCHAR(64)" `
LicensePlateNumber string ` json:"licensePlateNumber" xorm:"VARCHAR(64) 'licensePlateNumber'" `
}
func ( t * Carporttab ) TableName ( ) string {
@ -72,10 +77,18 @@ func (t *Carporttab) Update() bool {
func ( t * Carporttab ) SelectOne ( ) ( Carporttab , error ) {
e := db . MasterEngine ( )
var data Carporttab
_ , err := e . ID ( core . PK { t . Cid , t . Carportid } ) . Get ( & data )
exist , err := e . ID ( core . PK { t . Cid , t . Carportid } ) . Get ( & data )
if err != nil {
return data , err
}
str , err := json . Marshal ( data )
if err != nil {
fmt . Println ( "marshal error:" , err )
}
fmt . Println ( "data:" , string ( str ) )
if ! exist {
return data , errors . New ( "不存在该车位数据,请检查" )
}
return data , nil
}
@ -112,90 +125,45 @@ type CarporttabInfo struct {
Propertytab ` xorm:"extends" `
Propertytypetab ` xorm:"extends" `
}
//车位费查询
func ( t * Carporttab ) Search ( buildingid string , unit string , room string ) ( data ContractInfo , err error ) {
func ( t * Carporttab ) Search ( ) ( data ContractInfo , err error ) {
//联查
e := db . MasterEngine ( )
if ! utils . ValueIsEmpty ( t . Carportid ) {
var info CarporttabContract
query := e . Table ( "carporttab" ) . Join ( "RIGHT" , "propertytab" , "carporttab.propertyid=propertytab.propertyid and carporttab.cid=propertytab.cid" ) . Join ( "LEFT" , "propertytypetab" , "carporttab.propertytypeid=propertytypetab.propertytypeid and carporttab.cid=propertytypetab.cid" ) . Join ( "LEFT" , "contracttab" , "carporttab.contractid=contracttab.contractid and carporttab.cid=contracttab.cid" ) . Where ( "carporttab.cid = ?" , t . Cid )
if ! utils . ValueIsEmpty ( buildingid ) {
query = query . And ( "propertytab.buildingid = ?" , buildingid )
}
if ! utils . ValueIsEmpty ( unit ) {
query = query . And ( "propertytab.unit = ?" , unit )
}
if ! utils . ValueIsEmpty ( room ) {
query = query . And ( "propertytab.room = ?" , room )
}
if ! utils . ValueIsEmpty ( t . Carportid ) {
query = query . And ( "carporttab.carportid = ?" , t . Carportid )
}
if utils . ValueIsEmpty ( info . Propertytab . Propertyid ) {
data . Propertyid = buildingid + "-" + unit + "-" + room
} else {
data . Propertyid = info . Propertytab . Propertyid
}
_ , err = query . Get ( & info )
if err != nil {
return data , err
}
data . Propertyid = info . Propertytab . Propertyid
data . Carportid = info . Carporttab . Carportid
data . Cid = info . Propertytab . Cid
data . Room = info . Propertytab . Room
data . Unit = info . Unit
data . Buildingid = info . Propertytab . Buildingid
data . Contractid = info . Propertytab . Contractid
data . Descr = info . Propertytab . Descr
data . Contact = info . Propertytab . Contact
data . Phone1 = info . Propertytab . Phone1
data . Phone2 = info . Propertytab . Phone2
data . Constructionarea = info . Propertytab . Constructionarea
data . Unitprice = info . Propertytypetab . Unitprice
data . Contracttab = info . Contracttab
data . Chargetype = 3
} else {
var info CarporttabInfo
query := e . Table ( "propertytab" ) . Join ( "LEFT" , "propertytypetab" , "propertytab.cid=propertytypetab.cid" ) . Where ( "propertytab.cid = ? and propertytypetab.propertytypeid = ?" , t . Cid , "车位费" )
if ! utils . ValueIsEmpty ( buildingid ) {
query = query . And ( "propertytab.buildingid = ?" , buildingid )
}
if ! utils . ValueIsEmpty ( unit ) {
query = query . And ( "propertytab.unit = ?" , unit )
}
if ! utils . ValueIsEmpty ( room ) {
query = query . And ( "propertytab.room = ?" , room )
}
if utils . ValueIsEmpty ( info . Propertytab . Propertyid ) {
data . Propertyid = buildingid + "-" + unit + "-" + room
} else {
data . Propertyid = info . Propertytab . Propertyid
}
_ , err = query . Get ( & info )
if err != nil {
return data , err
}
data . Propertyid = info . Propertytab . Propertyid
data . Cid = info . Propertytab . Cid
data . Room = info . Propertytab . Room
data . Unit = info . Unit
data . Buildingid = info . Propertytab . Buildingid
data . Contractid = info . Propertytab . Contractid
data . Descr = info . Propertytab . Descr
data . Contact = info . Propertytab . Contact
data . Phone1 = info . Propertytab . Phone1
data . Phone2 = info . Propertytab . Phone2
data . Constructionarea = info . Propertytab . Constructionarea
data . Unitprice = info . Propertytypetab . Unitprice
data . Chargetype = 3
var carport Carporttab
exist , err := e . Table ( t . TableName ( ) ) . ID ( core . PK { t . Cid , t . Carportid } ) . Get ( & carport )
if err != nil {
return data , err
}
if ! exist {
return data , errors . New ( "车位数据不存在,请检查" )
}
carPortIdList := make ( [ ] string , 0 )
err = e . Table ( t . TableName ( ) ) . Where ( "cid = ? and propertyid = ?" , t . Cid , t . Propertyid ) . Cols ( "carportid" ) . Find ( & carPortIdList )
var propertytype Propertytypetab
exist , err = e . Table ( propertytype . TableName ( ) ) . ID ( core . PK { t . Cid , carport . Propertytypeid } ) . Get ( & propertytype )
if err != nil {
return data , err
}
data . CarportidList = carPortIdList
if ! exist {
return data , errors . New ( "资产数据不存在,请检查" )
}
var property Propertytab
if carport . Propertyid != "" {
exist , err = e . Table ( property . TableName ( ) ) . ID ( core . PK { t . Cid , carport . Propertyid } ) . Get ( & property )
if err == nil && exist {
data . Room = property . Room
data . Unit = property . Unit
data . Buildingid = property . Buildingid
}
}
data . Carportid = carport . Carportid
data . Propertyid = carport . Propertyid
data . Cid = carport . Cid
data . Contractid = carport . Contractid
data . Descr = carport . Descr
data . Contact = carport . Contact
data . Phone1 = carport . Phone
data . Unitprice = propertytype . Unitprice
data . Chargetype = 3
return data , nil
}