|
|
@ -2,9 +2,6 @@ package com.app.service; |
|
|
|
|
|
|
|
|
|
|
|
import com.app.bean.Community; |
|
|
|
import com.app.bean.Community; |
|
|
|
import org.apache.log4j.Logger; |
|
|
|
import org.apache.log4j.Logger; |
|
|
|
import org.hibernate.criterion.DetachedCriteria; |
|
|
|
|
|
|
|
import org.hibernate.criterion.MatchMode; |
|
|
|
|
|
|
|
import org.hibernate.criterion.Restrictions; |
|
|
|
|
|
|
|
import org.hibernate.transform.Transformers; |
|
|
|
import org.hibernate.transform.Transformers; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.dao.DataAccessException; |
|
|
|
import org.springframework.dao.DataAccessException; |
|
|
@ -22,7 +19,7 @@ import java.util.List; |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public class CommunityServiceImpl implements CommunityService{ |
|
|
|
public class CommunityServiceImpl implements CommunityService{ |
|
|
|
|
|
|
|
|
|
|
|
private static Logger logger= Logger.getLogger(CommunityServiceImpl.class); |
|
|
|
private static final Logger logger= Logger.getLogger(CommunityServiceImpl.class); |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private HibernateTemplate hibernateTemplate; |
|
|
|
private HibernateTemplate hibernateTemplate; |
|
|
@ -70,22 +67,6 @@ public class CommunityServiceImpl implements CommunityService{ |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<Community> list(Community community,Integer type) { |
|
|
|
public List<Community> list(Community community,Integer type) { |
|
|
|
DetachedCriteria criteria= DetachedCriteria.forClass(Community.class); |
|
|
|
|
|
|
|
criteria.add(Restrictions.eq("type",type)); |
|
|
|
|
|
|
|
if(community!=null) { |
|
|
|
|
|
|
|
if (community.getName() != null && community.getName().length() > 0) { |
|
|
|
|
|
|
|
criteria.add(Restrictions.like("name", community.getName(), MatchMode.ANYWHERE)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (community.getPid() != null) { |
|
|
|
|
|
|
|
criteria.add(Restrictions.eq("pid", community.getPid())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (community.getCid() != null) { |
|
|
|
|
|
|
|
criteria.add(Restrictions.eq("cid", community.getCid())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (community.getAid() != null) { |
|
|
|
|
|
|
|
criteria.add(Restrictions.eq("aid", community.getAid())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuffer sql=new StringBuffer(); |
|
|
|
StringBuffer sql=new StringBuffer(); |
|
|
|
sql.append("select community.id,\n") |
|
|
|
sql.append("select community.id,\n") |
|
|
@ -110,7 +91,11 @@ public class CommunityServiceImpl implements CommunityService{ |
|
|
|
.append(" from community,\n") |
|
|
|
.append(" from community,\n") |
|
|
|
.append(" house\n") |
|
|
|
.append(" house\n") |
|
|
|
.append(" where community.id = house.community_id\n") |
|
|
|
.append(" where community.id = house.community_id\n") |
|
|
|
.append(" group by community.id) b\n") |
|
|
|
.append(" group by community.id\n") |
|
|
|
|
|
|
|
.append("union all\n") |
|
|
|
|
|
|
|
.append("select id,0,0\n") |
|
|
|
|
|
|
|
.append("from community\n") |
|
|
|
|
|
|
|
.append("where id not in(select community_id from house)) b\n") |
|
|
|
.append("where community.id = b.id"); |
|
|
|
.append("where community.id = b.id"); |
|
|
|
|
|
|
|
|
|
|
|
if(community!=null){ |
|
|
|
if(community!=null){ |
|
|
@ -121,9 +106,13 @@ public class CommunityServiceImpl implements CommunityService{ |
|
|
|
sql.append(" and community.pid=").append(community.getPid()); |
|
|
|
sql.append(" and community.pid=").append(community.getPid()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(community.getCid()!=null){ |
|
|
|
if(community.getCid()!=null){ |
|
|
|
|
|
|
|
sql.append(" and community.cid=").append(community.getCid()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(community.getAid()!=null){ |
|
|
|
sql.append(" and community.aid=").append(community.getAid()); |
|
|
|
sql.append(" and community.aid=").append(community.getAid()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sql.append(" and community.type=").append(type); |
|
|
|
|
|
|
|
|
|
|
|
List<Community> communities=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql.toString()).setResultTransformer(Transformers.aliasToBean(Community.class)).list(); |
|
|
|
List<Community> communities=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql.toString()).setResultTransformer(Transformers.aliasToBean(Community.class)).list(); |
|
|
|
|
|
|
|
|
|
|
|