package com.his.service;
/*
* Copyright 2005 Joe Walker
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.directwebremoting.util.Logger;
import com.his.common.DBManage;
/**
* A container for a set of people
*
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class Messages {
Connection con = null;
/**
* Pre-populate with random people
*/
public Messages() {
con = DBManage.getConnection();
}
public Set getDepartsments() {
Set departments = new HashSet();
String sql = "select * from department";
try {
PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
Department department = new Department();
department.setDepartmentDescription(rs
.getString("department_description"));
department.setDepartmentName(rs.getString("department_name"));
department.setId(rs.getInt("Id"));
departments.add(department);
}
rs.close();
pst.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return departments;
}
public Set getGroups() {
Set groups = new HashSet();
String sql = "select * from groups";
try {
PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
Group group = new Group();
group.setGroupDescription(rs.getString("group_description"));
group.setGroupName(rs.getString("group_name"));
group.setId(rs.getInt("Id"));
groups.add(group);
}
rs.close();
pst.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return groups;
}
public Set getEmploys(int departmentID) {
Set persons = new HashSet();
String sql = "select * from employ where department_id=?";
try {
PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, departmentID);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
Employ person = new Employ();
person.setTelephone(rs.getString("emp_telephone"));
person.setId(rs.getInt("Id"));
person.setName(rs.getString("employ_name"));
persons.add(person);
}
rs.close();
pst.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return persons;
}
public Set getPersons(int groupID) {
Set persons = new HashSet();
String sql = "select * from person where groupID=?";
try {
PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, groupID);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
Person person = new Person();
person.setTelephone(rs.getString("telephone"));
person.setId(rs.getInt("personID"));
person.setName(rs.getString("name"));
persons.add(person);
}
rs.close();
pst.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return persons;
}
public int getReceiveMessagesCount(String beginDate, String endDate,
String telephone) {
int count = 0;
String sql = "select count(*) from receive_sms where receive_time> ? and receive_time < ?";
if (telephone != null && !telephone.trim().equalsIgnoreCase("")) {
sql = sql + " and send_telephone= ?";
}
if(beginDate.endsWith(""))beginDate="0";
if(endDate.endsWith(""))endDate="0";
try {
PreparedStatement pst = con.prepareStatement(sql);
pst.setDate(1, new java.sql.Date(Long.parseLong(beginDate)));
pst.setDate(2, new java.sql.Date(Long.parseLong(endDate)));
if (telephone != null && !telephone.trim().equalsIgnoreCase("")) {
pst.setString(3, telephone);
}
ResultSet rs = pst.executeQuery();
while (rs.next()) {
count = rs.getInt(1);
}
sql = "";
rs.close();
pst.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return count;
}
public int getSendMessagesCount(String beginDate, String endDate,
String telephone) {
int count = 0;
String sql = "select count(*) from sended_sms where send_date > ? and send_date < ?";
if (telephone != null && !telephone.trim().equalsIgnoreCase("")) {
sql = sql + " and receive_telephone= ?";
}
if(beginDate.endsWith(""))beginDate="0";
if(endDate.endsWith(""))endDate="0";
try {
PreparedStatement pst = con.prepareStatement(sql);
pst.setDate(1, new java.sql.Date(Long.parseLong(beginDate)));
pst.setDate(2, new java.sql.Date(Long.parseLong(endDate)));
if (telephone != null && !telephone.trim().equalsIgnoreCase("")) {
pst.setString(3, telephone);
}
ResultSet rs = pst.executeQuery();
while (rs.next()) {
count = rs.getInt(1);
}
sql = "";
rs.close();
pst.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return count;
}
/**
* Accessor for the current list of people
* 1:check2:pregnant3:health_care4:m5:sh6:ac7:bu
*
* @return the current list of people
*/
public Set getActivityMessages() {
messages.clear();
String sql = "select * from sended_sms where service_type=6";
try {
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
Message message = new Message();
message.setContent(rs.getString("content"));
message.setId(rs.getInt("Id"));
message.setSendDate(rs.getDate("send_date").toLocaleString());
message.setSendedState(rs.getInt("sended_state"));
message.setTelephone(rs.getString("receive_telephone"));
message.setServiceType(rs.getInt("service_type"));
messages.add(message);
}
rs.close();
st.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return messages;
}
public Set getBulletinMessages() {
messages.clear();
String sql = "select * from sended_sms where service_type=7";
try {
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
Message message = new Message();
message.setContent(rs.getString("content"));
message.setId(rs.getInt("Id"));
message.setSendDate(rs.getDate("send_date").toLocaleString());
message.setSendedState(rs.getInt("sended_state"));
message.setTelephone(rs.getString("receive_telephone"));
message.setServiceType(rs.getInt("service_type"));
messages.add(message);
}
rs.close();
st.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return messages;
}
public Set getSheduleMessages() {
messages.clear();
String sql = "select * from sended_sms where service_type=5";
try {
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
Message message = new Message();
message.setContent(rs.getString("content"));
message.setId(rs.getInt("Id"));
message.setSendDate(rs.getDate("send_date").toLocaleString());
message.setSendedState(rs.getInt("sended_state"));
message.setTelephone(rs.getString("receive_telephone"));
message.setServiceType(rs.getInt("service_type"));
messages.add(message);
}
rs.close();
st.close();
} catch (SQLException e1) {
评论0