From 052af95bb3f36297de918cfac8df143f92dd6d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Fri, 3 Nov 2017 00:23:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BA=93=E5=AD=98=E7=8A=B6?= =?UTF-8?q?=E5=86=B5=E6=8A=A5=E8=A1=A8=E7=9A=84=E6=95=B0=E6=8D=AE=EF=BC=88?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jsh/dao/materials/DepotItemDAO.java | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) 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