From 3ea3e6ac0db260b46aa262bc2ab33d8ab8860b86 Mon Sep 17 00:00:00 2001
From: hdw <496960745@qq.com>
Date: 星期一, 29 十月 2018 14:36:24 +0800
Subject: [PATCH] Merge branch 'dev_lxw' of https://whychdw@gitlab.com/whyclxw1/gx_tieta.git into dev_lxw

---
 gx_tieta/src/com/fgkj/dao/impl/StationtrafficImpl.java |  167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 167 insertions(+), 0 deletions(-)

diff --git a/gx_tieta/src/com/fgkj/dao/impl/StationtrafficImpl.java b/gx_tieta/src/com/fgkj/dao/impl/StationtrafficImpl.java
new file mode 100644
index 0000000..4cbec20
--- /dev/null
+++ b/gx_tieta/src/com/fgkj/dao/impl/StationtrafficImpl.java
@@ -0,0 +1,167 @@
+package com.fgkj.dao.impl;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import com.fgkj.actions.ActionUtil;
+import com.fgkj.dao.BaseDAO;
+import com.fgkj.dao.CallBack;
+import com.fgkj.dao.DAOHelper;
+import com.fgkj.db.DBUtil;
+import com.fgkj.dto.Stationtraffic;
+import com.sun.org.apache.bcel.internal.generic.IINC;
+
+public class StationtrafficImpl implements BaseDAO,CallBack{
+
+	public List getResults(ResultSet rs) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public boolean add(Object obj) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	public boolean update(Object obj) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	public boolean del(Object obj) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	public List searchAll() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+    //缁熻鍩虹珯娴侀噺
+	public List serchByCondition(Object obj) {
+		final Stationtraffic straffic=(Stationtraffic) obj;
+		String sql=" select distinct tb_stationtraffic.num,dev_id,record_time,dayflow,nowflow" +
+				"  ,tb_battinf.StationId,tb_battinf.stationName,tb_battinf.stationName1,tb_battinf.stationName2,tb_battinf.stationName3,tb_battinf.stationName5 " +
+				"  from web_site.tb_stationtraffic,db_battinf.tb_battinf " +
+				"  where web_site.tb_stationtraffic.dev_id=db_battinf.tb_battinf.fBSDeviceId  " +
+				"  and record_time>? and record_time<? " +
+				"  and dev_id=? " ;
+		//鐢ㄦ埛绠$悊
+		String userSql=" and db_battinf.tb_battinf.StationId in(" +
+				" select distinct db_user.tb_user_battgroup_baojigroup_battgroup.StationId from db_user.tb_user_battgroup_baojigroup_battgroup,db_user.tb_user_battgroup_baojigroup_usr where db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id=db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id  and db_user.tb_user_battgroup_baojigroup_usr.uId=? "+
+				" ) ";		
+		sql+=userSql;
+		String orderSql="  order by dev_id,record_time asc ";
+		sql+=orderSql;
+		List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{straffic.getRecord_time(),straffic.getRecord_time1(),straffic.getDev_id(),Integer.parseInt(straffic.getNote())}, new CallBack() {
+			
+			public List getResults(ResultSet rs) {
+				List list=new ArrayList();
+				// 鏃堕棿娈�
+				String perid_Time = ""; 
+				Calendar now = Calendar.getInstance();
+				int nowflow=0;
+				try {
+					while(rs.next()){
+						
+						int nowflows=rs.getInt("nowflow");
+						// 骞翠唤锛屽搴︼紝鏈堜唤
+						Date dev_recordtime = rs.getTimestamp("record_time");
+						// 鑾峰彇鍏蜂綋骞翠唤锛屾湀浠藉拰璇ユ湀鐨勬�诲ぉ鏁�
+						/*int year = dev_recordtime.getYear() + 1900;
+						int month = dev_recordtime.getMonth() + 1;*/
+						now.setTime(dev_recordtime);
+						int year = now.get(Calendar.YEAR);
+				        int month = now.get(Calendar.MONTH) + 1; // 0-based!
+				        int day = now.get(Calendar.DAY_OF_MONTH);
+						//System.out.println(dev_recordtime+"   "+day);
+						String perid_Times="";
+                        if(straffic.getNum()==1){//鏈堢粺璁�
+                        	perid_Times = ActionUtil.getFirstDayOfMonth(year, month - 1);
+        					perid_Times += "~";
+        					perid_Times += ActionUtil.getLastDayOfMonth(year, month - 1);
+						}else if (straffic.getNum()==3) {// 鎸夊勾浠�
+							perid_Times = ActionUtil.getFirstDayOfMonth(year, 0);
+							perid_Times += "~";
+							perid_Times += ActionUtil.getLastDayOfMonth(year, 11);
+						}else if(straffic.getNum()==2){ //鏃ョ粺璁�
+							perid_Times = ActionUtil.getDayTime(year, month-1, day, 1);
+        					perid_Times += "~";
+        					perid_Times += ActionUtil.getDayTime(year, month-1, day, 4);
+						}
+                        //System.out.println(perid_Times+" "+perid_Time+" "+nowflows);
+						if(perid_Times.equals(perid_Time)){
+							nowflow+=nowflows;
+						}else{
+							if(perid_Time.equals("")){
+							     perid_Time=perid_Times;
+							     nowflow+=nowflows;
+							     continue;
+							}
+							Stationtraffic st=new Stationtraffic();
+							st.setDev_id(rs.getInt("dev_id"));
+							st.setNowflow(nowflow);
+							st.setStationName(rs.getString("stationName"));
+							st.setStationName1(rs.getString("stationName1"));
+							st.setStationName2(rs.getString("stationName2"));
+							st.setStationName3(rs.getString("stationName3"));
+							st.setStationName5(rs.getString("stationName5"));
+							st.setNote(perid_Time);
+							list.add(st);
+							nowflow=0;
+							nowflow+=nowflows;
+							perid_Time=perid_Times;
+							
+						}
+					if(rs.isLast()){
+						Stationtraffic st=new Stationtraffic();
+						st.setDev_id(rs.getInt("dev_id"));
+						st.setNowflow(nowflow);
+						st.setStationName(rs.getString("stationName"));
+						st.setStationName1(rs.getString("stationName1"));
+						st.setStationName2(rs.getString("stationName2"));
+						st.setStationName3(rs.getString("stationName3"));
+						st.setStationName5(rs.getString("stationName5"));
+						st.setNote(perid_Time);
+						list.add(st);
+					}
+					}
+					
+				} catch (SQLException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				return list;
+			}
+		});
+		return list;
+	}
+
+	public List serchByInfo(Object obj) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+   public static void main(String[] args) throws ParseException {
+	     StationtrafficImpl simpl=new StationtrafficImpl();
+	     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		 Date date1 = sdf.parse("2000-01-01 00:00:00");
+		 Date date2 = sdf.parse("2020-01-01 00:00:00");
+		 
+	     Stationtraffic st=new Stationtraffic();
+	     st.setNum(3);
+	     st.setDev_id(910000001);
+	     st.setNote("1002");
+	     st.setRecord_time(ActionUtil.getSimpDate(date1));
+	     st.setRecord_time1(ActionUtil.getSimpDate(date2));
+	     List<Stationtraffic> list=simpl.serchByCondition(st);
+	     for (Stationtraffic s : list) {
+			System.out.println(s);
+		}
+}
+}

--
Gitblit v1.9.1