Java教程

狂神说java超市管理系统service层

本文主要是介绍狂神说java超市管理系统service层,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

接口

package service.LogService.RoleService;

import po.role;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public interface RoleList {
    public List<role> RoleListService() throws SQLException, ClassNotFoundException;
}

 

package service.LogService;

import po.user;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public interface LoginService {
    //登入接口
    public user Login(String User,String pwd) throws SQLException, ClassNotFoundException;
    //修改密码接口
    public  boolean UppwdService(int id,String pwd) throws SQLException, ClassNotFoundException;
    //获取人员数量
    public  int CountService(String Username,int id) throws SQLException, ClassNotFoundException;
    //获取人员信息
    public List <user> UserList(String UserName, int id,int a,int b) throws SQLException, ClassNotFoundException;
    //添加用户
    public boolean adduser(user user) throws SQLException, ClassNotFoundException;
    //查询用户是否存在
    public  boolean exuser(String user);
    //删除用户
    public boolean deluser(int id);
    //根据ID查询用户
    public  user selectuser(int id);
    //更新用户信息
    public Boolean UPuser(user user);
}

实现类

package service.LogService.RoleService;

import dao.BaseDao;
import dao.Role.RoleListimpl;
import po.role;
import service.LogService.RoleService.RoleList;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleListServiceimpl implements RoleList {
    public List<role> RoleListService() {
        Connection conn  = null;
        try {
            conn = BaseDao.GetConn();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        RoleListimpl roleListimpl = new RoleListimpl();
        List<role> roles = null;
        try {
            roles = roleListimpl.SelectRole(conn);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        BaseDao.ConnClose((com.mysql.jdbc.Connection) conn,null,null);
        return roles;
    }
}

 

package service.LogService;
import com.mysql.jdbc.StringUtils;
import dao.BaseDao;
import dao.LoginDao.LoginDao;
import dao.LoginDao.LoginDaoImpl;
import po.user;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
//登入service
public class LoginServiceImpl implements LoginService {
    LoginDao loginDao;

    public LoginServiceImpl() {
        loginDao = new LoginDaoImpl();
    }
//登入
    public user Login(String User, String pwd) throws SQLException, ClassNotFoundException {
        Connection conn = BaseDao.GetConn();
        user user1 = null;
        user1 = loginDao.LoginUser(conn, User);
        BaseDao.ConnClose((com.mysql.jdbc.Connection) conn, null, null);
        return user1;
    }
//修改service
    public boolean UppwdService(int id, String pwd) throws SQLException, ClassNotFoundException {
        Connection conn = null;
        boolean flag;
        int i = 0;
        if (pwd != null) {
            conn = BaseDao.GetConn();
            i = loginDao.UpPwd(conn, id, pwd);
        }
        if (i != 0) {
            flag = true;
        } else {
            flag = false;
        }
        return flag;
    }
//通过组或用户名获取数量
    public int CountService(String Username, int id) throws SQLException, ClassNotFoundException {
        Connection conn = null;
        conn = BaseDao.GetConn();
        int count = loginDao.CountName(conn, Username, id);
        BaseDao.ConnClose((com.mysql.jdbc.Connection) conn, null, null);
        return count;
    }
//获取用户列表
    public List<user> UserList(String UserName, int id, int a, int b) throws SQLException, ClassNotFoundException {
        Connection conn = null;
        conn = BaseDao.GetConn();
        ArrayList<user> UserList = new ArrayList<user>();
        UserList = (ArrayList<user>) loginDao.UerList(conn, UserName, id, a, b);
        BaseDao.ConnClose((com.mysql.jdbc.Connection) conn, null, null);
        return UserList;
    }
//添加用户
    public boolean adduser(user user) throws SQLException {
        boolean flag = false;
        Connection conn = null;
        if (user != null) {
            if (StringUtils.isNullOrEmpty(user.getUserPassword())) {
                flag = false;
            }
            if (StringUtils.isNullOrEmpty(user.getUserCode())) {
                flag = false;
            }
            if (StringUtils.isNullOrEmpty(user.getUserRole())) {
                flag = false;
            };
            try {
                conn = BaseDao.GetConn();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                conn.setAutoCommit(false);
                flag= loginDao.adduser(conn,user);
                conn.commit();
                conn.setAutoCommit(true);
            } catch (SQLException e) {
                conn.rollback();
                e.printStackTrace();
                flag=false;
            }finally {
                BaseDao.ConnClose((com.mysql.jdbc.Connection) conn,null,null);
            }
        }
        return flag;
    }
//查询用户是否存在
    public boolean exuser(String user) {
        boolean flag=false;
        int a=0;
        Connection conn=null;
        try {
            conn = BaseDao.GetConn();
            a= loginDao.ecuser(conn,user);
            if(a>0){
                flag=false;
            }else{
                flag=true;
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return flag;
    }
//删除用户
    public boolean deluser(int id) {
        boolean flag=false;
        Connection conn=null;
        int a=0;
        try {
            conn=BaseDao.GetConn();
           a = loginDao.deluser(conn,id);
           if(a>0){
               flag = true;
           }else{
               flag=false;
           }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            flag=false;
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.ConnClose((com.mysql.jdbc.Connection) conn,null,null);
        }
        return flag;
    }
    //根据用户查询ID;
    public user selectuser(int id) {
        user user = new user();
        user =null;
        Connection conn=null;
        try {
            conn = BaseDao.GetConn();
            user= loginDao.selectuser(conn,id);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user;
    }
  //更新用户信息
    public Boolean UPuser(user user) {
        boolean  flag = false;
        Connection conn=null;
        int updatauser = 0;
        try {
            conn =BaseDao.GetConn();
            conn.setAutoCommit(false);
            updatauser = loginDao.updatauser(conn, user);
            conn.commit();
            conn.setAutoCommit(true);
            if(updatauser!=0){
                flag = true;
            }else{
                flag = false;
            }
        } catch (ClassNotFoundException e) {
            try {
                conn.rollback();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            e.printStackTrace();
            flag = false;
        } catch (SQLException e) {
            try {
                conn.rollback();
                flag = false;
            } catch (SQLException ex) {
                ex.printStackTrace();
                flag = false;
            }
            e.printStackTrace();
            flag = false;
        }finally {
            BaseDao.ConnClose((com.mysql.jdbc.Connection) conn,null,null);
        }
        return flag;
    }
}

 

这篇关于狂神说java超市管理系统service层的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!