5.29blog:
(一)數據庫設計部分:
創建數據庫hourse:
1:關注表
CREATE TABLE `guanzhu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`hid` int(11) DEFAULT NULL,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
2:歷史表
CREATE TABLE `history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`uname` varchar(65) DEFAULT NULL,
`createtime` datetime DEFAULT NULL,
`hid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8;
3:房屋信息表
CREATE TABLE `hourse` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uname` varchar(255) DEFAULT NULL COMMENT '房東名字',
`uid` int(11) DEFAULT NULL,
`image` varchar(255) DEFAULT NULL COMMENT '主視圖',
`image1` varchar(255) DEFAULT NULL,
`image2` varchar(255) DEFAULT NULL,
`area` int(11) DEFAULT NULL COMMENT '面積',
`address` varchar(255) DEFAULT NULL COMMENT '地址',
`rent_type` int(11) DEFAULT NULL COMMENT '0 日租 1月租',
`day_price` double DEFAULT NULL COMMENT '日租金',
`month_price` double DEFAULT NULL COMMENT '月租金',
`hourse_type` int(66) unsigned DEFAULT NULL COMMENT '1一室一廳2兩室一廳3三室一廳',
`state` int(11) DEFAULT '0' COMMENT '0可申請 1已申請 2已審覈 3已入組 4已退房',
`fabu_state` int(11) DEFAULT '0' COMMENT '0 未審覈 自己房屋審覈情況',
`name` varchar(64) DEFAULT NULL COMMENT '名字',
`xiaoqv` varchar(64) DEFAULT NULL COMMENT '歸屬小區',
`introduce` varchar(4000) DEFAULT NULL COMMENT '房子介紹',
`xqintrodece` varchar(4000) DEFAULT NULL COMMENT '小區介紹',
`createtime` datetime DEFAULT NULL COMMENT '發佈時間',
`tel` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
4:訂單房屋表
CREATE TABLE `hourse_order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`hid` int(11) DEFAULT NULL COMMENT '房子ID',
`in_time` datetime DEFAULT NULL COMMENT '入住時間',
`pay_type` int(11) DEFAULT NULL COMMENT '支付方式',
`out_time` datetime DEFAULT NULL COMMENT '退房時間',
`price` double DEFAULT NULL COMMENT '總價',
`state` int(11) DEFAULT NULL COMMENT '申請狀態',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5:留言實體表
CREATE TABLE `message` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` varchar(2000) DEFAULT NULL COMMENT '留言內容',
`uid` int(11) DEFAULT NULL COMMENT '留言人',
`hid` int(11) DEFAULT NULL COMMENT '被留言房屋',
`rank` int(11) DEFAULT NULL COMMENT '評分',
`time` datetime DEFAULT NULL COMMENT '評論時間',
`uname` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
6:CREATE TABLE `my_hource` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`hid` int(11) DEFAULT NULL,
`time` datetime DEFAULT NULL,
`uid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
7:申請表
CREATE TABLE `shenqing` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL COMMENT '申請人id',
`hid` int(11) DEFAULT NULL COMMENT '房子ID',
`time` datetime DEFAULT NULL COMMENT '申請時間',
`uname` varchar(64) DEFAULT NULL COMMENT '房東姓名',
`state` int(11) DEFAULT NULL COMMENT '申請狀態',
`intime` varchar(64) DEFAULT NULL COMMENT '入住時間',
`renttype` int(11) DEFAULT NULL COMMENT '租住類型',
`price` double DEFAULT NULL COMMENT '價格',
`hname` varchar(64) DEFAULT NULL COMMENT '房子姓名',
`huid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
8:用戶表
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`realname` varchar(255) DEFAULT NULL,
`role` varchar(32) DEFAULT 's' COMMENT 'admin guest',
`image` varchar(64) DEFAULT NULL COMMENT 'u圖片',
`address` varchar(255) DEFAULT NULL COMMENT '收貨地址',
`phone` varchar(64) DEFAULT NULL,
`idnumber` varchar(65) DEFAULT NULL COMMENT '身份證號',
`tel` varchar(64) DEFAULT NULL,
`sex` int(11) DEFAULT '0',
`pay` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
(二)典型代碼展示部分:(代碼不知道貼什麼,所以詳細設計與系統實現還是見文檔吧)
import java.util.*;
import java.util.Map.Entry;
/**
* 基於用戶的協同過濾推薦算法實現
A a b d
B a c
C b e
D c d e
* @author Administrator
*
*/
public class UserCF {
/**
*
* @param userList 用戶喜好集合
* @param recommendUser 需要的用戶
* @return
*/
public List<Integer> recoment(List<RecommentUser> userList,Integer recommendUser){
List<Sorf> sorfList = new ArrayList<>();
int[][] sparseMatrix = new int[userList.size()][userList.size()];//建立用戶稀疏矩陣,用於用戶相似度計算【相似度矩陣】
Map<Integer, Integer> userItemLength = new HashMap<>();//存儲每一個用戶對應的不同物品總數 eg: A 3
Map<Integer, Set<Integer>> itemUserCollection = new HashMap<>();//建立物品到用戶的倒排表 eg: a A B
Set<Integer> items = new HashSet<>();//輔助存儲物品集合
Map<Integer, Integer> userID = new HashMap<>();//輔助存儲每一個用戶的用戶ID映射
Map<Integer, Integer> idUser = new HashMap<>();//輔助存儲每一個ID對應的用戶映射
System.out.println("Input user--items maping infermation:<eg:A a b d>");
for(int i = 0; i < userList.size() ; i++){//依次處理N個用戶 輸入數據 以空格間隔
RecommentUser user = userList.get(i);
int uid = userList.get(i).getId();
int size = userList.get(i).getLikeList().size();
userItemLength.put(uid, size);//eg: A 3
userID.put(uid, i);//用戶ID與稀疏矩陣建立對應關係
idUser.put(i, uid);
//建立物品--用戶倒排表
for(int j = 0; j < size; j ++){
if(items.contains(user.getLikeList().get(j))){//如果已經包含對應的物品--用戶映射,直接添加對應的用戶
itemUserCollection.get(user.getLikeList().get(j)).add(uid);
}else{//否則創建對應物品--用戶集合映射
items.add(user.getLikeList().get(j));
itemUserCollection.put(user.getLikeList().get(j), new HashSet<Integer>());//創建物品--用戶倒排關係
itemUserCollection.get(user.getLikeList().get(j)).add(uid);
}
}
}
System.out.println(itemUserCollection.toString());
//計算相似度矩陣【稀疏】
Set<Entry<Integer, Set<Integer>>> entrySet = itemUserCollection.entrySet();
Iterator<Entry<Integer, Set<Integer>>> iterator = entrySet.iterator();
while(iterator.hasNext()){
Set<Integer> commonUsers = iterator.next().getValue();
for (Integer user_u : commonUsers) {
for (Integer user_v : commonUsers) {
if(user_u.equals(user_v)){
continue;
}
sparseMatrix[userID.get(user_u)][userID.get(user_v)] += 1;//計算用戶u與用戶v都有正反饋的物品總數
}
}
}
for (int i = 0; i < userList.size(); i++) {
System.out.println("用戶" + userList.get(i).getId() + ":" + userList.get(i).getLikeList().toString());
}
//計算用戶之間的相似度【餘弦相似性】
int recommendUserId = userID.get(recommendUser);
for (int j = 0;j < sparseMatrix.length; j++) {
if(j != recommendUserId){
System.out.println(idUser.get(recommendUserId)+"--"+idUser.get(j)+"相似度:"+sparseMatrix[recommendUserId][j]/Math.sqrt(userItemLength.get(idUser.get(recommendUserId))*userItemLength.get(idUser.get(j))));
}
}
//計算指定用戶recommendUser的物品推薦度
for(Integer item: items){//遍歷每一件物品
Set<Integer> users = itemUserCollection.get(item);//得到購買當前物品的所有用戶集合
if(!users.contains(recommendUser)){//如果被推薦用戶沒有購買當前物品
// 則進行推薦度計算
double itemRecommendDegree = 0.0;
for(Integer user: users){
itemRecommendDegree += sparseMatrix[userID.get(recommendUser)][userID.get(user)]/Math.sqrt(userItemLength.get(recommendUser)*userItemLength.get(user));//推薦度計算
}
System.out.println("商品"+item+" 對用戶 "+recommendUser +"'推薦度:"+itemRecommendDegree);
Sorf sorf = new Sorf(item,itemRecommendDegree);
sorfList.add(sorf);
}
}
Collections.sort(sorfList);
int size = 0;
if(sorfList.size() <5){
size = sorfList.size();
}else {
size = 4;
}
List<Integer> ids = new ArrayList<>();
for (int i = 0; i < size; i++) {
ids.add(sorfList.get(i).getKey());
}
return ids;
}
}
6.19blog:
(一)測試:
單元測試:
黑盒測試:
(二)部署過程:
第一步:服務器的環境部署
1:安裝jdk8
2:安裝MySQL5.7 可以按照這個鏈接進行安裝:https://www.cnblogs.com/chancy/p/9444187.html
3:在服務器上安裝tomcat,安裝完成過後開啓服務,在自己電腦瀏覽器地址欄輸入IP:8080
4:可以用Xftp將已經打包好的項目.war發送到服務器webapps目錄下,並改名爲ROOT.war(記得將原來的ROOT刪除)
5:然後瀏覽器輸入IP:8080/就出現了我們的項目了
(三)項目訪問地址以及需注意的相關事項說明:
瀏覽器地址欄輸入:http://148.70.249.79:8080/
一些事項說明:
1:管理員登錄也是通過該頁面進行登錄,有個管理員賬號,然後便可以進入後臺管理系統。
下圖即爲後臺管理界面:
2:發佈房屋上傳圖片後,該頁面沒有什麼明顯顯示,但是你將光標移到上傳處就會顯示你的圖片名字,即成功上傳。
3:項目可能還存在一些bu