本文實例為大家分享了java書店系統(tǒng)畢業(yè)設(shè)計第二篇,供大家參考,具體內(nèi)容如下
1、用戶管理(user.txt)
字段名和順序
說明:其中的type為int類型,用來表示操作用戶的類型。
1——表示為admin,可以進(jìn)行全部操作
2——表示為能操作圖書模塊的人員
3——表示為能操作進(jìn)貨模塊的人員
4——表示為能操作銷售模塊的人員
5——表示為能操作庫存模塊的人員
type用了枚舉實現(xiàn)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package cn.hncu.bookStore.user.common; public enum UserTypeEnum { AdMIN( 1 , "超級管理員" ),BOOK( 2 , "圖書管理員" ),IN( 3 , "進(jìn)貨管理員" ),OUT( 4 , "銷售管理員" ),STOCK( 5 , "庫存管理員" ); private final int type; private final String name; UserTypeEnum( int type,String name){ //默認(rèn)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+ "\"對應(yīng)的用戶類型" ); //非法參數(shù)異常 } public static String getNameByType( int type){ for (UserTypeEnum utm:UserTypeEnum.values()){ if (utm.getType()==type){ return utm.getName(); } } throw new IllegalArgumentException( "沒有該\"" +type+ "\"對應(yīng)的用戶類型" ); //非法參數(shù)異常 } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package cn.hncu.bookStore.user.vo; import java.io.Serializable; import cn.hncu.bookStore.user.common.UserTypeEnum; /** * *@author<a href="mailto:[email protected]">xzm</a> */ 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); } } |
1
2
3
4
|
package cn.hncu.bookStore.user.vo; public class UserQueryModel extends UserModel{ private static final long serialVersionUID = 1L; } |
dao層:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
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 { /** * 注冊一個新用戶,如果該用戶存在,則不能創(chuàng)建 * @param user * 待創(chuàng)建的用戶 * @return * 如果創(chuàng)建成功,則返回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); /** * 查詢一個用戶的數(shù)據(jù) * @param uuid * 待查詢信息的用戶編號 * @return * 如果用戶存在,返回指定 uuid的用戶對象,否則返回null */ public UserModel getSingle(String uuid); /** * 根據(jù)查詢值對象約束的條件,返回所有滿足user的用戶對象集合 * @param user * 查詢值對象 * @return * 如果有滿足查詢值對象約束的條件的用戶,則返回用戶對象集合,否則返回空集合 */ public List<UserModel> getByCondition(UserQueryModel user); /** * 獲取文件中所有用戶對象 * @return * 返回文件中所有用戶對象 */ public List<UserModel> getAll(); } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
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<UserModel> list=getAll(); //獲取文件中已存在的所有用戶對象 for (UserModel u:list){ //遍歷 if (u.getUuid().equals(user.getUuid())){ //如果此用戶已存在,則不能注冊 return false ; } } //經(jīng)過上面的遍歷,說明user不存在,則可以注冊 list.add(user); return FileIOUtil.writeToFile(list, FILE_NAME); } @Override public boolean delete(String uuid) { List<UserModel> list=getAll(); for ( int i= 0 ;i<list.size();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<UserModel> list=getAll(); for ( int i= 0 ;i<list.size();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<UserModel> list=getAll(); for (UserModel u:list){ if (u.getUuid().equals(uuid)){ return u; } } return null ; } @Override public List<UserModel> getByCondition(UserQueryModel user) { List<UserModel> list=getAll(); List<UserModel> reslist= new ArrayList<UserModel>(); 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<UserModel> getAll() { return FileIOUtil.readFromFile(FILE_NAME); } } |
1
2
3
4
5
6
7
8
9
10
11
|
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(); } } |
業(yè)務(wù)邏輯層:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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<UserModel> getByCondition(UserQueryModel user); public List<UserModel> getAll(); public abstract List<UserModel> getAllIn(); public List<UserModel> getAllOut(); } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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.getUuidDAO().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<UserModel> getByCondition(UserQueryModel user) { return dao.getByCondition(user); } @Override public List<UserModel> getAll() { return dao.getAll(); } @Override public List<UserModel> getAllIn() { UserQueryModel user= new UserQueryModel(); user.setType(UserTypeEnum.IN.getType()); return dao.getByCondition(user); } public List<UserModel> getAllOut() { UserQueryModel user= new UserQueryModel(); user.setType(UserTypeEnum.OUT.getType()); return dao.getByCondition(user); } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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(); } } |
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。