超市管理项目-4 工具类的创建

1.编写配置文件

url=jdbc:mysql:///supermark?serverTimezone=Asia/Shanghai
username=root
password=ch520134

2.读取配置文件

 //加载配置文件
    static {
        try (
                InputStream is = JDBCUntil.class.getClassLoader().getResourceAsStream("jdbc.properties");
                ){
            //加载配置文件
            p.load(is);
            //创建进货单
            creatTable();
            //设置当前时间
            setdata();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

3.创建数据库连接(基于jdbc)

 public static Connection getConnection(){
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(p.getProperty("url"),p.getProperty("username"),p.getProperty("password"));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

4.创建登陆方法

4.1根据不同的输入进行不同权限的登陆

   //进行登陆
    public static void login(){
        String sql = "select * from employee where number=? and password=?";
        System.out.println("请选择登陆类型:1.管理员 2.收银员 3.采购员 4.VIP ");
        int id = sc.nextInt();
        switch (id){
            case 1:
                System.out.println("请输入账号:");
                String aId = sc.next();
                System.out.println("请输入密码:");
                String aPwd = sc.next();
                List sale = select(sql, "sale", aId, aPwd);
                if(sale.size()!=0){
                    for (Sale sale1:sale) {
                        if (sale1.getCategory().equals("管理员")&&(sale1.getPwd().equals(aPwd)&&sale1.getId().equals(aId))) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = sale1.getId();
                            num = 1;
                            return;
                        }else {
                            System.out.println("登陆失败...");
                            isOk=false;
                        }
                        
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            case 2:
                System.out.println("请输入账号:");
                String bId = sc.next();
                System.out.println("请输入密码:");
                String bPwd = sc.next();
                List sale2 = select(sql, "sale", bId, bPwd);
                if(sale2.size()!=0){
                    for (Sale sale1:sale2) {
                        if (sale1.getCategory().equals("收银员")&&(sale1.getPwd().equals(bPwd)&&sale1.getId().equals(bId))) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = sale1.getId();
                            num = 2;
                            return;
                        }else {
                            System.out.println("登陆失败...");
                            isOk=false;
                        }
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            case 3:
                System.out.println("请输入账号:");
                String cId = sc.next();
                System.out.println("请输入密码:");
                String cPwd = sc.next();
                List sale3 = select(sql, "sale", cId, cPwd);
                if(sale3.size()!=0){
                    for (Sale sale1:sale3) {
                        if (sale1.getCategory().equals("采购员") && (sale1.getPwd().equals(cPwd)&&sale1.getId().equals(cId))) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = sale1.getId();
                            num = 3;
                            return;
                        }else {
                            System.out.println("登陆失败...");
                            isOk=false;
                        }
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            case 4:
                System.out.println("请输入VIP账号:");
                String VIPId = sc.next();
                System.out.println("请输入VIPs手机号码:");
                String VIPPhone = sc.next();
                String sqlVIP = "select * from vip where v_number=? and v_phone=?";
                List sale4 = select(sqlVIP, "vip", VIPId, VIPPhone);
                if(sale4.size()!=0){
                    for (VIP vip:sale4) {
                        if (vip.getId()!=null) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = vip.getId();
                            num = 4;
                            return;
                        }else {
                            System.out.println("登陆失败...");
                            isOk=false;
                        }
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            default:
                isOk=false;
                break;
        }
    }

5.创建打卡方法

5.1根据当前时间进行打卡

//上班打卡
    public static void clockIn(){
        date = new java.util.Date();
        SimpleDateFormat dateFormats = new SimpleDateFormat("HH:mm:ss");
        String sql = "INSERT INTO clock_info(employee_no,clock_in_time,clock_date) values(?,?,?)";
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        List clock_info = select(sqll, "clock_info", number, dateFormat.format(date));
        if (clock_info.size()==0){
            updates(sql,number,date,dateFormat.format(date));
            //显示是否迟到
            String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
            select(sqls,"check_info_in",datas,number);
        }else {
            System.out.println("你已打过卡...");
        }
    }
//下班打卡
    public static void clockOut(){
        java.util.Date date1 = new Date();
        String format = dateFormat.format(date1);
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        List clock_info = select(sqll, "clock_info", number, dateFormat.format(date));
        for(Clock_info clockInfo:clock_info){
            if (clockInfo.getClock_out_time()!=null){
                System.out.println("你已打过卡...");
            }
            else {
                String sql = "UPDATE  clock_info set clock_off_time=? where clock_date like ? and employee_no=?";
                updates(sql,date,format,number);
                String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
                select(sqls,"check_info_off",datas,number);
            }
        }
    }

5.2根据数据库中的日期进行打卡

//2021-4月上班打卡
    public static void clockIns(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String sql = "INSERT INTO clock_info(employee_no,clock_in_time,clock_date) values(?,?,?)";
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        //2021-4-6到目前的毫秒数
        long time = 29376000000l;
        long currTime = (System.currentTimeMillis()-time);
        List clock_info = JDBCUntil.select(sqll, "clock_info", number, format.format(currTime));
        if (clock_info.size()==0){
            JDBCUntil.updates(sql,number,dateFormat.format(currTime),format.format(currTime));
            //显示是否迟到
            String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
            JDBCUntil.select(sqls,"check_info_in",format.format(currTime),number);
        }else {
            System.out.println("你已打过卡...");
        }
    }
    //2021-4下班打卡
    public static void clockOuts(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //2021-4-6到目前的毫秒数
        long time = 29376000000l;
        long currTime = (System.currentTimeMillis()-time);
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        List clock_info = select(sqll, "clock_info", number, format.format(currTime));
        for(Clock_info clockInfo:clock_info){
            if (clockInfo.getClock_out_time()!=null){
                System.out.println("你已打过卡...");
            }
            else {
                String sql = "UPDATE  clock_info set clock_off_time=? where clock_date like ? and employee_no=?";
                updates(sql,dateFormat.format(currTime),format.format(currTime),number);
                String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
                select(sqls,"check_info_off",format.format(currTime),number);
            }
        }
    }

6.创建查询方法

//根据不同的String check_info进行不同的解析操作
    public static List select(String sql,String check_info,Object...args){
        List list = new ArrayList<>();
        try (
                PreparedStatement ps = getConnection().prepareStatement(sql);
        ) {
            if (args != null && args.length > 0) {
                int parameterIndex = 1;
                for (int i = 0; i < args.length; i++) {
                    //System.out.println(ps);
                    ps.setObject(parameterIndex++, args[i]);
                }
            }
            ResultSet rs = ps.executeQuery();
            //上班打卡信息
            if("check_info_in".equals(check_info)){
                while (rs.next()){
                    if (rs.getString("diff_in_status")!=null){
                        //打印上班状态
                        System.out.println(rs.getString("diff_in_status"));
                        break;
                    }
                }
            }
            //下班打卡信息
            if("check_info_off".equals(check_info)){
                while (rs.next()) {
                    if (rs.getString("diff_off_time") != null) {
                        //打印下班状态
                        System.out.println(rs.getString("diff_off_time"));
                        break;
                    }
                }
            }
            //查询员工信息
            else if("sale".equals(check_info)){
                while (rs.next()){
                    Sale sale = new Sale();
                    sale.setId(rs.getString("number"));
                    sale.setName(rs.getString("username"));
                    sale.setPwd(rs.getString("password"));
                    sale.setSex(rs.getString("sex"));
                    sale.setPhone(rs.getString("phone"));
                    sale.setCategory(rs.getInt("role"));
                    sale.setOnJob(rs.getInt("remark"));
                    list.add(sale);
                }
                return list;
            }
            //查询补货单
            else if("addgoods".equals(check_info)){
                while (rs.next()){
                    AddGoods addGoods = new AddGoods();
                    addGoods.setGoods_number(rs.getInt("goods_number"));
                    addGoods.setGoods_count(rs.getInt("goods_count"));
                    addGoods.setDate(rs.getDate("add_time"));
                    addGoods.setAdd_e_number(rs.getString("add_e_number"));
                    list.add(addGoods);
                }
                return list;
            }
            //查询营业额
            else if("sell_info".equals(check_info)){
                while (rs.next()){
                    Sell_Info sell_info = new Sell_Info();
                    sell_info.setS_c_number(rs.getInt("s_c_number"));
                    sell_info.setS_quantity(rs.getInt("s_quantity"));
                    sell_info.setS_time(rs.getTime("s_time"));
                    sell_info.setS_e_number(rs.getString("s_e_number"));
                    sell_info.setS_vip_number(rs.getString("s_vip_number"));
                    if (rs.getString("s_vip_number")==null) {
                        sell_info.setMoney(rs.getInt("s_quantity")*rs.getDouble("c_price"));
                    }else {
                        sell_info.setMoney(rs.getInt("s_quantity")*rs.getDouble("vip_price"));
                    }
                    list.add(sell_info);
                }
                return list;
            }
            //查询出勤
            else if("attendanceQuery".equals(check_info)){
                while (rs.next()){
                    Check_Info check_infos = new Check_Info();
                    check_infos.setWork_date(rs.getString("work_date"));
                    check_infos.setEmployee_no(rs.getString("employee_no"));
                    check_infos.setClock_in_time(rs.getString("clock_in_time"));
                    check_infos.setClock_off_time(rs.getString("clock_off_time"));
                    check_infos.setDiff_in_status(rs.getString("diff_in_status"));
                    check_infos.setDiff_off_time(rs.getString("diff_off_time"));
                    list.add(check_infos);
                }
                return list;
            }
            //查询VIP
            else if("vip".equals(check_info)){
                while (rs.next()){
                    VIP vip = new VIP();
                    vip.setId(rs.getString("v_number"));
                    vip.setName(rs.getString("v_name"));
                    vip.setIntegral(rs.getInt("v_score"));
                    vip.setPhone(rs.getString("v_phone"));
                    vip.setData(rs.getDate("v_date"));
                    list.add(vip);
                }
                return list;
            }
            //查询打卡记录表
            else if("clock_info".equals(check_info)){
                while (rs.next()){
                    Clock_info clock_info = new Clock_info();
                    clock_info.setClock_id(rs.getInt("clock_id"));
                    clock_info.setEmployee_no(rs.getString("employee_no"));
                    clock_info.setClock_in_time(rs.getDate("clock_in_time"));
                    clock_info.setClock_out_time(rs.getDate("clock_off_time"));
                    clock_info.setClock_date(rs.getDate("clock_date"));
                    list.add(clock_info);
                }
                return list;
            }
            //查询货品
            else if(check_info.equals("goods")){
                while (rs.next()){
                    Goods goods = new Goods();
                    goods.setGoodsId(rs.getInt("c_number"));
                    goods.setGoodsName(rs.getString("c_name"));
                    goods.setGoodsPrice(rs.getDouble("c_price"));
                    goods.setVipPrice(rs.getDouble("vip_price"));
                    goods.setGoodsStock(rs.getInt("inventory"));
                    list.add(goods);
                }
                return list;
            }
            else if(check_info.equals("clock_info")){
                while (rs.next()){
                    Goods goods = new Goods();
                    goods.setGoodsId(rs.getInt("c_number"));
                    goods.setGoodsName(rs.getString("c_name"));
                    goods.setGoodsPrice(rs.getDouble("c_price"));
                    goods.setVipPrice(rs.getDouble("vip_price"));
                    goods.setGoodsStock(rs.getInt("inventory"));
                    list.add(goods);
                }
                return list;
            }
            else if(check_info.equals("work_date")){
                while (rs.next()){
                    list.add(rs.getDate("work_date"));
                }
                return list;
            }
        } catch (Exception e) {
            System.out.println("出错了哦...");
        }
        return list;
    }

7.创建增删改统一方法

public static void updates(String sql,Object...args){//可变参数列表
        try (
                PreparedStatement ps = getConnection().prepareStatement(sql);
        ) {
            if (args != null && args.length > 0) {//可变参数不为空
                int parameterIndex = 1;//sql语句的?位置
                for (int i = 0; i < args.length; i++) {//循环赋值
                    ps.setObject(parameterIndex++, args[i]);
                }
            }
            ps.executeUpdate();
            
        } catch (Exception e) {
            System.out.println("出错了哦...");
        }
    }

8.工具类源码

/**
 * @ClassName until.JDBCUntil
 * @Description JDBC工具类
 * @Author chenxys
 * @Date 2022/3/10 11:33
 * @Version
 */
@SuppressWarnings("all")
public class JDBCUntil {
    static java.util.Date date = new Date();
    static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    //将时间转换为年月日
    public static String datas = dateFormat.format(date);
    //获取登陆的id
    public static String number;
    //用于存放时间
    static boolean in_time = true;
    //登陆类型
    public static int num;
    static Scanner sc = new Scanner(System.in);
    //创建成功
    private static boolean isCreat = false;
    //创建商品表
    public static void creatTable(){
        if (!isCreat){
            String sql1 ="DROP TABLE IF EXISTS add_goods";
            String sql2 = "CREATE TABLE add_goods\n" +
                    "(\n" +
                    "goods_number int,\n" +
                    "goods_count int,\n" +
                    "add_time datetime,\n" +
                    "add_e_number varchar(20)\n" +
                    ")";
            updates(sql1);
            updates(sql2);
            isCreat = true;
        }
    }
    //是否存在
    public static boolean isCL = false;
    //登陆成功
    static boolean isOk = false;
    static Properties p = new Properties();
    //加载配置文件
    static {
        try (
                InputStream is = JDBCUntil.class.getClassLoader().getResourceAsStream("jdbc.properties");
                ){
            //加载配置文件
            p.load(is);
            //创建进货单
            creatTable();
            //设置当前时间
            setdata();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void setdata(){
        String sql = "select * from work_date ORDER BY work_date desc";
        List work_date = select(sql, "work_date");
        for (Date s:work_date){
            if (datas.compareTo(String.valueOf(s))==0){
                isCL=true;
                return;
            }
        }
        if (!isCL){
            String sqls = "insert into work_date(work_date) values (?) ";
            updates(sqls,datas);
        }
    }
    public static Connection getConnection(){
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(p.getProperty("url"),p.getProperty("username"),p.getProperty("password"));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
    public static void updates(String sql,Object...args){//可变参数列表
        try (
                PreparedStatement ps = getConnection().prepareStatement(sql);
        ) {
            if (args != null && args.length > 0) {//可变参数不为空
                int parameterIndex = 1;//sql语句的?位置
                for (int i = 0; i < args.length; i++) {//循环赋值
                    ps.setObject(parameterIndex++, args[i]);
                }
            }
            ps.executeUpdate();

        } catch (Exception e) {
            System.out.println("出错了哦...");
        }
    }
    //根据不同的String check_info进行不同的解析操作
    public static List select(String sql,String check_info,Object...args){
        List list = new ArrayList<>();
        try (
                PreparedStatement ps = getConnection().prepareStatement(sql);
        ) {
            if (args != null && args.length > 0) {
                int parameterIndex = 1;
                for (int i = 0; i < args.length; i++) {
                    ps.setObject(parameterIndex++, args[i]);
                }
            }
            ResultSet rs = ps.executeQuery();
            //上班打卡信息
            if("check_info_in".equals(check_info)){
                while (rs.next()){
                    if (rs.getString("diff_in_status")!=null){
                        //打印上班状态
                        System.out.println(rs.getString("diff_in_status"));
                        break;
                    }
                }
            }
            //下班打卡信息
            if("check_info_off".equals(check_info)){
                while (rs.next()) {
                    if (rs.getString("diff_off_time") != null) {
                        //打印下班状态
                        System.out.println(rs.getString("diff_off_time"));
                        break;
                    }
                }
            }
            //查询员工信息
            else if("sale".equals(check_info)){
                while (rs.next()){
                    Sale sale = new Sale();
                    sale.setId(rs.getString("number"));
                    sale.setName(rs.getString("username"));
                    sale.setPwd(rs.getString("password"));
                    sale.setSex(rs.getString("sex"));
                    sale.setPhone(rs.getString("phone"));
                    sale.setCategory(rs.getInt("role"));
                    sale.setOnJob(rs.getInt("remark"));
                    list.add(sale);
                }
                return list;
            }
            //查询营业额
            else if("sell_info".equals(check_info)){
                while (rs.next()){
                    Sell_Info sell_info = new Sell_Info();
                    sell_info.setS_c_number(rs.getInt("s_c_number"));
                    sell_info.setS_quantity(rs.getInt("s_quantity"));
                    sell_info.setS_time(rs.getTime("s_time"));
                    sell_info.setS_e_number(rs.getString("s_e_number"));
                    sell_info.setS_vip_number(rs.getString("s_vip_number"));
                    if (rs.getString("s_vip_number")==null) {
                        sell_info.setMoney(rs.getInt("s_quantity")*rs.getDouble("c_price"));
                    }else {
                        sell_info.setMoney(rs.getInt("s_quantity")*rs.getDouble("vip_price"));
                    }
                    list.add(sell_info);
                }
                return list;
            }
            //查询出勤
            else if("attendanceQuery".equals(check_info)){
                while (rs.next()){
                    Check_Info check_infos = new Check_Info();
                    check_infos.setWork_date(rs.getString("work_date"));
                    check_infos.setEmployee_no(rs.getString("employee_no"));
                    check_infos.setClock_in_time(rs.getString("clock_in_time"));
                    check_infos.setClock_off_time(rs.getString("clock_off_time"));
                    check_infos.setDiff_in_status(rs.getString("diff_in_status"));
                    check_infos.setDiff_off_time(rs.getString("diff_off_time"));
                    list.add(check_infos);
                }
                return list;
            }
            //查询VIP
            else if("vip".equals(check_info)){
                while (rs.next()){
                    VIP vip = new VIP();
                    vip.setId(rs.getString("v_number"));
                    vip.setName(rs.getString("v_name"));
                    vip.setIntegral(rs.getInt("v_score"));
                    vip.setPhone(rs.getString("v_phone"));
                    vip.setData(rs.getDate("v_date"));
                    list.add(vip);
                }
                return list;
            }
            //查询打卡记录表
            else if("clock_info".equals(check_info)){
                while (rs.next()){
                    Clock_info clock_info = new Clock_info();
                    clock_info.setClock_id(rs.getInt("clock_id"));
                    clock_info.setEmployee_no(rs.getString("employee_no"));
                    clock_info.setClock_in_time(rs.getDate("clock_in_time"));
                    clock_info.setClock_out_time(rs.getDate("clock_off_time"));
                    clock_info.setClock_date(rs.getDate("clock_date"));
                    list.add(clock_info);
                }
                return list;
            }
            //查询货品
            else if(check_info.equals("goods")){
                while (rs.next()){
                    Goods goods = new Goods();
                    goods.setGoodsId(rs.getInt("c_number"));
                    goods.setGoodsName(rs.getString("c_name"));
                    goods.setGoodsPrice(rs.getDouble("c_price"));
                    goods.setVipPrice(rs.getDouble("vip_price"));
                    goods.setGoodsStock(rs.getInt("inventory"));
                    list.add(goods);
                }
                return list;
            }
            else if(check_info.equals("clock_info")){
                while (rs.next()){
                    Goods goods = new Goods();
                    goods.setGoodsId(rs.getInt("c_number"));
                    goods.setGoodsName(rs.getString("c_name"));
                    goods.setGoodsPrice(rs.getDouble("c_price"));
                    goods.setVipPrice(rs.getDouble("vip_price"));
                    goods.setGoodsStock(rs.getInt("inventory"));
                    list.add(goods);
                }
                return list;
            }
            else if(check_info.equals("work_date")){
                while (rs.next()){
                    list.add(rs.getDate("work_date"));
                }
                return list;
            }
        } catch (Exception e) {
            System.out.println("出错了哦...");
        }
        return list;
    }
    //上班打卡
    public static void clockIn(){
        date = new java.util.Date();
        SimpleDateFormat dateFormats = new SimpleDateFormat("HH:mm:ss");
        String sql = "INSERT INTO clock_info(employee_no,clock_in_time,clock_date) values(?,?,?)";
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        List clock_info = select(sqll, "clock_info", number, dateFormat.format(date));
        if (clock_info.size()==0){
            updates(sql,number,date,dateFormat.format(date));
            //显示是否迟到
            String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
            select(sqls,"check_info_in",datas,number);
        }else {
            System.out.println("你已打过卡...");
        }
    }
    //下班打卡
    public static void clockOut(){
        java.util.Date date1 = new Date();
        String format = dateFormat.format(date1);
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        List clock_info = select(sqll, "clock_info", number, dateFormat.format(date));
        for(Clock_info clockInfo:clock_info){
            if (clockInfo.getClock_out_time()!=null){
                System.out.println("你已打过卡...");
            }
            else {
                String sql = "UPDATE  clock_info set clock_off_time=? where clock_date like ? and employee_no=?";
                updates(sql,date,format,number);
                String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
                select(sqls,"check_info_off",datas,number);
            }
        }
    }
    //返回是否登陆成功
    public static boolean isIsOk(){
        return isOk;
    }
    //进行登陆
    public static void login(){
        String sql = "select * from employee where number=? and password=?";
        System.out.println("请选择登陆类型:1.管理员 2.收银员 3.采购员 4.VIP ");
        int id = sc.nextInt();
        switch (id){
            case 1:
                System.out.println("请输入账号:");
                String aId = sc.next();
                System.out.println("请输入密码:");
                String aPwd = sc.next();
                List sale = select(sql, "sale", aId, aPwd);
                if(sale.size()!=0){
                    for (Sale sale1:sale) {
                        if (sale1.getCategory().equals("管理员")) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = sale1.getId();
                            num = 1;
                            return;
                        }
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            case 2:
                System.out.println("请输入账号:");
                String bId = sc.next();
                System.out.println("请输入密码:");
                String bPwd = sc.next();
                List sale2 = select(sql, "sale", bId, bPwd);
                if(sale2.size()!=0){
                    for (Sale sale1:sale2) {
                        if (sale1.getCategory().equals("收银员")) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = sale1.getId();
                            num = 2;
                            return;
                        }
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            case 3:
                System.out.println("请输入账号:");
                String cId = sc.next();
                System.out.println("请输入密码:");
                String cPwd = sc.next();
                List sale3 = select(sql, "sale", cId, cPwd);
                if(sale3.size()!=0){
                    for (Sale sale1:sale3) {
                        if (sale1.getCategory().equals("采购员")) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = sale1.getId();
                            num = 3;
                            return;
                        }
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            case 4:
                System.out.println("请输入VIP账号:");
                String VIPId = sc.next();
                System.out.println("请输入VIPs手机号码:");
                String VIPPhone = sc.next();
                String sqlVIP = "select * from vip where v_number=? and v_phone=?";
                List sale4 = select(sqlVIP, "vip", VIPId, VIPPhone);
                if(sale4.size()!=0){
                    for (VIP vip:sale4) {
                        if (vip.getId()!=null) {
                            System.out.println("登陆成功...");
                            isOk = true;
                            number = vip.getId();
                            num = 4;
                            return;
                        }
                    }
                }else {
                    System.out.println("登陆失败...");
                    isOk=false;
                }
                break;
            default:
                isOk=false;
                break;
        }
    }
    //2021-4月上班打卡
    public static void clockIns(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String sql = "INSERT INTO clock_info(employee_no,clock_in_time,clock_date) values(?,?,?)";
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        //2021-4-6到目前的毫秒数
        long time = 29376000000l;
        long currTime = (System.currentTimeMillis()-time);
        List clock_info = JDBCUntil.select(sqll, "clock_info", number, format.format(currTime));
        if (clock_info.size()==0){
            JDBCUntil.updates(sql,number,dateFormat.format(currTime),format.format(currTime));
            //显示是否迟到
            String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
            JDBCUntil.select(sqls,"check_info_in",format.format(currTime),number);
        }else {
            System.out.println("你已打过卡...");
        }
    }
    //2021-4下班打卡
    public static void clockOuts(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //2021-4-6到目前的毫秒数
        long time = 29376000000l;
        long currTime = (System.currentTimeMillis()-time);
        String sqll = "select * from clock_info where employee_no=? and clock_date=?";
        List clock_info = select(sqll, "clock_info", number, format.format(currTime));
        for(Clock_info clockInfo:clock_info){
            if (clockInfo.getClock_out_time()!=null){
                System.out.println("你已打过卡...");
            }
            else {
                String sql = "UPDATE  clock_info set clock_off_time=? where clock_date like ? and employee_no=?";
                updates(sql,dateFormat.format(currTime),format.format(currTime),number);
                String sqls = "select * from check_info where work_date=? and employee_no=? limit 1";
                select(sqls,"check_info_off",format.format(currTime),number);
            }
        }
    }
}

你可能感兴趣的:(超市管理系统,mysql,数据库,java)