diff --git a/src/main/java/com/jsh/dao/materials/DepotItemDAO.java b/src/main/java/com/jsh/dao/materials/DepotItemDAO.java index c285cc80..ec1d676b 100644 --- a/src/main/java/com/jsh/dao/materials/DepotItemDAO.java +++ b/src/main/java/com/jsh/dao/materials/DepotItemDAO.java @@ -61,6 +61,47 @@ public class DepotItemDAO extends BaseDAO implements DepotItemIDAO pageUtil.setPageList(query.list()); } + @SuppressWarnings("unchecked") + @Override + public void findPriceByType(PageUtil pageUtil,String type,Integer dId,Long MId,String MonthTime,Boolean isPrev) throws JshException + { + //多表联查,多表连查,此处用到了createSQLQuery,可以随便写sql语句,很方便 + Query query; + StringBuffer queryString = new StringBuffer(); + if(type.equals("入库")) { + if (isPrev) { + queryString.append("select sum(AllPrice) as AllPrice from jsh_depotitem di,jsh_depothead dh where di.HeaderId = dh.id "); + queryString.append(" and ((type='入库' and DepotId='" + dId + "') " + + " or (SubType='调拨' and AnotherDepotId='" + dId + "') " + + " or (SubType='礼品充值' and AnotherDepotId='" + dId + "')) "); + queryString.append(" and MaterialId =" + MId + " and dh.OperTime <'" + MonthTime + "-01 00:00:00' "); + query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); + } else { + queryString.append("select sum(AllPrice) as AllPrice from jsh_depotitem di,jsh_depothead dh where di.HeaderId = dh.id "); + queryString.append(" and ((type='入库' and DepotId='" + dId + "') " + + " or (SubType='调拨' and AnotherDepotId='" + dId + "') " + + " or (SubType='礼品充值' and AnotherDepotId='" + dId + "')) "); + queryString.append(" and MaterialId =" + MId + " and dh.OperTime >='" + MonthTime + "-01 00:00:00' and dh.OperTime <='" + MonthTime + "-31 59:59:59' "); + query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); + } + } + else { + if (isPrev) { + queryString.append("select sum(AllPrice) as AllPrice from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='出库'"); + queryString.append(" and DepotId='" + dId + "'"); + queryString.append(" and MaterialId =" + MId + " and jsh_depothead.OperTime <'" + MonthTime + "-01 00:00:00' "); + query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); + } else { + queryString.append("select sum(AllPrice) as AllPrice from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='出库'"); + queryString.append(" and DepotId='" + dId + "'"); + queryString.append(" and MaterialId =" + MId + " and jsh_depothead.OperTime >='" + MonthTime + "-01 00:00:00' and jsh_depothead.OperTime <='" + MonthTime + "-31 59:59:59' "); + query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); + } + } + pageUtil.setTotalCount(query.list().size()); + pageUtil.setPageList(query.list()); + } + @SuppressWarnings("unchecked") @Override public void findByTypeAndMaterialId(PageUtil pageUtil,String type,Long MId) throws JshException { @@ -103,32 +144,6 @@ public class DepotItemDAO extends BaseDAO implements DepotItemIDAO } pageUtil.setPageList(query.list()); } - - @SuppressWarnings("unchecked") - @Override - public void findPriceByType(PageUtil pageUtil,String type,Integer ProjectId,Long MId,String MonthTime,Boolean isPrev) throws JshException - { - //多表联查,多表连查,此处用到了createSQLQuery,可以随便写sql语句,很方便 - Query query; - StringBuffer queryString = new StringBuffer(); - if (isPrev) { - queryString.append("select sum(AllPrice) as AllPrice from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='" + type + "'"); - if (ProjectId != null) { - queryString.append(" and DepotId='" + ProjectId + "'"); - } - queryString.append(" and MaterialId =" + MId + " and jsh_depothead.OperTime <'" + MonthTime + "-01 00:00:00' "); - query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); - } else { - queryString.append("select sum(AllPrice) as AllPrice from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='" + type + "'"); - if (ProjectId != null) { - queryString.append(" and DepotId='" + ProjectId + "'"); - } - queryString.append(" and MaterialId =" + MId + " and jsh_depothead.OperTime >='" + MonthTime + "-01 00:00:00' and jsh_depothead.OperTime <='" + MonthTime + "-31 59:59:59' "); - query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); - } - pageUtil.setTotalCount(query.list().size()); - pageUtil.setPageList(query.list()); - } @SuppressWarnings("unchecked") @Override