1
This commit is contained in:
parent
9cf96cf800
commit
3ac5b2b0c3
3
app.go
3
app.go
@ -64,6 +64,8 @@ func (this *app) init(userApp UserApp) {
|
|||||||
_sysLog.init()
|
_sysLog.init()
|
||||||
_tgLog = new(TGLog_)
|
_tgLog = new(TGLog_)
|
||||||
_tgLog.init()
|
_tgLog.init()
|
||||||
|
_pageQuery = new (pageQuery)
|
||||||
|
_pageQuery.init()
|
||||||
_httpCliMgr = new(HttpCliMgr)
|
_httpCliMgr = new(HttpCliMgr)
|
||||||
_httpCliMgr.init()
|
_httpCliMgr.init()
|
||||||
{
|
{
|
||||||
@ -90,6 +92,7 @@ func (this *app) init(userApp UserApp) {
|
|||||||
func (this *app) unInit() {
|
func (this *app) unInit() {
|
||||||
this.chGoLoopTimerExit <- 1
|
this.chGoLoopTimerExit <- 1
|
||||||
_httpCliMgr.unInit()
|
_httpCliMgr.unInit()
|
||||||
|
_pageQuery.unInit()
|
||||||
_timer.unInit()
|
_timer.unInit()
|
||||||
_timer = nil
|
_timer = nil
|
||||||
this.userApp.UnInit()
|
this.userApp.UnInit()
|
||||||
|
56
pagequery.go
56
pagequery.go
@ -30,6 +30,7 @@ type PageQueryFilter interface {
|
|||||||
And() PageQueryFilter
|
And() PageQueryFilter
|
||||||
Or() PageQueryFilter
|
Or() PageQueryFilter
|
||||||
Not() PageQueryFilter
|
Not() PageQueryFilter
|
||||||
|
GetLinkOp() LinkOp
|
||||||
GenSql() string
|
GenSql() string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,11 +46,11 @@ type PageQueryOne struct {
|
|||||||
type PageQueryComp struct {
|
type PageQueryComp struct {
|
||||||
linkOp LinkOp
|
linkOp LinkOp
|
||||||
not bool
|
not bool
|
||||||
subFilters []*PageQueryOne
|
subFilters []PageQueryFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
type PageQueryParam struct {
|
type PageQueryParam struct {
|
||||||
Filter []PageQueryFilter
|
Filter *PageQueryComp
|
||||||
OrderBy string
|
OrderBy string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +63,13 @@ func (this *PageQueryParam) genSql() string {
|
|||||||
return sql
|
return sql
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) Like(fieldName string, val string) *PageQueryOne {
|
func (this *pageQuery) init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *pageQuery) unInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *pageQuery) Like(fieldName string, val string) PageQueryFilter {
|
||||||
f := &PageQueryOne{
|
f := &PageQueryOne{
|
||||||
cond: QC_LIKE,
|
cond: QC_LIKE,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
@ -70,7 +77,7 @@ func (this *pageQuery) Like(fieldName string, val string) *PageQueryOne {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) EQ(fieldName string, val string) *PageQueryOne {
|
func (this *pageQuery) EQ(fieldName string, val string) PageQueryFilter {
|
||||||
f := &PageQueryOne{
|
f := &PageQueryOne{
|
||||||
cond: QC_EQ,
|
cond: QC_EQ,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
@ -78,7 +85,7 @@ func (this *pageQuery) EQ(fieldName string, val string) *PageQueryOne {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) LT(fieldName string, val string) *PageQueryOne {
|
func (this *pageQuery) LT(fieldName string, val string) PageQueryFilter {
|
||||||
f := &PageQueryOne{
|
f := &PageQueryOne{
|
||||||
cond: QC_LT,
|
cond: QC_LT,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
@ -86,7 +93,7 @@ func (this *pageQuery) LT(fieldName string, val string) *PageQueryOne {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) LE(fieldName string, val string) *PageQueryOne {
|
func (this *pageQuery) LE(fieldName string, val string) PageQueryFilter {
|
||||||
f := &PageQueryOne{
|
f := &PageQueryOne{
|
||||||
cond: QC_LE,
|
cond: QC_LE,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
@ -94,7 +101,7 @@ func (this *pageQuery) LE(fieldName string, val string) *PageQueryOne {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) GT(fieldName string, val string) *PageQueryOne {
|
func (this *pageQuery) GT(fieldName string, val string) PageQueryFilter {
|
||||||
f := &PageQueryOne{
|
f := &PageQueryOne{
|
||||||
cond: QC_GT,
|
cond: QC_GT,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
@ -102,7 +109,7 @@ func (this *pageQuery) GT(fieldName string, val string) *PageQueryOne {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) GE(fieldName string, val string) *PageQueryOne {
|
func (this *pageQuery) GE(fieldName string, val string) PageQueryFilter {
|
||||||
f := &PageQueryOne{
|
f := &PageQueryOne{
|
||||||
cond: QC_GE,
|
cond: QC_GE,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
@ -110,7 +117,7 @@ func (this *pageQuery) GE(fieldName string, val string) *PageQueryOne {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) Custom(fieldName string, val string) *PageQueryOne {
|
func (this *pageQuery) Custom(fieldName string, val string) PageQueryFilter {
|
||||||
f := &PageQueryOne{
|
f := &PageQueryOne{
|
||||||
cond: QC_CUSTOM,
|
cond: QC_CUSTOM,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
@ -118,13 +125,13 @@ func (this *pageQuery) Custom(fieldName string, val string) *PageQueryOne {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *pageQuery) Comp(subFilters []*PageQueryOne) *PageQueryComp {
|
func (this *pageQuery) Comp(subFilters ...PageQueryFilter) PageQueryFilter {
|
||||||
f := &PageQueryComp{
|
f := &PageQueryComp{
|
||||||
subFilters: subFilters}
|
subFilters: subFilters}
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *PageQueryOne) IgnoreEmpy() *PageQueryOne {
|
func (this *PageQueryOne) IgnoreEmpy() PageQueryFilter {
|
||||||
this.ignoreEmpty = true
|
this.ignoreEmpty = true
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -145,6 +152,10 @@ func (this *PageQueryOne) Not() PageQueryFilter {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *PageQueryOne) GetLinkOp() LinkOp {
|
||||||
|
return this.linkOp
|
||||||
|
}
|
||||||
|
|
||||||
func (this *PageQueryOne) GenSql() string {
|
func (this *PageQueryOne) GenSql() string {
|
||||||
if this.ignoreEmpty && this.val == "" {
|
if this.ignoreEmpty && this.val == "" {
|
||||||
return " "
|
return " "
|
||||||
@ -169,11 +180,11 @@ func (this *PageQueryOne) GenSql() string {
|
|||||||
panic("page query cond error")
|
panic("page query cond error")
|
||||||
}
|
}
|
||||||
if this.not {
|
if this.not {
|
||||||
sql = fmt.Sprintf( "NOT (%s) ", sql)
|
sql = fmt.Sprintf(" NOT (%s) ", sql)
|
||||||
}
|
}
|
||||||
switch this.linkOp {
|
switch this.linkOp {
|
||||||
case LK_AND:
|
case LK_AND:
|
||||||
sql = fmt.Sprintf( "AND (%s) ", sql)
|
sql = fmt.Sprintf(" AND (%s) ", sql)
|
||||||
case LK_OR:
|
case LK_OR:
|
||||||
sql = fmt.Sprintf(" OR (%s) ", sql)
|
sql = fmt.Sprintf(" OR (%s) ", sql)
|
||||||
default:
|
default:
|
||||||
@ -197,20 +208,31 @@ func (this *PageQueryComp) Not() PageQueryFilter {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *PageQueryComp) GetLinkOp() LinkOp {
|
||||||
|
return this.linkOp
|
||||||
|
}
|
||||||
|
|
||||||
func (this *PageQueryComp) GenSql() string {
|
func (this *PageQueryComp) GenSql() string {
|
||||||
if len(this.subFilters) <= 0 {
|
if len(this.subFilters) <= 0 {
|
||||||
return " "
|
return " "
|
||||||
}
|
}
|
||||||
sql := ""
|
sql := " "
|
||||||
for _, filter := range this.subFilters {
|
for index, filter := range this.subFilters {
|
||||||
|
if index == 0 {
|
||||||
|
if filter.GetLinkOp() == LK_AND {
|
||||||
|
sql = " 1=1 "
|
||||||
|
} else {
|
||||||
|
sql = " 1<>1 "
|
||||||
|
}
|
||||||
|
}
|
||||||
sql += filter.GenSql()
|
sql += filter.GenSql()
|
||||||
}
|
}
|
||||||
if this.not {
|
if this.not {
|
||||||
sql = fmt.Sprintf( "NOT (%s) ", sql)
|
sql = fmt.Sprintf(" NOT (%s) ", sql)
|
||||||
}
|
}
|
||||||
switch this.linkOp {
|
switch this.linkOp {
|
||||||
case LK_AND:
|
case LK_AND:
|
||||||
sql = fmt.Sprintf( "AND (%s) ", sql)
|
sql = fmt.Sprintf(" AND (%s) ", sql)
|
||||||
case LK_OR:
|
case LK_OR:
|
||||||
sql = fmt.Sprintf(" OR (%s) ", sql)
|
sql = fmt.Sprintf(" OR (%s) ", sql)
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user