package com.zhiyou100.dao.impl;
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 com.sun.crypto.provider.RSACipher;
import com.zhiyou100.dao.NoticeDao;
import com.zhiyou100.entity.NoticeDo;
import com.zhiyou100.util.DBUtil;
import com.zhiyou100.util.NoticeSearchTypeName;
public class NoticeDaoImpl implements NoticeDao {
@Override
public List<NoticeDo> listNotice(long pageIndex) {
List<NoticeDo> list = new ArrayList<NoticeDo>();
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "SELECT n.id,u.name,n.title,d.name,n.content,n.begin_time,n.end_time FROM notice as n,user as u,department as d "
+ "WHERE n.is_delete =0 AND n.user_id =u.id AND n.department_id=d.id LIMIT ?,5";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setLong(1, pageIndex);
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
NoticeDo noticeDo = new NoticeDo();
noticeDo.setId(executeQuery.getLong(1));
noticeDo.setUserName(executeQuery.getString(2));
noticeDo.setContent(executeQuery.getString(3));
noticeDo.setDepartmentName(executeQuery.getString(4));
noticeDo.setContent(executeQuery.getString(5));
noticeDo.setBeginTime(executeQuery.getDate(6));
noticeDo.setEndTime(executeQuery.getDate(7));
list.add(noticeDo);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
@Override
public long countNotice() {
long count = 0;
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.user_id = u.id AND n.department_id = d.id;";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
count = executeQuery.getInt(1);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
@Override
public List<NoticeDo> listNotice(String keyword, NoticeSearchTypeName type, long pageIndex) {
ArrayList<NoticeDo> list = new ArrayList<NoticeDo>();
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = null;
switch (type) {
case NOTICE_TITLE:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
case NOTICE_CONTENT:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.content like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
case USER_NAME:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND u.name like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
case DEPARTMENT_NAME:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND d.name like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
default:
break;
}
try (PreparedStatement preparedStatement = connection.prepareStatement(sql);) {
preparedStatement.setString(1, "%" + keyword + "%");
preparedStatement.setLong(2, pageIndex);
try (ResultSet executeQuery = preparedStatement.executeQuery();) {
while (executeQuery.next()) {
NoticeDo noticeDo = new NoticeDo();
noticeDo.setId(executeQuery.getLong(1));
noticeDo.setUserName(executeQuery.getString(2));
noticeDo.setTitle(executeQuery.getString(3));
noticeDo.setDepartmentName(executeQuery.getString(4));
noticeDo.setContent(executeQuery.getString(5));
noticeDo.setBeginTime(executeQuery.getDate(6));
noticeDo.setEndTime(executeQuery.getDate(7));
list.add(noticeDo);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
@Override
public long countNotice(String keyword, NoticeSearchTypeName type) {
long count = 0;
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "";
switch (type) {
case NOTICE_CONTENT:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
case NOTICE_TITLE:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
case USER_NAME:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
case DEPARTMENT_NAME:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
default:
break;
}
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setString(1, "%" + keyword + "%");
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
count = executeQuery.getLong(1);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
@Override
public NoticeDo getNoticeById(long id) {
NoticeDo noticeDo = null;
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time, d.id FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.id = ? AND n.user_id = u.id AND n.department_id = d.id;";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setLong(1, id);
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
noticeDo = new NoticeDo();
noticeDo.setId(executeQuery.getLong(1));
noticeDo.setUserName(executeQuery.getString(2));
noticeDo.setTitle(executeQuery.getString(3));
noticeDo.setDepartmentName(executeQuery.getString(4));
noticeDo.setContent(executeQuery.getString(5));
noticeDo.setBeginTime(executeQuery.getDate(6));
noticeDo.setEndTime(executeQuery.getDate(7));
noticeDo.setDepartmentId(executeQuery.getLong(8));
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return noticeDo;
}
@Override
public void addNotice(NoticeDo notice) {
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "INSERT INTO notice(user_id, title, department_id, content, begin_time, end_time) VALUES (?, ?, ?, ?, ?, ?);";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setLong(1, notice.getUserId());
prepareStatement.setString(2, notice.getTitle());
prepareStatement.setLong(3, notice.getDepartmentId());
prepareStatement.setString(4, notice.getContent());
prepareStatement.setDate(5, notice.getBeginTime());
prepareStatement.setDate(6, notice.getEndTime());
prepareStatement.executeUpdate();
没有合适的资源?快使用搜索试试~ 我知道了~
客户关系管理系统 使用(JavaBean+Jsp+Servlet) 搭建.zip
共280个文件
svn-base:127个
java:81个
jsp:34个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 17 浏览量
2023-08-10
23:19:13
上传
评论
收藏 1.4MB ZIP 举报
温馨提示
用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。
资源推荐
资源详情
资源评论
收起资源包目录
客户关系管理系统 使用(JavaBean+Jsp+Servlet) 搭建.zip (280个子文件)
.classpath 1KB
org.eclipse.wst.common.component 649B
org.eclipse.wst.jsdt.ui.superType.container 49B
font-awesome.css 32KB
font-awesome.min.css 26KB
main.css 3KB
admin.css 2KB
index.css 1004B
wc.db 101KB
entries 2B
fontawesome-webfont.eot 67KB
format 2B
.gitattributes 65B
.gitignore 277B
NoticeDaoImpl.java 9KB
EmailDaoImpl.java 9KB
UserDaoImpl.java 8KB
ClientClassifyDaoImpl.java 4KB
ClientStatusDaoImpl.java 4KB
DepartmentDaoImpl.java 4KB
ClientFromDaoImpl.java 4KB
RoleDaoImpl.java 4KB
UserDo.java 4KB
ServletNotice.java 3KB
ListServlet.java 2KB
UpdateServlet.java 2KB
AddServlet.java 2KB
SaveServlet.java 2KB
EmailDO.java 2KB
ListServlet.java 2KB
RoleDo.java 2KB
UpdateServlet.java 2KB
AddServlet.java 2KB
ServletUser.java 2KB
UpdateServlet.java 2KB
NoticeDo.java 2KB
UpdateServlet.java 2KB
UpdateServlet.java 2KB
UserServlceImpl.java 2KB
NoticeService.java 2KB
UpdateServlet.java 2KB
ClientClassifyDo.java 1KB
UpdateServlet.java 1KB
NoticeDao.java 1KB
ClientStatusDo.java 1KB
EmailServiceImpl.java 1KB
AddServlet.java 1KB
ClientFromDo.java 1KB
DepartmentDo.java 1KB
LoginServlet.java 1KB
AddServlet.java 1KB
EmailDaoImplTest.java 1KB
AddServlet.java 1KB
AddServlet.java 1KB
AddServlet.java 1KB
EmailDao.java 1KB
DBUtil.java 1KB
NoticeServiceImpl.java 1KB
EmailService.java 1KB
DepartmentService.java 1KB
SelectServlet.java 1KB
RoleListServlet.java 1KB
RoleService.java 1KB
ReceiveServlet.java 1KB
ClientClassifyServiceImpl.java 1KB
ListServlce.java 1019B
DeleteServlet.java 1016B
DraftServlet.java 1013B
SendServlet.java 1011B
ServletDepartment.java 999B
ListServlet.java 997B
RoleDao.java 996B
DeleteServlet.java 994B
UserService.java 980B
ListServlet.java 975B
ClientStatusServiceImpl.java 953B
DeleteServlet.java 933B
ListServlet.java 926B
DepartmentServiceImpl.java 903B
ClientFromServiceImpl.java 901B
DeleteServlet.java 891B
DeleteServlet.java 874B
DeleteServlet.java 853B
DeleteServlet.java 842B
RoleServiceImpl.java 771B
UserDao.java 662B
RoleDaoImplTest.java 588B
ClientClassifyDao.java 467B
ClientClassifyService.java 425B
ClientStatusService.java 398B
ClientStatusDao.java 389B
ClientFromService.java 374B
DepartmentDao.java 367B
ClientFromDao.java 363B
NoticeSearchTypeName.java 122B
jquery.js 261KB
jquery.min.js 85KB
admin.js 495B
.jsdtscope 626B
index.jsp 6KB
共 280 条
- 1
- 2
- 3
资源评论
c++服务器开发
- 粉丝: 3176
- 资源: 4461
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功