Java-超市收银系统(Java基础知识项目)
员工考勤信息系统实现智能化的考勤功能需求:企业上班时间:9:00企业下班时间:18:00标准:11:00>上班打卡时间>9:00:迟到处理上班打卡时间>11:00旷工处理16:00<下班打卡时间<18:00早退处理下班打卡时间<16:00旷工处理上班、下班缺卡旷工处理上班时间有数据,下班没有数据
·
超市收银系统:
该系统主要是针对Java基础知识的练习项目
设计目标是面向小超市
系统主要分为两个模块:会员登入模块、员工登录模块
其中员工登录中还有其他许多小模块,如会员管理、上下班打卡等
其中比较难的主要是营业额查询、收银结算和打卡
开发工具:eclipse
数据库:MySQL 8 sqlyog
关于打卡:
员工考勤信息系统
实现智能化的考勤功能
需求:
企业上班时间:9:00
企业下班时间:18:00
标准:
11:00>上班打卡时间>9:00: 迟到处理
上班打卡时间>11:00 旷工处理
16:00<下班打卡时间<18:00 早退处理
下班打卡时间<16:00 旷工处理
上班、下班缺卡 旷工处理
上班时间有数据,下班没有数据 旷工处理
上班时间没有数据,下班有数据 旷工处理
1、实现员工智能考勤
a、能够根据员工的打卡信息,统计考勤信息
(考勤信息:迟到(个数)、早退(个数)、旷工(个数))
2、实现员工打卡功能
a、上班打卡
b、下班打卡
3、员工注册功能
数据库中打卡语句:
数据库视图
create or replace view check_info_son
as
select work_date,employee_no,clock_in_time,clock_off_time,
TIMESTAMPDIFF(MINUTE, clock_in_time, concat(clock_date,' 09:00:00')) as diff_in_time,
TIMESTAMPDIFF(MINUTE, clock_off_time, concat(clock_date,' 18:00:00')) as diff_off_time
from work_date w
left join clock_info t
on t.clock_date = w.work_date
create or replace view check_info
as
select t.work_date,t.employee_no,clock_in_time,clock_off_time,
case
when diff_in_time<-120
then '旷工'
when diff_in_time<0
then '迟到'
when diff_in_time>0
then '正常'
else '忘记打卡'
end as diff_in_status,
case
when diff_off_time>120
then '旷工'
when diff_off_time>0
then '早退'
when diff_off_time<0
then '正常'
else '忘记打卡'
end as diff_off_time
from check_info_son t
select * from check_info;
select * from employee where number='s0001';
因为我使用的数据库为:
所以在eclipse中的jar包为:
关于这个的操作我之前的博客有
在我的项目中以下这个文件也有所不同
如下:
driver=com.mysql.cj.jdbc.Driver
#url=jdbc:mysql:///mydb1?rewriteBatchedStatements=true&useUnicode=true&charcterEncoding=utf8
url=jdbc:mysql:///supermaket?rewriteBatchedStatements=true&serverTimezone=UTC
#url=jdbc:mysql:///mydb1?rewriteBatchedStatements=true
user=root
password=123456
整个项目分别有:
管理员功能实现代码:
impl 中代码
package com.gec.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import com.gec.dao.AdminDao;
import com.gec.dao.BuyerDao;
import com.gec.domain.Admin;
import com.gec.domain.Buyer;
import com.gec.domain.Cashier;
import com.gec.util.JDBCUtil;
public class AdminDaoImpl implements AdminDao{
Scanner sc = new Scanner(System.in);
private String sql;
@Override
//管理员 账号密码
public Admin login(String number, String password) {
Connection conn = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
conn = JDBCUtil.getConnection();
String sql = "select * from employee where number = ? and password=?";
statement = conn.prepareStatement(sql);
statement.setString(1, number);
statement.setString(2, password);
System.out.println("sql:" + statement);
//执行
rs = statement.executeQuery();
//遍历结果集
while(rs.next()) {
//rs.getInt(1); 这种不推荐
String nb = rs.getString("number");
String uname = rs.getString("username");
String upassword = rs.getString("password");
String sex = rs.getString("sex");
String phonr = rs.getString("phone");
int role = rs.getInt("role");
//创建用户对象
Admin user = new Admin();
user.setNumber(nb);
user.setUsername(uname);
user.setSex(sex);
user.setPassword(upassword);
user.setPhone(phonr);
user.setRole(role);
//返回用户信息
return user;
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.closeConn(conn, statement, rs);
}
return null;
}
@Override
//删除
public void remove(String number) {
Connection conn = null;
Statement statement = null;
try {
String sql = "delete from employee where number=" + number;
conn = JDBCUtil.getConnection();
statement = conn.createStatement();
//执行Sql
statement.executeUpdate(sql);
//观察sql打印
System.out.println(sql);
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.closeConn(conn, statement, null);
}
}
@Override
//查询所有
public void QueryAll(Admin all) {
Connection conn = null;
ResultSet rs = null;
PreparedStatement st = null;
try {
conn = JDBCUtil.getConnection();
st = conn.prepareStatement(sql);
rs = st.executeQuery();
while (rs.next()) {
Admin employee = new Admin();
employee.setNumber(rs.getString("number"));
employee.setUsername(rs.getString("username"));
employee.setPassword(rs.getString("password"));
employee.setSex(rs.getString("sex"));
employee.setPhone(rs.getString("phone"));
employee.setRole(rs.getInt("role"));
System.out.println(employee);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.closeConn(conn, st, rs);
}
}
@Override
//添加
public void saveUser(Admin user) {
Connection conn = null;
Statement statement = null;
try {
//String sql = "insert into tb_user(name,sex)values('" + name + "','" + sex +"')";
String sql = "insert into employee(number,username,password,sex,phone,role,remark)values('"+ user.getNumber() + "',"
+ "'" + user.getUsername() + "','" + user.getPassword() +"','" + user.getSex() +"','"+ user.getPhone()+"','" + user.getRole() +",'"+ user.getRemark() +")";
conn = JDBCUtil.getConnection();
statement = conn.createStatement();
//执行Sql
statement.executeUpdate(sql);
//观察sql打印
System.out.println(sql);
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.closeConn(conn, statement, null);
}
}
@Override
//查找
public List<Admin> findAdmin(Admin role) {
Connection conn = JDBCUtil.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
List<Admin> employees = new ArrayList<Admin>();
String sql = "select * from employee where role = " + role;
try {
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
Admin employee = new Admin();
employee.setNumber(rs.getString("number"));
employee.setPassword(rs.getString("password"));
employee.setSex(rs.getString("sex"));
employee.setRole(rs.getInt("role"));
employee.setPhone(rs.getString("phone"));
employee.setUsername(rs.getString("username"));
employees.add(employee);
}
return employees;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.closeConn(conn, ps, rs);
}
return null;
}
@Override
//修改
public void update(Admin number) {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
Admin admin =new Admin();
try {
String sql = "update employee set username ='" + admin.getUsername() + "',password='" + admin.getPassword() + "',sex ='" +admin.getSex() + "',phone ='" +admin.getPhone() + "' where number = '" + admin.getNumber() + "'";
conn = JDBCUtil.getConnection();
st = conn.createStatement();
// 执行sql
st.executeUpdate(sql);
// 观察sql打印
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.closeConn(conn, st, null);
}
}
@Override
//上班打卡
public Date clockIn(Admin ad) {
Date date = new Date();
Connection conn = JDBCUtil.getConnection();
PreparedStatement ps = null;
String sql = "insert into clock_info (employee_no,clock_in_time,clock_date) values (?,?,?)";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, ad.getNumber());
Timestamp timeStamp = new Timestamp(date.getTime());
ps.setTimestamp(2, timeStamp);
Date clock_date = new Date();
ps.setDate(3, new java.sql.Date(clock_date.getTime()));
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.closeConn(conn, ps, null);
}
return date;
}
@Override
//下班打卡
public Date clockOut(Admin ad2) {
Connection conn = JDBCUtil.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "update clock_info set clock_off_time = ? where clock_date = ? and employee_no = ? ";
Date date = new Date();
Timestamp timeStamp = new Timestamp(date.getTime());
try {
ps = conn.prepareStatement(sql);
ps.setTimestamp(1, timeStamp);
ps.setDate(2, new java.sql.Date(date.getTime()));
ps.setString(3, ad2.getNumber());
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
return timeStamp;
}
@Override
//查询超市营业额
public void turnover(Admin price) {
// TODO Auto-generated method stub
}
@Override
//会员管理
public void VipManage() {
// TODO Auto-generated method stub
}
@Override
public List findAdmin() {
// TODO Auto-generated method stub
return null;
}
@Override
//修改
public Admin update(String number) {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
Admin admin =new Admin();
try {
String sql = "update employee set username ='" + admin.getUsername() + "',password='" + admin.getPassword() + "',sex ='" +admin.getSex() + "',phone ='" +admin.getPhone() + "' where number = '" + admin.getNumber() + "'";
conn = JDBCUtil.getConnection();
st = conn.createStatement();
// 执行sql
st.executeUpdate(sql);
// 观察sql打印
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.closeConn(conn, st, null);
}
return admin;
}
@Override
//出勤管理
public void lookAttendance(String work_date) {
List<Admin> clock_infos = new ArrayList();
List<Admin> check_infos = new ArrayList();
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try {
conn = JDBCUtil.getConnection();
String sql = "select check_info.work_date,check_info.employee_no,employee.username,check_info.clock_in_time,check_info.clock_off_time,check_info.diff_in_status,check_info.diff_off_time"
+ " from check_info,employee where check_info.employee_no = employee.number and work_date = '" + work_date + "'";
st = conn.prepareStatement(sql);
// 执行
rs = st.executeQuery();
System.out.println("工作日期\t\t员工编号\t\t员工姓名\t\t上班时间\t\t\t下班时间\t\t 上班情况\t下班情况");
// 遍历结果集
while (rs.next()) {
work_date = rs.getString("work_date");
String employee_no = rs.getString("employee_no");
String username = rs.getString("username");
String clock_in_time = rs.getString("clock_in_time");
String clock_off_time = rs.getString("clock_off_time");
String diff_in_status = rs.getString("diff_in_status");
String diff_off_time = rs.getString("diff_off_time");
if (clock_in_time == null) {
clock_in_time= "null\t\t";
}else if (clock_off_time == null) {
clock_off_time= "null\t\t";
}
System.out.println(work_date + "\t" + employee_no + "\t\t" + username + "\t" + clock_in_time + "\t" + clock_off_time + "\t" + diff_in_status + "\t" + diff_off_time);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.closeConn(conn, st, rs);
}
}
@Override
//钱
public void money(Admin employee) {
String sql = null;
System.out.println("请输入你想要购买的商品:");
int number = sc.nextInt();
//通过商品名查找商品库存
int inventory = findInventoryByNumber(number);
System.out.println("你想要购买的商品还有:"+inventory+"件,你想要购买:");
int buy = sc.nextInt();
String sql1 = "update goods set inventory = inventory - " + buy + " where c_number = '" + number +"'";
settlementDML(sql1);
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String d = dateFormat.format(date);
System.out.println("是否是会员购买:(y/n)");
String isVip = sc.next();
if(isVip.equals("y")) {
System.out.println("请输入购买的会员号:");
String vipNumber = sc.next();
sql = "insert into sell_info (s_c_number,s_quantity,s_time,s_e_number,s_vip_number) values ("+number+","+buy+",'"+d+"','"+employee.getNumber()+"','"+vipNumber+"')";
}else {
sql = "insert into sell_info (s_c_number,s_quantity,s_time,s_e_number) values ("+number+","+buy+",'"+d+"','"+employee.getNumber()+"')";
}
settlementDML(sql);
}
//通过商品名来查找商品的库存
@Override
public int findInventoryByNumber(int number) {
Connection conn = JDBCUtil.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select inventory from goods where c_number = ?";
try {
ps = conn.prepareStatement(sql);
ps.setInt(1, number);
rs = ps.executeQuery();
//判断结果集是否为空
if(rs.next()) {
//判断库存是否为0
int inventory = rs.getInt("inventory");
if(inventory <= 0) {
System.out.println("你想要购买的商品没有库存了,是否让采购员去进货?(y/n)");
String isBuy = sc.next();
if(isBuy.equals("y")) {
BuyerDao bdao = new BuyerDaoImpl();
bdao.Buy();
}
}else {
return inventory;
}
}else {
System.out.println("没有找到你想要购买的商品!");
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.closeConn(conn, ps, rs);
}
return 0;
}
//执行dml语句
@Override
public void settlementDML(String sql) {
Connection conn = JDBCUtil.getConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(sql);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.closeConn(conn, ps, null);
}
}
@Override
public void money(String sf2) {
// TODO Auto-generated method stub
}
}
更多推荐
已为社区贡献11条内容
所有评论(0)