多平台统一管理软件接口,如何实现多平台统一管理软件接口
188
2023-07-03
java书店系统毕业设计 用户模块(2)
本文实例为大家分享了java书店系统毕业设计第二篇,供大家参考,具体内容如下
1、用户管理(user.txt)
字段名和顺序
说明:其中的type为int类型,用来表示操作用户的类型。
1——表示为admin,可以进行全部操作
2——表示为能操作图书模块的人员
3——表示为能操作进货模块的人员
4——表示为能操作销售模块的人员
5——表示为能操作库存模块的人员
type用了枚举实现
package cn.hncu.bookStore.user.common;
public enum UserTypeEnum {
AdMIN(1,"超级管理员"),BOOK(2,"图书管理员"),IN(3,"进货管理员"),OUT(4,"销售管理员"),STOCK(5,"库存管理员");
private final int type;
private final String name;
UserTypeEnum(int type,String name){//默认private
this.name =name;
this.type=type;
}
public int getType() {
return type;
}
public String getName() {
return name;
}
public static int getTypeByName(String name){
for(UserTypeEnum utm:UserTypeEnum.values()){
if(utm.getName().equals(name.trim())){
return utm.getType();
}
}
throw new IllegalArgumentException("没有该\""+name+"\"对应的用户类型");//非法参数异常
}
public static String getNameByType(int type){
for(UserTypeEnum utm:UserTypeEnum.values()){
if(utm.getType()==type){
return utm.getName();
}
}
throw new IllegalArgumentException("没有该\""+type+"\"对应的用户类型");//非法参数异常
}
}
package cn.hncu.bookStore.user.vo;
import java.io.Serializable;
import cn.hncu.bookStore.user.common.UserTypeEnum;
/**
*
*@authorxzm
*/
public class UserModel implements Serializable{
private static final long serialVersionUID = 1L;
private String uuid,name,pwd;//用户编号,用户名称,用户密码
private int type;//用户类型
public UserModel() {
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
UserModel other = (UserModel) obj;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
}
@Override
public String toString() {
return uuid + "," + name +"," + UserTypeEnum.getNameByType(type);
}
}
package cn.hncu.bookStore.user.vo;
public class UserQueryModel extends UserModel{
private static final long serialVersionUID = 1L;
}
dao层:
package cn.hncu.bookStore.user.dao.dao;
import java.util.List;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
public interface UserDAo {
/**
* 注册一个新用户,如果该用户存在,则不能创建
* @param user
* 待创建的用户
* @return
* 如果创建成功,则返回true,否则返回false
*/
public boolean create(UserModel user);
/**
* 删除一个用户,如果该用户不存在,则删除失败
* @param uuid
* 待删除用户的uuid
* @return
* 如果删除成功则返回true,否则返回false
*/
public boolean delete(String uuid);
/**
* 更新用户信息,如果用户不存在,则不能更新
* @param user
* 待更新信息的用户
* @return
* 如果更新成功返回true,否则返回false
*/
public boolean update(UserModel user);
/**
* 查询一个用户的数据
* @param uuid
* 待查询信息的用户编号
* @return
* 如果用户存在,返回指定 uuid的用户对象,否则返回null
*/
public UserModel getSingle(String uuid);
/**
* 根据查询值对象约束的条件,返回所有满足user的用户对象集合
* @param user
* 查询值对象
* @return
* 如果有满足查询值对象约束的条件的用户,则返回用户对象集合,否则返回空集合
*/
public List
/**
* 获取文件中所有用户对象
* @return
* 返回文件中所有用户对象
*/
public List
}
package cn.hncu.bookStore.user.dao.impl;
import java.util.ArrayList;
import java.util.List;
import cn.hncu.bookStore.user.dao.dao.UserDAo;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
import cn.hncu.bookStore.utils.FileIOUtil;
public class UserDAOFileImpl implements UserDAo {
private final static String FILE_NAME="a.txt";
@Override
public boolean create(UserModel user) {
if(user==null){//如果待注册的用户信息为null,则不能注册,返回false
return false;
}
List
for(UserModel u:list){//遍历
if(u.getUuid().equals(user.getUuid())){//如果此用户已存在,则不能注册
return false;
}
}
//经过上面的遍历,说明user不存在,则可以注册
list.add(user);
return FileIOUtil.writeToFile(list, FILE_NAME);
}
@Override
public boolean delete(String uuid) {
List
for(int i=0;i UserModel u=list.get(i); if(u.getUuid().equals(uuid)){ list.remove(i);//删除 return FileIOUtil.writeToFile(list, FILE_NAME); } } return false; } @Override public boolean update(UserModel user) { List for(int i=0;i UserModel u=list.get(i); if(u.getUuid().equals(user.getUuid())){ list.set(i, user);//重置编号为user.getUuid()的用户 return FileIOUtil.writeToFile(list, FILE_NAME); } } return false; } @Override public UserModel getSingle(String uuid) { List for(UserModel u:list){ if(u.getUuid().equals(uuid)){ return u; } } return null; } @Override public List List List for(UserModel u:list){ if(user.getUuid()!=null && user.getUuid().trim().length()>0){ if(!user.getUuid().trim().equals(u.getUuid())){ continue; } } if(user.getName()!=null && user.getName().trim().length()>0){ if(u.getName().indexOf(user.getName())==-1){ continue; } } if(user.getType()>0){ if(u.getType()!=user.getType()){ continue; } } reslist.add(u); } return reslist; } @Override public List return FileIOUtil.readFromFile(FILE_NAME); } } package cn.hncu.bookStore.user.dao.factory; import cn.hncu.bookStore.user.dao.dao.UserDAo; import cn.hncu.bookStore.user.dao.impl.UserDAOFileImpl; public class UserDAOFactory { private UserDAOFactory(){ } public static UserDAo getUserDAo(){ return new UserDAOFileImpl(); } } 业务逻辑层: package cn.hncu.bookStore.user.business.ebi; import java.util.List; import cn.hncu.bookStore.user.vo.UserModel; import cn.hncu.bookStore.user.vo.UserQueryModel; public interface UserEbi { public boolean create(UserModel user); public boolean delete(String uuid); public boolean update(UserModel user); public UserModel getSingle(String uuid); public List public List public abstract List public List } package cn.hncu.bookStore.user.business.ebo; import java.util.List; import cn.hncu.bookStore.common.uuidModelConstance; import cn.hncu.bookStore.common.uuid.dao.factory.uuidDAOFactory; import cn.hncu.bookStore.user.business.ebi.UserEbi; import cn.hncu.bookStore.user.common.UserTypeEnum; import cn.hncu.bookStore.user.dao.dao.UserDAo; import cn.hncu.bookStore.user.dao.factory.UserDAOFactory; import cn.hncu.bookStore.user.vo.UserModel; import cn.hncu.bookStore.user.vo.UserQueryModel; public class UserEbo implements UserEbi { //注入 UserDAo dao = UserDAOFactory.getUserDAo(); @Override public boolean create(UserModel user) { String uuid=uuidDAOFactory.getUuhttp://idDAO().getNextNum(uuidModelConstance.User); user.setUuid(uuid); return dao.create(user); } @Override public boolean delete(String uuid) { return dao.delete(uuid); } @Override public boolean update(UserModel user) { return dao.update(user); } @Override public UserModel getSingle(String uuid) { return dao.getSingle(uuid); } @Override public List return dao.getByCondition(user); } @Override public List return dao.getAll(); } @Override public List UserQueryModel user=new UserQueryModel(); user.setType(UserTypeEnum.IN.getType()); return dao.getByCondition(user); } public List UserQueryModel user=new UserQueryModel(); user.setType(UserTypeEnum.OUT.getType()); return dao.getByCondition(user); } } package cn.hncu.bookStore.user.business.factory; import cn.hncu.bookStore.user.business.ebi.UserEbi; import cn.hncu.bookStore.user.business.ebo.UserEbo; public class UserEbiFactory { private UserEbiFactory() { } public static UserEbi getUserEbi(){ return new UserEbo(); } }
UserModel u=list.get(i);
if(u.getUuid().equals(uuid)){
list.remove(i);//删除
return FileIOUtil.writeToFile(list, FILE_NAME);
}
}
return false;
}
@Override
public boolean update(UserModel user) {
List
for(int i=0;i UserModel u=list.get(i); if(u.getUuid().equals(user.getUuid())){ list.set(i, user);//重置编号为user.getUuid()的用户 return FileIOUtil.writeToFile(list, FILE_NAME); } } return false; } @Override public UserModel getSingle(String uuid) { List for(UserModel u:list){ if(u.getUuid().equals(uuid)){ return u; } } return null; } @Override public List List List for(UserModel u:list){ if(user.getUuid()!=null && user.getUuid().trim().length()>0){ if(!user.getUuid().trim().equals(u.getUuid())){ continue; } } if(user.getName()!=null && user.getName().trim().length()>0){ if(u.getName().indexOf(user.getName())==-1){ continue; } } if(user.getType()>0){ if(u.getType()!=user.getType()){ continue; } } reslist.add(u); } return reslist; } @Override public List return FileIOUtil.readFromFile(FILE_NAME); } } package cn.hncu.bookStore.user.dao.factory; import cn.hncu.bookStore.user.dao.dao.UserDAo; import cn.hncu.bookStore.user.dao.impl.UserDAOFileImpl; public class UserDAOFactory { private UserDAOFactory(){ } public static UserDAo getUserDAo(){ return new UserDAOFileImpl(); } } 业务逻辑层: package cn.hncu.bookStore.user.business.ebi; import java.util.List; import cn.hncu.bookStore.user.vo.UserModel; import cn.hncu.bookStore.user.vo.UserQueryModel; public interface UserEbi { public boolean create(UserModel user); public boolean delete(String uuid); public boolean update(UserModel user); public UserModel getSingle(String uuid); public List public List public abstract List public List } package cn.hncu.bookStore.user.business.ebo; import java.util.List; import cn.hncu.bookStore.common.uuidModelConstance; import cn.hncu.bookStore.common.uuid.dao.factory.uuidDAOFactory; import cn.hncu.bookStore.user.business.ebi.UserEbi; import cn.hncu.bookStore.user.common.UserTypeEnum; import cn.hncu.bookStore.user.dao.dao.UserDAo; import cn.hncu.bookStore.user.dao.factory.UserDAOFactory; import cn.hncu.bookStore.user.vo.UserModel; import cn.hncu.bookStore.user.vo.UserQueryModel; public class UserEbo implements UserEbi { //注入 UserDAo dao = UserDAOFactory.getUserDAo(); @Override public boolean create(UserModel user) { String uuid=uuidDAOFactory.getUuhttp://idDAO().getNextNum(uuidModelConstance.User); user.setUuid(uuid); return dao.create(user); } @Override public boolean delete(String uuid) { return dao.delete(uuid); } @Override public boolean update(UserModel user) { return dao.update(user); } @Override public UserModel getSingle(String uuid) { return dao.getSingle(uuid); } @Override public List return dao.getByCondition(user); } @Override public List return dao.getAll(); } @Override public List UserQueryModel user=new UserQueryModel(); user.setType(UserTypeEnum.IN.getType()); return dao.getByCondition(user); } public List UserQueryModel user=new UserQueryModel(); user.setType(UserTypeEnum.OUT.getType()); return dao.getByCondition(user); } } package cn.hncu.bookStore.user.business.factory; import cn.hncu.bookStore.user.business.ebi.UserEbi; import cn.hncu.bookStore.user.business.ebo.UserEbo; public class UserEbiFactory { private UserEbiFactory() { } public static UserEbi getUserEbi(){ return new UserEbo(); } }
UserModel u=list.get(i);
if(u.getUuid().equals(user.getUuid())){
list.set(i, user);//重置编号为user.getUuid()的用户
return FileIOUtil.writeToFile(list, FILE_NAME);
}
}
return false;
}
@Override
public UserModel getSingle(String uuid) {
List
for(UserModel u:list){
if(u.getUuid().equals(uuid)){
return u;
}
}
return null;
}
@Override
public List
List
List
for(UserModel u:list){
if(user.getUuid()!=null && user.getUuid().trim().length()>0){
if(!user.getUuid().trim().equals(u.getUuid())){
continue;
}
}
if(user.getName()!=null && user.getName().trim().length()>0){
if(u.getName().indexOf(user.getName())==-1){
continue;
}
}
if(user.getType()>0){
if(u.getType()!=user.getType()){
continue;
}
}
reslist.add(u);
}
return reslist;
}
@Override
public List
return FileIOUtil.readFromFile(FILE_NAME);
}
}
package cn.hncu.bookStore.user.dao.factory;
import cn.hncu.bookStore.user.dao.dao.UserDAo;
import cn.hncu.bookStore.user.dao.impl.UserDAOFileImpl;
public class UserDAOFactory {
private UserDAOFactory(){
}
public static UserDAo getUserDAo(){
return new UserDAOFileImpl();
}
}
业务逻辑层:
package cn.hncu.bookStore.user.business.ebi;
import java.util.List;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
public interface UserEbi {
public boolean create(UserModel user);
public boolean delete(String uuid);
public boolean update(UserModel user);
public UserModel getSingle(String uuid);
public List
public List
public abstract List
public List
}
package cn.hncu.bookStore.user.business.ebo;
import java.util.List;
import cn.hncu.bookStore.common.uuidModelConstance;
import cn.hncu.bookStore.common.uuid.dao.factory.uuidDAOFactory;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.common.UserTypeEnum;
import cn.hncu.bookStore.user.dao.dao.UserDAo;
import cn.hncu.bookStore.user.dao.factory.UserDAOFactory;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
public class UserEbo implements UserEbi {
//注入
UserDAo dao = UserDAOFactory.getUserDAo();
@Override
public boolean create(UserModel user) {
String uuid=uuidDAOFactory.getUuhttp://idDAO().getNextNum(uuidModelConstance.User);
user.setUuid(uuid);
return dao.create(user);
}
@Override
public boolean delete(String uuid) {
return dao.delete(uuid);
}
@Override
public boolean update(UserModel user) {
return dao.update(user);
}
@Override
public UserModel getSingle(String uuid) {
return dao.getSingle(uuid);
}
@Override
public List
return dao.getByCondition(user);
}
@Override
public List
return dao.getAll();
}
@Override
public List
UserQueryModel user=new UserQueryModel();
user.setType(UserTypeEnum.IN.getType());
return dao.getByCondition(user);
}
public List
UserQueryModel user=new UserQueryModel();
user.setType(UserTypeEnum.OUT.getType());
return dao.getByCondition(user);
}
}
package cn.hncu.bookStore.user.business.factory;
import cn.hncu.bookStore.user.business.ebi.UserEbi;
import cn.hncu.bookStore.user.business.ebo.UserEbo;
public class UserEbiFactory {
private UserEbiFactory() {
}
public static UserEbi getUserEbi(){
return new UserEbo();
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~