This commit is contained in:
azw 2023-08-20 13:07:00 +08:00
parent 9cf96cf800
commit 3ac5b2b0c3
2 changed files with 42 additions and 17 deletions

3
app.go
View File

@ -64,6 +64,8 @@ func (this *app) init(userApp UserApp) {
_sysLog.init()
_tgLog = new(TGLog_)
_tgLog.init()
_pageQuery = new (pageQuery)
_pageQuery.init()
_httpCliMgr = new(HttpCliMgr)
_httpCliMgr.init()
{
@ -90,6 +92,7 @@ func (this *app) init(userApp UserApp) {
func (this *app) unInit() {
this.chGoLoopTimerExit <- 1
_httpCliMgr.unInit()
_pageQuery.unInit()
_timer.unInit()
_timer = nil
this.userApp.UnInit()

View File

@ -30,6 +30,7 @@ type PageQueryFilter interface {
And() PageQueryFilter
Or() PageQueryFilter
Not() PageQueryFilter
GetLinkOp() LinkOp
GenSql() string
}
@ -45,11 +46,11 @@ type PageQueryOne struct {
type PageQueryComp struct {
linkOp LinkOp
not bool
subFilters []*PageQueryOne
subFilters []PageQueryFilter
}
type PageQueryParam struct {
Filter []PageQueryFilter
Filter *PageQueryComp
OrderBy string
}
@ -62,7 +63,13 @@ func (this *PageQueryParam) genSql() string {
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{
cond: QC_LIKE,
fieldName: fieldName,
@ -70,7 +77,7 @@ func (this *pageQuery) Like(fieldName string, val string) *PageQueryOne {
return f
}
func (this *pageQuery) EQ(fieldName string, val string) *PageQueryOne {
func (this *pageQuery) EQ(fieldName string, val string) PageQueryFilter {
f := &PageQueryOne{
cond: QC_EQ,
fieldName: fieldName,
@ -78,7 +85,7 @@ func (this *pageQuery) EQ(fieldName string, val string) *PageQueryOne {
return f
}
func (this *pageQuery) LT(fieldName string, val string) *PageQueryOne {
func (this *pageQuery) LT(fieldName string, val string) PageQueryFilter {
f := &PageQueryOne{
cond: QC_LT,
fieldName: fieldName,
@ -86,7 +93,7 @@ func (this *pageQuery) LT(fieldName string, val string) *PageQueryOne {
return f
}
func (this *pageQuery) LE(fieldName string, val string) *PageQueryOne {
func (this *pageQuery) LE(fieldName string, val string) PageQueryFilter {
f := &PageQueryOne{
cond: QC_LE,
fieldName: fieldName,
@ -94,7 +101,7 @@ func (this *pageQuery) LE(fieldName string, val string) *PageQueryOne {
return f
}
func (this *pageQuery) GT(fieldName string, val string) *PageQueryOne {
func (this *pageQuery) GT(fieldName string, val string) PageQueryFilter {
f := &PageQueryOne{
cond: QC_GT,
fieldName: fieldName,
@ -102,7 +109,7 @@ func (this *pageQuery) GT(fieldName string, val string) *PageQueryOne {
return f
}
func (this *pageQuery) GE(fieldName string, val string) *PageQueryOne {
func (this *pageQuery) GE(fieldName string, val string) PageQueryFilter {
f := &PageQueryOne{
cond: QC_GE,
fieldName: fieldName,
@ -110,7 +117,7 @@ func (this *pageQuery) GE(fieldName string, val string) *PageQueryOne {
return f
}
func (this *pageQuery) Custom(fieldName string, val string) *PageQueryOne {
func (this *pageQuery) Custom(fieldName string, val string) PageQueryFilter {
f := &PageQueryOne{
cond: QC_CUSTOM,
fieldName: fieldName,
@ -118,13 +125,13 @@ func (this *pageQuery) Custom(fieldName string, val string) *PageQueryOne {
return f
}
func (this *pageQuery) Comp(subFilters []*PageQueryOne) *PageQueryComp {
func (this *pageQuery) Comp(subFilters ...PageQueryFilter) PageQueryFilter {
f := &PageQueryComp{
subFilters: subFilters}
return f
}
func (this *PageQueryOne) IgnoreEmpy() *PageQueryOne {
func (this *PageQueryOne) IgnoreEmpy() PageQueryFilter {
this.ignoreEmpty = true
return this
}
@ -145,6 +152,10 @@ func (this *PageQueryOne) Not() PageQueryFilter {
return this
}
func (this *PageQueryOne) GetLinkOp() LinkOp {
return this.linkOp
}
func (this *PageQueryOne) GenSql() string {
if this.ignoreEmpty && this.val == "" {
return " "
@ -169,11 +180,11 @@ func (this *PageQueryOne) GenSql() string {
panic("page query cond error")
}
if this.not {
sql = fmt.Sprintf( "NOT (%s) ", sql)
sql = fmt.Sprintf(" NOT (%s) ", sql)
}
switch this.linkOp {
case LK_AND:
sql = fmt.Sprintf( "AND (%s) ", sql)
sql = fmt.Sprintf(" AND (%s) ", sql)
case LK_OR:
sql = fmt.Sprintf(" OR (%s) ", sql)
default:
@ -197,20 +208,31 @@ func (this *PageQueryComp) Not() PageQueryFilter {
return this
}
func (this *PageQueryComp) GetLinkOp() LinkOp {
return this.linkOp
}
func (this *PageQueryComp) GenSql() string {
if len(this.subFilters) <= 0 {
return " "
}
sql := ""
for _, filter := range this.subFilters {
sql := " "
for index, filter := range this.subFilters {
if index == 0 {
if filter.GetLinkOp() == LK_AND {
sql = " 1=1 "
} else {
sql = " 1<>1 "
}
}
sql += filter.GenSql()
}
if this.not {
sql = fmt.Sprintf( "NOT (%s) ", sql)
sql = fmt.Sprintf(" NOT (%s) ", sql)
}
switch this.linkOp {
case LK_AND:
sql = fmt.Sprintf( "AND (%s) ", sql)
sql = fmt.Sprintf(" AND (%s) ", sql)
case LK_OR:
sql = fmt.Sprintf(" OR (%s) ", sql)
default: