grails createCriteria,createAlias创建左连接查询 grailscreateCriteriacreateAliasleft
程序员文章站
2022-03-24 13:35:48
...
def QueryResult findAllInOutStock(String manInfoName,String supplieName,String wareName,
Integer category,Integer inOutType,Date beginTime,
Date endTime,Integer offset,Integer max){
def list=TbInoutStock.createCriteria().list {
//createAlias 第三个参数控制链接,
//0:表示inner join,
//1:表示left outer join ,
//2:表示right outer join
createAlias("manufacturers", "manufacturers",1)
if(manInfoName!=null && !"".equals(manInfoName)){
like("manufacturers.fullName","%"+manInfoName+"%")
}
if(supplieName!=null && !"".equals(supplieName)){
createAlias("selfSupplieInfo","selfSupplieInfo",1)
createAlias("supplier","supplier",1)
or {
like("selfSupplieInfo.fullName","%"+supplieName+"%")
like("supplier.fullName","%"+supplieName+"%")
}
}
if(wareName!=null &&!"".equals(wareName)){
createAlias("ware","ware",1)
like("ware.fullName","%"+wareName+"%")
}
if(category!=null){
eq("manufacturers.category",category)
}
if(inOutType!=null){
eq("inOutType",inOutType)
}
if(beginTime!=null){
gte("inOutDate",beginTime)
}
if(endTime!=null){
lt("inOutDate",endTime)
}
eq("status",1)
if(offset){
firstResult(offset)
}
if(max){
maxResults(max)
}
order("inOutDate","desc")
}
def totalCount=TbInoutStock.createCriteria().count{
createAlias("manufacturers", "manufacturers",1)
if(manInfoName!=null && !"".equals(manInfoName)){
like("manufacturers.fullName","%"+manInfoName+"%")
}
if(supplieName!=null && !"".equals(supplieName)){
createAlias("selfSupplieInfo","selfSupplieInfo",1)
createAlias("supplier","supplier",1)
or {
like("selfSupplieInfo.fullName","%"+supplieName+"%")
like("supplier.fullName","%"+supplieName+"%")
}
}
if(wareName!=null &&!"".equals(wareName)){
createAlias("ware","ware",1)
like("ware.fullName","%"+wareName+"%")
}
if(category!=null){
eq("manufacturers.category",category)
}
if(inOutType!=null){
eq("inOutType",inOutType)
}
if(beginTime!=null){
gte("inOutDate",beginTime)
}
if(endTime!=null){
lt("inOutDate",endTime)
}
eq("status",1)
}
QueryResult queryResult=new QueryResult()
queryResult.list=list
queryResult.totalCount=totalCount
return queryResult
}
Integer category,Integer inOutType,Date beginTime,
Date endTime,Integer offset,Integer max){
def list=TbInoutStock.createCriteria().list {
//createAlias 第三个参数控制链接,
//0:表示inner join,
//1:表示left outer join ,
//2:表示right outer join
createAlias("manufacturers", "manufacturers",1)
if(manInfoName!=null && !"".equals(manInfoName)){
like("manufacturers.fullName","%"+manInfoName+"%")
}
if(supplieName!=null && !"".equals(supplieName)){
createAlias("selfSupplieInfo","selfSupplieInfo",1)
createAlias("supplier","supplier",1)
or {
like("selfSupplieInfo.fullName","%"+supplieName+"%")
like("supplier.fullName","%"+supplieName+"%")
}
}
if(wareName!=null &&!"".equals(wareName)){
createAlias("ware","ware",1)
like("ware.fullName","%"+wareName+"%")
}
if(category!=null){
eq("manufacturers.category",category)
}
if(inOutType!=null){
eq("inOutType",inOutType)
}
if(beginTime!=null){
gte("inOutDate",beginTime)
}
if(endTime!=null){
lt("inOutDate",endTime)
}
eq("status",1)
if(offset){
firstResult(offset)
}
if(max){
maxResults(max)
}
order("inOutDate","desc")
}
def totalCount=TbInoutStock.createCriteria().count{
createAlias("manufacturers", "manufacturers",1)
if(manInfoName!=null && !"".equals(manInfoName)){
like("manufacturers.fullName","%"+manInfoName+"%")
}
if(supplieName!=null && !"".equals(supplieName)){
createAlias("selfSupplieInfo","selfSupplieInfo",1)
createAlias("supplier","supplier",1)
or {
like("selfSupplieInfo.fullName","%"+supplieName+"%")
like("supplier.fullName","%"+supplieName+"%")
}
}
if(wareName!=null &&!"".equals(wareName)){
createAlias("ware","ware",1)
like("ware.fullName","%"+wareName+"%")
}
if(category!=null){
eq("manufacturers.category",category)
}
if(inOutType!=null){
eq("inOutType",inOutType)
}
if(beginTime!=null){
gte("inOutDate",beginTime)
}
if(endTime!=null){
lt("inOutDate",endTime)
}
eq("status",1)
}
QueryResult queryResult=new QueryResult()
queryResult.list=list
queryResult.totalCount=totalCount
return queryResult
}