Skip to content

Commit

Permalink
有是一个绝妙的进步
Browse files Browse the repository at this point in the history
  • Loading branch information
SmacUL committed Apr 24, 2020
1 parent c6ff852 commit d7662b6
Show file tree
Hide file tree
Showing 24 changed files with 299 additions and 71 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

基于协同过滤算法的新闻推荐系统, 推荐部分未开始. 项目分前后端与爬虫.

项目分支:
- main: 主分支, 保存最新的可预览状态.
- dev: Mac 上的开发分支
- dev-win: Win 上的开发分支

不同分支使用的数据库可能并不一致, 以分支中的 `NewsRecommend.sql` 文件为准

## 数据库 NewsRecommend.sql
MySQL 导入自动建库

Expand Down
28 changes: 25 additions & 3 deletions back/src/main/java/com/smacul/demo/controller/SelfController.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,29 @@ public String cusLogin(@RequestParam String cusName, @RequestParam String cusPas
return "登录失败";
}

/**
* 用户退出登录
* 20-04-24 创建方法
* @return
*/
@RequestMapping("/quit")
public String quitLogin() {
session.setAttribute("customer", null);
return "退出成功";
}

/**
* 用户注册
* 20-04-18 创建方法
*
* todo 少了一段, 在注册用户的时候, 需要同时管理 CusFeatureCount.
* 20-04-24 逻辑修改, 在注册时清空 session 中的用户
* @param cusName
* @param cusPass
* @return
*/
@RequestMapping("/register")
public String cusRegister(@RequestParam String cusName, @RequestParam String cusPass) {
try {
session.setAttribute("customer", null);
return selfService.setNewCus(cusName, cusPass);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
Expand Down Expand Up @@ -146,10 +157,21 @@ public CusFeatureFullMod getCusFeatureInfo(@RequestParam Integer cusId) {
return selfService.getCusFeatureInfo(cusId);
}

/**
* 获取指定用户的动态
* 20-04-24 创建方法
* @param cusId
* @param page
* @param pageSize
* @return
*/
@RequestMapping("/dynamic")
public List<CusDynamicMod> getCusDynamic(
@RequestParam Integer cusId, @RequestParam Integer page, @RequestParam Integer pageSize) {
return null;
if (session.getAttribute("customer") == null) {
return null;
}
return selfService.getCusDynamic(cusId, page, pageSize);
}

}
13 changes: 13 additions & 0 deletions back/src/main/java/com/smacul/demo/dao/ArtDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface ArtDao {
* 全局获取一页文章缩略内容, 包括文章基本信息, 文章作者基本信息, 文章的特征统计信息
* 20-04-19 创建方法
* 20-04-23 BUG 修改, SQL 多了一个逗号
* 20-04-24 方法修改, 替换了排序方式
* @param start
* @param pageSize
* @return
Expand All @@ -29,6 +30,7 @@ public interface ArtDao {
* 按照类别获取一页文章缩略内容, 包括文章基本信息, 文章作者基本信息, 文章的特征统计信息
* 20-04-19 创建方法
* 20-04-23 BUG 修改, SQL 多了一个逗号; 参数 type 修改为 artType
* 20-04-24 方法修改, 替换了排序方式
* @param artType
* @param start
* @param pageSize
Expand All @@ -40,6 +42,7 @@ public interface ArtDao {
* 获取一页热点新闻的文章缩略信息, 包括文章基本信息, 文章作者基本信息, 文章的特征统计信息
* 20-04-19 创建方法
* 20-04-23 BUG 修改, SQL 多了一个逗号
* 20-04-24 方法修改, 替换了排序方式
* @param start
* @param pageSize
* @return
Expand Down Expand Up @@ -74,10 +77,20 @@ public interface ArtDao {
* 简单的搜索功能
* 20-04-20 创建方法
* 20-04-23 BUG 修改, SQL 多了一个逗号; 删除了 SQL 中不必要的字段.
* 20-04-24 方法修改, 替换了排序方式
* @param key
* @param start
* @param pageSize
* @return
*/
List<ArtFullMod> searchContentSimple(String key, Integer start, Integer pageSize);

/**
* 返回一篇文章的基本信息
* 20-04-24 创建方法
* @param flag 用来判断此查询是否要生效, 生效值 非 11.
* @param artId
* @return
*/
ArtFullMod getSingleArt(Integer flag, Integer artId);
}
10 changes: 10 additions & 0 deletions back/src/main/java/com/smacul/demo/dao/ComDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ public interface ComDao {
/**
* 添加评论
* 20-04-10 创建方法
* 20-04-24 允许评论后返回自增主键
* @param comment
* @return
*/
Integer addCom(Comment comment);

/**
* 获取单一一条评论, 不包括其回复
* 20-04-24 创建方法
* @param flag 用来判断是否需要查询, 生效值为 2
* @param comId
* @return
*/
ComFullMod getSingleCom(Integer flag, Integer comId);

}
13 changes: 12 additions & 1 deletion back/src/main/java/com/smacul/demo/dao/CusBehaviorRecordDao.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.smacul.demo.dao;

import com.smacul.demo.bean.CusBehaviorRecord;
import com.smacul.demo.model.CusDynamicMod;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CusBehaviorRecordDao {

Expand Down Expand Up @@ -103,6 +106,14 @@ Integer addCusBehavior(
Integer deleteCusBehavior(
Integer cusIdFrom, Integer cusIdTo, Integer behavior, Integer artId, Integer type, Integer targetId);

CusBehaviorRecord getCusBehaviorRecordByCusId(Integer cusId);
/**
* 分页获取指定用户动态
* 20-04-24 创建方法
* @param cusId
* @param start
* @param pageSize
* @return
*/
List<CusDynamicMod> getCusDynamicByCusId(Integer cusId, Integer start, Integer pageSize);

}
10 changes: 10 additions & 0 deletions back/src/main/java/com/smacul/demo/dao/RepDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ public interface RepDao {
/**
* 添加回复
* 20-04-19 创建方法
* 20-04-24 允许插入后返回自增主键
* @param reply
* @return
*/
Integer addRep(Reply reply);

/**
* 获取单一一条回复
* 20-04-24 创建方法
* @param flag 用于判断查询是否生效, 生效值位 3
* @param repId
* @return
*/
RepFullMod getSingleRep(Integer flag, Integer repId);

}
2 changes: 2 additions & 0 deletions back/src/main/java/com/smacul/demo/model/ArtFullMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class ArtFullMod {
private Integer artLegal;
private Integer artCusId;

// 文章作者
private Customer customer;
private ArtFeatureCount artFeature;
// 浏览者-文章的行为
private CusArtBehaviorMod cusArtBehavior;

public Integer getArtId() {
Expand Down
29 changes: 29 additions & 0 deletions back/src/main/java/com/smacul/demo/model/CusDynamicMod.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.smacul.demo.model;

import com.smacul.demo.bean.Customer;

import java.sql.Timestamp;

public class CusDynamicMod {
Expand All @@ -11,7 +13,10 @@ public class CusDynamicMod {
private Timestamp cbrTime;
// 行为发生的位置代号, 0: 默认, 1: 文章, 2: 评论, 3:回复
private Integer cbrType;
private Integer cbrArtId;

private Customer cusFrom;
private Customer cusTo;
private ArtFullMod article;
private ComFullMod comment;
private RepFullMod reply;
Expand Down Expand Up @@ -64,6 +69,22 @@ public void setCbrType(Integer cbrType) {
this.cbrType = cbrType;
}

public Customer getCusFrom() {
return cusFrom;
}

public void setCusFrom(Customer cusFrom) {
this.cusFrom = cusFrom;
}

public Customer getCusTo() {
return cusTo;
}

public void setCusTo(Customer cusTo) {
this.cusTo = cusTo;
}

public ArtFullMod getArticle() {
return article;
}
Expand All @@ -87,4 +108,12 @@ public RepFullMod getReply() {
public void setReply(RepFullMod reply) {
this.reply = reply;
}

public Integer getCbrArtId() {
return cbrArtId;
}

public void setCbrArtId(Integer cbrArtId) {
this.cbrArtId = cbrArtId;
}
}
8 changes: 8 additions & 0 deletions back/src/main/java/com/smacul/demo/service/SelfService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public interface SelfService {
*/
CusFeatureFullMod getCusFeatureInfo(Integer cusId);

/**
* 分页获取指定用户的动态
* 20-04-24 创建方法
* @param cusId
* @param page
* @param pageSize
* @return
*/
List<CusDynamicMod> getCusDynamic(Integer cusId, Integer page, Integer pageSize);

}
4 changes: 2 additions & 2 deletions back/src/main/java/com/smacul/demo/service/ShapeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface ShapeService {
/**
* 评论编辑 5
* cbrCusIdFrom | cbrCusIdTo | cbrBehavior | cbrTime | cbrArtId | cbrType | cbrTargetId
* cusId | cusId | 5 | comTime | artId | 2 | comId
* cusId | artCusId | 5 | comTime | artId | 2 | comId
* @param cusId
* @param artId
* @param comId
Expand Down Expand Up @@ -84,7 +84,7 @@ public interface ShapeService {
/**
* 回复编辑(包括回复与回复的回复) 8
* cbrCusIdFrom | cbrCusIdTo | cbrBehavior | cbrTime | cbrArtId | cbrType | cbrTargetId
* cusId | cusId | 8 | repTime | artId | 3 | repId
* cusId | artCusId | 8 | repTime | artId | 3 | repId
* 20-04-19 创建方法
* @param cusId
* @param artId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public CusFeatureFullMod getCusFeatureInfo(Integer cusId) {
@Override
public List<CusDynamicMod> getCusDynamic(Integer cusId, Integer page, Integer pageSize) {
Integer start = PageHandler.calcuStartNO(page, pageSize);
//CusBehaviorRecord cusBehaviorRecord = cusBehaviorRecordDao.
return null;
return cusBehaviorRecordDao.getCusDynamicByCusId(cusId, start, pageSize);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.smacul.demo.service.impl;

import com.smacul.demo.bean.Customer;
import com.smacul.demo.dao.ArtDao;
import com.smacul.demo.dao.ArtFeatureCountDao;
import com.smacul.demo.dao.CusBehaviorRecordDao;
import com.smacul.demo.dao.CusFeatureCountDao;
import com.smacul.demo.model.ArtFullMod;
import com.smacul.demo.service.ShapeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -92,9 +94,10 @@ public Boolean setCusBehaviorArtDislike(Integer cusId, Integer artId, Boolean ty

@Override
public Boolean setCusBehaviorComEdit(Integer cusId, Integer artId, Integer comId) {
String artType = artDao.getArtTypeByArtId(artId);
Integer cbr = cbrDao.addCusBehavior(cusId, cusId, 5, artId, 2, comId);
Integer cfc = cusFeatureCountDao.updateCusFeature(cusId, "cfc_" + artType, 1);
// String artType = artDao.getArtTypeByArtId(artId);
ArtFullMod artFull = artDao.getArtFull(artId);
Integer cbr = cbrDao.addCusBehavior(cusId, artFull.getArtCusId(), 5, artId, 2, comId);
Integer cfc = cusFeatureCountDao.updateCusFeature(cusId, "cfc_" + artFull.getArtType(), 1);
Integer afc = artFeatureCountDao.updateArtFeature(artId, "afc_com_num", 1);
if (cbr == 1 && cfc == 1 && afc == 1) {
return true;
Expand All @@ -115,9 +118,10 @@ public Boolean setCusBehaviorComDislike(Integer cusId, Integer comCusId, Integer

@Override
public Boolean setCusBehaviorRepEdit(Integer cusId, Integer artId, Integer repId) {
String artType = artDao.getArtTypeByArtId(artId);
Integer cbr = cbrDao.addCusBehavior(cusId, cusId, 8, artId, 3, repId);
Integer cfc = cusFeatureCountDao.updateCusFeature(cusId, "cfc_" + artType, 1);
// String artType = artDao.getArtTypeByArtId(artId);
ArtFullMod artFull = artDao.getArtFull(artId);
Integer cbr = cbrDao.addCusBehavior(cusId, artFull.getArtCusId(), 8, artId, 3, repId);
Integer cfc = cusFeatureCountDao.updateCusFeature(cusId, "cfc_" + artFull.getArtType(), 1);
Integer afc = artFeatureCountDao.updateArtFeature(artId, "afc_rep_num", 1);
if (cbr == 1 && cfc == 1 && afc == 1) {
return true;
Expand Down
14 changes: 10 additions & 4 deletions back/src/main/resources/mapper/ArtMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
<select id="getTinyArtOnePageFromGlobal" resultMap="artFullModRM">
select art_id, art_title, art_spider, art_type, art_tags, art_image_url, art_time, art_legal, art_cus_id
from Article left join artscorelist on Article.art_id = artscorelist.asl_art_id
order by art_time desc
order by artscorelist.asl_art_score desc
limit #{start}, #{pageSize}
</select>

<select id="getTinyArtOnePageByType" resultMap="artFullModRM">
select art_id, art_title, art_spider, art_type, art_tags, art_image_url, art_time, art_legal, art_cus_id
from Article left join artscorelist on Article.art_id = artscorelist.asl_art_id
where art_type = #{artType}
order by art_time desc
order by artscorelist.asl_art_score desc
limit #{start}, #{pageSize}
</select>

<select id="getHotArtOnePage" resultMap="artFullModRM">
select art_id, art_title, art_spider, art_type, art_tags, art_image_url, art_time, art_legal, art_cus_id
from Article left join ArtTimeList on Article.art_id = ArtTimeList.atl_art_id
order by art_time desc
order by ArtTimeList.atl_art_score desc
limit #{start}, #{pageSize}
</select>

Expand All @@ -49,10 +49,16 @@
select art_id, art_title, art_spider, art_type, art_tags, art_image_url, art_time, art_legal, art_cus_id
from Article left join artscorelist on Article.art_id = artscorelist.asl_art_id
where art_title like concat('%', #{key}, '%') or art_content like concat('%', #{key}, '%')
order by art_time desc
order by artscorelist.asl_art_score desc
limit #{start}, #{pageSize}
</select>

<select id="getSingleArt" resultType="com.smacul.demo.model.ArtFullMod">
select *
from Article
where 11 != #{flag} and art_id = #{artId}
</select>

<resultMap id="artFullModRM" type="com.smacul.demo.model.ArtFullMod">
<id property="artId" column="art_id"></id>
<result property="artTitle" column="art_title"></result>
Expand Down
8 changes: 7 additions & 1 deletion back/src/main/resources/mapper/ComMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.smacul.demo.dao.ComDao">
<insert id="addCom">
<insert id="addCom" useGeneratedKeys="true" keyProperty="comId" parameterType="com.smacul.demo.bean.Comment">
insert into Comment(com_content, com_legal, com_cus_id, com_art_id)
values(#{comContent}, #{comLegal}, #{comCusId}, #{comArtId})
</insert>
Expand All @@ -16,6 +16,12 @@
order by com_time desc
</select>

<select id="getSingleCom" resultType="com.smacul.demo.model.ComFullMod">
select *
from Comment
where 2 = #{flag} and com_id = #{comId}
</select>

<resultMap id="searchCommentsRM" type="com.smacul.demo.model.ComFullMod">
<id property="comId" column="com_id"></id>
<result property="comArtId" column="com_art_id"></result>
Expand Down
Loading

0 comments on commit d7662b6

Please sign in to comment.