package com.oaoffice.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.oaoffice.util.DbFun;
import com.oaoffice.bean.User;
import com.oaoffice.dao.UserDao;
import com.oaoffice.util.PagingVO;
public class UserDaoImpl implements UserDao{
@SuppressWarnings("resource")
public Integer insert(User bean) {
//user_id,user_name,user_realname,user_pwd,user_sex,phonenumber,user_born
//user_address,user_hobby,user_email,selfassessment,headpic,dept_id
StringBuilder sb = new StringBuilder();
sb.append(" Insert Into User(user_name,user_realname,user_pwd,user_sex,");
sb.append(" phonenumber,user_born,user_address,user_email,headpic,dept_id)");
sb.append("Values(?,?,?,?,?,?,?,?,?,?)");
String sql = sb.toString();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Integer num = 0;
try {
conn = DbFun.getConn();
pstmt = conn.prepareStatement(sql);
pstmt.setObject(1, bean.getUser_name());
pstmt.setObject(2, bean.getUser_realname());
pstmt.setObject(3, bean.getUser_pwd());
pstmt.setObject(4, bean.getUser_sex());
pstmt.setObject(5, bean.getPhonenumber());
pstmt.setObject(6, bean.getUser_born());
pstmt.setObject(7, bean.getUser_address());
pstmt.setObject(8, bean.getUser_email());
pstmt.setObject(9, bean.getHeadpic());
pstmt.setObject(10, bean.getDept_id());
num = pstmt.executeUpdate();
// 如果受影响行数大于0,说明添加成功;之后,要获取刚刚添加的行的主键值
if (num > 0) {
sql = "Select @@Identity";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
num = rs.getInt(1);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DbFun.close(rs, pstmt, conn);
}
return num;
}
public List<User> list() {
List<User> list = new ArrayList<User>();
StringBuilder sb = new StringBuilder();
sb.append("SELECT");
sb.append(" a.*,");
sb.append(" d.role_name,");
sb.append(" b.dept_name");
sb.append(" FROM" );
sb.append(" USER AS a");
sb.append(" LEFT JOIN dept b ON a.dept_id = b.dept_id ");
sb.append(" LEFT JOIN user_role c ON c.user_id = a.user_id ");
sb.append(" LEFT JOIN role d ON c.role_id = d.role_id ");
String sql = sb.toString();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
//user_id,user_name,user_realname,user_pwd,user_sex,phonenumber,user_born
//user_address,user_hobby,user_email,selfassessment,headpic,dept_id
try {
conn = DbFun.getConn();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
User tmpbean = null;
while (rs.next()) {
tmpbean = new User();
tmpbean.setUser_id(rs.getInt("user_id"));
tmpbean.setUser_name(rs.getString("user_name"));
tmpbean.setUser_realname(rs.getString("user_realname"));
tmpbean.setUser_pwd(rs.getString("user_pwd"));
tmpbean.setUser_sex(rs.getString("user_sex"));
tmpbean.setPhonenumber(rs.getString("phonenumber"));
tmpbean.setUser_born(rs.getDate("user_born"));
tmpbean.setUser_address(rs.getString("user_address"));
tmpbean.setUser_email(rs.getString("user_email"));
tmpbean.setHeadpic(rs.getString("headpic"));
tmpbean.setDept_id(rs.getInt("dept_id"));
tmpbean.setDept_name(rs.getString("dept_name"));
tmpbean.setRole_name(rs.getString("role_name"));
list.add(tmpbean);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DbFun.close(rs, pstmt, conn);
}
return list;
}
public Integer delete(Integer id) {
StringBuilder sb = new StringBuilder();
sb.append(" delete from User where user_id=?");
String sql = sb.toString();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Integer num = 0;
try {
conn = DbFun.getConn();
pstmt = conn.prepareStatement(sql);
pstmt.setObject(1, id);
num = pstmt.executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DbFun.close(rs, pstmt, conn);
}
return num;
}
public Integer update(User bean) {
// TODO Auto-generated method stub
StringBuilder sb = new StringBuilder();
sb.append(" update User Set ");
sb.append(" user_name=? ");
sb.append(" ,user_realname=? ");
sb.append(" ,user_pwd=? ");
sb.append(" ,user_sex=? ");
sb.append(" ,phonenumber=? ");
sb.append(" ,user_born=? ");
sb.append(" ,user_address=? ");
sb.append(" ,user_hobby=? ");
sb.append(" ,user_email=? ");
sb.append(" ,selfassessment=? ");
sb.append(" ,headpic=? ");
sb.append(" ,dept_id=? ");
sb.append(" where user_id=?");
String sql = sb.toString();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Integer num = 0;
//uname,upass,realName,gender,birthday
try {
conn = DbFun.getConn();
pstmt = conn.prepareStatement(sql);
pstmt.setObject(1, bean.getUser_name());
pstmt.setObject(2, bean.getUser_realname());
pstmt.setObject(3, bean.getUser_pwd());
pstmt.setObject(4, bean.getUser_sex());
pstmt.setObject(5, bean.getPhonenumber());
pstmt.setObject(6, bean.getUser_born());
pstmt.setObject(7, bean.getUser_address());
pstmt.setObject(8, bean.getUser_hobby());
pstmt.setObject(9, bean.getUser_email());
pstmt.setObject(10, bean.getSelfassessment());
pstmt.setObject(11, bean.getHeadpic());
pstmt.setObject(12, bean.getDept_id());
pstmt.setObject(13, bean.getUser_id());
num = pstmt.executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DbFun.close(rs, pstmt, conn);
}
return num;
}
public User load(Integer id) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT");
sb.append(" a.*,");
sb.append(" b.dept_name");
sb.append(" FROM" );
sb.append(" USER AS a");
sb.append(" LEFT JOIN dept b ON a.dept_id = b.dept_id ");
sb.append(" Where user_id=?");
String sql = sb.toString();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
User bean = null;
try {
conn = DbFun.getConn();
pstmt = conn.prepareStatement(sql);
pstmt.setObject(1, id);
rs = pstmt.executeQuery();
if (rs.next()) {
bean = new User();
bean.setUser_id(rs.getInt("user_id"));
bean.setUser_name(rs.getString("user_name"));
bean.setUser_realname(rs.getString("user_realname"));
bean.setUser_pwd(rs.getString("user_pwd"));
bean.setUser_sex(rs.getString("user_sex"));
bean.setPhonenumber(rs.getString("phonenumber"));
bean.setUser_born(rs.getDate("user_born"));
bean.setUser_address(rs.getString("user_address"));
bean.setUser_hobby(rs.getString("user_hobby"));
bean.setUser_email(rs.getString("user_email"));
bean.setSelfassessment(rs.getString("selfassessment"));
bean.setHeadpic(rs.getString("headpic"));
bean.setDept_id(rs.getInt("dept_id"));
bean.setDept_name(rs.getString("dept_name"));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DbFun.close(rs, pstmt, conn);
}
return bean;
}
public Integer count() {
StringBuilder sb = new StringBuilder();
sb.append(" select count(1) from User");
String sql = sb.toString();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Integer num = 0;
try {
conn = DbFun.getConn();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next()) {
num=rs.getInt(1);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DbFun.close(rs, pstmt, conn);
}
return num;
}
public User loadByName(String name) {
/
OAoffice-master(OA管理系统源码).zip
需积分: 0 61 浏览量
更新于2023-04-09
1
收藏 10.31MB ZIP 举报
该项目是基于SSM框架,数据库采用的是Mysql数据库。大致的功能实现分为4大部分:个人办公、工作流程、行政办公、系统管理。每一个大模块下,又细分成多个小模块。项目的界面UI是就LayUI前端控件。项目中有过滤器、定时器、文件上传、较为复杂的OA流程。
程高兴
- 粉丝: 523
- 资源: 463
最新资源
- 中小学数字化平台解决方案.docx
- 弱电人需要的网络基础知识汇总.docx
- 智慧龙湖天街数字化解决方案.pptx
- 温室大棚、集约养殖、水肥一体、高效节水等设施农业建设方案.docx
- 物流实训室元宇宙解决方案.docx
- 温室大棚、集约养殖、水肥一体、高效节水等设施农业建设方案.pptx
- 农村客货邮融合发展建设方案.docx
- 乡村富民特色产业农业品牌建设方案.pptx
- 农业农村基础设施建设方案.pptx
- 工地数字孪生可视化平台解决方案.pptx
- 基于线性代数与机器学习的实验任务解析-含代码及解答
- 人物检测37-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- ANSYS WORKBENCH轴承动力学仿真,ANSYS做内圈、外圈和滚子故障的模拟图片为凯斯西储大学SKF轴承内外圈故障的结果,振动加速度包络后故障特征频率可以与实验相差仅为5%
- 戴尔笔记本Dell 5400 EDC41 - 维修图纸
- matlab实现遗传算法求解迪卡侬生产调度优化问题(含甘特图)-遗传算法-生产调度-Matlab-迪卡侬生产调度优化
- 时变动态分位数CoVaR、delta-CoVaR,分位数回归 △CoVaR测度 溢出效应 动态 Adrian2016基于分位数回归方法计算动态条件在险价值 R语言代码,代码更数据就能用,需要修改的