package db_Service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import model.Message;
public class MessageService {
private Connection conn;
private PreparedStatement pstmt;
public MessageService(){
conn = new DBRead().getCon();
}
public void recall(int id){
updateStauts(id,"recall");
int itemId=0;
try {
pstmt=conn.prepareStatement("select itemId from message where id=?");
pstmt.setInt(1, id);
ResultSet rs =pstmt.executeQuery();
if(rs.next()){
itemId=rs.getInt(1);
System.out.println("itemId="+itemId);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ItemService is=new ItemService();
is.updateFind(itemId, "1", null);
}
public void updatesItem(Message message){
try {
pstmt=conn.prepareStatement("update Message set status=?,message=?,isread=0 where itemId=? and listener=?");
pstmt.setString(1, message.getStatus());
pstmt.setString(2, message.getMessage());
pstmt.setInt(3, message.getItemId());
pstmt.setString(4, message.getListener());
pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void updateStauts(int id, String status){
try {
pstmt= conn.prepareStatement("update Message set status=? where id =?");
pstmt.setString(1,status);
pstmt.setInt(2, id);
pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int[] countAll(String userid){
int[] i=new int[4];
try {
pstmt=conn.prepareStatement("select count(*) from Message where listener=? and isread=0");
pstmt.setString(1, userid);
ResultSet rs=pstmt.executeQuery();
if(rs.next())
i[0]=rs.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
pstmt=conn.prepareStatement("select count(*) from Message where listener=? and isread=0 and status in('agreed','refused','send')");
pstmt.setString(1, userid);
ResultSet rs=pstmt.executeQuery();
if(rs.next())
i[1]=rs.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
pstmt=conn.prepareStatement("select count(*) from Message where listener=? and isread=0 and status in('agree','refuse','wait','check')");
pstmt.setString(1, userid);
ResultSet rs=pstmt.executeQuery();
if(rs.next())
i[2]=rs.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
pstmt=conn.prepareStatement("select count(*) from Message where listener=? and isread=0 and status in('check')");
pstmt.setString(1, userid);
ResultSet rs=pstmt.executeQuery();
if(rs.next())
i[3]=rs.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return i;
}
public Message selectMessageByItem(int id){
Message message=new Message();
try {
pstmt= conn.prepareStatement("select * from Message where itemId=? and status='send'");
pstmt.setInt(1, id);
ResultSet rs =pstmt.executeQuery();
if(rs.next()){
message.setId(rs.getInt(1));
message.setMessage(rs.getString(2));
message.setTalker(rs.getString(3));
message.setListener(rs.getString(4));
message.setTime(rs.getString(5));
message.setIsRead(rs.getInt(6));
message.setStatus(rs.getString(7));
message.setItemId(rs.getInt(8));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return message;
}
public Message selectMessageById(int id){
Message message=new Message();
try {
pstmt= conn.prepareStatement("select * from Message where id=?");
pstmt.setInt(1, id);
ResultSet rs =pstmt.executeQuery();
if(rs.next()){
message.setId(rs.getInt(1));
message.setMessage(rs.getString(2));
message.setTalker(rs.getString(3));
message.setListener(rs.getString(4));
message.setTime(rs.getString(5));
message.setIsRead(rs.getInt(6));
message.setStatus(rs.getString(7));
message.setItemId(rs.getInt(8));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return message;
}
public int noRead(List<Message> messages){
int number=0;
for(int i=0;i<messages.size();i++){
if(!(messages.get(i).getIsRead()==1)){
number++;
}
}
return number;
}
public List<Message> serverMessage(String userId){
List<Message> messages=new ArrayList<Message>();
try {
pstmt= conn.prepareStatement("select * from Message where listener=? and talker='gm'");
pstmt.setString(1, userId);
ResultSet rs =pstmt.executeQuery();
while(rs.next()){
Message message=new Message();
message.setId(rs.getInt(1));
message.setMessage(rs.getString(2));
message.setListener(userId);
message.setTime(rs.getString(5));
message.setIsRead(rs.getInt(6));
message.setStatus(rs.getString(7));
message.setItemId(rs.getInt(8));
messages.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return messages;
}
public List<Message> receiveMessage(String userId){
List<Message> messages=new ArrayList<Message>();
try {
pstmt= conn.prepareStatement("select * from Message where listener=? and status in('agreed','refused','send')");
pstmt.setString(1, userId);
ResultSet rs =pstmt.executeQuery();
while(rs.next()){
Message message=new Message();
message.setId(rs.getInt(1));
message.setMessage(rs.getString(2));
message.setListener(userId);
message.setTime(rs.getString(5));
message.setIsRead(rs.getInt(6));
message.setStatus(rs.getString(7));
message.setItemId(rs.getInt(8));
messages.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
pstmt= conn.prepareStatement("update Message set isread=1 where listener=? and status in('agreed','refused','send')");
pstmt.setString(1, userId);
pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return messages;
}
public List<Message> checkMessage(String userId){
List<Message> messages=new ArrayList<Message>();
try {
pstmt= conn.prepareStatement("select * from Message where listener=? and status in('check')");
pstmt.setString(1, userId);
ResultSet rs =pstmt.executeQuery();
while(rs.next()){
Message message=new Message();
message.setId(rs.getInt(1));
message.setMessage(rs.getString(2));
message.setListener(userId);
message.setTime(rs.getString(5));
message.setIsRead(rs.getInt(6));
message.setStatus(rs.getString(7));
message.setItemId(rs.getInt(8));
messages.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
pstmt= conn.prepareStatement("update Message set isread=1 where listener=? an
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
东北大学软件学院JSP大作业 (213个子文件)
MessageService.class 9KB
ItemService.class 7KB
Loster.class 7KB
Fabu.class 7KB
Check.class 3KB
Choose.class 3KB
Receive.class 3KB
Sender.class 3KB
ServerMessage.class 3KB
AboutMe.class 3KB
Denglu.class 3KB
zhuce.class 3KB
FYCCShowLoster.class 2KB
YHJXLShowLoster.class 2KB
TSGShowLoster.class 2KB
SKShowLoster.class 2KB
STShowLoster.class 2KB
WGShowLoster.class 2KB
JZShowLoster.class 2KB
XXShowLoster.class 2KB
ShowLoster.class 2KB
Item.class 2KB
UserService.class 2KB
Agree.class 2KB
Message.class 2KB
Refuse.class 2KB
User.class 1KB
Recall.class 1KB
DBRead.class 1KB
Text.class 1KB
ItemUtil.class 909B
Text1.class 751B
Upload.class 505B
.classpath 1KB
org.eclipse.wst.common.component 480B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 143KB
bootstrap.min.css 118KB
animate.css 67KB
font-awesome.min.css 28KB
bootstrap-theme.css 26KB
general.css 24KB
font-awesome.css 21KB
font-awesome.min.css 17KB
style2.css 14KB
style.css 14KB
base.css 10KB
magnific-popup.css 8KB
custom.css 6KB
message.css 4KB
snow.css 3KB
bootstrap-fileinput.css 2KB
owl.theme.css 2KB
owl.carousel.css 1KB
reset.css 773B
xinxiluru.css 416B
index.css 397B
fontawesome-webfont.eot 37KB
glyphicons-halflings-regular.eot 20KB
status.gif 14KB
mysql-connector-java-5.1.5-bin.jar 661KB
jstl-1.2.jar 405KB
commons-io-2.5.jar 204KB
commons-fileupload-1.3.2.jar 69KB
MessageService.java 10KB
ItemService.java 9KB
Fabu.java 6KB
Loster.java 6KB
zhuce.java 4KB
Denglu.java 3KB
Check.java 2KB
Receive.java 2KB
Sender.java 2KB
Choose.java 2KB
ServerMessage.java 2KB
AboutMe.java 2KB
XXShowLoster.java 2KB
YHJXLShowLoster.java 2KB
TSGShowLoster.java 2KB
WGShowLoster.java 2KB
STShowLoster.java 2KB
FYCCShowLoster.java 2KB
SKShowLoster.java 2KB
JZShowLoster.java 2KB
ShowLoster.java 2KB
UserService.java 2KB
Item.java 2KB
Agree.java 1KB
Message.java 1KB
Refuse.java 1KB
User.java 875B
Recall.java 789B
Text.java 608B
Upload.java 593B
DBRead.java 546B
ItemUtil.java 374B
Text1.java 368B
cc.jpeg 421KB
yinyuedi4.jpeg 147KB
yinyuedi2.jpeg 115KB
共 213 条
- 1
- 2
- 3
资源评论
qq_35672878
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Windows 常见运行运行库32+64
- 基于3KW光伏并网单相逆变器设计(TMS320F28035控制板+显示板+STM32F103功率板)硬件(原理图+PCB)工程
- 正点原子HAL库 STM32F4 外部中断(学习自用附源码)
- delphi rzcombobox DropDownList 灰色背景改为白色
- sap sd.docsap sd.doc
- torch-1.10.2-cp38-cp38-win-amd64.whl
- 菜单栏实现增加数据,修改数据,查询数据,删除数据
- 全国省市区三级联动json文件,带code
- C8_全局&局部&static.zip
- Unity和安卓交互插件Unity调Android Native Goodies PRO
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功